ROOT_Application
2.0
C++ Core modules and GUIStock
|
Use with RealTime to receive messages from python ServerPortfolio. More...
#include <TCPServer.h>
Public Member Functions | |
Constructors and destructor | |
TCPServer (StockManager *sm, unsigned int iport) | |
Constructor, io_service is a private data member (my_io_service). More... | |
TCPServer (StockManager *sm, unsigned int iport, boost::asio::io_service &io_service) | |
Constructor, io_service created in the calling function. More... | |
virtual | ~TCPServer () |
Destructor. More... | |
Functions for running / stopping the server | |
void | StartServer () |
Start the server. More... | |
void | StopServer () |
Stop the server. More... | |
bool | IsRunning () |
Return the status of the server. More... | |
Private Member Functions | |
void | start_accept () |
create a new tcp_connection to receive message More... | |
void | handle_accept (tcp_connection::pointer new_connection, const boost::system::error_code &error) |
handle the received message: parse and send string data to StockManager. More... | |
void | LoopThread () |
Function run by the internal thread. More... | |
Private Attributes | |
StockManager * | f_sm |
Pointer to the StockManager singleton, will receive and treat the messages. More... | |
unsigned int | port |
Port where the server listens. More... | |
boost::asio::io_service | my_io_service |
io_service needed for asimc. More... | |
tcp::acceptor | acceptor_ |
... More... | |
std::thread | t_ |
Internal thread. More... | |
Status of the server | |
bool | is_running |
Indicate if the server is running. More... | |
bool | want_exit |
Indicate the thread must exit, set in destructor only. More... | |
Locks for threads communication | |
std::mutex | loop_mutex |
std::condition_variable | loop_cv |
Use with RealTime to receive messages from python ServerPortfolio.
Alternative to re-reading INST files every time.
It can only receive messages, does not reply.
The server run in an independent thread, created in constructor.
It sends the data to StockManager (associated by aggregation)
Only one tcp_connection exists at a time, the thread will update StockManager.
Maybe need to extend if many messages.
Use boost::asio approach
Definition at line 122 of file TCPServer.h.
TCPServer::TCPServer | ( | StockManager * | sm, |
unsigned int | iport | ||
) |
Constructor, io_service is a private data member (my_io_service).
Creates a thread and a first tcp_connection, but the server is waiting after the constructor.
It seems supported to have it as data member. Not sure about the limitation.
Certainly fine if io_service is used only for one class. Would need a global instance if more objects use it ??
It is the version used now
sm | pointer to the StockManager singleton |
iport | port number where the server listens |
Definition at line 75 of file TCPServer.cpp.
References f_sm, is_running, port, and want_exit.
TCPServer::TCPServer | ( | StockManager * | sm, |
unsigned int | iport, | ||
boost::asio::io_service & | io_service | ||
) |
Constructor, io_service created in the calling function.
Passing an instance of io_service seems to be in all examples
If it is used only for the server, we can use the other constructor which uses a data member
sm | pointer to the StockManager singleton |
iport | port number where the server listens |
io_service | instance of boost::asio::io_service created in the main function (in most of the examples) |
Definition at line 63 of file TCPServer.cpp.
References f_sm, is_running, port, and want_exit.
|
virtual |
Destructor.
Definition at line 89 of file TCPServer.cpp.
References is_running, and StopServer().
|
private |
handle the received message: parse and send string data to StockManager.
new_connection is deleted automatically at the end of the function.
An other is created by a call to start_accept.
Set error code
Definition at line 285 of file TCPServer.cpp.
References f_sm, is_running, StockManager::SendDatadCSV(), start_accept(), and StockException::what().
Referenced by start_accept().
|
inline |
|
private |
Function run by the internal thread.
Definition at line 215 of file TCPServer.cpp.
References acceptor_, is_running, loop_cv, loop_mutex, start_accept(), and want_exit.
Referenced by StartServer().
|
private |
create a new tcp_connection to receive message
Definition at line 259 of file TCPServer.cpp.
References acceptor_, tcp_connection::create(), and handle_accept().
Referenced by handle_accept(), and LoopThread().
void TCPServer::StartServer | ( | ) |
Start the server.
It will run on its internal thread
Definition at line 111 of file TCPServer.cpp.
References is_running, loop_cv, loop_mutex, LoopThread(), port, and t_.
Referenced by main().
void TCPServer::StopServer | ( | ) |
Stop the server.
Definition at line 157 of file TCPServer.cpp.
References acceptor_, is_running, loop_cv, loop_mutex, t_, and want_exit.
Referenced by ~TCPServer().
|
private |
...
Definition at line 205 of file TCPServer.h.
Referenced by LoopThread(), start_accept(), and StopServer().
|
private |
Pointer to the StockManager singleton, will receive and treat the messages.
It is set in the constructor and should not be deleted in the destructor.
Definition at line 196 of file TCPServer.h.
Referenced by handle_accept(), and TCPServer().
|
private |
Indicate if the server is running.
Definition at line 209 of file TCPServer.h.
Referenced by handle_accept(), IsRunning(), LoopThread(), StartServer(), StopServer(), TCPServer(), and ~TCPServer().
|
private |
Definition at line 220 of file TCPServer.h.
Referenced by LoopThread(), StartServer(), and StopServer().
|
private |
Definition at line 219 of file TCPServer.h.
Referenced by LoopThread(), StartServer(), and StopServer().
|
private |
|
private |
Port where the server listens.
Definition at line 198 of file TCPServer.h.
Referenced by StartServer(), and TCPServer().
|
private |
Internal thread.
Definition at line 214 of file TCPServer.h.
Referenced by StartServer(), and StopServer().
|
private |
Indicate the thread must exit, set in destructor only.
Definition at line 211 of file TCPServer.h.
Referenced by LoopThread(), StopServer(), and TCPServer().