PikaStdDevice_BaseDev.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "PikaStdDevice_BaseDev.h"
  2. #include "PikaStdDevice_common.h"
  3. #if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 10, 4)
  4. #error "This library requires PikaScript version 1.10.4 or higher"
  5. #endif
  6. PikaEventListener* g_pika_device_event_listener;
  7. void PikaStdDevice_BaseDev_addEventCallback(PikaObj* self, Arg* eventCallBack) {
  8. #if PIKA_EVENT_ENABLE
  9. /* init event_listener for the first time */
  10. if (NULL == g_pika_device_event_listener) {
  11. pika_eventListener_init(&g_pika_device_event_listener);
  12. }
  13. if (PIKA_RES_OK != obj_runNativeMethod(self, "platformGetEventId", NULL)) {
  14. obj_setErrorCode(self, 1);
  15. obj_setSysOut(self, "Error: Method %s no found.", "platformGetEventId");
  16. }
  17. uintptr_t eventId = obj_getInt(self, "eventId");
  18. pika_eventListener_registEventCallback(g_pika_device_event_listener,
  19. eventId, eventCallBack);
  20. #else
  21. obj_setErrorCode(self, 1);
  22. obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled.");
  23. #endif
  24. }
  25. void PikaStdDevice_BaseDev_addEventCallBack(PikaObj* self, Arg* eventCallBack) {
  26. pika_platform_printf("Warning: Method %s is deprecated, please use %s.\r\n",
  27. "addEventCallBack", "addEventCallback");
  28. PikaStdDevice_BaseDev_addEventCallback(self, eventCallBack);
  29. }
  30. void PikaStdDevice_BaseDev_platformGetEventId(PikaObj* self) {
  31. ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
  32. }