+/* Save all positions, the ones not in the pqueue will have NULL
+ * ep. */
+void lttv_traceset_context_position_save(const LttvTracesetContext *self,
+ LttvTracesetContextPosition *pos)
+{
+ guint i;
+ guint num_traces = lttv_traceset_number(self->ts);
+
+ for(i=0; i<num_traces;i++) {
+ GArray * tracefiles = self->traces[i]->tracefiles;
+ guint j;
+ guint num_tracefiles = tracefiles->len;
+
+ for(j=0;j<num_tracefiles;j++) {
+ LttvTracefileContext **tfc = &g_array_index(tracefiles,
+ LttvTracefileContext*, j);
+
+ LttEvent *event = ltt_tracefile_get_event((*tfc)->tf);
+ LttEventPosition *ep;
+
+ if(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0) {
+ ep = ltt_event_position_new();
+ ltt_event_position(event, ep);
+ if(ltt_time_compare((*tfc)->timestamp, pos->timestamp) < 0)
+ pos->timestamp = (*tfc)->timestamp;
+ } else {
+ ep = NULL;
+ }
+ g_array_append_val(pos->tfc, *tfc);
+ g_array_append_val(pos->ep, ep);
+ }
+
+ }
+}
+
+void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos)
+{
+ int i;
+ LttEventPosition **ep;
+
+ for(i=0;i<pos->ep->len;i++) {
+ ep = &g_array_index(pos->ep, LttEventPosition*, i);
+ if(*ep != NULL)
+ g_free(*ep);
+ }
+ g_array_free(pos->ep, TRUE);
+ g_array_free(pos->tfc, TRUE);
+ g_free(pos);
+}
+
+void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest,
+ const LttvTracesetContextPosition *src)
+{
+ int i;
+ LttEventPosition **src_ep, **dest_ep;
+
+ g_array_set_size(dest->ep, src->ep->len);
+ g_array_set_size(dest->tfc, src->tfc->len);
+
+ for(i=0;i<src->ep->len;i++) {
+ src_ep = &g_array_index(src->ep, LttEventPosition*, i);
+ dest_ep = &g_array_index(dest->ep, LttEventPosition*, i);
+ if(*src_ep != NULL) {
+ *dest_ep = ltt_event_position_new();
+ ltt_event_position_copy(
+ *dest_ep,
+ *src_ep);
+ } else
+ *dest_ep = NULL;
+ }
+ for(i=0;i<src->tfc->len;i++) {
+ g_array_index(dest->tfc, LttvTracefileContext*, i) =
+ g_array_index(src->tfc, LttvTracefileContext*, i);
+ }
+ dest->timestamp = src->timestamp;
+}
+
+gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self,
+ const LttvTracesetContextPosition *pos)
+{
+ int i;
+ int ret = 0;
+
+ if(pos->ep->len == 0) {
+ if(lttv_traceset_number(self->ts) == 0) return 0;
+ else return 1;
+ }
+ if(lttv_traceset_number(self->ts) == 0)
+ return -1;
+
+ for(i=0;i<pos->ep->len;i++) {
+ LttEventPosition *ep = g_array_index(pos->ep, LttEventPosition*, i);
+ LttvTracefileContext *tfc =
+ g_array_index(pos->tfc, LttvTracefileContext*, i);
+
+ if(ep == NULL) {
+ if(ltt_time_compare(tfc->timestamp, ltt_time_infinite) != 0) {
+ ret = -1;
+ }
+ } else {
+ if(ltt_time_compare(tfc->timestamp, ltt_time_infinite) == 0) {
+ ret = 1;
+ } else {
+ LttEvent *event = ltt_tracefile_get_event(tfc->tf);
+
+ ret = ltt_event_position_compare((LttEventPosition*)event,
+ ep);
+ }
+ }
+ if(ret != 0) return ret;
+
+ }
+ return 0;
+}
+
+
+gint lttv_traceset_context_pos_pos_compare(
+ const LttvTracesetContextPosition *pos1,
+ const LttvTracesetContextPosition *pos2)
+{
+ int i, j;
+ int ret;
+
+ if(pos1->ep->len == 0) {
+ if(pos2->ep->len == 0) return 0;
+ else return 1;
+ }
+ if(pos2->ep->len == 0)
+ return -1;
+
+ for(i=0;i<pos1->ep->len;i++) {
+ LttEventPosition *ep1 = g_array_index(pos1->ep, LttEventPosition*, i);
+ LttvTracefileContext *tfc1 = g_array_index(pos1->tfc,
+ LttvTracefileContext*, i);
+
+ if(ep1 != NULL) {
+ for(j=0;j<pos2->ep->len;j++) {
+ LttEventPosition *ep2 = g_array_index(pos2->ep, LttEventPosition*, j);
+ LttvTracefileContext *tfc2 = g_array_index(pos2->tfc,
+ LttvTracefileContext*, j);
+ if(tfc1 == tfc2) {
+ if(ep2 != NULL)
+ ret = ltt_event_position_compare(ep1, ep2);
+ else
+ ret = -1;
+
+ if(ret != 0) return ret;
+ }
+ }
+ } else {
+ for(j=0;j<pos2->ep->len;j++) {
+ LttEventPosition *ep2 = g_array_index(pos2->ep, LttEventPosition*, j);
+ LttvTracefileContext *tfc2 = g_array_index(pos2->tfc,
+ LttvTracefileContext*, j);
+ if(tfc1 == tfc2) {
+ if(ep2 != NULL) ret = 1;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+
+LttTime lttv_traceset_context_position_get_time(
+ const LttvTracesetContextPosition *pos)
+{
+ return pos->timestamp;
+}
+
+
+LttvTracefileContext *lttv_traceset_context_get_current_tfc(LttvTracesetContext *self)
+{
+ GTree *pqueue = self->pqueue;
+ LttvTracefileContext *tfc = NULL;
+
+ g_tree_foreach(pqueue, get_first, &tfc);
+
+ return tfc;
+}
+#if 0
+/* lttv_process_traceset_synchronize_tracefiles
+ *
+ * Use the sync_position field of the trace set context to synchronize each
+ * tracefile with the previously saved position.
+ *
+ * If no previous position has been saved, it simply does nothing.
+ */
+void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *tsc)
+{
+ g_assert(lttv_process_traceset_seek_position(tsc, tsc->sync_position) == 0);
+}
+
+
+
+
+void lttv_process_traceset_get_sync_data(LttvTracesetContext *tsc)
+{
+ lttv_traceset_context_position_save(tsc, tsc->sync_position);