nidas  v1.2-1520
SampleOutput.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  ** 2006, 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_SAMPLEOUTPUT_H
28 #define NIDAS_CORE_SAMPLEOUTPUT_H
29 
30 #include "Sample.h"
31 #include "SampleClient.h"
32 #include "Parameter.h"
33 #include "IOStream.h"
34 #include "HeaderSource.h"
35 #include "ConnectionRequester.h"
36 
37 // #include <nidas/util/McSocket.h>
38 
39 namespace nidas { namespace core {
40 
41 class DSMConfig;
42 class SampleTag;
43 
47 class SampleOutput: public SampleClient, public IOChannelRequester, public DOMable
48 {
49 public:
50 
51  virtual ~SampleOutput() {}
52 
57  virtual SampleOutput* getOriginal() const = 0;
58 
59  virtual void setName(const std::string& val) = 0;
60 
61  virtual const std::string& getName() const = 0;
62 
63  virtual bool isRaw() const = 0;
64 
72  virtual void addRequestedSampleTag(SampleTag* tag)
74 
75  virtual std::list<const SampleTag*> getRequestedSampleTags() const = 0;
76 
83  virtual void addSourceSampleTag(const SampleTag* tag)
85 
86  virtual void addSourceSampleTags(const std::list<const SampleTag*>& tags)
88 
89  virtual std::list<const SampleTag*> getSourceSampleTags() const = 0;
90 
101  throw(nidas::util::IOException) = 0;
102 
110  virtual int getReconnectDelaySecs() const = 0;
111 
112  virtual void setReconnectDelaySecs(int val) = 0;
113 
114  virtual int getFd() const = 0;
115 
116  virtual IOChannel* getIOChannel() const = 0;
117 
122  virtual size_t write(const void* buf, size_t len)
123  throw(nidas::util::IOException) = 0;
124 
125  virtual void close() throw(nidas::util::IOException) = 0;
126 
127  virtual void setHeaderSource(HeaderSource* val) = 0;
128 
129  virtual void setDSMConfig(const DSMConfig* val) = 0;
130 
131  virtual const DSMConfig* getDSMConfig() const = 0;
132 
133  virtual void setLatency(float val)
134  throw(nidas::util::InvalidParameterException) = 0;
135 
136  virtual float getLatency() const = 0;
137 
138 protected:
139 
140  virtual SampleOutput* clone(IOChannel* iochannel) = 0;
141 
142 };
143 
148 {
149 public:
150 
152 
159 
160  ~SampleOutputBase();
161 
170  virtual void setIOChannel(IOChannel* val);
171 
172  SampleOutput* getOriginal() const
173  {
174  return _original;
175  }
176 
177  void setName(const std::string& val) { _name = val; }
178 
179  const std::string& getName() const { return _name; }
180 
181  bool isRaw() const { return false; }
182 
185 
186  std::list<const SampleTag*> getRequestedSampleTags() const;
187 
188  void addSourceSampleTag(const SampleTag* tag)
190 
191  void addSourceSampleTags(const std::list<const SampleTag*>& tags)
193 
194  std::list<const SampleTag*> getSourceSampleTags() const;
195 
203  throw(nidas::util::IOException);
204 
212  SampleOutput* connected(IOChannel* ochan) throw();
213 
219  int getReconnectDelaySecs() const;
220 
221  void setReconnectDelaySecs(int val);
222 
223  int getFd() const;
224 
225  void close() throw(nidas::util::IOException);
226 
227  dsm_time_t getNextFileTime() const { return _nextFileTime; }
228 
229  void createNextFile(dsm_time_t) throw(nidas::util::IOException);
230 
235  size_t write(const void* buf, size_t len)
236  throw(nidas::util::IOException) override;
237 
238  void fromDOMElement(const xercesc::DOMElement* node)
239  throw(nidas::util::InvalidParameterException);
240 
241  IOChannel* getIOChannel() const { return _iochan; }
242 
244  {
245  _headerSource = val;
246  }
247 
248  void setDSMConfig(const DSMConfig* val)
249  {
250  _dsm = val;
251  }
252 
253  const DSMConfig* getDSMConfig() const
254  {
255  return _dsm;
256  }
257 
258  size_t getNumDiscardedSamples() const { return _nsamplesDiscarded; }
259 
266  void addParameter(Parameter* val);
267 
271  const std::list<const Parameter*>& getParameters() const
272  {
273  return _constParameters;
274  }
275 
280  const Parameter* getParameter(const std::string& name) const;
281 
290  void setLatency(float val)
292  {
293  _latency = val;
294  }
295 
296  float getLatency() const { return _latency; }
297 
298 protected:
303 
304  size_t incrementDiscardedSamples() { return _nsamplesDiscarded++; }
305 
307  {
308  return _connectionRequester;
309  }
310 
311  std::string _name;
312 
324  void disconnect() throw(nidas::util::IOException);
325 
326 private:
327 
328  mutable nidas::util::Mutex _tagsMutex;
329 
330  std::list<SampleTag*> _requestedTags;
331 
332  std::list<const SampleTag*> _constRequestedTags;
333 
334  IOChannel* _iochan;
335 
336  SampleConnectionRequester* _connectionRequester;
337 
338  dsm_time_t _nextFileTime;
339 
340  HeaderSource* _headerSource;
341 
342  const DSMConfig* _dsm;
343 
344  size_t _nsamplesDiscarded;
345 
349  std::map<std::string,Parameter*> _parameters;
350 
355  std::list<const Parameter*> _constParameters;
356 
357  std::list<const SampleTag*> _sourceTags;
358 
362  SampleOutput* _original;
363 
364  float _latency;
365 
366  int _reconnectDelaySecs;
367 
372 
376  SampleOutputBase& operator=(const SampleOutputBase&);
377 
378 };
379 
380 }} // namespace nidas namespace core
381 
382 #endif
Interface for an object that requests connections SampleOutputs.
Definition: ConnectionRequester.h:42
virtual void setName(const std::string &val)=0
virtual ~SampleOutput()
Definition: SampleOutput.h:51
virtual void setDSMConfig(const DSMConfig *val)=0
virtual std::list< const SampleTag * > getRequestedSampleTags() const =0
const std::string & getName() const
Definition: SampleOutput.h:179
virtual SampleOutput * clone(IOChannel *iochannel)=0
virtual int getReconnectDelaySecs() const =0
Derived classes implement this to indicate whether a connection should be requested again if one fail...
virtual void fromDOMElement(const xercesc::DOMElement *)=0
Initialize myself from a xercesc::DOMElement.
const DSMConfig * getDSMConfig() const
Definition: SampleOutput.h:253
virtual void requestConnection(SampleConnectionRequester *)=0
Request a connection, of this SampleOutput, but don&#39;t wait for it.
An interface for sending a SampleHeader to a SampleOutput.
Definition: HeaderSource.h:42
virtual std::list< const SampleTag * > getSourceSampleTags() const =0
std::string _name
Definition: SampleOutput.h:311
void setName(const std::string &val)
Definition: SampleOutput.h:177
float getLatency() const
Definition: SampleOutput.h:296
virtual IOChannelRequester * connected(IOChannel *)=0
Interface of an output stream of samples.
Definition: SampleOutput.h:47
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC...
Definition: Sample.h:61
Class that should include all that is configurable about a DSM.
Definition: DSMConfig.h:55
virtual void addRequestedSampleTag(SampleTag *tag)=0
Some SampleOutputs don&#39;t send out all the Samples that they receive.
virtual void close()=0
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method...
Definition: DOMable.h:51
Implementation of portions of SampleOutput.
Definition: SampleOutput.h:147
virtual const DSMConfig * getDSMConfig() const =0
SampleOutput * getOriginal() const
Get pointer to SampleOutput that was cloned.
Definition: SampleOutput.h:172
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
void setHeaderSource(HeaderSource *val)
Definition: SampleOutput.h:243
virtual float getLatency() const =0
virtual void addSourceSampleTags(const std::list< const SampleTag * > &tags)=0
A channel for Input or Output of data.
Definition: IOChannel.h:64
virtual void setLatency(float val)=0
void setLatency(float val)
Set desired latency, providing some control over the response time vs buffer efficiency tradeoff...
Definition: SampleOutput.h:290
virtual void setReconnectDelaySecs(int val)=0
virtual SampleOutput * getOriginal() const =0
Get pointer to SampleOutput that was cloned.
virtual size_t write(const void *buf, size_t len)=0
Plain raw write, typically only used to write an initial header.
SampleConnectionRequester * getSampleConnectionRequester()
Definition: SampleOutput.h:306
virtual IOChannel * getIOChannel() const =0
size_t incrementDiscardedSamples()
Definition: SampleOutput.h:304
int len
Definition: sing.cc:934
Definition: Parameter.h:46
virtual bool isRaw() const =0
virtual int getFd() const =0
virtual const std::string & getName() const =0
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
virtual void addSourceSampleTag(const SampleTag *tag)=0
Some SampleOutputs like to be informed of what SampleTags they will be receiving from their SampleSou...
virtual void setHeaderSource(HeaderSource *val)=0
bool isRaw() const
Definition: SampleOutput.h:181
const std::list< const Parameter * > & getParameters() const
Get list of parameters.
Definition: SampleOutput.h:271
void setDSMConfig(const DSMConfig *val)
Definition: SampleOutput.h:248
Interface for an object that requests connections to Inputs or Outputs.
Definition: IOChannel.h:54
Definition: InvalidParameterException.h:35
size_t getNumDiscardedSamples() const
Definition: SampleOutput.h:258