+ get_absolute_pathname(pathname, abs_path);
+ t->pathname = g_quark_from_string(abs_path);
+
+ g_datalist_init(&t->tracefiles);
+
+ /* Test to see if it looks like a trace */
+ dir = opendir(abs_path);
+ if(dir == NULL) {
+ perror(abs_path);
+ goto open_error;
+ }
+ while((entry = readdir(dir)) != NULL) {
+ strcpy(path, abs_path);
+ strcat(path, "/");
+ strcat(path, entry->d_name);
+ ret = stat(path, &stat_buf);
+ if(ret == -1) {
+ perror(path);
+ continue;
+ }
+ if(S_ISDIR(stat_buf.st_mode)) {
+ if(strcmp(entry->d_name, "control") == 0) {
+ control_found = 1;
+ }
+ if(strcmp(entry->d_name, "eventdefs") == 0) {
+ eventdefs_found = 1;
+ }
+ }
+ }
+ closedir(dir);
+
+ if(!control_found || !eventdefs_found) goto find_error;
+
+ /* Open all the tracefiles */
+ if(open_tracefiles(t, abs_path, "")) {
+ g_warning("Error opening tracefile %s", abs_path);
+ goto find_error;
+ }
+
+ /* Prepare the facilities containers : array and mapping */
+ /* Array is zeroed : the "exists" field is set to false by default */
+ t->facilities_by_num = g_array_sized_new (FALSE,
+ TRUE, sizeof(LttFacility),
+ NUM_FACILITIES);
+ t->facilities_by_num = g_array_set_size(t->facilities_by_num, NUM_FACILITIES);
+
+ g_datalist_init(&t->facilities_by_name);
+
+ /* Parse each trace control/facilitiesN files : get runtime fac. info */
+ group = g_datalist_id_get_data(&t->tracefiles, LTT_TRACEFILE_NAME_FACILITIES);
+ if(group == NULL) {
+ g_error("Trace %s has no facility tracefile", abs_path);
+ g_assert(0);
+ goto facilities_error;
+ }
+
+ /* Get the trace information for the control/facility 0 tracefile */
+ g_assert(group->len > 0);
+ tf = &g_array_index (group, LttTracefile, 0);
+ header = (struct ltt_block_start_header*)tf->buffer.head;
+ g_assert(parse_trace_header(header->trace,
+ tf, t) == 0);
+
+ t->num_cpu = group->len;
+
+ for(i=0; i<group->len; i++) {
+ tf = &g_array_index (group, LttTracefile, i);
+ if(ltt_process_facility_tracefile(tf))
+ goto facilities_error;
+ }
+
+ return t;
+
+ /* Error handling */
+facilities_error:
+ g_datalist_clear(&t->facilities_by_name);
+ g_array_free(t->facilities_by_num, TRUE);
+find_error:
+ g_datalist_clear(&t->tracefiles);
+open_error:
+ g_free(t);
+alloc_error:
+ return NULL;
+
+}
+
+GQuark ltt_trace_name(const LttTrace *t)
+{
+ return t->pathname;
+}
+
+
+/******************************************************************************
+ * When we copy a trace, we want all the opening actions to happen again :
+ * the trace will be reopened and totally independant from the original.
+ * That's why we call ltt_trace_open.
+ *****************************************************************************/
+LttTrace *ltt_trace_copy(LttTrace *self)
+{
+ return ltt_trace_open(g_quark_to_string(self->pathname));
+}
+
+void ltt_trace_close(LttTrace *t)
+{
+ guint i;
+ LttFacility *fac;
+
+ for(i=0; i<t->facilities_by_num->len; i++) {
+ fac = &g_array_index (t->facilities_by_num, LttFacility, i);
+ if(fac->exists)
+ ltt_facility_close(fac);
+ }
+
+ g_datalist_clear(&t->facilities_by_name);
+ g_array_free(t->facilities_by_num, TRUE);
+ g_datalist_clear(&t->tracefiles);
+ g_free(t);
+}
+
+
+/*****************************************************************************
+ *Get the system description of the trace
+ ****************************************************************************/
+
+LttFacility *ltt_trace_facility_by_id(LttTrace *t, guint8 id)
+{
+ g_assert(id < t->facilities_by_num->len);
+ return &g_array_index(t->facilities_by_num, LttFacility, id);
+}
+
+/* ltt_trace_facility_get_by_name
+ *
+ * Returns the GArray of facility indexes. All the fac_ids that matches the
+ * requested facility name.
+ *
+ * If name is not found, returns NULL.
+ */
+GArray *ltt_trace_facility_get_by_name(LttTrace *t, GQuark name)
+{
+ return g_datalist_id_get_data(&t->facilities_by_name, name);
+}
+
+/*****************************************************************************
+ * Functions to discover all the event types in the trace
+ ****************************************************************************/
+
+#if 0
+unsigned ltt_trace_eventtype_number(LttTrace *t)
+{
+ unsigned int i;
+ unsigned count = 0;
+ unsigned int num = t->facility_number;
+ LttFacility * f;
+
+ for(i=0;i<num;i++){
+ f = (LttFacility*)g_ptr_array_index(t->facilities, i);
+ count += f->event_number;
+ }
+ return count;
+}
+#endif //0
+
+#if 0
+//use an iteration on all the trace facilities, and inside iteration on all the
+//event types in each facilities instead.
+LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId)
+{
+ LttEventType *event_type;
+
+ LttFacility * f;
+ f = ltt_trace_facility_by_id(t,evId);
+
+ if(unlikely(!f)) event_type = NULL;
+ else event_type = f->events[evId - f->base_id];
+
+ return event_type;
+}
+#endif //0
+
+#if 0
+/*****************************************************************************
+ * ltt_trace_find_tracefile
+ *
+ * Find a tracefile by name and index in the group.
+ *
+ * Returns a pointer to the tracefiles, else NULL.
+ ****************************************************************************/
+
+LttTracefile *ltt_trace_find_tracefile(LttTrace *t, const gchar *name)
+{
+}
+#endif //0