#include <core.h>
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::Logger & | logger ()=0 |
Returns the program logger object. | |
virtual ModManager & | modules ()=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? |
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)
anonymous enum |
This enum lists all possible flags for use with the schedule() function.
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.
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.
[in] | msg | A message to log before exiting. If 0, exitmsg is logged instead. |
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).
[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. |
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.
[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. |
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.
[in] | action | May be either sfReload, sfSync, sfRestart, sfStop or sfFatal (for the last three, don't forget to set exitmsg accordingly). |
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.
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.
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.
virtual unsigned int modules::Core::debuglevel | ( | unsigned int | lev | ) | [inline, virtual] |
Sets debug level to a new value.
[in] | lev | The new debug level. |
virtual unsigned int modules::Core::flags | ( | ) | const [inline, virtual] |
Returns current program flags controlling runtime behaviour.
virtual unsigned int modules::Core::flags_add | ( | unsigned int | flg | ) | [inline, virtual] |
Adds new flags to the current program flags that control runtime behaviour.
[in] | flg | Program flags to be added, which consist of an or'ed set of pfForeground, pfBackground, pfConfigured or pfReadOnly. |
virtual unsigned int modules::Core::flags_remove | ( | unsigned int | flg | ) | [inline, virtual] |
Removes flags from the current program flags that control runtime behaviour.
[in] | flg | Program flags to be removed, which consist of an or'ed set of pfForeground, pfBackground, pfConfigured or 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.
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.
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.
Implemented in core::Epona.
virtual std::string const modules::Core::version_string | ( | ) | const [pure virtual] |
Returns the program version string, in free format.
Implemented in core::Epona.
int const modules::Core::exitmsg_size = 256 [static] |
Maximum size of the exit message.
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().