nidas v1.2.3
IOChannel.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_IOCHANNEL_H
28#define NIDAS_CORE_IOCHANNEL_H
29
30#include "ConnectionInfo.h"
31
32#include "Datagrams.h"
33#include "DOMable.h"
34
35#include "Sample.h"
36
39
40#include <sys/uio.h>
41
42#include <set>
43
44namespace nidas { namespace core {
45
46class DSMService;
47class DSMConfig;
48class IOChannel;
49class SampleTag;
50
56{
57public:
60};
61
65class IOChannel : public DOMable {
66
67public:
68
69 IOChannel();
70
72
74 {
75 if (&rhs != this) {
76 *(DOMable*) this = rhs;
77 _dsm = rhs._dsm;
78 }
79 return *this;
80 }
81
82 virtual ~IOChannel() {}
83
87 virtual IOChannel* clone() const = 0;
88
89 virtual void setName(const std::string& val) = 0;
90
91 virtual const std::string& getName() const = 0;
92
93 /*
94 * The requestType is used when establishing McSocket
95 * connections and is ignored otherwise.
96 */
97 virtual void setRequestType(enum McSocketRequest) {}
98
99 virtual enum McSocketRequest getRequestType() const { return (enum McSocketRequest)0; }
100
107 virtual bool isNewInput() const { return false; }
108
122
123 virtual int getReconnectDelaySecs() const
124 {
125 return 10;
126 }
127
131 virtual void setNonBlocking(bool val) = 0;
132
136 virtual bool isNonBlocking() const = 0;
137
145 virtual IOChannel* connect() = 0;
146
154 virtual const ConnectionInfo& getConnectionInfo() const
155 {
156 return _conInfo;
157 }
158
159 virtual void setConnectionInfo(const ConnectionInfo& val)
160 {
161 _conInfo = val;
162 }
163
167 virtual size_t getBufferSize() const { return 8192; }
168
176 virtual size_t read(void* buf, size_t len) = 0;
177
185 virtual size_t write(const void* buf, size_t len) = 0;
186
194 virtual size_t write(const struct iovec* iov, int iovcnt) = 0;
195
201 virtual void flush()
202 {}
203
207 virtual void close() = 0;
208
209 virtual int getFd() const = 0;
210
214 static IOChannel* createIOChannel(const xercesc::DOMElement* node);
215
228#ifdef DOXYGEN
229 virtual dsm_time_t createFile(dsm_time_t t, bool exact)
230#else
231 virtual dsm_time_t createFile(dsm_time_t, bool)
232#endif
233 {
234 return LONG_LONG_MAX;
235 }
236
242 virtual bool writeNidasHeader() const { return true; }
243
247 virtual void setDSMConfig(const DSMConfig* val)
248 {
249 _dsm = val;
250 }
251
255 virtual const DSMConfig* getDSMConfig() const
256 {
257 return _dsm;
258 }
259
265 virtual void addSampleTag(const nidas::core::SampleTag*);
266
267private:
268
270
272
273};
274
275}} // namespace nidas namespace core
276
277#endif
Extra information associated with an IOChannel concerning the connection.
Definition ConnectionInfo.h:39
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method,...
Definition DOMable.h:51
Class that should include all that is configurable about a DSM.
Definition DSMConfig.h:55
Interface for an object that requests connections to Inputs or Outputs.
Definition IOChannel.h:56
virtual IOChannelRequester * connected(IOChannel *)=0
virtual ~IOChannelRequester()
Definition IOChannel.h:58
A channel for Input or Output of data.
Definition IOChannel.h:65
virtual bool writeNidasHeader() const
Should the NIDAS header be written to this IOChannel? NIDAS headers are not written to DatagramSocket...
Definition IOChannel.h:242
static IOChannel * createIOChannel(const xercesc::DOMElement *node)
Definition IOChannel.cc:44
virtual size_t getBufferSize() const
Return suggested buffer length.
Definition IOChannel.h:167
virtual IOChannel * clone() const =0
Derived classes must provide clone.
IOChannel(const IOChannel &x)
Definition IOChannel.h:71
virtual enum McSocketRequest getRequestType() const
Definition IOChannel.h:99
virtual const std::string & getName() const =0
virtual void setConnectionInfo(const ConnectionInfo &val)
Definition IOChannel.h:159
virtual void requestConnection(IOChannelRequester *)=0
After the IOChannel is configured, a user of IOChannel calls requestConnection to get things started.
virtual void flush()
Default flush implementation does nothing.
Definition IOChannel.h:201
virtual const ConnectionInfo & getConnectionInfo() const
What is the IP address of the host at the other end of the connection.
Definition IOChannel.h:154
virtual void setRequestType(enum McSocketRequest)
Definition IOChannel.h:97
virtual int getReconnectDelaySecs() const
Definition IOChannel.h:123
virtual size_t read(void *buf, size_t len)=0
Physical read method which must be implemented in derived classes.
virtual size_t write(const struct iovec *iov, int iovcnt)=0
Physical write method which must be implemented in derived classes.
virtual bool isNonBlocking() const =0
virtual void addSampleTag(const nidas::core::SampleTag *)
The special NetcdfRPCChannel subclass needs a way to add a SampleTag to the IOChannel through a virtu...
Definition IOChannel.cc:81
ConnectionInfo _conInfo
Definition IOChannel.h:271
virtual void close()=0
virtual void setName(const std::string &val)=0
virtual ~IOChannel()
Definition IOChannel.h:82
IOChannel()
Definition IOChannel.cc:39
virtual const DSMConfig * getDSMConfig() const
What DSM is this IOChannel connected to? May be NULL.
Definition IOChannel.h:255
virtual int getFd() const =0
virtual void setNonBlocking(bool val)=0
const DSMConfig * _dsm
Definition IOChannel.h:269
virtual dsm_time_t createFile(dsm_time_t t, bool exact)
Request that an IOChannel open a new file, with a name based on a time.
Definition IOChannel.h:229
IOChannel & operator=(const IOChannel &rhs)
Definition IOChannel.h:73
virtual void setDSMConfig(const DSMConfig *val)
What DSM is this IOChannel connected to?
Definition IOChannel.h:247
virtual bool isNewInput() const
Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from t...
Definition IOChannel.h:107
virtual size_t write(const void *buf, size_t len)=0
Physical write method which must be implemented in derived classes.
virtual IOChannel * connect()=0
Establish a connection.
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
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
McSocketRequest
Definition Datagrams.h:34
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:62
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
int len
Definition sing.cc:948