S3FC project page | S3FC home page |
#include <s3_message.h>
Collaboration diagram for s3_message_box:
Public Types | |
typedef std::list< s3_message > | T_RX_Queue |
Public Methods | |
s3_message_box (const std::string &name="", unsigned int n_queue_len=20) | |
Construct a new message box instance with specified name and rx_queue length. More... | |
~s3_message_box () | |
Disconnect message box from post office. More... | |
void | set_name (const std::string &name) |
Set the name of this s3_message_client instance. More... | |
void | connect () |
Connect to and register with the post office. More... | |
void | disconnect () |
Disconnect and unregister from the post_office. More... | |
void | subscribe_group (const std::string &group) |
Subscribe this message box to the specified group. More... | |
void | unsubscribe_group (const std::string &group) |
Unsubscribe this message box from the specified group. More... | |
void | subscribe_arrival (const s3_semaphore &sem) |
Subscribe the supplied semaphore to the arrival notification list. More... | |
s3_message::msg_id_t | send_msg (const std::string &dst, const std::string &body, bool priority=false) |
Send a message to the specified destination. More... | |
s3_message::msg_id_t | reply_msg (const s3_message &msg, const std::string &body="") |
Send a reply message. More... | |
s3_message | get_msg () |
Retrieve and remove the candidate message from the queue. More... | |
Static Public Methods | |
void | init (const std::string &ip_addr, int port) |
Initialise the postal system. More... | |
void | de_init () |
De-initialise the postal system - stop the post office active in the current process space. More... | |
bool | initialised () |
Return the initialisation status. More... | |
Static Public Attributes | |
unsigned int | dropped_msg_count = 0 |
This counter keeps track of how many messages have been dropped in this process space. More... | |
Protected Methods | |
void | deliver_msg (const s3_message &msg) |
Add a message into the queue. More... | |
std::string | err_str (const std::string &err) |
Return an error string containing the message box name. More... | |
std::string | get_next_message_id () |
Return the next message id in the sequence. More... | |
Private Attributes | |
bool | connected |
Flag indicating whether a connection to a post office exists. More... | |
std::string | name |
Name of this message box. More... | |
unsigned int | rx_queue_len |
Queue lengths (RX and TX). More... | |
T_RX_Queue | rx_queue |
RX queue - finite length is implemented in deliver_msg. More... | |
std::list< std::string > | subscription_list |
Group subscription list. More... | |
int | seq_nr |
Sequence count used to generate message IDs. More... | |
std::list< s3_semaphore * > | arrival_notification_list |
Everybody in list is notified if message is received. More... | |
s3_mutex | state_lock |
Global lock ensures state consistency. More... | |
Static Private Attributes | |
s3_post_office * | poffice = 0 |
Post office instance - the post office that we use. More... | |
Friends | |
class | s3_post_office |
name
is implemented as a string
. The rx_queue
is implemented by an STL list
containing s3_message
objects. An internal parameter contains the maximum size that the list may attain. s3_post_office
is declared as a friend class, in order to make use of the delivery mechanism. Each sent message is tagged with a message ID, that is a string consisting of the name of the message_box and a sequence number. This ID should be used in calls to s3_message::is_reply()
.
@note: This implementation is not intended to be used as a communication endpoint by more than one thread at the same time.
Definition at line 513 of file s3_message.h.
|
Definition at line 518 of file s3_message.h. |
|
Construct a new message box instance with specified
Definition at line 203 of file s3_message.cc. |
|
Disconnect message box from post office.
Definition at line 215 of file s3_message.cc. References disconnect. |
|
Connect to and register with the post office.
Throw an
Definition at line 292 of file s3_message.cc. References s3_post_office::add_dst, connected, err_str, name, and poffice. Referenced by s3_msgb_log_buffer::s3_msgb_log_buffer, s3_msgb_log_rx_thread::s3_msgb_log_rx_thread, s3_rpc_client::s3_rpc_client, and s3_rpc_server::s3_rpc_server. |
|
De-initialise the postal system - stop the post office active in the current process space.
Definition at line 254 of file s3_message.cc. References s3_post_office::disconnect, initialised, poffice, s3_thread_base::request_terminate, and s3_thread_base::wait_on_exit. |
|
Add a message into the queue. If the message queue is full, the oldest non-priority message is removed, unless there are only priority messages in the queue, in which case it removes the oldest priority message. Definition at line 451 of file s3_message.cc. References arrival_notification_list, dropped_msg_count, s3_message::get_class, s3_mutex::lock, s3_message::NORMAL, s3_message::PRIORITY, rx_queue, rx_queue_len, state_lock, and s3_mutex::unlock. |
|
Disconnect and unregister from the post_office.
Throw an Definition at line 312 of file s3_message.cc. References connected, err_str, name, poffice, s3_post_office::remove_dst, subscription_list, and unsubscribe_group. Referenced by ~s3_message_box, s3_msgb_log_buffer::~s3_msgb_log_buffer, s3_msgb_log_rx_thread::~s3_msgb_log_rx_thread, s3_rpc_client::~s3_rpc_client, and s3_rpc_server::~s3_rpc_server. |
|
Return an error string containing the message box name.
Definition at line 529 of file s3_message.cc. References name. Referenced by connect, disconnect, send_msg, set_name, subscribe_arrival, subscribe_group, and unsubscribe_group. |
|
Retrieve and remove the candidate message from the queue. If there are no messages in the queue, an empty message is returned. Definition at line 427 of file s3_message.cc. References s3_mutex::lock, rx_queue, state_lock, and s3_mutex::unlock. Referenced by s3_rpc_server::main_loop, and s3_msgb_log_rx_thread::main_loop. |
|
Return the next message id in the sequence.
Definition at line 538 of file s3_message.cc. |
|
Initialise the postal system. This should be called exactly once in every process space, before any message boxes is instantiated.
Definition at line 225 of file s3_message.cc. References s3_post_office::connect, initialised, poffice, and s3_post_office. Referenced by s3_msgb_log_buffer::s3_msgb_log_buffer, and s3_msgb_log_rx_thread::s3_msgb_log_rx_thread. |
|
Return the initialisation status.
The status is Definition at line 271 of file s3_message.cc. References s3_post_office::is_connected, poffice, and S3FC_DBG. Referenced by de_init, init, s3_msgb_log_buffer::s3_msgb_log_buffer, and s3_msgb_log_rx_thread::s3_msgb_log_rx_thread. |
|
Send a reply message.
This is similar to sending an ordinary message, except that the destination address and priority are taken from
Definition at line 415 of file s3_message.cc. References s3_post_office::dispatch_msg, get_next_message_id, s3_message::msg_id_t, name, and poffice. Referenced by s3_rpc_server::reply_client. |
|
Send a message to the specified destination. A priority message is sent if the priority flag is set.
Definition at line 396 of file s3_message.cc. References connected, s3_post_office::dispatch_msg, err_str, get_next_message_id, s3_message::msg_id_t, name, s3_message::NORMAL, poffice, and s3_message::PRIORITY. Referenced by s3_rpc_client::call_common, and s3_msgb_log_buffer::write_to_device. |
|
Set the name of this
Throw an
Definition at line 281 of file s3_message.cc. Referenced by s3_msgb_log_buffer::s3_msgb_log_buffer, s3_rpc_client::s3_rpc_client, and s3_rpc_server::s3_rpc_server. |
|
Subscribe the supplied semaphore to the arrival notification list.
Definition at line 379 of file s3_message.cc. References arrival_notification_list, and err_str. Referenced by s3_rpc_server::main_loop, and s3_msgb_log_rx_thread::s3_msgb_log_rx_thread. |
|
Subscribe this message box to the specified group.
Throw an
Definition at line 331 of file s3_message.cc. References s3_post_office::add_dst, connected, err_str, poffice, and subscription_list. |
|
Unsubscribe this message box from the specified group.
Throw an
Definition at line 356 of file s3_message.cc. References connected, err_str, poffice, s3_post_office::remove_dst, and subscription_list. Referenced by disconnect. |
|
Definition at line 516 of file s3_message.h. Referenced by init. |
|
Everybody in list is notified if message is received.
Definition at line 559 of file s3_message.h. Referenced by deliver_msg, and subscribe_arrival. |
|
Flag indicating whether a connection to a post office exists.
Definition at line 535 of file s3_message.h. Referenced by connect, disconnect, send_msg, subscribe_group, and unsubscribe_group. |
|
This counter keeps track of how many messages have been dropped in this process space.
Definition at line 200 of file s3_message.cc. Referenced by deliver_msg. |
|
Name of this message box.
Definition at line 539 of file s3_message.h. Referenced by connect, disconnect, err_str, get_next_message_id, reply_msg, send_msg, and set_name. |
|
Post office instance - the post office that we use. All messages boxes in a process space share the post office, so we set this to point to a global instance. The post office is created by init() Definition at line 199 of file s3_message.cc. Referenced by connect, de_init, disconnect, init, initialised, reply_msg, send_msg, subscribe_group, and unsubscribe_group. |
|
RX queue - finite length is implemented in deliver_msg.
Definition at line 547 of file s3_message.h. Referenced by deliver_msg, and get_msg. |
|
Queue lengths (RX and TX).
Definition at line 543 of file s3_message.h. Referenced by deliver_msg. |
|
Sequence count used to generate message IDs.
Definition at line 555 of file s3_message.h. Referenced by get_next_message_id. |
|
Global lock ensures state consistency.
Definition at line 563 of file s3_message.h. Referenced by deliver_msg, and get_msg. |
|
Group subscription list.
Definition at line 551 of file s3_message.h. Referenced by disconnect, subscribe_group, and unsubscribe_group. |
Send comments to: s3fc@stonethree.com |
|