Blender V4.5
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 "DNA_listBase.h"
12
13#include "RNA_prototypes.hh"
14#include "RNA_types.hh"
15#include <cstdio>
16
17struct ID;
18struct bContext;
19struct wmMsg;
20/* Opaque (don't expose outside `wm_message_bus.cc`). */
21struct wmMsgBus;
25
26using wmMsgNotifyFn = void (*)(bContext *C,
27 wmMsgSubscribeKey *msg_key,
28 wmMsgSubscribeValue *msg_val);
30 wmMsgSubscribeValue *msg_val);
31
32/* Exactly what arguments here is not obvious. */
34 void (*)(bContext *C, wmMsgBus *mbus, ID *id_src, ID *id_dst, wmMsgSubscribeValue *msg_val);
35enum {
38};
39#define WM_MSG_TYPE_NUM 2
40
42 struct {
43 unsigned int (*hash_fn)(const void *msg);
44 bool (*cmp_fn)(const void *a, const void *b);
45
46 /* Creation, duplication and deletion callbacks. */
47 /* Not needed currently, key are always allocated by duplicating from stack data. */
48 /* void *(*key_alloc_fn)(); */
49 void *(*key_duplicate_fn)(const void *key);
50 void (*key_free_fn)(void *key);
52
53 void (*update_by_id)(wmMsgBus *mbus, ID *id_src, ID *id_dst);
54 void (*remove_by_id)(wmMsgBus *mbus, const ID *id);
55 void (*repr)(FILE *stream, const wmMsgSubscribeKey *msg_key);
56};
57
58struct wmMsg {
59 unsigned int type;
60 // #ifndef NDEBUG
61 /* For debugging: '__func__:__LINE__'. */
62 const char *id;
63 // #endif
64};
65
70 /* Over-allocate, eg: #wmMsgSubscribeKey_RNA. */
71 /* Last member will be `wmMsg_*`. */
72};
73
77
79 void *owner;
81 void *user_data;
82
87
90 /* Tag to run when handling events,
91 * we may want option for immediate execution. */
92 uint tag : 1;
93};
94
100
102
104void WM_msgbus_destroy(wmMsgBus *mbus);
105
106void WM_msgbus_clear_by_owner(wmMsgBus *mbus, void *owner);
107
108void WM_msg_dump(wmMsgBus *mbus, const char *info_str);
109void WM_msgbus_handle(wmMsgBus *mbus, bContext *C);
110
123 const wmMsgSubscribeKey *msg_key_test,
124 const wmMsgSubscribeValue *msg_val_params);
125
126void WM_msg_id_update(wmMsgBus *mbus, ID *id_src, ID *id_dst);
127void WM_msg_id_remove(wmMsgBus *mbus, const ID *id);
128
129/* -------------------------------------------------------------------------- */
130/* `wm_message_bus_static.cc` */
131
132enum {
133 /* Generic window redraw. */
137};
138
140 int event;
141};
142
144 wmMsg head; /* Keep first. */
146};
147
152
153void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info);
154
156 const wmMsgParams_Static *msg_key_params);
157void WM_msg_publish_static_params(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params);
159 /* #wmMsgParams_Static (expanded). */
160 int event);
162 const wmMsgParams_Static *msg_key_params,
163 const wmMsgSubscribeValue *msg_val_params,
164 const char *id_repr);
166 int event,
167 const wmMsgSubscribeValue *msg_val_params,
168 const char *id_repr);
169
170/* -------------------------------------------------------------------------- */
171/* `wm_message_bus_rna.cc` */
172
185
186struct wmMsg_RNA {
187 wmMsg head; /* Keep first. */
189};
190
195
196void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info);
197
199void WM_msg_publish_rna_params(wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params);
201 /* #wmMsgParams_RNA (expanded). */
203 PropertyRNA *prop);
205 const wmMsgParams_RNA *msg_key_params,
206 const wmMsgSubscribeValue *msg_val_params,
207 const char *id_repr);
210 const PropertyRNA *prop,
211 const wmMsgSubscribeValue *msg_val_params,
212 const char *id_repr);
213
214/* ID variants. */
216 ID *id,
217 const wmMsgSubscribeValue *msg_val_params,
218 const char *id_repr);
219void WM_msg_publish_ID(wmMsgBus *mbus, ID *id);
220
221#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_) \
222 { \
223 wmMsgParams_RNA msg_key_params_ = {{}}; \
224 msg_key_params_.ptr = RNA_pointer_create_discrete(id_, &RNA_##type_, data_); \
225 msg_key_params_.prop = &rna_##type_##_##prop_; \
226 WM_msg_publish_rna_params(mbus, &msg_key_params_); \
227 } \
228 ((void)0)
229#define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value) \
230 { \
231 wmMsgParams_RNA msg_key_params_ = {{}}; \
232 msg_key_params_.ptr = RNA_pointer_create_discrete(id_, &RNA_##type_, data_); \
233 msg_key_params_.prop = &rna_##type_##_##prop_; \
234 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
235 } \
236 ((void)0)
237
238/* Anonymous variants (for convenience). */
239#define WM_msg_subscribe_rna_anon_type(mbus, type_, value) \
240 { \
241 PointerRNA msg_ptr_ = {nullptr, &RNA_##type_, nullptr}; \
242 wmMsgParams_RNA msg_key_params_ = {{}}; \
243 msg_key_params_.ptr = msg_ptr_; \
244\
245 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
246 } \
247 ((void)0)
248#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value) \
249 { \
250 PointerRNA msg_ptr_ = {nullptr, &RNA_##type_, nullptr}; \
251 wmMsgParams_RNA msg_key_params_ = {{}}; \
252 msg_key_params_.ptr = msg_ptr_; \
253 msg_key_params_.prop = &rna_##type_##_##prop_; \
254\
255 WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
256 } \
257 ((void)0)
unsigned int uint
These structs are the foundation for all linked lists in the library system.
#define C
Definition RandGen.cpp:29
Definition DNA_ID.h:404
const PropertyRNA * prop
wmMsgSubscribeKey head
wmMsgSubscribeKey * prev
wmMsgSubscribeKey * next
wmMsgSubscribeValueFreeDataFn free_data
wmMsgSubscribeValue * next
wmMsgSubscribeValueUpdateIdFn update_id
wmMsgSubscribeValue * prev
struct wmMsgTypeInfo::@336105212232015317135126101342040026306335204204 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:4226
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)
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)
@ WM_MSG_STATICTYPE_WINDOW_DRAW
@ WM_MSG_STATICTYPE_FILE_READ
@ WM_MSG_STATICTYPE_SCREEN_EDIT
@ WM_MSG_TYPE_STATIC
@ WM_MSG_TYPE_RNA
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)
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)