1
0

sysmemcb.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef _SYSMEMCB_H
  2. #define _SYSMEMCB_H
  3. namespace SysMemCallback {
  4. enum {
  5. ONMALLOC=10,
  6. ONFREE=20,
  7. ONREALLOC=30,
  8. ONCHANGE=40,
  9. };
  10. };
  11. #include <api/syscb/callbacks/syscbi.h>
  12. #define SYSMEMCALLBACK_PARENT SysCallbackI
  13. class SysMemCallbackI : public SYSMEMCALLBACK_PARENT {
  14. protected:
  15. SysMemCallbackI() { }
  16. public:
  17. virtual void sysmem_onMalloc(void *memory, int size)=0;
  18. virtual void sysmem_onFree(void *memory)=0;
  19. virtual void sysmem_onRealloc(void *prev_memory, void *new_memory, int new_size)=0;
  20. virtual void sysmem_onChange(void *memory)=0;
  21. private:
  22. virtual FOURCC syscb_getEventType() { return SysCallback::SYSMEM; }
  23. virtual int syscb_notify(int msg, intptr_t param1=0, intptr_t param2=0) {
  24. switch (msg) {
  25. case SysMemCallback::ONMALLOC:
  26. sysmem_onMalloc((void *)param1, param2);
  27. break;
  28. case SysMemCallback::ONFREE:
  29. sysmem_onFree((void *)param1);
  30. break;
  31. case SysMemCallback::ONREALLOC: {
  32. void **ptrs = (void **)param1;
  33. sysmem_onRealloc(ptrs[0], ptrs[1], param2);
  34. }
  35. break;
  36. case SysMemCallback::ONCHANGE:
  37. sysmem_onChange((void *)param1);
  38. break;
  39. default: return 0;
  40. }
  41. return 1;
  42. }
  43. };
  44. #endif