bt_manager_event.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2019 Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief bt manager event notify.
  9. */
  10. #define SYS_LOG_NO_NEWLINE
  11. #define SYS_LOG_DOMAIN "bt manager"
  12. #include <os_common_api.h>
  13. #include <zephyr.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stream.h>
  18. #include <msg_manager.h>
  19. #include <mem_manager.h>
  20. #include <app_manager.h>
  21. #include "bt_manager_inner.h"
  22. #include "btservice_api.h"
  23. #include "bt_porting_inner.h"
  24. static void _bt_manager_event_notify_cb(struct app_msg *msg, int result, void *not_used)
  25. {
  26. if (msg && msg->ptr)
  27. bt_mem_free(msg->ptr);
  28. }
  29. int bt_manager_event_notify(int event_id, void *event_data, int event_data_size)
  30. {
  31. struct app_msg msg = {0};
  32. char *fg_app = app_manager_get_current_app();
  33. #if !CONFIG_AEM_WATCH_SUPPORT
  34. if (!fg_app)
  35. return -ENODEV;
  36. #endif
  37. /**ota not deal bt event when process*/
  38. if (memcmp(fg_app, "ota", strlen("ota")) == 0)
  39. return 0;
  40. if (event_data && event_data_size) {
  41. msg.ptr = bt_mem_malloc(event_data_size + 1);
  42. if (!msg.ptr)
  43. return -ENOMEM;
  44. memset(msg.ptr, 0, event_data_size + 1);
  45. memcpy(msg.ptr, event_data, event_data_size);
  46. msg.callback = _bt_manager_event_notify_cb;
  47. }
  48. msg.type = MSG_BT_EVENT;
  49. msg.cmd = event_id;
  50. #if CONFIG_AEM_WATCH_SUPPORT
  51. return send_async_msg("main", &msg);
  52. #else
  53. return send_async_msg(fg_app, &msg);
  54. #endif
  55. }
  56. int bt_manager_event_notify_ext(int event_id, void *event_data, int event_data_size , void* call_cb)
  57. {
  58. struct app_msg msg = {0};
  59. char *fg_app = app_manager_get_current_app();
  60. #if !CONFIG_AEM_WATCH_SUPPORT
  61. if (!fg_app)
  62. return -ENODEV;
  63. #endif
  64. /**ota not deal bt event when process*/
  65. if (memcmp(fg_app, "ota", strlen("ota")) == 0)
  66. return -ENODEV;
  67. if (event_data && event_data_size) {
  68. msg.ptr = bt_mem_malloc(event_data_size + 1);
  69. if (!msg.ptr)
  70. return -ENOMEM;
  71. memset(msg.ptr, 0, event_data_size + 1);
  72. memcpy(msg.ptr, event_data, event_data_size);
  73. msg.callback = call_cb;
  74. }
  75. msg.type = MSG_BT_EVENT;
  76. msg.cmd = event_id;
  77. #if CONFIG_AEM_WATCH_SUPPORT
  78. return send_async_msg("main", &msg);
  79. #else
  80. return send_async_msg(fg_app, &msg);
  81. #endif
  82. }
  83. int bt_manager_state_notify(int state)
  84. {
  85. struct app_msg msg = {0};
  86. msg.type = MSG_BT_EVENT;
  87. msg.cmd = state;
  88. return send_async_msg("main", &msg);
  89. }