ADD: added Listener and Sender
This commit is contained in:
56
include/WHISPER/InternalUDPListener.hpp
Normal file
56
include/WHISPER/InternalUDPListener.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "WHISPER/Messages/Message.hpp"
|
||||
#include "WHISPER/whisper.hpp"
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <WHISPER/localClients.hpp>
|
||||
|
||||
#define ZMQ_BUILD_DRAFT_API 1
|
||||
#include <zmq.hpp>
|
||||
#include <zmq_addon.hpp>
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
class InternalUDPListener{
|
||||
|
||||
private:
|
||||
std::uint16_t port_;
|
||||
//zeromq io contex
|
||||
zmq::context_t ctx;
|
||||
///shared pointer to receiving socket
|
||||
std::shared_ptr<zmq::socket_t> receiverSocket_ = nullptr;
|
||||
std::thread listeningThread;
|
||||
|
||||
std::atomic<bool> listening_ = false;
|
||||
std::atomic<bool> stoplistening_ = false;
|
||||
|
||||
std::vector<WHISPER::MsgTopics> subscribedTopics;
|
||||
|
||||
std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiverQueue_;
|
||||
|
||||
|
||||
void listen();
|
||||
|
||||
std::uint16_t checkPort(std::uint16_t port);
|
||||
|
||||
public:
|
||||
InternalUDPListener(std::uint16_t port);
|
||||
~InternalUDPListener();
|
||||
void connect(std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiver);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
std::uint16_t getPort();
|
||||
|
||||
void subscribe(WHISPER::MsgTopics topic);
|
||||
void unsubscribe(WHISPER::MsgTopics topic);
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
39
include/WHISPER/InternalUDPSender.hpp
Normal file
39
include/WHISPER/InternalUDPSender.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "WHISPER/Messages/Message.hpp"
|
||||
#include "WHISPER/whisper.hpp"
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <WHISPER/localClients.hpp>
|
||||
|
||||
#define ZMQ_BUILD_DRAFT_API 1
|
||||
#include <zmq.hpp>
|
||||
#include <zmq_addon.hpp>
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
class InternalUDPSender{
|
||||
|
||||
private:
|
||||
/// address to send to
|
||||
std::string address_;
|
||||
/// port to send to
|
||||
std::uint16_t port_;
|
||||
/// zeromq io contex
|
||||
zmq::context_t ctx;
|
||||
/// shared pointer to receiving socket
|
||||
std::shared_ptr<zmq::socket_t> senderSocket_ = nullptr;
|
||||
|
||||
public:
|
||||
InternalUDPSender(std::string address, std::uint16_t port);
|
||||
~InternalUDPSender();
|
||||
|
||||
void send(WHISPER::Message msg,WHISPER::MsgTopics topic = WHISPER::MANAGEMENT);
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user