ADD: Message container and Join Message
This commit is contained in:
@@ -10,8 +10,21 @@
|
||||
* @copyright 2022 MPLv2
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#define ZMQ_BUILD_DRAFT_API 1
|
||||
#include <zmq.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
|
||||
#include <WHISPER/threadSafeQueue.hpp>
|
||||
#include <WHISPER/Messages/Message.hpp>
|
||||
|
||||
/**
|
||||
* @brief namespace for all whisper-com related components
|
||||
@@ -20,7 +33,57 @@ namespace WHISPER
|
||||
{
|
||||
// Add datatypes here
|
||||
class whispercomm{
|
||||
|
||||
|
||||
private:
|
||||
/// device ID
|
||||
std::uint32_t ownID_;
|
||||
/// device Type
|
||||
SourceType ownDeviceType_;
|
||||
/// all topics this service subscribed
|
||||
std::vector<std::string> subscribedTopics;
|
||||
|
||||
/// show if the service is connected or not
|
||||
std::atomic<bool> connected;
|
||||
|
||||
/// attribute identifying this service as a gateway and all packets should be forwarded
|
||||
bool gateway = false;
|
||||
|
||||
/// variable for holding the receive thread identifier
|
||||
std::thread receiveThread;
|
||||
|
||||
/// variable indicating if the receiveThread should be stopped
|
||||
std::atomic<bool> stopReceiveThread;
|
||||
|
||||
std::shared_ptr<threadSafeQueue<std::string>> receiveQueue = nullptr;
|
||||
|
||||
|
||||
|
||||
void receive();
|
||||
|
||||
|
||||
public:
|
||||
whispercomm(std::uint32_t id, SourceType owndevicetype):ownID_(id),ownDeviceType_(owndevicetype)
|
||||
{
|
||||
receiveQueue = std::make_shared<threadSafeQueue<std::string>>();
|
||||
};
|
||||
void connect(std::shared_ptr<threadSafeQueue<std::string>> receiver);
|
||||
void publish(std::string msg);
|
||||
void disconnect();
|
||||
void subscribe(std::string topic);
|
||||
void unsubscribe(std::string topic);
|
||||
|
||||
protected:
|
||||
|
||||
void addMsgToReceiverQueue(std::string);
|
||||
|
||||
|
||||
virtual void derivedConnect() = 0;
|
||||
virtual void derivedDisconnect() = 0;
|
||||
virtual void derivedPublish(std::string msg) = 0;
|
||||
virtual void derivedReceive() = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user