Blender V5.3
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.hh"
14#include "BLI_hash_c.hh"
15#include "BLI_listbase.hh"
16#include "BLI_string.hh"
17#include "BLI_string_ref.hh"
18
19#include "WM_types.hh"
21
22namespace blender {
23
24/* -------------------------------------------------------------------------- */
25
26static uint wm_msg_remote_io_gset_hash(const void *key_p)
27{
28 const wmMsgSubscribeKey_RemoteIO *key = static_cast<const wmMsgSubscribeKey_RemoteIO *>(key_p);
29 const wmMsgParams_RemoteIO *params = &key->msg.params;
30 uint k = BLI_hash_string(params->remote_url);
31 return k;
32}
33static bool wm_msg_remote_io_gset_cmp(const void *key_a_p, const void *key_b_p)
34{
35 const wmMsgParams_RemoteIO *params_a =
36 &(static_cast<const wmMsgSubscribeKey_RemoteIO *>(key_a_p))->msg.params;
37 const wmMsgParams_RemoteIO *params_b =
38 &(static_cast<const wmMsgSubscribeKey_RemoteIO *>(key_b_p))->msg.params;
39 return !STREQ(params_a->remote_url, params_b->remote_url);
40}
41
42static void *wm_msg_remote_io_gset_key_duplicate(const void *key_p)
43{
44 const wmMsgSubscribeKey_RemoteIO *key_src = static_cast<const wmMsgSubscribeKey_RemoteIO *>(
45 key_p);
46 wmMsgSubscribeKey_RemoteIO *key = MEM_new<wmMsgSubscribeKey_RemoteIO>(__func__, *key_src);
48 return key;
49}
50static void wm_msg_remote_io_gset_key_free(void *key_p)
51{
52 wmMsgSubscribeKey_RemoteIO *key = static_cast<wmMsgSubscribeKey_RemoteIO *>(key_p);
53 MEM_delete(key->msg.params.remote_url);
54 wmMsgSubscribeValueLink *msg_lnk_next;
55 for (wmMsgSubscribeValueLink *msg_lnk = key->head.values.first(); 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_delete(msg_lnk);
61 }
62 MEM_delete(key);
63}
64
65static void wm_msg_remote_io_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
66{
67 const wmMsgSubscribeKey_RemoteIO *m = reinterpret_cast<wmMsgSubscribeKey_RemoteIO *>(
68 const_cast<wmMsgSubscribeKey *>(msg_key));
69 fprintf(stream,
70 "<wmMsg_RemoteIO %p, "
71 "id='%s', "
72 "values_len=%d\n",
73 m,
74 m->msg.head.id,
75 m->head.values.count());
76}
77
79{
80 msgtype_info->gset.hash_fn = wm_msg_remote_io_gset_hash;
81 msgtype_info->gset.cmp_fn = wm_msg_remote_io_gset_cmp;
82 msgtype_info->gset.key_duplicate_fn = wm_msg_remote_io_gset_key_duplicate;
83 msgtype_info->gset.key_free_fn = wm_msg_remote_io_gset_key_free;
84 msgtype_info->repr = wm_msg_remote_io_repr;
85}
86
87/* -------------------------------------------------------------------------- */
88
90 const wmMsgParams_RemoteIO *msg_key_params)
91{
93 key_test.msg.params = *msg_key_params;
94 return static_cast<wmMsgSubscribeKey_RemoteIO *>(
96}
97
99{
100 CLOG_DEBUG(WM_LOG_MSGBUS_PUB, "remote_io(remote_url=%s)", msg_key_params->remote_url);
101
102 wmMsgSubscribeKey_RemoteIO *key = WM_msg_lookup_remote_io(mbus, msg_key_params);
103 if (key) {
104 WM_msg_publish_with_key(mbus, &key->head);
105 }
106}
107
108void WM_msg_publish_remote_io(wmMsgBus *mbus, const StringRef remote_url)
109{
110 wmMsgParams_RemoteIO params{};
111 params.remote_url = BLI_strdupn(remote_url.data(), remote_url.size());
112 WM_msg_publish_remote_io_params(mbus, &params);
113
114 /* Value was copied into the publish key. */
115 MEM_delete(params.remote_url);
116}
117
119 const wmMsgParams_RemoteIO *msg_key_params,
120 const wmMsgSubscribeValue *msg_val_params,
121 const char *id_repr)
122{
123 wmMsgSubscribeKey_RemoteIO msg_key_test{};
124
125 /* Use when added. */
126 msg_key_test.msg.head.id = id_repr;
127 msg_key_test.msg.head.type = WM_MSG_TYPE_REMOTE_IO;
128 /* For lookup. */
129 msg_key_test.msg.params = *msg_key_params;
130
131 WM_msg_subscribe_with_key(mbus, &msg_key_test.head, msg_val_params);
132}
133
135 const StringRef remote_url,
136 const wmMsgSubscribeValue *msg_val_params,
137 const char *id_repr)
138{
139 wmMsgParams_RemoteIO params{};
140 params.remote_url = BLI_strdupn(remote_url.data(), remote_url.size());
141 WM_msg_subscribe_remote_io_params(mbus, &params, msg_val_params, id_repr);
142
143 /* Value was copied into the subscribe key. */
144 MEM_delete(params.remote_url);
145}
146
147} // namespace blender
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
Read Blender memory allocation and freeing.
#define STREQ(a, b)
constexpr int64_t size() const
constexpr const char * data() const
BMesh Iterators.
wmMsgSubscribeKey_RemoteIO * WM_msg_lookup_remote_io(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params)
unsigned int uint
Definition BKE_text.h:55
void * BLI_gset_lookup(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
static uint wm_msg_remote_io_gset_hash(const void *key_p)
void WM_msg_publish_remote_io_params(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params)
void WM_msg_subscribe_remote_io_params(wmMsgBus *mbus, const wmMsgParams_RemoteIO *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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_msgtypeinfo_init_remote_io(wmMsgTypeInfo *msgtype_info)
void WM_msg_subscribe_remote_io(wmMsgBus *mbus, const StringRef remote_url, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
@ WM_MSG_TYPE_REMOTE_IO
void WM_msg_publish_remote_io(wmMsgBus *mbus, const StringRef remote_url)
void WM_msg_publish_with_key(wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
static void * wm_msg_remote_io_gset_key_duplicate(const void *key_p)
static bool wm_msg_remote_io_gset_cmp(const void *key_a_p, const void *key_b_p)
static void wm_msg_remote_io_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
BLI_INLINE unsigned int BLI_hash_string(const char *str)
Definition BLI_hash_c.hh:69
static void wm_msg_remote_io_gset_key_free(void *key_p)
CLG_LogRef * WM_LOG_MSGBUS_PUB
GSet * messages_gset[WM_MSG_TYPE_NUM]
ListBaseT< wmMsgSubscribeValueLink > values
void(*) repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
struct blender::wmMsgTypeInfo::@222252052342264033027352010177057107113002371022 gset
wmMsgParams_RemoteIO params
unsigned int type
const char * id