#include <connection.h>
Public Member Functions | |
Connection (ConnectorP &) | |
Constructor/destructor. | |
virtual | ~Connection () throw () |
void | shutdown (void) |
Close down a connection. | |
virtual std::string | class_name (void) const |
Sub-class identification strings (abstract virtual). | |
virtual std::string | get_id (void) const =0 |
Protected Member Functions | |
virtual void | start_engine (void)=0 |
virtual void | stop_engine (void)=0 |
Close down the processing engine, if one is running. | |
void | note_disconnect (void) |
Note (to the MasterController) that we've disconnected. | |
Protected Attributes | |
ConnectorP | base |
The underlying Connector. | |
bool | please_exit |
Private Member Functions | |
void | manager (void) |
Connection manager. | |
Static Private Member Functions | |
static void * | manager_thread (void *) |
Wrapper function for the manager() method. | |
Private Attributes | |
pthread_mutex_t | mutex |
Locks the data members of Connection, principally base and conn_state. | |
pthread_t | tid_manager |
The thread-id of the manager() thread. |
This is not much more than an interface, really, but provides the basic functionality, and some code exists to manage connections on a level where we don't need to know the details of their implementation.
Definition at line 89 of file connection.h.
Connection::Connection | ( | ConnectorP & | c | ) |
Constructor/destructor.
Definition at line 52 of file connection.cc.
References manager_thread(), mutex, PTHREAD_CHECK_AND_THROW, and tid_manager.
Connection::~Connection | ( | void | ) | throw () [virtual] |
void * Connection::manager_thread | ( | void * | instance | ) | [static, private] |
Wrapper function for the manager() method.
These wrapper function(s) exist so that class methods may be invoked as new threads via pthread_create(). These need to be static methods, to therefore have "C" name-bindings.
manager_thread() is private because it's [currently] only expected to be called by Connection::Connection.
Definition at line 96 of file connection.cc.
References manager().
Referenced by Connection().
void Connection::manager | ( | void | ) | [private] |
Connection manager.
Manages an established connection. It is responsible for starting threads to manage reading and writing, and expected to continue to run as a thread waiting for messages (and state-changes ?).
Definition at line 110 of file connection.cc.
References base, CATCH_STR_OR_DIE, class_name(), get_id(), Messageable::get_message(), Messageable::handle_message(), mutex, MUTEX_LOG, note_disconnect(), please_exit, PTHREAD_CHECK_AND_THROW, shutdown(), start_engine(), stop_engine(), and CMException::what().
Referenced by manager_thread().
void Connection::shutdown | ( | void | ) |
Close down a connection.
Shutdown an existing (possibly established) connection.
This calls virtual methods which will know the details for shutting down each type of connection.
Definition at line 389 of file connection.cc.
References Message::C_None, CATCH_OR_DIE, get_id(), please_exit, Messageable::queue_message(), and stop_engine().
Referenced by Messageable::handle_message(), and manager().
virtual void Connection::start_engine | ( | void | ) | [protected, pure virtual] |
virtual void Connection::stop_engine | ( | void | ) | [protected, pure virtual] |
Close down the processing engine, if one is running.
Implemented in BiDirConn, and Outlet.
Referenced by manager(), and shutdown().
virtual std::string Connection::class_name | ( | void | ) | const [inline, virtual] |
Sub-class identification strings (abstract virtual).
Reimplemented in BiDirConn, and Outlet.
Definition at line 160 of file connection.h.
Referenced by manager().
virtual std::string Connection::get_id | ( | void | ) | const [pure virtual] |
Implements Messageable.
Implemented in BiDirConn, and Outlet.
Referenced by manager(), and shutdown().
void Connection::note_disconnect | ( | void | ) | [protected] |
Note (to the MasterController) that we've disconnected.
Note our disconnection to the MasterController.
Set our own state to disconnected (if we're tracking our state), and send a message to the MasterController telling it we're disconnected. It will call our reconnect() method, or shut us down, or any such other thing depending on its desires.
Definition at line 300 of file connection.cc.
References Message::C_Disconnected, MasterController::get_instance(), and Messageable::queue_message().
Referenced by manager(), BiDirConn::reader(), and Outlet::write_data().
ConnectorP Connection::base [protected] |
The underlying Connector.
Definition at line 168 of file connection.h.
Referenced by Outlet::get_id(), BiDirConn::get_id(), manager(), BiDirConn::reader(), BiDirConn::stop_engine(), and Outlet::write_data().
bool Connection::please_exit [protected] |
A variable set true by stop_engine and/or shutdown, so that manager() knows to go away.
Definition at line 175 of file connection.h.
Referenced by manager(), shutdown(), and Outlet::writer().
pthread_mutex_t Connection::mutex [private] |
Locks the data members of Connection, principally base and conn_state.
Definition at line 179 of file connection.h.
Referenced by Connection(), manager(), BiDirConn::~BiDirConn(), ~Connection(), and Outlet::~Outlet().
pthread_t Connection::tid_manager [private] |
The thread-id of the manager() thread.
Definition at line 188 of file connection.h.
Referenced by Connection().