dispatch_st.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 dispatch_st.h
  8. *
  9. * \brief private structures used for the dispatcher module
  10. */
  11. #ifndef TOR_DISPATCH_ST_H
  12. #define TOR_DISPATCH_ST_H
  13. #ifdef DISPATCH_PRIVATE
  14. #include "lib/container/smartlist.h"
  15. /**
  16. * Information about the recipient of a message.
  17. **/
  18. typedef struct dispatch_rcv_t {
  19. /** The subsystem receiving a message. */
  20. subsys_id_t sys;
  21. /** True iff this recipient is enabled. */
  22. bool enabled;
  23. /** The function that will handle the message. */
  24. recv_fn_t fn;
  25. } dispatch_rcv_t;
  26. /**
  27. * Information used by a dispatcher to handle and dispatch a single message
  28. * ID. It maps that message ID to its type, channel, and list of receiver
  29. * functions.
  30. *
  31. * This structure is used when the dispatcher is running.
  32. **/
  33. typedef struct dtbl_entry_t {
  34. /** The number of enabled non-stub subscribers for this message.
  35. *
  36. * Note that for now, this will be the same as <b>n_fns</b>, since there is
  37. * no way to turn these subscribers on an off yet. */
  38. uint16_t n_enabled;
  39. /** The channel that handles this message. */
  40. channel_id_t channel;
  41. /** The associated C type for this message. */
  42. msg_type_id_t type;
  43. /**
  44. * The number of functions pointers for subscribers that receive this
  45. * message, in rcv. */
  46. uint16_t n_fns;
  47. /**
  48. * The recipients for this message.
  49. */
  50. dispatch_rcv_t rcv[FLEXIBLE_ARRAY_MEMBER];
  51. } dtbl_entry_t;
  52. /**
  53. * A queue of messages for a given channel, used by a live dispatcher.
  54. */
  55. typedef struct dqueue_t {
  56. /** The queue of messages itself. */
  57. TOR_SIMPLEQ_HEAD( , msg_t) queue;
  58. /** A function to be called when the queue becomes nonempty. */
  59. dispatch_alertfn_t alert_fn;
  60. /** An argument for the alert_fn. */
  61. void *alert_fn_arg;
  62. } dqueue_t ;
  63. /**
  64. * A single dispatcher for cross-module messages.
  65. */
  66. struct dispatch_t {
  67. /**
  68. * The length of <b>table</b>: the number of message IDs that this
  69. * dispatcher can handle.
  70. */
  71. size_t n_msgs;
  72. /**
  73. * The length of <b>queues</b>: the number of channels that this dispatcher
  74. * has configured.
  75. */
  76. size_t n_queues;
  77. /**
  78. * The length of <b>typefns</b>: the number of C type IDs that this
  79. * dispatcher has configured.
  80. */
  81. size_t n_types;
  82. /**
  83. * An array of message queues, indexed by channel ID.
  84. */
  85. dqueue_t *queues;
  86. /**
  87. * An array of entries about how to handle particular message types, indexed
  88. * by message ID.
  89. */
  90. dtbl_entry_t **table;
  91. /**
  92. * An array of function tables for manipulating types, index by message
  93. * type ID.
  94. **/
  95. dispatch_typefns_t *typefns;
  96. };
  97. #endif
  98. #endif