[Bf-blender-cvs] [efddc5b30ee] soc-2020-info-editor: Refactor window manager message bus to use CLOG instead of print

Mateusz Grzeliński noreply at git.blender.org
Wed Jul 1 11:39:55 CEST 2020


Commit: efddc5b30ee77919d3ef306d11b313f8c00d94f5
Author: Mateusz Grzeliński
Date:   Wed Jul 1 10:01:32 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rBefddc5b30ee77919d3ef306d11b313f8c00d94f5

Refactor window manager message bus to use CLOG instead of print

- create logger wm.msgbus.handle

===================================================================

M	source/blender/python/intern/bpy_msgbus.c
M	source/blender/windowmanager/message_bus/intern/wm_message_bus.c
M	source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c
M	source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c
M	source/blender/windowmanager/message_bus/wm_message_bus.h

===================================================================

diff --git a/source/blender/python/intern/bpy_msgbus.c b/source/blender/python/intern/bpy_msgbus.c
index 45c5aba1e3e..7bfc0fce5d4 100644
--- a/source/blender/python/intern/bpy_msgbus.c
+++ b/source/blender/python/intern/bpy_msgbus.c
@@ -306,7 +306,7 @@ static PyObject *bpy_msgbus_subscribe_rna(PyObject *UNUSED(self), PyObject *args
   WM_msg_subscribe_rna_params(mbus, &msg_key_params, &msg_val_params, __func__);
 
   if (0) { /* For debugging. */
-    WM_msg_dump(mbus, __func__);
+    WM_msg_log_str(mbus);
   }
 
   Py_RETURN_NONE;
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus.c b/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
index 86a106462c3..c8c30063359 100644
--- a/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
@@ -18,6 +18,7 @@
  * \ingroup wm
  */
 
+#include <BLI_dynstr.h>
 #include <string.h>
 
 #include "CLG_log.h"
@@ -108,27 +109,31 @@ void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner)
   }
 }
 
-void WM_msg_dump(struct wmMsgBus *mbus, const char *info_str)
+char *WM_msg_log_str(struct wmMsgBus *mbus)
 {
-  printf(">>>> %s\n", info_str);
+  DynStr *message = BLI_dynstr_new();
   LISTBASE_FOREACH (wmMsgSubscribeKey *, key, &mbus->messages) {
     const wmMsg *msg = wm_msg_subscribe_value_msg_cast(key);
     const wmMsgTypeInfo *info = &wm_msg_types[msg->type];
-    info->repr(stdout, key);
+    char *info_repr = info->repr(key);
+    BLI_dynstr_appendf(message, "%s", info_repr);
+    MEM_freeN(info_repr);
   }
-  printf("<<<< %s\n", info_str);
+  char *cstring = BLI_dynstr_get_cstring(message);
+  BLI_dynstr_free(message);
+  return cstring;
 }
 
+static CLG_LogRef WM_LOG_MSGBUS_HANDLE = {"wm.msgbus.handle"};
+
 void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C)
 {
   if (mbus->messages_tag_count == 0) {
-    // printf("msgbus: skipping\n");
+    CLOG_INFO(&WM_LOG_MSGBUS_HANDLE, 4, "skipping msbus=%p", mbus);
     return;
   }
 
-  if (false) {
-    WM_msg_dump(mbus, __func__);
-  }
+  CLOG_STR_INFO_N(&WM_LOG_MSGBUS_HANDLE, 4, WM_msg_log_str(mbus));
 
   // uint a = 0, b = 0;
   LISTBASE_FOREACH (wmMsgSubscribeKey *, key, &mbus->messages) {
@@ -144,7 +149,7 @@ void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C)
   }
   BLI_assert(mbus->messages_tag_count == 0);
   mbus->messages_tag_count = 0;
-  // printf("msgbus: keys=%u values=%u\n", a, b);
+  //  CLOG_STR_INFO(&WM_LOG_MSGBUS_HANDLE, 4, "msgbus: keys=%u values=%u", a, b);
 }
 
 /**
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c b/source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c
index 460dca57e4f..e26822570ef 100644
--- a/source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c
@@ -18,6 +18,7 @@
  * \ingroup wm
  */
 
+#include <BLI_dynstr.h>
 #include <stdio.h>
 
 #include "CLG_log.h"
@@ -47,7 +48,8 @@ static uint wm_msg_rna_gset_hash(const void *key_p)
 {
   const wmMsgSubscribeKey_RNA *key = key_p;
   const wmMsgParams_RNA *params = &key->msg.params;
-  //  printf("%s\n", RNA_struct_identifier(params->ptr.type));
+  //  CLOG_INFO(WM_LOG_MSGBUS_HANDLE, 4, "RNA struct identifier=%s",
+  //  RNA_struct_identifier(params->ptr.type));
   uint k = void_hash_uint(params->ptr.type);
   k ^= void_hash_uint(params->ptr.data);
   k ^= void_hash_uint(params->ptr.owner_id);
@@ -77,19 +79,24 @@ static void wm_msg_rna_gset_key_free(void *key_p)
   MEM_freeN(key);
 }
 
-static void wm_msg_rna_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
+static char *wm_msg_rna_repr(const wmMsgSubscribeKey *msg_key)
 {
+  DynStr *repr = BLI_dynstr_new();
   const wmMsgSubscribeKey_RNA *m = (wmMsgSubscribeKey_RNA *)msg_key;
   const char *none = "<none>";
-  fprintf(stream,
-          "<wmMsg_RNA %p, "
-          "id='%s', "
-          "%s.%s values_len=%d\n",
-          m,
-          m->msg.head.id,
-          m->msg.params.ptr.type ? RNA_struct_identifier(m->msg.params.ptr.type) : none,
-          m->msg.params.prop ? RNA_property_identifier((PropertyRNA *)m->msg.params.prop) : none,
-          BLI_listbase_count(&m->head.values));
+  BLI_dynstr_appendf(
+      repr,
+      "<wmMsg_RNA %p, "
+      "id='%s', "
+      "%s.%s values_len=%d\n",
+      m,
+      m->msg.head.id,
+      m->msg.params.ptr.type ? RNA_struct_identifier(m->msg.params.ptr.type) : none,
+      m->msg.params.prop ? RNA_property_identifier((PropertyRNA *)m->msg.params.prop) : none,
+      BLI_listbase_count(&m->head.values));
+  char *cstring = BLI_dynstr_get_cstring(repr);
+  BLI_dynstr_free(repr);
+  return cstring;
 }
 
 static void wm_msg_rna_update_by_id(struct wmMsgBus *mbus, ID *id_src, ID *id_dst)
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c b/source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c
index c47cec4b3e4..1d776f93bec 100644
--- a/source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c
@@ -18,6 +18,7 @@
  * \ingroup wm
  */
 
+#include <BLI_dynstr.h>
 #include <stdio.h>
 
 #include "CLG_log.h"
@@ -59,16 +60,20 @@ static void wm_msg_static_gset_key_free(void *key_p)
   MEM_freeN(key);
 }
 
-static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
+static char *wm_msg_static_repr(const wmMsgSubscribeKey *msg_key)
 {
+  DynStr *repr = BLI_dynstr_new();
   const wmMsgSubscribeKey_Static *m = (wmMsgSubscribeKey_Static *)msg_key;
-  fprintf(stream,
-          "<wmMsg_Static %p, "
-          "id='%s', "
-          "values_len=%d\n",
-          m,
-          m->msg.head.id,
-          BLI_listbase_count(&m->head.values));
+  BLI_dynstr_appendf(repr,
+                     "<wmMsg_Static %p, "
+                     "id='%s', "
+                     "values_len=%d\n",
+                     m,
+                     m->msg.head.id,
+                     BLI_listbase_count(&m->head.values));
+  char *cstring = BLI_dynstr_get_cstring(repr);
+  BLI_dynstr_free(repr);
+  return cstring;
 }
 
 void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info)
diff --git a/source/blender/windowmanager/message_bus/wm_message_bus.h b/source/blender/windowmanager/message_bus/wm_message_bus.h
index 8020be3017a..13a4b938f18 100644
--- a/source/blender/windowmanager/message_bus/wm_message_bus.h
+++ b/source/blender/windowmanager/message_bus/wm_message_bus.h
@@ -61,7 +61,7 @@ typedef struct wmMsgTypeInfo {
 
   void (*update_by_id)(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst);
   void (*remove_by_id)(struct wmMsgBus *mbus, const struct ID *id);
-  void (*repr)(FILE *stream, const struct wmMsgSubscribeKey *msg_key);
+  char *(*repr)(const struct wmMsgSubscribeKey *msg_key);
 
   /* sizeof(wmMsgSubscribeKey_*) */
   uint msg_key_size;
@@ -117,7 +117,7 @@ void WM_msgbus_destroy(struct wmMsgBus *mbus);
 
 void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner);
 
-void WM_msg_dump(struct wmMsgBus *mbus, const char *info);
+char *WM_msg_log_str(struct wmMsgBus *mbus);
 void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C);
 
 void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key);



More information about the Bf-blender-cvs mailing list