Blender V4.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
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#include "BLI_utildefines.h"
18
19#include "WM_message.hh"
20#include "WM_types.hh"
22
23/* -------------------------------------------------------------------------- */
24
25static uint wm_msg_static_gset_hash(const void *key_p)
26{
27 const wmMsgSubscribeKey_Static *key = static_cast<const wmMsgSubscribeKey_Static *>(key_p);
28 const wmMsgParams_Static *params = &key->msg.params;
29 uint k = params->event;
30 return k;
31}
32static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
33{
34 const wmMsgParams_Static *params_a = &((const wmMsgSubscribeKey_Static *)key_a_p)->msg.params;
35 const wmMsgParams_Static *params_b = &((const wmMsgSubscribeKey_Static *)key_b_p)->msg.params;
36 return !(params_a->event == params_b->event);
37}
38static void wm_msg_static_gset_key_free(void *key_p)
39{
40 wmMsgSubscribeKey *key = static_cast<wmMsgSubscribeKey *>(key_p);
41 wmMsgSubscribeValueLink *msg_lnk_next;
42 for (wmMsgSubscribeValueLink *msg_lnk =
43 static_cast<wmMsgSubscribeValueLink *>(key->values.first);
44 msg_lnk;
45 msg_lnk = msg_lnk_next)
46 {
47 msg_lnk_next = msg_lnk->next;
48 BLI_remlink(&key->values, msg_lnk);
49 MEM_freeN(msg_lnk);
50 }
51 MEM_freeN(key);
52}
53
54static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
55{
57 fprintf(stream,
58 "<wmMsg_Static %p, "
59 "id='%s', "
60 "values_len=%d\n",
61 m,
62 m->msg.head.id,
64}
65
67{
68 msgtype_info->gset.hash_fn = wm_msg_static_gset_hash;
69 msgtype_info->gset.cmp_fn = wm_msg_static_gset_cmp;
71 msgtype_info->repr = wm_msg_static_repr;
72
73 msgtype_info->msg_key_size = sizeof(wmMsgSubscribeKey_Static);
74}
75
76/* -------------------------------------------------------------------------- */
77
79 const wmMsgParams_Static *msg_key_params)
80{
82 key_test.msg.params = *msg_key_params;
83 return static_cast<wmMsgSubscribeKey_Static *>(
85}
86
88{
89 CLOG_INFO(WM_LOG_MSGBUS_PUB, 2, "static(event=%d)", msg_key_params->event);
90
91 wmMsgSubscribeKey_Static *key = WM_msg_lookup_static(mbus, msg_key_params);
92 if (key) {
93 WM_msg_publish_with_key(mbus, &key->head);
94 }
95}
96
97void WM_msg_publish_static(wmMsgBus *mbus, int event)
98{
100 params.event = event;
102}
103
105 const wmMsgParams_Static *msg_key_params,
106 const wmMsgSubscribeValue *msg_val_params,
107 const char *id_repr)
108{
109 wmMsgSubscribeKey_Static msg_key_test = {{nullptr}};
110
111 /* Use when added. */
112 msg_key_test.msg.head.id = id_repr;
113 msg_key_test.msg.head.type = WM_MSG_TYPE_STATIC;
114 /* For lookup. */
115 msg_key_test.msg.params = *msg_key_params;
116
117 WM_msg_subscribe_with_key(mbus, &msg_key_test.head, msg_val_params);
118}
119
121 int event,
122 const wmMsgSubscribeValue *msg_val_params,
123 const char *id_repr)
124{
126 params.event = event;
127 WM_msg_subscribe_static_params(mbus, &params, msg_val_params, id_repr);
128}
void * BLI_gset_lookup(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:1058
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:130
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int uint
#define CLOG_INFO(clg_ref, level,...)
Definition CLG_log.h:179
Read Guarded memory(de)allocation.
CLG_LogRef * WM_LOG_MSGBUS_PUB
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void * first
GSet * messages_gset[WM_MSG_TYPE_NUM]
struct wmMsgTypeInfo::@1392 gset
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)
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)