MasterController Class Reference

#include <mastercont.h>

Inheritance diagram for MasterController:

Inheritance graph
[legend]
Collaboration diagram for MasterController:

Collaboration graph
[legend]

List of all members.

Public Member Functions

std::string get_id (void) const

Static Public Member Functions

static void run (ConfigP &config, bool server=false)
static MasterControllerget_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 MasterControllersingle_instance = NULL
 Our singleton instance.


Detailed Description

The master controller object definition. This singleton object handles incoming Unix signals, program-wide Messages passed to it from various sources (all of them Connections?), and acts accordingly. It also uses the passed-in configuration to start up and manage any appropriate Connections and Listeners.

Definition at line 67 of file mastercont.h.


Constructor & Destructor Documentation

MasterController::MasterController ( ConfigP config,
bool  server 
) [protected]

Definition at line 67 of file mastercont.cc.

Referenced by run().

Here is the caller graph for this function:

MasterController::~MasterController ( void   )  [protected]

Todo:
Should send messages or signals to our recipients.

Definition at line 72 of file mastercont.cc.


Member Function Documentation

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

std::string MasterController::get_id ( void   )  const [virtual]

Implements Messageable.

Definition at line 553 of file mastercont.cc.

References server.

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().

Here is the call graph for this function:

Here is the caller graph for this function:

void MasterController::start_connections (  )  [private]

Todo:
MasterController::start_connections() doesn't know how to tell if it should be connecting to a TTY or a TCP connection!

Todo:
We need to write the code that will allow a server to listen on a TCP address/port, as well as the ability to listen on a UDS.

Todo:
We need to move the setup of the Listener (and therefore the Incoming) up, so that we don't construct (and therefore connect) the LogFile and/or History objects if we're just going to exit...

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

void MasterController::block_signals (  )  [private]

Block all signals. Call this method before starting up threads.

Definition at line 446 of file mastercont.cc.

References all, and prev.

Referenced by run().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Todo:
Consider rethinking the SIGNO definition, here. Do we need to do this with a define? Could we use a pointer?

Definition at line 455 of file mastercont.cc.

References all, and SIGNO.

Referenced by handle_signals().

Here is the caller graph for this function:


Member Data Documentation

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]

Definition at line 121 of file mastercont.h.

Referenced by block_signals().

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().

Our singleton instance.

Definition at line 130 of file mastercont.h.

Referenced by get_instance(), and run().


The documentation for this class was generated from the following files:

Generated on Tue May 13 11:32:48 2008 for consmgr by  doxygen 1.5.5