nidas  v1.2-1520
DSMEngineIntf.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_ENGINEINTF_H
28 #define NIDAS_CORE_ENGINEINTF_H
29 
30 #include "XmlRpcThread.h"
31 #include <nidas/util/IOException.h>
32 #include <xmlrpcpp/XmlRpcException.h>
33 
34 #include <iostream>
35 
36 namespace nidas { namespace core {
37 
38 class DSMSensor;
39 
45 {
46 public:
47  DSMEngineIntf();
48 
49  int run() throw(nidas::util::Exception);
50 
56  void registerSensor(const std::string& devname, DSMSensor* sensor)
57  {
58  _sensorAction.registerSensor(devname,sensor);
59  }
60 
61 private:
62 
67  class DSMAction : public XmlRpc::XmlRpcServerMethod
68  {
69  public:
70  DSMAction(XmlRpc::XmlRpcServer* s) : XmlRpc::XmlRpcServerMethod("DSMAction", s) {}
71  void execute(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result) throw();
72  std::string help() { return std::string("parameter \"action\" should be \"start\", \"stop\", \"restart\", \"quit\", \"reboot\" or \"shutdown\""); }
73 
74  };
75 
82  class SensorAction : public XmlRpc::XmlRpcServerMethod
83  {
84  public:
85  SensorAction(XmlRpc::XmlRpcServer* s) : XmlRpc::XmlRpcServerMethod("SensorAction", s),_nameToSensor() {}
86  void execute(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result) throw();
87 
88  std::string help() { return std::string("parameter \"device\" should match a device name for a DSMSensor that has registered itself with DSMEngineIntf"); }
89 
90  void registerSensor(const std::string& devname, DSMSensor* sensor)
91  {
92  _nameToSensor[devname] = sensor;
93  }
94 
95  private:
96  std::map<std::string,DSMSensor*> _nameToSensor;
97  };
98 
99  XmlRpc::XmlRpcServer* _xmlrpc_server;
102 
104  DSMEngineIntf(const DSMEngineIntf &);
105 
108 };
109 
110 }} // namespace nidas namespace core
111 
112 #endif
DSMAction _dsmAction
Definition: DSMEngineIntf.h:100
SensorAction _sensorAction
Definition: DSMEngineIntf.h:101
Invoke an executeXmlRpc() method on a DSMSensor.
Definition: DSMEngineIntf.h:82
DSMAction(XmlRpc::XmlRpcServer *s)
Definition: DSMEngineIntf.h:70
void execute(XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
Definition: DSMEngineIntf.cc:76
void registerSensor(const std::string &devname, DSMSensor *sensor)
Definition: DSMEngineIntf.h:90
std::string help()
Definition: DSMEngineIntf.h:88
void execute(XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
Definition: DSMEngineIntf.cc:52
Definition: Exception.h:35
void registerSensor(const std::string &devname, DSMSensor *sensor)
Register a sensor to have its executeXmlRpc() method called when a &quot;SensorAction&quot; XmlRpc request come...
Definition: DSMEngineIntf.h:56
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
std::map< std::string, DSMSensor * > _nameToSensor
Definition: DSMEngineIntf.h:96
A thread that provides XML-based Remote Procedure Calls to web interfaces.
Definition: XmlRpcThread.h:39
int run()
The method which will run in its own thread.
Definition: DSMEngineIntf.cc:98
std::string help()
Definition: DSMEngineIntf.h:72
DSMEngineIntf & operator=(const DSMEngineIntf &)
Assignment not needed.
SensorAction(XmlRpc::XmlRpcServer *s)
Definition: DSMEngineIntf.h:85
XmlRpc::XmlRpcServer * _xmlrpc_server
Definition: DSMEngineIntf.h:99
A thread that provides XML-based Remote Procedure Calls to web interfaces from the DSMEngine...
Definition: DSMEngineIntf.h:44
DSMEngineIntf()
Definition: DSMEngineIntf.cc:44
Send a command to a DSMEngine.
Definition: DSMEngineIntf.h:67