nidas v1.2.3
IODevice.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#ifndef NIDAS_CORE_IODEVICE_H
27#define NIDAS_CORE_IODEVICE_H
28
31
32#include <sys/ioctl.h>
33
34namespace nidas { namespace core {
35
42{
43public:
44
46
47 virtual ~IODevice() {}
48
52 virtual void setName(const std::string& val)
53 {
54 _devname = val;
55 }
56
57 virtual const std::string& getName() const
58 {
59 return _devname;
60 }
61
70 virtual void open(int flags) = 0;
71
75 virtual int getReadFd() const = 0;
76
80 virtual int getWriteFd() const = 0;
81
87 virtual size_t read(void *buf, size_t len) = 0;
88
94 virtual size_t read(void *buf, size_t len,int msecTimeout) = 0;
95
122 virtual size_t getBytesAvailable() const
123 {
124 int nbytes;
125 int err = ::ioctl(getReadFd(),FIONREAD,&nbytes);
126 if (err < 0)
127 throw nidas::util::IOException(getName(),"ioctl FIONREAD",errno);
128 return nbytes;
129 }
130
136 virtual size_t write(const void *buf, size_t len) = 0;
137
138 /*
139 * Perform an ioctl on the device. request is an integer
140 * value which must be supported by the device. Normally
141 * this is a value from a header file for the device.
142 *
143 * @throws nidas::util::IOException
144 */
145 virtual void ioctl(int request, void* buf, size_t len) = 0;
146
152 virtual void close() = 0;
153
157 // bool reopenOnIOException() const { return false; }
158
159private:
160
161 std::string _devname;
162
167
172
173
174};
175
176}} // namespace nidas namespace core
177
178#endif
#define err(format, arg...)
Definition ck_lams.cc:55
An interface to an IO device.
Definition IODevice.h:42
virtual void ioctl(int request, void *buf, size_t len)=0
std::string _devname
Whether to reopen this sensor on an IOException.
Definition IODevice.h:161
IODevice(const IODevice &)
Derived classes don't implement copy so we won't here.
virtual size_t read(void *buf, size_t len, int msecTimeout)=0
Read from the sensor with a millisecond timeout.
virtual int getWriteFd() const =0
The file descriptor used when writing to this sensor.
virtual ~IODevice()
Definition IODevice.h:47
virtual size_t write(const void *buf, size_t len)=0
Write to the sensor.
virtual const std::string & getName() const
Definition IODevice.h:57
virtual size_t read(void *buf, size_t len)=0
Read from the sensor.
virtual void close()=0
Close the device.
virtual int getReadFd() const =0
The file descriptor used when reading from this sensor.
virtual void open(int flags)=0
Open the device.
virtual void setName(const std::string &val)
Set the device name to be opened for this sensor.
Definition IODevice.h:52
virtual size_t getBytesAvailable() const
Return how many bytes are available to read on this IODevice.
Definition IODevice.h:122
IODevice()
Definition IODevice.h:45
IODevice & operator=(const IODevice &)
Derived classes don't implement assignment so we won't here.
Definition IOException.h:37
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
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
int len
Definition sing.cc:948