Blender  V3.3
wm_message_bus.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 #include "RNA_prototypes.h"
10 #include "RNA_types.h"
11 #include <stdio.h>
12 
13 struct ID;
14 struct bContext;
15 struct wmMsg;
16 
17 /* opaque (don't expose outside wm_message_bus.c) */
18 struct wmMsgBus;
19 struct wmMsgSubscribeKey;
20 struct wmMsgSubscribeValue;
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef void (*wmMsgNotifyFn)(struct bContext *C,
28  struct wmMsgSubscribeKey *msg_key,
29  struct wmMsgSubscribeValue *msg_val);
31  struct wmMsgSubscribeValue *msg_val);
32 
33 /* Exactly what arguments here is not obvious. */
35  struct wmMsgBus *mbus,
36  struct ID *id_src,
37  struct ID *id_dst,
38  struct wmMsgSubscribeValue *msg_val);
39 enum {
42 };
43 #define WM_MSG_TYPE_NUM 2
44 
45 typedef struct wmMsgTypeInfo {
46  struct {
47  unsigned int (*hash_fn)(const void *msg);
48  bool (*cmp_fn)(const void *a, const void *b);
49  void (*key_free_fn)(void *key);
50  } gset;
51 
52  void (*update_by_id)(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst);
53  void (*remove_by_id)(struct wmMsgBus *mbus, const struct ID *id);
54  void (*repr)(FILE *stream, const struct wmMsgSubscribeKey *msg_key);
55 
56  /* sizeof(wmMsgSubscribeKey_*) */
59 
60 typedef struct wmMsg {
61  unsigned int type;
62  // #ifdef DEBUG
63  /* For debugging: '__func__:__LINE__'. */
64  const char *id;
65  // #endif
67 
68 typedef struct wmMsgSubscribeKey {
72  /* over-alloc, eg: wmMsgSubscribeKey_RNA */
73  /* Last member will be 'wmMsg_*' */
75 
77 typedef struct wmMsgSubscribeValue {
78  struct wmMsgSubscribe *next, *prev;
79 
81  void *owner;
83  void *user_data;
84 
89 
92  /* tag to run when handling events,
93  * we may want option for immediate execution. */
94  uint tag : 1;
96 
98 typedef struct wmMsgSubscribeValueLink {
102 
103 void WM_msgbus_types_init(void);
104 
105 struct wmMsgBus *WM_msgbus_create(void);
106 void WM_msgbus_destroy(struct wmMsgBus *mbus);
107 
108 void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner);
109 
110 void WM_msg_dump(struct wmMsgBus *mbus, const char *info);
111 void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C);
112 
113 void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key);
125  const wmMsgSubscribeKey *msg_key_test,
126  const wmMsgSubscribeValue *msg_val_params);
127 
128 void WM_msg_id_update(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst);
129 void WM_msg_id_remove(struct wmMsgBus *mbus, const struct ID *id);
130 
131 /* -------------------------------------------------------------------------- */
132 /* wm_message_bus_static.c */
133 
134 enum {
135  /* generic window redraw */
139 };
140 
141 typedef struct wmMsgParams_Static {
142  int event;
144 
145 typedef struct wmMsg_Static {
146  wmMsg head; /* keep first */
149 
150 typedef struct wmMsgSubscribeKey_Static {
154 
155 void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info);
156 
158  const wmMsgParams_Static *msg_key_params);
159 void WM_msg_publish_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params);
160 void WM_msg_publish_static(struct wmMsgBus *mbus,
161  /* wmMsgParams_Static (expanded) */
162  int event);
163 void WM_msg_subscribe_static_params(struct wmMsgBus *mbus,
164  const wmMsgParams_Static *msg_key_params,
165  const wmMsgSubscribeValue *msg_val_params,
166  const char *id_repr);
167 void WM_msg_subscribe_static(struct wmMsgBus *mbus,
168  int event,
169  const wmMsgSubscribeValue *msg_val_params,
170  const char *id_repr);
171 
172 /* -------------------------------------------------------------------------- */
173 /* wm_message_bus_rna.c */
174 
175 typedef struct wmMsgParams_RNA {
180 
185  char *data_path;
187 
188 typedef struct wmMsg_RNA {
189  wmMsg head; /* keep first */
192 
193 typedef struct wmMsgSubscribeKey_RNA {
197 
198 void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info);
199 
201  const wmMsgParams_RNA *msg_key_params);
202 void WM_msg_publish_rna_params(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params);
203 void WM_msg_publish_rna(struct wmMsgBus *mbus,
204  /* wmMsgParams_RNA (expanded) */
205  PointerRNA *ptr,
206  PropertyRNA *prop);
207 void WM_msg_subscribe_rna_params(struct wmMsgBus *mbus,
208  const wmMsgParams_RNA *msg_key_params,
209  const wmMsgSubscribeValue *msg_val_params,
210  const char *id_repr);
211 void WM_msg_subscribe_rna(struct wmMsgBus *mbus,
212  PointerRNA *ptr,
213  const PropertyRNA *prop,
214  const wmMsgSubscribeValue *msg_val_params,
215  const char *id_repr);
216 
217 /* ID variants */
218 void WM_msg_subscribe_ID(struct wmMsgBus *mbus,
219  struct ID *id,
220  const wmMsgSubscribeValue *msg_val_params,
221  const char *id_repr);
222 void WM_msg_publish_ID(struct wmMsgBus *mbus, struct ID *id);
223 
224 #define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_) \
225  { \
226  wmMsgParams_RNA msg_key_params_ = {{0}}; \
227  RNA_pointer_create(id_, &RNA_##type_, data_, &msg_key_params_.ptr); \
228  msg_key_params_.prop = &rna_##type_##_##prop_; \
229  WM_msg_publish_rna_params(mbus, &msg_key_params_); \
230  } \
231  ((void)0)
232 #define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value) \
233  { \
234  wmMsgParams_RNA msg_key_params_ = {{0}}; \
235  RNA_pointer_create(id_, &RNA_##type_, data_, &msg_key_params_.ptr); \
236  msg_key_params_.prop = &rna_##type_##_##prop_; \
237  WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
238  } \
239  ((void)0)
240 
241 /* Anonymous variants (for convenience) */
242 #define WM_msg_subscribe_rna_anon_type(mbus, type_, value) \
243  { \
244  PointerRNA msg_ptr_ = {0, &RNA_##type_}; \
245  wmMsgParams_RNA msg_key_params_ = {{0}}; \
246  msg_key_params_.ptr = msg_ptr_; \
247 \
248  WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
249  } \
250  ((void)0)
251 #define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value) \
252  { \
253  PointerRNA msg_ptr_ = {0, &RNA_##type_}; \
254  wmMsgParams_RNA msg_key_params_ = {{0}}; \
255  msg_key_params_.ptr = msg_ptr_; \
256  msg_key_params_.prop = &rna_##type_##_##prop_; \
257 \
258  WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
259  } \
260  ((void)0)
261 
262 #ifdef __cplusplus
263 }
264 #endif
unsigned int uint
Definition: BLI_sys_types.h:67
#define C
Definition: RandGen.cpp:25
SyclQueue void void size_t num_bytes void
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
Definition: DNA_ID.h:368
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)
struct wmMsgTypeInfo::@1202 gset
unsigned int(* hash_fn)(const void *msg)
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:3480
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)
@ WM_MSG_STATICTYPE_WINDOW_DRAW
@ WM_MSG_STATICTYPE_FILE_READ
@ WM_MSG_STATICTYPE_SCREEN_EDIT
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)
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)
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
@ WM_MSG_TYPE_STATIC
@ WM_MSG_TYPE_RNA
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)