HawkTracer  0.8.0
timeline.h File Reference

Go to the source code of this file.

Macros

#define HT_TIMELINE_FEATURE(timeline, feature_id, feature_type)   ((feature_type*)ht_timeline_get_feature(timeline, feature_id))
 Returns a pointer to a timeline's feature. More...
 
#define HT_TIMELINE_MAX_FEATURES   32
 Defines maximum number of features that can be attached to a timeline. More...
 
#define HT_TIMELINE_PUSH_EVENT(TIMELINE, EVENT_TYPE, ...)   HT_TIMELINE_PUSH_EVENT_PEDANTIC(TIMELINE, EVENT_TYPE, ht_base_event, __VA_ARGS__)
 Pushes an event to the timeline. More...
 
#define HT_TIMELINE_PUSH_EVENT_PEDANTIC(TIMELINE, EVENT_TYPE, ...)
 Pushes an event to the timeline. More...
 

Typedefs

typedef typedefHT_DECLS_BEGIN struct _HT_Timeline HT_Timeline
 

Functions

HT_API HT_Timelineht_timeline_create (size_t buffer_capacity, HT_Boolean thread_safe, HT_Boolean serialize_events, const char *listeners, HT_ErrorCode *out_err)
 
HT_API void ht_timeline_destroy (HT_Timeline *timeline)
 Destroys a timeline. More...
 
HT_API HT_ErrorCode ht_timeline_register_listener (HT_Timeline *timeline, HT_TimelineListenerCallback callback, void *user_data)
 Registers new listener to a timeline. More...
 
HT_API void ht_timeline_unregister_all_listeners (HT_Timeline *timeline)
 Removes all the listeners from a timeline. More...
 
HT_API void ht_timeline_init_event (HT_Timeline *timeline, HT_Event *event)
 Initializes event according to timeline's parameters. More...
 
HT_API void ht_timeline_push_event (HT_Timeline *timeline, HT_Event *event)
 Pushes an event to a timeline. More...
 
HT_API void ht_timeline_flush (HT_Timeline *timeline)
 Transfers all the events from internal buffer to listeners. More...
 
HT_API void ht_timeline_set_feature (HT_Timeline *timeline, size_t feature_id, void *feature)
 
HT_API void * ht_timeline_get_feature (HT_Timeline *timeline, size_t feature_id)
 
HT_API HT_EventIdProviderht_timeline_get_id_provider (HT_Timeline *timeline)
 

Macro Definition Documentation

◆ HT_TIMELINE_FEATURE

#define HT_TIMELINE_FEATURE (   timeline,
  feature_id,
  feature_type 
)    ((feature_type*)ht_timeline_get_feature(timeline, feature_id))

Returns a pointer to a timeline's feature.

◆ HT_TIMELINE_MAX_FEATURES

#define HT_TIMELINE_MAX_FEATURES   32

Defines maximum number of features that can be attached to a timeline.

◆ HT_TIMELINE_PUSH_EVENT

#define HT_TIMELINE_PUSH_EVENT (   TIMELINE,
  EVENT_TYPE,
  ... 
)    HT_TIMELINE_PUSH_EVENT_PEDANTIC(TIMELINE, EVENT_TYPE, ht_base_event, __VA_ARGS__)

Pushes an event to the timeline.

The macro automatically constructs the event, so user only needs to specify values for event fields (excluding values for HT_Event; i.e. timestamp, event_id and klass_id).

Parameters
TIMELINEthe timeline.
EVENT_TYPEa type of the event to push.
...a list of parameters of the event.

◆ HT_TIMELINE_PUSH_EVENT_PEDANTIC

#define HT_TIMELINE_PUSH_EVENT_PEDANTIC (   TIMELINE,
  EVENT_TYPE,
  ... 
)
Value:
do { \
HT_Event ht_base_event = { \
ht_##EVENT_TYPE##_get_event_klass_instance(), \
ht_monotonic_clock_get_timestamp(), \
ht_event_id_provider_next(ht_timeline_get_id_provider(TIMELINE)) \
}; \
EVENT_TYPE ev = {__VA_ARGS__}; \
ht_timeline_push_event(TIMELINE, HT_EVENT(&ev)); \
} while (0)
HT_API HT_EventIdProvider * ht_timeline_get_id_provider(HT_Timeline *timeline)
#define HT_EVENT(event)
Definition: events.h:23

Pushes an event to the timeline.

The difference between this macro and HT_TIMELINE_PUSH_EVENT() is that it requires using curly brackets for sub-events. It provides a special variable ht_base_event that represents the HT_Event base instance. For example, to push SubEvent to a timeline, you should do:

struct SubEvent {
HT_Event base;
int field1;
float field2;
};
HT_TIMELINE_PUSH_EVENT_PEDANTIC(timeline, SubEvent, {{ht_base_event}, 3, 9.3f});

The macro allows you to push events without generating compiler warnings (unlike HT_TIMELINE_PUSH_EVENT()).

Parameters
TIMELINEthe timeline.
EVENT_TYPEa type of the event to push.
...a list of parameters of the event.

Typedef Documentation

◆ HT_Timeline

typedef typedefHT_DECLS_BEGIN struct _HT_Timeline HT_Timeline

Function Documentation

◆ ht_timeline_create()

HT_API HT_Timeline* ht_timeline_create ( size_t  buffer_capacity,
HT_Boolean  thread_safe,
HT_Boolean  serialize_events,
const char *  listeners,
HT_ErrorCode out_err 
)

◆ ht_timeline_destroy()

HT_API void ht_timeline_destroy ( HT_Timeline timeline)

Destroys a timeline.

Parameters
timelinea pointer to the timeline to destroy.

◆ ht_timeline_flush()

HT_API void ht_timeline_flush ( HT_Timeline timeline)

Transfers all the events from internal buffer to listeners.

Parameters
timelinethe timeline.

◆ ht_timeline_get_feature()

HT_API void* ht_timeline_get_feature ( HT_Timeline timeline,
size_t  feature_id 
)

◆ ht_timeline_get_id_provider()

HT_API HT_EventIdProvider* ht_timeline_get_id_provider ( HT_Timeline timeline)

◆ ht_timeline_init_event()

HT_API void ht_timeline_init_event ( HT_Timeline timeline,
HT_Event event 
)

Initializes event according to timeline's parameters.

The method sets a timestamp and event_id for the event.

Parameters
timelinethe timeline.
eventthe event to initialize.

◆ ht_timeline_push_event()

HT_API void ht_timeline_push_event ( HT_Timeline timeline,
HT_Event event 
)

Pushes an event to a timeline.

Parameters
timelinethe timeline.
eventthe event.

◆ ht_timeline_register_listener()

HT_API HT_ErrorCode ht_timeline_register_listener ( HT_Timeline timeline,
HT_TimelineListenerCallback  callback,
void *  user_data 
)

Registers new listener to a timeline.

Parameters
timelinethe timeline.
callbacka callback of the listener.
user_dataadditional data that will be passed to the listener's callback.
Returns
HT_ERR_OK if registration completed successfully; otherwise, error code.

◆ ht_timeline_set_feature()

HT_API void ht_timeline_set_feature ( HT_Timeline timeline,
size_t  feature_id,
void *  feature 
)

◆ ht_timeline_unregister_all_listeners()

HT_API void ht_timeline_unregister_all_listeners ( HT_Timeline timeline)

Removes all the listeners from a timeline.

Parameters
timelinethe timeline.