Go to the documentation of this file. 1 #ifndef HAWKTRACER_EVENT_MACROS_H 2 #define HAWKTRACER_EVENT_MACROS_H 10 #define HT_EVENT_GET_SIZE_FUNCTION(C_TYPE) ht_##C_TYPE##_get_size 11 #define HT_EVENT_SERIALIZE_FUNCTION(C_TYPE) ht_##C_TYPE##_fnc_serialize 12 #define HT_EVENT_REGISTER_KLASS_FUNCTION(C_TYPE) ht_##C_TYPE##_register_event_klass 13 #define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(C_TYPE) ht_##C_TYPE##_get_event_klass_instance 15 #define HT_EVENT_RUNTIME_SIZEOF_STRUCT(VAR_NAME, FIELD, C_TYPE) HT_EVENT_GET_SIZE_FUNCTION(C_TYPE)(((HT_Event*)&VAR_NAME->FIELD)) 16 #define HT_EVENT_RUNTIME_SIZEOF_INTEGER(VAR_NAME, FIELD, C_TYPE) sizeof(VAR_NAME->FIELD) 17 #define HT_EVENT_RUNTIME_SIZEOF_POINTER(VAR_NAME, FIELD, C_TYPE) sizeof(VAR_NAME->FIELD) 18 #define HT_EVENT_RUNTIME_SIZEOF_DOUBLE(VAR_NAME, FIELD, C_TYPE) sizeof(VAR_NAME->FIELD) 19 #define HT_EVENT_RUNTIME_SIZEOF_STRING(VAR_NAME, FIELD, C_TYPE) (VAR_NAME->FIELD ? strlen(VAR_NAME->FIELD) + 1 : 0) 20 #define HT_EVENT_RUNTIME_SIZEOF__(VAR_NAME, DATA_TYPE, C_TYPE, FIELD, ...) +HT_EVENT_RUNTIME_SIZEOF_##DATA_TYPE(VAR_NAME, FIELD, C_TYPE) 21 #define HT_EVENT_RUNTIME_SIZEOF_(...) MKCREFLECT_EXPAND_(HT_EVENT_RUNTIME_SIZEOF__(__VA_ARGS__, 0)) 22 #define HT_EVENT_RUNTIME_SIZEOF(X, USER_DATA) HT_EVENT_RUNTIME_SIZEOF_(USER_DATA, MKCREFLECT_EXPAND_VA_ X) 24 #define HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD) memcpy(buffer + offset, (char*)&VAR_NAME->FIELD, sizeof(VAR_NAME->FIELD)), offset += sizeof(VAR_NAME->FIELD); 26 #define HT_EVENT_RUNTIME_SERIALIZE_STRUCT(C_TYPE, FIELD) offset += HT_EVENT_SERIALIZE_FUNCTION(C_TYPE)(((HT_Event*)&VAR_NAME->FIELD), buffer); 27 #define HT_EVENT_RUNTIME_SERIALIZE_INTEGER(C_TYPE, FIELD) HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD) 28 #define HT_EVENT_RUNTIME_SERIALIZE_POINTER(C_TYPE, FIELD) HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD) 29 #define HT_EVENT_RUNTIME_SERIALIZE_DOUBLE(C_TYPE, FIELD) HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD) 30 #define HT_EVENT_RUNTIME_SERIALIZE_STRING(C_TYPE, FIELD) do {\ 31 size_t len = (VAR_NAME->FIELD) ? strlen(VAR_NAME->FIELD) + 1 : 0; \ 32 memcpy(buffer + offset, VAR_NAME->FIELD, len); \ 35 #define HT_EVENT_RUNTIME_SERIALIZE__(DATA_TYPE, C_TYPE, FIELD, ...) HT_EVENT_RUNTIME_SERIALIZE_##DATA_TYPE(C_TYPE, FIELD) 36 #define HT_EVENT_RUNTIME_SERIALIZE_(...) MKCREFLECT_EXPAND_(HT_EVENT_RUNTIME_SERIALIZE__(__VA_ARGS__, 0)) 37 #define HT_EVENT_RUNTIME_SERIALIZE(X, USER_DATA) HT_EVENT_RUNTIME_SERIALIZE_ (MKCREFLECT_EXPAND_VA_ X) 40 #define HT_EVENT_GET_SIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, ...) \ 41 size_t HT_EVENT_GET_SIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME) \ 43 return MKCREFLECT_FOREACH(HT_EVENT_RUNTIME_SIZEOF, ((TYPE_NAME*)VAR_NAME), (STRUCT, BASE_TYPE, base), __VA_ARGS__); \ 45 #define HT_EVENT_GET_SIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, ...) \ 46 HT_API size_t HT_EVENT_GET_SIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME);\ 48 #define HT_EVENT_SERIALIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, ...) \ 49 size_t HT_EVENT_SERIALIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME_, HT_Byte* buffer) \ 52 TYPE_NAME* VAR_NAME = (TYPE_NAME*)VAR_NAME_; \ 53 MKCREFLECT_FOREACH(HT_EVENT_RUNTIME_SERIALIZE, 0, (STRUCT, BASE_TYPE, base), __VA_ARGS__) \ 56 #define HT_EVENT_SERIALIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, ...) \ 57 HT_API size_t HT_EVENT_SERIALIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME_, HT_Byte* buffer); 59 #define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DEF(TYPE_NAME) \ 60 HT_EventKlass* HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(TYPE_NAME)(void) \ 62 static HT_EventKlass klass_instance = { \ 64 HT_EVENT_SERIALIZE_FUNCTION(TYPE_NAME), \ 65 HT_EVENT_GET_SIZE_FUNCTION(TYPE_NAME), \ 68 return &klass_instance; \ 70 #define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DECL(TYPE_NAME) \ 71 HT_API HT_EventKlass* HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(TYPE_NAME)(void); 73 #define HT_EVENT_REGISTER_KLASS_FUNCTION_DEF(TYPE_NAME) \ 74 HT_EventKlassId HT_EVENT_REGISTER_KLASS_FUNCTION(TYPE_NAME)(void) \ 76 HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(TYPE_NAME)()->type_info = mkcreflect_get_##TYPE_NAME##_type_info(); \ 77 return ht_registry_register_event_klass(HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(TYPE_NAME)()); \ 79 #define HT_EVENT_REGISTER_KLASS_FUNCTION_DECL(TYPE_NAME) \ 80 HT_API HT_EventKlassId HT_EVENT_REGISTER_KLASS_FUNCTION(TYPE_NAME)(void); 82 #define HT_EVENT_DEFINE_STRUCTURE(TYPE_NAME, BASE_TYPE, ...) \ 83 MKCREFLECT_DEFINE_STRUCT(TYPE_NAME, \ 84 (STRUCT, BASE_TYPE, base), \ 85 MKCREFLECT_EXPAND_VA_(__VA_ARGS__)) 87 #define HT_EVENT_DECLARATIONS(TYPE_NAME, BASE_TYPE, ...) \ 88 HT_EVENT_GET_SIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \ 89 HT_EVENT_SERIALIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \ 90 HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DECL(TYPE_NAME) \ 91 HT_EVENT_REGISTER_KLASS_FUNCTION_DECL(TYPE_NAME) 93 #define HT_EVENT_DEFINITIONS_(TYPE_NAME, BASE_TYPE, ...) \ 94 HT_EVENT_GET_SIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \ 95 HT_EVENT_SERIALIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \ 96 HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DEF(TYPE_NAME) \ 97 HT_EVENT_REGISTER_KLASS_FUNCTION_DEF(TYPE_NAME) 99 #define HT_DECLARE_EVENT_KLASS(TYPE_NAME, BASE_TYPE, ...) \ 100 HT_EVENT_DEFINE_STRUCTURE(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \ 101 HT_EVENT_DECLARATIONS(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \ 102 HT_EVENT_DEFINITIONS(TYPE_NAME, BASE_TYPE, __VA_ARGS__) 104 #ifndef HT_EVENT_DEFINITIONS 105 #define HT_EVENT_DEFINITIONS(TYPE_NAME, BASE_TYPE, ...)