nidas  v1.2-1520
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 
40 namespace nidas { namespace core {
41 
42 class Project;
43 class DSMConfig;
44 class DSMSensor;
45 class SensorHandler;
46 class SamplePipeline;
47 class DSMEngineIntf;
48 class XMLConfigInput;
49 class DSMEngineStat;
50 
55 public:
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  {
139  return command == DSM_QUIT || command == DSM_REBOOT || command == DSM_SHUTDOWN;
140  }
141 
142  enum command getCommand() const { return _command; }
143 
144 private:
145 
147 
153  void setupSignals();
154 
158  void waitForSignal(int secs);
159 
165  void initialize(xercesc::DOMDocument* projectDoc)
167 
168  void startXmlRpcThread() throw(nidas::util::Exception);
169 
170  void killXmlRpcThread() throw();
171 
172  void openSensors() throw(nidas::util::IOException);
173 
174  void connectOutputs() throw(nidas::util::IOException);
175 
176  void connectProcessors() throw(nidas::util::IOException,
177  nidas::util::InvalidParameterException);
178 
179  void disconnectProcessors() throw();
180 
181  void closeOutputs() throw();
182 
183  void interrupt();
184 
185  void deleteDataThreads() throw();
186 
187  void joinDataThreads() throw();
188 
193  void connect(SampleOutput*) throw();
194 
195  void disconnect(SampleOutput*) throw();
196 
200  void connect(SampleInput*) throw() { assert(false); }
201 
205  void disconnect(SampleInput*) throw() { assert(false); }
206 
210 
212 
217  bool _syslogit;
218 
220  std::string _configFile;
221 
226 
228 
230 
232 
234 
239 
242 
246  std::set<SampleOutput*> _outputSet;
247 
249 
251 
252  sigset_t _signalMask;
253 
254  pthread_t _myThreadId;
255 
257 
260 
262  DSMEngine(const DSMEngine&);
263 
265  DSMEngine& operator=(const DSMEngine&);
266 
267 };
268 
269 }} // namespace nidas namespace core
270 
271 #endif
272 
Definition: DSMEngine.h:135
Interface for an object that requests connections SampleOutputs.
Definition: ConnectionRequester.h:42
void interrupt()
Definition: DSMEngine.cc:458
void joinDataThreads()
Definition: DSMEngine.cc:469
enum command _command
Definition: DSMEngine.h:211
void killXmlRpcThread()
Definition: DSMEngine.cc:647
bool quitCommand(enum command command)
Definition: DSMEngine.h:137
static DSMEngine * getInstance()
Get a pointer to the singleton instance of DSMEngine created by main().
Definition: DSMEngine.h:75
void registerSensorWithXmlRpc(const std::string &devname, DSMSensor *)
Sensors register with the DSMEngineIntf XmlRpcThread if they have a executeXmlRpc() method which can ...
Definition: DSMEngine.cc:664
static int main(int argc, char **argv)
Entry point to run a DSMEngine process from a command line.
Definition: DSMEngine.cc:141
void deleteDataThreads()
Definition: DSMEngine.cc:534
enum nidas::core::DSMEngine::run_states _runState
SensorHandler implements a DSMSensor event loop.
Definition: SensorHandler.h:87
DSMEngineIntf * _xmlrpcThread
This thread provides XML-based Remote Procedure calls.
Definition: DSMEngine.h:241
void disconnect(SampleInput *)
DSMEngine does not receive SampleInputs, so these will die with an assert.
Definition: DSMEngine.h:205
void start()
Starts the main loop (for the XMLRPC call).
Definition: DSMEngine.cc:550
Definition: DSMEngine.h:209
void initLogger()
Initialize the Logger.
Definition: DSMEngine.cc:296
Definition: DSMEngine.h:135
Interface of an output stream of samples.
Definition: SampleOutput.h:47
Class that should include all that is configurable about a DSM.
Definition: DSMConfig.h:55
void openSensors()
Definition: DSMEngine.cc:690
void waitForSignal(int secs)
Unblock and wait for signals of interest.
Definition: DSMEngine.cc:600
A IP version 4 socket address, containing a host address, and a port number.
Definition: Inet4SocketAddress.h:41
void shutdown()
Quits the main loop, and spawns a &quot;halt&quot; shell command.
Definition: DSMEngine.cc:575
Definition: DSMEngine.h:135
void startXmlRpcThread()
Definition: DSMEngine.cc:638
int initProcess()
Initialize various process parameters, uid, etc.
Definition: DSMEngine.cc:301
void usage()
Print runstring usage to stderr.
Definition: DSMEngine.cc:280
DSMEngineStat * _statusThread
A thread that generates streaming XML time and status.
Definition: DSMEngine.h:238
DSMEngine()
Definition: DSMEngine.cc:83
DSMEngine & operator=(const DSMEngine &)
No assignment.
run_states
Definition: DSMEngine.h:209
void restart()
Restarts the main loop (for the XMLRPC call).
Definition: DSMEngine.cc:565
bool _externalControl
Definition: DSMEngine.h:207
nidas::util::Inet4SocketAddress _configSockAddr
Address to use when fishing for the XML configuration.
Definition: DSMEngine.h:225
void connectOutputs()
Definition: DSMEngine.cc:719
~DSMEngine()
Nuke it.
Definition: DSMEngine.cc:111
bool _syslogit
Whether to log messages on syslog (true) or stderr (false).
Definition: DSMEngine.h:217
std::string _configFile
Name of XML configuration file.
Definition: DSMEngine.h:220
const DSMConfig * getDSMConfig() const
Definition: DSMEngine.h:122
int run()
main loop
Definition: DSMEngine.cc:314
Definition: DSMEngine.h:209
void disconnectProcessors()
Definition: DSMEngine.cc:846
void stop()
Stops the main loop (for the XMLRPC call).
Definition: DSMEngine.cc:559
void quit()
Quit the main loop.
Definition: DSMEngine.cc:570
void connect(SampleOutput *)
Implementation of SampleConnectionRequester connect methods.
Definition: DSMEngine.cc:738
A NidasAppArg is command-line argument which can be handled by NidasApp.
Definition: NidasApp.h:73
Definition: DSMEngine.h:209
void setupSignals()
Create a signal mask, and block those masked signals.
Definition: DSMEngine.cc:587
Application for running the NIDAS data acquistion process.
Definition: DSMEngine.h:54
SamplePipeline * _pipeline
Definition: DSMEngine.h:233
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
static DSMEngine * _instance
Definition: DSMEngine.h:146
int _logLevel
Definition: DSMEngine.h:250
Definition: DSMEngine.h:135
int parseRunstring(int argc, char **argv)
Parse the runstring parameters.
Definition: DSMEngine.cc:212
NidasApp handles common options for NIDAS applications.
Definition: NidasApp.h:572
NidasAppArg DisableAutoConfig
Definition: DSMEngine.h:259
NidasAppArg ExternalControl
Definition: DSMEngine.h:258
Definition: DSMEngine.h:135
enum command getCommand() const
Definition: DSMEngine.h:142
std::set< SampleOutput * > _outputSet
Connected SampleOutputs.
Definition: DSMEngine.h:246
Thread which provides status in XML form from a dsm on a datagram socket, to be read by the status_li...
Definition: StatusThread.h:112
nidas::util::Mutex _outputMutex
Definition: DSMEngine.h:248
Project * _project
Definition: DSMEngine.h:227
void disconnect(SampleOutput *)
How SampleOutputs notify their SampleConnectionRequester that they wish to be closed, likely do to an IOException.
Definition: DSMEngine.cc:755
NidasApp _app
Definition: DSMEngine.h:256
pthread_t _myThreadId
Definition: DSMEngine.h:254
SensorHandler * _selector
Definition: DSMEngine.h:231
Definition: Project.h:60
SamplePipeline sorts samples that are coming from one or more inputs.
Definition: SamplePipeline.h:79
bool _disableAutoconfig
Definition: DSMEngine.h:208
void reboot()
Quits the main loop, and spawns a &quot;reboot&quot; shell command.
Definition: DSMEngine.cc:581
const SensorHandler * getSensorHandler() const
Definition: DSMEngine.h:124
Definition: DSMEngine.h:135
A thread that provides XML-based Remote Procedure Calls to web interfaces from the DSMEngine...
Definition: DSMEngineIntf.h:44
void closeOutputs()
Definition: DSMEngine.cc:784
void initialize(xercesc::DOMDocument *projectDoc)
Initialize the DSMEngine based on the parameters in the DOMDocument.
Definition: DSMEngine.cc:669
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
DSMConfig * _dsmConfig
Definition: DSMEngine.h:229
sigset_t _signalMask
Definition: DSMEngine.h:252
command
Definition: DSMEngine.h:135
void connectProcessors()
Definition: DSMEngine.cc:826
Definition: InvalidParameterException.h:35
Interface of an input SampleSource.
Definition: SampleInput.h:47