Browse Source

Add has_hook functions taking function pointer or callback data in EventHandler

Younguk Kim 8 years ago
parent
commit
b71ee446e3
2 changed files with 43 additions and 0 deletions
  1. 40 0
      panda/src/event/eventHandler.cxx
  2. 3 0
      panda/src/event/eventHandler.h

+ 40 - 0
panda/src/event/eventHandler.cxx

@@ -182,6 +182,46 @@ has_hook(const string &event_name) const {
 }
 
 
+/**
+ * Returns true if there is the hook added on the indicated event name and
+ * function pointer, false otherwise.
+ */
+bool EventHandler::
+has_hook(const string &event_name, EventFunction *function) const {
+  assert(!event_name.empty());
+  Hooks::const_iterator hi;
+  hi = _hooks.find(event_name);
+  if (hi != _hooks.end()) {
+    const Functions& functions = (*hi).second;
+    if (functions.find(function) != functions.end()) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+
+/**
+ * Returns true if there is the hook added on the indicated event name,
+ * function pointer and callback data, false otherwise.
+ */
+bool EventHandler::
+has_hook(const string &event_name, EventCallbackFunction *function, void *data) const {
+  assert(!event_name.empty());
+  CallbackHooks::const_iterator chi;
+  chi = _cbhooks.find(event_name);
+  if (chi != _cbhooks.end()) {
+    const CallbackFunctions& cbfunctions = (*chi).second;
+    if (cbfunctions.find(CallbackFunction(function, data)) != cbfunctions.end()) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+
 /**
  * Removes the indicated function from the named event hook.  Returns true if
  * the hook was removed, false if it wasn't there in the first place.

+ 3 - 0
panda/src/event/eventHandler.h

@@ -55,6 +55,9 @@ public:
   bool add_hook(const string &event_name, EventCallbackFunction *function,
                 void *data);
   bool has_hook(const string &event_name) const;
+  bool has_hook(const string &event_name, EventFunction *function) const;
+  bool has_hook(const string &event_name, EventCallbackFunction *function,
+                void *data) const;
   bool remove_hook(const string &event_name, EventFunction *function);
   bool remove_hook(const string &event_name, EventCallbackFunction *function,
                    void *data);