nidas  v1.2-1520
Site.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_SITE_H
28 #define NIDAS_CORE_SITE_H
29 
30 #include "DOMable.h"
31 #include "DSMConfig.h"
32 #include "Parameter.h"
33 #include "Dictionary.h"
34 
35 #include <list>
36 #include <map>
37 
38 namespace nidas { namespace core {
39 
40 class Project;
41 class DSMServer;
42 class DSMConfig;
43 class DSMSensor;
44 
49 class Site : public DOMable {
50 public:
51  Site();
52 
53  virtual ~Site();
54 
58  void setName(const std::string& val) { _name = val; }
59 
60  const std::string& getName() const { return _name; }
61 
68  void setNumber(int val) { _number = val; }
69 
70  int getNumber() const { return _number; }
71 
75  bool operator == (const Site& x) const
76  {
77  if (this == &x) return true;
78  return _name == x._name &&
79  _suffix == x._suffix &&
80  _number == x._number;
81  }
82 
86  bool operator != (const Site& x) const
87  {
88  return !operator == (x);
89  }
90 
94  bool operator < (const Site& x) const
95  {
96  if (operator == (x)) return false;
97  return _name.compare(x._name) < 0;
98  }
99 
104  void setSuffix(const std::string& val) { _suffix = val; }
105 
106  const std::string& getSuffix() const { return _suffix; }
107 
111  const Project* getProject() const { return _project; }
112 
113  Project* getProject() { return _project; }
114 
118  void setProject(Project* val) { _project = val; }
119 
126  {
127  _dsms.push_back(dsm);
128  _ncDsms.push_back(dsm);
129  }
130 
132  {
133  std::list<const DSMConfig*>::iterator di;
134  for (di = _dsms.begin(); di != _dsms.end(); )
135  if (dsm == *di) di = _dsms.erase(di);
136  else ++di;
137  for (std::list<DSMConfig*>::iterator di = _ncDsms.begin();
138  di != _ncDsms.end(); )
139  if (dsm == *di) {
140  DSMConfig* deletableDSMConfig = *di;
141  di = _ncDsms.erase(di);
142  // The DSM configuration has been removed from both lists, now delete the object.
143  delete deletableDSMConfig;
144  }
145  else ++di;
146  }
147 
148  const std::list<const DSMConfig*>& getDSMConfigs() const
149  {
150  return _dsms;
151  }
152 
153  const std::list<DSMConfig*>& getDSMConfigs()
154  {
155  return _ncDsms;
156  }
157 
161  void addServer(DSMServer* srvr) { _servers.push_back(srvr); }
162 
163  const std::list<DSMServer*>& getServers() const { return _servers; }
164 
170  DSMServer* findServer(const std::string& hostname) const;
171 
176  const DSMConfig* findDSM(const nidas::util::Inet4Address& addr) const;
177 
181  const DSMConfig* findDSM(unsigned int id) const;
182 
186  const DSMConfig* findDSM(const std::string& name) const;
187 
191  DSMSensor* findSensor(unsigned int id) const;
192 
196  void initSensors() throw(nidas::util::IOException);
197 
201  void initSensors(DSMConfig* dsm) throw(nidas::util::IOException);
202 
208  virtual void addParameter(Parameter* val);
209 
210  virtual const Parameter* getParameter(const std::string& name) const;
211 
212  virtual const std::list<const Parameter*>& getParameters() const;
213 
219  virtual bool getApplyVariableConversions() const
220  {
221  return _applyCals;
222  }
223 
235  std::string expandString(const std::string& input) const
236  {
237  return _dictionary.expandString(input);
238  }
239 
244  bool getTokenValue(const std::string& token,std::string& value) const
245  {
246  return _dictionary.getTokenValue(token,value);
247  }
248 
249  const Dictionary& getDictionary() const
250  {
251  return _dictionary;
252  }
253 
255 
257 
259 
261 
263 
265 
267 
268  void validate()
269  throw(nidas::util::InvalidParameterException);
270 
271  void fromDOMElement(const xercesc::DOMElement*)
272  throw(nidas::util::InvalidParameterException);
273 
274  xercesc::DOMElement*
275  toDOMParent(xercesc::DOMElement* parent,bool complete) const
276  throw(xercesc::DOMException);
277 
278  xercesc::DOMElement*
279  toDOMElement(xercesc::DOMElement* node,bool complete) const
280  throw(xercesc::DOMException);
281 
282 private:
283 
288 
289  std::string _name;
290 
291  int _number;
292 
293  std::string _suffix;
294 
295  class MyDictionary : public Dictionary {
296  public:
297  MyDictionary(Site* site): _site(site) {}
298  MyDictionary(const MyDictionary& x): Dictionary(),_site(x._site) {}
300  {
301  if (&rhs != this) {
302  *(Dictionary*) this = rhs;
303  _site = rhs._site;
304  }
305  return *this;
306  }
307  bool getTokenValue(const std::string& token, std::string& value) const;
308  private:
310  } _dictionary;
311 
312  std::list<const DSMConfig*> _dsms;
313 
314  std::list<DSMConfig*> _ncDsms;
315 
316  std::list<DSMServer*> _servers;
317 
321  std::map<std::string,Parameter*> _parameterMap;
322 
327  std::list<const Parameter*> _constParameters;
328 
332  Site(const Site&);
333 
337  Site& operator=(const Site&);
338 
339 protected:
344 
345 };
346 
347 }} // namespace nidas namespace core
348 
349 #endif
void setSuffix(const std::string &val)
Set the suffix for the Site.
Definition: Site.h:104
Class for iterating over the DSMServers of a Project.
Definition: NidsIterators.h:66
virtual void addParameter(Parameter *val)
Add a parameter to this Site.
Definition: Site.cc:135
Interface for a Dictionary class, which can return a string value for a string token name...
Definition: Dictionary.h:38
const std::string & getSuffix() const
Definition: Site.h:106
std::list< DSMConfig * > _ncDsms
Definition: Site.h:314
ProcessorIterator getProcessorIterator() const
Definition: Site.cc:79
virtual ~Site()
Definition: Site.cc:52
std::list< const DSMConfig * > _dsms
Definition: Site.h:312
const std::list< const DSMConfig * > & getDSMConfigs() const
Definition: Site.h:148
A measurement site.
Definition: Site.h:49
Definition: Site.h:295
const std::string & getName() const
Definition: Site.h:60
Project * getProject()
Definition: Site.h:113
const std::list< DSMConfig * > & getDSMConfigs()
Definition: Site.h:153
SensorIterator getSensorIterator() const
Definition: Site.cc:89
const DSMConfig * findDSM(const nidas::util::Inet4Address &addr) const
Find a DSM whose name corresponds to a given IP address.
Definition: Site.cc:404
std::list< DSMServer * > _servers
Definition: Site.h:316
Class that should include all that is configurable about a DSM.
Definition: DSMConfig.h:55
Class for iterating over the Variables of a Project, Site, DSMConfig, DSMSensor, or SampleTag...
Definition: NidsIterators.h:286
MyDictionary & operator=(const MyDictionary &rhs)
Definition: Site.h:299
bool _applyCals
Should NIDAS apply calibrations, or defer them to other processing.
Definition: Site.h:343
std::string expandString(const std::string &input) const
Utility function to expand ${TOKEN} or $TOKEN fields in a string.
Definition: Site.h:235
Site * _site
Definition: Site.h:309
VariableIterator getVariableIterator() const
Definition: Site.cc:99
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method...
Definition: DOMable.h:51
void setProject(Project *val)
Set the current project for this Site.
Definition: Site.h:118
std::string expandString(const std::string &input) const
Utility function that scans a string for tokens like ${XXXX}, or $XXX followed by any characters from...
Definition: Dictionary.cc:33
xercesc::DOMElement * toDOMParent(xercesc::DOMElement *parent, bool complete) const
Create a DOMElement and append it to the parent.
Definition: Site.cc:339
void setName(const std::string &val)
Set the name of the Site.
Definition: Site.h:58
bool getTokenValue(const std::string &token, std::string &value) const
Implement a lookup for tokens that I know about, like $SITE, and $AIRCRAFT.
Definition: Site.h:244
virtual bool getApplyVariableConversions() const
Do we want DSMSensor::process methods at this site to apply variable conversions? Currently on raf...
Definition: Site.h:219
SampleTagIterator getSampleTagIterator() const
Definition: Site.cc:94
xercesc::DOMElement * toDOMElement(xercesc::DOMElement *node, bool complete) const
Add my content into a DOMElement.
Definition: Site.cc:350
Class for iterating over the Processors of a DSMServer or DSMConfig.
Definition: NidsIterators.h:149
Class for iterating over the DSMServices of a DSMServer.
Definition: NidsIterators.h:91
Site & operator=(const Site &)
Assignment not supported.
DSMServiceIterator getDSMServiceIterator() const
Definition: Site.cc:74
const std::list< DSMServer * > & getServers() const
Definition: Site.h:163
const Project * getProject() const
Provide pointer to Project.
Definition: Site.h:111
DSMServer * findServer(const std::string &hostname) const
Look for a server on this aircraft that either has no name or whose name matches hostname.
Definition: Site.cc:375
Site()
Definition: Site.cc:43
void initSensors()
Initialize all sensors for a Site.
Definition: Site.cc:107
std::string _name
Definition: Site.h:289
bool operator<(const Site &x) const
Less than operator for Site, compares the names.
Definition: Site.h:94
nidas::core::Site::MyDictionary _dictionary
const Dictionary & getDictionary() const
Definition: Site.h:249
DSMConfigIterator getDSMConfigIterator() const
Definition: Site.cc:84
void addServer(DSMServer *srvr)
A Site has one or more DSMServers.
Definition: Site.h:161
std::string _suffix
Definition: Site.h:293
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
Definition: Parameter.h:46
void setNumber(int val)
Identify the Site by number.
Definition: Site.h:68
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition: NidsIterators.h:217
void validate()
Definition: Site.cc:262
std::map< std::string, Parameter * > _parameterMap
Mapping of Parameters, by name.
Definition: Site.h:321
Class for iterating over the DSMSensors of a Project, Site, or DSMConfig.
Definition: NidsIterators.h:185
int _number
Definition: Site.h:291
DSMSensor * findSensor(unsigned int id) const
Find a DSMSensor by the full id, both the DSM id and the sensor id.
Definition: Site.cc:446
MyDictionary(const MyDictionary &x)
Definition: Site.h:298
Definition: Project.h:60
virtual const std::list< const Parameter * > & getParameters() const
Definition: Site.cc:148
bool getTokenValue(const std::string &token, std::string &value) const
Definition: Site.cc:465
DSMServerIterator getDSMServerIterator() const
Definition: Site.cc:69
A provider of services to a DSM.
Definition: DSMServer.h:50
Class for iterating over the DSMConfigs of a Project or Site.
Definition: NidsIterators.h:124
virtual const Parameter * getParameter(const std::string &name) const
Definition: Site.cc:141
int getNumber() const
Definition: Site.h:70
void removeDSMConfig(DSMConfig *dsm)
Definition: Site.h:131
MyDictionary(Site *site)
Definition: Site.h:297
Support for IP version 4 host address.
Definition: Inet4Address.h:46
std::list< const Parameter * > _constParameters
List of const pointers to Parameters for providing via getParameters().
Definition: Site.h:327
Project * _project
Pointer back to my project.
Definition: Site.h:287
bool operator!=(const Site &x) const
Non-equivalence operator for Site.
Definition: Site.h:86
void fromDOMElement(const xercesc::DOMElement *)
Initialize myself from a xercesc::DOMElement.
Definition: Site.cc:153
bool operator==(const Site &x) const
Equivalence operator for Site, checks name.
Definition: Site.h:75
void addDSMConfig(DSMConfig *dsm)
A Site contains one or more DSMs.
Definition: Site.h:125