mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Add a new obj void* argument to the local session handler.
This commit is contained in:
parent
d4142f8923
commit
06cd3e0f6b
@ -51,7 +51,7 @@ void SessionManager::handle_local_publish(const std::string &client_id, const Pu
|
||||
LocalSession &l = local_sessions[i];
|
||||
|
||||
if (topic_match(l.filter, TopicName(packet.topic_name))) {
|
||||
l.func(client_id, packet.message_data);
|
||||
l.func(client_id, packet.message_data, l.obj);
|
||||
}
|
||||
}
|
||||
}
|
@ -78,24 +78,26 @@ public:
|
||||
*/
|
||||
void handle_publish(const PublishPacket &publish_packet);
|
||||
|
||||
void handle_local_publish(const std::string &client_id, const PublishPacket &packet);
|
||||
void handle_local_publish(const std::string &client_id, const PublishPacket &packet);
|
||||
|
||||
/** Container of BrokerSessions. */
|
||||
std::list<std::unique_ptr<BrokerSession> > sessions;
|
||||
|
||||
public:
|
||||
void add_local_session(const std::string &filter, void (*func)(const std::string &client_id, const std::vector<uint8_t> &data)) {
|
||||
void add_local_session(const std::string &filter, void (*func)(const std::string &client_id, const std::vector<uint8_t> &data, void *obj), void *obj) {
|
||||
LocalSession l;
|
||||
|
||||
l.filter = filter;
|
||||
l.func = func;
|
||||
l.filter = filter;
|
||||
l.func = func;
|
||||
l.obj = obj;
|
||||
|
||||
local_sessions.push_back(l);
|
||||
local_sessions.push_back(l);
|
||||
}
|
||||
|
||||
struct LocalSession {
|
||||
std::string filter;
|
||||
void (*func)(const std::string &client_id, const std::vector<uint8_t> &data);
|
||||
void (*func)(const std::string &client_id, const std::vector<uint8_t> &data, void *obj);
|
||||
void *obj;
|
||||
};
|
||||
|
||||
std::vector<LocalSession> local_sessions;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "mqtt_server.h"
|
||||
|
||||
void MQTTServer::add_local_session(const std::string &filter, void (*func)(const std::string &client_id, const std::vector<uint8_t> &data)) {
|
||||
session_manager->add_local_session(filter, func);
|
||||
void MQTTServer::add_local_session(const std::string &filter, void (*func)(const std::string &client_id, const std::vector<uint8_t> &data, void *obj), void* obj) {
|
||||
session_manager->add_local_session(filter, func, obj);
|
||||
}
|
||||
|
||||
void MQTTServer::initialize() {
|
||||
|
@ -21,7 +21,7 @@ class MQTTServer {
|
||||
public:
|
||||
static void listener_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *addr, int socklen, void *arg);
|
||||
|
||||
void add_local_session(const std::string &filter, void (*func)(const std::string &client_id, const std::vector<uint8_t> &data));
|
||||
void add_local_session(const std::string &filter, void (*func)(const std::string &client_id, const std::vector<uint8_t> &data, void *obj), void* obj);
|
||||
|
||||
void initialize();
|
||||
void run_async();
|
||||
|
Loading…
Reference in New Issue
Block a user