mega fix for states : per cpu and _not_ per tracefile state. We have many tracefiles...
[lttv.git] / ltt / branches / poly / ltt / facility.c
index 1d9ed5f66fb807b35a848e986017f6889ab02b56..53519c02a683046b00b0b10b2c95aa16931a3aff 100644 (file)
 
 /* search for the (named) type in the table, if it does not exist
    create a new one */
-LttType * lookup_named_type(LttFacility *fac, type_descriptor * td);
+LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td);
 
 /* construct directed acyclic graph for types, and tree for fields */
-void construct_types_and_fields(LttFacility * fac,type_descriptor * td, 
+void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td, 
                             LttField * fld);
 
 /* generate the facility according to the events belongin to it */
@@ -74,12 +74,12 @@ void freeLttNamedType(LttType * type);
 
 int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
 {
+  int ret = 0;
   gchar *token;
-  parse_file in;
-  gsize length;
+  parse_file_t in;
   facility_t * fac;
-  guint32 checksum;
-  GError * error = NULL;
+  unsigned long checksum;
+  //GError * error = NULL;
   gchar buffer[BUFFER_SIZE];
 
   in.buffer = &(buffer[0]);
@@ -87,15 +87,18 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
   in.error = error_callback;
   in.name = pathname;
 
-  in.fd = g_open(in.name, O_RDONLY, 0);
-  if(in.fd < 0 ) {
+  //in.fd = g_open(in.name, O_RDONLY, 0);
+  //if(in.fd < 0 ) {
+  in.fp = fopen(in.name, "r");
+  if(in.fp == NULL) {
     g_warning("cannot open facility description file %s",
         in.name);
-    return 1;
+    ret = 1;
+    goto open_error;
   }
 
-  in.channel = g_io_channel_unix_new(in.fd);
-  in.pos = 0;
+  //in.channel = g_io_channel_unix_new(in.fd);
+  //in.pos = 0;
 
   while(1){
     token = getToken(&in);
@@ -115,9 +118,9 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
       parseFacility(&in, fac);
 
       //check if any namedType is not defined
-      g_assert(checkNamedTypesImplemented(&fac->named_types) == 0);
+      checkNamedTypesImplemented(&fac->named_types);
     
-      g_assert(generateChecksum(fac->name, &checksum, &fac->events) == 0);
+      generateChecksum(fac->name, &checksum, &fac->events);
 
       generateFacility(f, fac, checksum);
 
@@ -133,18 +136,22 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
     }
     else {
       g_warning("facility token was expected in file %s", in.name);
+      ret = 1;
       goto parse_error;
     }
   }
 
  parse_error:
-  g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */
-  if(error != NULL) {
-    g_warning("Can not close file: \n%s\n", error->message);
-    g_error_free(error);
-  }
+  //g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */
+  //if(error != NULL) {
+  fclose(in.fp);
+open_error:
+  //  g_warning("Can not close file: \n%s\n", error->message);
+  //  g_error_free(error);
+  //}
 
-  g_close(in.fd);
+  //g_close(in.fd);
+  return ret;
 }
 
 
@@ -160,7 +167,7 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
 void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
 {
   char * facilityName = fac->name;
-  sequence * events = &fac->events;
+  sequence_t * events = &fac->events;
   int i;
   //LttEventType * evType;
   LttEventType * event_type;
@@ -244,24 +251,42 @@ void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
  ****************************************************************************/
 
 
-void construct_types_and_fields(LttFacility * fac, type_descriptor * td, 
+void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td, 
                             LttField * fld)
 {
-  int i, flag;
-  type_descriptor * tmpTd;
+  int i;
+  type_descriptor_t * tmpTd;
 
   switch(td->type) {
-  case LTT_ENUM:
-    fld->field_type->element_number = td->labels.position;
-    fld->field_type->enum_strings = g_new(GQuark,td->labels.position);
-    for(i=0;i<td->labels.position;i++){
-      fld->field_type->enum_strings[i] 
-                     = g_quark_from_string(((char*)(td->labels.array[i])));
-    }
-    break;
-  case LTT_ARRAY:
-    fld->field_type->element_number = (unsigned)td->size;
-  case LTT_SEQUENCE:
+    case INT:
+    case UINT:
+    case FLOAT:
+      fld->field_type->size = td->size;
+      break;
+    case POINTER:
+    case LONG:
+    case ULONG:
+    case SIZE_T:
+    case SSIZE_T:
+    case OFF_T:
+      fld->field_type->size = 0;
+      break;
+    case STRING:
+      fld->field_type->size = 0;
+      break;
+    case ENUM:
+      fld->field_type->element_number = td->labels.position;
+      fld->field_type->enum_strings = g_new(GQuark,td->labels.position);
+      for(i=0;i<td->labels.position;i++){
+        fld->field_type->enum_strings[i] 
+                       = g_quark_from_string(((char*)(td->labels.array[i])));
+      }
+      fld->field_type->size = td->size;
+      break;
+
+    case ARRAY:
+      fld->field_type->element_number = (unsigned)td->size;
+    case SEQUENCE:
     fld->field_type->element_type = g_new(LttType*,1);
     tmpTd = td->nested_type;
     fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd);
@@ -280,8 +305,9 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
     fld->child[0]->current_element = 0;
     construct_types_and_fields(fac, tmpTd, fld->child[0]);
     break;
-  case LTT_STRUCT:
-  case LTT_UNION:
+
+  case STRUCT:
+  case UNION:
     fld->field_type->element_number = td->fields.position;
 
     g_assert(fld->field_type->element_type == NULL);
@@ -289,7 +315,7 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
 
     fld->child = g_new(LttField*, td->fields.position);      
     for(i=0;i<td->fields.position;i++){
-      tmpTd = ((type_fields*)(td->fields.array[i]))->type;
+      tmpTd = ((field_t*)(td->fields.array[i]))->type;
 
        fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
       fld->child[i] = g_new(LttField,1); 
@@ -298,7 +324,7 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
       fld->child[i]->field_type = fld->field_type->element_type[i]; 
 
       fld->child[i]->field_type->element_name 
-                 = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name);
+                 = g_quark_from_string(((field_t*)(td->fields.array[i]))->name);
 
       fld->child[i]->offset_root = 0;
       fld->child[i]->fixed_root = FIELD_UNKNOWN;
@@ -311,8 +337,8 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
       fld->child[i]->current_element = 0;
       construct_types_and_fields(fac, tmpTd, fld->child[i]);
     }    
-
     break;
+
   default:
     g_error("construct_types_and_fields : unknown type");
   }
@@ -415,17 +441,22 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
  *                     : either find the named type, or create a new LttType
  ****************************************************************************/
 
-LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
+LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td)
 {
-  GQuark name = g_quark_from_string(td->type_name);
+  LttType *type = NULL;
+  GQuark name = 0;
+  
+  if(td->type_name != NULL) {
+    /* Named type */
+    name = g_quark_from_string(td->type_name);
+  
+    type = g_datalist_id_get_data(&fac->named_types, name);
+  }
   
-  LttType *type = g_datalist_id_get_data(&fac->named_types, name);
-
   if(type == NULL){
+    /* Create the type */
     type = g_new(LttType,1);
     type->type_name = name;
-    g_datalist_id_set_data_full(&fac->named_types, name,
-        type, (GDestroyNotify)freeLttNamedType);
     type->type_class = td->type;
     if(td->fmt) type->fmt = g_strdup(td->fmt);
     else type->fmt = NULL;
@@ -433,8 +464,11 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td)
     type->enum_strings = NULL;
     type->element_type = NULL;
     type->element_number = 0;
+    
+    if(td->type_name != NULL)
+      g_datalist_id_set_data_full(&fac->named_types, name,
+                  type, (GDestroyNotify)freeLttNamedType);
   }
-
   return type;
 }
 
@@ -493,6 +527,7 @@ void freeLttType(LttType ** type)
 {
   unsigned int i;
   if(*type == NULL) return;
+  if((*type)->type_name != 0) return; //this is a named type.
   //if((*type)->type_name){
   //  return; //this is a named type
   //}
@@ -602,6 +637,8 @@ guint8 ltt_facility_eventtype_number(LttFacility *f)
 
 LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i)
 {
+  if(!f->exists) return NULL;
+
   g_assert(i < f->events->len);
   return &g_array_index(f->events, LttEventType, i);
 }
@@ -620,6 +657,7 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i)
 
 LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, GQuark name)
 {
-  LttEventType *et = g_datalist_get_data(f->events_by_name, name);
+  LttEventType *et = g_datalist_id_get_data(&f->events_by_name, name);
+  return et;
 }
 
This page took 0.02647 seconds and 4 git commands to generate.