esp_event_private.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. xSemaphoreTake(loop->mutex, portMAX_DELAY);
  21. esp_event_base_instance_t* base_it;
  22. SLIST_FOREACH(base_it, &(loop->event_bases), event_base_entry) {
  23. esp_event_id_instance_t* event_it;
  24. SLIST_FOREACH(event_it, &(base_it->event_ids), event_id_entry) {
  25. esp_event_handler_instance_t* handler_it;
  26. SLIST_FOREACH(handler_it, &(event_it->handlers), handler_entry) {
  27. if (base_it->base == event_base && event_it->id == event_id && handler_it->handler == event_handler) {
  28. result = true;
  29. goto out;
  30. }
  31. }
  32. }
  33. }
  34. out:
  35. xSemaphoreGive(loop->mutex);
  36. return result;
  37. }