From: Attila Molnar Date: Sat, 5 Dec 2015 14:58:48 +0000 (+0100) Subject: m_cap Provide the OnCapValueChange event and add Cap::Manager::NotifyValueChange() X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=302053cf8f5378da7f23e5d2f68a24c9d2325351;hp=912fd7a922beaeecdf602fa9d70964aee2a6bb63;p=user%2Fhenk%2Fcode%2Finspircd.git m_cap Provide the OnCapValueChange event and add Cap::Manager::NotifyValueChange() --- diff --git a/include/modules/cap.h b/include/modules/cap.h index e05263ad3..6f91f5aee 100644 --- a/include/modules/cap.h +++ b/include/modules/cap.h @@ -55,6 +55,11 @@ namespace Cap * @param add If true, the capability is being added, otherwise its being removed */ virtual void OnCapAddDel(Capability* cap, bool add) = 0; + + /** Called whenever the value of a cap changes. + * @param cap Capability whose value changed + */ + virtual void OnCapValueChange(Capability* cap) { } }; class Manager : public DataProvider @@ -82,6 +87,11 @@ namespace Cap * @return Capability object pointer if found, NULL otherwise */ virtual Capability* Find(const std::string& name) const = 0; + + /** Notify manager when a value of a cap changed + * @param cap Cap whose value changed + */ + virtual void NotifyValueChange(Capability* cap) = 0; }; /** Represents a client capability. @@ -135,6 +145,16 @@ namespace Cap friend class ManagerImpl; + protected: + /** Notify the manager that the value of the capability changed. + * Must be called if the value of the cap changes for any reason. + */ + void NotifyValueChange() + { + if (IsRegistered()) + manager->NotifyValueChange(this); + } + public: /** Constructor, initializes the capability. * Caps are active by default. diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index a6b5aa900..e1593e33f 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -122,6 +122,12 @@ class Cap::ManagerImpl : public Cap::Manager return NULL; } + void NotifyValueChange(Capability* cap) CXX11_OVERRIDE + { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Cap %s changed value", cap->GetName().c_str()); + FOREACH_MOD_CUSTOM(evprov, Cap::EventListener, OnCapValueChange, (cap)); + } + Protocol GetProtocol(LocalUser* user) const { return ((capext.get(user) & CAP_302_BIT) ? CAP_302 : CAP_LEGACY);