]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
m_cap Provide the OnCapValueChange event and add Cap::Manager::NotifyValueChange()
authorAttila Molnar <attilamolnar@hush.com>
Sat, 5 Dec 2015 14:58:48 +0000 (15:58 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 5 Dec 2015 14:58:48 +0000 (15:58 +0100)
include/modules/cap.h
src/modules/m_cap.cpp

index e05263ad3cb018f607bbaaf860264d6bf9ec56b3..6f91f5aeefbb6575029c2109654eccb14c281f05 100644 (file)
@@ -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.
index a6b5aa900931e183f65ea7e332f6e8c8f82c626d..e1593e33f50f54f64a870d814346721a2fca68ac 100644 (file)
@@ -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);