Blender V5.3
wm_message_bus_static.cc
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#include <cstdio>
10
11#include "CLG_log.h"
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_ghash.hh"
16#include "BLI_listbase.hh"
17
18#include "WM_message.hh"
19#include "WM_types.hh"
21
22namespace blender {
23
24/* -------------------------------------------------------------------------- */
25
26static uint wm_msg_static_gset_hash(const void *key_p)
27{
28 const wmMsgSubscribeKey_Static *key = static_cast<const wmMsgSubscribeKey_Static *>(key_p);
29 const wmMsgParams_Static *params = &key->msg.params;
30 uint k = params->event;
31 return k;
32}
33static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
34{
35 const wmMsgParams_Static *params_a =
36 &(static_cast<const wmMsgSubscribeKey_Static *>(key_a_p))->msg.params;
37 const wmMsgParams_Static *params_b =
38 &(static_cast<const wmMsgSubscribeKey_Static *>(key_b_p))->msg.params;
39 return !(params_a->event == params_b->event);
40}
41
42static void *wm_msg_static_gset_key_duplicate(const void *key_p)
43{
44 const wmMsgSubscribeKey *key_src = static_cast<const wmMsgSubscribeKey *>(key_p);
45 return MEM_new<wmMsgSubscribeKey>(__func__, *key_src);
46}
47static void wm_msg_static_gset_key_free(void *key_p)
48{
49 wmMsgSubscribeKey *key = static_cast<wmMsgSubscribeKey *>(key_p);
50 wmMsgSubscribeValueLink *msg_lnk_next;
51 for (wmMsgSubscribeValueLink *msg_lnk = key->values.first(); msg_lnk; msg_lnk = msg_lnk_next) {
52 msg_lnk_next = msg_lnk->next;
53 BLI_remlink(&key->values, msg_lnk);
54 MEM_delete(msg_lnk);
55 }
56 MEM_delete(key);
57}
58
59static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
60{
61 const wmMsgSubscribeKey_Static *m = reinterpret_cast<wmMsgSubscribeKey_Static *>(
62 const_cast<wmMsgSubscribeKey *>(msg_key));
63 fprintf(stream,
64 "<wmMsg_Static %p, "
65 "id='%s', "
66 "values_len=%d\n",
67 m,
68 m->msg.head.id,
69 m->head.values.count());
70}
71
73{
74 msgtype_info->gset.hash_fn = wm_msg_static_gset_hash;
75 msgtype_info->gset.cmp_fn = wm_msg_static_gset_cmp;
76 msgtype_info->gset.key_duplicate_fn = wm_msg_static_gset_key_duplicate;
77 msgtype_info->gset.key_free_fn = wm_msg_static_gset_key_free;
78 msgtype_info->repr = wm_msg_static_repr;
79}
80
81/* -------------------------------------------------------------------------- */
82
84 const wmMsgParams_Static *msg_key_params)
85{
87 key_test.msg.params = *msg_key_params;
88 return static_cast<wmMsgSubscribeKey_Static *>(
90}
91
93{
94 CLOG_DEBUG(WM_LOG_MSGBUS_PUB, "static(event=%d)", msg_key_params->event);
95
96 wmMsgSubscribeKey_Static *key = WM_msg_lookup_static(mbus, msg_key_params);
97 if (key) {
98 WM_msg_publish_with_key(mbus, &key->head);
99 }
100}
101
102void WM_msg_publish_static(wmMsgBus *mbus, int event)
103{
104 wmMsgParams_Static params{};
105 params.event = event;
106 WM_msg_publish_static_params(mbus, &params);
107}
108
110 const wmMsgParams_Static *msg_key_params,
111 const wmMsgSubscribeValue *msg_val_params,
112 const char *id_repr)
113{
114 wmMsgSubscribeKey_Static msg_key_test{};
115
116 /* Use when added. */
117 msg_key_test.msg.head.id = id_repr;
118 msg_key_test.msg.head.type = WM_MSG_TYPE_STATIC;
119 /* For lookup. */
120 msg_key_test.msg.params = *msg_key_params;
121
122 WM_msg_subscribe_with_key(mbus, &msg_key_test.head, msg_val_params);
123}
124
126 int event,
127 const wmMsgSubscribeValue *msg_val_params,
128 const char *id_repr)
129{
130 wmMsgParams_Static params{};
131 params.event = event;
132 WM_msg_subscribe_static_params(mbus, &params, msg_val_params, id_repr);
133}
134
135} // namespace blender
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
Read Blender memory allocation and freeing.
BMesh Iterators.
static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
unsigned int uint
Definition BKE_text.h:55
void * BLI_gset_lookup(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
wmMsgSubscribeKey_Static * WM_msg_lookup_static(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
static void wm_msg_static_gset_key_free(void *key_p)
static void * wm_msg_static_gset_key_duplicate(const void *key_p)
wmMsgSubscribeKey * WM_msg_subscribe_with_key(wmMsgBus *mbus, const wmMsgSubscribeKey *msg_key_test, const wmMsgSubscribeValue *msg_val_params)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void WM_msg_publish_static_params(wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
void WM_msg_publish_with_key(wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
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_subscribe_static(wmMsgBus *mbus, int event, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info)
CLG_LogRef * WM_LOG_MSGBUS_PUB
static uint wm_msg_static_gset_hash(const void *key_p)
GSet * messages_gset[WM_MSG_TYPE_NUM]
ListBaseT< wmMsgSubscribeValueLink > values
void(*) repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
struct blender::wmMsgTypeInfo::@222252052342264033027352010177057107113002371022 gset
wmMsgParams_Static params
unsigned int type
const char * id