]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/event.h
Fix a bunch of really obvious unnecessary includes.
[user/henk/code/inspircd.git] / include / event.h
index 39273413fa448eb534c47332d0cd71ac26fd8000..baa24d7d08798b9f5c9a370dac3bae2af1f64510 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2018-2020 Sadie Powell <sadie@witchery.services>
  *   Copyright (C) 2015, 2018 Attila Molnar <attilamolnar@hush.com>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
@@ -20,6 +20,8 @@
 
 #pragma once
 
+#include "base.h"
+
 namespace Events
 {
        class ModuleEventListener;
@@ -58,6 +60,9 @@ class Events::ModuleEventProvider : public ServiceProvider, private dynamic_refe
                prov.SetCaptureHook(this);
        }
 
+       /** Retrieves the module which created this listener. */
+       const Module* GetModule() const { return prov.creator; }
+
        /** Get list of objects subscribed to this event
         * @return List of subscribed objects
         */
@@ -181,13 +186,16 @@ inline bool Events::ModuleEventProvider::ElementComp::operator()(Events::ModuleE
  * 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) \
+       if (!(prov).GetModule() || !(prov).GetModule()->dying) \
        { \
-               listenerclass* _t = static_cast<listenerclass*>(*_i); \
-               const Module* _m = _t->GetModule(); \
-               if (_m && !_m->dying) \
+               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); \
+                       const Module* _m = _t->GetModule(); \
+                       if (_m && !_m->dying) \
                        _t->func params ; \
+               } \
        } \
 } while (0);
 
@@ -200,15 +208,18 @@ inline bool Events::ModuleEventProvider::ElementComp::operator()(Events::ModuleE
  */
 #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) \
+       if (!(prov).GetModule() || !(prov).GetModule()->dying) \
        { \
-               listenerclass* _t = static_cast<listenerclass*>(*_i); \
-               const Module* _m = _t->GetModule(); \
-               if (!_m || _m->dying) \
-                       continue; \
-               result = _t->func params ; \
-               if (result != MOD_RES_PASSTHRU) \
-                       break; \
+               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); \
+                       const Module* _m = _t->GetModule(); \
+                       if (!_m || _m->dying) \
+                               continue; \
+                       result = _t->func params ; \
+                       if (result != MOD_RES_PASSTHRU) \
+                               break; \
+               } \
        } \
 } while (0);