diff options
author | Peter Powell <petpow@saberuk.com> | 2018-08-13 20:17:46 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2018-08-13 21:51:11 +0100 |
commit | 58a0a7e01422e62de1565a8eb0a1febdc463d04d (patch) | |
tree | 8861789deefe9df3524690de8ccd11e5366f1f2e /include/event.h | |
parent | e2a820cce21342478653a34cf8ce2b593128d035 (diff) |
Implement IRCv3 message tag support.
Co-authored-by: Attila Molnar <attilamolnar@hush.com>
Diffstat (limited to 'include/event.h')
-rw-r--r-- | include/event.h | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/include/event.h b/include/event.h index c9bad7d04..73a45a541 100644 --- a/include/event.h +++ b/include/event.h @@ -34,7 +34,12 @@ namespace Events class Events::ModuleEventProvider : public ServiceProvider, private dynamic_reference_base::CaptureHook { public: - typedef std::vector<ModuleEventListener*> SubscriberList; + struct Comp + { + bool operator()(ModuleEventListener* one, ModuleEventListener* two) const; + }; + + typedef insp::flat_multiset<ModuleEventListener*, Comp> SubscriberList; /** Constructor * @param mod Module providing the event(s) @@ -84,20 +89,25 @@ class Events::ModuleEventListener : private dynamic_reference_base::CaptureHook */ dynamic_reference_nocheck<ModuleEventProvider> prov; + const unsigned int eventpriority; + /** Called by the dynref when the event provider becomes available */ void OnCapture() CXX11_OVERRIDE { - prov->subscribers.push_back(this); + prov->subscribers.insert(this); } public: + static const unsigned int DefaultPriority = 100; + /** Constructor * @param mod Module subscribing * @param eventid Identifier of the event to subscribe to */ - ModuleEventListener(Module* mod, const std::string& eventid) + ModuleEventListener(Module* mod, const std::string& eventid, unsigned int eventprio = DefaultPriority) : prov(mod, eventid) + , eventpriority(eventprio) { prov.SetCaptureHook(this); // If the dynamic_reference resolved at construction our capture handler wasn't called @@ -108,18 +118,25 @@ class Events::ModuleEventListener : private dynamic_reference_base::CaptureHook ~ModuleEventListener() { if (prov) - stdalgo::erase(prov->subscribers, this); + prov->subscribers.erase(this); } + + friend struct ModuleEventProvider::Comp; }; +inline bool Events::ModuleEventProvider::Comp::operator()(Events::ModuleEventListener* one, Events::ModuleEventListener* two) const +{ + return (one->eventpriority < two->eventpriority); +} + /** * Run the given hook provided by a module * * FOREACH_MOD_CUSTOM(accountevprov, AccountEventListener, OnAccountChange, MOD_RESULT, (user, newaccount)) */ #define FOREACH_MOD_CUSTOM(prov, listenerclass, func, params) do { \ - const Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ - for (Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ + const ::Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ + for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ { \ listenerclass* _t = static_cast<listenerclass*>(*_i); \ _t->func params ; \ @@ -135,8 +152,8 @@ class Events::ModuleEventListener : private dynamic_reference_base::CaptureHook */ #define FIRST_MOD_RESULT_CUSTOM(prov, listenerclass, func, result, params) do { \ result = MOD_RES_PASSTHRU; \ - const Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ - for (Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ + const ::Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ + for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ { \ listenerclass* _t = static_cast<listenerclass*>(*_i); \ result = _t->func params ; \ |