TDME2 1.9.121
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
UDPClient Class Reference

UDP client. More...

#include <tdme/network/udpclient/UDPClient.h>

Inheritance diagram for UDPClient:
Inheritance graph
Collaboration diagram for UDPClient:
Collaboration graph

Classes

struct  Message
 
struct  SafeMessage
 
struct  UDPClient_Statistics
 

Public Member Functions

 UDPClient (const string &ip, const unsigned int port)
 Public constructor. More...
 
bool isInitialized ()
 
bool isConnected ()
 
const string & getIp ()
 
const unsigned int getPort ()
 
const string & getClientKey ()
 
void setClientKey (const string &clientKey)
 Set client key. More...
 
virtual void run ()
 Run thread program. More...
 
bool processSafeMessage (UDPClientMessage *clientMessage)
 Returns if a message should be processed or already have been processed. More...
 
UDPClientMessagereceiveMessage ()
 Receive message. More...
 
void sendMessage (UDPClientMessage *clientMessage, bool safe)
 Pushes a message to be send, takes over ownership of message. More...
 
UDPClientMessagecreateMessage (stringstream *frame)
 Create message. More...
 
const UDPClient_Statistics getStatistics ()
 
- Public Member Functions inherited from Thread
 Thread (const string &name, size_t stackSize=2 *1024 *1024)
 Public constructor. More...
 
virtual ~Thread ()
 Public destructor. More...
 
void join ()
 Blocks caller thread until this thread has been terminated. More...
 
void start ()
 Starts this objects thread. More...
 
virtual void run ()=0
 Abstract run() method, should be implemented by subclassed class, will be called after spawn by start() More...
 
void stop ()
 Requests that this thread should be stopped. More...
 
bool isStopRequested ()
 Returns if stop has been requested. More...
 

Static Public Member Functions

static uint64_t getRetryTime (const uint8_t retries)
 Get retry time for given retry count. More...
 
- Static Public Member Functions inherited from Thread
static int getHardwareThreadCount ()
 
static void sleep (const uint64_t milliseconds)
 sleeps current thread for given time in milliseconds More...
 

Private Types

typedef queue< Message * > MessageQueue
 
typedef map< uint32_t, Message * > MessageMapAck
 
typedef queue< UDPClientMessage * > RecvMessageQueue
 
typedef map< uint32_t, SafeMessage * > MessageMapSafe
 

Private Member Functions

void processAckReceived (const uint32_t messageId)
 Processes ack reveived. More...
 
void processAckMessages ()
 Process ack messages. More...
 
void cleanUpSafeMessages ()
 Clean up safe messages. More...
 

Private Attributes

bool initialized
 
bool connected
 
string ip
 
uint32_t port
 
uint32_t clientId
 
uint32_t messageCount
 
string clientKey
 
KernelEventMechanism kem
 
Mutex messageQueueMutex
 
MessageQueue messageQueue
 
Mutex messageMapAckMutex
 
MessageMapAck messageMapAck
 
Mutex recvMessageQueueMutex
 
RecvMessageQueue recvMessageQueue
 
Mutex messageMapSafeMutex
 
MessageMapSafe messageMapSafe
 
UDPSocket socket
 
UDPClient_Statistics statistics
 

Static Private Attributes

static const int MESSAGEACK_RESENDTIMES_TRIES = 7
 
static const uint64_t MESSAGEACK_RESENDTIMES [MESSAGEACK_RESENDTIMES_TRIES] = {125L, 250L, 500L, 750L, 1000L, 2000L, 5000L}
 
static const int MESSAGEQUEUE_SEND_BATCH_SIZE = 100
 
static const uint64_t MESSAGEACK_KEEPTIME = 5000L
 
static const uint64_t MESSAGESSAFE_KEEPTIME = 5000L
 

Detailed Description

UDP client.

Author
Andreas Drewke

Definition at line 38 of file UDPClient.h.

Member Typedef Documentation

◆ MessageMapAck

typedef map<uint32_t, Message*> MessageMapAck
private

Definition at line 170 of file UDPClient.h.

◆ MessageMapSafe

typedef map<uint32_t, SafeMessage*> MessageMapSafe
private

Definition at line 179 of file UDPClient.h.

◆ MessageQueue

typedef queue<Message*> MessageQueue
private

Definition at line 169 of file UDPClient.h.

◆ RecvMessageQueue

typedef queue<UDPClientMessage*> RecvMessageQueue
private

Definition at line 171 of file UDPClient.h.

Constructor & Destructor Documentation

◆ UDPClient()

UDPClient ( const string &  ip,
const unsigned int  port 
)

Public constructor.

Parameters
ipserver ip
portserver port

Definition at line 48 of file UDPClient.cpp.

Member Function Documentation

◆ cleanUpSafeMessages()

void cleanUpSafeMessages ( )
private

Clean up safe messages.

Definition at line 512 of file UDPClient.cpp.

◆ createMessage()

UDPClientMessage * createMessage ( stringstream *  frame)

Create message.

Parameters
frameframe content

Definition at line 550 of file UDPClient.cpp.

◆ getClientKey()

const string & getClientKey ( )
Returns
client key

Definition at line 79 of file UDPClient.cpp.

◆ getIp()

const string & getIp ( )
Returns
server ip

Definition at line 71 of file UDPClient.cpp.

◆ getPort()

const unsigned int getPort ( )
Returns
server port

Definition at line 75 of file UDPClient.cpp.

◆ getRetryTime()

uint64_t getRetryTime ( const uint8_t  retries)
static

Get retry time for given retry count.

Parameters
retriesretry count
Returns
approximatly retry time in ms

Definition at line 533 of file UDPClient.cpp.

◆ getStatistics()

const UDPClient::UDPClient_Statistics getStatistics ( )
Returns
UDP client statistics

Definition at line 560 of file UDPClient.cpp.

◆ isConnected()

bool isConnected ( )
Returns
initialized

Definition at line 67 of file UDPClient.cpp.

◆ isInitialized()

bool isInitialized ( )
Returns
initialized

Definition at line 63 of file UDPClient.cpp.

◆ processAckMessages()

void processAckMessages ( )
private

Process ack messages.

Definition at line 400 of file UDPClient.cpp.

◆ processAckReceived()

void processAckReceived ( const uint32_t  messageId)
private

Processes ack reveived.

Parameters
messageIdmessage id
Exceptions
tdme::network::udpclient::NetworkClientException

Definition at line 375 of file UDPClient.cpp.

◆ processSafeMessage()

bool processSafeMessage ( UDPClientMessage clientMessage)

Returns if a message should be processed or already have been processed.

Parameters
clientMessageclient message
Returns
if message should be processed or not
Exceptions
tdme::network::udpclient::NetworkClientException

Definition at line 467 of file UDPClient.cpp.

◆ receiveMessage()

UDPClientMessage * receiveMessage ( )

Receive message.

Returns
message or nullptr, needs to be deleted after processing

Definition at line 539 of file UDPClient.cpp.

◆ run()

void run ( )
virtual

Run thread program.

Implements Thread.

Definition at line 87 of file UDPClient.cpp.

◆ sendMessage()

void sendMessage ( UDPClientMessage clientMessage,
bool  safe 
)

Pushes a message to be send, takes over ownership of message.

Parameters
clientMessageclient message object
safesafe
Exceptions
tdme::network::udpclient::NetworkClientException

Definition at line 314 of file UDPClient.cpp.

◆ setClientKey()

void setClientKey ( const string &  clientKey)

Set client key.

Parameters
clientKeyclient key

Definition at line 83 of file UDPClient.cpp.

Member Data Documentation

◆ clientId

uint32_t clientId
private

Definition at line 153 of file UDPClient.h.

◆ clientKey

string clientKey
private

Definition at line 155 of file UDPClient.h.

◆ connected

bool connected
private

Definition at line 150 of file UDPClient.h.

◆ initialized

bool initialized
private

Definition at line 149 of file UDPClient.h.

◆ ip

string ip
private

Definition at line 151 of file UDPClient.h.

◆ kem

KernelEventMechanism kem
private

Definition at line 182 of file UDPClient.h.

◆ MESSAGEACK_KEEPTIME

const uint64_t MESSAGEACK_KEEPTIME = 5000L
staticprivate

Definition at line 160 of file UDPClient.h.

◆ MESSAGEACK_RESENDTIMES

const uint64_t MESSAGEACK_RESENDTIMES = {125L, 250L, 500L, 750L, 1000L, 2000L, 5000L}
staticprivate

Definition at line 158 of file UDPClient.h.

◆ MESSAGEACK_RESENDTIMES_TRIES

const int MESSAGEACK_RESENDTIMES_TRIES = 7
staticprivate

Definition at line 157 of file UDPClient.h.

◆ messageCount

uint32_t messageCount
private

Definition at line 154 of file UDPClient.h.

◆ messageMapAck

MessageMapAck messageMapAck
private

Definition at line 188 of file UDPClient.h.

◆ messageMapAckMutex

Mutex messageMapAckMutex
private

Definition at line 187 of file UDPClient.h.

◆ messageMapSafe

MessageMapSafe messageMapSafe
private

Definition at line 194 of file UDPClient.h.

◆ messageMapSafeMutex

Mutex messageMapSafeMutex
private

Definition at line 193 of file UDPClient.h.

◆ messageQueue

MessageQueue messageQueue
private

Definition at line 185 of file UDPClient.h.

◆ MESSAGEQUEUE_SEND_BATCH_SIZE

const int MESSAGEQUEUE_SEND_BATCH_SIZE = 100
staticprivate

Definition at line 159 of file UDPClient.h.

◆ messageQueueMutex

Mutex messageQueueMutex
private

Definition at line 184 of file UDPClient.h.

◆ MESSAGESSAFE_KEEPTIME

const uint64_t MESSAGESSAFE_KEEPTIME = 5000L
staticprivate

Definition at line 173 of file UDPClient.h.

◆ port

uint32_t port
private

Definition at line 152 of file UDPClient.h.

◆ recvMessageQueue

RecvMessageQueue recvMessageQueue
private

Definition at line 191 of file UDPClient.h.

◆ recvMessageQueueMutex

Mutex recvMessageQueueMutex
private

Definition at line 190 of file UDPClient.h.

◆ socket

UDPSocket socket
private

Definition at line 196 of file UDPClient.h.

◆ statistics

UDPClient_Statistics statistics
private

Definition at line 198 of file UDPClient.h.


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