nidas  v1.2-1520
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 
37 #include <nidas/util/IOException.h>
39 
40 #include <sys/uio.h>
41 
42 #include <set>
43 
44 namespace nidas { namespace core {
45 
46 class DSMService;
47 class DSMConfig;
48 class IOChannel;
49 
55 {
56 public:
57  virtual ~IOChannelRequester() {}
58  virtual IOChannelRequester* connected(IOChannel*) throw() = 0;
59 };
60 
64 class IOChannel : public DOMable {
65 
66 public:
67 
68  IOChannel();
69 
70  IOChannel(const IOChannel& x):DOMable(),_dsm(x._dsm),_conInfo() {}
71 
73  {
74  if (&rhs != this) {
75  *(DOMable*) this = rhs;
76  _dsm = rhs._dsm;
77  }
78  return *this;
79  }
80 
81  virtual ~IOChannel() {}
82 
86  virtual IOChannel* clone() const = 0;
87 
88  virtual void setName(const std::string& val) = 0;
89 
90  virtual const std::string& getName() const = 0;
91 
92  /*
93  * The requestType is used when establishing McSocket
94  * connections and is ignored otherwise.
95  */
96  virtual void setRequestType(enum McSocketRequest) {}
97 
98  virtual enum McSocketRequest getRequestType() const { return (enum McSocketRequest)0; }
99 
106  virtual bool isNewInput() const { return false; }
107 
118  virtual void requestConnection(IOChannelRequester*)
119  throw(nidas::util::IOException) = 0;
120 
121  virtual int getReconnectDelaySecs() const
122  {
123  return 10;
124  }
125 
126  virtual void setNonBlocking(bool val)
127  throw(nidas::util::IOException) = 0;
128 
129  virtual bool isNonBlocking() const
130  throw(nidas::util::IOException) = 0;
131 
136  virtual IOChannel* connect()
137  throw(nidas::util::IOException,nidas::util::UnknownHostException) = 0;
138 
146  virtual const ConnectionInfo& getConnectionInfo() const
147  {
148  return _conInfo;
149  }
150 
151  virtual void setConnectionInfo(const ConnectionInfo& val)
152  {
153  _conInfo = val;
154  }
155 
159  virtual size_t getBufferSize() const throw() { return 8192; }
160 
166  virtual size_t read(void* buf, size_t len) throw(nidas::util::IOException) = 0;
167 
173  virtual size_t write(const void* buf, size_t len)
174  throw(nidas::util::IOException) = 0;
175 
181  virtual size_t write(const struct iovec* iov, int iovcnt)
182  throw(nidas::util::IOException) = 0;
183 
187  virtual void flush() throw(nidas::util::IOException) {}
188 
189  virtual void close() throw(nidas::util::IOException) = 0;
190 
191  virtual int getFd() const = 0;
192 
193  static IOChannel* createIOChannel(const xercesc::DOMElement* node)
194  throw(nidas::util::InvalidParameterException);
195 
206 #ifdef DOXYGEN
207  virtual dsm_time_t createFile(dsm_time_t t, bool exact)
209 #else
210  virtual dsm_time_t createFile(dsm_time_t, bool)
211  throw(nidas::util::IOException)
212 #endif
213  {
214  return LONG_LONG_MAX;
215  }
216 
222  virtual bool writeNidasHeader() const { return true; }
223 
227  virtual void setDSMConfig(const DSMConfig* val)
228  {
229  _dsm = val;
230  }
231 
235  virtual const DSMConfig* getDSMConfig() const
236  {
237  return _dsm;
238  }
239 
240 private:
241 
242  const DSMConfig* _dsm;
243 
245 
246 };
247 
248 }} // namespace nidas namespace core
249 
250 #endif
virtual void flush()
Default flush implementation does nothing.
Definition: IOChannel.h:187
McSocketRequest
Definition: Datagrams.h:34
virtual IOChannelRequester * connected(IOChannel *)=0
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
virtual bool isNewInput() const
Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from t...
Definition: IOChannel.h:106
Class that should include all that is configurable about a DSM.
Definition: DSMConfig.h:55
virtual const DSMConfig * getDSMConfig() const
What DSM is this IOChannel connected to? May be NULL.
Definition: IOChannel.h:235
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:207
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method...
Definition: DOMable.h:51
Extra information associated with an IOChannel concerning the connection.
Definition: ConnectionInfo.h:38
ConnectionInfo _conInfo
Definition: IOChannel.h:244
virtual ~IOChannelRequester()
Definition: IOChannel.h:57
A channel for Input or Output of data.
Definition: IOChannel.h:64
virtual void setRequestType(enum McSocketRequest)
Definition: IOChannel.h:96
virtual void setDSMConfig(const DSMConfig *val)
What DSM is this IOChannel connected to?
Definition: IOChannel.h:227
virtual void setConnectionInfo(const ConnectionInfo &val)
Definition: IOChannel.h:151
IOChannel(const IOChannel &x)
Definition: IOChannel.h:70
int len
Definition: sing.cc:934
virtual bool writeNidasHeader() const
Should the NIDAS header be written to this IOChannel? NIDAS headers are not written to DatagramSocket...
Definition: IOChannel.h:222
Definition: IOException.h:37
IOChannel & operator=(const IOChannel &rhs)
Definition: IOChannel.h:72
virtual ~IOChannel()
Definition: IOChannel.h:81
virtual size_t getBufferSize() const
Return suggested buffer length.
Definition: IOChannel.h:159
const DSMConfig * _dsm
Definition: IOChannel.h:242
Interface for an object that requests connections to Inputs or Outputs.
Definition: IOChannel.h:54