nidas v1.2.3
|
Application for running the NIDAS data acquistion process. More...
#include <DSMEngine.h>
Public Types | |
enum | command { DSM_STOP , DSM_RUN , DSM_QUIT , DSM_RESTART , DSM_REBOOT , DSM_SHUTDOWN } |
Public Member Functions | |
DSMEngine () | |
~DSMEngine () | |
Nuke it. | |
void | initLogger () |
Initialize the Logger. | |
int | initProcess () |
Initialize various process parameters, uid, etc. | |
int | run () throw () |
main loop | |
int | parseRunstring (int argc, char **argv) |
Parse the runstring parameters. | |
void | usage () |
Print runstring usage to stderr. | |
void | start () |
Starts the main loop (for the XMLRPC call). | |
void | stop () |
Stops the main loop (for the XMLRPC call). | |
void | restart () |
Restarts the main loop (for the XMLRPC call). | |
void | quit () |
Quit the main loop. | |
void | shutdown () |
Quits the main loop, and spawns a "halt" shell command. | |
void | reboot () |
Quits the main loop, and spawns a "reboot" shell command. | |
const DSMConfig * | getDSMConfig () const |
const SensorHandler * | getSensorHandler () const |
void | registerSensorWithXmlRpc (const std::string &devname, DSMSensor *) |
Sensors register with the DSMEngineIntf XmlRpcThread if they have a executeXmlRpc() method which can be invoked with a "SensorAction" XmlRpc request. | |
bool | quitCommand (enum command command) |
enum command | getCommand () const |
Static Public Member Functions | |
static int | main (int argc, char **argv) throw () |
Entry point to run a DSMEngine process from a command line. | |
static DSMEngine * | getInstance () |
Get a pointer to the singleton instance of DSMEngine created by main(). | |
Private Types | |
enum | run_states { DSM_RUNNING , DSM_ERROR , DSM_STOPPED } |
Private Member Functions | |
void | setupSignals () |
Create a signal mask, and block those masked signals. | |
void | waitForSignal (int secs) |
Unblock and wait for signals of interest. | |
void | initialize (xercesc::DOMDocument *projectDoc) |
Initialize the DSMEngine based on the parameters in the DOMDocument. | |
void | startXmlRpcThread () |
void | killXmlRpcThread () |
void | openSensors () |
void | connectOutputs () |
void | connectProcessors () |
void | disconnectProcessors () throw () |
void | closeOutputs () throw () |
void | interrupt () |
void | deleteDataThreads () throw () |
void | joinDataThreads () throw () |
void | connect (SampleOutput *) throw () |
Implementation of SampleConnectionRequester connect methods. | |
void | disconnect (SampleOutput *) throw () |
How SampleOutputs notify their SampleConnectionRequester that they wish to be closed, likely do to an IOException. | |
void | connect (SampleInput *) throw () |
DSMEngine does not receive SampleInputs, so this will die with an assert. | |
void | disconnect (SampleInput *) throw () |
DSMEngine does not receive SampleInputs, so these will die with an assert. | |
DSMEngine (const DSMEngine &) | |
No copy. | |
DSMEngine & | operator= (const DSMEngine &) |
No assignment. | |
Private Attributes | |
bool | _externalControl |
bool | _disableAutoconfig |
enum nidas::core::DSMEngine::run_states | _runState |
enum command | _command |
bool | _syslogit |
Whether to log messages on syslog (true) or stderr (false). | |
std::string | _configFile |
Name of XML configuration file. | |
nidas::util::Inet4SocketAddress | _configSockAddr |
Address to use when fishing for the XML configuration. | |
Project * | _project |
DSMConfig * | _dsmConfig |
SensorHandler * | _selector |
SamplePipeline * | _pipeline |
DSMEngineStat * | _statusThread |
A thread that generates streaming XML time and status. | |
DSMEngineIntf * | _xmlrpcThread |
This thread provides XML-based Remote Procedure calls. | |
std::set< SampleOutput * > | _outputSet |
Connected SampleOutputs. | |
nidas::util::Mutex | _outputMutex |
int | _logLevel |
sigset_t | _signalMask |
pthread_t | _myThreadId |
NidasApp | _app |
NidasAppArg | ExternalControl |
NidasAppArg | DisableAutoConfig |
Static Private Attributes | |
static DSMEngine * | _instance = 0 |
Application for running the NIDAS data acquistion process.
DSMEngine::DSMEngine | ( | ) |
References _configSockAddr, NIDAS_MULTICAST_ADDR, NIDAS_SVC_REQUEST_PORT_UDP, and setupSignals().
DSMEngine::~DSMEngine | ( | ) |
|
private |
References _dsmConfig, _outputMutex, _outputSet, _pipeline, nidas::core::SampleOutput::close(), nidas::core::SampleClient::flush(), nidas::core::SampleOutputRequestThread::getInstance(), nidas::core::SampleOutput::getName(), nidas::core::SampleOutput::getOriginal(), nidas::core::DSMConfig::getOutputs(), nidas::core::SamplePipeline::getProcessedSampleSource(), nidas::core::SamplePipeline::getRawSampleSource(), nidas::core::getSample(), nidas::core::SampleOutput::isRaw(), nidas::util::Mutex::lock(), LOG_ERR, nidas::core::SampleSource::removeSampleClient(), and nidas::util::Mutex::unlock().
Referenced by run().
|
inlineprivate |
DSMEngine does not receive SampleInputs, so this will die with an assert.
References nidas::core::getSample().
|
privatevirtual |
Implementation of SampleConnectionRequester connect methods.
This is how DSMEngine is notified of remote connections.
Implements nidas::core::SampleConnectionRequester.
References LOG_INFO.
|
private |
nidas::util::IOException |
References _dsmConfig, _pipeline, nidas::core::SampleOutput::addSourceSampleTags(), DLOG, nidas::core::SampleOutputRequestThread::getInstance(), nidas::core::SampleOutput::getName(), nidas::core::DSMConfig::getOutputs(), nidas::core::SamplePipeline::getProcessedSampleSource(), nidas::core::SamplePipeline::getRawSampleSource(), nidas::core::getSample(), and nidas::core::SampleOutput::isRaw().
Referenced by run().
|
private |
|
private |
References _pipeline, _selector, _statusThread, nidas::core::DerivedDataReader::deleteInstance(), and nidas::core::DerivedDataReader::getInstance().
Referenced by run().
|
inlineprivate |
DSMEngine does not receive SampleInputs, so these will die with an assert.
References nidas::core::getSample().
|
privatevirtual |
How SampleOutputs notify their SampleConnectionRequester that they wish to be closed, likely do to an IOException.
Implements nidas::core::SampleConnectionRequester.
References nidas::core::SampleOutputRequestThread::getInstance(), nidas::core::SampleOutput::getOriginal(), and LOG_ERR.
|
private |
References _dsmConfig, _pipeline, nidas::core::SampleIOProcessor::disconnectSource(), and nidas::core::DSMConfig::getProcessorIterator().
Referenced by run().
References _dsmConfig.
Get a pointer to the singleton instance of DSMEngine created by main().
References _instance.
Referenced by nidas::core::DSMEngineIntf::DSMAction::execute(), nidas::dynld::DSC_A2DSensor::open(), nidas::dynld::raf::A2D_Serial::open(), nidas::dynld::raf::DSMAnalogSensor::open(), nidas::dynld::raf::PSI9116_Sensor::open(), and nidas::core::DSMEngineStat::run().
|
inline |
References _selector.
|
private |
Initialize the DSMEngine based on the parameters in the DOMDocument.
This method initializes the Project object, _project from the DOM, and sets the value of _dsmConfig.
nidas::util::InvalidParameterException |
References _app, _configFile, _disableAutoconfig, _dsmConfig, _project, nidas::core::Project::disableAutoconfig(), nidas::core::Project::findDSM(), nidas::core::Project::fromDOMElement(), nidas::core::NidasApp::getHostName(), nidas::core::DSMConfig::getName(), ILOG, and nidas::core::Project::setConfigName().
Referenced by run().
void DSMEngine::initLogger | ( | ) |
Initialize the Logger.
References _app, and nidas::core::NidasApp::setupDaemon().
int DSMEngine::initProcess | ( | ) |
Initialize various process parameters, uid, etc.
References _app, nidas::core::NidasApp::checkPidFile(), nidas::core::NidasApp::lockMemory(), and nidas::core::NidasApp::setupProcess().
|
private |
|
private |
|
private |
)
References _xmlrpcThread, DLOG, nidas::core::XmlRpcThread::interrupt(), nidas::util::Thread::join(), and WLOG.
Entry point to run a DSMEngine process from a command line.
main creates an instance of DSMEngine, passes it the command line arguments and calls the run method.
References nidas::core::DSMSensor::deleteLooper(), nidas::core::getSample(), ILOG, NSECS_PER_SEC, PLOG, and nidas::core::XMLImplementation::terminate().
Referenced by main().
|
private |
nidas::util::IOException |
References _dsmConfig, _pipeline, _selector, nidas::core::SamplePipeline::connect(), nidas::core::DSMConfig::getProcHeapMax(), nidas::core::DSMConfig::getProcLateSampleCacheSize(), nidas::core::DSMConfig::getProcSorterLength(), nidas::core::DSMConfig::getRawHeapMax(), nidas::core::DSMConfig::getRawLateSampleCacheSize(), nidas::core::DSMConfig::getRawSorterLength(), nidas::core::DSMConfig::getRemoteSerialSocketPort(), nidas::core::getSample(), nidas::core::DSMConfig::getSensors(), LOG_INFO, nidas::core::DSMConfig::openSensors(), nidas::core::SamplePipeline::setKeepStats(), nidas::core::SamplePipeline::setProcHeapMax(), nidas::core::SamplePipeline::setProcLateSampleCacheSize(), nidas::core::SamplePipeline::setProcSorterLength(), nidas::core::SamplePipeline::setRawHeapMax(), nidas::core::SamplePipeline::setRawLateSampleCacheSize(), nidas::core::SamplePipeline::setRawSorterLength(), nidas::core::SamplePipeline::setRealTime(), nidas::util::Thread::setRealTimeFIFOPriority(), and nidas::util::Thread::start().
Referenced by run().
Parse the runstring parameters.
If the runstring parameters are not OK, then DSMEngine::usage() is called to print a message to stderr, and this method then returns a error value of 1.
References _app, _configFile, _configSockAddr, _externalControl, nidas::core::NidasAppArg::asBool(), nidas::core::NidasApp::DebugDaemon, DisableAutoConfig, nidas::core::NidasApp::enableArguments(), ExternalControl, nidas::core::getSample(), nidas::core::NidasApp::Help, nidas::core::NidasApp::helpRequested(), nidas::core::NidasApp::Hostname, nidas::core::NidasApp::loggingArgs(), NIDAS_MULTICAST_ADDR, NIDAS_SVC_REQUEST_PORT_UDP, nidas::core::NidasApp::parseArgs(), nidas::core::NidasApp::PidFile, port, usage(), nidas::core::NidasApp::Username, and nidas::core::NidasApp::Version.
void DSMEngine::quit | ( | ) |
Quit the main loop.
References _myThreadId, and nidas::core::getSample().
References DSM_QUIT, DSM_REBOOT, and DSM_SHUTDOWN.
Referenced by run().
void DSMEngine::reboot | ( | ) |
Quits the main loop, and spawns a "reboot" shell command.
References _command, _myThreadId, DSM_REBOOT, and nidas::core::getSample().
Sensors register with the DSMEngineIntf XmlRpcThread if they have a executeXmlRpc() method which can be invoked with a "SensorAction" XmlRpc request.
devname | string matching the "device" XmlRpc parameter, typically the device name. |
References _xmlrpcThread, and nidas::core::DSMEngineIntf::registerSensor().
void DSMEngine::restart | ( | ) |
Restarts the main loop (for the XMLRPC call).
References _myThreadId, and nidas::core::getSample().
int DSMEngine::run | ( | ) | ||||
throw | ( | ) |
main loop
References _command, _configFile, _configSockAddr, _dsmConfig, _project, _runState, _signalMask, _statusThread, closeOutputs(), connectOutputs(), connectProcessors(), nidas::core::DerivedDataReader::createInstance(), deleteDataThreads(), disconnectProcessors(), DSM_ERROR, DSM_RESTART, DSM_RUN, DSM_RUNNING, DSM_STOP, nidas::core::DSMConfig::getDerivedDataSocketAddr(), nidas::core::SampleOutputRequestThread::getInstance(), nidas::core::getSample(), nidas::core::DSMConfig::getStatusSocketAddr(), initialize(), interrupt(), joinDataThreads(), openSensors(), nidas::core::parseXMLConfigFile(), PLOG, quitCommand(), nidas::core::requestXMLConfig(), nidas::util::Thread::start(), nidas::core::XMLImplementation::terminate(), and waitForSignal().
|
private |
Create a signal mask, and block those masked signals.
DSMEngine uses sigwait, and does not register asynchronous signal handlers.
References _signalMask, and nidas::core::getSample().
Referenced by DSMEngine().
void DSMEngine::shutdown | ( | ) |
Quits the main loop, and spawns a "halt" shell command.
References _command, _myThreadId, DSM_SHUTDOWN, and nidas::core::getSample().
void DSMEngine::start | ( | ) |
Starts the main loop (for the XMLRPC call).
References _command, _myThreadId, DSM_RUN, and nidas::core::getSample().
|
private |
nidas::util::Exception |
References _externalControl, _xmlrpcThread, and nidas::util::Thread::start().
void DSMEngine::stop | ( | ) |
Stops the main loop (for the XMLRPC call).
References _command, _myThreadId, DSM_STOP, and nidas::core::getSample().
void DSMEngine::usage | ( | ) |
Print runstring usage to stderr.
References _app, nidas::core::NidasApp::getName(), nidas::core::getSample(), NIDAS_MULTICAST_ADDR, NIDAS_SVC_REQUEST_PORT_UDP, and nidas::core::NidasApp::usage().
Referenced by parseRunstring().
Unblock and wait for signals of interest.
References _command, _signalMask, DSM_QUIT, DSM_RESTART, nidas::core::getSample(), ILOG, PLOG, timeoutSecs, and WLOG.
Referenced by run().
|
private |
Referenced by initialize(), initLogger(), initProcess(), parseRunstring(), and usage().
Referenced by getCommand(), reboot(), run(), shutdown(), start(), stop(), and waitForSignal().
|
private |
Name of XML configuration file.
If empty, multicast for config.
Referenced by initialize(), parseRunstring(), and run().
|
private |
Address to use when fishing for the XML configuration.
Referenced by DSMEngine(), parseRunstring(), and run().
|
private |
Referenced by initialize().
|
private |
Referenced by closeOutputs(), connectOutputs(), connectProcessors(), disconnectProcessors(), getDSMConfig(), initialize(), openSensors(), and run().
|
private |
Referenced by parseRunstring(), and startXmlRpcThread().
|
staticprivate |
Referenced by getInstance().
|
private |
|
private |
|
private |
Referenced by closeOutputs().
|
private |
Connected SampleOutputs.
Referenced by closeOutputs().
|
private |
Referenced by closeOutputs(), connectOutputs(), connectProcessors(), deleteDataThreads(), disconnectProcessors(), interrupt(), joinDataThreads(), and openSensors().
|
private |
Referenced by initialize(), run(), and ~DSMEngine().
|
private |
Referenced by run().
|
private |
Referenced by deleteDataThreads(), getSensorHandler(), interrupt(), joinDataThreads(), and openSensors().
|
private |
Referenced by run(), setupSignals(), and waitForSignal().
|
private |
A thread that generates streaming XML time and status.
Referenced by deleteDataThreads(), interrupt(), joinDataThreads(), run(), and ~DSMEngine().
|
private |
Whether to log messages on syslog (true) or stderr (false).
Set to false from -d runstring option, otherwise true.
|
private |
This thread provides XML-based Remote Procedure calls.
Referenced by killXmlRpcThread(), registerSensorWithXmlRpc(), startXmlRpcThread(), and ~DSMEngine().
|
private |
Referenced by parseRunstring().
|
private |
Referenced by parseRunstring().