nidas v1.2.3
|
An interface to an IO device. More...
#include <IODevice.h>
Public Member Functions | |
IODevice () | |
virtual | ~IODevice () |
virtual void | setName (const std::string &val) |
Set the device name to be opened for this sensor. | |
virtual const std::string & | getName () const |
virtual void | open (int flags)=0 |
Open the device. | |
virtual int | getReadFd () const =0 |
The file descriptor used when reading from this sensor. | |
virtual int | getWriteFd () const =0 |
The file descriptor used when writing to this sensor. | |
virtual size_t | read (void *buf, size_t len)=0 |
Read from the sensor. | |
virtual size_t | read (void *buf, size_t len, int msecTimeout)=0 |
Read from the sensor with a millisecond timeout. | |
virtual size_t | getBytesAvailable () const |
Return how many bytes are available to read on this IODevice. | |
virtual size_t | write (const void *buf, size_t len)=0 |
Write to the sensor. | |
virtual void | ioctl (int request, void *buf, size_t len)=0 |
virtual void | close ()=0 |
Close the device. | |
Private Member Functions | |
IODevice (const IODevice &) | |
Derived classes don't implement copy so we won't here. | |
IODevice & | operator= (const IODevice &) |
Derived classes don't implement assignment so we won't here. | |
Private Attributes | |
std::string | _devname |
Whether to reopen this sensor on an IOException. | |
An interface to an IO device.
The main user of this interface is DSMSensor, which contains an IODevice, using it to do I/O with the underlying device.
|
inline |
|
inlinevirtual |
Derived classes don't implement copy so we won't here.
Close the device.
nidas::util::IOException |
Implemented in nidas::core::ServerSocketIODevice, nidas::core::TCPSocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::UnixIODevice.
Referenced by nidas::core::DSMSensor::close().
Return how many bytes are available to read on this IODevice.
This method is only useful when ioctl FIONREAD is supported on this this IODevice, as for example with a UDP socket. It is not available, and not necessary, on most other devices, like serial ports, TCP sockets, or devices with nidas driver module support, in which case it will return an nidas::util::IOException. It is an optimization for use with UDP sockets, where after select determines that data is available on the socket file descriptor, a read will only read one datagram, even if there are more than one packet available, which would not be optimal if a sensor generated many small packets. Rather than returning back to select, we check if there are more datagrams to read. This is not necessary on other types of IODevices, where it is just a matter of using a big enough buffer to get all (or most) available data after a select.
According to man udp(7), FIONREAD will return 0 if the size of the next packet is 0. So, if select/poll indicate there is data available, one read at least should be done, just in case a sensor sends a datagram of length 0, otherwise it will never be consumed.
nidas::util::IOException |
References err, getName(), getReadFd(), and ioctl().
Referenced by nidas::core::DSMSensor::getBytesAvailable().
References _devname.
Referenced by nidas::core::SerialPortIODevice::applyTermios(), nidas::core::ServerSocketIODevice::close(), nidas::core::TCPSocketIODevice::close(), nidas::core::UDPSocketIODevice::close(), nidas::core::UnixIODevice::close(), getBytesAvailable(), nidas::core::UnixIODevice::ioctl(), nidas::core::ServerSocketIODevice::ioctl(), nidas::core::SocketIODevice::ioctl(), nidas::core::SerialPortIODevice::open(), nidas::core::ServerSocketIODevice::open(), nidas::core::SocketIODevice::open(), nidas::core::UnixIODevice::open(), nidas::core::UnixIODevice::read(), nidas::core::UnixIODevice::read(), nidas::core::SerialPortIODevice::setRTS485(), nidas::core::SerialPortIODevice::write(), and nidas::core::UnixIODevice::write().
The file descriptor used when reading from this sensor.
Implemented in nidas::core::ServerSocketIODevice, nidas::core::TCPSocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::UnixIODevice.
Referenced by getBytesAvailable(), and nidas::core::DSMSensor::getReadFd().
The file descriptor used when writing to this sensor.
Implemented in nidas::core::ServerSocketIODevice, nidas::core::TCPSocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::UnixIODevice.
Referenced by nidas::core::DSMSensor::getWriteFd().
Implemented in nidas::core::UnixIODevice, nidas::core::ServerSocketIODevice, and nidas::core::SocketIODevice.
Referenced by getBytesAvailable(), and nidas::core::DSMSensor::ioctl().
Open the device.
This operation should not block - it should either fail or succeed in a reasonable amount of time, typically less than 1 or 2 seconds.
Implemented in nidas::core::SerialPortIODevice, nidas::core::ServerSocketIODevice, nidas::core::SocketIODevice, nidas::core::TCPSocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::UnixIODevice.
Referenced by nidas::core::DSMSensor::open().
Derived classes don't implement assignment so we won't here.
Read from the sensor.
nidas::util::IOException |
Implemented in nidas::core::ServerSocketIODevice, nidas::core::TCPSocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::UnixIODevice.
Referenced by nidas::core::DSMSensor::read(), and nidas::core::DSMSensor::read().
Read from the sensor with a millisecond timeout.
nidas::util::IOException |
Implemented in nidas::core::ServerSocketIODevice, nidas::core::TCPSocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::UnixIODevice.
Set the device name to be opened for this sensor.
References _devname, and nidas::core::getSample().
Referenced by nidas::core::DSMSensor::open(), and nidas::core::UnixIODevice::UnixIODevice().
Write to the sensor.
nidas::util::IOException |
Implemented in nidas::core::SerialPortIODevice, nidas::core::ServerSocketIODevice, nidas::core::TCPSocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::UnixIODevice.
Referenced by nidas::core::DSMSensor::write().
|
private |