S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_post_office_switch Class Reference

An implementation of Post Office Switch. More...

#include <s3_message.h>

Inheritance diagram for s3_post_office_switch:

Inheritance graph
[legend]
Collaboration diagram for s3_post_office_switch:

Collaboration graph
[legend]
List of all members.

Public Methods

 s3_post_office_switch (int n_port)
 Construct an instance with the specified port number, and immediately start accepting connections. More...

virtual ~s3_post_office_switch ()
virtual void main_loop ()
 Main event loop: poll the incoming transport queue for new packets. More...


Protected Methods

bool add_dst (const std::string &dst, client_id_t client, bool is_group)
 Implement the add_dst operation. More...

bool remove_dst (const std::string &dst, client_id_t client, bool is_group)
 Implement the remove_dst operation. More...

void remove_client (client_id_t client)
 Remove the specified client from all client lists. More...

void reply_success (const s3_txport_data< s3_message > &packet)
 Send a "success" reply in response to a message. More...

void reply_failure (const s3_txport_data< s3_message > &packet)
 Send a "failure" reply in response to a message. More...

void forward_msg (const s3_message &msg, const client_id_t client)
 Forward a message to a client. More...

void log_msg (const std::string &where, const std::string &what)
 Log a message. More...

std::string get_next_message_id ()
 Return the next message id in the sequence. More...

void handle_transport_events ()
 Handle all the pending transport events. More...


Private Types

typedef s3_txport_client_id client_id_t
 Type of thing used to identify connected clients. More...

typedef s3_fifo_queue< s3_txport_data<
s3_message > > 
queue_t

Private Attributes

s3_txport_tcp< s3_message > * conn
 Physical (TCP/IP) connection endpoint that maintains a client connection list.. More...

txp_event_queuer txp_event_queuer
 Event handler that pushes transport events into the event queue. More...

std::map< std::string, dst_datadst_map
 Map from destination (strings) to clients id and type. More...

int seq_nr
 Sequence count used to generate message IDs. More...

s3_semaphore started
 Semaphore used to synchronise startup. More...


Friends

struct dst_data

Detailed Description

An implementation of Post Office Switch.

The TCP/IP network link is implemented by a s3_txport_tcp<s3_message> instance operating as a server (i.e. listening).

See also:
Postal System

Definition at line 908 of file s3_message.h.


Member Typedef Documentation

typedef s3_txport_client_id s3_post_office_switch::client_id_t [private]
 

Type of thing used to identify connected clients.

We use the type that is supplied by the transport.

Definition at line 940 of file s3_message.h.

Referenced by main_loop.

typedef s3_fifo_queue<s3_txport_data<s3_message> > s3_post_office_switch::queue_t [private]
 

Definition at line 958 of file s3_message.h.


Constructor & Destructor Documentation

s3_post_office_switch::s3_post_office_switch int    n_port
 

Construct an instance with the specified port number, and immediately start accepting connections.

Only return once the switch is up and running.

Parameters:
n_port  Port at which to listen.

Definition at line 1096 of file s3_message.cc.

References conn, s3_txport_tcp< s3_message >::listen, s3_txport_tcp< s3_message >::listening, seq_nr, s3_thread_base::start, started, s3_event_dispatcher< s3_txport_event >::subscribe_handler, txp_event_queuer, and s3_semaphore::wait.

s3_post_office_switch::~s3_post_office_switch   [virtual]
 

Definition at line 1128 of file s3_message.cc.

References conn, s3_thread_base::is_running, s3_thread_base::request_terminate, s3_txport_tcp< s3_message >::stop, and s3_thread_base::wait_on_exit.


Member Function Documentation

bool s3_post_office_switch::add_dst const std::string &    dst,
client_id_t    client,
bool    is_group
[protected]
 

Implement the add_dst operation.

Parameters:
dst  Destination name.
client  Client ID.
group  Is destination a group ?

Definition at line 1324 of file s3_message.cc.

References dst_data, dst_map, and log_msg.

Referenced by main_loop.

void s3_post_office_switch::forward_msg const s3_message   msg,
const client_id_t    client
[protected]
 

Forward a message to a client.

Parameters:
msg  Message.
client  Client id.

Definition at line 1487 of file s3_message.cc.

References conn, s3_message::get_debug_str, s3_txport_tcp< s3_message >::get_tx_queue, and S3FC_DBG.

Referenced by main_loop, reply_failure, and reply_success.

std::string s3_post_office_switch::get_next_message_id   [protected]
 

Return the next message id in the sequence.

Definition at line 1506 of file s3_message.cc.

References seq_nr.

Referenced by reply_failure, and reply_success.

void s3_post_office_switch::handle_transport_events   [protected]
 

Handle all the pending transport events.

Definition at line 1514 of file s3_message.cc.

References s3_txport_event::disconnect, s3_post_office_switch::txp_event_queuer::ev_queue, s3_txport_event::event, s3_txport_event::id, remove_client, and txp_event_queuer.

Referenced by main_loop.

void s3_post_office_switch::log_msg const std::string &    where,
const std::string &    what
[protected]
 

Log a message.

Parameters:
where  Function name where the error occured.
what  Error string

Definition at line 1498 of file s3_message.cc.

Referenced by add_dst, main_loop, and remove_dst.

void s3_post_office_switch::main_loop   [virtual]
 

Main event loop: poll the incoming transport queue for new packets.

A received packet is forwarded to all connections, except the one on which it originated.

Implements s3_thread_base.

Definition at line 1140 of file s3_message.cc.

References add_dst, client_id_t, conn, s3_message::CONTROL, s3_txport_data::data, s3_periodic_notifier::disable, dst_map, s3_fifo_queue< s3_txport_data< s3_message > >::empty, s3_periodic_notifier::enable, s3_post_office_switch::txp_event_queuer::ev_queue, forward_msg, s3_txport_data::get_id, s3_txport_tcp< s3_message >::get_rx_queue, handle_transport_events, s3_txport_tcp< s3_message >::listening, s3_thread_base::lock_state, log_msg, s3_semaphore::post, remove_dst, reply_failure, reply_success, S3FC_DBG, started, s3_conversion::string_to_vec_string, s3_periodic_notifier::subscribe, s3_thread_base::test_terminate, txp_event_queuer, s3_thread_base::unlock_state, s3_periodic_notifier::unsubscribe, and s3_semaphore::wait.

void s3_post_office_switch::remove_client client_id_t    client [protected]
 

Remove the specified client from all client lists.

If this leaves the client list of destination empty, the destination is removed from the destination type.

Parameters:
client  Client to remove.

Definition at line 1434 of file s3_message.cc.

References dst_map.

Referenced by handle_transport_events.

bool s3_post_office_switch::remove_dst const std::string &    dst,
client_id_t    client,
bool    is_group
[protected]
 

Implement the remove_dst operation.

Parameters:
dst  Destination name.
client  Client ID.
group  Is destination a group ?

Definition at line 1380 of file s3_message.cc.

References dst_map, and log_msg.

Referenced by main_loop.

void s3_post_office_switch::reply_failure const s3_txport_data< s3_message > &    packet [protected]
 

Send a "failure" reply in response to a message.

Parameters:
packet  The packet containing original message.

Definition at line 1476 of file s3_message.cc.

References s3_txport_data::data, forward_msg, s3_txport_data::get_id, and get_next_message_id.

Referenced by main_loop.

void s3_post_office_switch::reply_success const s3_txport_data< s3_message > &    packet [protected]
 

Send a "success" reply in response to a message.

Parameters:
packet  The packet containing original message.

Definition at line 1464 of file s3_message.cc.

References s3_txport_data::data, forward_msg, s3_txport_data::get_id, and get_next_message_id.

Referenced by main_loop.


Friends And Related Function Documentation

friend struct dst_data [friend]
 

Definition at line 943 of file s3_message.h.

Referenced by add_dst.


Member Data Documentation

s3_txport_tcp<s3_message>* s3_post_office_switch::conn [private]
 

Physical (TCP/IP) connection endpoint that maintains a client connection list..

Definition at line 966 of file s3_message.h.

Referenced by forward_msg, main_loop, s3_post_office_switch, and ~s3_post_office_switch.

std::map<std::string, dst_data> s3_post_office_switch::dst_map [private]
 

Map from destination (strings) to clients id and type.

This is the destination registry. Packets can only be routed to destinations that appear in this map. Group destinations can have many clients, but individual destinations may only have a single client. This control is implemented in add_dst() and remove_dst(). This doesn't require a separate lock as in the case of the post_office, as only a single thread access it at any given time.

Definition at line 981 of file s3_message.h.

Referenced by add_dst, main_loop, remove_client, and remove_dst.

int s3_post_office_switch::seq_nr [private]
 

Sequence count used to generate message IDs.

Definition at line 985 of file s3_message.h.

Referenced by get_next_message_id, and s3_post_office_switch.

s3_semaphore s3_post_office_switch::started [private]
 

Semaphore used to synchronise startup.

Reimplemented from s3_thread_base.

Definition at line 989 of file s3_message.h.

Referenced by main_loop, and s3_post_office_switch.

txp_event_queuer s3_post_office_switch::txp_event_queuer [private]
 

Event handler that pushes transport events into the event queue.

Definition at line 971 of file s3_message.h.

Referenced by handle_transport_events, main_loop, and s3_post_office_switch.


The documentation for this class was generated from the following files:
Send comments to: s3fc@stonethree.com SourceForge Logo