+/*****************************************************************************
+ *Function name
+ * ltt_event_position : get the event's position
+ *Input params
+ * e : an instance of an event type
+ * ep : a pointer to event's position structure
+ ****************************************************************************/
+
+void ltt_event_position(LttEvent *e, LttEventPosition *ep)
+{
+ ep->block_num = e->which_block;
+ ep->event_num = e->which_event;
+ ep->event_time = e->event_time;
+ ep->event_cycle_count = e->event_cycle_count;
+ ep->heart_beat_number = e->tracefile->cur_heart_beat_number;
+ ep->old_position = TRUE;
+ ep->event_offset = e->data - e->tracefile->buffer - EVENT_HEADER_SIZE ;
+ ep->tf = e->tracefile;
+
+ /* This is a workaround for fast position seek */
+ ep->last_event_pos = e->last_event_pos;
+ ep->prev_block_end_time = e->prev_block_end_time;
+ ep->prev_event_time = e->prev_event_time;
+ ep->pre_cycle_count = e->pre_cycle_count;
+ ep->count = e->count;
+ /* end of workaround */
+}
+
+LttEventPosition * ltt_event_position_new()
+{
+ return g_new(LttEventPosition, 1);
+}
+
+/*****************************************************************************
+ *Function name
+ * ltt_event_position_get : get the block number and index of the event
+ *Input params
+ * ep : a pointer to event's position structure
+ * block_number : the block number of the event
+ * index_in_block : the index of the event within the block
+ ****************************************************************************/
+
+void ltt_event_position_get(LttEventPosition *ep,
+ unsigned *block_number, unsigned *index_in_block, LttTracefile ** tf)
+{
+ *block_number = ep->block_num;
+ *index_in_block = ep->event_num;
+ *tf = ep->tf;
+}
+
+/*****************************************************************************
+ *Function name
+ * ltt_event_position_set : set the block number and index of the event
+ * It does put the old_position gboolean to FALSE, as it is impossible
+ * to know the quick position to seek in the tracefile.
+ *Input params
+ * ep : a pointer to event's position structure
+ * block_number : the block number of the event
+ * index_in_block : the index of the event within the block
+ ****************************************************************************/
+
+void ltt_event_position_set(LttEventPosition *ep,
+ unsigned block_number, unsigned index_in_block)
+{
+ if(ep->block_num != block_number || ep->event_num != index_in_block)
+ ep->old_position = FALSE;
+
+ ep->block_num = block_number;
+ ep->event_num = index_in_block;
+
+}
+
+/*****************************************************************************
+ * Function name
+ * ltt_event_position_compare : compare two positions
+ * A NULL value is infinite.
+ * Input params
+ * ep1 : a pointer to event's position structure
+ * ep2 : a pointer to event's position structure
+ * Return
+ * -1 is ep1 < ep2
+ * 1 if ep1 > ep2
+ * 0 if ep1 == ep2
+ ****************************************************************************/
+
+
+gint ltt_event_position_compare(const LttEventPosition *ep1,
+ const LttEventPosition *ep2)
+{
+ if(ep1->tf != ep2->tf)
+ g_error("ltt_event_position_compare on different tracefiles makes no sense");
+ if(ep1 == NULL && ep2 == NULL)
+ return 0;
+ if(ep1 != NULL && ep2 == NULL)
+ return -1;
+ if(ep1 == NULL && ep2 != NULL)
+ return 1;
+
+ if(ep1->block_num < ep2->block_num)
+ return -1;
+ if(ep1->block_num > ep2->block_num)
+ return 1;
+ if(ep1->event_num < ep2->event_num)
+ return -1;
+ if(ep1->event_num > ep2->event_num)
+ return 1;
+ return 0;
+}
+
+/*****************************************************************************
+ * Function name
+ * ltt_event_event_position_compare : compare two positions, one in event,
+ * other in position opaque structure.
+ * Input params
+ * event : a pointer to event structure
+ * ep : a pointer to event's position structure
+ * Return
+ * -1 is event < ep
+ * 1 if event > ep
+ * 0 if event == ep
+ ****************************************************************************/
+
+gint ltt_event_event_position_compare(const LttEvent *event,
+ const LttEventPosition *ep)
+{
+ if(event == NULL && ep == NULL)
+ return 0;
+ if(event != NULL && ep == NULL)
+ return -1;
+ if(event == NULL && ep != NULL)
+ return 1;
+
+ g_assert(event->tracefile == ep->tf);
+
+ if(event->which_block < ep->block_num)
+ return -1;
+ if(event->which_block > ep->block_num)
+ return 1;
+ if(event->which_event < ep->event_num)
+ return -1;
+ if(event->which_event > ep->event_num)
+ return 1;
+ return 0;
+}
+
+/*****************************************************************************
+ * Function name
+ * ltt_event_position_copy : copy position
+ * Input params
+ * src : a pointer to event's position structure source
+ * dest : a pointer to event's position structure dest
+ * Return
+ * void
+ ****************************************************************************/
+void ltt_event_position_copy(LttEventPosition *dest,
+ const LttEventPosition *src)
+{
+ if(src == NULL)
+ dest = NULL;
+ else
+ *dest = *src;
+}
+
+