Blender V5.0
wm_message_bus_remote_io.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "CLG_log.h"
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_ghash.h"
14#include "BLI_hash.h"
15#include "BLI_listbase.h"
16#include "BLI_string.h"
17#include "BLI_string_ref.hh"
18
19#include "WM_types.hh"
21
22/* -------------------------------------------------------------------------- */
23
24static uint wm_msg_remote_io_gset_hash(const void *key_p)
25{
26 const wmMsgSubscribeKey_RemoteIO *key = static_cast<const wmMsgSubscribeKey_RemoteIO *>(key_p);
28 uint k = BLI_hash_string(params->remote_url);
29 return k;
30}
31static bool wm_msg_remote_io_gset_cmp(const void *key_a_p, const void *key_b_p)
32{
33 const wmMsgParams_RemoteIO *params_a =
34 &(static_cast<const wmMsgSubscribeKey_RemoteIO *>(key_a_p))->msg.params;
35 const wmMsgParams_RemoteIO *params_b =
36 &(static_cast<const wmMsgSubscribeKey_RemoteIO *>(key_b_p))->msg.params;
37 return !STREQ(params_a->remote_url, params_b->remote_url);
38}
39
40static void *wm_msg_remote_io_gset_key_duplicate(const void *key_p)
41{
42 const wmMsgSubscribeKey_RemoteIO *key_src = static_cast<const wmMsgSubscribeKey_RemoteIO *>(
43 key_p);
46 return key;
47}
48static void wm_msg_remote_io_gset_key_free(void *key_p)
49{
50 wmMsgSubscribeKey_RemoteIO *key = static_cast<wmMsgSubscribeKey_RemoteIO *>(key_p);
52 wmMsgSubscribeValueLink *msg_lnk_next;
53 for (wmMsgSubscribeValueLink *msg_lnk =
54 static_cast<wmMsgSubscribeValueLink *>(key->head.values.first);
55 msg_lnk;
56 msg_lnk = msg_lnk_next)
57 {
58 msg_lnk_next = msg_lnk->next;
59 BLI_remlink(&key->head.values, msg_lnk);
60 MEM_freeN(msg_lnk);
61 }
62 MEM_freeN(key);
63}
64
65static void wm_msg_remote_io_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
66{
68 fprintf(stream,
69 "<wmMsg_RemoteIO %p, "
70 "id='%s', "
71 "values_len=%d\n",
72 m,
73 m->msg.head.id,
75}
76
85
86/* -------------------------------------------------------------------------- */
87
89 const wmMsgParams_RemoteIO *msg_key_params)
90{
92 key_test.msg.params = *msg_key_params;
93 return static_cast<wmMsgSubscribeKey_RemoteIO *>(
95}
96
98{
99 CLOG_DEBUG(WM_LOG_MSGBUS_PUB, "remote_io(remote_url=%s)", msg_key_params->remote_url);
100
101 wmMsgSubscribeKey_RemoteIO *key = WM_msg_lookup_remote_io(mbus, msg_key_params);
102 if (key) {
103 WM_msg_publish_with_key(mbus, &key->head);
104 }
105}
106
108{
110 params.remote_url = BLI_strdupn(remote_url.data(), remote_url.size());
112
113 /* Value was copied into the publish key. */
114 MEM_freeN(params.remote_url);
115}
116
118 const wmMsgParams_RemoteIO *msg_key_params,
119 const wmMsgSubscribeValue *msg_val_params,
120 const char *id_repr)
121{
122 wmMsgSubscribeKey_RemoteIO msg_key_test{};
123
124 /* Use when added. */
125 msg_key_test.msg.head.id = id_repr;
126 msg_key_test.msg.head.type = WM_MSG_TYPE_REMOTE_IO;
127 /* For lookup. */
128 msg_key_test.msg.params = *msg_key_params;
129
130 WM_msg_subscribe_with_key(mbus, &msg_key_test.head, msg_val_params);
131}
132
134 const blender::StringRef remote_url,
135 const wmMsgSubscribeValue *msg_val_params,
136 const char *id_repr)
137{
139 params.remote_url = BLI_strdupn(remote_url.data(), remote_url.size());
140 WM_msg_subscribe_remote_io_params(mbus, &params, msg_val_params, id_repr);
141
142 /* Value was copied into the subscribe key. */
143 MEM_freeN(params.remote_url);
144}
void * BLI_gset_lookup(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
BLI_INLINE unsigned int BLI_hash_string(const char *str)
Definition BLI_hash.h:67
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
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition string.cc:30
unsigned int uint
#define STREQ(a, b)
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
Read Guarded memory(de)allocation.
CLG_LogRef * WM_LOG_MSGBUS_PUB
constexpr int64_t size() const
constexpr const char * data() const
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_RemoteIO 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_REMOTE_IO
static bool wm_msg_remote_io_gset_cmp(const void *key_a_p, const void *key_b_p)
void WM_msgtypeinfo_init_remote_io(wmMsgTypeInfo *msgtype_info)
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_publish_remote_io_params(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params)
void WM_msg_publish_remote_io(wmMsgBus *mbus, const blender::StringRef remote_url)
static void wm_msg_remote_io_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
wmMsgSubscribeKey_RemoteIO * WM_msg_lookup_remote_io(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params)
static void * wm_msg_remote_io_gset_key_duplicate(const void *key_p)
static void wm_msg_remote_io_gset_key_free(void *key_p)
void WM_msg_subscribe_remote_io(wmMsgBus *mbus, const blender::StringRef remote_url, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
static uint wm_msg_remote_io_gset_hash(const void *key_p)