ADD: added usage of a async callback for testing
This commit is contained in:
@@ -27,6 +27,7 @@ namespace DirectCommunication
|
|||||||
|
|
||||||
void sendMessage(std::string msg);
|
void sendMessage(std::string msg);
|
||||||
std::string getLatestMessage();
|
std::string getLatestMessage();
|
||||||
|
void disconnect();
|
||||||
|
|
||||||
void registerMessageCallback(std::function<void(std::string)> MessageHandle);
|
void registerMessageCallback(std::function<void(std::string)> MessageHandle);
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "zmq.hpp"
|
#include "zmq.hpp"
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
|
|
||||||
namespace DirectCommunication
|
namespace DirectCommunication
|
||||||
@@ -34,12 +36,24 @@ namespace DirectCommunication
|
|||||||
DirectCommunicationClient::~DirectCommunicationClient()
|
DirectCommunicationClient::~DirectCommunicationClient()
|
||||||
{
|
{
|
||||||
sendMessage("CLOSE");
|
sendMessage("CLOSE");
|
||||||
isConnected = false;
|
|
||||||
|
|
||||||
stopWorker_ = true;
|
stopWorker_ = true;
|
||||||
Worker_.join();
|
Worker_.join();
|
||||||
|
|
||||||
socket_.close();
|
socket_.close();
|
||||||
|
isConnected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectCommunicationClient::disconnect()
|
||||||
|
{
|
||||||
|
sendMessage("CLOSE");
|
||||||
|
|
||||||
|
stopWorker_ = true;
|
||||||
|
Worker_.join();
|
||||||
|
|
||||||
|
socket_.close();
|
||||||
|
isConnected = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectCommunicationClient::registerMessageCallback(std::function<void(std::string)> MessageHandle)
|
void DirectCommunicationClient::registerMessageCallback(std::function<void(std::string)> MessageHandle)
|
||||||
@@ -89,8 +103,9 @@ namespace DirectCommunication
|
|||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
if (MessageHandle_ != nullptr)
|
if (MessageHandle_ != nullptr)
|
||||||
{
|
{
|
||||||
MessageHandle_(msg.to_string());
|
auto i = std::async(std::launch::async, MessageHandle_, msg.to_string());
|
||||||
|
// MessageHandle_(msg.to_string());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user