1- #include " tigerapi/push_client .h"
1+ #include " tigerapi/push_socket/push_client_impl .h"
22#include " tigerapi/client_config.h"
33#include " tigerapi/push_socket/push_socket.h"
44#include " openapi_pb\pb_source\PushData.pb.h"
55#include < iostream>
66#include " google/protobuf/util/json_util.h"
77
8- std::shared_ptr<TIGER_API::PushClient > TIGER_API::PushClient::create_push_client (const TIGER_API::ClientConfig& client_config)
8+ std::shared_ptr<TIGER_API::PushClientImpl > TIGER_API::PushClientImpl::create_push_client_impl (const TIGER_API::ClientConfig& client_config)
99{
10- return std::shared_ptr<TIGER_API::PushClient >(new TIGER_API::PushClient ( ));
10+ return std::shared_ptr<TIGER_API::PushClientImpl >(new TIGER_API::PushClientImpl (client_config ));
1111}
1212
13- TIGER_API::PushClient ::~PushClient ()
13+ TIGER_API::PushClientImpl ::~PushClientImpl ()
1414{
1515 io_service_.stop ();
1616
@@ -20,61 +20,62 @@ TIGER_API::PushClient::~PushClient()
2020 }
2121}
2222
23- TIGER_API::PushClient::PushClient ()
23+ TIGER_API::PushClientImpl::PushClientImpl (const TIGER_API::ClientConfig& client_config)
24+ :client_config_(client_config)
2425{
2526
2627}
2728
28- void TIGER_API::PushClient ::connect (const TIGER_API::ClientConfig& client_config )
29+ void TIGER_API::PushClientImpl ::connect ()
2930{
3031 LOG (INFO) << " create a worker thread to perform asynchronous network connections" ;
3132 // 启动工作线程
32- worker_thread_ = std::shared_ptr<std::thread>(new std::thread ([this , client_config ]
33+ worker_thread_ = std::shared_ptr<std::thread>(new std::thread ([this ]
3334 {
34- socket_ = PushSocket::create_push_socket (&io_service_, client_config );
35+ socket_ = PushSocket::create_push_socket (&io_service_, client_config_ );
3536 socket_->connect ();
3637
3738 LOG (INFO) << " io_service run on work thread" ;
3839 io_service_.run ();
3940 }));
4041}
4142
42- void TIGER_API::PushClient ::disconnect ()
43+ void TIGER_API::PushClientImpl ::disconnect ()
4344{
4445 // 跨线程调用,需要异步投递任务
45- io_service_.post (boost::bind (&PushClient ::do_disconnect, this ));
46+ io_service_.post (boost::bind (&PushClientImpl ::do_disconnect, this ));
4647}
4748
48- void TIGER_API::PushClient ::set_connected_callback (const std::function<void ()>& cb)
49+ void TIGER_API::PushClientImpl ::set_connected_callback (const std::function<void ()>& cb)
4950{
5051 if (socket_)
5152 {
5253 socket_->set_connected_callback (cb);
5354 }
5455}
5556
56- void TIGER_API::PushClient ::set_disconnected_callback (const std::function<void ()>& cb)
57+ void TIGER_API::PushClientImpl ::set_disconnected_callback (const std::function<void ()>& cb)
5758{
5859 if (socket_)
5960 {
6061 socket_->set_disconnected_callback (cb);
6162 }
6263}
6364
64- void TIGER_API::PushClient ::set_inner_error_callback (const std::function<void (std::string)>& cb)
65+ void TIGER_API::PushClientImpl ::set_inner_error_callback (const std::function<void (std::string)>& cb)
6566{
6667 if (socket_)
6768 {
6869 socket_->set_inner_error_callback (cb);
6970 }
7071}
7172
72- void TIGER_API::PushClient ::set_asset_changed_callback (const std::function<void (const tigeropen::push::pb::AssetData&)>& cb)
73+ void TIGER_API::PushClientImpl ::set_asset_changed_callback (const std::function<void (const tigeropen::push::pb::AssetData&)>& cb)
7374{
7475 asset_changed_ = cb;
7576}
7677
77- bool TIGER_API::PushClient ::subscribe_asset (const std::string& account)
78+ bool TIGER_API::PushClientImpl ::subscribe_asset (const std::string& account)
7879{
7980 if (!socket_)
8081 {
@@ -97,7 +98,7 @@ bool TIGER_API::PushClient::subscribe_asset(const std::string& account)
9798 return true ;
9899}
99100
100- bool TIGER_API::PushClient ::unsubscribe_asset (const std::string& account)
101+ bool TIGER_API::PushClientImpl ::unsubscribe_asset (const std::string& account)
101102{
102103 if (!socket_)
103104 {
@@ -120,7 +121,7 @@ bool TIGER_API::PushClient::unsubscribe_asset(const std::string& account)
120121 return true ;
121122}
122123
123- bool TIGER_API::PushClient ::send_frame (const tigeropen::push::pb::Request& request)
124+ bool TIGER_API::PushClientImpl ::send_frame (const tigeropen::push::pb::Request& request)
124125{
125126 // 序列化pb对象到字符串
126127 std::string packed_frame = request.SerializeAsString ();
@@ -136,28 +137,28 @@ bool TIGER_API::PushClient::send_frame(const tigeropen::push::pb::Request& reque
136137 LOG (DEBUG) << " send frame:" << packed_frame_json;
137138
138139 // 跨线程,异步投递任务
139- io_service_.post (boost::bind (&PushClient ::do_write, this , packed_frame));
140+ io_service_.post (boost::bind (&PushClientImpl ::do_write, this , packed_frame));
140141
141142 return true ;
142143}
143144
144- void TIGER_API::PushClient ::do_write (const std::string& frame)
145+ void TIGER_API::PushClientImpl ::do_write (const std::string& frame)
145146{
146147 if (socket_)
147148 {
148149 socket_->send_message (frame);
149150 }
150151}
151152
152- void TIGER_API::PushClient ::do_disconnect ()
153+ void TIGER_API::PushClientImpl ::do_disconnect ()
153154{
154155 if (socket_)
155156 {
156157 socket_->disconnect ();
157158 }
158159}
159160
160- void TIGER_API::PushClient ::on_message (const std::shared_ptr<tigeropen::push::pb::Response>& response_pb_object)
161+ void TIGER_API::PushClientImpl ::on_message (const std::shared_ptr<tigeropen::push::pb::Response>& response_pb_object)
161162{
162163 if (response_pb_object->body ().datatype () == tigeropen::push::pb::SocketCommon_DataType_Asset && asset_changed_)
163164 {
0 commit comments