Blender V4.3
wm_message_bus.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "RNA_prototypes.hh"
12#include "RNA_types.hh"
13#include <stdio.h>
14
15struct ID;
16struct bContext;
17struct wmMsg;
18/* Opaque (don't expose outside `wm_message_bus.cc`). */
19struct wmMsgBus;
23
24using wmMsgNotifyFn = void (*)(bContext *C,
25 wmMsgSubscribeKey *msg_key,
26 wmMsgSubscribeValue *msg_val);
28 wmMsgSubscribeValue *msg_val);
29
30/* Exactly what arguments here is not obvious. */
32 void (*)(bContext *C, wmMsgBus *mbus, ID *id_src, ID *id_dst, wmMsgSubscribeValue *msg_val);
33enum {
36};
37#define WM_MSG_TYPE_NUM 2
38
40 struct {
41 unsigned int (*hash_fn)(const void *msg);
42 bool (*cmp_fn)(const void *a, const void *b);
43 void (*key_free_fn)(void *key);
45
46 void (*update_by_id)(wmMsgBus *mbus, ID *id_src, ID *id_dst);
47 void (*remove_by_id)(wmMsgBus *mbus, const ID *id);
48 void (*repr)(FILE *stream, const wmMsgSubscribeKey *msg_key);
49
50 /* `sizeof(wmMsgSubscribeKey_*)`. */
52};
53
54struct wmMsg {
55 unsigned int type;
56 // #ifndef NDEBUG
57 /* For debugging: '__func__:__LINE__'. */
58 const char *id;
59 // #endif
60};
61
66 /* Over-allocate, eg: #wmMsgSubscribeKey_RNA. */
67 /* Last member will be `wmMsg_*`. */
68};
69
73
75 void *owner;
77 void *user_data;
78
83
86 /* Tag to run when handling events,
87 * we may want option for immediate execution. */
88 uint tag : 1;
89};
90
96
98
100void WM_msgbus_destroy(wmMsgBus *mbus);
101
102void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner);
103
104void WM_msg_dump(wmMsgBus *mbus, const char *info_str);
105void WM_msgbus_handle(wmMsgBus *mbus, bContext *C);
106
119 const wmMsgSubscribeKey *msg_key_test,
120 const wmMsgSubscribeValue *msg_val_params);
121
122void WM_msg_id_update(wmMsgBus *mbus, ID *id_src, ID *id_dst);
123void WM_msg_id_remove(wmMsgBus *mbus, const ID *id);
124
125/* -------------------------------------------------------------------------- */
126/* `wm_message_bus_static.cc` */
127
128enum {
129 /* Generic window redraw. */
133};
134
136 int event;
137};
138
140 wmMsg head; /* Keep first. */
142};
143
148
149void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info);
150
152 const wmMsgParams_Static *msg_key_params);
153void WM_msg_publish_static_params(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params);
155 /* #wmMsgParams_Static (expanded). */
156 int event);
158 const wmMsgParams_Static *msg_key_params,
159 const wmMsgSubscribeValue *msg_val_params,
160 const char *id_repr);
162 int event,
163 const wmMsgSubscribeValue *msg_val_params,
164 const char *id_repr);
165
166/* -------------------------------------------------------------------------- */
167/* `wm_message_bus_rna.cc` */
168
181
182struct wmMsg_RNA {
183 wmMsg head; /* Keep first. */
185};
186
191
192void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info);
193
195void WM_msg_publish_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params);
197 /* #wmMsgParams_RNA (expanded). */
199 PropertyRNA *prop);
201 const wmMsgParams_RNA *msg_key_params,
202 const wmMsgSubscribeValue *msg_val_params,
203 const char *id_repr);
206 const PropertyRNA *prop,
207 const wmMsgSubscribeValue *msg_val_params,
208 const char *id_repr);
209
210/* ID variants. */
212 ID *id,
213 const wmMsgSubscribeValue *msg_val_params,
214 const char *id_repr);
215void WM_msg_publish_ID(wmMsgBus *mbus, ID *id);
216
217#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_) \
218 { \
219 wmMsgParams_RNA msg_key_params_ = {{0}}; \
220 msg_key_params_.ptr = RNA_pointer_create(id_, &RNA_##type_, data_); \
221 msg_key_params_.prop = &rna_##type_##_##prop_; \
222 WM_msg_publish_rna_params(mbus, &msg_key_params_); \
223 } \
224 ((void)0)
225#define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value) \
226 { \
227 wmMsgParams_RNA msg_key_params_ = {{0}}; \
228 msg_key_params_.ptr = RNA_pointer_create(id_, &RNA_##type_, data_); \
229 msg_key_params_.prop = &rna_##type_##_##prop_; \
230 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
231 } \
232 ((void)0)
233
234/* Anonymous variants (for convenience). */
235#define WM_msg_subscribe_rna_anon_type(mbus, type_, value) \
236 { \
237 PointerRNA msg_ptr_ = {0, &RNA_##type_}; \
238 wmMsgParams_RNA msg_key_params_ = {{0}}; \
239 msg_key_params_.ptr = msg_ptr_; \
240\
241 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
242 } \
243 ((void)0)
244#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value) \
245 { \
246 PointerRNA msg_ptr_ = {0, &RNA_##type_}; \
247 wmMsgParams_RNA msg_key_params_ = {{0}}; \
248 msg_key_params_.ptr = msg_ptr_; \
249 msg_key_params_.prop = &rna_##type_##_##prop_; \
250\
251 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
252 } \
253 ((void)0)
unsigned int uint
#define C
Definition RandGen.cpp:29
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
Definition DNA_ID.h:413
const PropertyRNA * prop
wmMsgSubscribeKey head
wmMsgSubscribeKey * prev
wmMsgSubscribeKey * next
wmMsgSubscribeValueFreeDataFn free_data
wmMsgSubscribeValue * next
wmMsgSubscribeValueUpdateIdFn update_id
wmMsgSubscribeValue * prev
struct wmMsgTypeInfo::@1392 gset
void(* remove_by_id)(wmMsgBus *mbus, const ID *id)
void(* update_by_id)(wmMsgBus *mbus, ID *id_src, ID *id_dst)
void(* repr)(FILE *stream, const wmMsgSubscribeKey *msg_key)
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.cc:4126
void WM_msg_subscribe_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
wmMsgSubscribeKey_RNA * WM_msg_lookup_rna(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void(*)(wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val) wmMsgSubscribeValueFreeDataFn
void WM_msgbus_destroy(wmMsgBus *mbus)
void WM_msg_publish_static(wmMsgBus *mbus, int event)
void WM_msg_publish_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info)
void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info)
@ WM_MSG_TYPE_STATIC
@ WM_MSG_TYPE_RNA
void WM_msg_publish_static_params(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
wmMsgSubscribeKey_Static * WM_msg_lookup_static(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
void(*)(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val) wmMsgNotifyFn
void WM_msg_subscribe_static(wmMsgBus *mbus, int event, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msg_publish_ID(wmMsgBus *mbus, ID *id)
void WM_msg_publish_with_key(wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
void WM_msg_id_update(wmMsgBus *mbus, ID *id_src, ID *id_dst)
void WM_msg_subscribe_static_params(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msg_publish_rna(wmMsgBus *mbus, PointerRNA *ptr, PropertyRNA *prop)
void WM_msgbus_handle(wmMsgBus *mbus, bContext *C)
@ WM_MSG_STATICTYPE_WINDOW_DRAW
@ WM_MSG_STATICTYPE_FILE_READ
@ WM_MSG_STATICTYPE_SCREEN_EDIT
void WM_msg_id_remove(wmMsgBus *mbus, const ID *id)
wmMsgBus * WM_msgbus_create()
void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner)
wmMsgSubscribeKey * WM_msg_subscribe_with_key(wmMsgBus *mbus, const wmMsgSubscribeKey *msg_key_test, const wmMsgSubscribeValue *msg_val_params)
void(*)(bContext *C, wmMsgBus *mbus, ID *id_src, ID *id_dst, wmMsgSubscribeValue *msg_val) wmMsgSubscribeValueUpdateIdFn
void WM_msgbus_types_init()
void WM_msg_dump(wmMsgBus *mbus, const char *info_str)
void WM_msg_subscribe_ID(wmMsgBus *mbus, ID *id, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)