pubsub.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. /** FuriPubSub Callback type */
  6. typedef void (*FuriPubSubCallback)(const void* message, void* context);
  7. /** FuriPubSub type */
  8. typedef struct FuriPubSub FuriPubSub;
  9. /** FuriPubSubSubscription type */
  10. typedef struct FuriPubSubSubscription FuriPubSubSubscription;
  11. /** Allocate FuriPubSub
  12. *
  13. * Reentrable, Not threadsafe, one owner
  14. *
  15. * @return pointer to FuriPubSub instance
  16. */
  17. FuriPubSub* furi_pubsub_alloc();
  18. /** Free FuriPubSub
  19. *
  20. * @param pubsub FuriPubSub instance
  21. */
  22. void furi_pubsub_free(FuriPubSub* pubsub);
  23. /** Subscribe to FuriPubSub
  24. *
  25. * Threadsafe, Reentrable
  26. *
  27. * @param pubsub pointer to FuriPubSub instance
  28. * @param[in] callback The callback
  29. * @param callback_context The callback context
  30. *
  31. * @return pointer to FuriPubSubSubscription instance
  32. */
  33. FuriPubSubSubscription*
  34. furi_pubsub_subscribe(FuriPubSub* pubsub, FuriPubSubCallback callback, void* callback_context);
  35. /** Unsubscribe from FuriPubSub
  36. *
  37. * No use of `pubsub_subscription` allowed after call of this method
  38. * Threadsafe, Reentrable.
  39. *
  40. * @param pubsub pointer to FuriPubSub instance
  41. * @param pubsub_subscription pointer to FuriPubSubSubscription instance
  42. */
  43. void furi_pubsub_unsubscribe(FuriPubSub* pubsub, FuriPubSubSubscription* pubsub_subscription);
  44. /** Publish message to FuriPubSub
  45. *
  46. * Threadsafe, Reentrable.
  47. *
  48. * @param pubsub pointer to FuriPubSub instance
  49. * @param message message pointer to publish
  50. */
  51. void furi_pubsub_publish(FuriPubSub* pubsub, void* message);
  52. #ifdef __cplusplus
  53. }
  54. #endif