+static int ltt_seek_next_event(LttTracefile *tf);
+
+void ltt_update_event_size(LttTracefile *tf);
+
+#if 0
+/* Functions to parse system.xml file (using glib xml parser) */
+static void parser_start_element (GMarkupParseContext __UNUSED__ *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error)
+{
+ int i=0;
+ LttSystemDescription* des = (LttSystemDescription* )user_data;
+ if(strcmp("system", element_name)){
+ *error = g_error_new(G_MARKUP_ERROR,
+ G_LOG_LEVEL_WARNING,
+ "This is not system.xml file");
+ return;
+ }
+
+ while(attribute_names[i]){
+ if(strcmp("node_name", attribute_names[i])==0){
+ des->node_name = g_strdup(attribute_values[i]);
+ }else if(strcmp("domainname", attribute_names[i])==0){
+ des->domain_name = g_strdup(attribute_values[i]);
+ }else if(strcmp("cpu", attribute_names[i])==0){
+ des->nb_cpu = atoi(attribute_values[i]);
+ }else if(strcmp("arch_size", attribute_names[i])==0){
+ if(strcmp(attribute_values[i],"LP32") == 0) des->size = LTT_LP32;
+ else if(strcmp(attribute_values[i],"ILP32") == 0) des->size = LTT_ILP32;
+ else if(strcmp(attribute_values[i],"LP64") == 0) des->size = LTT_LP64;
+ else if(strcmp(attribute_values[i],"ILP64") == 0) des->size = LTT_ILP64;
+ else if(strcmp(attribute_values[i],"UNKNOWN") == 0) des->size = LTT_UNKNOWN;
+ }else if(strcmp("endian", attribute_names[i])==0){
+ if(strcmp(attribute_values[i],"LITTLE_ENDIAN") == 0)
+ des->endian = LTT_LITTLE_ENDIAN;
+ else if(strcmp(attribute_values[i],"BIG_ENDIAN") == 0)
+ des->endian = LTT_BIG_ENDIAN;
+ }else if(strcmp("kernel_name", attribute_names[i])==0){
+ des->kernel_name = g_strdup(attribute_values[i]);
+ }else if(strcmp("kernel_release", attribute_names[i])==0){
+ des->kernel_release = g_strdup(attribute_values[i]);
+ }else if(strcmp("kernel_version", attribute_names[i])==0){
+ des->kernel_version = g_strdup(attribute_values[i]);
+ }else if(strcmp("machine", attribute_names[i])==0){
+ des->machine = g_strdup(attribute_values[i]);
+ }else if(strcmp("processor", attribute_names[i])==0){
+ des->processor = g_strdup(attribute_values[i]);
+ }else if(strcmp("hardware_platform", attribute_names[i])==0){
+ des->hardware_platform = g_strdup(attribute_values[i]);
+ }else if(strcmp("operating_system", attribute_names[i])==0){
+ des->operating_system = g_strdup(attribute_values[i]);
+ }else if(strcmp("ltt_major_version", attribute_names[i])==0){
+ des->ltt_major_version = atoi(attribute_values[i]);
+ }else if(strcmp("ltt_minor_version", attribute_names[i])==0){
+ des->ltt_minor_version = atoi(attribute_values[i]);
+ }else if(strcmp("ltt_block_size", attribute_names[i])==0){
+ des->ltt_block_size = atoi(attribute_values[i]);
+ }else{
+ *error = g_error_new(G_MARKUP_ERROR,
+ G_LOG_LEVEL_WARNING,
+ "Not a valid attribute");
+ return;
+ }
+ i++;
+ }
+}
+
+static void parser_characters (GMarkupParseContext __UNUSED__ *context,
+ const gchar *text,
+ gsize __UNUSED__ text_len,
+ gpointer user_data,
+ GError __UNUSED__ **error)
+{
+ LttSystemDescription* des = (LttSystemDescription* )user_data;
+ des->description = g_strdup(text);
+}
+#endif //0
+LttFacility *ltt_trace_get_facility_by_num(LttTrace *t,
+ guint num)
+{
+ g_assert(num < t->facilities_by_num->len);
+
+ return &g_array_index(t->facilities_by_num, LttFacility, num);
+
+}
+
+guint ltt_trace_get_num_cpu(LttTrace *t)
+{
+ return t->num_cpu;
+}
+
+
+/* trace can be NULL
+ *
+ * Return value : 0 success, 1 bad tracefile
+ */
+int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t)
+{
+ guint32 *magic_number = (guint32*)header;
+ struct ltt_trace_header_any *any = (struct ltt_trace_header_any *)header;
+
+ if(*magic_number == LTT_MAGIC_NUMBER)
+ tf->reverse_bo = 0;
+ else if(*magic_number == LTT_REV_MAGIC_NUMBER)
+ tf->reverse_bo = 1;
+ else /* invalid magic number, bad tracefile ! */
+ return 1;
+
+ /* Get float byte order : might be different from int byte order
+ * (or is set to 0 if the trace has no float (kernel trace)) */
+ tf->float_word_order = any->float_word_order;
+
+ if(t) {
+ t->arch_type = ltt_get_uint32(LTT_GET_BO(tf),
+ &any->arch_type);
+ t->arch_variant = ltt_get_uint32(LTT_GET_BO(tf),
+ &any->arch_variant);
+ t->arch_size = any->arch_size;
+ t->ltt_major_version = any->major_version;
+ t->ltt_minor_version = any->minor_version;
+ t->flight_recorder = any->flight_recorder;
+ t->has_heartbeat = any->has_heartbeat;
+ t->has_alignment = any->has_alignment;
+ t->has_tsc = any->has_tsc;
+ }
+
+
+ switch(any->major_version) {
+
+ case 0:
+ switch(any->minor_version) {
+ case 3:
+ {
+ tf->buffer_header_size =
+ sizeof(struct ltt_block_start_header)
+ + sizeof(struct ltt_trace_header_0_3);
+ g_warning("Unsupported trace version : %hhu.%hhu",
+ any->major_version, any->minor_version);
+ return 1;
+ }
+ break;
+ case 4:
+ {
+ struct ltt_trace_header_0_4 *vheader =
+ (struct ltt_trace_header_0_4 *)header;
+ tf->buffer_header_size =
+ sizeof(struct ltt_block_start_header)
+ + sizeof(struct ltt_trace_header_0_4);
+ if(t) {
+ t->start_monotonic = ltt_get_uint64(LTT_GET_BO(tf),
+ &vheader->start_monotonic);
+ t->start_time = ltt_get_time(LTT_GET_BO(tf),
+ &vheader->start_time);
+ }
+ }
+ break;
+ default:
+ g_warning("Unsupported trace version : %hhu.%hhu",
+ any->major_version, any->minor_version);
+ return 1;
+ }
+ break;
+
+ default:
+ g_warning("Unsupported trace version : %hhu.%hhu",
+ any->major_version, any->minor_version);
+ return 1;
+ }
+
+
+ return 0;
+}
+