Blender  V3.3
wm_message_bus_static.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdio.h>
8 
9 #include "CLG_log.h"
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_ghash.h"
14 #include "BLI_listbase.h"
15 #include "BLI_utildefines.h"
16 
17 #include "WM_message.h"
18 #include "WM_types.h"
20 
21 /* -------------------------------------------------------------------------- */
22 
23 static uint wm_msg_static_gset_hash(const void *key_p)
24 {
25  const wmMsgSubscribeKey_Static *key = key_p;
26  const wmMsgParams_Static *params = &key->msg.params;
27  uint k = params->event;
28  return k;
29 }
30 static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
31 {
32  const wmMsgParams_Static *params_a = &((const wmMsgSubscribeKey_Static *)key_a_p)->msg.params;
33  const wmMsgParams_Static *params_b = &((const wmMsgSubscribeKey_Static *)key_b_p)->msg.params;
34  return !((params_a->event == params_b->event));
35 }
36 static void wm_msg_static_gset_key_free(void *key_p)
37 {
38  wmMsgSubscribeKey *key = key_p;
39  wmMsgSubscribeValueLink *msg_lnk_next;
40  for (wmMsgSubscribeValueLink *msg_lnk = key->values.first; msg_lnk; msg_lnk = msg_lnk_next) {
41  msg_lnk_next = msg_lnk->next;
42  BLI_remlink(&key->values, msg_lnk);
43  MEM_freeN(msg_lnk);
44  }
45  MEM_freeN(key);
46 }
47 
48 static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
49 {
51  fprintf(stream,
52  "<wmMsg_Static %p, "
53  "id='%s', "
54  "values_len=%d\n",
55  m,
56  m->msg.head.id,
58 }
59 
61 {
62  msgtype_info->gset.hash_fn = wm_msg_static_gset_hash;
63  msgtype_info->gset.cmp_fn = wm_msg_static_gset_cmp;
65  msgtype_info->repr = wm_msg_static_repr;
66 
67  msgtype_info->msg_key_size = sizeof(wmMsgSubscribeKey_Static);
68 }
69 
70 /* -------------------------------------------------------------------------- */
71 
73  const wmMsgParams_Static *msg_key_params)
74 {
75  wmMsgSubscribeKey_Static key_test;
76  key_test.msg.params = *msg_key_params;
77  return BLI_gset_lookup(mbus->messages_gset[WM_MSG_TYPE_STATIC], &key_test);
78 }
79 
80 void WM_msg_publish_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
81 {
82  CLOG_INFO(WM_LOG_MSGBUS_PUB, 2, "static(event=%d)", msg_key_params->event);
83 
84  wmMsgSubscribeKey_Static *key = WM_msg_lookup_static(mbus, msg_key_params);
85  if (key) {
86  WM_msg_publish_with_key(mbus, &key->head);
87  }
88 }
89 
90 void WM_msg_publish_static(struct wmMsgBus *mbus, int event)
91 {
94  .event = event,
95  });
96 }
97 
99  const wmMsgParams_Static *msg_key_params,
100  const wmMsgSubscribeValue *msg_val_params,
101  const char *id_repr)
102 {
103  wmMsgSubscribeKey_Static msg_key_test = {{NULL}};
104 
105  /* use when added */
106  msg_key_test.msg.head.id = id_repr;
107  msg_key_test.msg.head.type = WM_MSG_TYPE_STATIC;
108  /* for lookup */
109  msg_key_test.msg.params = *msg_key_params;
110 
111  WM_msg_subscribe_with_key(mbus, &msg_key_test.head, msg_val_params);
112 }
113 
115  int event,
116  const wmMsgSubscribeValue *msg_val_params,
117  const char *id_repr)
118 {
120  &(const wmMsgParams_Static){
121  .event = event,
122  },
123  msg_val_params,
124  id_repr);
125 }
void * BLI_gset_lookup(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:1061
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:100
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
unsigned int uint
Definition: BLI_sys_types.h:67
#define CLOG_INFO(clg_ref, level,...)
Definition: CLG_log.h:187
Read Guarded memory(de)allocation.
struct CLG_LogRef * WM_LOG_MSGBUS_PUB
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void * first
Definition: DNA_listBase.h:31
struct GSet * messages_gset[WM_MSG_TYPE_NUM]
wmMsgSubscribeKey head
void(* repr)(FILE *stream, const struct wmMsgSubscribeKey *msg_key)
struct wmMsgTypeInfo::@1202 gset
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(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
wmMsgSubscribeKey * WM_msg_subscribe_with_key(struct wmMsgBus *mbus, const wmMsgSubscribeKey *msg_key_test, const wmMsgSubscribeValue *msg_val_params)
@ WM_MSG_TYPE_STATIC
struct wmMsgSubscribeKey_Static wmMsgSubscribeKey_Static
static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
void WM_msg_publish_static(struct wmMsgBus *mbus, int event)
void WM_msg_subscribe_static(struct wmMsgBus *mbus, int event, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info)
void WM_msg_publish_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
wmMsgSubscribeKey_Static * WM_msg_lookup_static(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
static uint wm_msg_static_gset_hash(const void *key_p)
void WM_msg_subscribe_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
static void wm_msg_static_gset_key_free(void *key_p)