ADD: added message callback to udp listener
This commit is contained in:
@@ -57,10 +57,16 @@ void InternalUDPListener::listen()
|
||||
|
||||
///res is the size of the received message or error; cant figure out what value is set when ther is an error
|
||||
res = receiverSocket_->recv(msg,zmq::recv_flags::none);
|
||||
// std::string message = msg.to_string();
|
||||
WHISPER::Message receivedMessage(msg.to_string());
|
||||
// std::string message = msg.to_string();
|
||||
|
||||
receiverQueue_->addElement(receivedMessage);
|
||||
if (useHandl_ == true)
|
||||
{
|
||||
auto i = std::async(std::launch::async, MessageHandle_, msg.to_string());
|
||||
} else
|
||||
{
|
||||
WHISPER::Message receivedMessage(msg.to_string());
|
||||
receiverQueue_->addElement(receivedMessage);
|
||||
}
|
||||
|
||||
}
|
||||
listening_ = false;
|
||||
@@ -118,6 +124,14 @@ void InternalUDPListener::unsubscribe(WHISPER::MsgTopics topic)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InternalUDPListener::registerMessageCallback(std::function<void(std::string)> MessageHandle)
|
||||
{
|
||||
this->MessageHandle_ = MessageHandle;
|
||||
useHandl_ = true;
|
||||
}
|
||||
|
||||
|
||||
std::uint16_t InternalUDPListener::checkPort(std::uint16_t port)
|
||||
{
|
||||
std::uint16_t localPort = port;
|
||||
|
||||
@@ -44,13 +44,13 @@ int main()
|
||||
// WHISPER::Join join(1,1,WHISPER::SourceType::SHIP,8000,"192.168.1.178");
|
||||
|
||||
auto receiver = std::make_shared<WHISPER::threadSafeQueue<WHISPER::Message>>();
|
||||
WHISPER::InternalUDPService service(0,1,WHISPER::SHIP,8000,"192.168.1.255","192.168.1.178");
|
||||
WHISPER::InternalUDPService service("01",8000,"192.168.1.255","192.168.1.178");
|
||||
service.connect(receiver);
|
||||
|
||||
service.subscribe(WHISPER::MsgTopicsMap[WHISPER::MsgTopics::DATA]);
|
||||
// service.subscribe(WHISPER::MsgTopicsMap[WHISPER::MsgTopics::TRACK]);
|
||||
|
||||
WHISPER::StringData data(0,1,WHISPER::SHIP,"hello world");
|
||||
WHISPER::StringData data("01","hello world");
|
||||
service.publish(data.serialize(), WHISPER::MsgTopicsMap[WHISPER::MsgTopics::DATA]);
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ int main()
|
||||
|
||||
|
||||
auto receiver = std::make_shared<WHISPER::threadSafeQueue<WHISPER::Message>>();
|
||||
WHISPER::InternalUDPService service(0,2,WHISPER::SHIP,8000,"192.168.1.255","192.168.1.178");
|
||||
WHISPER::InternalUDPService service("02",8000,"192.168.1.255","192.168.1.178");
|
||||
|
||||
service.subscribe(WHISPER::MsgTopicsMap[WHISPER::MsgTopics::TRACK]);
|
||||
service.subscribe(WHISPER::MsgTopicsMap[WHISPER::MsgTopics::DATA]);
|
||||
|
||||
Reference in New Issue
Block a user