pubsub_build.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (c) 2001, Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * @file pubsub_build.h
  8. * @brief Header used for constructing the OO publish-subscribe facility.
  9. *
  10. * (See pubsub.h for more general information on this API.)
  11. **/
  12. #ifndef TOR_PUBSUB_BUILD_H
  13. #define TOR_PUBSUB_BUILD_H
  14. struct dispatch_t;
  15. /**
  16. * A "dispatch builder" is an incomplete dispatcher, used when
  17. * registering messages. It does not have the same integrity guarantees
  18. * as a dispatcher. It cannot actually handle messages itself: once all
  19. * subsystems have registered, it is converted into a dispatch_t.
  20. **/
  21. typedef struct pubsub_builder_t pubsub_builder_t;
  22. /**
  23. * A "dispatch connector" is a view of the dispatcher that a subsystem
  24. * uses while initializing itself. It is specific to the subsystem, and
  25. * ensures that each subsystem doesn't need to identify itself
  26. * repeatedly while registering its messages.
  27. **/
  28. typedef struct pubsub_connector_t pubsub_connector_t;
  29. /**
  30. * Create a new pubsub_builder. This should only happen in the
  31. * main-init code.
  32. */
  33. pubsub_builder_t *pubsub_builder_new(void);
  34. /** DOCDOC */
  35. int pubsub_builder_check(pubsub_builder_t *);
  36. /**
  37. * Free a pubsub builder. This should only happen on error paths, where
  38. * we have decided not to construct a dispatcher for some reason.
  39. */
  40. #define pubsub_builder_free(db) \
  41. FREE_AND_NULL(pubsub_builder_t, pubsub_builder_free_, (db))
  42. /** Internal implementation of pubsub_builder_free(). */
  43. void pubsub_builder_free_(pubsub_builder_t *);
  44. /**
  45. * Create a pubsub connector that a single subsystem will use to
  46. * register its messages. The main-init code does this during susbsystem
  47. * initialization.
  48. */
  49. pubsub_connector_t *pubsub_connector_for_subsystem(pubsub_builder_t *,
  50. subsys_id_t);
  51. /**
  52. * The main-init code does this after subsystem initialization.
  53. */
  54. #define pubsub_connector_free(c) \
  55. FREE_AND_NULL(pubsub_connector_t, pubsub_connector_free_, (c))
  56. void pubsub_connector_free_(pubsub_connector_t *);
  57. /**
  58. * Constructs a dispatcher from a dispatch_builder, after checking that the
  59. * invariances on the messages, channels, and connections have been
  60. * respected.
  61. *
  62. * This should happen after every subsystem has initialized, and before
  63. * entering the mainloop.
  64. */
  65. struct dispatch_t *pubsub_builder_finalize(pubsub_builder_t *);
  66. #ifdef PUBSUB_PRIVATE
  67. struct pubsub_items_t;
  68. #define pubsub_items_free(cfg) \
  69. FREE_AND_NULL(pubsub_items_t, pubsub_items_free_, (cfg))
  70. void pubsub_items_free_(struct pubsub_items_t *cfg);
  71. #endif
  72. #endif