nidas  v1.2-1520
Public Member Functions | Private Member Functions | Private Attributes | List of all members
nidas::core::IODevice Class Referenceabstract

An interface to an IO device. More...

#include <IODevice.h>

Inheritance diagram for nidas::core::IODevice:
Inheritance graph
[legend]

Public Member Functions

 IODevice ()
 
virtual ~IODevice ()
 
virtual void setName (const std::string &val)
 Set the device name to be opened for this sensor. More...
 
virtual const std::string & getName () const
 
virtual void open (int flags)=0 throw (nidas::util::IOException,nidas::util::InvalidParameterException)
 Open the device. More...
 
virtual int getReadFd () const =0
 The file descriptor used when reading from this sensor. More...
 
virtual int getWriteFd () const =0
 The file descriptor used when writing to this sensor. More...
 
virtual size_t read (void *buf, size_t len)=0 throw (nidas::util::IOException)
 Read from the sensor. More...
 
virtual size_t read (void *buf, size_t len, int msecTimeout)=0 throw (nidas::util::IOException)
 Read from the sensor with a millisecond timeout. More...
 
virtual size_t getBytesAvailable () const throw (nidas::util::IOException)
 Return how many bytes are available to read on this IODevice. More...
 
virtual size_t write (const void *buf, size_t len)=0 throw (nidas::util::IOException)
 Write to the sensor. More...
 
virtual void ioctl (int request, void *buf, size_t len)=0 throw (nidas::util::IOException)
 
virtual void close ()=0 throw (nidas::util::IOException)
 Close the device. More...
 

Private Member Functions

 IODevice (const IODevice &)
 Derived classes don't implement copy so we won't here. More...
 
IODeviceoperator= (const IODevice &)
 Derived classes don't implement assignment so we won't here. More...
 

Private Attributes

std::string _devname
 Whether to reopen this sensor on an IOException. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

nidas::core::IODevice::IODevice ( )
inline
virtual nidas::core::IODevice::~IODevice ( )
inlinevirtual
nidas::core::IODevice::IODevice ( const IODevice )
private

Derived classes don't implement copy so we won't here.

Member Function Documentation

virtual void nidas::core::IODevice::close ( )
throw (nidas::util::IOException
)
pure virtual
virtual size_t nidas::core::IODevice::getBytesAvailable ( ) const
throw (nidas::util::IOException
)
inlinevirtual

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.

References err, getName(), getReadFd(), and ioctl().

Referenced by nidas::core::DSMSensor::getBytesAvailable().

virtual const std::string& nidas::core::IODevice::getName ( ) const
inlinevirtual
virtual int nidas::core::IODevice::getReadFd ( ) const
pure virtual
virtual int nidas::core::IODevice::getWriteFd ( ) const
pure virtual
virtual void nidas::core::IODevice::ioctl ( int  request,
void *  buf,
size_t  len 
)
throw (nidas::util::IOException
)
pure virtual
virtual void nidas::core::IODevice::open ( int  flags)
throw (nidas::util::IOException,
nidas::util::InvalidParameterException
)
pure virtual

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::UnixIODevice, nidas::core::SerialPortIODevice, nidas::core::ServerSocketIODevice, nidas::core::SocketIODevice, nidas::core::UDPSocketIODevice, and nidas::core::TCPSocketIODevice.

IODevice& nidas::core::IODevice::operator= ( const IODevice )
private

Derived classes don't implement assignment so we won't here.

virtual size_t nidas::core::IODevice::read ( void *  buf,
size_t  len 
)
throw (nidas::util::IOException
)
pure virtual
virtual size_t nidas::core::IODevice::read ( void *  buf,
size_t  len,
int  msecTimeout 
)
throw (nidas::util::IOException
)
pure virtual
virtual void nidas::core::IODevice::setName ( const std::string &  val)
inlinevirtual

Set the device name to be opened for this sensor.

References _devname.

Referenced by nidas::core::UnixIODevice::UnixIODevice().

virtual size_t nidas::core::IODevice::write ( const void *  buf,
size_t  len 
)
throw (nidas::util::IOException
)
pure virtual

Member Data Documentation

std::string nidas::core::IODevice::_devname
private

Whether to reopen this sensor on an IOException.

Referenced by getName(), and setName().


The documentation for this class was generated from the following file: