Line data Source code
1 : #include <iostream>
2 : #include "client_tcp.hpp"
3 : #include "client_tcp_map.hpp"
4 : #include <wfc/logger.hpp>
5 : #include <iow/ip/tcp/client/client.hpp>
6 : #include <iow/io/io_id.hpp>
7 : #include <wfc/asio.hpp> // TODO: убрать
8 : #include <wfc/memory.hpp>
9 :
10 : namespace wfc{ namespace io{
11 :
12 :
13 0 : void client_tcp::configure()
14 : {
15 0 : _client_map = std::make_shared<client_tcp_map>( this->global()->io_service);
16 0 : }
17 :
18 0 : void client_tcp::initialize()
19 : {
20 0 : auto opt = this->options();
21 0 : opt.args.workflow = this->get_workflow();
22 :
23 0 : if ( opt.rn )
24 : {
25 0 : if ( opt.connection.reader.sep.empty() ) opt.connection.reader.sep = "\r\n";
26 0 : if ( opt.connection.writer.sep.empty() ) opt.connection.writer.sep = "\r\n";
27 : }
28 :
29 0 : _client_map->reconfigure( opt );
30 0 : }
31 :
32 0 : void client_tcp::stop()
33 : {
34 0 : if ( _client_map!=nullptr )
35 : {
36 0 : _client_map->stop();
37 : }
38 0 : }
39 :
40 0 : void client_tcp::reg_io(io_id_t io_id, std::weak_ptr<iinterface> itf)
41 : {
42 0 : if ( !this->suspended() && _client_map!=nullptr )
43 : {
44 0 : _client_map->reg_io( io_id, itf);
45 : }
46 0 : }
47 :
48 0 : void client_tcp::unreg_io(io_id_t io_id)
49 : {
50 0 : if ( _client_map!=nullptr )
51 : {
52 0 : _client_map->unreg_io(io_id);
53 : }
54 0 : }
55 :
56 0 : void client_tcp::perform_io(data_ptr d, io_id_t io_id, output_handler_t handler)
57 : {
58 0 : if ( this->suspended() )
59 : {
60 0 : if ( handler!= nullptr )
61 0 : handler(nullptr);
62 : }
63 0 : else if ( _client_map!=nullptr )
64 : {
65 0 : _client_map->perform_io( std::move(d), io_id, std::move(handler) );
66 : }
67 0 : }
68 :
69 3 : }}
|