Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Storage parsing skip empty line
[simgrid.git] / src / instr / instr_paje_types.c
index 5bf0a6c..c2c4c42 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
 
 static type_t rootType = NULL;        /* the root type */
-static xbt_dict_t allTypes = NULL;    /* all declared types indexed by name */
 
 void PJ_type_alloc ()
 {
-  allTypes = xbt_dict_new_homogeneous (NULL);
 }
 
 void PJ_type_release ()
 {
-  xbt_dict_free (&allTypes);
   rootType = NULL;
-  allTypes = NULL;
 }
 
 type_t PJ_type_get_root ()
@@ -31,6 +27,10 @@ type_t PJ_type_get_root ()
 
 static type_t newType (const char *typename, const char *key, const char *color, e_entity_types kind, type_t father)
 {
+  if (typename == NULL || key == NULL){
+    THROWF(tracing_error, 0, "can't create a new type with name or key equal NULL");
+  }
+
   type_t ret = xbt_new0(s_type_t, 1);
   ret->name = xbt_strdup (typename);
   ret->father = father;
@@ -47,15 +47,11 @@ static type_t newType (const char *typename, const char *key, const char *color,
     xbt_dict_set (father->children, key, ret, NULL);
     XBT_DEBUG("new type %s, child of %s", typename, father->name);
   }
-
-  xbt_dict_set (allTypes, typename, ret, NULL);
   return ret;
 }
 
 void PJ_type_free (type_t type)
 {
-  xbt_dict_remove (allTypes, type->name);
-
   val_t value;
   char *value_name;
   xbt_dict_cursor_t cursor = NULL;
@@ -87,46 +83,46 @@ void PJ_type_free_all (void)
 {
   recursiveDestroyType (PJ_type_get_root());
   rootType = NULL;
+}
 
-  //checks
-  if (xbt_dict_length(allTypes) != 0){
-    THROWF(tracing_error, 0, "some types still present even after destroying all of them");
+type_t PJ_type_get (const char *name, type_t father)
+{
+  type_t ret = PJ_type_get_or_null (name, father);
+  if (ret == NULL){
+    THROWF (tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name);
   }
+  return ret;
 }
 
-static type_t recursiveGetType (const char *name, type_t root)
+type_t PJ_type_get_or_null (const char *name, type_t father)
 {
-  if (strcmp (root->name, name) == 0) return root;
+  if (name == NULL || father == NULL){
+    THROWF (tracing_error, 0, "can't get type with a NULL name or from a NULL father");
+  }
 
-  xbt_dict_cursor_t cursor = NULL;
-  type_t child;
+  type_t ret = NULL, child;
   char *child_name;
-  type_t ret = NULL;
-  xbt_dict_foreach(root->children, cursor, child_name, child) {
-    type_t found = recursiveGetType(name, child);
-    if (found){
-      if (ret == NULL){
-        ret = found;
+  xbt_dict_cursor_t cursor = NULL;
+  xbt_dict_foreach(father->children, cursor, child_name, child) {
+    if (strcmp (child->name, name) == 0){
+      if (ret != NULL){
+        THROWF (tracing_error, 0, "there are two children types with the same name?");
       }else{
-        THROWF(tracing_error, 0, "found two types with the same name");
+        ret = child;
       }
     }
   }
   return ret;
 }
 
-type_t PJ_type_get (const char *name, type_t father)
-{
-  return recursiveGetType (name, father);
-}
-
 type_t PJ_type_container_new (const char *name, type_t father)
 {
-  type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
-  if (ret){
-    THROWF(tracing_error, 1, "container type with name %s already exists", name);
+  if (name == NULL){
+    THROWF (tracing_error, 0, "can't create a container type with a NULL name");
   }
 
+  type_t ret = NULL;
+
   ret = newType (name, name, NULL, TYPE_CONTAINER, father);
   if (father == NULL){
     rootType = ret;
@@ -139,19 +135,13 @@ type_t PJ_type_container_new (const char *name, type_t father)
   return ret;
 }
 
-type_t PJ_type_event_new (const char *name, const char *color, type_t father)
+type_t PJ_type_event_new (const char *name, type_t father)
 {
-  type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
-  if (ret){
-    THROWF(tracing_error, 1, "event type with name %s already exists", name);
+  if (name == NULL){
+    THROWF (tracing_error, 0, "can't create an event type with a NULL name");
   }
 
-  char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
-  if (!color){
-    ret = newType (name, name, white, TYPE_EVENT, father);
-  }else{
-    ret = newType (name, name, color, TYPE_EVENT, father);
-  }
+  type_t ret = newType (name, name, NULL, TYPE_EVENT, father);
   XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
   new_pajeDefineEventType(ret);
   return ret;
@@ -159,11 +149,12 @@ type_t PJ_type_event_new (const char *name, const char *color, type_t father)
 
 type_t PJ_type_variable_new (const char *name, const char *color, type_t father)
 {
-  type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
-  if (ret){
-    THROWF(tracing_error, 1, "variable type with name %s already exists", name);
+  if (name == NULL){
+    THROWF (tracing_error, 0, "can't create a variable type with a NULL name");
   }
 
+  type_t ret = NULL;
+
   char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
   if (!color){
     ret = newType (name, name, white, TYPE_VARIABLE, father);
@@ -177,11 +168,12 @@ type_t PJ_type_variable_new (const char *name, const char *color, type_t father)
 
 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest)
 {
-  type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
-  if (ret){
-    THROWF(tracing_error, 1, "link type with name %s already exists", name);
+  if (name == NULL){
+    THROWF (tracing_error, 0, "can't create a link type with a NULL name");
   }
 
+  type_t ret = NULL;
+
   char key[INSTR_DEFAULT_STR_SIZE];
   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id, dest->id);
   ret = newType (name, key, NULL, TYPE_LINK, father);
@@ -192,11 +184,12 @@ type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t
 
 type_t PJ_type_state_new (const char *name, type_t father)
 {
-  type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
-  if (ret){
-    THROWF(tracing_error, 1, "state type with name %s already exists", name);
+  if (name == NULL){
+    THROWF (tracing_error, 0, "can't create a state type with a NULL name");
   }
 
+  type_t ret = NULL;
+
   ret = newType (name, name, NULL, TYPE_STATE, father);
   XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
   new_pajeDefineStateType(ret);