pubsub.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.h
  8. * @brief Header for OO publish-subscribe functionality.
  9. *
  10. * This module provides a wrapper around the "dispatch" module,
  11. * ensuring type-safety and allowing us to do static analysis on
  12. * publication and subscriptions.
  13. *
  14. * With this module, we enforce:
  15. * <ul>
  16. * <li>that every message has (potential) publishers and subscribers;
  17. * <li>that every message is published and subscribed from the correct
  18. * channels, with the correct type ID, every time it is published.
  19. * <li>that type IDs correspond to a single C type, and that the C types are
  20. * used correctly.
  21. * <li>that when a message is published or subscribed, it is done with
  22. * a correct subsystem identifier
  23. * </ul>
  24. *
  25. * We do this by making "publication requests" and "subscription requests"
  26. * into objects, and doing some computation on them before we create
  27. * a dispatch_t with them.
  28. *
  29. * Rather than using the dispatch module directly, a publishing module
  30. * receives a "binding" object that it uses to send messages with the right
  31. * settings.
  32. *
  33. * Most users of this module will want to use this header, and the
  34. * pubsub_macros.h header for convenience.
  35. */
  36. /*
  37. *
  38. * Overview: Messages are sent over channels. Before sending a message on a
  39. * channel, or receiving a message on a channel, a subsystem needs to register
  40. * that it publishes, or subscribes, to that message, on that channel.
  41. *
  42. * Messages, channels, and subsystems are represented internally as short
  43. * integers, though they are associated with human-readable strings for
  44. * initialization and debugging.
  45. *
  46. * When registering for a message, a subsystem must say whether it is an
  47. * exclusive publisher/subscriber to that message type, or whether other
  48. * subsystems may also publish/subscribe to it.
  49. *
  50. * All messages and their publishers/subscribers must be registered early in
  51. * the initialization process.
  52. *
  53. * By default, it is an error for a message type to have publishers and no
  54. * subscribers on a channel, or subscribers and no publishers on a channel.
  55. *
  56. * A subsystem may register for a message with a note that delivery or
  57. * production is disabled -- for example, because the subsystem is
  58. * disabled at compile-time. It is not an error for a message type to
  59. * have all of its publishers or subscribers disabled.
  60. *
  61. * After a message is sent, it is delivered to every recipient. This
  62. * delivery happens from the top level of the event loop; it may be
  63. * interleaved with network events, timers, etc.
  64. *
  65. * Messages may have associated data. This data is typed, and is owned
  66. * by the message. Strings, byte-arrays, and integers have built-in
  67. * support. Other types may be added. If objects are to be sent,
  68. * they should be identified by handle. If an object requires cleanup,
  69. * it should be declared with an associated free function.
  70. *
  71. * Semantically, if two subsystems communicate only by this kind of
  72. * message passing, neither is considered to depend on the other, though
  73. * both are considered to have a dependency on the message and on any
  74. * types it contains.
  75. *
  76. * (Or generational index?)
  77. */
  78. #ifndef TOR_PUBSUB_PUBSUB_H
  79. #define TOR_PUBSUB_PUBSUB_H
  80. #include "lib/pubsub/pub_binding_st.h"
  81. #include "lib/pubsub/pubsub_connect.h"
  82. #include "lib/pubsub/pubsub_flags.h"
  83. #include "lib/pubsub/pubsub_macros.h"
  84. #include "lib/pubsub/pubsub_publish.h"
  85. #endif /* !defined(TOR_PUBSUB_PUBSUB_H) */