Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/message_bus/intern/wm_message_bus.c
| Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | if (BLI_listbase_is_empty(&msg_key->values)) { | ||||
| UNUSED_VARS_NDEBUG(ok); | UNUSED_VARS_NDEBUG(ok); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void WM_msg_dump(struct wmMsgBus *mbus, const char *info_str) | void WM_msg_dump(struct wmMsgBus *mbus, const char *info_str) | ||||
| { | { | ||||
| printf(">>>> %s\n", info_str); | printf(">>>> %s\n", info_str); | ||||
| for (wmMsgSubscribeKey *key = mbus->messages.first; key; key = key->next) { | LISTBASE_FOREACH (wmMsgSubscribeKey *, key, &mbus->messages) { | ||||
| const wmMsg *msg = wm_msg_subscribe_value_msg_cast(key); | const wmMsg *msg = wm_msg_subscribe_value_msg_cast(key); | ||||
| const wmMsgTypeInfo *info = &wm_msg_types[msg->type]; | const wmMsgTypeInfo *info = &wm_msg_types[msg->type]; | ||||
| info->repr(stdout, key); | info->repr(stdout, key); | ||||
| } | } | ||||
| printf("<<<< %s\n", info_str); | printf("<<<< %s\n", info_str); | ||||
| } | } | ||||
| void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C) | void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C) | ||||
| { | { | ||||
| if (mbus->messages_tag_count == 0) { | if (mbus->messages_tag_count == 0) { | ||||
| // printf("msgbus: skipping\n"); | // printf("msgbus: skipping\n"); | ||||
| return; | return; | ||||
| } | } | ||||
| if (false) { | if (false) { | ||||
| WM_msg_dump(mbus, __func__); | WM_msg_dump(mbus, __func__); | ||||
| } | } | ||||
| // uint a = 0, b = 0; | // uint a = 0, b = 0; | ||||
| for (wmMsgSubscribeKey *key = mbus->messages.first; key; key = key->next) { | LISTBASE_FOREACH (wmMsgSubscribeKey *, key, &mbus->messages) { | ||||
| for (wmMsgSubscribeValueLink *msg_lnk = key->values.first; msg_lnk; msg_lnk = msg_lnk->next) { | LISTBASE_FOREACH (wmMsgSubscribeValueLink *, msg_lnk, &key->values) { | ||||
| if (msg_lnk->params.tag) { | if (msg_lnk->params.tag) { | ||||
| msg_lnk->params.notify(C, key, &msg_lnk->params); | msg_lnk->params.notify(C, key, &msg_lnk->params); | ||||
| msg_lnk->params.tag = false; | msg_lnk->params.tag = false; | ||||
| mbus->messages_tag_count -= 1; | mbus->messages_tag_count -= 1; | ||||
| } | } | ||||
| // b++; | // b++; | ||||
| } | } | ||||
| // a++; | // a++; | ||||
| Show All 26 Lines | wmMsgSubscribeKey *WM_msg_subscribe_with_key(struct wmMsgBus *mbus, | ||||
| void **r_key; | void **r_key; | ||||
| if (!BLI_gset_ensure_p_ex(mbus->messages_gset[type], msg_key_test, &r_key)) { | if (!BLI_gset_ensure_p_ex(mbus->messages_gset[type], msg_key_test, &r_key)) { | ||||
| key = *r_key = MEM_mallocN(info->msg_key_size, __func__); | key = *r_key = MEM_mallocN(info->msg_key_size, __func__); | ||||
| memcpy(key, msg_key_test, info->msg_key_size); | memcpy(key, msg_key_test, info->msg_key_size); | ||||
| BLI_addtail(&mbus->messages, key); | BLI_addtail(&mbus->messages, key); | ||||
| } | } | ||||
| else { | else { | ||||
| key = *r_key; | key = *r_key; | ||||
| for (wmMsgSubscribeValueLink *msg_lnk = key->values.first; msg_lnk; msg_lnk = msg_lnk->next) { | LISTBASE_FOREACH (wmMsgSubscribeValueLink *, msg_lnk, &key->values) { | ||||
| if ((msg_lnk->params.notify == msg_val_params->notify) && | if ((msg_lnk->params.notify == msg_val_params->notify) && | ||||
| (msg_lnk->params.owner == msg_val_params->owner) && | (msg_lnk->params.owner == msg_val_params->owner) && | ||||
| (msg_lnk->params.user_data == msg_val_params->user_data)) { | (msg_lnk->params.user_data == msg_val_params->user_data)) { | ||||
| return key; | return key; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| wmMsgSubscribeValueLink *msg_lnk = MEM_mallocN(sizeof(wmMsgSubscribeValueLink), __func__); | wmMsgSubscribeValueLink *msg_lnk = MEM_mallocN(sizeof(wmMsgSubscribeValueLink), __func__); | ||||
| msg_lnk->params = *msg_val_params; | msg_lnk->params = *msg_val_params; | ||||
| BLI_addtail(&key->values, msg_lnk); | BLI_addtail(&key->values, msg_lnk); | ||||
| return key; | return key; | ||||
| } | } | ||||
| void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key) | void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key) | ||||
| { | { | ||||
| CLOG_INFO(WM_LOG_MSGBUS_SUB, | CLOG_INFO(WM_LOG_MSGBUS_SUB, | ||||
| 2, | 2, | ||||
| "tagging subscribers: (ptr=%p, len=%d)", | "tagging subscribers: (ptr=%p, len=%d)", | ||||
| msg_key, | msg_key, | ||||
| BLI_listbase_count(&msg_key->values)); | BLI_listbase_count(&msg_key->values)); | ||||
| for (wmMsgSubscribeValueLink *msg_lnk = msg_key->values.first; msg_lnk; | LISTBASE_FOREACH (wmMsgSubscribeValueLink *, msg_lnk, &msg_key->values) { | ||||
| msg_lnk = msg_lnk->next) { | |||||
| if (false) { /* make an option? */ | if (false) { /* make an option? */ | ||||
| msg_lnk->params.notify(NULL, msg_key, &msg_lnk->params); | msg_lnk->params.notify(NULL, msg_key, &msg_lnk->params); | ||||
| } | } | ||||
| else { | else { | ||||
| if (msg_lnk->params.tag == false) { | if (msg_lnk->params.tag == false) { | ||||
| msg_lnk->params.tag = true; | msg_lnk->params.tag = true; | ||||
| mbus->messages_tag_count += 1; | mbus->messages_tag_count += 1; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines | |||||