Blender  V2.93
wm_message_bus.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #pragma once
22 
23 #include "RNA_types.h"
24 #include <stdio.h>
25 
26 struct ID;
27 struct bContext;
28 struct wmMsg;
29 
30 /* opaque (don't expose outside wm_message_bus.c) */
31 struct wmMsgBus;
32 struct wmMsgSubscribeKey;
33 struct wmMsgSubscribeValue;
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 typedef void (*wmMsgNotifyFn)(struct bContext *C,
41  struct wmMsgSubscribeKey *msg_key,
42  struct wmMsgSubscribeValue *msg_val);
43 typedef void (*wmMsgSubscribeValueFreeDataFn)(struct wmMsgSubscribeKey *msg_key,
44  struct wmMsgSubscribeValue *msg_val);
45 
46 /* Exactly what arguments here is not obvious. */
47 typedef void (*wmMsgSubscribeValueUpdateIdFn)(struct bContext *C,
48  struct wmMsgBus *mbus,
49  struct ID *id_src,
50  struct ID *id_dst,
51  struct wmMsgSubscribeValue *msg_val);
52 enum {
55 };
56 #define WM_MSG_TYPE_NUM 2
57 
58 typedef struct wmMsgTypeInfo {
59  struct {
60  unsigned int (*hash_fn)(const void *msg);
61  bool (*cmp_fn)(const void *a, const void *b);
62  void (*key_free_fn)(void *key);
63  } gset;
64 
65  void (*update_by_id)(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst);
66  void (*remove_by_id)(struct wmMsgBus *mbus, const struct ID *id);
67  void (*repr)(FILE *stream, const struct wmMsgSubscribeKey *msg_key);
68 
69  /* sizeof(wmMsgSubscribeKey_*) */
72 
73 typedef struct wmMsg {
74  unsigned int type;
75  // #ifdef DEBUG
76  /* For debugging: '__func__:__LINE__'. */
77  const char *id;
78  // #endif
80 
81 typedef struct wmMsgSubscribeKey {
85  /* over-alloc, eg: wmMsgSubscribeKey_RNA */
86  /* Last member will be 'wmMsg_*' */
88 
90 typedef struct wmMsgSubscribeValue {
91  struct wmMsgSubscribe *next, *prev;
92 
94  void *owner;
96  void *user_data;
97 
102 
105  /* tag to run when handling events,
106  * we may want option for immediate execution. */
107  uint tag : 1;
109 
111 typedef struct wmMsgSubscribeValueLink {
115 
116 void WM_msgbus_types_init(void);
117 
118 struct wmMsgBus *WM_msgbus_create(void);
119 void WM_msgbus_destroy(struct wmMsgBus *mbus);
120 
121 void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner);
122 
123 void WM_msg_dump(struct wmMsgBus *mbus, const char *info);
124 void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C);
125 
126 void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key);
128  const wmMsgSubscribeKey *msg_key_test,
129  const wmMsgSubscribeValue *msg_val_params);
130 
131 void WM_msg_id_update(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst);
132 void WM_msg_id_remove(struct wmMsgBus *mbus, const struct ID *id);
133 
134 /* -------------------------------------------------------------------------- */
135 /* wm_message_bus_static.c */
136 
137 enum {
138  /* generic window redraw */
142 };
143 
144 typedef struct wmMsgParams_Static {
145  int event;
147 
148 typedef struct wmMsg_Static {
149  wmMsg head; /* keep first */
152 
153 typedef struct wmMsgSubscribeKey_Static {
157 
158 void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info);
159 
161  const wmMsgParams_Static *msg_key_params);
162 void WM_msg_publish_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params);
163 void WM_msg_publish_static(struct wmMsgBus *mbus,
164  /* wmMsgParams_Static (expanded) */
165  int event);
166 void WM_msg_subscribe_static_params(struct wmMsgBus *mbus,
167  const wmMsgParams_Static *msg_key_params,
168  const wmMsgSubscribeValue *msg_val_params,
169  const char *id_repr);
170 void WM_msg_subscribe_static(struct wmMsgBus *mbus,
171  int event,
172  const wmMsgSubscribeValue *msg_val_params,
173  const char *id_repr);
174 
175 /* -------------------------------------------------------------------------- */
176 /* wm_message_bus_rna.c */
177 
178 typedef struct wmMsgParams_RNA {
183 
188  char *data_path;
190 
191 typedef struct wmMsg_RNA {
192  wmMsg head; /* keep first */
195 
196 typedef struct wmMsgSubscribeKey_RNA {
200 
201 #ifdef __GNUC__
202 # define _WM_MESSAGE_EXTERN_BEGIN \
203  _Pragma("GCC diagnostic push"); \
204  _Pragma("GCC diagnostic ignored \"-Wredundant-decls\"");
205 # define _WM_MESSAGE_EXTERN_END _Pragma("GCC diagnostic pop");
206 #else
207 # define _WM_MESSAGE_EXTERN_BEGIN
208 # define _WM_MESSAGE_EXTERN_END
209 #endif
210 
211 void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info);
212 
214  const wmMsgParams_RNA *msg_key_params);
215 void WM_msg_publish_rna_params(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params);
216 void WM_msg_publish_rna(struct wmMsgBus *mbus,
217  /* wmMsgParams_RNA (expanded) */
218  PointerRNA *ptr,
219  PropertyRNA *prop);
220 void WM_msg_subscribe_rna_params(struct wmMsgBus *mbus,
221  const wmMsgParams_RNA *msg_key_params,
222  const wmMsgSubscribeValue *msg_val_params,
223  const char *id_repr);
224 void WM_msg_subscribe_rna(struct wmMsgBus *mbus,
225  PointerRNA *ptr,
226  const PropertyRNA *prop,
227  const wmMsgSubscribeValue *msg_val_params,
228  const char *id_repr);
229 
230 /* ID variants */
231 void WM_msg_subscribe_ID(struct wmMsgBus *mbus,
232  struct ID *id,
233  const wmMsgSubscribeValue *msg_val_params,
234  const char *id_repr);
235 void WM_msg_publish_ID(struct wmMsgBus *mbus, struct ID *id);
236 
237 #define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_) \
238  { \
239  wmMsgParams_RNA msg_key_params_ = {{0}}; \
240  _WM_MESSAGE_EXTERN_BEGIN; \
241  extern PropertyRNA rna_##type_##_##prop_; \
242  _WM_MESSAGE_EXTERN_END; \
243  RNA_pointer_create(id_, &RNA_##type_, data_, &msg_key_params_.ptr); \
244  msg_key_params_.prop = &rna_##type_##_##prop_; \
245  WM_msg_publish_rna_params(mbus, &msg_key_params_); \
246  } \
247  ((void)0)
248 #define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value) \
249  { \
250  wmMsgParams_RNA msg_key_params_ = {{0}}; \
251  _WM_MESSAGE_EXTERN_BEGIN; \
252  extern PropertyRNA rna_##type_##_##prop_; \
253  _WM_MESSAGE_EXTERN_END; \
254  RNA_pointer_create(id_, &RNA_##type_, data_, &msg_key_params_.ptr); \
255  msg_key_params_.prop = &rna_##type_##_##prop_; \
256  WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
257  } \
258  ((void)0)
259 
260 /* Anonymous variants (for convenience) */
261 #define WM_msg_subscribe_rna_anon_type(mbus, type_, value) \
262  { \
263  WM_msg_subscribe_rna_params(mbus, \
264  &(const wmMsgParams_RNA){ \
265  .ptr = \
266  (PointerRNA){ \
267  .type = &RNA_##type_, \
268  }, \
269  .prop = NULL, \
270  }, \
271  value, \
272  __func__); \
273  } \
274  ((void)0)
275 #define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value) \
276  { \
277  _WM_MESSAGE_EXTERN_BEGIN; \
278  extern PropertyRNA rna_##type_##_##prop_; \
279  _WM_MESSAGE_EXTERN_END; \
280  WM_msg_subscribe_rna_params(mbus, \
281  &(const wmMsgParams_RNA){ \
282  .ptr = \
283  (PointerRNA){ \
284  .type = &RNA_##type_, \
285  }, \
286  .prop = &rna_##type_##_##prop_, \
287  }, \
288  value, \
289  __func__); \
290  } \
291  ((void)0)
292 
293 #ifdef __cplusplus
294 }
295 #endif
unsigned int uint
Definition: BLI_sys_types.h:83
#define C
Definition: RandGen.cpp:39
static unsigned a[3]
Definition: RandGen.cpp:92
Definition: DNA_ID.h:273
const PropertyRNA * prop
wmMsgSubscribeKey head
wmMsgSubscribeKey head
struct wmMsgSubscribeKey * next
struct wmMsgSubscribeKey * prev
wmMsgSubscribeValueFreeDataFn free_data
wmMsgSubscribeValueUpdateIdFn update_id
struct wmMsgSubscribe * next
wmMsgNotifyFn notify
struct wmMsgSubscribe * prev
void(* remove_by_id)(struct wmMsgBus *mbus, const struct ID *id)
void(* update_by_id)(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst)
void(* repr)(FILE *stream, const struct wmMsgSubscribeKey *msg_key)
unsigned int(* hash_fn)(const void *msg)
struct wmMsgTypeInfo::@1166 gset
void(* key_free_fn)(void *key)
bool(* cmp_fn)(const void *a, const void *b)
wmMsgParams_RNA params
wmMsgParams_Static params
unsigned int type
const char * id
PointerRNA * ptr
Definition: wm_files.c:3157
struct wmMsgSubscribeValueLink wmMsgSubscribeValueLink
struct wmMsgSubscribeKey wmMsgSubscribeKey
void WM_msg_subscribe_rna_params(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msg_publish_rna_params(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
struct wmMsgParams_RNA wmMsgParams_RNA
void WM_msg_publish_static(struct wmMsgBus *mbus, int event)
struct wmMsg_RNA wmMsg_RNA
void WM_msg_id_update(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst)
void(* wmMsgSubscribeValueFreeDataFn)(struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val)
wmMsgSubscribeKey_RNA * WM_msg_lookup_rna(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
struct wmMsgSubscribeKey_RNA wmMsgSubscribeKey_RNA
void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info)
void WM_msg_subscribe_static(struct wmMsgBus *mbus, int event, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner)
void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info)
@ WM_MSG_STATICTYPE_WINDOW_DRAW
@ WM_MSG_STATICTYPE_FILE_READ
@ WM_MSG_STATICTYPE_SCREEN_EDIT
void WM_msg_publish_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
void WM_msg_subscribe_ID(struct wmMsgBus *mbus, struct ID *id, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msg_publish_ID(struct wmMsgBus *mbus, struct ID *id)
void WM_msgbus_destroy(struct wmMsgBus *mbus)
@ WM_MSG_TYPE_STATIC
@ WM_MSG_TYPE_RNA
struct wmMsg_Static wmMsg_Static
struct wmMsgTypeInfo wmMsgTypeInfo
void WM_msg_publish_rna(struct wmMsgBus *mbus, PointerRNA *ptr, PropertyRNA *prop)
struct wmMsgSubscribeValue wmMsgSubscribeValue
wmMsgSubscribeKey_Static * WM_msg_lookup_static(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
void WM_msg_dump(struct wmMsgBus *mbus, const char *info)
void WM_msgbus_types_init(void)
struct wmMsgParams_Static wmMsgParams_Static
void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
void WM_msg_id_remove(struct wmMsgBus *mbus, const struct ID *id)
void(* wmMsgNotifyFn)(struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val)
wmMsgSubscribeKey * WM_msg_subscribe_with_key(struct wmMsgBus *mbus, const wmMsgSubscribeKey *msg_key_test, const wmMsgSubscribeValue *msg_val_params)
void(* wmMsgSubscribeValueUpdateIdFn)(struct bContext *C, struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst, struct wmMsgSubscribeValue *msg_val)
void WM_msg_subscribe_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C)
struct wmMsg wmMsg
struct wmMsgSubscribeKey_Static wmMsgSubscribeKey_Static
struct wmMsgBus * WM_msgbus_create(void)
void WM_msg_subscribe_rna(struct wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)