DESERT 3.5.1
Loading...
Searching...
No Matches
UwSocket Class Reference

#include <uwsocket.h>

Inheritance diagram for UwSocket:
Collaboration diagram for UwSocket:

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.

Definition at line 58 of file uwsocket.h.

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 

Definition at line 66 of file uwsocket.h.

Constructor & Destructor Documentation

◆ UwSocket()

UwSocket::UwSocket ( )

Constructor of the UwSocket class.

Definition at line 40 of file uwsocket.cpp.

◆ ~UwSocket()

UwSocket::~UwSocket ( )
virtual

Destructor of the UwSocket class.

Definition at line 49 of file uwsocket.cpp.

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.

Definition at line 273 of file uwsocket.cpp.

◆ 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.

Definition at line 54 of file uwsocket.cpp.

◆ 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.

Definition at line 60 of file uwsocket.cpp.

◆ 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.

Definition at line 317 of file uwsocket.cpp.

◆ setServer()

virtual void UwSocket::setServer ( )
inlinevirtual

Method that sets SERVER role.

Reimplemented from UwConnector.

Definition at line 139 of file uwsocket.h.

◆ setTCP()

virtual void UwSocket::setTCP ( )
inlinevirtual

Method that sets TCP as transport protocol.

Reimplemented from UwConnector.

Definition at line 122 of file uwsocket.h.

◆ setUDP()

virtual void UwSocket::setUDP ( )
inlinevirtual

Method that sets UDP as transport protocol.

Reimplemented from UwConnector.

Definition at line 130 of file uwsocket.h.

◆ 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.

Definition at line 286 of file uwsocket.cpp.

Member Data Documentation

◆ cl_addr

struct sockaddr_in UwSocket::cl_addr
private

Definition at line 162 of file uwsocket.h.

◆ isClient

bool UwSocket::isClient
private

Bool value that defines the role of the socket.

Definition at line 157 of file uwsocket.h.

◆ proto

Transport UwSocket::proto
private

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

Definition at line 153 of file uwsocket.h.

◆ socketfd

int UwSocket::socketfd
private

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

Definition at line 149 of file uwsocket.h.


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