#include <mastercont.h>
Public Member Functions | |
std::string | get_id (void) const |
Static Public Member Functions | |
static void | run (ConfigP &config, bool server=false) |
static MasterController * | get_instance () |
Protected Member Functions | |
MasterController (ConfigP &config, bool server) | |
~MasterController () | |
Private Member Functions | |
void | manage_connections () |
void | start_connections () |
void | destroy_children (void) |
This function is in the wrong place and does the wrong thing. | |
void | block_signals () |
Block all signals. Call this method before starting up threads. | |
void | handle_signals () |
int | wait_for_signal () |
Static Private Member Functions | |
static void * | signal_handler_thread (void *) |
The thread-head function for handling signals. | |
Private Attributes | |
sigset_t | all |
State needed by the signal blocking/receiving methods. | |
sigset_t | prev |
ConfigP | config |
The configuration we're using. | |
bool | server |
Static Private Attributes | |
static MasterController * | single_instance = NULL |
Our singleton instance. |
Definition at line 67 of file mastercont.h.
MasterController::MasterController | ( | ConfigP & | config, | |
bool | server | |||
) | [protected] |
Definition at line 67 of file mastercont.cc.
Referenced by run().
MasterController::~MasterController | ( | void | ) | [protected] |
Definition at line 72 of file mastercont.cc.
void MasterController::run | ( | ConfigP & | config, | |
bool | server = false | |||
) | [static] |
This is the main method that you run in order to start the MasterController doing its job. This method will not return until the MasterController has shut itself down, which is typically followed immediately by program termination. The config argument is the configuration that the MasterController should use to determine which Connections to bring up and how to connect them.
Definition at line 95 of file mastercont.cc.
References block_signals(), manage_connections(), MasterController(), PTHREAD_CHECK_AND_THROW, signal_handler_thread(), and single_instance.
Referenced by main().
MasterController * MasterController::get_instance | ( | ) | [static] |
Returns the singleton MasterController instance. It is not appropriate to call this method while the the run() method is not currently executing, so this doesn't exactly follow the typical Singleton design pattern. (An exception will be thrown if you attempt to call this method when the MasterController is not running.)
Definition at line 138 of file mastercont.cc.
References single_instance.
Referenced by Incoming::listener_thread(), and Connection::note_disconnect().
std::string MasterController::get_id | ( | void | ) | const [virtual] |
void MasterController::manage_connections | ( | ) | [private] |
Manage starting, connecting, and listening for Messages from our Connection and Listener objects.
Definition at line 149 of file mastercont.cc.
References Message::C_Disconnected, Message::C_Exit, destroy_children(), Messageable::get_message(), Message::M_Command, server, start_connections(), and CMException::what().
Referenced by run().
void MasterController::start_connections | ( | ) | [private] |
Definition at line 213 of file mastercont.cc.
References Messager::add_recipient(), build_addr(), CATCH_OR_DIE, CATCH_STR_OR_DIE, config, CONNECT_TO_ONE, BiDirConn::get_id(), Incoming::get_id(), HISTORY, Messager::recipients, server, and CMException::what().
Referenced by manage_connections().
void MasterController::destroy_children | ( | void | ) | [private] |
This function is in the wrong place and does the wrong thing.
It knows about internals of Messager, and is basically using the list of recipients held in Messager as a list of child objects that we're managing. These should not be blurred like this...
Definition at line 409 of file mastercont.cc.
References Messager::recip_mutex, and Messager::recipients.
Referenced by manage_connections().
void * MasterController::signal_handler_thread | ( | void * | instance | ) | [static, private] |
The thread-head function for handling signals.
Definition at line 433 of file mastercont.cc.
References handle_signals().
Referenced by run().
void MasterController::block_signals | ( | ) | [private] |
Block all signals. Call this method before starting up threads.
Definition at line 446 of file mastercont.cc.
Referenced by run().
void MasterController::handle_signals | ( | ) | [private] |
Blocks waiting for Unix signals. If it's not a SIGTERM or similar, we handle the signal as appropriate within the method. Returns when we receive a termination signal.
Special case return from wait_for_signal() that means no signal was actually recieved. Just wait again...
Definition at line 502 of file mastercont.cc.
References Message::C_Exit, Messageable::queue_message(), server, and wait_for_signal().
Referenced by signal_handler_thread().
int MasterController::wait_for_signal | ( | ) | [private] |
Blocks, waiting for a single Unix signal. When a signal is received, returns the signal number that came in. You'll probably want to handle it and then just call this method again.
Definition at line 455 of file mastercont.cc.
Referenced by handle_signals().
sigset_t MasterController::all [private] |
State needed by the signal blocking/receiving methods.
Definition at line 121 of file mastercont.h.
Referenced by block_signals(), and wait_for_signal().
sigset_t MasterController::prev [private] |
ConfigP MasterController::config [private] |
The configuration we're using.
Definition at line 124 of file mastercont.h.
Referenced by start_connections().
bool MasterController::server [private] |
Whether we're intended to use the given configuration as a server or as a client.
Definition at line 127 of file mastercont.h.
Referenced by get_id(), handle_signals(), manage_connections(), and start_connections().
MasterController * MasterController::single_instance = NULL [static, private] |
Our singleton instance.
Definition at line 130 of file mastercont.h.
Referenced by get_instance(), and run().