|
AndroMeta
2.0.0
|
An MProgram is created at the top-level of program, managing command-line arguments and configuration, UNIX signals, and clean shutdown. More...
#include <MProgram.h>
Public Types | |
| enum | ExitType { FullExit, ImmediateExit, ForceExit } |
Public Member Functions | |
| MProgram (int &argc, char **argv, const mvar &args=undef) | |
| MProgram (const mvar &args=undef) | |
| virtual | ~MProgram () |
| virtual void | onExit () |
| virtual void | onFatalSignal () |
| virtual void | onSigHup () |
| virtual void | onSigInt () |
| virtual void | onSigQuit () |
| virtual void | onSigIll () |
| virtual void | onSigTrap () |
| virtual void | onSigAbrt () |
| virtual void | onSigFpe () |
| virtual void | onSigBus () |
| virtual void | onSigSegv () |
| virtual void | onSigSys () |
| virtual void | onSigPipe () |
| virtual void | onSigAlrm () |
| virtual void | onSigTerm () |
| virtual void | onSigUrg () |
| virtual void | onSigCont () |
| virtual void | onSigChld () |
| virtual void | onSigIo () |
| virtual void | onSigXCPU () |
| virtual void | onSigXFSz () |
| virtual void | onSigVtAlrm () |
| virtual void | onSigProf () |
| virtual void | onSigWInch () |
| virtual void | onSigUsr1 () |
| virtual void | onSigUsr2 () |
Static Public Member Functions | |
| static mvar | parseArgs (int argc, char **argv) |
| static mstr | toArgStr (const mvar &v) |
| static void | exit (int status, ExitType exitType=ImmediateExit) |
| static MProgram * | instance () |
| static mvar | args () |
| static bool | hasArg (const mstr &key) |
| static void | setArgs (const mvar &args) |
| static mvar | arg (const mstr &key) |
| static mvar | arg (const mstr &key, const mvar &def) |
| static void | setArg (const mstr &key, const mvar &value) |
| static void | argDefault (const mstr &key, const mvar &value, const mstr &description="") |
| static void | argDefault (const mstr &key, const mstr &alias, const mvar &value, const mstr &description) |
| static void | requireArg (const mstr &key, const mstr &description="") |
| static mstr | usage (const mstr &msg) |
| static void | resetSignalHandlers () |
| static void | setOutputStream (std::ostream &outputStream) |
Static Public Attributes | |
| static int | argc |
| static char ** | argv |
An MProgram is created at the top-level of program, managing command-line arguments and configuration, UNIX signals, and clean shutdown.
MProgram provides a unified interface for reading command-line arguments and configration via the use of mvar's. Arguments then provide a thread-safe means of sharing global data. MProgram allows required and default arguments to be specified. It provides a simplified signal handling interface -- just re-implement one of the sigXXX methods.
Exit types.
| Meta::MProgram::MProgram | ( | int & | argc, |
| char ** | argv, | ||
| const mvar & | args = undef |
||
| ) |
Constructor.
| Meta::MProgram::MProgram | ( | const mvar & | args = undef | ) |
Constructor. Create an MProgram without reading command-line arguments.
| args | Contains any initial arguments including "name" which defaults to "program". |
| virtual Meta::MProgram::~MProgram | ( | ) | [virtual] |
Destructor.
| static mvar Meta::MProgram::arg | ( | const mstr & | key | ) | [static] |
| static mvar Meta::MProgram::arg | ( | const mstr & | key, |
| const mvar & | def | ||
| ) | [static] |
| static void Meta::MProgram::argDefault | ( | const mstr & | key, |
| const mvar & | value, | ||
| const mstr & | description = "" |
||
| ) | [static] |
Specify an argument default that will be used in the absence of the argument existing in the configuration and command-line arguments. This method is normally called at the start of a program.
| description | The description used for auto-generated documentation. |
| static void Meta::MProgram::argDefault | ( | const mstr & | key, |
| const mstr & | alias, | ||
| const mvar & | value, | ||
| const mstr & | description | ||
| ) | [static] |
Specify an argument default with an alias. This method is normally called at the start of a program.
| key | e.g: "length" |
| alias | e.g: "l" |
| description | The description used for auto-generated documentation. |
| static mvar Meta::MProgram::args | ( | ) | [static] |
Get a copy of the arguments.
| static void Meta::MProgram::exit | ( | int | status, |
| ExitType | exitType = ImmediateExit |
||
| ) | [static] |
This methods provides a clean shutdown and exit, in varying levels.
FullExit - for a full clean shutdown and exit, allowing MProc's to terminate before shutting down MProc tasks.
ImmediateExit - Do not wait for MProc's to terminate, unless they are using system resources that need to be released.
ForceExit - Force an exit now, only doing cleanup that is immediate. Should not be used unless there is a specific reason to do so.
| static bool Meta::MProgram::hasArg | ( | const mstr & | key | ) | [static] |
| static MProgram* Meta::MProgram::instance | ( | ) | [static] |
Get the instance of MProgram.
| virtual void Meta::MProgram::onExit | ( | ) | [virtual] |
Application-specific handling on exit.
| virtual void Meta::MProgram::onFatalSignal | ( | ) | [virtual] |
Default signal handler called upon receiving a signal whose default UNIX behavior is to exit. By default it calls MProgram::exit(1).
| virtual void Meta::MProgram::onSigAbrt | ( | ) | [virtual] |
Signal handler called on SIGABRT. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigAlrm | ( | ) | [virtual] |
Signal handler called on SIGALRM. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigBus | ( | ) | [virtual] |
Signal handler called on SIGBUS. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigChld | ( | ) | [virtual] |
Signal handler called on SIGCHLD. Default behavior is ignore.
| virtual void Meta::MProgram::onSigCont | ( | ) | [virtual] |
Signal handler called on SIGCONT. Default behavior is ignore.
| virtual void Meta::MProgram::onSigFpe | ( | ) | [virtual] |
Signal handler called on SIGFPE. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigHup | ( | ) | [virtual] |
Signal handler called on SIGHUP. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigIll | ( | ) | [virtual] |
Signal handler called on SIGILL. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigInt | ( | ) | [virtual] |
Signal handler called on SIGINT. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigIo | ( | ) | [virtual] |
Signal handler called on SIGIO. Default behavior is ignore.
| virtual void Meta::MProgram::onSigPipe | ( | ) | [virtual] |
Signal handler called on SIGPIPE. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigProf | ( | ) | [virtual] |
Signal handler called on SIGPROF. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigQuit | ( | ) | [virtual] |
Signal handler called on SIGQUIT. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigSegv | ( | ) | [virtual] |
Signal handler called on SIGSEGV. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigSys | ( | ) | [virtual] |
Signal handler called on SIGSYS. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigTerm | ( | ) | [virtual] |
Signal handler called on SIGTERM. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigTrap | ( | ) | [virtual] |
Signal handler called on SIGTRAP. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigUrg | ( | ) | [virtual] |
Signal handler called on SIGURG. Default behavior is ignore.
| virtual void Meta::MProgram::onSigUsr1 | ( | ) | [virtual] |
Signal handler called on SIGUSR1. Default behavior is ignore.
| virtual void Meta::MProgram::onSigUsr2 | ( | ) | [virtual] |
Signal handler called on SIGUSR2. Default behavior is ignore.
| virtual void Meta::MProgram::onSigVtAlrm | ( | ) | [virtual] |
Signal handler called on SIGFTALRM. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigWInch | ( | ) | [virtual] |
Signal handler called on SIGWINCH. Default behavior is ignore.
| virtual void Meta::MProgram::onSigXCPU | ( | ) | [virtual] |
Signal handler called on SIGXCPU. Default behavior is to call onFatalSignal().
| virtual void Meta::MProgram::onSigXFSz | ( | ) | [virtual] |
Signal handler called on SIGXFSZ. Default behavior is to call onFatalSignal().
| static mvar Meta::MProgram::parseArgs | ( | int | argc, |
| char ** | argv | ||
| ) | [static] |
Manually parse command-line args to an mvar.
| static void Meta::MProgram::requireArg | ( | const mstr & | key, |
| const mstr & | description = "" |
||
| ) | [static] |
Require an argument to exist, else display an error and exit. This method is normally called at the start of a program.
| description | The description used for auto-generated documentation. |
| static void Meta::MProgram::resetSignalHandlers | ( | ) | [static] |
Useful when temporary signal handlers are installed, when afterwards MProgram's standard signal handling needs to be reinstalled.
| static void Meta::MProgram::setArg | ( | const mstr & | key, |
| const mvar & | value | ||
| ) | [static] |
Set an argument to a value.
| static void Meta::MProgram::setArgs | ( | const mvar & | args | ) | [static] |
Set all arguments.
| static void Meta::MProgram::setOutputStream | ( | std::ostream & | outputStream | ) | [static] |
Set the main output stream used by various parts of the framework. The default is cout.
| static mstr Meta::MProgram::toArgStr | ( | const mvar & | v | ) | [static] |
Performs the inverse of parseArgs().
| static mstr Meta::MProgram::usage | ( | const mstr & | msg | ) | [static] |
Auto-generate a usage message based on the information provided by calls to argDefault() and requireArg().
| msg | The top-level usage message. e.g: "program [OPTION]... [FILE]..." |
int Meta::MProgram::argc [static] |
The original argc as passed to MProgram.
char** Meta::MProgram::argv [static] |
The original argv as passed to MProgram.
1.7.6.1