tor  0.4.2.1-alpha-dev
dispatch.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-2018, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 #ifndef TOR_DISPATCH_H
8 #define TOR_DISPATCH_H
9 
10 #include "lib/dispatch/msgtypes.h"
11 
53 typedef struct dispatch_t dispatch_t;
54 
55 struct dispatch_cfg_t;
56 
57 dispatch_t *dispatch_new(const struct dispatch_cfg_t *cfg);
58 
62 #define dispatch_free(d) \
63  FREE_AND_NULL(dispatch_t, dispatch_free_, (d))
64 
66 
68  subsys_id_t sender,
69  channel_id_t channel,
70  message_id_t msg,
71  msg_type_id_t type,
72  msg_aux_data_t auxdata);
73 
74 int dispatch_send_msg(dispatch_t *d, msg_t *m);
75 
77 
78 /* Flush up to <b>max_msgs</b> currently pending messages from the
79  * dispatcher. Messages that are not pending when this function are
80  * called, are not flushed by this call. Return 0 on success, -1 on
81  * unrecoverable error.
82  */
83 int dispatch_flush(dispatch_t *, channel_id_t chan, int max_msgs);
84 
98 typedef void (*dispatch_alertfn_t)(struct dispatch_t *,
99  channel_id_t, void *);
100 
101 int dispatch_set_alert_fn(dispatch_t *d, channel_id_t chan,
102  dispatch_alertfn_t fn, void *userdata);
103 
104 #define dispatch_free_msg(d,msg) \
105  STMT_BEGIN { \
106  msg_t **msg_tmp_ptr__ = &(msg); \
107  dispatch_free_msg_((d), *msg_tmp_ptr__); \
108  *msg_tmp_ptr__= NULL; \
109  } STMT_END
110 void dispatch_free_msg_(const dispatch_t *d, msg_t *msg);
111 
112 char *dispatch_fmt_msg_data(const dispatch_t *d, const msg_t *msg);
113 
114 #endif /* !defined(TOR_DISPATCH_H) */
char * dispatch_fmt_msg_data(const dispatch_t *d, const msg_t *msg)
Definition: dispatch_core.c:43
int dispatch_send_msg_unchecked(dispatch_t *d, msg_t *m)
Types used for messages in the dispatcher code.
struct dispatch_t dispatch_t
Definition: dispatch.h:53
int dispatch_flush(dispatch_t *, channel_id_t chan, int max_msgs)
dispatch_t * dispatch_new(const dispatch_cfg_t *cfg)
Definition: dispatch_new.c:112
Definition: msgtypes.h:50
uint16_t msg_type_id_t
Definition: msgtypes.h:29
uint16_t subsys_id_t
Definition: msgtypes.h:22
int dispatch_set_alert_fn(dispatch_t *d, channel_id_t chan, dispatch_alertfn_t fn, void *userdata)
Definition: dispatch_core.c:88
int dispatch_send(dispatch_t *d, subsys_id_t sender, channel_id_t channel, message_id_t msg, msg_type_id_t type, msg_aux_data_t auxdata)
void dispatch_free_msg_(const dispatch_t *d, msg_t *msg)
Definition: dispatch_core.c:30
void(* dispatch_alertfn_t)(struct dispatch_t *, channel_id_t, void *)
Definition: dispatch.h:98
void dispatch_free_(dispatch_t *)
Definition: dispatch_core.c:55