Scale Stack 0.3 Developer Documentation

scalestack::kernel::core Class Reference

#include <core.h>

Inheritance diagram for scalestack::kernel::core:
scalestack::kernel::logger

Public Member Functions

 core (void)
 ~core ()
void parse_arguments (int argument_count, const char **arguments)
void parse_file (const std::string &filename)
void add_module_option_value (const std::string &module_name, const std::string &option_name, const std::string &value)
void set_signal_handlers (void)
void handle_signal (int signal_number)
moduleget_or_add_module (const std::string &name)
moduleget_module (const std::string &name) const
size_t get_module_count (void) const
modulebegin_module (void)
modulenext_module (void)
void add_service (const std::string &name, service *service)
serviceremove_service (const std::string &name)
serviceget_service (const std::string &name) const
size_t get_service_count (void) const
void add_log (const std::string &name, log *log)
logremove_log (const std::string &name)
logget_log (const std::string &name) const
size_t get_log_count (void) const
void run (void)
void shutdown (void)

Private Types

typedef std::vector< std::string > files
typedef std::vector< std::string > paths
typedef std::vector< module * > modules
typedef std::map< std::string,
std::string > 
aliases
typedef std::map< std::string,
service * > 
services
typedef std::map< std::string,
log * > 
logs

Private Member Functions

 core (const core &)
coreoperator= (const core &)
void _parse_argument (std::string argument)
const std::string & _get_alias (const std::string &name) const
module_get_module (const std::string &name) const
void _notify (void)
void _set_fatal_message (const char *format, std::va_list arguments) const
void _log_message (log::level log_level, const char *format, std::va_list arguments) const
void _log (log::level log_level, const char *context, const char *format, std::va_list arguments) const
void _print_help (void)
void _print_config (void)

Private Attributes

bool _need_help
bool _need_config
bool _shutdown_request
bool _iterator_on_modules
int _notify_pipe [2]
files _open_files
paths _paths
modules _modules
modules _new_modules
modules::iterator _module_iterator
aliases _aliases
services _services
logs _logs

Friends

class module

Detailed Description

This class is the central part of the kernel and is responsible for managing modules, services, and kernel logs. This and other kernel classes should be kept as minimal as possible and instead prefer pushing functionality into modules.

Definition at line 49 of file core.h.


Member Typedef Documentation

typedef std::vector<std::string> scalestack::kernel::core::files [private]

Definition at line 343 of file core.h.

typedef std::vector<std::string> scalestack::kernel::core::paths [private]

Definition at line 344 of file core.h.

typedef std::vector<module*> scalestack::kernel::core::modules [private]

Definition at line 345 of file core.h.

typedef std::map<std::string, std::string> scalestack::kernel::core::aliases [private]

Definition at line 346 of file core.h.

typedef std::map<std::string, service*> scalestack::kernel::core::services [private]

Definition at line 347 of file core.h.

typedef std::map<std::string, log*> scalestack::kernel::core::logs [private]

Definition at line 348 of file core.h.


Constructor & Destructor Documentation

scalestack::kernel::core::core ( void   ) 

Initialize all data members and add a log_console object to the list of logs.

Definition at line 73 of file core.cc.

scalestack::kernel::core::~core (  ) 

Ensure all modules are properly cleaned up and generate error messages if there are leftover services or logs.

Definition at line 101 of file core.cc.

scalestack::kernel::core::core ( const core  )  [private]

Don't allow copying of objects.


Member Function Documentation

void scalestack::kernel::core::parse_arguments ( int  argument_count,
const char **  arguments 
)

Parse arguments, most likely from the main() function arguments.

Parameters:
[in] argument_count Argument count.
[in] arguments Array of argument values.

Definition at line 139 of file core.cc.

void scalestack::kernel::core::parse_file ( const std::string &  filename  ) 

Parse arguments from a file. The options in the file should be formatted the same as the command line options with one option per line. Comments start with a '#', and all empty lines are ignored.

Parameters:
[in] filename Name of the file to parse.

Definition at line 174 of file core.cc.

void scalestack::kernel::core::add_module_option_value ( const std::string &  module_name,
const std::string &  option_name,
const std::string &  value 
)

Add an option value for a module. If a value already exists, the old value is overwritten. Options can be of the form:

module_name - Add the module name to be loaded. module_name=value - Add a module alias from module_name to value. module_name.option_name=value - Set a module option.

Parameters:
[in] module_name Name of the module to add the option for.
[in] option_name Name of the option.
[in] value Value of the option.

Definition at line 226 of file core.cc.

void scalestack::kernel::core::set_signal_handlers ( void   ) 

Set common signal handlers. Calling applications can either use this for convenience or handle their own signals. If applications need more than one core object, they cannot use this function and must handle their own signals, calling handle_signal() as needed. SIGPIPE is set to be ignored, and the following signals are set to call handle_signal(): SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGUSR1, and SIGUSR2.

Definition at line 300 of file core.cc.

void scalestack::kernel::core::handle_signal ( int  signal_number  ) 

Handle signals received by application signal handlers. This currently process SIGINT, SIGQUIT, and SIGTERM as shutdown requests. This can be used by applications that wish to handle their own signals.

Parameters:
[in] signal_number Signal that was caught and needs to be handled.

Definition at line 340 of file core.cc.

module & scalestack::kernel::core::get_or_add_module ( const std::string &  name  ) 

Get a module that has been added to the core, or add one if a module by that name doesn't exist.

Parameters:
[in] name Name of the module to add. This is used in constructing the path of the module to load. Name comparisons are case insensitive.
Returns:
The module that was added.

Definition at line 352 of file core.cc.

module & scalestack::kernel::core::get_module ( const std::string &  name  )  const

Get a module that has been added to the core.

Parameters:
[in] name Name of the module to look for. This is used to check both the name and alias list. Name comparisons are case insensitive.
Returns:
The module that was found.

Definition at line 366 of file core.cc.

size_t scalestack::kernel::core::get_module_count ( void   )  const

Get a count of the number of modules in the core.

Definition at line 377 of file core.cc.

module * scalestack::kernel::core::begin_module ( void   ) 

Reset the module iterator to the beginning and return first module. This should be called first before iterating through all modules. The most common way to use this interface is:

   for (module* module = core.begin_module();
        module != NULL;
        module = core.next_module())
   {
     // Do something with module here.
   }
Returns:
First module or NULL if there are no modules.

Definition at line 382 of file core.cc.

module * scalestack::kernel::core::next_module ( void   ) 

Get the next module while iterating, see begin_module() for usage details.

Returns:
Next module or NULL if at the end of the list.

Definition at line 389 of file core.cc.

void scalestack::kernel::core::add_service ( const std::string &  name,
service service 
)

Add a service object for the given name. If a service by that name already exists, this will throw an exception.

Parameters:
[in] name Name of the service to add.
[in] service The service object to add.

Definition at line 403 of file core.cc.

service * scalestack::kernel::core::remove_service ( const std::string &  name  ) 

Remove a service object for the given name.

Parameters:
[in] name Name of the service to remove.
Returns:
The service object that was removed.

Definition at line 413 of file core.cc.

service & scalestack::kernel::core::get_service ( const std::string &  name  )  const

Get a service object for the given name.

Parameters:
[in] name Name of the service to get.
Returns:
The service object that was requested.

Definition at line 425 of file core.cc.

size_t scalestack::kernel::core::get_service_count ( void   )  const

Get a count of the number of services that have been added.

Definition at line 434 of file core.cc.

void scalestack::kernel::core::add_log ( const std::string &  name,
log log 
)

Add a log object for the given name. If a log by that name already exists, this will throw an exception.

Parameters:
[in] name Name of the log to add.
[in] log The log object to add.

Definition at line 439 of file core.cc.

log * scalestack::kernel::core::remove_log ( const std::string &  name  ) 

Remove a log object for the given name.

Parameters:
[in] name Name of the log to remove.
Returns:
The log object that was removed.

Definition at line 449 of file core.cc.

log & scalestack::kernel::core::get_log ( const std::string &  name  )  const

Get a log object for the given name.

Parameters:
[in] name Name of the log to get.
Returns:
The log object that was requested.

Definition at line 461 of file core.cc.

size_t scalestack::kernel::core::get_log_count ( void   )  const

Get a count of the number of logs that have been added.

Definition at line 470 of file core.cc.

void scalestack::kernel::core::run ( void   ) 

This is the main loop of the core and will continue running until a shutdown request is received.

Definition at line 475 of file core.cc.

void scalestack::kernel::core::shutdown ( void   ) 

Notify the kernel core that it should start the shutdown process. This is usually called from signal handlers or modules providing administrative functions.

Definition at line 526 of file core.cc.

core& scalestack::kernel::core::operator= ( const core  )  [private]

Don't allow assignment of objects.

void scalestack::kernel::core::_parse_argument ( std::string  argument  )  [private]

Parse a single argument from any source. The format is module[.option][=value], and the parsed value is passed into add_module_option_value().

Parameters:
[in] argument Argment to parse.

Definition at line 537 of file core.cc.

const string & scalestack::kernel::core::_get_alias ( const std::string &  name  )  const [private]

Resolve module names using the alias map.

Parameters:
[in] name Name to look up in alias map.
Returns:
Alias if found, or original name that was passed in.

Definition at line 602 of file core.cc.

module * scalestack::kernel::core::_get_module ( const std::string &  name  )  const [private]

Get a module that has been added to the core, this is only used internally. This behaves just like get_module() (and is used by that method) but does not throw exceptions when the module is not found.

Definition at line 615 of file core.cc.

void scalestack::kernel::core::_notify ( void   )  [private]

Notify the main loop that it should wake up and process pending events.

Definition at line 641 of file core.cc.

void scalestack::kernel::core::_set_fatal_message ( const char *  format,
std::va_list  arguments 
) const [private, virtual]

Set a fatal message as the error string. This is declared const so other const methods can call it.

Parameters:
[in] format Message format string.
[in] arguments Argument list for formatted message.

Implements scalestack::kernel::logger.

Definition at line 647 of file core.cc.

void scalestack::kernel::core::_log_message ( log::level  log_level,
const char *  format,
std::va_list  arguments 
) const [private, virtual]

Log a core message. This is declared const so other const methods can call it.

Parameters:
[in] log_level Log level for this message.
[in] format Message format string.
[in] arguments Argument list for formatted message.

Implements scalestack::kernel::logger.

Definition at line 654 of file core.cc.

void scalestack::kernel::core::_log ( log::level  log_level,
const char *  context,
const char *  format,
std::va_list  arguments 
) const [private]

Send a log message to all configured logs. This is declared const so other const methods can call it.

Parameters:
[in] log_level Log level for this message.
[in] context Context string for this message.
[in] format Message format string.
[in] arguments Argument list for formatted message.

Definition at line 661 of file core.cc.

void scalestack::kernel::core::_print_help ( void   )  [private]

Print a help message for the kernel and all loaded modules with options.

Definition at line 676 of file core.cc.

void scalestack::kernel::core::_print_config ( void   )  [private]

Print the parsed configuration options for the kernel and all modules.

Definition at line 718 of file core.cc.


Friends And Related Function Documentation

friend class module [friend]

Definition at line 364 of file core.h.


Field Documentation

Definition at line 350 of file core.h.

Definition at line 351 of file core.h.

Definition at line 352 of file core.h.

Definition at line 353 of file core.h.

Definition at line 354 of file core.h.

Definition at line 355 of file core.h.

Definition at line 356 of file core.h.

Definition at line 357 of file core.h.

Definition at line 358 of file core.h.

modules::iterator scalestack::kernel::core::_module_iterator [private]

Definition at line 359 of file core.h.

Definition at line 360 of file core.h.

Definition at line 361 of file core.h.

Definition at line 362 of file core.h.


The documentation for this class was generated from the following files:
Generated on Thu Feb 17 13:10:22 2011 by  doxygen 1.6.3