COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ServerNetworkComm Class Reference

This class is the server network level. More...

#include <ServerNetworkComm.hpp>

Inherits SignalHandler.

Classes

struct  ClientInfo
 

Public Member Functions

 ServerNetworkComm ()
 Constructor. More...
 
 ~ServerNetworkComm ()
 Destructor. More...
 
bool open_port (unsigned short port=62784)
 Opens a port the server has to listen to. More...
 
void run ()
 
void close ()
 Stops all network operations. More...
 
void send_message_to_client (const std::string &message, uiCommon::LogMessage::Type type, const std::string &uuid=std::string())
 Sends a message to a client. More...
 
void send_frame_to_client (common::XML::SignalFrame &signal, const std::string &uuid=std::string())
 
void send_frame_rejected_to_client (const std::string clientid, const std::string &frameid, const common::URI &sender, const std::string &reason)
 
- Public Member Functions inherited from SignalHandler
 ~SignalHandler ()
 
const storage_tsignal_list () const
 
SignalPtr signal (const SignalID &sname)
 
SignalCPtr signal (const SignalID &sname) const
 
SignalRet call_signal (const SignalID &sname, SignalArgs &sinput)
 Calls the signal by providing its name and input. More...
 
SignalRet call_signal (const SignalID &sname, std::vector< std::string > &sinput)
 Calls the signal by providing its name and input. More...
 
bool signal_exists (const SignalID &sname) const
 Checks if a signal exists or not. More...
 
Signalregist_signal (const SignalID &sname)
 Regist signal. More...
 
void unregist_signal (const SignalID &sname)
 Unregist signal. More...
 

Private Member Functions

void init_accept ()
 
void init_send (boost::shared_ptr< network::TCPConnection > client, common::XML::SignalFrame &frame)
 
void init_read (ClientInfo &client)
 
void callback_accept (boost::shared_ptr< network::TCPConnection > conn, const boost::system::error_code &error)
 
void callback_send (boost::shared_ptr< network::TCPConnection > conn, const boost::system::error_code &error)
 
void callback_read (boost::shared_ptr< network::TCPConnection > conn, const boost::system::error_code &error)
 
void send_message (boost::shared_ptr< network::TCPConnection > client, const std::string &message, uiCommon::LogMessage::Type type)
 Sends a message to a client. More...
 
void send (boost::shared_ptr< network::TCPConnection > client, const common::XML::XmlDoc &signal)
 Sends a message to a client. More...
 
void send_frame_rejected (boost::shared_ptr< network::TCPConnection > client, const std::string &frameid, const cf3::common::URI &sender, const std::string &reason)
 
boost::shared_ptr< network::TCPConnectionget_connection (const std::string &uuid) const
 Retrieves a client socket from its UuiD. More...
 

Private Attributes

boost::asio::io_service * m_io_service
 
boost::asio::ip::tcp::acceptor * m_acceptor
 
unsigned short m_port
 
std::map< boost::shared_ptr< network::TCPConnection >, ClientInfom_clients
 Mutex for thread-safe operations. More...
 

Additional Inherited Members

- Public Types inherited from SignalHandler
typedef std::vector< SignalPtrstorage_t
 storage type for signals More...
 
- Public Attributes inherited from SignalHandler
storage_t m_signals
 storage of the signals More...
 

Detailed Description

This class is the server network level.

For all signals emitted by this class, the first parameter identifies the client that caused the signal to be emitted. A same client will always have the same id. When client disconnects, its id will never be given to another client.

Author
Quentin Gasper.

Definition at line 43 of file ServerNetworkComm.hpp.

Constructor & Destructor Documentation

Constructor.

Definition at line 48 of file ServerNetworkComm.cpp.

Destructor.

Closes the sockets before the object is deleted.

Definition at line 58 of file ServerNetworkComm.cpp.

Member Function Documentation

void callback_accept ( boost::shared_ptr< network::TCPConnection conn,
const boost::system::error_code &  error 
)
private

Definition at line 173 of file ServerNetworkComm.cpp.

void callback_read ( boost::shared_ptr< network::TCPConnection conn,
const boost::system::error_code &  error 
)
private

Definition at line 209 of file ServerNetworkComm.cpp.

void callback_send ( boost::shared_ptr< network::TCPConnection conn,
const boost::system::error_code &  error 
)
private

Definition at line 199 of file ServerNetworkComm.cpp.

void close ( )

Stops all network operations.

Definition at line 93 of file ServerNetworkComm.cpp.

TCPConnection::Ptr get_connection ( const std::string &  uuid) const
private

Retrieves a client socket from its UuiD.

Parameters
uuidClient UuiD
Returns
Returns a pointer to the socket, or nullptr if client UuiD was -1 (all clients).
Exceptions
UnknownClientIdExceptionif Client id is unknown.

Definition at line 343 of file ServerNetworkComm.cpp.

void init_accept ( )
private

Definition at line 122 of file ServerNetworkComm.cpp.

void init_read ( ClientInfo client)
private

Definition at line 160 of file ServerNetworkComm.cpp.

void init_send ( boost::shared_ptr< network::TCPConnection client,
common::XML::SignalFrame frame 
)
private

Definition at line 137 of file ServerNetworkComm.cpp.

bool open_port ( unsigned short  port = 62784)

Opens a port the server has to listen to.

All network interfaces (local loop, ethernet, wi-fi,...) are listened to.

Parameters
hostAddressServer address.
Exceptions
NetworkExceptionThrows a NetworkException if the server cannot listen to the given port.

Definition at line 103 of file ServerNetworkComm.cpp.

void run ( )

Definition at line 77 of file ServerNetworkComm.cpp.

void send ( boost::shared_ptr< network::TCPConnection client,
const common::XML::XmlDoc signal 
)
private

Sends a message to a client.

Parameters
clientClient m_socket to use. If nullptr, the frame will be sent to all clients.
signalSignal frame to send.
Returns
Returns the number of bytes sent.
void send_frame_rejected ( boost::shared_ptr< network::TCPConnection client,
const std::string &  frameid,
const cf3::common::URI sender,
const std::string &  reason 
)
private

Definition at line 309 of file ServerNetworkComm.cpp.

void send_frame_rejected_to_client ( const std::string  clientid,
const std::string &  frameid,
const common::URI sender,
const std::string &  reason 
)

Definition at line 290 of file ServerNetworkComm.cpp.

void send_frame_to_client ( common::XML::SignalFrame signal,
const std::string &  uuid = std::string() 
)

Definition at line 282 of file ServerNetworkComm.cpp.

void send_message ( boost::shared_ptr< network::TCPConnection client,
const std::string &  message,
uiCommon::LogMessage::Type  type 
)
private

Sends a message to a client.

Parameters
clientClient socket to use. If nullptr, the message will be sent to all clients.
messageMessage to send.
Returns
Returns true if the frame was built and sent successfully; otherwise returns false.

Definition at line 325 of file ServerNetworkComm.cpp.

void send_message_to_client ( const std::string &  message,
uiCommon::LogMessage::Type  type,
const std::string &  uuid = std::string() 
)

Sends a message to a client.

Parameters
messageMessage to send
uuidClient UuiD, or an empty string to send to all clients.
Exceptions
UnknownClientIdExceptionif Client UuiD is unknown.

Definition at line 300 of file ServerNetworkComm.cpp.

Member Data Documentation

boost::asio::ip::tcp::acceptor* m_acceptor
private

Definition at line 128 of file ServerNetworkComm.hpp.

std::map<boost::shared_ptr<network::TCPConnection>, ClientInfo> m_clients
private

Mutex for thread-safe operations.

The client sockets. The key is pointer to the m_socket. The value is the client UuiD.

Definition at line 138 of file ServerNetworkComm.hpp.

boost::asio::io_service* m_io_service
private

Definition at line 126 of file ServerNetworkComm.hpp.

unsigned short m_port
private

Definition at line 130 of file ServerNetworkComm.hpp.


The documentation for this class was generated from the following files:
Send comments to:
COOLFluiD Web Admin