Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

oxygen::NetControl Class Reference

SimControlNode that accepts and manages a set of network client connections via UDP or TCP. More...

#include <netcontrol.h>

Inheritance diagram for oxygen::NetControl:

Inheritance graph
[legend]
Collaboration diagram for oxygen::NetControl:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::map< rcss::net::Addr,
boost::shared_ptr< Client > > 
TAddrMap
typedef std::map< rcss::net::Addr,
boost::shared_ptr< NetBuffer > > 
TBufferMap
typedef std::list< rcss::net::Addr > TAddrList
enum  ESocketType { ST_TCP, ST_UDP }

Public Member Functions

 NetControl ()
virtual ~NetControl ()
virtual void InitSimulation ()
 creates the managed socket, when the simulation starts
virtual void DoneSimulation ()
 called once before the simulation is shut down
virtual void StartCycle ()
 called when a new simulation cycle starts, before the simulation is stepped
virtual void EndCycle ()
 called when the current simulation cycle ends
virtual void ClientConnect (boost::shared_ptr< Client > client)
 called when a new client connects
virtual void ClientDisconnect (boost::shared_ptr< Client > client)
 called when a client disconnects
void SetServerPort (rcss::net::Addr::PortType port)
 sets the local port, on which connections are accepted
rcss::net::Addr::PortType GetServerPort ()
 returns the local port, on which connections are accepted
void SetServerType (ESocketType type)
 sets the type of the socket on which connections are accepted
ESocketType GetServerType ()
 returns the type of the socket on which connections are accepted
void SendMessage (boost::shared_ptr< Client > client, const std::string &msg)
 sends a message to the given client
void SendMessage (const rcss::net::Addr &addr, const std::string &msg)
 sends a message to the client with the given address

Static Public Member Functions

static boost::shared_ptr<
rcss::net::Socket > 
NetControl::CreateSocket (ESocketType type)
 create a socket according to the given ESocketType

Protected Member Functions

std::string NetControl::DescribeSocketType ()
 returns a human readable description of the socket type and port
void AcceptTCPConnections ()
 checks for and accepts pending TCP connections
void NetControl::ReadMessages ()
 reads and stores all available messages
void ReadTCPMessages ()
 reads and stores all available TCP messages
void ReadUDPMessages ()
 reads and stores all available UDP messages.
void StoreFragment (const rcss::net::Addr &addr, int size)
 copies the message fragment with length
void AddClient (const rcss::net::Addr &from, boost::shared_ptr< rcss::net::Socket > socket=boost::shared_ptr< rcss::net::Socket >())
 creates a new client entry.
void RemoveClient (const rcss::net::Addr &from)
 removes a client entry and closes the associated socket.
void CloseDeadConnections ()
 removes all clients marked in the mCloseClients list

Protected Attributes

boost::shared_ptr< NetMessagemNetMessage
 cached reference to the NetMessage child node
rcss::net::Addr mLocalAddr
 the local port, on which connections are accepted
ESocketType mSocketType
 the type of created socket
boost::shared_ptr< rcss::net::Socket > mSocket
 the socket used to accept connections
TAddrMap mClients
 map of known clients, based on remote address
TAddrList mCloseClients
 list of client connections to be closed
TBufferMap mBuffers
 list of queued messages
int mBufferSize
 the size of the allocated receive buffer
boost::shared_array< char > mBuffer
 the receive buffer
int mClientId
 the next available unique client id

Classes

struct  Client

Detailed Description

SimControlNode that accepts and manages a set of network client connections via UDP or TCP.

With each simulation cycle it collects all pending client messages in a set of network buffers, each corresponding to a client. It furthes provides methods to send messages to connected clients.

The segmentation of the received data into messages and the composition of messages is delegated to a NetMessage class that is registered to a NetControl node. It is responsible to manage the MetaProtocol, i.e. it adds and removes any additional message framing and type information.

Definition at line 45 of file netcontrol.h.


Member Typedef Documentation

typedef std::list<rcss::net::Addr> oxygen::NetControl::TAddrList
 

Definition at line 75 of file netcontrol.h.

typedef std::map<rcss::net::Addr, boost::shared_ptr<Client> > oxygen::NetControl::TAddrMap
 

Definition at line 70 of file netcontrol.h.

typedef std::map<rcss::net::Addr, boost::shared_ptr<NetBuffer> > oxygen::NetControl::TBufferMap
 

Definition at line 73 of file netcontrol.h.


Member Enumeration Documentation

enum oxygen::NetControl::ESocketType
 

Enumerator:
ST_TCP 
ST_UDP 

Definition at line 48 of file netcontrol.h.


Constructor & Destructor Documentation

NetControl::NetControl  ) 
 

Definition at line 36 of file netcontrol.cpp.

References mBuffer, mBufferSize, mClientId, mLocalAddr, mSocketType, and ST_TCP.

NetControl::~NetControl  )  [virtual]
 

Definition at line 45 of file netcontrol.cpp.


Member Function Documentation

void NetControl::AcceptTCPConnections  )  [protected]
 

checks for and accepts pending TCP connections

Definition at line 336 of file netcontrol.cpp.

References AddClient(), zeitgeist::Object::GetLog(), zeitgeist::Leaf::GetName(), mSocket, mSocketType, and ST_TCP.

Referenced by StartCycle().

Here is the call graph for this function:

void oxygen::NetControl::AddClient const rcss::net::Addr &  from,
boost::shared_ptr< rcss::net::Socket >  socket = boost::shared_ptr< rcss::net::Socket >()
[protected]
 

creates a new client entry.

Parameters:
from is the remote adress of the client.
socket gives the loacl socket for a TCP connection the for a TCP connection

Referenced by AcceptTCPConnections(), and ReadUDPMessages().

virtual void oxygen::NetControl::ClientConnect boost::shared_ptr< Client client  )  [virtual]
 

called when a new client connects

virtual void oxygen::NetControl::ClientDisconnect boost::shared_ptr< Client client  )  [virtual]
 

called when a client disconnects

void NetControl::CloseDeadConnections  )  [protected]
 

removes all clients marked in the mCloseClients list

Definition at line 414 of file netcontrol.cpp.

References mCloseClients, and RemoveClient().

Referenced by EndCycle().

Here is the call graph for this function:

void NetControl::DoneSimulation  )  [virtual]
 

called once before the simulation is shut down

Reimplemented from oxygen::SimControlNode.

Definition at line 205 of file netcontrol.cpp.

References zeitgeist::Object::GetLog(), zeitgeist::Leaf::GetName(), mClients, mNetMessage, mSocket, and RemoveClient().

Here is the call graph for this function:

void NetControl::EndCycle  )  [virtual]
 

called when the current simulation cycle ends

Reimplemented from oxygen::SimControlNode.

Reimplemented in oxygen::AgentControl, and oxygen::MonitorControl.

Definition at line 433 of file netcontrol.cpp.

References CloseDeadConnections().

Referenced by oxygen::MonitorControl::EndCycle(), and oxygen::AgentControl::EndCycle().

Here is the call graph for this function:

rcss::net::Addr::PortType NetControl::GetServerPort  ) 
 

returns the local port, on which connections are accepted

Definition at line 54 of file netcontrol.cpp.

References mLocalAddr.

NetControl::ESocketType NetControl::GetServerType  ) 
 

returns the type of the socket on which connections are accepted

Definition at line 64 of file netcontrol.cpp.

References mSocketType.

void NetControl::InitSimulation  )  [virtual]
 

creates the managed socket, when the simulation starts

Reimplemented from oxygen::SimControlNode.

Definition at line 126 of file netcontrol.cpp.

References zeitgeist::Object::GetClass(), zeitgeist::Object::GetLog(), zeitgeist::Leaf::GetName(), mLocalAddr, mNetMessage, mSocket, mSocketType, and ST_TCP.

Here is the call graph for this function:

static boost::shared_ptr<rcss::net::Socket> oxygen::NetControl::NetControl::CreateSocket ESocketType  type  )  [static]
 

create a socket according to the given ESocketType

std::string oxygen::NetControl::NetControl::DescribeSocketType  )  [protected]
 

returns a human readable description of the socket type and port

void oxygen::NetControl::NetControl::ReadMessages  )  [protected]
 

reads and stores all available messages

void NetControl::ReadTCPMessages  )  [protected]
 

reads and stores all available TCP messages

Definition at line 534 of file netcontrol.cpp.

References zeitgeist::Object::GetLog(), zeitgeist::Leaf::GetName(), mBuffer, mBufferSize, mClients, mCloseClients, and StoreFragment().

Here is the call graph for this function:

void NetControl::ReadUDPMessages  )  [protected]
 

reads and stores all available UDP messages.

UDP fragments from unknown sources generate new client entries

Definition at line 473 of file netcontrol.cpp.

References AddClient(), zeitgeist::Object::GetLog(), zeitgeist::Leaf::GetName(), mBuffer, mBufferSize, mClients, mSocket, and StoreFragment().

Here is the call graph for this function:

void oxygen::NetControl::RemoveClient const rcss::net::Addr &  from  )  [protected]
 

removes a client entry and closes the associated socket.

Parameters:
from is the remote adress of the client.

Referenced by CloseDeadConnections(), and DoneSimulation().

void oxygen::NetControl::SendMessage const rcss::net::Addr &  addr,
const std::string &  msg
 

sends a message to the client with the given address

void oxygen::NetControl::SendMessage boost::shared_ptr< Client client,
const std::string &  msg
 

sends a message to the given client

Referenced by oxygen::MonitorControl::EndCycle(), and oxygen::AgentControl::EndCycle().

void oxygen::NetControl::SetServerPort rcss::net::Addr::PortType  port  ) 
 

sets the local port, on which connections are accepted

void NetControl::SetServerType ESocketType  type  ) 
 

sets the type of the socket on which connections are accepted

Definition at line 59 of file netcontrol.cpp.

References mSocketType.

void NetControl::StartCycle  )  [virtual]
 

called when a new simulation cycle starts, before the simulation is stepped

Reimplemented from oxygen::SimControlNode.

Reimplemented in oxygen::AgentControl, and oxygen::MonitorControl.

Definition at line 423 of file netcontrol.cpp.

References AcceptTCPConnections().

Referenced by oxygen::MonitorControl::StartCycle(), and oxygen::AgentControl::StartCycle().

Here is the call graph for this function:

void oxygen::NetControl::StoreFragment const rcss::net::Addr &  addr,
int  size
[protected]
 

copies the message fragment with length

Parameters:
size currently in the receive buffer to the input queue of the client with the remoted address
addr 

Referenced by ReadTCPMessages(), and ReadUDPMessages().


Member Data Documentation

boost::shared_array<char> oxygen::NetControl::mBuffer [protected]
 

the receive buffer

Definition at line 193 of file netcontrol.h.

Referenced by NetControl(), ReadTCPMessages(), and ReadUDPMessages().

TBufferMap oxygen::NetControl::mBuffers [protected]
 

list of queued messages

Definition at line 187 of file netcontrol.h.

Referenced by oxygen::MonitorControl::StartCycle(), and oxygen::AgentControl::StartCycle().

int oxygen::NetControl::mBufferSize [protected]
 

the size of the allocated receive buffer

Definition at line 190 of file netcontrol.h.

Referenced by NetControl(), ReadTCPMessages(), and ReadUDPMessages().

int oxygen::NetControl::mClientId [protected]
 

the next available unique client id

Definition at line 196 of file netcontrol.h.

Referenced by NetControl().

TAddrMap oxygen::NetControl::mClients [protected]
 

map of known clients, based on remote address

Definition at line 181 of file netcontrol.h.

Referenced by DoneSimulation(), oxygen::MonitorControl::EndCycle(), oxygen::AgentControl::EndCycle(), ReadTCPMessages(), ReadUDPMessages(), and oxygen::AgentControl::StartCycle().

TAddrList oxygen::NetControl::mCloseClients [protected]
 

list of client connections to be closed

Definition at line 184 of file netcontrol.h.

Referenced by CloseDeadConnections(), and ReadTCPMessages().

rcss::net::Addr oxygen::NetControl::mLocalAddr [protected]
 

the local port, on which connections are accepted

Definition at line 172 of file netcontrol.h.

Referenced by oxygen::AgentControl::AgentControl(), GetServerPort(), InitSimulation(), oxygen::MonitorControl::MonitorControl(), and NetControl().

boost::shared_ptr<NetMessage> oxygen::NetControl::mNetMessage [protected]
 

cached reference to the NetMessage child node

Definition at line 169 of file netcontrol.h.

Referenced by DoneSimulation(), oxygen::MonitorControl::EndCycle(), oxygen::AgentControl::EndCycle(), InitSimulation(), oxygen::MonitorControl::StartCycle(), and oxygen::AgentControl::StartCycle().

boost::shared_ptr<rcss::net::Socket> oxygen::NetControl::mSocket [protected]
 

the socket used to accept connections

Definition at line 178 of file netcontrol.h.

Referenced by AcceptTCPConnections(), DoneSimulation(), InitSimulation(), and ReadUDPMessages().

ESocketType oxygen::NetControl::mSocketType [protected]
 

the type of created socket

Definition at line 175 of file netcontrol.h.

Referenced by AcceptTCPConnections(), GetServerType(), InitSimulation(), NetControl(), and SetServerType().


The documentation for this class was generated from the following files:
Generated on Thu Apr 6 15:47:45 2006 for rcssserver3d by  doxygen 1.4.4