modules::Core Class Reference

Core module class. More...

#include <core.h>

Inheritance diagram for modules::Core:

modules::Module core::Epona

List of all members.

Public Types

enum  {
  sfReload = 0x00000001, sfSync = 0x00000002, sfRestart = 0x00000004, sfStop = 0x00000008,
  sfFatal = 0x00000010
}
 Schedule flags. More...
enum  {
  pfForeground = 0x00000001, pfBackground = 0x00000002, pfConfigured = 0x00000004, pfReadOnly = 0x00000008,
  pfQuiet = 0x00000010, pfVeryQuiet = 0x00000020
}
 Program flags. More...

Public Member Functions

 Core ()
 Constructor.
virtual void fatal (char const *msg=0)=0
 Exit the program immediately.
void fatalf (char const *msg,...) FORMAT(printf
 Same as fatal but works like printf().
void void log (xlog::LogLevel const &level, char const *format,...) FORMAT(printf
 Logs a message.
void void void log_perror (xlog::LogLevel const &level, char const *format,...) FORMAT(printf
 Logs a message with a system error.
virtual void schedule (unsigned int action)
 Schedule program-related action.
virtual
cmdline::CmdLineParser
clp ()=0
 Returns the parsed command-line parameters.
virtual
conf::ConfLogger
conf_logger ()=0
 Returns the configuration logger object.
virtual unsigned int debuglevel () const
 Returns current debug level.
virtual unsigned int debuglevel (unsigned int lev)
 Sets debug level to a new value.
virtual unsigned int flags () const
 Returns current program flags.
virtual unsigned int flags_add (unsigned int flg)
 Adds new flags to current program flags.
virtual unsigned int flags_remove (unsigned int flg)
 Removes flags from current program flags.
virtual xlog::Loggerlogger ()=0
 Returns the program logger object.
virtual ModManagermodules ()=0
 Returns the modules manager object.
virtual bool started () const
 Returns whether the program is started.
virtual time_t start_time () const
 Returns when the program started.
virtual
scheduler::Scheduler
tasks ()=0
 Returns the program scheduler object.
virtual std::string const version_string () const =0
 Returns the version string.

Public Attributes

char exitmsg [exitmsg_size]
 Program exit message.

Static Public Attributes

static int const exitmsg_size = 256
 Program exit message size.

Protected Attributes

unsigned int m_action
 Scheduled action (through schedule()).
unsigned int m_debuglevel
 Debug level.
unsigned int m_flags
 Program flags.
bool m_started
 Started?
time_t m_starttime
 When did it start?


Detailed Description

This is the core module class, i.e. the module that handles all the program basics.

It encapsulates all the core features one might expect such as the command-line parser, the conf logger, the modules manager, the scheduler or the program logger. There's also a few functions that control the program flow.

Other modules will always be able to rely on a module derived from this class as the module manager ensures this module exists and can't be unloaded (yes, that wouldn't make much sense, really. :P)


Member Enumeration Documentation

anonymous enum

This enum lists all possible flags for use with the schedule() function.

Enumerator:
sfReload  Reload configuration.
sfSync  Send a sync message to modules.
sfRestart  Restart the program.
sfStop  Stops the program.
sfFatal  Stops the program abruptly (ignores all other flags if set).

anonymous enum

This enum lists all possible flags for use with the flags() function family.

Enumerator:
pfForeground  The program won't go into background.
pfBackground  The program runs in background.
pfConfigured  The program configuration file(s) ha(s/ve) been loaded.
pfReadOnly  The program should not write anything to disk.
pfQuiet  Nothing shall be written to stdout.
pfVeryQuiet  Nothing shall be written to stdout and stderr.


Member Function Documentation

virtual void modules::Core::fatal ( char const *  msg = 0  )  [pure virtual]

When something goes so wrong that there's no way to continue execution normally, call this to exit the program.

Parameters:
[in] msg A message to log before exiting. If 0, exitmsg is logged instead.
See also:
exitmsg

Implemented in core::Epona.

void void modules::Core::log ( xlog::LogLevel const &  level,
char const *  format,
  ... 
)

Logs a message through the program logger (the Logger::log() function is used).

Parameters:
[in] level The log level of the message.
[in] format A format string for the message, similar to the one used by the printf() family of functions.
[in] ... Parameters for the format string.
See also:
LogLevel, Logger, Logger::log()

void void void modules::Core::log_perror ( xlog::LogLevel const &  level,
char const *  format,
  ... 
)

Logs a message through the program logger (the Logger::log() function is used). If errno is non-zero, then a system error message (as returned by the strerror() function) will be appended to it.

Parameters:
[in] level The log level of the message.
[in] format A format string for the message, similar to the one used by the printf() family of functions.
[in] ... Parameters for the format string.
See also:
LogLevel, Logger, Logger::log()

virtual void modules::Core::schedule ( unsigned int  action  )  [inline, virtual]

This function schedules a program-related action to be executed once, at the next main loop iteration, allowing them to be executed in a safe manner whatever the context is when the scheduling is done.

This function may be called multiple times to schedule different actions. The order in which the actions are done is undefined in that case, although sfFatal is ALWAYS processed first.

Parameters:
[in] action May be either sfReload, sfSync, sfRestart, sfStop or sfFatal (for the last three, don't forget to set exitmsg accordingly).
See also:
sfReload, sfSync, sfRestart, sfStop, sfFatal

virtual cmdline::CmdLineParser& modules::Core::clp (  )  [pure virtual]

Returns the command-line parameters, already parsed. Should be used by modules that want to handle their own command-line parameters (a parameter is never invalid so all parameters given at program start are always there). Modules must use only long options though, because they can't predict which short options will be already in use by the core.

Returns:
The command-line parameters.
See also:
cmdline::CmdLineParser

Implemented in core::Epona.

virtual conf::ConfLogger& modules::Core::conf_logger (  )  [pure virtual]

Returns the configuration logger object, that may be used by modules when they need to create configuration parsers.

Returns:
The configuration logger.

Implemented in core::Epona.

virtual unsigned int modules::Core::debuglevel (  )  const [inline, virtual]

Returns current debug level, usually between 0 and 4 (but it can be more if user requests it). Debug messages must be logged only if debuglevel is non-zero.

Returns:
The debug level.

virtual unsigned int modules::Core::debuglevel ( unsigned int  lev  )  [inline, virtual]

Sets debug level to a new value.

Parameters:
[in] lev The new debug level.
Returns:
The new debug level.
See also:
debuglevel()

virtual unsigned int modules::Core::flags (  )  const [inline, virtual]

Returns current program flags controlling runtime behaviour.

Returns:
The current program flags, which consist of an or'ed set of pfForeground, pfBackground, pfConfigured or pfReadOnly.
See also:
pfForeground pfBackground pfConfigured pfReadOnly

virtual unsigned int modules::Core::flags_add ( unsigned int  flg  )  [inline, virtual]

Adds new flags to the current program flags that control runtime behaviour.

Parameters:
[in] flg Program flags to be added, which consist of an or'ed set of pfForeground, pfBackground, pfConfigured or pfReadOnly.
Returns:
The new current program flags.
See also:
pfForeground pfBackground pfConfigured pfReadOnly

virtual unsigned int modules::Core::flags_remove ( unsigned int  flg  )  [inline, virtual]

Removes flags from the current program flags that control runtime behaviour.

Parameters:
[in] flg Program flags to be removed, which consist of an or'ed set of pfForeground, pfBackground, pfConfigured or pfReadOnly.
Returns:
New current program flags.
See also:
pfForeground pfBackground pfConfigured pfReadOnly

virtual xlog::Logger& modules::Core::logger (  )  [pure virtual]

Returns the program logger object, that may be used by the program to log messages through various means, as well as register log modules.

Returns:
The program logger.

Implemented in core::Epona.

virtual ModManager& modules::Core::modules (  )  [pure virtual]

Returns the modules manager object, that is used to load, unload and maintain the modules used by the program.

Returns:
The modules manager

Implemented in core::Epona.

virtual bool modules::Core::started (  )  const [inline, virtual]

Returns whether the program is started (i.e. all initialization finished, in the main loop).

virtual time_t modules::Core::start_time (  )  const [inline, virtual]

Returns when the program started (i.e. when the core module was created).

virtual scheduler::Scheduler& modules::Core::tasks (  )  [pure virtual]

Returns the program scheduler object, that modules may use to schedule tasks to be run periodically. It's basically their main way to hook the main loop to get things to be done when they need to.

Returns:
The scheduler.

Implemented in core::Epona.

virtual std::string const modules::Core::version_string (  )  const [pure virtual]

Returns the program version string, in free format.

Returns:
A version string.

Implemented in core::Epona.


Member Data Documentation

int const modules::Core::exitmsg_size = 256 [static]

Maximum size of the exit message.

See also:
exitmsg

char modules::Core::exitmsg[exitmsg_size]

The message that will be logged before exiting the program. Must be set prior to ask for program termination or restart through fatal(), fatalf() or schedule().


The documentation for this class was generated from the following file:
Generated on Fri Apr 18 22:03:28 2008 for Epona API by  doxygen 1.5.3