ApparatusFramework::TcpClientDevice Class Reference
[Device Services]

#include <DeviceServices/Win32/current/include/TcpClientDevice.h>

Inheritance diagram for ApparatusFramework::TcpClientDevice:
ApparatusFramework::CharDevice

List of all members.

Public Member Functions

Construction and Destruction

 TcpClientDevice (const char *host, const uint16 port)
virtual ~TcpClientDevice ()
Interface

Virtual functions for interface definition

virtual int32 open (void *arg)
virtual int32 close ()
virtual int32 read (uint8 *buffer, const int32 count)
virtual int32 write (uint8 *buffer, const int32 count)
virtual int32 ioCtl (uint32 cmd, void *arg)
virtual int32 seek (uint32 offset, SeekWhenceEnum whence)
virtual void flush ()

Detailed Description

Implements a TCP/IP client with a CharDevice interface. This enables the use of TCP sockets wherever a device is needed, e.g. for logging purposes. Due to the limited CharDevice abstraction, only basic features of sockets are available.

Definition at line 61 of file TcpClientDevice.h.


Constructor & Destructor Documentation

ApparatusFramework::TcpClientDevice::TcpClientDevice ( const char *  host,
const uint16  port 
)

Constructs a new TcpClientDevice object. Stores the settings and tries to initialize the winsocket dll. The connection is not established yet, this will be done when the device is opened.

Parameters:
host IP address to be connected, e.g. "127.0.0.1"
port TCP port to be connected, e.g. 49152
virtual ApparatusFramework::TcpClientDevice::~TcpClientDevice (  )  [virtual]

Destructs the object and releases all resources.


Member Function Documentation

virtual int32 ApparatusFramework::TcpClientDevice::close (  )  [virtual]

Closes the device, releases resources used for the operation. After another open, the device is ready for communication again.

Returns:
Returns status of the method.
  • >=0: successful
  • <0: ErrorCode, this value is device dependent.

Implements ApparatusFramework::CharDevice.

virtual void ApparatusFramework::TcpClientDevice::flush (  )  [virtual]

Writes all internally buffered data onto the device and clears the send and receive buffers.

Implements ApparatusFramework::CharDevice.

virtual int32 ApparatusFramework::TcpClientDevice::ioCtl ( uint32  cmd,
void *  arg 
) [virtual]

Universal method that may be used to configure the device and implement functionality not provided by the interface. The meaning of the different commands executed by this function is entirely device dependent (cmd 1 on device A may be something completely different on device B).

Parameters:
cmd A command that specifies the function to be executed by the method
arg A pointer to an argument passed to the function to be executed
Returns:
Returns status of the method.
  • >=0: Successful
  • <0: ErrorCode, this value is device dependent.

Implements ApparatusFramework::CharDevice.

virtual int32 ApparatusFramework::TcpClientDevice::open ( void *  arg  )  [virtual]

Opens a character device. First method to be called after the instantiation. If this method returns successfully, the device is ready to use.

Parameters:
arg A void pointer that can be used for whatever one one choses (default = null).
Returns:
Returns status of the method.
  • 0: Successful
  • >0: ErrorCode, this value is device dependent.

Implements ApparatusFramework::CharDevice.

virtual int32 ApparatusFramework::TcpClientDevice::read ( uint8 buffer,
const int32  count 
) [virtual]

Reads a specified number of characters from the device into a provided buffer. This read method for a device is usually implemented blocking (blocks the calling client).

Parameters:
buffer Pointer to a character buffer. Its the buffer that read will use to fill in the fetched data.
count Number of characters to be read (does not necessarily correspond with the return value).
Returns:
Number of characters read, or error code if < 0.

Implements ApparatusFramework::CharDevice.

virtual int32 ApparatusFramework::TcpClientDevice::seek ( uint32  offset,
SeekWhenceEnum  whence 
) [virtual]

Allows to jump onto a certain position. Seek uses an offset that specifies the location from a certain starting point. (e.g. used in files to write onto a specified position). seek may also be used to find the size of a file (return value of seek(0, SEEK_END)).

Parameters:
offset A number that specifies the amount of chars the wanted position is away from a given starting position (whence defines that).
whence Defines the starting position or how the given index should be interpreted.

  • CHAR_DEVICE_SEEK_START: The seek starts at the beginning of the file.
  • CHAR_DEVICE_SEEK_CURRENT: The seek starts right where we are now (in case we have already read chars).
  • CHAR_DEVICE_SEEK_END: The seek starts at the end of the file.
Returns:
  • >=0: The new offset
  • <0: Error code

Implements ApparatusFramework::CharDevice.

virtual int32 ApparatusFramework::TcpClientDevice::write ( uint8 buffer,
const int32  count 
) [virtual]

Writes a specified number of characters from a buffer onto the device.

Parameters:
buffer Pointer to a character buffer. Its the buffer that write takes as data source.
count Number of characters to be taken out of the buffer onto the device.
Returns:
Number of charaters written, or error code if < 0.

Implements ApparatusFramework::CharDevice.

© 2004-2010 bbv Software Services AG / Apparatus Services