Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/message_bus/wm_message_bus.h
- This file was added.
| /* | |||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | |||||
| * | |||||
| * This program is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU General Public License | |||||
| * as published by the Free Software Foundation; either version 2 | |||||
| * of the License, or (at your option) any later version. | |||||
| * | |||||
| * This program is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with this program; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * ***** END GPL LICENSE BLOCK ***** | |||||
| */ | |||||
| /** \file blender/windowmanager/wm_message_bus.h | |||||
| * \ingroup wm | |||||
| */ | |||||
| #ifndef __WM_MESSAGE_BUS_H__ | |||||
| #define __WM_MESSAGE_BUS_H__ | |||||
| struct GSet; | |||||
| struct ID; | |||||
| struct bContext; | |||||
| struct wmMsg; | |||||
| /* opaque (don't expose outside wm_message_bus.c) */ | |||||
| struct wmMsgBus; | |||||
| struct wmMsgSubscribeKey; | |||||
| struct wmMsgSubscribeValue; | |||||
| typedef void (*wmMsgNotifyFn)( | |||||
| struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val); | |||||
| enum { | |||||
| WM_MSG_TYPE_RNA = 0, | |||||
| WM_MSG_TYPE_STATIC = 1, | |||||
| }; | |||||
| #define WM_MSG_TYPE_NUM 2 | |||||
| #ifdef WM_MESSAGE_BUS_INTERN | |||||
| struct wmMsgBus { | |||||
| struct GSet *messages_gset[WM_MSG_TYPE_NUM]; | |||||
| /* Messages in order of being added. */ | |||||
| ListBase messages; | |||||
| /* Avoid checking messages when no tags exist. */ | |||||
| uint messages_tag_count; | |||||
| }; | |||||
| #endif | |||||
| typedef struct wmMsgTypeInfo { | |||||
| struct { | |||||
| unsigned int (*hash_fn)(const void *msg); | |||||
| bool (*cmp_fn)(const void *a, const void *b); | |||||
| void (*key_free_fn)(void *key); | |||||
| } gset; | |||||
| void (*remove_by_id)(struct wmMsgBus *mbus, const struct ID *id); | |||||
| void (*repr)(FILE *stream, const struct wmMsgSubscribeKey *msg_key); | |||||
| /* sizeof(wmMsgSubscribeKey_*) */ | |||||
| uint msg_key_size; | |||||
| } wmMsgTypeInfo; | |||||
| typedef struct wmMsg { | |||||
| unsigned int type; | |||||
| // #ifdef DEBUG | |||||
| /* For debugging: '__func__:__LINE__'. */ | |||||
| const char *id; | |||||
| // #endif | |||||
| } wmMsg; | |||||
mont29: That’s rather double linked list imho? Or did you mean 'simple linked list'? ;) | |||||
| typedef struct wmMsgSubscribeKey { | |||||
| /** Single linked list for predicable ordering, otherwise we would depend on ghash bucketing. */ | |||||
| struct wmMsgSubscribeKey *next, *prev; | |||||
| ListBase values; | |||||
| /* over-alloc, eg: wmMsgSubscribeKey_RNA */ | |||||
| wmMsg msg[0]; | |||||
| } wmMsgSubscribeKey; | |||||
Done Inline ActionsThat’s rather double linked list imho? Or did you mean 'simple linked list'? ;) mont29: That’s rather double linked list imho? Or did you mean 'simple linked list'? ;) | |||||
| /** One of many in #wmMsgSubscribeKey.values */ | |||||
| typedef struct wmMsgSubscribeValue { | |||||
| /** Single linked list for predicable ordering, otherwise we would depend on ghash bucketing. */ | |||||
| struct wmMsgSubscribe *next, *prev; | |||||
| /** handle, used to iterate and clear. */ | |||||
| void *owner; | |||||
| void *user_data; | |||||
| wmMsgNotifyFn notify; | |||||
| /* tag to run when handling events, | |||||
| * we may want option for immediate execution. */ | |||||
| uint tag : 1; | |||||
| } wmMsgSubscribeValue; | |||||
Done Inline ActionsThat’s rather double linked list imho? Or did you mean 'simple linked list'? ;) mont29: That’s rather double linked list imho? Or did you mean 'simple linked list'? ;) | |||||
| /** One of many in #wmMsgSubscribeKey.values */ | |||||
| typedef struct wmMsgSubscribeValueLink { | |||||
| /** Single linked list for predicable ordering, otherwise we would depend on ghash bucketing. */ | |||||
| struct wmMsgSubscribeValueLink *next, *prev; | |||||
| wmMsgSubscribeValue params; | |||||
| } wmMsgSubscribeValueLink; | |||||
| void WM_msgbus_types_init(void); | |||||
| struct wmMsgBus *WM_msgbus_create(void); | |||||
| void WM_msgbus_destroy(struct wmMsgBus *mbus); | |||||
| void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner); | |||||
| void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C); | |||||
| void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key); | |||||
| void WM_msg_subscribe_with_key( | |||||
| struct wmMsgBus *mbus, | |||||
| const wmMsgSubscribeKey *msg_key_test, | |||||
| const wmMsgSubscribeValue *msg_val_params); | |||||
| void WM_msg_id_remove(struct wmMsgBus *mbus, const struct ID *id); | |||||
| /* -------------------------------------------------------------------------- */ | |||||
| /* wm_message_bus_static.c */ | |||||
| enum { | |||||
| /* generic window redraw */ | |||||
| WM_MSG_STATICTYPE_WINDOW_DRAW = 0, | |||||
| WM_MSG_STATICTYPE_SCREEN_EDIT = 1, | |||||
| WM_MSG_STATICTYPE_FILE_READ = 2, | |||||
| }; | |||||
| typedef struct wmMsgParams_Static { | |||||
| int event; | |||||
| } wmMsgParams_Static; | |||||
| typedef struct wmMsg_Static { | |||||
| wmMsg head; /* keep first */ | |||||
| wmMsgParams_Static params; | |||||
| } wmMsg_Static; | |||||
| typedef struct wmMsgSubscribeKey_Static { | |||||
| wmMsgSubscribeKey head; | |||||
| wmMsg_Static msg; | |||||
| } wmMsgSubscribeKey_Static; | |||||
| void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msg_type); | |||||
| wmMsgSubscribeKey_Static *WM_msg_lookup_static( | |||||
| struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params); | |||||
| void WM_msg_publish_static_params( | |||||
| struct wmMsgBus *mbus, | |||||
| const wmMsgParams_Static *msg_key_params); | |||||
| void WM_msg_publish_static( | |||||
| struct wmMsgBus *mbus, | |||||
| /* wmMsgParams_Static (expanded) */ | |||||
| int event); | |||||
| void WM_msg_subscribe_static_params( | |||||
| struct wmMsgBus *mbus, | |||||
| const wmMsgParams_Static *msg_key_params, | |||||
| const wmMsgSubscribeValue *msg_val_params); | |||||
| void WM_msg_subscribe_static( | |||||
| struct wmMsgBus *mbus, | |||||
| int event, | |||||
| const wmMsgSubscribeValue *msg_val_params); | |||||
| /* -------------------------------------------------------------------------- */ | |||||
| /* wm_message_bus_rna.c */ | |||||
| typedef struct wmMsgParams_RNA { | |||||
| /** when #PointerRNA.data & id.data are NULL. match against all. */ | |||||
| PointerRNA ptr; | |||||
| /** when NULL, match against any property. */ | |||||
| const PropertyRNA *prop; | |||||
| } wmMsgParams_RNA; | |||||
| typedef struct wmMsg_RNA { | |||||
| wmMsg head; /* keep first */ | |||||
| wmMsgParams_RNA params; | |||||
| } wmMsg_RNA; | |||||
| typedef struct wmMsgSubscribeKey_RNA { | |||||
| wmMsgSubscribeKey head; | |||||
| wmMsg_RNA msg; | |||||
| } wmMsgSubscribeKey_RNA; | |||||
| void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msg_type); | |||||
| wmMsgSubscribeKey_RNA *WM_msg_lookup_rna( | |||||
| struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params); | |||||
| void WM_msg_publish_rna_params( | |||||
| struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params); | |||||
| void WM_msg_publish_rna( | |||||
| struct wmMsgBus *mbus, | |||||
| /* wmMsgParams_RNA (expanded) */ | |||||
| PointerRNA *ptr, PropertyRNA *prop); | |||||
| void WM_msg_subscribe_rna_params( | |||||
| struct wmMsgBus *mbus, | |||||
| const wmMsgParams_RNA *msg_key_params, | |||||
| const wmMsgSubscribeValue *msg_val_params); | |||||
| void WM_msg_subscribe_rna( | |||||
| struct wmMsgBus *mbus, | |||||
| PointerRNA *ptr, const PropertyRNA *prop, | |||||
| const wmMsgSubscribeValue *msg_val_params); | |||||
| /* ID variants */ | |||||
| void WM_msg_subscribe_ID( | |||||
| struct wmMsgBus *mbus, struct ID *id, const wmMsgSubscribeValue *msg_val_params); | |||||
| void WM_msg_publish_ID( | |||||
| struct wmMsgBus *mbus, struct ID *id); | |||||
| #endif /* __WM_MESSAGE_BUS_H__ */ | |||||
That’s rather double linked list imho? Or did you mean 'simple linked list'? ;)