event_publisher.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "wasm_app.h"
  6. #include "wa-inc/request.h"
  7. #include "wa-inc/timer_wasm_app.h"
  8. int num = 0;
  9. void
  10. publish_overheat_event()
  11. {
  12. attr_container_t *event;
  13. event = attr_container_create("event");
  14. attr_container_set_string(&event, "warning", "temperature is over high");
  15. api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
  16. attr_container_get_serialize_length(event));
  17. attr_container_destroy(event);
  18. }
  19. /* Timer callback */
  20. void
  21. timer1_update(user_timer_t timer)
  22. {
  23. publish_overheat_event();
  24. }
  25. void
  26. start_timer()
  27. {
  28. user_timer_t timer;
  29. /* set up a timer */
  30. timer = api_timer_create(1000, true, false, timer1_update);
  31. api_timer_restart(timer, 1000);
  32. }
  33. void
  34. on_init()
  35. {
  36. start_timer();
  37. }
  38. void
  39. on_destroy()
  40. {
  41. /* real destroy work including killing timer and closing sensor is
  42. accomplished in wasm app library version of on_destroy() */
  43. }