sensorfw
SocketReader Class Reference

Helper class for reading socket datachannel from sensord. More...

#include <socketreader.h>

Inheritance diagram for SocketReader:

Public Member Functions

 SocketReader (QObject *parent=0)
 Constructor. More...
 
 ~SocketReader ()
 Destructor. More...
 
bool initiateConnection (int sessionId)
 Initiates new data socket connection. More...
 
bool dropConnection ()
 Drops socket connection. More...
 
QLocalSocket * socket ()
 Provides access to the internal QLocalSocket for direct reading. More...
 
bool read (void *buffer, int size)
 Attempt to read given number of bytes from the socket. More...
 
template<typename T >
bool read (QVector< T > &values)
 Attempt to read objects from the sockets. More...
 
bool isConnected ()
 Returns whether the socket is currently connected. More...
 

Detailed Description

Helper class for reading socket datachannel from sensord.

SocketReader provides common handler for all sensors using socket data channel. It is used by AbstractSensorChannelInterface to maintain the socket connection to the server.

Definition at line 41 of file socketreader.h.

Constructor & Destructor Documentation

◆ SocketReader()

SocketReader::SocketReader ( QObject *  parent = 0)

Constructor.

Parameters
parentParent QObject.

◆ ~SocketReader()

SocketReader::~SocketReader ( )

Destructor.

Member Function Documentation

◆ dropConnection()

bool SocketReader::dropConnection ( )

Drops socket connection.

Returns
was the connection successfully closed.

◆ initiateConnection()

bool SocketReader::initiateConnection ( int  sessionId)

Initiates new data socket connection.

Parameters
sessionIdID for the current session.
Returns
was the connection established successfully.

◆ isConnected()

bool SocketReader::isConnected ( )

Returns whether the socket is currently connected.

Returns
is socket connected.

◆ read() [1/2]

template<typename T >
bool SocketReader::read ( QVector< T > &  values)

Attempt to read objects from the sockets.

The call blocks until there are minimum amount of expected bytes availabled in the socket.

Parameters
valuesVector to which objects will be appended.
Template Parameters
Ttype of expected object in the stream.
Returns
true if atleast one object was read.

Definition at line 129 of file socketreader.h.

◆ read() [2/2]

bool SocketReader::read ( void *  buffer,
int  size 
)

Attempt to read given number of bytes from the socket.

As QLocalSocket is used, we are guaranteed that any number of bytes written in single operation are available for immediate reading with a single operation.

Parameters
sizeNumber of bytes to read.
bufferLocation for storing the data.
Returns
was given amount of bytes read succesfully.

◆ socket()

QLocalSocket * SocketReader::socket ( )

Provides access to the internal QLocalSocket for direct reading.

Returns
Pointer to the internal QLocalSocket. Pointer can be NULL if initiateConnection() has not been called successfully.

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