You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
i2pd/libi2pd/Event.h

54 lines
1.2 KiB
C

#ifndef EVENT_H__
#define EVENT_H__
#include <map>
#include <string>
#include <memory>
8 years ago
#include <mutex>
#include <tuple>
#include <boost/asio.hpp>
typedef std::map<std::string, std::string> EventType;
namespace i2p
{
8 years ago
namespace event
{
class EventListener {
public:
virtual ~EventListener() {};
virtual void HandleEvent(const EventType & ev) = 0;
8 years ago
/** @brief handle collected event when pumped */
virtual void HandlePumpEvent(const EventType & ev, const uint64_t & val) = 0;
8 years ago
};
8 years ago
class EventCore
{
public:
void QueueEvent(const EventType & ev);
8 years ago
void CollectEvent(const std::string & type, const std::string & ident, uint64_t val);
8 years ago
void SetListener(EventListener * l);
8 years ago
void PumpCollected(EventListener * l);
8 years ago
private:
8 years ago
std::mutex m_collect_mutex;
struct CollectedEvent
{
std::string Key;
std::string Ident;
uint64_t Val;
};
std::map<std::string, CollectedEvent> m_collected;
8 years ago
EventListener * m_listener = nullptr;
};
#ifdef WITH_EVENTS
8 years ago
extern EventCore core;
#endif
8 years ago
}
}
8 years ago
void QueueIntEvent(const std::string & type, const std::string & ident, uint64_t val);
void EmitEvent(const EventType & ev);
#endif