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];
|
LocalSession &l = local_sessions[i];
|
||||||
|
|
||||||
if (topic_match(l.filter, TopicName(packet.topic_name))) {
|
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_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. */
|
/** Container of BrokerSessions. */
|
||||||
std::list<std::unique_ptr<BrokerSession> > sessions;
|
std::list<std::unique_ptr<BrokerSession> > sessions;
|
||||||
|
|
||||||
public:
|
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;
|
LocalSession l;
|
||||||
|
|
||||||
l.filter = filter;
|
l.filter = filter;
|
||||||
l.func = func;
|
l.func = func;
|
||||||
|
l.obj = obj;
|
||||||
|
|
||||||
local_sessions.push_back(l);
|
local_sessions.push_back(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LocalSession {
|
struct LocalSession {
|
||||||
std::string filter;
|
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;
|
std::vector<LocalSession> local_sessions;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "mqtt_server.h"
|
#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)) {
|
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);
|
session_manager->add_local_session(filter, func, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQTTServer::initialize() {
|
void MQTTServer::initialize() {
|
||||||
|
@ -21,7 +21,7 @@ class MQTTServer {
|
|||||||
public:
|
public:
|
||||||
static void listener_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *addr, int socklen, void *arg);
|
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 initialize();
|
||||||
void run_async();
|
void run_async();
|
||||||
|
Loading…
Reference in New Issue
Block a user