DESERT 4.0.0
UwSocket Class Reference

#include <uwsocket.h>

Inheritance diagram for UwSocket:
Inheritance graph
Collaboration diagram for UwSocket:
Collaboration graph

Public Types

enum class  Transport { TCP = 0 , UDP }
 

Public Member Functions

 UwSocket ()
 
virtual ~UwSocket ()
 
virtual bool openConnection (const std::string &path)
 
virtual bool closeConnection ()
 
virtual const bool isConnected ()
 
virtual int writeToDevice (const std::string &msg)
 
virtual int readFromDevice (void *wpos, int maxlen)
 
virtual void setTCP ()
 
virtual void setUDP ()
 
virtual void setServer ()
 
- Public Member Functions inherited from UwConnector
 UwConnector ()
 
virtual ~UwConnector ()
 
virtual const int getErrno ()
 

Private Attributes

int socketfd
 
Transport proto
 
bool isClient
 
struct sockaddr_in cl_addr
 

Additional Inherited Members

- Protected Attributes inherited from UwConnector
int local_errno
 

Detailed Description

Class that implements a TCP or UDP socket. For each UwSocket object, a thread is spawned and dedicated to reading the socket buffer ans retrieving data: while sending is done in the calling thread.

Member Enumeration Documentation

◆ Transport

enum class UwSocket::Transport
strong

Enum structure thet represents the transport protocol being used. The two possible choices are, of course, TCP or UDP.

Enumerator
TCP 
UDP 

Constructor & Destructor Documentation

◆ UwSocket()

UwSocket::UwSocket ( )

Constructor of the UwSocket class

References UwConnector::local_errno.

◆ ~UwSocket()

UwSocket::~UwSocket ( )
virtual

Destructor of the UwSocket class

Member Function Documentation

◆ closeConnection()

bool UwSocket::closeConnection ( )
virtual

Method that closes an active connection to a device

Returns
boolean true if connection is correctly closed, false otherwise

Implements UwConnector.

References socketfd.

◆ isConnected()

const bool UwSocket::isConnected ( )
virtual

Returns true if socket fd differs from -1, that means the connection is up

Returns
if socket file descriptor is valid

Implements UwConnector.

References socketfd.

◆ openConnection()

bool UwSocket::openConnection ( const std::string &  path)
virtual

Method that opens a TCP or UDP connection, accordinto to UwSocket::proto variable: the behavior depends both on the transport protocol selected and the path specified in the constructor parameter. If TCP is set:

  • IP:PORT will try to connect to the provided IP and PORT
  • PORT will try to connect to the provided port on localhost if, otherwise, UDP is set:
  • IP:PORT will save the IP and port for data forwarding
  • PORT will bind the provided port to receive data through it
    Returns
    boolean true if connection is correctly opened, false otherwise

Implements UwConnector.

References cl_addr, isClient, UwConnector::local_errno, proto, sep, socketfd, TCP, and udp_init_string.

◆ readFromDevice()

int UwSocket::readFromDevice ( void *  wpos,
int  maxlen 
)
virtual

Function that dumps data from the device's memory to a backup buffer. The unloaded data is saved to a temporary buffer, to be parsed later.

Parameters
posposition to start writing data to: a pointer to some buffer
Returns
ineger number of read bytes

Implements UwConnector.

References cl_addr, proto, socketfd, and TCP.

◆ setServer()

virtual void UwSocket::setServer ( )
inlinevirtual

Method that sets SERVER role

Reimplemented from UwConnector.

References isClient.

◆ setTCP()

virtual void UwSocket::setTCP ( )
inlinevirtual

Method that sets TCP as transport protocol

Reimplemented from UwConnector.

References proto, and TCP.

◆ setUDP()

virtual void UwSocket::setUDP ( )
inlinevirtual

Method that sets UDP as transport protocol

Reimplemented from UwConnector.

References proto, and UDP.

◆ writeToDevice()

int UwSocket::writeToDevice ( const std::string &  msg)
virtual

Method that writes a command to the modem interface

Parameters
msgstd::string command to be sent to the device

Implements UwConnector.

References cl_addr, proto, socketfd, and TCP.

Member Data Documentation

◆ cl_addr

struct sockaddr_in UwSocket::cl_addr
private

◆ isClient

bool UwSocket::isClient
private

Bool value that defines the role of the socket

Referenced by openConnection(), and setServer().

◆ proto

Transport UwSocket::proto
private

Transport protocol to be used: either Transport::TCP or Transport::UDP.

Referenced by openConnection(), readFromDevice(), setTCP(), setUDP(), and writeToDevice().

◆ socketfd

int UwSocket::socketfd
private

Integer value that stores the socket descriptor as generated by the function UwSocket::openConnection().

Referenced by closeConnection(), isConnected(), openConnection(), readFromDevice(), and writeToDevice().


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