1
0

cbmgr.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <precomp.h>
  2. #ifndef NOCBMGR
  3. #include "cbmgr.h"
  4. #include <api/syscb/callbacks/syscb.h>
  5. #include <bfc/multimap.h>
  6. static MultiMap<int, SysCallback> cblist;
  7. static PtrList<SysCallback> delete_list;
  8. static int reentry_counter=0;
  9. void CallbackManager::registerCallback(SysCallback *cb, void *param, WaComponent *owner) {
  10. cblist.multiAddItem(cb->getEventType(), cb, TRUE);
  11. }
  12. void CallbackManager::deregisterCallback(SysCallback *cb, WaComponent *owner) {
  13. delete_list.addItem(cb);
  14. cblist.multiDelItem(cb->getEventType(), cb); // remove ref
  15. }
  16. void CallbackManager::issueCallback(int eventtype, int msg, int param1, int param2) {
  17. ASSERT(reentry_counter >= 0);
  18. reentry_counter++;
  19. const PtrList<SysCallback> *mlist = cblist.getListForIndex(eventtype);
  20. if (mlist != NULL) {
  21. foreach(mlist)
  22. SysCallback *cb = mlist->getfor();
  23. ASSERT(cb != NULL);
  24. if (!delete_list.haveItem(cb))
  25. cb->notify(msg, param1, param2);
  26. endfor
  27. }
  28. reentry_counter--;
  29. if (reentry_counter == 0)
  30. delete_list.removeAll();
  31. }
  32. int CallbackManager::getNumCallbacks() {
  33. return cblist.getNumItems();
  34. }
  35. #endif