Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

GDataExchange Class Reference

This class implements Grisu's bidirectional data exchange interface based on TCP/IP sockets. More...

List of all members.

Signals

void connectionStateSignal (unsigned char status, char *hostname, int port)
 Raised when the status of the socket connection has changed.


Public Member Functions

 GDataExchange (GDataReader *reader)
 Creates a new data exchange object.

 ~GDataExchange (void)
 Destroys the data exchange object.

bool setupServerSocket (void)
 Finds a free port in the range GDE_PORTRANGE_LO and GDE_PORTRANGE_HI and creates a server socket listening on this port.

void asyncSend (unsigned char *data, unsigned int size)
 Asynchronously sends out data.

unsigned int syncSend (unsigned char *data, unsigned int size)
 Synchronously sends out data.

unsigned int syncRead (unsigned char *buffer, unsigned int size)
 Synchronously reads data.


Private Slots

void acceptedSlot (KSocket *sock)
 Called when the server socket accepted a connection.

void readSlot (KSocket *sock)
 Called when data is available for reading.

void writeSlot (KSocket *sock)
 Called when the socket is ready for writing.

void closeSlot (KSocket *sock)
 Called when the socket connection was closed.


Private Member Functions

void closeServerSocket (void)
 Closes the server socket.


Private Attributes

Q_OBJECT KServerSocket * serverSocket
 The server socket, which controls all connections to clients.

KSocket * socket
 The socket that is used in the current connection.

GBufferoutData
 The outbound data buffer.

GBufferinData
 The inbound data buffer.

GDataReaderdataReader
 Pointer to a class that handles incoming data.

char hostname [GDE_HOSTNAME_MAXLEN]
 The name of the host Grisu is running on.

int port
 The number of the port that is used in the current connection (-1 if no connection has been established so far).


Detailed Description

This class implements Grisu's bidirectional data exchange interface based on TCP/IP sockets.

GDataExchange provides both asynchronous and synchronous I/O on the socket connection.

In asnychronous mode, when incoming data becomes available, this data is read without any interaction from outside this class. After reading has completed, a signal is raised which contains the data as an argument.

Outbound data is buffered within GDataExchange and then sent out asynchronously.

Author:
Holger Wunsch


Constructor & Destructor Documentation

GDataExchange::GDataExchange GDataReader reader  ) 
 

Creates a new data exchange object.

Sets up the server socket.

Parameters:
reader the data reader that handles incoming data.

GDataExchange::~GDataExchange void   ) 
 

Destroys the data exchange object.


Member Function Documentation

void GDataExchange::acceptedSlot KSocket *  sock  )  [private, slot]
 

Called when the server socket accepted a connection.

Parameters:
sock the socket that was created after accepting the connection.

void GDataExchange::asyncSend unsigned char *  data,
unsigned int  size
 

Asynchronously sends out data.

Parameters:
data the data to be sent.
size the size of the data.

void GDataExchange::closeServerSocket void   )  [private]
 

Closes the server socket.

void GDataExchange::closeSlot KSocket *  sock  )  [private, slot]
 

Called when the socket connection was closed.

Parameters:
sock not used.

void GDataExchange::connectionStateSignal unsigned char  status,
char *  hostname,
int  port
[signal]
 

Raised when the status of the socket connection has changed.

Parameters:
status the new connection status (a GDE_STATUS_xxxx constant)
hostname the name of the host Grisu is running on (may be NULL)
port the numer of the port used in the connection (may be -1)

void GDataExchange::readSlot KSocket *  sock  )  [private, slot]
 

Called when data is available for reading.

After all available data was read, it is passed on to dataReader->processData.

Parameters:
sock not used.

bool GDataExchange::setupServerSocket void   ) 
 

Finds a free port in the range GDE_PORTRANGE_LO and GDE_PORTRANGE_HI and creates a server socket listening on this port.

Raises a connectionStateSignal with information about the status of the connection, and also prints the status information to stdout.

Returns:
true if the server socket was set up successfully, false otherwise.

unsigned int GDataExchange::syncRead unsigned char *  buffer,
unsigned int  size
 

Synchronously reads data.

If no data is available, this method immediately returns (non-blocking I/O).

Parameters:
buffer the buffer the data is to be stored in
size the size of the buffer.
Returns:
the number of bytes read, or -1 (0xFFFFFFFF) if no data is available or in case of an error (errno can be queried to get additional information since this function directly calls read(...)).

unsigned int GDataExchange::syncSend unsigned char *  data,
unsigned int  size
 

Synchronously sends out data.

Does not return before the data has been sent. This method performs the same functionality as write(...) from the C library.

Parameters:
data the data to be sent
size the size of the data
Returns:
the number of bytes written, or -1 (0xFFFFFFFF) in case of an error (errno can be queried to get additional information since this function directly calls write(...)).

void GDataExchange::writeSlot KSocket *  sock  )  [private, slot]
 

Called when the socket is ready for writing.

Writes all data on outBuffer to the socket, then deletes the buffer.

Parameters:
sock not used.


Member Data Documentation

GDataReader* GDataExchange::dataReader [private]
 

Pointer to a class that handles incoming data.

char GDataExchange::hostname[GDE_HOSTNAME_MAXLEN] [private]
 

The name of the host Grisu is running on.

GBuffer* GDataExchange::inData [private]
 

The inbound data buffer.

GBuffer* GDataExchange::outData [private]
 

The outbound data buffer.

int GDataExchange::port [private]
 

The number of the port that is used in the current connection (-1 if no connection has been established so far).

Q_OBJECT KServerSocket* GDataExchange::serverSocket [private]
 

The server socket, which controls all connections to clients.

KSocket* GDataExchange::socket [private]
 

The socket that is used in the current connection.


Generated on Sun Apr 27 18:26:58 2003 for Grisu by doxygen1.3