esp_event_private.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "esp_event_private.h"
  14. #include "esp_event_internal.h"
  15. #include "esp_log.h"
  16. bool esp_event_is_handler_registered(esp_event_loop_handle_t event_loop, esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler)
  17. {
  18. esp_event_loop_instance_t* loop = (esp_event_loop_instance_t*) event_loop;
  19. bool result = false;
  20. esp_event_loop_node_t* loop_node;
  21. esp_event_base_node_t* base_node;
  22. esp_event_id_node_t* id_node;
  23. esp_event_handler_node_t* handler;
  24. SLIST_FOREACH(loop_node, &(loop->loop_nodes), next) {
  25. SLIST_FOREACH(handler, &(loop_node->handlers), next) {
  26. if(event_base == ESP_EVENT_ANY_BASE && event_id == ESP_EVENT_ANY_ID && handler->handler_ctx->handler == event_handler)
  27. {
  28. result = true;
  29. goto out;
  30. }
  31. }
  32. SLIST_FOREACH(base_node, &(loop_node->base_nodes), next) {
  33. if (base_node->base == event_base) {
  34. SLIST_FOREACH(handler, &(base_node->handlers), next) {
  35. if(event_id == ESP_EVENT_ANY_ID && handler->handler_ctx->handler == event_handler)
  36. {
  37. result = true;
  38. goto out;
  39. }
  40. }
  41. SLIST_FOREACH(id_node, &(base_node->id_nodes), next) {
  42. if(id_node->id == event_id) {
  43. SLIST_FOREACH(handler, &(id_node->handlers), next) {
  44. if(handler->handler_ctx->handler == event_handler)
  45. {
  46. result = true;
  47. goto out;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55. out:
  56. xSemaphoreGive(loop->mutex);
  57. return result;
  58. }