Blender V5.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
8
9#pragma once
10
11#include "BLI_string_ref.hh"
12
13#include "DNA_listBase.h"
14
15#include "RNA_prototypes.hh"
16#include "RNA_types.hh"
17#include <cstdio>
18
19namespace blender {
20
21struct ID;
22struct bContext;
23struct wmMsg;
24/* Opaque (don't expose outside `wm_message_bus.cc`). */
25struct wmMsgBus;
29
30using wmMsgNotifyFn = void (*)(bContext *C,
31 wmMsgSubscribeKey *msg_key,
32 wmMsgSubscribeValue *msg_val);
34 wmMsgSubscribeValue *msg_val);
35
36/* Exactly what arguments here is not obvious. */
38 void (*)(bContext *C, wmMsgBus *mbus, ID *id_src, ID *id_dst, wmMsgSubscribeValue *msg_val);
39enum {
47};
48#define WM_MSG_TYPE_NUM 3
49
51 struct {
52 unsigned int (*hash_fn)(const void *msg);
53 bool (*cmp_fn)(const void *a, const void *b);
54
55 /* Creation, duplication and deletion callbacks. */
56 /* Not needed currently, key are always allocated by duplicating from stack data. */
57 /* void *(*key_alloc_fn)(); */
58 void *(*key_duplicate_fn)(const void *key);
59 void (*key_free_fn)(void *key);
61
62 void (*update_by_id)(wmMsgBus *mbus, ID *id_src, ID *id_dst);
63 void (*remove_by_id)(wmMsgBus *mbus, const ID *id);
64 void (*repr)(FILE *stream, const wmMsgSubscribeKey *msg_key);
65};
66
67struct wmMsg {
68 unsigned int type;
69 // #ifndef NDEBUG
70 /* For debugging: '__func__:__LINE__'. */
71 const char *id;
72 // #endif
73};
74
78 ListBaseT<wmMsgSubscribeValueLink> values;
79 /* Over-allocate, eg: #wmMsgSubscribeKey_RNA. */
80 /* Last member will be `wmMsg_*`. */
81};
82
86
88 void *owner;
90 void *user_data;
91
96
99 /* Tag to run when handling events,
100 * we may want option for immediate execution. */
102};
103
109
111
113void WM_msgbus_destroy(wmMsgBus *mbus);
114
115void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner);
116
117void WM_msg_dump(wmMsgBus *mbus, const char *info_str);
118void WM_msgbus_handle(wmMsgBus *mbus, bContext *C);
119
132 const wmMsgSubscribeKey *msg_key_test,
133 const wmMsgSubscribeValue *msg_val_params);
134
135void WM_msg_id_update(wmMsgBus *mbus, ID *id_src, ID *id_dst);
136void WM_msg_id_remove(wmMsgBus *mbus, const ID *id);
137
138/* -------------------------------------------------------------------------- */
139/* `wm_message_bus_static.cc` */
140
141enum {
142 /* Generic window redraw. */
146};
147
149 int event;
150};
151
153 wmMsg head; /* Keep first. */
155};
156
161
162void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info);
163
165 const wmMsgParams_Static *msg_key_params);
166void WM_msg_publish_static_params(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params);
168 /* #wmMsgParams_Static (expanded). */
169 int event);
171 const wmMsgParams_Static *msg_key_params,
172 const wmMsgSubscribeValue *msg_val_params,
173 const char *id_repr);
175 int event,
176 const wmMsgSubscribeValue *msg_val_params,
177 const char *id_repr);
178
179/* -------------------------------------------------------------------------- */
180/* `wm_message_bus_remote_io.cc` */
181
183 /* Owned, needs freeing with `MEM_delete_void()`. */
184 const char *remote_url;
185};
186
191
196
198
200 const wmMsgParams_RemoteIO *msg_key_params);
201void WM_msg_publish_remote_io_params(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params);
202void WM_msg_publish_remote_io(wmMsgBus *mbus, StringRef remote_url);
204 const wmMsgParams_RemoteIO *msg_key_params,
205 const wmMsgSubscribeValue *msg_val_params,
206 const char *id_repr);
208 StringRef remote_url,
209 const wmMsgSubscribeValue *msg_val_params,
210 const char *id_repr);
211
212/* -------------------------------------------------------------------------- */
213/* `wm_message_bus_rna.cc` */
214
227
228struct wmMsg_RNA {
229 wmMsg head; /* Keep first. */
231};
232
237
238void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info);
239
241void WM_msg_publish_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params);
243 /* #wmMsgParams_RNA (expanded). */
244 PointerRNA *ptr,
245 PropertyRNA *prop);
247 const wmMsgParams_RNA *msg_key_params,
248 const wmMsgSubscribeValue *msg_val_params,
249 const char *id_repr);
251 PointerRNA *ptr,
252 const PropertyRNA *prop,
253 const wmMsgSubscribeValue *msg_val_params,
254 const char *id_repr);
255
256/* ID variants. */
258 ID *id,
259 const wmMsgSubscribeValue *msg_val_params,
260 const char *id_repr);
261void WM_msg_publish_ID(wmMsgBus *mbus, ID *id);
262
263#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_) \
264 { \
265 wmMsgParams_RNA msg_key_params_ = {{}}; \
266 msg_key_params_.ptr = RNA_pointer_create_discrete(id_, RNA_##type_, data_); \
267 msg_key_params_.prop = &rna_##type_##_##prop_; \
268 WM_msg_publish_rna_params(mbus, &msg_key_params_); \
269 } \
270 ((void)0)
271#define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value) \
272 { \
273 wmMsgParams_RNA msg_key_params_ = {{}}; \
274 msg_key_params_.ptr = RNA_pointer_create_discrete(id_, RNA_##type_, data_); \
275 msg_key_params_.prop = &rna_##type_##_##prop_; \
276 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
277 } \
278 ((void)0)
279
280/* Anonymous variants (for convenience). */
281#define WM_msg_subscribe_rna_anon_type(mbus, type_, value) \
282 { \
283 PointerRNA msg_ptr_ = {nullptr, RNA_##type_, nullptr}; \
284 wmMsgParams_RNA msg_key_params_ = {{}}; \
285 msg_key_params_.ptr = msg_ptr_; \
286\
287 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
288 } \
289 ((void)0)
290#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value) \
291 { \
292 PointerRNA msg_ptr_ = {nullptr, RNA_##type_, nullptr}; \
293 wmMsgParams_RNA msg_key_params_ = {{}}; \
294 msg_key_params_.ptr = msg_ptr_; \
295 msg_key_params_.prop = &rna_##type_##_##prop_; \
296\
297 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
298 } \
299 ((void)0)
300
301} // namespace blender
These structs are the foundation for all linked lists in the library system.
#define C
Definition RandGen.cpp:29
BMesh Iterators.
void WM_msg_id_update(wmMsgBus *mbus, ID *id_src, ID *id_dst)
wmMsgSubscribeKey_RemoteIO * WM_msg_lookup_remote_io(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params)
void WM_msg_dump(wmMsgBus *mbus, const char *info_str)
void WM_msgbus_destroy(wmMsgBus *mbus)
unsigned int uint
Definition BKE_text.h:55
@ WM_MSG_STATICTYPE_WINDOW_DRAW
@ WM_MSG_STATICTYPE_SCREEN_EDIT
@ WM_MSG_STATICTYPE_FILE_READ
void WM_msg_publish_remote_io_params(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params)
wmMsgBus * WM_msgbus_create()
wmMsgSubscribeKey_Static * WM_msg_lookup_static(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
void WM_msgbus_types_init()
void WM_msg_subscribe_remote_io_params(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msg_subscribe_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msgbus_handle(wmMsgBus *mbus, bContext *C)
wmMsgSubscribeKey * WM_msg_subscribe_with_key(wmMsgBus *mbus, const wmMsgSubscribeKey *msg_key_test, const wmMsgSubscribeValue *msg_val_params)
void(*)(wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val) wmMsgSubscribeValueFreeDataFn
void(*)(bContext *C, wmMsgBus *mbus, ID *id_src, ID *id_dst, wmMsgSubscribeValue *msg_val) wmMsgSubscribeValueUpdateIdFn
void WM_msgtypeinfo_init_remote_io(wmMsgTypeInfo *msgtype_info)
void(*)(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val) wmMsgNotifyFn
void WM_msg_subscribe_remote_io(wmMsgBus *mbus, const StringRef remote_url, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
@ WM_MSG_TYPE_REMOTE_IO
void WM_msg_publish_static_params(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
void WM_msg_publish_remote_io(wmMsgBus *mbus, const StringRef remote_url)
void WM_msg_publish_with_key(wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner)
void WM_msg_publish_rna(wmMsgBus *mbus, PointerRNA *ptr, PropertyRNA *prop)
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msg_publish_ID(wmMsgBus *mbus, ID *id)
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_static(wmMsgBus *mbus, int event)
void WM_msg_id_remove(wmMsgBus *mbus, const ID *id)
void WM_msg_subscribe_static(wmMsgBus *mbus, int event, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info)
void WM_msg_subscribe_ID(wmMsgBus *mbus, ID *id, 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_publish_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info)
const PropertyRNA * prop
wmMsgSubscribeKey * next
ListBaseT< wmMsgSubscribeValueLink > values
wmMsgSubscribeKey * prev
wmMsgSubscribeValue * prev
wmMsgSubscribeValueFreeDataFn free_data
wmMsgSubscribeValueUpdateIdFn update_id
wmMsgSubscribeValue * next
bool(*) cmp_fn(const void *a, const void *b)
unsigned int(*) hash_fn(const void *msg)
void(*) repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
void(*) remove_by_id(wmMsgBus *mbus, const ID *id)
struct blender::wmMsgTypeInfo::@222252052342264033027352010177057107113002371022 gset
void(*) update_by_id(wmMsgBus *mbus, ID *id_src, ID *id_dst)
wmMsgParams_RNA params
wmMsgParams_RemoteIO params
wmMsgParams_Static params
unsigned int type
const char * id