ADD: added methode for message handling in the directCommsClient and Server
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "zmq.hpp"
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
@@ -27,6 +28,9 @@ namespace DirectCommunication
|
||||
void sendMessage(std::string msg);
|
||||
std::string getLatestMessage();
|
||||
|
||||
void registerMessageCallback(std::function<void(std::string)> MessageHandle);
|
||||
|
||||
|
||||
private:
|
||||
ushort port_;
|
||||
std::string serverAddress_;
|
||||
@@ -40,6 +44,8 @@ namespace DirectCommunication
|
||||
|
||||
std::atomic_bool isConnected = true;
|
||||
|
||||
std::function<void(std::string)> MessageHandle_ = nullptr;
|
||||
|
||||
|
||||
WHISPER::threadSafeQueue<std::string> receivedMessages_;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "zmq.hpp"
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
@@ -27,6 +28,8 @@ namespace DirectCommunication
|
||||
void sendMessage(std::string msg);
|
||||
std::string getLatestMessage();
|
||||
|
||||
void registerMessageCallback(std::function<void(std::string)> MessageHandle);
|
||||
|
||||
int countClients();
|
||||
|
||||
private:
|
||||
@@ -44,6 +47,8 @@ namespace DirectCommunication
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void DirectCommunicationClient::registerMessageCallback(std::function<void(std::string)> MessageHandle)
|
||||
{
|
||||
MessageHandle_ = MessageHandle;
|
||||
}
|
||||
|
||||
void DirectCommunicationClient::sendMessage(std::string msg)
|
||||
{
|
||||
|
||||
@@ -77,7 +82,14 @@ namespace DirectCommunication
|
||||
|
||||
}else
|
||||
{
|
||||
receivedMessages_.addElement(msg.to_string());
|
||||
if (MessageHandle_ != nullptr)
|
||||
{
|
||||
MessageHandle_(msg.to_string());
|
||||
}
|
||||
else
|
||||
{
|
||||
receivedMessages_.addElement(msg.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,12 @@ namespace DirectCommunication
|
||||
socket_.close();
|
||||
}
|
||||
|
||||
void DirectCommunicationServer::registerMessageCallback(std::function<void(std::string)> MessageHandle)
|
||||
{
|
||||
MessageHandle_ = MessageHandle;
|
||||
}
|
||||
|
||||
|
||||
void DirectCommunicationServer::sendMessage(std::string msg)
|
||||
{
|
||||
if (connectedClients_.size() > 0)
|
||||
@@ -84,8 +90,15 @@ namespace DirectCommunication
|
||||
auto it = std::find(connectedClients_.begin(), connectedClients_.end(), msg.routing_id());
|
||||
connectedClients_.erase(it);
|
||||
}else
|
||||
{
|
||||
receivedMessages_.addElement(msg.to_string());
|
||||
{
|
||||
if (MessageHandle_ != nullptr)
|
||||
{
|
||||
MessageHandle_(msg.to_string());
|
||||
}
|
||||
else
|
||||
{
|
||||
receivedMessages_.addElement(msg.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user