ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Private Member Functions | Private Attributes
TCPServer Class Reference

Use with RealTime to receive messages from python ServerPortfolio. More...

#include <TCPServer.h>

Collaboration diagram for TCPServer:
Collaboration graph
[legend]

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

StockManagerf_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
 

Detailed Description

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.

Constructor & Destructor Documentation

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

Parameters
smpointer to the StockManager singleton
iportport 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

Parameters
smpointer to the StockManager singleton
iportport number where the server listens
io_serviceinstance of boost::asio::io_service created in the main function (in most of the examples)
Deprecated:

Definition at line 63 of file TCPServer.cpp.

References f_sm, is_running, port, and want_exit.

TCPServer::~TCPServer ( )
virtual

Destructor.

Definition at line 89 of file TCPServer.cpp.

References is_running, and StopServer().

Here is the call graph for this function:

Member Function Documentation

void TCPServer::handle_accept ( tcp_connection::pointer  new_connection,
const boost::system::error_code &  error 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

bool TCPServer::IsRunning ( )
inline

Return the status of the server.

Definition at line 164 of file TCPServer.h.

References is_running.

void TCPServer::LoopThread ( )
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().

Here is the call graph for this function:

Here is the caller graph for this function:

void TCPServer::start_accept ( )
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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

Field Documentation

tcp::acceptor TCPServer::acceptor_
private

...

Definition at line 205 of file TCPServer.h.

Referenced by LoopThread(), start_accept(), and StopServer().

StockManager* TCPServer::f_sm
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().

bool TCPServer::is_running
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().

std::condition_variable TCPServer::loop_cv
private

Definition at line 220 of file TCPServer.h.

Referenced by LoopThread(), StartServer(), and StopServer().

std::mutex TCPServer::loop_mutex
private

Definition at line 219 of file TCPServer.h.

Referenced by LoopThread(), StartServer(), and StopServer().

boost::asio::io_service TCPServer::my_io_service
private

io_service needed for asimc.

calls

Definition at line 201 of file TCPServer.h.

unsigned int TCPServer::port
private

Port where the server listens.

Definition at line 198 of file TCPServer.h.

Referenced by StartServer(), and TCPServer().

std::thread TCPServer::t_
private

Internal thread.

Definition at line 214 of file TCPServer.h.

Referenced by StartServer(), and StopServer().

bool TCPServer::want_exit
private

Indicate the thread must exit, set in destructor only.

Definition at line 211 of file TCPServer.h.

Referenced by LoopThread(), StopServer(), and TCPServer().


The documentation for this class was generated from the following files: