S3FC project page S3FC home page

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

s3_txport_local Class Template Reference

Local (inter-thread) transport mechanism. More...

#include <s3_txport_local.h>

Inheritance diagram for s3_txport_local:

Inheritance graph
[legend]
Collaboration diagram for s3_txport_local:

Collaboration graph
[legend]
List of all members.

Public Methods

 s3_txport_local (unsigned int queue_size=4)
 Constructor. More...

 ~s3_txport_local ()
 Destructor. More...

s3_fifo_queue< s3_txport_data<
T_Data > > & 
get_tx_queue ()
 Return a reference to a s3_fifo_queue specialised on the s3_txport_data for the transmit data queue. More...

s3_fifo_queue< s3_txport_data<
T_Data > > & 
get_rx_queue ()
 Return a reference to a s3_fifo_queue specialised on the s3_txport_data for the received data queue. More...

std::list< s3_txport_client_idget_client_id_list () const
 Returns a list of all currently connected clients. More...

void send_metadata (s3_txport_client_id id, const std::string &metadata)
 Transmit metadata to the remote connection. More...

bool is_connected_by_id (s3_txport_client_id id)
 Returns true if the client is still considered to be active. More...

bool disconnect_by_id (s3_txport_client_id id)
 Disconnect the indicated remote connection. More...

void disconnect_all ()
 Disconnect all clients, regardless, but keep the listener etc. alive. More...

bool listening () const
 Returns true if the server is listening for connections. More...

s3_txport_client_id connect (s3_txport_local< T_Data > *listener)
 Make a connection to a s3_txport_local listener. More...

bool listen ()
 Set up a listener (effectively a switch) to which other s3_txports_local can connect. More...

void main_loop ()
 Function that is invoked as the main loop in its own thread. More...

int num_connections () const
 returns the current number of connections. More...


Private Types

typedef std::map< s3_txport_client_id,
s3_txport_local< T_Data > * > 
c_map
 Type to mutually map txports to each other. More...


Private Methods

s3_txport_local * register_me (s3_txport_local *remote)
 Register this transport with the remote transport. More...

void deregister_me (const s3_txport_local *remote)
 Deregister an instance of a local transport with this instance. More...

s3_txport_client_id next_id ()
 Increment the connection id. It is always non-zero for valid connections. More...

void cleanup ()
 Code to clean up if the thread. More...


Private Attributes

s3_fifo_queue< s3_txport_data<
T_Data > > 
rx_queue
 Queue from which the data will be read. More...

s3_fifo_queue< s3_txport_data<
T_Data > > 
tx_queue
 Queue in which to write data to be sent to a client. More...

s3_semaphore terminate
 Post to this to terminate the listener thread. More...

s3_semaphore sem
 Semaphore used to signal various activities. More...

s3_txport_client_id connect_id
 Counter to ensure unique connection IDs. More...

c_map connections
 Map the client connection ID to the client's queue. More...

s3_periodic_notifier pn
 Blipper to keep the listener thread from blocking. More...

s3_mutex connection_mutex
 Static state mutex to protect the connection structure. More...


Detailed Description

template<class T_Data>
class s3_txport_local< T_Data >

Local (inter-thread) transport mechanism.

This class allows threads to connect to each other via queues, in a similar fasion to the tcp transports. Individual transports are able to connect to each other and to set up listeners, analogous to servers. It behaves in the same way as the s3_txport_tcp class.

Definition at line 52 of file s3_txport_local.h.


Member Typedef Documentation

template<class T_Data>
typedef std::map<s3_txport_client_id, s3_txport_local<T_Data>* > s3_txport_local::c_map [private]
 

Type to mutually map txports to each other.

Definition at line 70 of file s3_txport_local.h.


Constructor & Destructor Documentation

template<class T_Data>
s3_txport_local< T_Data >::s3_txport_local unsigned int    queue_size = 4
 

Constructor.

Parameters:
queue_size  The size of the local queue

Definition at line 33 of file s3_txport_local.tcc.

References s3_thread_base::start.

template<class T_Data>
s3_txport_local< T_Data >::~s3_txport_local  
 

Destructor.

Definition at line 40 of file s3_txport_local.tcc.

References disconnect_all, s3_thread_base::is_running, s3_semaphore::post, terminate, and s3_thread_base::wait_on_exit.


Member Function Documentation

template<class T_Data>
void s3_txport_local< T_Data >::cleanup   [private, virtual]
 

Code to clean up if the thread.

Reimplemented from s3_thread_base.

Definition at line 238 of file s3_txport_local.tcc.

References s3_periodic_notifier::disable, pn, S3FC_DBG, sem, tx_queue, and s3_periodic_notifier::unsubscribe.

template<class T_Data>
s3_txport_client_id s3_txport_local< T_Data >::connect s3_txport_local< T_Data > *    listener
 

Make a connection to a s3_txport_local listener.

Currently, only one connection is allowed per pair of transports. The connection will fail if you are already talking to the desitination. This behavior may change in the future.

Parameters:
listener  A s3_txport_local that is listening
Returns:
A valid conneciton ID client id or 0 if a connection could not be made.

Definition at line 146 of file s3_txport_local.tcc.

References s3_txport_event::connect, connection_mutex, connections, s3_event_dispatcher< s3_txport_event >::dispatch_event, s3_txport_event::error, s3_mutex::lock, next_id, register_me, s3_txport_client_id, and s3_mutex::unlock.

template<class T_Data>
void s3_txport_local< T_Data >::deregister_me const s3_txport_local< T_Data > *    remote [private]
 

Deregister an instance of a local transport with this instance.

Parameters:
remote  pointer to the remote instance we are to talk to

Definition at line 205 of file s3_txport_local.tcc.

References connection_mutex, connections, s3_txport_event::disconnect, s3_event_dispatcher< s3_txport_event >::dispatch_event, s3_mutex::lock, and s3_mutex::unlock.

template<class T_Data>
void s3_txport_local< T_Data >::disconnect_all   [virtual]
 

Disconnect all clients, regardless, but keep the listener etc. alive.

Implements s3_txport_base.

Definition at line 125 of file s3_txport_local.tcc.

References connections, and disconnect_by_id.

Referenced by ~s3_txport_local.

template<class T_Data>
bool s3_txport_local< T_Data >::disconnect_by_id s3_txport_client_id    id [virtual]
 

Disconnect the indicated remote connection.

Parameters:
The  ID of the remote to be disconnected.

Implements s3_txport_base.

Definition at line 103 of file s3_txport_local.tcc.

References connection_mutex, connections, s3_txport_event::disconnect, s3_event_dispatcher< s3_txport_event >::dispatch_event, s3_mutex::lock, s3_txport_client_id, and s3_mutex::unlock.

Referenced by disconnect_all.

template<class T_Data>
std::list< s3_txport_client_id > s3_txport_local< T_Data >::get_client_id_list   const [virtual]
 

Returns a list of all currently connected clients.

Note that this list reflects the situation at the time of the call, and there is no guarantee that all the clients in the list are connected. Messages to unconnected clients are simply driopped.

Implements s3_txport_base.

Definition at line 64 of file s3_txport_local.tcc.

References connection_mutex, connections, s3_mutex::lock, and s3_mutex::unlock.

template<class T_Data>
s3_fifo_queue< s3_txport_data< T_Data > > & s3_txport_local< T_Data >::get_rx_queue   [virtual]
 

Return a reference to a s3_fifo_queue specialised on the s3_txport_data for the received data queue.

Implements s3_txport_base.

Definition at line 57 of file s3_txport_local.tcc.

References rx_queue.

template<class T_Data>
s3_fifo_queue< s3_txport_data< T_Data > > & s3_txport_local< T_Data >::get_tx_queue   [virtual]
 

Return a reference to a s3_fifo_queue specialised on the s3_txport_data for the transmit data queue.

Implements s3_txport_base.

Definition at line 51 of file s3_txport_local.tcc.

References tx_queue.

template<class T_Data>
bool s3_txport_local< T_Data >::is_connected_by_id s3_txport_client_id    id [virtual]
 

Returns true if the client is still considered to be active.

Implements s3_txport_base.

Definition at line 93 of file s3_txport_local.tcc.

References connection_mutex, connections, s3_mutex::lock, s3_txport_client_id, and s3_mutex::unlock.

template<class T_Data>
bool s3_txport_local< T_Data >::listen  
 

Set up a listener (effectively a switch) to which other s3_txports_local can connect.

Returns:
true if the listener was set up successully.

Definition at line 232 of file s3_txport_local.tcc.

template<class T_Data>
bool s3_txport_local< T_Data >::listening   const [virtual]
 

Returns true if the server is listening for connections.

Implements s3_txport_base.

Definition at line 140 of file s3_txport_local.tcc.

References s3_thread_base::is_running.

template<class T_Data>
void s3_txport_local< T_Data >::main_loop   [virtual]
 

Function that is invoked as the main loop in its own thread.

Override this in derived class.

Note:
This is to become pure virtual once the older void* main_loop(void*) is dropped entirely.

Implements s3_thread_base.

Definition at line 248 of file s3_txport_local.tcc.

References s3_fifo_queue< s3_txport_data< T_Data > >::close_output, connection_mutex, connections, s3_event_dispatcher< s3_txport_event >::dispatch_event, s3_periodic_notifier::enable, s3_txport_event::error, s3_mutex::lock, s3_fifo_queue< s3_txport_data< T_Data > >::nbl_open_output, pn, sem, s3_periodic_notifier::subscribe, terminate, s3_semaphore::try_wait, tx_queue, s3_mutex::unlock, and s3_semaphore::wait.

template<class T_Data>
s3_txport_client_id s3_txport_local< T_Data >::next_id   [inline, private]
 

Increment the connection id. It is always non-zero for valid connections.

Definition at line 96 of file s3_txport_local.h.

References connect_id, and s3_txport_client_id.

Referenced by connect, and register_me.

template<class T_Data>
int s3_txport_local< T_Data >::num_connections   const
 

returns the current number of connections.

Definition at line 292 of file s3_txport_local.tcc.

References connection_mutex, connections, s3_mutex::lock, and s3_mutex::unlock.

template<class T_Data>
s3_txport_local< T_Data > * s3_txport_local< T_Data >::register_me s3_txport_local< T_Data > *    remote [private]
 

Register this transport with the remote transport.

Parameters:
remote  pointer to the remote instance we are to talk to
Returns:
a pointer to this instance if we have been registered, or 0 if we are already registered.

Definition at line 173 of file s3_txport_local.tcc.

References s3_txport_event::connect, connection_mutex, connections, s3_event_dispatcher< s3_txport_event >::dispatch_event, s3_txport_event::error, s3_mutex::lock, next_id, s3_txport_client_id, and s3_mutex::unlock.

Referenced by connect.

template<class T_Data>
void s3_txport_local< T_Data >::send_metadata s3_txport_client_id    id,
const std::string &    metadata
[virtual]
 

Transmit metadata to the remote connection.

The metadata will be dispatched to any s3_event_handler types attached to the s3_txport_base.

Parameters:
id  The ID of the remote client to whom the metadata must be sent
metadata  A string of metadata payload.

Implements s3_txport_base.

Definition at line 78 of file s3_txport_local.tcc.

References connection_mutex, connections, s3_mutex::lock, s3_txport_event::metadata, s3_txport_client_id, and s3_mutex::unlock.


Member Data Documentation

template<class T_Data>
s3_txport_client_id s3_txport_local::connect_id [private]
 

Counter to ensure unique connection IDs.

Definition at line 67 of file s3_txport_local.h.

Referenced by next_id.

template<class T_Data>
s3_mutex s3_txport_local::connection_mutex [private]
 

Static state mutex to protect the connection structure.

Definition at line 79 of file s3_txport_local.h.

Referenced by connect, deregister_me, disconnect_by_id, get_client_id_list, is_connected_by_id, main_loop, num_connections, register_me, and send_metadata.

template<class T_Data>
c_map s3_txport_local::connections [private]
 

Map the client connection ID to the client's queue.

Definition at line 73 of file s3_txport_local.h.

Referenced by connect, deregister_me, disconnect_all, disconnect_by_id, get_client_id_list, is_connected_by_id, main_loop, num_connections, register_me, and send_metadata.

template<class T_Data>
s3_periodic_notifier s3_txport_local::pn [private]
 

Blipper to keep the listener thread from blocking.

Definition at line 76 of file s3_txport_local.h.

Referenced by cleanup, and main_loop.

template<class T_Data>
s3_fifo_queue<s3_txport_data<T_Data> > s3_txport_local::rx_queue [private]
 

Queue from which the data will be read.

Definition at line 55 of file s3_txport_local.h.

Referenced by get_rx_queue.

template<class T_Data>
s3_semaphore s3_txport_local::sem [private]
 

Semaphore used to signal various activities.

Definition at line 64 of file s3_txport_local.h.

Referenced by cleanup, and main_loop.

template<class T_Data>
s3_semaphore s3_txport_local::terminate [private]
 

Post to this to terminate the listener thread.

Definition at line 61 of file s3_txport_local.h.

Referenced by main_loop, and ~s3_txport_local.

template<class T_Data>
s3_fifo_queue<s3_txport_data<T_Data> > s3_txport_local::tx_queue [private]
 

Queue in which to write data to be sent to a client.

Definition at line 58 of file s3_txport_local.h.

Referenced by cleanup, get_tx_queue, and main_loop.


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