-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTopic.hpp
36 lines (26 loc) · 848 Bytes
/
Topic.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once
#include <stddef.h>
#include <list>
#include <memory>
#include <mutex>
#include <string>
#include <utility>
#include "Connection.hpp"
#include "jsonrpc/jsonrpcpp.hpp"
namespace eventhub {
using TopicPtr = std::shared_ptr<class Topic>;
using TopicSubscriberList = std::list<std::pair<ConnectionWeakPtr, jsonrpcpp::Id>>;
class Topic final {
public:
explicit Topic(const std::string& topicFilter) { _id = topicFilter; }
~Topic();
TopicSubscriberList::iterator addSubscriber(ConnectionPtr conn, const jsonrpcpp::Id subscriptionRequestId);
void deleteSubscriberByIterator(TopicSubscriberList::iterator it);
void publish(const std::string& data);
std::size_t getSubscriberCount();
private:
std::string _id;
TopicSubscriberList _subscriber_list;
std::mutex _subscriber_lock;
};
}; // namespace eventhub