ADD: added methode for message handling in the directCommsClient and Server
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "zmq.hpp"
|
#include "zmq.hpp"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -27,6 +28,9 @@ namespace DirectCommunication
|
|||||||
void sendMessage(std::string msg);
|
void sendMessage(std::string msg);
|
||||||
std::string getLatestMessage();
|
std::string getLatestMessage();
|
||||||
|
|
||||||
|
void registerMessageCallback(std::function<void(std::string)> MessageHandle);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ushort port_;
|
ushort port_;
|
||||||
std::string serverAddress_;
|
std::string serverAddress_;
|
||||||
@@ -40,6 +44,8 @@ namespace DirectCommunication
|
|||||||
|
|
||||||
std::atomic_bool isConnected = true;
|
std::atomic_bool isConnected = true;
|
||||||
|
|
||||||
|
std::function<void(std::string)> MessageHandle_ = nullptr;
|
||||||
|
|
||||||
|
|
||||||
WHISPER::threadSafeQueue<std::string> receivedMessages_;
|
WHISPER::threadSafeQueue<std::string> receivedMessages_;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "zmq.hpp"
|
#include "zmq.hpp"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -27,6 +28,8 @@ namespace DirectCommunication
|
|||||||
void sendMessage(std::string msg);
|
void sendMessage(std::string msg);
|
||||||
std::string getLatestMessage();
|
std::string getLatestMessage();
|
||||||
|
|
||||||
|
void registerMessageCallback(std::function<void(std::string)> MessageHandle);
|
||||||
|
|
||||||
int countClients();
|
int countClients();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -44,6 +47,8 @@ namespace DirectCommunication
|
|||||||
|
|
||||||
bool hasClient(std::uint32_t clientId);
|
bool hasClient(std::uint32_t clientId);
|
||||||
|
|
||||||
|
std::function<void(std::string)> MessageHandle_ = nullptr;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
libs/protobuf/third_party/googletest
vendored
2
libs/protobuf/third_party/googletest
vendored
Submodule libs/protobuf/third_party/googletest updated: 4c9a3bb62b...46db91ef6f
@@ -36,6 +36,11 @@ namespace DirectCommunication
|
|||||||
socket_.close();
|
socket_.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DirectCommunicationClient::registerMessageCallback(std::function<void(std::string)> MessageHandle)
|
||||||
|
{
|
||||||
|
MessageHandle_ = MessageHandle;
|
||||||
|
}
|
||||||
|
|
||||||
void DirectCommunicationClient::sendMessage(std::string msg)
|
void DirectCommunicationClient::sendMessage(std::string msg)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -76,9 +81,16 @@ namespace DirectCommunication
|
|||||||
socket_.disconnect("tcp://"+serverAddress_+":"+std::to_string(port_));
|
socket_.disconnect("tcp://"+serverAddress_+":"+std::to_string(port_));
|
||||||
|
|
||||||
}else
|
}else
|
||||||
|
{
|
||||||
|
if (MessageHandle_ != nullptr)
|
||||||
|
{
|
||||||
|
MessageHandle_(msg.to_string());
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
receivedMessages_.addElement(msg.to_string());
|
receivedMessages_.addElement(msg.to_string());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ namespace DirectCommunication
|
|||||||
socket_.close();
|
socket_.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DirectCommunicationServer::registerMessageCallback(std::function<void(std::string)> MessageHandle)
|
||||||
|
{
|
||||||
|
MessageHandle_ = MessageHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DirectCommunicationServer::sendMessage(std::string msg)
|
void DirectCommunicationServer::sendMessage(std::string msg)
|
||||||
{
|
{
|
||||||
if (connectedClients_.size() > 0)
|
if (connectedClients_.size() > 0)
|
||||||
@@ -84,11 +90,18 @@ namespace DirectCommunication
|
|||||||
auto it = std::find(connectedClients_.begin(), connectedClients_.end(), msg.routing_id());
|
auto it = std::find(connectedClients_.begin(), connectedClients_.end(), msg.routing_id());
|
||||||
connectedClients_.erase(it);
|
connectedClients_.erase(it);
|
||||||
}else
|
}else
|
||||||
|
{
|
||||||
|
if (MessageHandle_ != nullptr)
|
||||||
|
{
|
||||||
|
MessageHandle_(msg.to_string());
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
receivedMessages_.addElement(msg.to_string());
|
receivedMessages_.addElement(msg.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user