nidas v1.2.3
DSMEngine.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2005, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_CORE_DSMENGINE_H
28#define NIDAS_CORE_DSMENGINE_H
29
30#include "ConnectionRequester.h"
31#include "XMLException.h"
32#include "NidasApp.h"
35
36#include <set>
37
38#include <signal.h>
39
40namespace nidas { namespace core {
41
42class Project;
43class DSMConfig;
44class DSMSensor;
45class SensorHandler;
46class SamplePipeline;
47class DSMEngineIntf;
48class XMLConfigInput;
49class DSMEngineStat;
50
55public:
56
57 DSMEngine();
58
62 ~DSMEngine();
63
69 static int main(int argc, char** argv) throw();
70
75 static DSMEngine* getInstance() { return _instance; }
76
80 void initLogger();
81
85 int initProcess();
86
88 int run() throw();
89
97 int parseRunstring(int argc, char** argv);
98
102 void usage();
103
105 void start();
106
108 void stop();
109
111 void restart();
112
114 void quit();
115
117 void shutdown();
118
120 void reboot();
121
122 const DSMConfig* getDSMConfig() const { return _dsmConfig; }
123
124 const SensorHandler* getSensorHandler() const { return _selector; }
125
133 void registerSensorWithXmlRpc(const std::string& devname,DSMSensor*);
134
136
138 {
140 }
141
142 enum command getCommand() const { return _command; }
143
144private:
145
147
153 void setupSignals();
154
158 void waitForSignal(int secs);
159
167 void initialize(xercesc::DOMDocument* projectDoc);
168
172 void startXmlRpcThread();
173
177 void killXmlRpcThread();
178
182 void openSensors();
183
187 void connectOutputs();
188
193 void connectProcessors();
194
195 void disconnectProcessors() throw();
196
197 void closeOutputs() throw();
198
199 void interrupt();
200
201 void deleteDataThreads() throw();
202
203 void joinDataThreads() throw();
204
209 void connect(SampleOutput*) throw();
210
211 void disconnect(SampleOutput*) throw();
212
216 void connect(SampleInput*) throw() { assert(false); }
217
221 void disconnect(SampleInput*) throw() { assert(false); }
222
226
228
234
236 std::string _configFile;
237
242
244
246
248
250
255
258
262 std::set<SampleOutput*> _outputSet;
263
265
267
268 sigset_t _signalMask;
269
270 pthread_t _myThreadId;
271
273
276
279
282
283};
284
285}} // namespace nidas namespace core
286
287#endif
288
int main()
Definition ck_arinc.cc:117
Class that should include all that is configurable about a DSM.
Definition DSMConfig.h:55
A thread that provides XML-based Remote Procedure Calls to web interfaces from the DSMEngine.
Definition DSMEngineIntf.h:45
Thread which provides status in XML form from a dsm on a datagram socket, to be read by the status_li...
Definition StatusThread.h:113
Application for running the NIDAS data acquistion process.
Definition DSMEngine.h:54
SensorHandler * _selector
Definition DSMEngine.h:247
int initProcess()
Initialize various process parameters, uid, etc.
Definition DSMEngine.cc:301
const SensorHandler * getSensorHandler() const
Definition DSMEngine.h:124
void setupSignals()
Create a signal mask, and block those masked signals.
Definition DSMEngine.cc:588
void killXmlRpcThread()
Definition DSMEngine.cc:648
Project * _project
Definition DSMEngine.h:243
void initialize(xercesc::DOMDocument *projectDoc)
Initialize the DSMEngine based on the parameters in the DOMDocument.
Definition DSMEngine.cc:670
nidas::util::Mutex _outputMutex
Definition DSMEngine.h:264
void connectProcessors()
Definition DSMEngine.cc:832
enum nidas::core::DSMEngine::run_states _runState
~DSMEngine()
Nuke it.
Definition DSMEngine.cc:111
NidasApp _app
Definition DSMEngine.h:272
void closeOutputs()
Definition DSMEngine.cc:790
DSMEngineIntf * _xmlrpcThread
This thread provides XML-based Remote Procedure calls.
Definition DSMEngine.h:257
void quit()
Quit the main loop.
Definition DSMEngine.cc:571
std::string _configFile
Name of XML configuration file.
Definition DSMEngine.h:236
sigset_t _signalMask
Definition DSMEngine.h:268
const DSMConfig * getDSMConfig() const
Definition DSMEngine.h:122
DSMEngineStat * _statusThread
A thread that generates streaming XML time and status.
Definition DSMEngine.h:254
command
Definition DSMEngine.h:135
@ DSM_RUN
Definition DSMEngine.h:135
@ DSM_REBOOT
Definition DSMEngine.h:135
@ DSM_QUIT
Definition DSMEngine.h:135
@ DSM_SHUTDOWN
Definition DSMEngine.h:135
@ DSM_STOP
Definition DSMEngine.h:135
@ DSM_RESTART
Definition DSMEngine.h:135
DSMEngine()
Definition DSMEngine.cc:83
void disconnect(SampleInput *)
DSMEngine does not receive SampleInputs, so these will die with an assert.
Definition DSMEngine.h:221
DSMEngine & operator=(const DSMEngine &)
No assignment.
void startXmlRpcThread()
Definition DSMEngine.cc:639
NidasAppArg ExternalControl
Definition DSMEngine.h:274
bool quitCommand(enum command command)
Definition DSMEngine.h:137
void disconnectProcessors()
Definition DSMEngine.cc:852
void registerSensorWithXmlRpc(const std::string &devname, DSMSensor *)
Sensors register with the DSMEngineIntf XmlRpcThread if they have a executeXmlRpc() method which can ...
Definition DSMEngine.cc:665
void waitForSignal(int secs)
Unblock and wait for signals of interest.
Definition DSMEngine.cc:601
void connectOutputs()
Definition DSMEngine.cc:725
void connect(SampleOutput *)
Implementation of SampleConnectionRequester connect methods.
Definition DSMEngine.cc:744
void start()
Starts the main loop (for the XMLRPC call).
Definition DSMEngine.cc:551
enum command _command
Definition DSMEngine.h:227
int run()
main loop
Definition DSMEngine.cc:314
bool _disableAutoconfig
Definition DSMEngine.h:224
void initLogger()
Initialize the Logger.
Definition DSMEngine.cc:296
DSMConfig * _dsmConfig
Definition DSMEngine.h:245
bool _externalControl
Definition DSMEngine.h:223
void deleteDataThreads()
Definition DSMEngine.cc:535
nidas::util::Inet4SocketAddress _configSockAddr
Address to use when fishing for the XML configuration.
Definition DSMEngine.h:241
void openSensors()
Definition DSMEngine.cc:696
void joinDataThreads()
Definition DSMEngine.cc:470
pthread_t _myThreadId
Definition DSMEngine.h:270
bool _syslogit
Whether to log messages on syslog (true) or stderr (false).
Definition DSMEngine.h:233
std::set< SampleOutput * > _outputSet
Connected SampleOutputs.
Definition DSMEngine.h:262
int _logLevel
Definition DSMEngine.h:266
void disconnect(SampleOutput *)
How SampleOutputs notify their SampleConnectionRequester that they wish to be closed,...
Definition DSMEngine.cc:761
int parseRunstring(int argc, char **argv)
Parse the runstring parameters.
Definition DSMEngine.cc:212
SamplePipeline * _pipeline
Definition DSMEngine.h:249
run_states
Definition DSMEngine.h:225
@ DSM_ERROR
Definition DSMEngine.h:225
@ DSM_RUNNING
Definition DSMEngine.h:225
@ DSM_STOPPED
Definition DSMEngine.h:225
void reboot()
Quits the main loop, and spawns a "reboot" shell command.
Definition DSMEngine.cc:582
void shutdown()
Quits the main loop, and spawns a "halt" shell command.
Definition DSMEngine.cc:576
void restart()
Restarts the main loop (for the XMLRPC call).
Definition DSMEngine.cc:566
void stop()
Stops the main loop (for the XMLRPC call).
Definition DSMEngine.cc:560
static DSMEngine * _instance
Definition DSMEngine.h:146
NidasAppArg DisableAutoConfig
Definition DSMEngine.h:275
void interrupt()
Definition DSMEngine.cc:459
static DSMEngine * getInstance()
Get a pointer to the singleton instance of DSMEngine created by main().
Definition DSMEngine.h:75
void usage()
Print runstring usage to stderr.
Definition DSMEngine.cc:280
enum command getCommand() const
Definition DSMEngine.h:142
DSMEngine(const DSMEngine &)
No copy.
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition DSMSensor.h:88
A NidasAppArg is command-line argument which can be handled by NidasApp.
Definition NidasApp.h:76
NidasApp handles common options for NIDAS applications.
Definition NidasApp.h:576
Definition Project.h:60
Interface for an object that requests connections SampleOutputs.
Definition ConnectionRequester.h:43
Interface of an input SampleSource.
Definition SampleInput.h:48
Interface of an output stream of samples.
Definition SampleOutput.h:49
SamplePipeline sorts samples that are coming from one or more inputs.
Definition SamplePipeline.h:80
SensorHandler implements a DSMSensor event loop.
Definition SensorHandler.h:88
A IP version 4 socket address, containing a host address, and a port number.
Definition Inet4SocketAddress.h:41
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31