X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules.h;h=68044ae89ad5a44d9f455c66d0548a1e4b14f6e1;hb=c202dea024542b9c6c6b771bb9a3a081d9eacdc5;hp=1a88a038963a26f80f06dfb94cca556af2db69bc;hpb=4ab593d2a3f849579cc9ac389e42097aef6e9236;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules.h b/include/modules.h index 1a88a0389..68044ae89 100644 --- a/include/modules.h +++ b/include/modules.h @@ -119,23 +119,21 @@ struct ModResult { /** * This #define allows us to call a method in all * loaded modules in a readable simple way, e.g.: - * 'FOREACH_MOD(I_OnConnect,OnConnect(user));' + * 'FOREACH_MOD(OnConnect,(user));' */ #define FOREACH_MOD(y,x) do { \ - EventHandlerIter safei; \ - for (EventHandlerIter _i = ServerInstance->Modules->EventHandlers[y].begin(); _i != ServerInstance->Modules->EventHandlers[y].end(); ) \ + const IntModuleList& _handlers = ServerInstance->Modules->EventHandlers[I_ ## y]; \ + for (IntModuleList::const_reverse_iterator _i = _handlers.rbegin(), _next; _i != _handlers.rend(); _i = _next) \ { \ - safei = _i; \ - ++safei; \ + _next = _i+1; \ try \ { \ - (*_i)->x ; \ + (*_i)->y x ; \ } \ catch (CoreException& modexcept) \ { \ ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s",modexcept.GetReason()); \ } \ - _i = safei; \ } \ } while (0); @@ -147,21 +145,19 @@ struct ModResult { */ #define DO_EACH_HOOK(n,v,args) \ do { \ - EventHandlerIter iter_ ## n = ServerInstance->Modules->EventHandlers[I_ ## n].begin(); \ - while (iter_ ## n != ServerInstance->Modules->EventHandlers[I_ ## n].end()) \ + const IntModuleList& _handlers = ServerInstance->Modules->EventHandlers[I_ ## n]; \ + for (IntModuleList::const_reverse_iterator _i = _handlers.rbegin(), _next; _i != _handlers.rend(); _i = _next) \ { \ - Module* mod_ ## n = *iter_ ## n; \ - iter_ ## n ++; \ + _next = _i+1; \ try \ { \ - v = (mod_ ## n)->n args; + v = (*_i)->n args; #define WHILE_EACH_HOOK(n) \ } \ catch (CoreException& except_ ## n) \ { \ ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s", (except_ ## n).GetReason()); \ - (void) mod_ ## n; /* catch mismatched pairs */ \ } \ } \ } while(0) @@ -245,74 +241,6 @@ class CoreExport DataProvider : public ServiceProvider : ServiceProvider(Creator, Name, SERVICE_DATA) {} }; -class CoreExport dynamic_reference_base : public interfacebase -{ - private: - std::string name; - void resolve(); - protected: - ServiceProvider* value; - public: - ModuleRef creator; - dynamic_reference_base(Module* Creator, const std::string& Name); - ~dynamic_reference_base(); - inline const std::string& GetProvider() { return name; } - void SetProvider(const std::string& newname); - void check(); - operator bool() { return (value != NULL); } - static void reset_all(); -}; - -inline void dynamic_reference_base::check() -{ - if (!value) - throw ModuleException("Dynamic reference to '" + name + "' failed to resolve"); -} - -template -class dynamic_reference : public dynamic_reference_base -{ - public: - dynamic_reference(Module* Creator, const std::string& Name) - : dynamic_reference_base(Creator, Name) {} - - inline T* operator->() - { - check(); - return static_cast(value); - } - - T* operator*() - { - return operator->(); - } -}; - -template -class dynamic_reference_nocheck : public dynamic_reference_base -{ - public: - dynamic_reference_nocheck(Module* Creator, const std::string& Name) - : dynamic_reference_base(Creator, Name) {} - - T* operator->() - { - return static_cast(value); - } - - T* operator*() - { - return operator->(); - } -}; - -class ModeReference : public dynamic_reference_nocheck -{ - public: - ModeReference(Module* mod, const std::string& modename) - : dynamic_reference_nocheck(mod, "mode/" + modename) {} -}; - /** Priority types which can be used by Module::Prioritize() */ enum Priority { PRIORITY_FIRST, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER }; @@ -322,7 +250,7 @@ enum Priority { PRIORITY_FIRST, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER } enum Implementation { I_BEGIN, - I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnRehash, + I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois, I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNick, I_OnUserMessage, I_OnMode, I_OnGetServerDescription, I_OnSyncUser, @@ -348,6 +276,11 @@ enum Implementation */ class CoreExport Module : public classbase, public usecountbase { + /** Detach an event from this module + * @param i Event type to detach + */ + void DetachEvent(Implementation i); + public: /** File that this module was loaded from */ @@ -386,6 +319,13 @@ class CoreExport Module : public classbase, public usecountbase { } + /** This method is called when you should reload module specific configuration: + * on boot, on a /REHASH and on module load. + * @param status The current status, can be inspected for more information; + * also used for reporting configuration errors and warnings. + */ + virtual void ReadConfig(ConfigStatus& status); + /** Returns the version number of a Module. * The method should return a Version object with its version information assigned via * Version::Version @@ -476,14 +416,6 @@ class CoreExport Module : public classbase, public usecountbase */ virtual void OnModuleRehash(User* user, const std::string ¶meter); - /** Called on rehash. - * This method is called after a rehash has completed. You should use it to reload any module - * configuration from the main configuration file. - * @param user The user that performed the rehash, if it was initiated by a user and that user - * is still connected. - */ - virtual void OnRehash(User* user); - /** Called whenever a snotice is about to be sent to a snomask. * snomask and type may both be modified; the message may not. * @param snomask The snomask the message is going to (e.g. 'A') @@ -1258,7 +1190,9 @@ class CoreExport ModuleManager /** Internal unload module hook */ bool CanUnload(Module*); + public: + typedef std::map ModuleMap; /** Event handler hooks. * This needs to be public to be used by FOREACH_MOD and friends. @@ -1340,6 +1274,11 @@ class CoreExport ModuleManager */ void DetachAll(Module* mod); + /** Attach all events to a module (used on module load) + * @param mod Module to attach to all events + */ + void AttachAll(Module* mod); + /** Returns text describing the last module error * @return The last error message to occur */ @@ -1415,6 +1354,11 @@ class CoreExport ModuleManager * @return The list of module names */ const std::vector GetAllModuleNames(int filter); + + /** Get a map of all loaded modules keyed by their name + * @return A ModuleMap containing all loaded modules + */ + const ModuleMap& GetModules() const { return Modules; } }; /** Do not mess with these functions unless you know the C preprocessor @@ -1481,7 +1425,7 @@ struct AllModuleList { { \ return new y; \ } \ - extern "C" const char inspircd_src_version[] = VERSION " r" REVISION; + extern "C" const char inspircd_src_version[] = VERSION " " REVISION; #endif #define COMMAND_INIT(c) MODULE_INIT(CommandModule)