pubsub.h 1.7 KB

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