Commit 96861037 authored by thorsten's avatar thorsten
Browse files

* Added Wrapper for new event_handler

parent bd82aed1
//
// Created by thorsten on 28.11.16.
//
#ifndef RELAYMQCPP_RELAYEVENTHANDLER_H
#define RELAYMQCPP_RELAYEVENTHANDLER_H
#include <unordered_map>
#include "Socket.h"
#include "Relay.h"
class RelayEventHandler: public Socket {
private:
relay_event_handler_t* handler;
std::unordered_map<relay_t*, RelayRef> relays;
public:
RelayEventHandler(relay_event_type_t type);
~RelayEventHandler();
void Add(RelayRef relay);
void Remove(RelayRef relay);
bool hasNext();
std::pair<int, RelayRef> Next();
zsock_t* getRaw();
};
#endif //RELAYMQCPP_RELAYEVENTHANDLER_H
//
// Created by thorsten on 28.11.16.
//
#include "../include/RelayEventHandler.h"
RelayEventHandler::RelayEventHandler(relay_event_type_t type) {
handler = relay_event_handler_new(type, NULL);
relays = {};
assert(handler);
}
void RelayEventHandler::Add(RelayRef relay) {
assert(handler);
int rc = relay_event_handler_add(handler, relay->relay);
relays.emplace(relay->relay, relay);
assert(rc == 0);
}
void RelayEventHandler::Remove(RelayRef relay) {
assert(handler);
int rc = relay_event_handler_remove(handler, relay->relay);
relays.erase(relay->relay);
assert(rc == 0);
}
bool RelayEventHandler::hasNext() {
return relay_event_handler_has_next(handler) == 0;
}
std::pair<int, RelayRef> RelayEventHandler::Next() {
int rc = relay_event_handler_next(handler);
if(rc == 0){
int event = relay_event_handler_type(handler);
relay_t* source = relay_event_handler_source(handler);
assert(source);
RelayRef r = this->relays[source];
return std::make_pair(event, r);
} else{
return std::make_pair(0, nullptr);
}
}
zsock_t *RelayEventHandler::getRaw() {
return relay_event_handler_sock(handler);
}
RelayEventHandler::~RelayEventHandler() {
relay_event_handler_destroy(&handler);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment