+ GArray *fac_ids = (GArray *)data;
+
+ g_array_free(fac_ids, TRUE);
+}
+#endif //0
+
+/* Presumes the tracefile is already seeked at the beginning. It makes sense,
+ * because it must be done just after the opening */
+int ltt_process_facility_tracefile(LttTracefile *tf)
+{
+ int err;
+ //LttFacility *fac;
+ //GArray *fac_ids;
+ guint i;
+ //LttEventType *et;
+
+ while(1) {
+ err = ltt_tracefile_read_seek(tf);
+ if(err == EPERM) goto seek_error;
+ else if(err == ERANGE) break; /* End of tracefile */
+
+ err = ltt_tracefile_read_update_event(tf);
+ if(err) goto update_error;
+
+ /* We are on a facility load/or facility unload/ or heartbeat event */
+ /* The rules are :
+ * * facility 0 is hardcoded : this is the core facility. It will be shown
+ * in the facility array though, and is shown as "loaded builtin" in the
+ * trace.
+ * It contains event :
+ * 0 : facility load
+ * 1 : facility unload
+ * 2 : state dump facility load
+ * 3 : heartbeat
+ */
+ if(tf->event.event_id >= MARKER_CORE_IDS) {
+ /* Should only contain core facility */
+ g_warning("Error in processing facility file %s, "
+ "should not contain event id %u.", g_quark_to_string(tf->name),
+ tf->event.event_id);
+ err = EPERM;
+ goto event_id_error;
+ } else {
+
+ void *pos;
+ const char *marker_name, *format;
+ uint16_t id;
+ guint8 int_size, long_size, pointer_size, size_t_size, alignment;
+
+ // FIXME align
+ switch((enum marker_id)tf->event.event_id) {
+ case MARKER_ID_SET_MARKER_ID:
+ marker_name = (char*)(tf->event.data);
+ g_debug("Doing MARKER_ID_SET_MARKER_ID of marker %s", marker_name);
+ pos = (tf->event.data + strlen(marker_name) + 1);
+ pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
+ pos += ltt_align((size_t)pos, sizeof(uint16_t), tf->has_alignment);
+ id = ltt_get_uint16(LTT_GET_BO(tf), pos);
+ pos += sizeof(guint16);
+ int_size = *(guint8*)pos;
+ pos += sizeof(guint8);
+ long_size = *(guint8*)pos;
+ pos += sizeof(guint8);
+ pointer_size = *(guint8*)pos;
+ pos += sizeof(guint8);
+ size_t_size = *(guint8*)pos;
+ pos += sizeof(guint8);
+ alignment = *(guint8*)pos;
+ pos += sizeof(guint8);
+ marker_id_event(tf->trace, g_quark_from_string(marker_name),
+ id, int_size, long_size,
+ pointer_size, size_t_size, alignment);
+ break;
+ case MARKER_ID_SET_MARKER_FORMAT:
+ marker_name = (char*)(tf->event.data);
+ g_debug("Doing MARKER_ID_SET_MARKER_FORMAT of marker %s",
+ marker_name);
+ pos = (tf->event.data + strlen(marker_name) + 1);
+ pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
+ format = (const char*)pos;
+ pos += strlen(format) + 1;
+ pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
+ marker_format_event(tf->trace, g_quark_from_string(marker_name),
+ format);
+ /* get information from dictionnary TODO */
+ break;
+ case MARKER_ID_HEARTBEAT_32:
+ case MARKER_ID_HEARTBEAT_64:
+ break;
+ default:
+ g_warning("Error in processing facility file %s, "
+ "unknown event id %hhu.",
+ g_quark_to_string(tf->name),
+ tf->event.event_id);
+ err = EPERM;
+ goto event_id_error;
+ }
+ }
+ }
+ return 0;
+
+ /* Error handling */
+event_id_error:
+update_error:
+seek_error:
+ g_warning("An error occured in facility tracefile parsing");
+ return err;
+}
+
+
+LttTrace *ltt_trace_open(const gchar *pathname)
+{
+ gchar abs_path[PATH_MAX];
+ LttTrace * t;
+ LttTracefile *tf;
+ GArray *group;
+ int i, ret;
+ struct ltt_block_start_header *header;
+ DIR *dir;
+ struct dirent *entry;
+ guint control_found = 0;
+ guint eventdefs_found = 0;
+ struct stat stat_buf;
+ gchar path[PATH_MAX];
+
+ t = g_new(LttTrace, 1);
+ if(!t) goto alloc_error;
+
+ 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;