Line data Source code
1 : //
2 : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2013-2015
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #include "hash_domain.hpp"
8 : #include <hash/logger.hpp>
9 : #include <unistd.h>
10 : #include <wfc/logger.hpp>
11 : #include <wfc/logger/ilogger.hpp>
12 : #include <wfc/wfc_exit.hpp>
13 : #include <wlog/logger_fun.hpp>
14 : #include <iow/logger.hpp>
15 :
16 :
17 : namespace demo{ namespace hash{
18 :
19 : class logger: public wfc::ilogger
20 : {
21 : public:
22 :
23 : formatter_fun stdout_formatter() override
24 : {
25 : return &logger::formater;
26 : }
27 :
28 : static void formater(std::ostream& os, const wlog::time_point& /*tp*/,
29 : const std::string& /*name*/, const std::string& /*ident*/, const std::string& str)
30 : {
31 : auto beg = str.find('[');
32 : auto end = str.find(']');
33 : if ( beg!=std::string::npos && end!=std::string::npos )
34 : os << std::string(
35 : str.begin() + static_cast<std::ptrdiff_t>(beg + 1),
36 : str.begin() + static_cast<std::ptrdiff_t>(end)
37 : );
38 : else
39 : os << str;
40 : }
41 : };
42 :
43 1 : void hash_domain::configure()
44 : {
45 : ///! this->set_target("logger", "IOW", std::make_shared<logger>() );
46 1 : DEBUG_LOG_DEBUG("hash_domain::configure " << this->options().param)
47 1 : }
48 :
49 0 : void hash_domain::reconfigure()
50 : {
51 : ///! this->set_target("logger", "IOW", std::make_shared<logger>() );
52 0 : DEBUG_LOG_DEBUG("hash_domain::reconfigure " << this->options().param)
53 0 : }
54 :
55 0 : void hash_domain::reconfigure_basic()
56 : {
57 0 : DEBUG_LOG_DEBUG("hash_domain::reconfigure_basic " << this->options().param)
58 0 : }
59 :
60 1 : void hash_domain::initialize()
61 : {
62 1 : }
63 :
64 1 : void hash_domain::get_hash(request::get_hash::ptr req, response::get_hash::handler cb )
65 : {
66 1 : if ( this->notify_ban(req, cb) )
67 1 : return;
68 :
69 1 : auto res = std::make_unique<response::get_hash>();
70 1 : res->value = std::hash< std::string >()( req->value );
71 1 : cb( std::move(res) );
72 : }
73 :
74 0 : void hash_domain::perform_io(data_ptr d, io_id_t, output_handler_t handler)
75 : {
76 0 : if (d==nullptr)
77 0 : return handler(nullptr);
78 :
79 0 : std::string str( d->begin(), d->end() );
80 0 : size_t val = std::hash< std::string >()( str );
81 0 : std::string valstr = std::to_string(val);
82 0 : auto res = std::make_unique<data_type>( valstr.begin(), valstr.end() );
83 0 : handler( std::move(res) );
84 : }
85 :
86 3 : }}
|