pubsub_build.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #include "lib/dispatch/msgtypes.h"
  15. struct dispatch_t;
  16. struct pubsub_connector_t;
  17. /**
  18. * A "dispatch builder" is an incomplete dispatcher, used when
  19. * registering messages. It does not have the same integrity guarantees
  20. * as a dispatcher. It cannot actually handle messages itself: once all
  21. * subsystems have registered, it is converted into a dispatch_t.
  22. **/
  23. typedef struct pubsub_builder_t pubsub_builder_t;
  24. /**
  25. * A "pubsub items" holds the configuration items used to configure a
  26. * pubsub_builder. After the builder is finalized, this field is extracted,
  27. * and used later to tear down pointers that enable publishing.
  28. **/
  29. typedef struct pubsub_items_t pubsub_items_t;
  30. /**
  31. * Create a new pubsub_builder. This should only happen in the
  32. * main-init code.
  33. */
  34. pubsub_builder_t *pubsub_builder_new(void);
  35. /** DOCDOC */
  36. int pubsub_builder_check(pubsub_builder_t *);
  37. /**
  38. * Free a pubsub builder. This should only happen on error paths, where
  39. * we have decided not to construct a dispatcher for some reason.
  40. */
  41. #define pubsub_builder_free(db) \
  42. FREE_AND_NULL(pubsub_builder_t, pubsub_builder_free_, (db))
  43. /** Internal implementation of pubsub_builder_free(). */
  44. void pubsub_builder_free_(pubsub_builder_t *);
  45. /**
  46. * Create a pubsub connector that a single subsystem will use to
  47. * register its messages. The main-init code does this during susbsystem
  48. * initialization.
  49. */
  50. struct pubsub_connector_t *pubsub_connector_for_subsystem(pubsub_builder_t *,
  51. subsys_id_t);
  52. /**
  53. * The main-init code does this after subsystem initialization.
  54. */
  55. #define pubsub_connector_free(c) \
  56. FREE_AND_NULL(struct pubsub_connector_t, pubsub_connector_free_, (c))
  57. void pubsub_connector_free_(struct pubsub_connector_t *);
  58. /**
  59. * Constructs a dispatcher from a dispatch_builder, after checking that the
  60. * invariances on the messages, channels, and connections have been
  61. * respected.
  62. *
  63. * This should happen after every subsystem has initialized, and before
  64. * entering the mainloop.
  65. */
  66. struct dispatch_t *pubsub_builder_finalize(pubsub_builder_t *,
  67. pubsub_items_t **items_out);
  68. /**
  69. * Clear all pub_binding_t backpointers in <b>items</b>.
  70. **/
  71. void pubsub_items_clear_bindings(pubsub_items_t *items);
  72. #define pubsub_items_free(cfg) \
  73. FREE_AND_NULL(pubsub_items_t, pubsub_items_free_, (cfg))
  74. void pubsub_items_free_(pubsub_items_t *cfg);
  75. #endif