nidas v1.2.3
|
NidasApp handles common options for NIDAS applications. More...
#include <NidasApp.h>
Classes | |
class | IdFormat |
An IdFormat specifies the format for the SPS ID plus other characteristics, like the width when using decimal format. More... | |
Public Types | |
enum | id_format_t { NOFORMAT_ID , AUTO_ID , DECIMAL_ID , HEX_ID , OCTAL_ID } |
The four possible output formats for sensor-plus-sample IDs: More... | |
Public Member Functions | |
nidas_app_arglist_t | loggingArgs () |
This is a convenience method to return all of the logging-related options in a list, such that this list can be extended if new log options are enabled. | |
NidasApp (const std::string &name) | |
Construct a NidasApp instance and give it a name to be used for the usage info. | |
~NidasApp () | |
If this instance is the current application instance, then the application instance is reset to null when this is destroyed. | |
std::string | getName () |
void | setProcessName (const std::string &argv0) |
Set the name of this particular process, usually argv[0]. | |
std::string | getProcessName () |
Get the process name, as set by setProcessName(), or else return the app name from getName(). | |
void | setApplicationInstance () |
An instance of NidasApp can be set as an application-wide instance, like an application context, which other parts of the application can retrieve with getApplicationInstance(). | |
void | allowUnrecognized (bool allow) |
Set whether unrecognized flags should throw an exception or not. | |
bool | allowUnrecognized () |
Return whether unrecognized flags are allowed or not. | |
void | enableArguments (const nidas_app_arglist_t &arglist) |
Add the list of NidasAppArg pointers to the set of arguments accepted by this NidasApp instance. | |
void | requireArguments (const nidas_app_arglist_t &arglist) |
Add arguments to this NidasApp same as enableArguments() but also set them as required. | |
void | checkRequiredArguments () |
Verify that all NidasAppArg arguments required by this NidasApp have been specified, otherwise throw NidasAppException. | |
nidas_app_arglist_t | getArguments () |
Return the list of arguments which are supported by this NidasApp, in other words, the arguments enabled by enableArguments() or requireArguments(). | |
void | requireLongFlag (const nidas_app_arglist_t &arglist, bool require=true) |
Call acceptShortFlag(false) on the given list of NidasApp instances, meaning only the long flag will be recognized. | |
void | startArgs (const ArgVector &args) |
Set the list of command-line argument strings to be parsed and handled by successive calls to nextArgument(). | |
void | startArgs (int argc, const char *const argv[]) |
Convenience method to convert the (argc, argv) run string to a list of arguments to pass to startArgs(). | |
NidasAppArg * | parseNext () |
Parse the next recognized argument from the list set in startArgs(). | |
bool | nextArg (std::string &arg) |
If the next argument to be parsed does not start with '-', then copy it into arg and remove it from the arguments. | |
ArgVector | unparsedArgs () |
ArgVector | parseArgs (const ArgVector &args) |
Parse all arguments accepted by this NidasApp in the command-line argument list args , but only handle the standard arguments. | |
ArgVector | parseArgs (int argc, const char *const argv[]) |
Convenience method to convert the (argc, argv) run string to a list of arguments to pass to parseArgs(). | |
void | parseLogConfig (const std::string &optarg) |
Parse a LogConfig from the given argument using the LogConfig string syntax, and add that LogConfig to the current LogScheme. | |
void | parseLogLevel (const std::string &optarg) |
This is an alias for parseLogConfig(), since the LogConfig string syntax is backwards compatible with parsing just log levels. | |
nidas::util::UTime | parseTime (const std::string &optarg) |
void | parseUsername (const std::string &username) |
void | parseInputs (const std::vector< std::string > &inputs, std::string default_input="", int default_port=0) |
Parse one or more input URLs from a list of non-option command-line arguments. | |
bool | inputsProvided () |
void | parseOutput (const std::string &optarg) |
Parse an output specifier in the form <strptime-filename-pattern>[<length>[smh]]. | |
std::string | outputFileName () |
Return just the output file pattern specified by an output option, without the file length specifier. | |
int | outputFileLength () |
Return the output file length in seconds. | |
int | logLevel () |
Return LogScheme::logLevel() for the current log scheme. | |
void | resetLogging () |
Reset logging to the NidasApp default. | |
void | setProcessData (bool process) |
Set the process-data setting in this NidasApp. | |
bool | processData () |
Return the current process-data setting for this NidasApp. | |
std::string | xmlHeaderFile () |
std::string | getConfigsXML () |
Derive the path to the XML file which lists project configs. | |
nidas::core::Dataset | getDataset (const std::string &datasetname) |
Derive a path to an XML datasets file according to the current environment settings, searching these paths in order: | |
nidas::util::UTime | getStartTime () |
Return the StartTime as a UTime. | |
nidas::util::UTime | getEndTime () |
Return the EndTime as a UTime. | |
void | setOutputClipping (const nidas::util::UTime &start, const nidas::util::UTime &end, nidas::core::SampleOutputBase *output) |
If Clipping has been enabled, call setTimeClippingWindow() on the given output using start and end . | |
void | setFileSetTimes (const nidas::util::UTime &start, const nidas::util::UTime &end, nidas::core::FileSet *fset) |
bool | interrupted (bool allow_exception=true) |
Return the value of the global interrupted flag. | |
void | setException (const nidas::util::Exception &ex) |
Like setInterrupted(true), but also allows an exception to be stored which can be tested and retrieved later with hasException() and getException(). | |
bool | hasException () |
See setException(). | |
nidas::util::Exception | getException () |
Return the current exception. | |
Project * | getProject () |
Return a pointer to the application-wide Project instance. | |
std::string | usage (const std::string &indent, bool brief) |
Return a usage string describing the arguments accepted by this application, rendering each argument by calling NidasAppArg::usage() with the given indent string and brief parameter. | |
std::string | usage (const std::string &indent=" ") |
Return the usage string, formatted according to the current brief setting. | |
bool | helpRequested () |
Return true when a help option was parsed, meaning the usage info has been requested. | |
bool | briefHelp () |
Return true if brief help requested, such as with -h. | |
void | setIdFormat (IdFormat idt) |
Store the format in which sample IDs should be shown. | |
IdFormat | getIdFormat () |
std::ostream & | formatSampleId (std::ostream &out, dsm_sample_id_t sid) |
Write the sensor-plus-sample ID part of sid to out using the ID format of this NidasApp instance, the format returned by getIdFormat(), same as calling formatSampleId(out, getIdFormat(),
sid). | |
std::string | formatId (dsm_sample_id_t sid) |
A more convenient form of formatSampleId() which just returns a string, and also includes the DSM id in the familiar format "<dsmid>,<sid>". | |
SampleMatcher & | sampleMatcher () |
Use this method to access the SampleMatcher instance for this NidasApp. | |
std::list< std::string > & | dataFileNames () |
Return the list of filenames parsed from the input URLs with parseInputs(). | |
nidas::util::SocketAddress * | socketAddress () |
If parseInputs() parsed a network socket specifier, then this method returns a pointer to the corresponding SocketAddress. | |
std::string | getHostName () |
Return the hostname passed to the Hostname argument, if any, otherwise return the current hostname as returned by gethostname(). | |
std::string | getShortHostName () |
Like getHostName(), but any '. | |
std::string | getUserName () |
Return the username passed to the Username argument, if enabled, otherwise return an empty string. | |
uid_t | getUserID () |
Return the userid of the username passed to the Username argument, otherwise 0. | |
uid_t | getGroupID () |
Return the groupid of the username passed to the Username argument, otherwise 0. | |
void | setupProcess () |
Setup a process with the user and group specified by the Username argument, and attempt to set related capabilities. | |
void | setupDaemonLogging (bool daemon_mode) |
Setup logging according to daemon mode. | |
void | setupDaemonLogging () |
Call setupDaemonLogging(daemon_mode), where daemon_mode is true only if DebugDaemon is false. | |
void | setupDaemon (bool daemon_mode) |
Call setupDaemonLogging(), then switch this process to daemon mode if daemon_mode is true. | |
void | setupDaemon () |
Call setupDaemon(daemon_mode), where daemon_mode is true only if DebugDaemon is false. | |
void | lockMemory () |
Attempt mlockall() for this process, first adding the CAP_IPC_LOCK capability if possible. | |
int | checkPidFile () |
Create a pid file for this process and return 0. | |
float | getSorterLength (float min, float max) |
Return sorter length value, or throw std::invalid_argument. | |
Static Public Member Functions | |
static NidasApp * | getApplicationInstance () |
Return the current application instance. | |
static void | setInterrupted (bool interrupted) |
Set the global interrupted state for NidasApp. | |
static void | setupSignals (void(*callback)(int signum)=0) |
Setup signal handling for HUP, INT, and TERM, equivalent to calling addSignal() for each. | |
static void | addSignal (int signum, void(*callback)(int signum)=0, bool nolog=false) |
Add the given signal signum to the list of signals handled by the NidasApp signal handler, and optionally set an additional callback. | |
static std::ostream & | formatSampleId (std::ostream &out, IdFormat idfmt, dsm_sample_id_t sid) |
Write the sensor-plus-sample ID part of sid to stream out using the format specified in idfmt . | |
Public Attributes | |
NidasAppArg | XmlHeaderFile |
NidasAppArg | LogShow |
NidasAppArg | LogConfig |
NidasAppArg | LogFields |
NidasAppArg | LogParam |
NidasAppArg | Help |
NidasAppArg | ProcessData |
NidasAppArg | StartTime |
NidasAppArg | EndTime |
NidasAppArg | SampleRanges |
NidasAppArg | FormatHexId |
NidasAppArg | FormatSampleId |
NidasAppArg | Version |
NidasAppInputFilesArg | InputFiles |
NidasAppArg | OutputFiles |
NidasAppArg | Username |
NidasAppArg | Hostname |
NidasAppArg | DebugDaemon |
NidasAppArg | ConfigsArg |
NidasAppArg | DatasetName |
NidasAppArg | Clipping |
NidasAppArg | SorterLength |
NidasAppArg | PidFile |
It is not enough to enable this arg in an app, the app must must call checkPidFile() as well. | |
Private Member Functions | |
void | setupLogScheme () |
Private Attributes | |
std::string | _appname |
std::string | _argv0 |
bool | _processData |
std::string | _xmlFileName |
IdFormat | _idFormat |
SampleMatcher | _sampleMatcher |
nidas::util::UTime | _startTime |
nidas::util::UTime | _endTime |
std::list< std::string > | _dataFileNames |
nidas::util::auto_ptr< nidas::util::SocketAddress > | _sockAddr |
std::string | _outputFileName |
int | _outputFileLength |
bool | _help |
bool | _brief |
std::string | _username |
std::string | _hostname |
uid_t | _userid |
gid_t | _groupid |
bool | _deleteProject |
nidas_app_arglist_t | _app_arguments |
ArgVector | _argv |
int | _argi |
bool | _hasException |
nidas::util::Exception | _exception |
bool | _allowUnrecognized |
nidas::util::LogScheme | _logscheme |
NidasApp keeps track of the LogScheme built up from arguments. | |
Static Private Attributes | |
static NidasApp * | application_instance = 0 |
NidasApp handles common options for NIDAS applications.
The application specifies which of the options are valid and it can specify defaults if necessary, then command-line arguments can be parsed and their settings retrieved through this instance. This class allows for consistent option letters and syntax across NIDAS applications. Applications can extend this class with their own options, either as a subclass or by delegation to an instance.
There are several NIDAS applications with common options that can be consolidated in this class:
The goal is to keep syntax and meaning for common arguments consistent across applications.
Standard option | Description | Replacement Syntax |
-i dsmid,sampleid | Sample IDs to include. | |
-x dsmid,sampleid | Sample IDs to exclude. | -i ^dsmid,sampid |
-l loglevel | Numeric log level. | -l number_or_name |
-l interval | Output file interval. | output@interval |
-h | Help | |
-p | Process samples | |
-X | Print Hex IDs | |
-v | Report version. | |
-x xmlfile | Explicit header file. | |
input | Socket or files. | |
output[@interval] | Output pattern, interval | |
-s starttime | Skip samples before start | |
-e endtime | Skip samples after end | |
-d | Run in debug mode instead of as a background daemon. | |
-f | Filter bad samples according to default filter rules. | |
–filter rules | Specify rules for filtering bad samples, using a key=value syntax. | –filter maxdsm=1024,mindsm=1,maxlen=32768,minlen=1 |
Below are notes about the deprecated options and the standard options made available through NidasApp.
Where -x is accepted but deprecated, -x A,B translates to -i ^A,B.
Since -l conflicts with log level and output file length, the separate -l for file length is being deprecated in favor of specifying the length in the output file pattern:
strptime_pattern[@_number_[units]]
Units can be (s)econds, (m)inutes, (h)ours, seconds is the default. Maybe later add units for size like kb, mb.
The -l option needs to be accepted for a while, perhaps differntiated automatically by whether it's a number greater than 10 (for apps which enable that option). But it should produce a warning. Is there ever a case where the output-file-length needs to be specified without an output file name pattern? Is there a reasonable default filename pattern if the output is simply <interval>?
The older –loglevel and –logconfig are obsolete. The short version -l, for the applications which accept it, is an alias for the newer –log option.
The log config string is a comma-separated list of LogConfig fields, where the field names are level, tag, file, function, file, and line. Additionally, a field can have the value 'enable' or 'disable' to set the active flag accordingly for matching log contexts. All the settings are combined into a single LogConfig and added to the current scheme.
If a field does not have an equal sign and is not 'enable' or 'disable', then it is interpreted as just a log level, compatible with what the -l option has always supported.
loglevel can be a number or the name of a log level:
7=debug,6=info,5=notice,4=warn,3=err
The default log level when a NidasApp is created is info.
Show log points as they are encountered while the code is running. This shows what log points would log messages if enabled by the logging configuration, and it gives information about each log point that can be used to enable only that log point.
Set the log message fields which will be shown in log messages. The <fields> argument is passed to the LogScheme::setShowFields() method of the current logging scheme.
Set a log parameter in the application log scheme.
sensor_extract
uses -s to map id selection to a new id, eg 10,1,10,3. Rather than add another option letter, maybe it would be better to extend the -i syntax: -i 10,1=10,3 where the = part is only allowed if specifically enabled. Then sensor_extract just needs a way to enable that extension and to get to that mapping. Or, maybe the mapping can be completely internal to the sample filter: if app passes the sample pointer to the filter, the filter can modify the sample id as specified after checking that the sample is selected.
The dsm and dsm_server applications both support a debug mode which runs in the foreground instead of as a daemon, and by default sends all log messages to standard output. The long form is –debug.
For daemon applications, switch to the given user after setting required capabilities.
Run as if on the given host instead of using current system hostname.
When a NidasApp is constructed, it sets up its own default logging scheme with a fallback log level of INFO. That log scheme is set as the current scheme only if there is not already a scheme with a non-empty name. That allows an app to install its own default LogScheme before creating a NidasApp, but the app of course can also install its own scheme after creating NidasApp. When NidasApp parses logging arguments, it updates and explicitly installs its LogScheme, so the user arguments always override the app and NidasApp defaults.
Since the default INFO log level is a fallback, that will be replaced by the first log config provided as an argument. So a log argument of "warning" will set the log scheme to only show messages at or more critical than warnings.
The four possible output formats for sensor-plus-sample IDs:
noformat - Use an existing setting or the default. auto - Use decimal for samples less than 0x8000, and hex otherwise. decimal - Use decimal for all samples. hex - Use hex for all samples. octal - Use octal for all samples. Not really used.
The default is auto. Set it with –id-format {auto|decimal|hex}.
Enumerator | |
---|---|
NOFORMAT_ID | |
AUTO_ID | |
DECIMAL_ID | |
HEX_ID | |
OCTAL_ID |
nidas::core::NidasApp::NidasApp | ( | const std::string & | name | ) |
Construct a NidasApp instance and give it a name to be used for the usage info.
References ConfigsArg, getName(), nidas::core::getSample(), PidFile, nidas::core::NidasAppArg::setDefault(), setupLogScheme(), and nidas::core::NidasAppArg::setUsageString().
nidas::core::NidasApp::~NidasApp | ( | ) |
If this instance is the current application instance, then the application instance is reset to null when this is destroyed.
References _deleteProject, application_instance, and nidas::core::Project::destroyInstance().
|
static |
Add the given signal signum
to the list of signals handled by the NidasApp signal handler, and optionally set an additional callback.
If non-zero, callback
is a function which will be called when the application receives an interrupt signal. The callback is called asynchronously, directly from the NidasApp signal handler function. There can only be one callback, so the one in effect is whatever was set last in setupSignals() and addSignal(). The NidasApp handler sets the flag returned by interrupted(), and then calls the callback
function with the signal number as a parameter. signum
is a symbol like SIGALRM, SIGHUP, SIGINT, and SIGTERM from signal.h. signum
can be zero, in which case only the callback function changes.
If nolog
is true, then nothing will be logged to cerr by the default signal handler when that signal is received.
References nidas::core::getSample(), and sigAction().
Referenced by SensorSimApp::main(), DataStats::run(), and setupSignals().
bool nidas::core::NidasApp::allowUnrecognized | ( | ) |
Return whether unrecognized flags are allowed or not.
References _allowUnrecognized.
Referenced by parseNext().
Set whether unrecognized flags should throw an exception or not.
By default, NidasApp throws an exception when parsing an argument which starts with '-' but is not accepted by one of the enabled arguments. Pass true to this method to ignore those unrecognized flags and leave them in the unparsed arguments list.
References _allowUnrecognized, and nidas::core::getSample().
Referenced by ARLIngest::parseRunstring(), DataDump::parseRunstring(), PacketReader::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), and parseRunstring().
|
inline |
Return true if brief help requested, such as with -h.
References _brief.
Referenced by DataDump::parseRunstring(), and DataStats::usage().
int nidas::core::NidasApp::checkPidFile | ( | ) |
Create a pid file for this process and return 0.
If the pid file already exists, then return 1. The path to the PID file is set by the PidFile NidasAppArg, which defaults to /tmp/run/nidas/<appname>.pid. The path can be changed on the command-line if the PidFile argument has been enabled. The directory for the pid file is created if necessary. Usually an app calls this method after the setupDaemon() and setupProcess() calls. This method checks for the pid file even if DebugDaemon is enabled. Otherwise it is possible to create multiple instances of a nidas service on a host which interfere with each other. If it is necessary to start multiple processes, then the –pid argument must be used change the pid file path.
References getProcessName(), nidas::core::getSample(), nidas::core::NidasAppArg::getValue(), PidFile, and PLOG.
Referenced by nidas::core::DSMEngine::initProcess(), and nidas::core::DSMServerApp::initProcess().
void nidas::core::NidasApp::checkRequiredArguments | ( | ) |
Verify that all NidasAppArg arguments required by this NidasApp have been specified, otherwise throw NidasAppException.
References DLOG, getArguments(), and nidas::core::getSample().
|
inline |
Return the list of filenames parsed from the input URLs with parseInputs().
If the input URL specified a network socket, then this list is empty. See socketAddress().
References _dataFileNames.
Referenced by DataPrep::parseRunstring(), StatsProcess::parseRunstring(), DataStats::run(), and StatsProcess::run().
void nidas::core::NidasApp::enableArguments | ( | const nidas_app_arglist_t & | arglist | ) |
Add the list of NidasAppArg pointers to the set of arguments accepted by this NidasApp instance.
Since the arguments are referenced by pointer, their lifetime should match the lifetime of the NidasApp instance. For example, define additional non-standard arguments as members of the same class in which NidasApp is a member.
The arglist can be created implicitly from the NidasAppArg instances, as in this example:
References _app_arguments, and nidas::core::getSample().
Referenced by DataStats::DataStats(), main(), ARLIngest::parseRunstring(), DataDump::parseRunstring(), DmdA2dCk::parseRunstring(), DataPrep::parseRunstring(), PacketReader::parseRunstring(), NidsMerge::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMEngine::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), PConfig::parseRunstring(), and requireArguments().
std::string nidas::core::NidasApp::formatId | ( | dsm_sample_id_t | sid | ) |
A more convenient form of formatSampleId() which just returns a string, and also includes the DSM id in the familiar format "<dsmid>,<sid>".
References formatSampleId(), GET_DSM_ID, and nidas::core::getSample().
Referenced by DataStats::createCounters(), SampleDispatcher::findStats(), DataStats::hashId(), DataStats::receive(), SampleDispatcher::SampleDispatcher(), and SampleToDatabase::SampleToDatabase().
std::ostream & nidas::core::NidasApp::formatSampleId | ( | std::ostream & | out, |
dsm_sample_id_t | sid ) |
Write the sensor-plus-sample ID part of sid
to out
using the ID format of this NidasApp instance, the format returned by getIdFormat(), same as calling formatSampleId(out, getIdFormat(),
sid).
References formatSampleId(), and getIdFormat().
|
static |
Write the sensor-plus-sample ID part of sid
to stream out
using the format specified in idfmt
.
This does not print the DSM ID, only the SPS ID.
References AUTO_ID, DECIMAL_ID, nidas::core::NidasApp::IdFormat::decimalWidth(), GET_SHORT_ID, nidas::core::getSample(), HEX_ID, nidas::core::NidasApp::IdFormat::idFormat(), and OCTAL_ID.
Referenced by formatId(), formatSampleId(), DataStats::printReport(), and DumpClient::receive().
|
static |
Return the current application instance.
References application_instance.
Referenced by SampleToDatabase::accumulate(), main(), parseRunstring(), DumpClient::printHeader(), DataStats::printReport(), DumpClient::receive(), SampleCounter::receive(), SampleToDatabase::SampleToDatabase(), PConfig::usage(), and usage().
nidas_app_arglist_t nidas::core::NidasApp::getArguments | ( | ) |
Return the list of arguments which are supported by this NidasApp, in other words, the arguments enabled by enableArguments() or requireArguments().
References _app_arguments.
Referenced by checkRequiredArguments().
std::string nidas::core::NidasApp::getConfigsXML | ( | ) |
Derive the path to the XML file which lists project configs.
This uses standard paths parameterized by environment variables, and accepts the first path whose environment variables are set in the environment:
If none of the above paths can be derived because of missing environment variables, then throw InvalidParameterException.
References nidas::core::getSample().
Referenced by nidas::core::DSMServerApp::parseRunstring(), StatsProcess::requireConfigsXML(), and DataPrep::run().
Derive a path to an XML datasets file according to the current environment settings, searching these paths in order:
Parse the derived file and return from it the Dataset with the given name. Throws an exception if the Dataset cannt be loaded.
References nidas::core::getSample(), ILOG, nidas::core::Dataset::putenv(), and WLOG.
Referenced by nidas::core::DSMServerApp::getDataset(), DataPrep::run(), and StatsProcess::run().
|
inline |
Return the EndTime as a UTime.
The value is UTime::MAX unless set by the EndTime argument.
References _endTime.
Referenced by DataPrep::parseRunstring(), NidsMerge::parseRunstring(), and StatsProcess::parseRunstring().
nidas::util::Exception nidas::core::NidasApp::getException | ( | ) |
Return the current exception.
If no exception has been set (hasException() returns false), then the return value is just a default constructed nidas::util::Exception.
References _exception.
Referenced by interrupted().
|
inline |
Return the groupid of the username passed to the Username argument, otherwise 0.
References _groupid.
Referenced by setupProcess().
std::string nidas::core::NidasApp::getHostName | ( | ) |
Return the hostname passed to the Hostname argument, if any, otherwise return the current hostname as returned by gethostname().
References _hostname, nidas::core::getSample(), and PLOG.
Referenced by getShortHostName(), StatsProcess::getStatisticsProcessor(), nidas::core::DSMEngine::initialize(), and nidas::core::DSMServerApp::run().
|
inline |
References _idFormat.
Referenced by formatSampleId(), and DumpClient::printHeader().
|
inline |
References _appname.
Referenced by getProcessName(), NidasApp(), setupDaemonLogging(), setupLogScheme(), TeeI2C::usage(), and nidas::core::DSMEngine::usage().
std::string nidas::core::NidasApp::getProcessName | ( | ) |
Get the process name, as set by setProcessName(), or else return the app name from getName().
References _argv0, and getName().
Referenced by checkPidFile(), DataPrep::matchVariables(), StatsProcess::run(), setupDaemon(), DataPrep::usage(), and nidas::core::DSMServerApp::usage().
Project * nidas::core::NidasApp::getProject | ( | ) |
Return a pointer to the application-wide Project instance.
The lifetime is tied to this NidasApp instance.
References _deleteProject, and nidas::core::Project::getInstance().
std::string nidas::core::NidasApp::getShortHostName | ( | ) |
Like getHostName(), but any '.
' qualifiers are removed and only the unqualified name is returned.
References getHostName().
Referenced by StatsProcess::parseRunstring().
Return sorter length value, or throw std::invalid_argument.
This checks the sorter length against the given min and max after parsing it as a float. Throws NidasAppException if the value is out of range, otherwise returns the value.
References nidas::core::NidasAppArg::asFloat(), nidas::core::NidasAppArg::getValue(), and SorterLength.
Referenced by DataPrep::parseRunstring(), and StatsProcess::parseRunstring().
|
inline |
Return the StartTime as a UTime.
The value is UTime::MIN unless set by the StartTime argument.
References _startTime.
Referenced by DataPrep::parseRunstring(), NidsMerge::parseRunstring(), and StatsProcess::parseRunstring().
|
inline |
Return the userid of the username passed to the Username argument, otherwise 0.
References _userid.
Referenced by setupProcess().
|
inline |
Return the username passed to the Username argument, if enabled, otherwise return an empty string.
References _username.
Referenced by setupProcess().
bool nidas::core::NidasApp::hasException | ( | ) |
|
inline |
Return true when a help option was parsed, meaning the usage info has been requested.
References _help.
Referenced by ARLIngest::parseRunstring(), DataDump::parseRunstring(), DataStats::parseRunstring(), DmdA2dCk::parseRunstring(), DataPrep::parseRunstring(), PacketReader::parseRunstring(), NidsMerge::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMEngine::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), and PConfig::parseRunstring().
|
inline |
References _dataFileNames, and _sockAddr.
Return the value of the global interrupted flag.
If allow_exception
is true, and an exception interruption has been set with setException(), then this call will throw that exception. This allows code which checks NidasApp::interrupted() in a loop to work the usual way but also propagate exceptions from the main loop when they happen elsewhere in the application.
References getException(), nidas::core::getSample(), and hasException().
Referenced by ARLIngest::arl_ingest_one(), DataStats::readHeader(), DataStats::readSamples(), DataStats::run(), DmdA2dCk::run(), DataPrep::run(), NidsMerge::run(), and StatsProcess::run().
void nidas::core::NidasApp::lockMemory | ( | ) |
Attempt mlockall() for this process, first adding the CAP_IPC_LOCK capability if possible.
References _argv0, DLOG, nidas::core::getSample(), ILOG, and WLOG.
Referenced by nidas::core::DSMEngine::initProcess().
nidas_app_arglist_t nidas::core::NidasApp::loggingArgs | ( | ) |
This is a convenience method to return all of the logging-related options in a list, such that this list can be extended if new log options are enabled.
Only LogConfig has a short log option of -l, so if that option does not conflict, it should be safe to enable all of them. The current list contains these options: LogShow, LogConfig, LogFields, LogParam.
References nidas::core::getSample(), LogConfig, LogFields, LogParam, and LogShow.
Referenced by DataStats::DataStats(), main(), ARLIngest::parseRunstring(), DataDump::parseRunstring(), DmdA2dCk::parseRunstring(), DataPrep::parseRunstring(), PacketReader::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMEngine::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), and PConfig::parseRunstring().
int nidas::core::NidasApp::logLevel | ( | ) |
Return LogScheme::logLevel() for the current log scheme.
bool nidas::core::NidasApp::nextArg | ( | std::string & | arg | ) |
If the next argument to be parsed does not start with '-', then copy it into arg
and remove it from the arguments.
Callers can use this to consume multiple arguments for a single option flag. Returns true when the argument exists and has been copied into arg
, otherwise returns false and arg
is unchanged. The returned argument will not be seen by parseNext(), and it will not be returned by unparsedArgs().
References _argi, _argv, and nidas::core::getSample().
Referenced by NidsMerge::parseRunstring().
|
inline |
Return the output file length in seconds.
References _outputFileLength.
Referenced by ARLIngest::parseRunstring(), and NidsMerge::parseRunstring().
|
inline |
Return just the output file pattern specified by an output option, without the file length specifier.
References _outputFileName.
Referenced by ARLIngest::parseRunstring(), and NidsMerge::parseRunstring().
Parse all arguments accepted by this NidasApp in the command-line argument list args
, but only handle the standard arguments.
Any application-specific arguments are only parsed and filled in. This is equivalent to calling startArgs() and then looping over parseNext(), except the caller can not handle individual arguments when they are parsed. For some arguments this works fine, since the last occurrence of an argument on the command-line will be the final value returned by NidasAppArg::getValue(). Returns the remaining unparsed arguments, same as would be returned by unparsedArgs().
This method deliberately does not call checkRequiredArguments(), since arguments like –help need to be handled by the caller even when required arguments are legitimately missing from the argument list. Instead, applications with required arguments should explicitly call checkRequiredArguments() after all required arguments should have been parsed.
The argument vector should not contain the process name. So this is a convenient way to call it from main():
args | Just the arguments, without the process name. |
NidasAppException |
References parseNext(), startArgs(), and unparsedArgs().
Referenced by parseArgs(), ARLIngest::parseRunstring(), DataDump::parseRunstring(), DataStats::parseRunstring(), DmdA2dCk::parseRunstring(), PacketReader::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMEngine::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), and parseRunstring().
Convenience method to convert the (argc, argv) run string to a list of arguments to pass to parseArgs().
Also, if the process name has not been set with setProcessName(), then set it to argv[0].
NidasAppException |
References _argv0, parseArgs(), and setProcessName().
void nidas::core::NidasApp::parseInputs | ( | const std::vector< std::string > & | inputs, |
std::string | default_input = "", | ||
int | default_port = 0 ) |
Parse one or more input URLs from a list of non-option command-line arguments.
The default_input
and default_port
can be passed here to override the defaults set in the InputFiles argument instance. If no inputs are provided, then the defaults are used. If no default is specified, then inputsProvided() will return false. An exception is not thrown just because no inputs were provided.
NidasAppException |
References _dataFileNames, _sockAddr, nidas::core::NidasAppInputFilesArg::default_input, nidas::core::NidasAppInputFilesArg::default_port, nidas::core::getSample(), InputFiles, LOG_DEBUG, and port.
Referenced by DataDump::parseRunstring(), DataStats::parseRunstring(), DmdA2dCk::parseRunstring(), DataPrep::parseRunstring(), and StatsProcess::parseRunstring().
Parse a LogConfig from the given argument using the LogConfig string syntax, and add that LogConfig to the current LogScheme.
NidasAppException |
References _logscheme, nidas::util::LogScheme::addConfig(), err, and nidas::core::getSample().
Referenced by parseLogLevel(), and parseNext().
This is an alias for parseLogConfig(), since the LogConfig string syntax is backwards compatible with parsing just log levels.
NidasAppException |
References parseLogConfig().
NidasAppArg * nidas::core::NidasApp::parseNext | ( | ) |
Parse the next recognized argument from the list set in startArgs().
If it is one of the standard arguments which are members of NidasApp, then handle the argument also. Either way, fill in the NidasAppArg with the flag and value (if any) extracted from the command-line, and return the pointer to that NidasAppArg. If no more arguments are left or none are recognized, then return null. Raise NidasAppException if there is an error parsing any of the standard arguments.
Recognized arguments are removed from the argument list. Call parseRemaining() to return the arguments which have not been parsed, such as to access positional arguments or detect unrecognized arguments. Positional arguments like input sockets and file names are not handled here, since they cannot be differentiated from app-specific arguments yet. Instead those arguments can be passed explicitly to the parseInputs() method.
NidasAppException |
References _app_arguments, _argi, _argv, _brief, _endTime, _help, _hostname, nidas::core::NidasApp::IdFormat::_idFormat, _idFormat, _logscheme, _processData, _sampleMatcher, _startTime, _xmlFileName, nidas::core::SampleMatcher::addCriteria(), nidas::util::LogScheme::addFallback(), allowUnrecognized(), AUTO_ID, DebugDaemon, DECIMAL_ID, EndTime, err, FormatHexId, FormatSampleId, nidas::core::Version::getCompilerDefinitions(), nidas::core::getSample(), nidas::core::Version::getSoftwareVersion(), nidas::core::NidasAppArg::getValue(), Help, HEX_ID, Hostname, LogConfig, LogFields, LogParam, LogShow, NOFORMAT_ID, OCTAL_ID, OutputFiles, parseLogConfig(), parseOutput(), nidas::util::LogScheme::parseParameter(), parseTime(), parseUsername(), ProcessData, SampleRanges, nidas::core::SampleMatcher::setEndTime(), setIdFormat(), nidas::util::LogScheme::setShowFields(), nidas::core::SampleMatcher::setStartTime(), nidas::util::LogScheme::showLogPoints(), StartTime, Username, and XmlHeaderFile.
Referenced by parseArgs(), DataPrep::parseRunstring(), NidsMerge::parseRunstring(), and PConfig::parseRunstring().
Parse an output specifier in the form <strptime-filename-pattern>[<length>[smh]].
NidasAppException |
References _outputFileLength, _outputFileName, err, and nidas::core::getSample().
Referenced by parseNext().
nidas::util::UTime nidas::core::NidasApp::parseTime | ( | const std::string & | optarg | ) |
References nidas::core::getSample().
Referenced by parseNext().
References _groupid, _userid, _username, and nidas::core::getSample().
Referenced by parseNext().
|
inline |
Return the current process-data setting for this NidasApp.
References _processData.
Referenced by DataStats::createCounters(), and DataStats::run().
void nidas::core::NidasApp::requireArguments | ( | const nidas_app_arglist_t & | arglist | ) |
Add arguments to this NidasApp same as enableArguments() but also set them as required.
See NidasAppArg::setRequired(). An application can conveniently check whether required arguments have been set by calling checkRequiredArguments() when all arguments have been parsed.
References enableArguments(), and nidas::core::getSample().
|
inline |
Call acceptShortFlag(false) on the given list of NidasApp instances, meaning only the long flag will be recognized.
References nidas::core::getSample().
Referenced by main().
void nidas::core::NidasApp::resetLogging | ( | ) |
Reset logging to the NidasApp default.
This erases all log schemes, then sets up the default NidasApp log scheme same as happens in the NidasApp constructor.
References setupLogScheme().
|
inline |
Use this method to access the SampleMatcher instance for this NidasApp.
After the SampleMatcher is configured by parsing command-line options, it can be used to select sample IDs like so:
References _sampleMatcher.
Referenced by DataStats::createCounters(), DataDump::parseRunstring(), DataStats::receive(), and SampleDispatcher::SampleDispatcher().
void nidas::core::NidasApp::setApplicationInstance | ( | ) |
An instance of NidasApp can be set as an application-wide instance, like an application context, which other parts of the application can retrieve with getApplicationInstance().
References application_instance.
Referenced by DataDump::DataDump(), DataStats::DataStats(), DmdA2dCk::DmdA2dCk(), main(), and PacketReader::PacketReader().
void nidas::core::NidasApp::setException | ( | const nidas::util::Exception & | ex | ) |
Like setInterrupted(true), but also allows an exception to be stored which can be tested and retrieved later with hasException() and getException().
This is useful, for example, in sample receive() methods which may be called from multiple threads and not necessarily from the main thread where readSamples() is called.
Note the exception type is strictly nidas::util::Exception, so a subclass reference can be passed, but the subclass is stripped when copied by NidasApp.
References _exception, _hasException, nidas::core::getSample(), and setInterrupted().
Referenced by SampleToDatabase::accumulate().
void nidas::core::NidasApp::setFileSetTimes | ( | const nidas::util::UTime & | start, |
const nidas::util::UTime & | end, | ||
nidas::core::FileSet * | fset ) |
References nidas::core::NidasAppArg::asBool(), Clipping, ILOG, nidas::util::UTime::isSet(), and USECS_PER_SEC.
Referenced by DataPrep::run(), and StatsProcess::run().
Store the format in which sample IDs should be shown.
References _idFormat, and nidas::core::getSample().
Referenced by parseNext(), and DataDump::parseRunstring().
Set the global interrupted state for NidasApp.
The default signal handler sets this flag, but this method allows the flag to be set from custom signal handlers or from other parts of the application.
References interrupted.
Referenced by DataStats::handleSignal(), and setException().
void nidas::core::NidasApp::setOutputClipping | ( | const nidas::util::UTime & | start, |
const nidas::util::UTime & | end, | ||
nidas::core::SampleOutputBase * | output ) |
If Clipping has been enabled, call setTimeClippingWindow() on the given output
using start
and end
.
References _endTime, _startTime, nidas::core::NidasAppArg::asBool(), Clipping, nidas::util::UTime::format(), ILOG, and nidas::core::SampleOutputBase::setTimeClippingWindow().
Referenced by DataPrep::run(), and StatsProcess::run().
Set the process-data setting in this NidasApp.
References _processData.
Set the name of this particular process, usually argv[0].
It defaults to the application name passed to the constructor and returned by getName().
References _argv0, and nidas::core::getSample().
Referenced by parseArgs(), and startArgs().
void nidas::core::NidasApp::setupDaemon | ( | ) |
Call setupDaemon(daemon_mode), where daemon_mode is true only if DebugDaemon is false.
References nidas::core::NidasAppArg::asBool(), DebugDaemon, and setupDaemon().
Referenced by setupDaemon().
Call setupDaemonLogging(), then switch this process to daemon mode if daemon_mode
is true.
References getProcessName(), nidas::core::getSample(), and setupDaemonLogging().
Referenced by nidas::core::DSMEngine::initLogger(), nidas::core::DSMServerApp::initLogger(), and StatsProcess::run().
void nidas::core::NidasApp::setupDaemonLogging | ( | ) |
Call setupDaemonLogging(daemon_mode), where daemon_mode is true only if DebugDaemon is false.
References nidas::core::NidasAppArg::asBool(), DebugDaemon, and setupDaemonLogging().
Referenced by setupDaemon(), and setupDaemonLogging().
Setup logging according to daemon mode.
Setup the logging scheme and create a Logger according to the daemon mode. Usually an application just calls setupDaemon(), since that method calls setupDaemonLogging() before switching to a daemon (if not disabled).
References _logscheme, getName(), LogShow, nidas::util::LogScheme::setShowFields(), and nidas::core::NidasAppArg::specified().
|
private |
References _logscheme, nidas::util::LogScheme::addFallback(), getName(), nidas::core::getSample(), and nidas::util::LOGGER_INFO.
Referenced by NidasApp(), and resetLogging().
void nidas::core::NidasApp::setupProcess | ( | ) |
Setup a process with the user and group specified by the Username argument, and attempt to set related capabilities.
References _argv0, DLOG, getGroupID(), nidas::core::getSample(), getUserID(), getUserName(), and WLOG.
Referenced by nidas::core::DSMEngine::initProcess(), and nidas::core::DSMServerApp::initProcess().
Setup signal handling for HUP, INT, and TERM, equivalent to calling addSignal() for each.
References addSignal().
Referenced by DataDump::DataDump(), DataStats::DataStats(), DmdA2dCk::DmdA2dCk(), ARLIngest::main(), DataPrep::main(), NidsMerge::main(), StatsProcess::main(), and setupSignals().
|
inline |
If parseInputs() parsed a network socket specifier, then this method returns a pointer to the corresponding SocketAddress.
Otherwise it returns null. The NidasApp instance owns the pointer.
References _sockAddr.
Referenced by DataPrep::parseRunstring(), StatsProcess::parseRunstring(), DataStats::run(), DataPrep::run(), and StatsProcess::run().
Set the list of command-line argument strings to be parsed and handled by successive calls to nextArgument().
The usual calling sequence is this:
References _argi, _argv, and nidas::core::getSample().
Referenced by parseArgs(), DataPrep::parseRunstring(), NidsMerge::parseRunstring(), PConfig::parseRunstring(), and startArgs().
Convenience method to convert the (argc, argv) run string to a list of arguments to pass to startArgs().
Also, if the process name has not been set with setProcessName(), then set it to argv[0].
NidasAppException |
References _argv0, setProcessName(), and startArgs().
ArgVector nidas::core::NidasApp::unparsedArgs | ( | ) |
References _argv.
Referenced by parseArgs(), DataPrep::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), and PConfig::parseRunstring().
Return a usage string describing the arguments accepted by this application, rendering each argument by calling NidasAppArg::usage() with the given indent
string and brief
parameter.
References _app_arguments, nidas::core::getSample(), and nidas::core::NidasAppArg::usage().
Referenced by DataPrep::usage(), TeeI2C::usage(), nidas::core::DSMEngine::usage(), nidas::core::DSMServerApp::usage(), ARLIngest::usage(), DataStats::usage(), DmdA2dCk::usage(), PacketReader::usage(), NidsMerge::usage(), StatsProcess::usage(), DataDump::usage(), usage(), and usage().
std::string nidas::core::NidasApp::usage | ( | const std::string & | indent = " " | ) |
|
inline |
References _xmlFileName.
Referenced by ARLIngest::parseRunstring(), DataPrep::parseRunstring(), StatsProcess::parseRunstring(), parseRunstring(), DataStats::run(), and DmdA2dCk::run().
|
private |
Referenced by allowUnrecognized(), and allowUnrecognized().
|
private |
Referenced by enableArguments(), getArguments(), parseNext(), and usage().
|
private |
Referenced by getName().
|
private |
Referenced by nextArg(), parseNext(), and startArgs().
|
private |
Referenced by nextArg(), parseNext(), startArgs(), and unparsedArgs().
|
private |
Referenced by getProcessName(), lockMemory(), parseArgs(), setProcessName(), setupProcess(), and startArgs().
|
private |
Referenced by briefHelp(), parseNext(), and usage().
|
private |
Referenced by dataFileNames(), inputsProvided(), and parseInputs().
|
private |
Referenced by getProject(), and ~NidasApp().
|
private |
Referenced by getEndTime(), parseNext(), and setOutputClipping().
|
private |
Referenced by getException(), and setException().
|
private |
Referenced by getGroupID(), and parseUsername().
|
private |
Referenced by hasException(), and setException().
|
private |
Referenced by helpRequested(), and parseNext().
|
private |
Referenced by getHostName(), and parseNext().
|
private |
Referenced by getIdFormat(), parseNext(), and setIdFormat().
|
private |
NidasApp keeps track of the LogScheme built up from arguments.
Referenced by parseLogConfig(), parseNext(), setupDaemonLogging(), and setupLogScheme().
|
private |
Referenced by outputFileLength(), and parseOutput().
|
private |
Referenced by outputFileName(), and parseOutput().
|
private |
Referenced by parseNext(), processData(), and setProcessData().
|
private |
Referenced by parseNext(), and sampleMatcher().
|
private |
Referenced by inputsProvided(), parseInputs(), and socketAddress().
|
private |
Referenced by getStartTime(), parseNext(), and setOutputClipping().
|
private |
Referenced by getUserID(), and parseUsername().
|
private |
Referenced by getUserName(), and parseUsername().
|
private |
Referenced by parseNext(), and xmlHeaderFile().
|
staticprivate |
Referenced by getApplicationInstance(), setApplicationInstance(), and ~NidasApp().
NidasAppArg nidas::core::NidasApp::Clipping |
Referenced by DataPrep::parseRunstring(), StatsProcess::parseRunstring(), setFileSetTimes(), and setOutputClipping().
NidasAppArg nidas::core::NidasApp::ConfigsArg |
Referenced by NidasApp(), and nidas::core::DSMServerApp::parseRunstring().
NidasAppArg nidas::core::NidasApp::DatasetName |
NidasAppArg nidas::core::NidasApp::DebugDaemon |
NidasAppArg nidas::core::NidasApp::EndTime |
NidasAppArg nidas::core::NidasApp::FormatHexId |
Referenced by DataStats::DataStats(), parseNext(), and DataDump::parseRunstring().
NidasAppArg nidas::core::NidasApp::FormatSampleId |
Referenced by DataStats::DataStats(), parseNext(), and DataDump::parseRunstring().
NidasAppArg nidas::core::NidasApp::Help |
Referenced by DataStats::DataStats(), main(), parseNext(), ARLIngest::parseRunstring(), DataDump::parseRunstring(), DmdA2dCk::parseRunstring(), DataPrep::parseRunstring(), PacketReader::parseRunstring(), NidsMerge::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMEngine::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), and PConfig::parseRunstring().
NidasAppArg nidas::core::NidasApp::Hostname |
NidasAppInputFilesArg nidas::core::NidasApp::InputFiles |
NidasAppArg nidas::core::NidasApp::LogConfig |
Referenced by loggingArgs(), main(), parseNext(), and NidsMerge::parseRunstring().
NidasAppArg nidas::core::NidasApp::LogFields |
Referenced by loggingArgs(), parseNext(), and NidsMerge::parseRunstring().
NidasAppArg nidas::core::NidasApp::LogParam |
Referenced by loggingArgs(), parseNext(), and NidsMerge::parseRunstring().
NidasAppArg nidas::core::NidasApp::LogShow |
Referenced by loggingArgs(), parseNext(), NidsMerge::parseRunstring(), and setupDaemonLogging().
NidasAppArg nidas::core::NidasApp::OutputFiles |
Referenced by parseNext(), ARLIngest::parseRunstring(), and NidsMerge::parseRunstring().
NidasAppArg nidas::core::NidasApp::PidFile |
It is not enough to enable this arg in an app, the app must must call checkPidFile() as well.
Referenced by checkPidFile(), NidasApp(), and nidas::core::DSMEngine::parseRunstring().
NidasAppArg nidas::core::NidasApp::ProcessData |
Referenced by DataStats::DataStats(), parseNext(), and DataDump::parseRunstring().
NidasAppArg nidas::core::NidasApp::SampleRanges |
Referenced by DataStats::DataStats(), parseNext(), and DataDump::parseRunstring().
NidasAppArg nidas::core::NidasApp::SorterLength |
Referenced by getSorterLength(), DataPrep::parseRunstring(), and StatsProcess::parseRunstring().
NidasAppArg nidas::core::NidasApp::StartTime |
NidasAppArg nidas::core::NidasApp::Username |
NidasAppArg nidas::core::NidasApp::Version |
Referenced by DataStats::DataStats(), ARLIngest::parseRunstring(), DataDump::parseRunstring(), DmdA2dCk::parseRunstring(), DataPrep::parseRunstring(), PacketReader::parseRunstring(), NidsMerge::parseRunstring(), StatsProcess::parseRunstring(), TeeI2C::parseRunstring(), nidas::core::DSMEngine::parseRunstring(), nidas::core::DSMServerApp::parseRunstring(), and PConfig::parseRunstring().
NidasAppArg nidas::core::NidasApp::XmlHeaderFile |