HawkTracer  0.10.0
event_macros.h File Reference
#include <hawktracer/events.h>
#include <hawktracer/mkcreflect.h>
#include <hawktracer/registry.h>
#include <string.h>

Go to the source code of this file.

Macros

#define HT_EVENT_GET_SIZE_FUNCTION(C_TYPE)   ht_##C_TYPE##_get_size
 
#define HT_EVENT_SERIALIZE_FUNCTION(C_TYPE)   ht_##C_TYPE##_fnc_serialize
 
#define HT_EVENT_REGISTER_KLASS_FUNCTION(C_TYPE)   ht_##C_TYPE##_register_event_klass
 
#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(C_TYPE)   ht_##C_TYPE##_get_event_klass_instance
 
#define HT_EVENT_RUNTIME_SIZEOF_STRUCT(VAR_NAME, FIELD, C_TYPE)   HT_EVENT_GET_SIZE_FUNCTION(C_TYPE)(((HT_Event*)&VAR_NAME->FIELD))
 
#define HT_EVENT_RUNTIME_SIZEOF_INTEGER(VAR_NAME, FIELD, C_TYPE)   sizeof(VAR_NAME->FIELD)
 
#define HT_EVENT_RUNTIME_SIZEOF_POINTER(VAR_NAME, FIELD, C_TYPE)   sizeof(VAR_NAME->FIELD)
 
#define HT_EVENT_RUNTIME_SIZEOF_DOUBLE(VAR_NAME, FIELD, C_TYPE)   sizeof(VAR_NAME->FIELD)
 
#define HT_EVENT_RUNTIME_SIZEOF_STRING(VAR_NAME, FIELD, C_TYPE)   (VAR_NAME->FIELD ? strlen(VAR_NAME->FIELD) + 1 : 0)
 
#define HT_EVENT_RUNTIME_SIZEOF__(VAR_NAME, DATA_TYPE, C_TYPE, FIELD, ...)   +HT_EVENT_RUNTIME_SIZEOF_##DATA_TYPE(VAR_NAME, FIELD, C_TYPE)
 
#define HT_EVENT_RUNTIME_SIZEOF_(...)   MKCREFLECT_EXPAND_(HT_EVENT_RUNTIME_SIZEOF__(__VA_ARGS__, 0))
 
#define HT_EVENT_RUNTIME_SIZEOF(X, USER_DATA)   HT_EVENT_RUNTIME_SIZEOF_(USER_DATA, MKCREFLECT_EXPAND_VA_ X)
 
#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);
 
#define HT_EVENT_RUNTIME_SERIALIZE_STRUCT(C_TYPE, FIELD)   offset += HT_EVENT_SERIALIZE_FUNCTION(C_TYPE)(((HT_Event*)&VAR_NAME->FIELD), buffer);
 
#define HT_EVENT_RUNTIME_SERIALIZE_INTEGER(C_TYPE, FIELD)   HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD)
 
#define HT_EVENT_RUNTIME_SERIALIZE_POINTER(C_TYPE, FIELD)   HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD)
 
#define HT_EVENT_RUNTIME_SERIALIZE_DOUBLE(C_TYPE, FIELD)   HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD)
 
#define HT_EVENT_RUNTIME_SERIALIZE_STRING(C_TYPE, FIELD)
 
#define HT_EVENT_RUNTIME_SERIALIZE__(DATA_TYPE, C_TYPE, FIELD, ...)   HT_EVENT_RUNTIME_SERIALIZE_##DATA_TYPE(C_TYPE, FIELD)
 
#define HT_EVENT_RUNTIME_SERIALIZE_(...)   MKCREFLECT_EXPAND_(HT_EVENT_RUNTIME_SERIALIZE__(__VA_ARGS__, 0))
 
#define HT_EVENT_RUNTIME_SERIALIZE(X, USER_DATA)   HT_EVENT_RUNTIME_SERIALIZE_ (MKCREFLECT_EXPAND_VA_ X)
 
#define HT_EVENT_GET_SIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, ...)
 
#define HT_EVENT_GET_SIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, ...)   HT_API size_t HT_EVENT_GET_SIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME);\
 
#define HT_EVENT_SERIALIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, ...)
 
#define HT_EVENT_SERIALIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, ...)   HT_API size_t HT_EVENT_SERIALIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME_, HT_Byte* buffer);
 
#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DEF(TYPE_NAME)
 
#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DECL(TYPE_NAME)   HT_API HT_EventKlass* HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(TYPE_NAME)(void);
 
#define HT_EVENT_REGISTER_KLASS_FUNCTION_DEF(TYPE_NAME)
 
#define HT_EVENT_REGISTER_KLASS_FUNCTION_DECL(TYPE_NAME)   HT_API HT_EventKlassId HT_EVENT_REGISTER_KLASS_FUNCTION(TYPE_NAME)(void);
 
#define HT_EVENT_DEFINE_STRUCTURE(TYPE_NAME, BASE_TYPE, ...)
 
#define HT_EVENT_DECLARATIONS(TYPE_NAME, BASE_TYPE, ...)
 
#define HT_EVENT_DEFINITIONS_(TYPE_NAME, BASE_TYPE, ...)
 
#define HT_DECLARE_EVENT_KLASS(TYPE_NAME, BASE_TYPE, ...)
 
#define HT_EVENT_DEFINITIONS(TYPE_NAME, BASE_TYPE, ...)
 

Macro Definition Documentation

◆ HT_DECLARE_EVENT_KLASS

#define HT_DECLARE_EVENT_KLASS (   TYPE_NAME,
  BASE_TYPE,
  ... 
)
Value:
HT_EVENT_DEFINE_STRUCTURE(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \
HT_EVENT_DECLARATIONS(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \
HT_EVENT_DEFINITIONS(TYPE_NAME, BASE_TYPE, __VA_ARGS__)
#define HT_EVENT_DEFINE_STRUCTURE(TYPE_NAME, BASE_TYPE,...)
Definition: event_macros.h:82

◆ HT_EVENT_DECLARATIONS

#define HT_EVENT_DECLARATIONS (   TYPE_NAME,
  BASE_TYPE,
  ... 
)
Value:
HT_EVENT_GET_SIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \
HT_EVENT_SERIALIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \
HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DECL(TYPE_NAME) \
HT_EVENT_REGISTER_KLASS_FUNCTION_DECL(TYPE_NAME)
#define HT_EVENT_GET_SIZE_FUNCTION_DECL(TYPE_NAME, BASE_TYPE,...)
Definition: event_macros.h:45

◆ HT_EVENT_DEFINE_STRUCTURE

#define HT_EVENT_DEFINE_STRUCTURE (   TYPE_NAME,
  BASE_TYPE,
  ... 
)
Value:
(STRUCT, BASE_TYPE, base), \
MKCREFLECT_EXPAND_VA_(__VA_ARGS__))
#define MKCREFLECT_EXPAND_VA_(...)
Definition: mkcreflect.h:54
MKCREFLECT_DEFINE_STRUCT(HT_Event,(POINTER, HT_EventKlass *, klass),(INTEGER, HT_TimestampNs, timestamp),(INTEGER, HT_EventId, id)) HT_API HT_EventKlass *ht_HT_Event_get_event_klass_instance(void)

◆ HT_EVENT_DEFINITIONS

#define HT_EVENT_DEFINITIONS (   TYPE_NAME,
  BASE_TYPE,
  ... 
)

◆ HT_EVENT_DEFINITIONS_

#define HT_EVENT_DEFINITIONS_ (   TYPE_NAME,
  BASE_TYPE,
  ... 
)
Value:
HT_EVENT_GET_SIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \
HT_EVENT_SERIALIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE, __VA_ARGS__) \
HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DEF(TYPE_NAME) \
HT_EVENT_REGISTER_KLASS_FUNCTION_DEF(TYPE_NAME)
#define HT_EVENT_GET_SIZE_FUNCTION_DEF(TYPE_NAME, BASE_TYPE,...)
Definition: event_macros.h:40

◆ HT_EVENT_GET_KLASS_INSTANCE_FUNCTION

#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION (   C_TYPE)    ht_##C_TYPE##_get_event_klass_instance

◆ HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DECL

#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DECL (   TYPE_NAME)    HT_API HT_EventKlass* HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(TYPE_NAME)(void);

◆ HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DEF

#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION_DEF (   TYPE_NAME)
Value:
{ \
static HT_EventKlass klass_instance = { \
NULL, \
HT_EVENT_SERIALIZE_FUNCTION(TYPE_NAME), \
HT_EVENT_GET_SIZE_FUNCTION(TYPE_NAME), \
HT_INVALID_KLASS_ID \
}; \
return &klass_instance; \
}
typedefHT_DECLS_BEGIN struct _HT_EventKlass HT_EventKlass
Definition: events.h:11
#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(C_TYPE)
Definition: event_macros.h:13

◆ HT_EVENT_GET_SIZE_FUNCTION

#define HT_EVENT_GET_SIZE_FUNCTION (   C_TYPE)    ht_##C_TYPE##_get_size

◆ HT_EVENT_GET_SIZE_FUNCTION_DECL

#define HT_EVENT_GET_SIZE_FUNCTION_DECL (   TYPE_NAME,
  BASE_TYPE,
  ... 
)    HT_API size_t HT_EVENT_GET_SIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME);\

◆ HT_EVENT_GET_SIZE_FUNCTION_DEF

#define HT_EVENT_GET_SIZE_FUNCTION_DEF (   TYPE_NAME,
  BASE_TYPE,
  ... 
)
Value:
size_t HT_EVENT_GET_SIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME) \
{ \
return MKCREFLECT_FOREACH(HT_EVENT_RUNTIME_SIZEOF, ((TYPE_NAME*)VAR_NAME), (STRUCT, BASE_TYPE, base), __VA_ARGS__); \
}
#define HT_EVENT_RUNTIME_SIZEOF(X, USER_DATA)
Definition: event_macros.h:22
#define MKCREFLECT_FOREACH(FNC, USER_DATA,...)
Definition: mkcreflect.h:116
#define HT_EVENT_GET_SIZE_FUNCTION(C_TYPE)
Definition: event_macros.h:10
HT_DECLS_BEGIN HT_Event
Definition: core_events.h:11

◆ HT_EVENT_REGISTER_KLASS_FUNCTION

#define HT_EVENT_REGISTER_KLASS_FUNCTION (   C_TYPE)    ht_##C_TYPE##_register_event_klass

◆ HT_EVENT_REGISTER_KLASS_FUNCTION_DECL

#define HT_EVENT_REGISTER_KLASS_FUNCTION_DECL (   TYPE_NAME)    HT_API HT_EventKlassId HT_EVENT_REGISTER_KLASS_FUNCTION(TYPE_NAME)(void);

◆ HT_EVENT_REGISTER_KLASS_FUNCTION_DEF

#define HT_EVENT_REGISTER_KLASS_FUNCTION_DEF (   TYPE_NAME)
Value:
{ \
HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(TYPE_NAME)()->type_info = mkcreflect_get_##TYPE_NAME##_type_info(); \
}
HT_API HT_EventKlassId ht_registry_register_event_klass(HT_EventKlass *event_klass)
Registers new event klass in the system, or gets identifier if klass is already registered.
HT_DECLS_BEGIN typedef uint32_t HT_EventKlassId
An unsigned integer used for event klass identifiers.
Definition: base_types.h:12
#define HT_EVENT_GET_KLASS_INSTANCE_FUNCTION(C_TYPE)
Definition: event_macros.h:13
#define HT_EVENT_REGISTER_KLASS_FUNCTION(C_TYPE)
Definition: event_macros.h:12

◆ HT_EVENT_RUNTIME_SERIALIZE

#define HT_EVENT_RUNTIME_SERIALIZE (   X,
  USER_DATA 
)    HT_EVENT_RUNTIME_SERIALIZE_ (MKCREFLECT_EXPAND_VA_ X)

◆ HT_EVENT_RUNTIME_SERIALIZE_

#define HT_EVENT_RUNTIME_SERIALIZE_ (   ...)    MKCREFLECT_EXPAND_(HT_EVENT_RUNTIME_SERIALIZE__(__VA_ARGS__, 0))

◆ HT_EVENT_RUNTIME_SERIALIZE__

#define HT_EVENT_RUNTIME_SERIALIZE__ (   DATA_TYPE,
  C_TYPE,
  FIELD,
  ... 
)    HT_EVENT_RUNTIME_SERIALIZE_##DATA_TYPE(C_TYPE, FIELD)

◆ HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_

#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);

◆ HT_EVENT_RUNTIME_SERIALIZE_DOUBLE

#define HT_EVENT_RUNTIME_SERIALIZE_DOUBLE (   C_TYPE,
  FIELD 
)    HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD)

◆ HT_EVENT_RUNTIME_SERIALIZE_INTEGER

#define HT_EVENT_RUNTIME_SERIALIZE_INTEGER (   C_TYPE,
  FIELD 
)    HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD)

◆ HT_EVENT_RUNTIME_SERIALIZE_POINTER

#define HT_EVENT_RUNTIME_SERIALIZE_POINTER (   C_TYPE,
  FIELD 
)    HT_EVENT_RUNTIME_SERIALIZE_BASE_TYPE_(C_TYPE, FIELD)

◆ HT_EVENT_RUNTIME_SERIALIZE_STRING

#define HT_EVENT_RUNTIME_SERIALIZE_STRING (   C_TYPE,
  FIELD 
)
Value:
do {\
size_t len = (VAR_NAME->FIELD) ? strlen(VAR_NAME->FIELD) + 1 : 0; \
memcpy(buffer + offset, VAR_NAME->FIELD, len); \
offset += len; \
} while (0);

◆ HT_EVENT_RUNTIME_SERIALIZE_STRUCT

#define HT_EVENT_RUNTIME_SERIALIZE_STRUCT (   C_TYPE,
  FIELD 
)    offset += HT_EVENT_SERIALIZE_FUNCTION(C_TYPE)(((HT_Event*)&VAR_NAME->FIELD), buffer);

◆ HT_EVENT_RUNTIME_SIZEOF

#define HT_EVENT_RUNTIME_SIZEOF (   X,
  USER_DATA 
)    HT_EVENT_RUNTIME_SIZEOF_(USER_DATA, MKCREFLECT_EXPAND_VA_ X)

◆ HT_EVENT_RUNTIME_SIZEOF_

#define HT_EVENT_RUNTIME_SIZEOF_ (   ...)    MKCREFLECT_EXPAND_(HT_EVENT_RUNTIME_SIZEOF__(__VA_ARGS__, 0))

◆ HT_EVENT_RUNTIME_SIZEOF__

#define HT_EVENT_RUNTIME_SIZEOF__ (   VAR_NAME,
  DATA_TYPE,
  C_TYPE,
  FIELD,
  ... 
)    +HT_EVENT_RUNTIME_SIZEOF_##DATA_TYPE(VAR_NAME, FIELD, C_TYPE)

◆ HT_EVENT_RUNTIME_SIZEOF_DOUBLE

#define HT_EVENT_RUNTIME_SIZEOF_DOUBLE (   VAR_NAME,
  FIELD,
  C_TYPE 
)    sizeof(VAR_NAME->FIELD)

◆ HT_EVENT_RUNTIME_SIZEOF_INTEGER

#define HT_EVENT_RUNTIME_SIZEOF_INTEGER (   VAR_NAME,
  FIELD,
  C_TYPE 
)    sizeof(VAR_NAME->FIELD)

◆ HT_EVENT_RUNTIME_SIZEOF_POINTER

#define HT_EVENT_RUNTIME_SIZEOF_POINTER (   VAR_NAME,
  FIELD,
  C_TYPE 
)    sizeof(VAR_NAME->FIELD)

◆ HT_EVENT_RUNTIME_SIZEOF_STRING

#define HT_EVENT_RUNTIME_SIZEOF_STRING (   VAR_NAME,
  FIELD,
  C_TYPE 
)    (VAR_NAME->FIELD ? strlen(VAR_NAME->FIELD) + 1 : 0)

◆ HT_EVENT_RUNTIME_SIZEOF_STRUCT

#define HT_EVENT_RUNTIME_SIZEOF_STRUCT (   VAR_NAME,
  FIELD,
  C_TYPE 
)    HT_EVENT_GET_SIZE_FUNCTION(C_TYPE)(((HT_Event*)&VAR_NAME->FIELD))

◆ HT_EVENT_SERIALIZE_FUNCTION

#define HT_EVENT_SERIALIZE_FUNCTION (   C_TYPE)    ht_##C_TYPE##_fnc_serialize

◆ HT_EVENT_SERIALIZE_FUNCTION_DECL

#define HT_EVENT_SERIALIZE_FUNCTION_DECL (   TYPE_NAME,
  BASE_TYPE,
  ... 
)    HT_API size_t HT_EVENT_SERIALIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME_, HT_Byte* buffer);

◆ HT_EVENT_SERIALIZE_FUNCTION_DEF

#define HT_EVENT_SERIALIZE_FUNCTION_DEF (   TYPE_NAME,
  BASE_TYPE,
  ... 
)
Value:
size_t HT_EVENT_SERIALIZE_FUNCTION(TYPE_NAME)(HT_Event* VAR_NAME_, HT_Byte* buffer) \
{ \
size_t offset = 0; \
TYPE_NAME* VAR_NAME = (TYPE_NAME*)VAR_NAME_; \
MKCREFLECT_FOREACH(HT_EVENT_RUNTIME_SERIALIZE, 0, (STRUCT, BASE_TYPE, base), __VA_ARGS__) \
return offset; \
}
#define HT_EVENT_SERIALIZE_FUNCTION(C_TYPE)
Definition: event_macros.h:11
uint8_t HT_Byte
An unsigned integer guaranteed to be 8 bits on all platforms.
Definition: base_types.h:26
HT_DECLS_BEGIN HT_Event
Definition: core_events.h:11
#define HT_EVENT_RUNTIME_SERIALIZE(X, USER_DATA)
Definition: event_macros.h:37