|
30 | 30 | * |
31 | 31 | * - `serialize_payload` which takes a payload of type `cb_arg_type` |
32 | 32 | * and serializes it into the given `json_stream`. ` |
33 | | - * |
34 | | - * For single-plugin hooks: |
35 | | - * - `single_response_cb` is called once the plugin has responded (or with |
36 | | - * buffer == NULL if there's no plugin). In addition an arbitrary |
37 | | - * additional argument of type `cb_arg_type` can be passed along |
38 | | - * that may contain any additional context necessary. It must free |
39 | | - * or otherwise take ownership of the cb_arg_type argument. |
40 | | - * |
41 | | - * For chained-plugin hooks: |
42 | 33 | * - `deserialize_cb` is called for each plugin, if it returns true the |
43 | 34 | * next one is called, otherwise the cb_arg_type argument is free. |
44 | 35 | * - If all `deserialize_cb` return true, `final_cb` is called. It must free |
|
49 | 40 | * that all the provided functions for serialization, deserialization |
50 | 41 | * and callback have the correct type. |
51 | 42 | */ |
52 | | - |
53 | | -enum plugin_hook_type { |
54 | | - PLUGIN_HOOK_SINGLE, |
55 | | - PLUGIN_HOOK_CHAIN, |
56 | | -}; |
57 | | - |
58 | 43 | struct plugin_hook { |
59 | 44 | const char *name; |
60 | 45 |
|
61 | | - /* Which type of plugin is this? It'll determine how many plugins can |
62 | | - * register this hook, and how the hooks are called. */ |
63 | | - enum plugin_hook_type type; |
64 | | - |
65 | | - /* For PLUGIN_HOOK_SINGLE hooks */ |
66 | | - void (*single_response_cb)(void *arg, |
67 | | - const char *buffer, const jsmntok_t *toks); |
68 | | - |
69 | | - /* For PLUGIN_HOOK_CHAIN hooks: */ |
70 | 46 | /* Returns false if we should stop iterating (and free arg). */ |
71 | 47 | bool (*deserialize_cb)(void *arg, |
72 | 48 | const char *buffer, const jsmntok_t *toks); |
@@ -114,31 +90,10 @@ bool plugin_hook_continue(void *arg, const char *buffer, const jsmntok_t *toks); |
114 | 90 | * response_cb function accepts the deserialized response format and |
115 | 91 | * an arbitrary extra argument used to maintain context. |
116 | 92 | */ |
117 | | -#define REGISTER_SINGLE_PLUGIN_HOOK(name, response_cb, \ |
118 | | - serialize_payload, cb_arg_type) \ |
119 | | - struct plugin_hook name##_hook_gen = { \ |
120 | | - stringify(name), \ |
121 | | - PLUGIN_HOOK_SINGLE, \ |
122 | | - typesafe_cb_cast( \ |
123 | | - void (*)(void *STEALS, const char *, const jsmntok_t *), \ |
124 | | - void (*)(cb_arg_type STEALS, const char *, const jsmntok_t *), \ |
125 | | - response_cb), \ |
126 | | - NULL, NULL, \ |
127 | | - typesafe_cb_cast(void (*)(void *, struct json_stream *), \ |
128 | | - void (*)(cb_arg_type, struct json_stream *), \ |
129 | | - serialize_payload), \ |
130 | | - NULL, /* .plugins */ \ |
131 | | - }; \ |
132 | | - AUTODATA(hooks, &name##_hook_gen); \ |
133 | | - PLUGIN_HOOK_CALL_DEF(name, cb_arg_type) |
134 | | - |
135 | | - |
136 | 93 | #define REGISTER_PLUGIN_HOOK(name, deserialize_cb, final_cb, \ |
137 | 94 | serialize_payload, cb_arg_type) \ |
138 | 95 | struct plugin_hook name##_hook_gen = { \ |
139 | 96 | stringify(name), \ |
140 | | - PLUGIN_HOOK_CHAIN, \ |
141 | | - NULL, \ |
142 | 97 | typesafe_cb_cast( \ |
143 | 98 | bool (*)(void *, const char *, const jsmntok_t *), \ |
144 | 99 | bool (*)(cb_arg_type, const char *, const jsmntok_t *), \ |
|
0 commit comments