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