Blender V5.0
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.h"
16#include "BLI_listbase.h"
17
18#include "WM_message.hh"
19#include "WM_types.hh"
21
22/* -------------------------------------------------------------------------- */
23
24static uint wm_msg_static_gset_hash(const void *key_p)
25{
26 const wmMsgSubscribeKey_Static *key = static_cast<const wmMsgSubscribeKey_Static *>(key_p);
27 const wmMsgParams_Static *params = &key->msg.params;
28 uint k = params->event;
29 return k;
30}
31static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
32{
33 const wmMsgParams_Static *params_a = &((const wmMsgSubscribeKey_Static *)key_a_p)->msg.params;
34 const wmMsgParams_Static *params_b = &((const wmMsgSubscribeKey_Static *)key_b_p)->msg.params;
35 return !(params_a->event == params_b->event);
36}
37
38static void *wm_msg_static_gset_key_duplicate(const void *key_p)
39{
40 const wmMsgSubscribeKey *key_src = static_cast<const wmMsgSubscribeKey *>(key_p);
41 return MEM_dupallocN<wmMsgSubscribeKey>(__func__, *key_src);
42}
43static void wm_msg_static_gset_key_free(void *key_p)
44{
45 wmMsgSubscribeKey *key = static_cast<wmMsgSubscribeKey *>(key_p);
46 wmMsgSubscribeValueLink *msg_lnk_next;
47 for (wmMsgSubscribeValueLink *msg_lnk =
48 static_cast<wmMsgSubscribeValueLink *>(key->values.first);
49 msg_lnk;
50 msg_lnk = msg_lnk_next)
51 {
52 msg_lnk_next = msg_lnk->next;
53 BLI_remlink(&key->values, msg_lnk);
54 MEM_freeN(msg_lnk);
55 }
56 MEM_freeN(key);
57}
58
59static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
60{
62 fprintf(stream,
63 "<wmMsg_Static %p, "
64 "id='%s', "
65 "values_len=%d\n",
66 m,
67 m->msg.head.id,
69}
70
79
80/* -------------------------------------------------------------------------- */
81
83 const wmMsgParams_Static *msg_key_params)
84{
86 key_test.msg.params = *msg_key_params;
87 return static_cast<wmMsgSubscribeKey_Static *>(
89}
90
92{
93 CLOG_DEBUG(WM_LOG_MSGBUS_PUB, "static(event=%d)", msg_key_params->event);
94
95 wmMsgSubscribeKey_Static *key = WM_msg_lookup_static(mbus, msg_key_params);
96 if (key) {
97 WM_msg_publish_with_key(mbus, &key->head);
98 }
99}
100
101void WM_msg_publish_static(wmMsgBus *mbus, int event)
102{
104 params.event = event;
106}
107
109 const wmMsgParams_Static *msg_key_params,
110 const wmMsgSubscribeValue *msg_val_params,
111 const char *id_repr)
112{
113 wmMsgSubscribeKey_Static msg_key_test{};
114
115 /* Use when added. */
116 msg_key_test.msg.head.id = id_repr;
117 msg_key_test.msg.head.type = WM_MSG_TYPE_STATIC;
118 /* For lookup. */
119 msg_key_test.msg.params = *msg_key_params;
120
121 WM_msg_subscribe_with_key(mbus, &msg_key_test.head, msg_val_params);
122}
123
125 int event,
126 const wmMsgSubscribeValue *msg_val_params,
127 const char *id_repr)
128{
130 params.event = event;
131 WM_msg_subscribe_static_params(mbus, &params, msg_val_params, id_repr);
132}
void * BLI_gset_lookup(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
unsigned int uint
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
Read Guarded memory(de)allocation.
CLG_LogRef * WM_LOG_MSGBUS_PUB
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void * first
GSet * messages_gset[WM_MSG_TYPE_NUM]
struct wmMsgTypeInfo::@062176151244273150215163026361115361006314120344 gset
void *(* key_duplicate_fn)(const void *key)
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_Static params
unsigned int type
const char * id
void WM_msg_publish_with_key(wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
wmMsgSubscribeKey * WM_msg_subscribe_with_key(wmMsgBus *mbus, const wmMsgSubscribeKey *msg_key_test, const wmMsgSubscribeValue *msg_val_params)
@ WM_MSG_TYPE_STATIC
static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
void WM_msg_publish_static(wmMsgBus *mbus, int event)
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)
static void * wm_msg_static_gset_key_duplicate(const void *key_p)
void WM_msg_subscribe_static(wmMsgBus *mbus, int event, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
static void wm_msg_static_repr(FILE *stream, const 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)
static uint wm_msg_static_gset_hash(const void *key_p)
static void wm_msg_static_gset_key_free(void *key_p)