Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove useless XBT_DEBUG
[simgrid.git] / src / instr / instr_paje_types.cpp
1 /* Copyright (c) 2012, 2014-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "src/instr/instr_private.h"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
10
11 static type_t rootType = nullptr;        /* the root type */
12
13 void PJ_type_alloc ()
14 {
15 }
16
17 void PJ_type_release ()
18 {
19   rootType = nullptr;
20 }
21
22 type_t PJ_type_get_root ()
23 {
24   return rootType;
25 }
26
27 static type_t newType (const char *typeNameBuff, const char *key, const char *color, e_entity_types kind, type_t father)
28 {
29   if (typeNameBuff == nullptr || key == nullptr){
30     THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
31   }
32
33   type_t ret = xbt_new0(s_type_t, 1);
34   ret->name = xbt_strdup (typeNameBuff);
35   ret->father = father;
36   ret->kind = kind;
37   ret->children = xbt_dict_new_homogeneous(nullptr);
38   ret->values = xbt_dict_new_homogeneous(nullptr);
39   ret->color = xbt_strdup (color);
40
41   char str_id[INSTR_DEFAULT_STR_SIZE];
42   snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
43   ret->id = xbt_strdup (str_id);
44
45   if (father != nullptr){
46     xbt_dict_set (father->children, key, ret, nullptr);
47     XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name);
48   }
49   return ret;
50 }
51
52 void PJ_type_free (type_t type)
53 {
54   val_t value;
55   char *value_name;
56   xbt_dict_cursor_t cursor = nullptr;
57   xbt_dict_foreach(type->values, cursor, value_name, value) {
58     PJ_value_free (value);
59   }
60   xbt_dict_free (&type->values);
61   xbt_free (type->name);
62   xbt_free (type->id);
63   xbt_free (type->color);
64   xbt_dict_free (&type->children);
65   xbt_free (type);
66   type = nullptr;
67 }
68
69 static void recursiveDestroyType (type_t type)
70 {
71   XBT_DEBUG("recursiveDestroyType %s", type->name);
72   xbt_dict_cursor_t cursor = nullptr;
73   type_t child;
74   char *child_name;
75   xbt_dict_foreach(type->children, cursor, child_name, child) {
76     recursiveDestroyType (child);
77   }
78   PJ_type_free(type);
79 }
80
81 void PJ_type_free_all ()
82 {
83   recursiveDestroyType (PJ_type_get_root());
84   rootType = nullptr;
85 }
86
87 type_t PJ_type_get (const char *name, type_t father)
88 {
89   type_t ret = PJ_type_get_or_null (name, father);
90   if (ret == nullptr){
91     THROWF (tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name);
92   }
93   return ret;
94 }
95
96 type_t PJ_type_get_or_null (const char *name, type_t father)
97 {
98   if (name == nullptr || father == nullptr){
99     THROWF (tracing_error, 0, "can't get type with a nullptr name or from a nullptr father");
100   }
101
102   type_t ret = nullptr;
103   type_t child;
104   char *child_name;
105   xbt_dict_cursor_t cursor = nullptr;
106   xbt_dict_foreach(father->children, cursor, child_name, child) {
107     if (strcmp (child->name, name) == 0){
108       if (ret != nullptr){
109         THROWF (tracing_error, 0, "there are two children types with the same name?");
110       }else{
111         ret = child;
112       }
113     }
114   }
115   return ret;
116 }
117
118 type_t PJ_type_container_new (const char *name, type_t father)
119 {
120   if (name == nullptr){
121     THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
122   }
123
124   type_t ret = nullptr;
125
126   ret = newType (name, name, nullptr, TYPE_CONTAINER, father);
127   if (father == nullptr){
128     rootType = ret;
129   }
130
131   if(father){
132     XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
133     DefineContainerEvent(ret);
134   }
135   return ret;
136 }
137
138 type_t PJ_type_event_new (const char *name, type_t father)
139
140   if (name == nullptr){
141     THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
142   }
143
144   type_t ret = newType (name, name, nullptr, TYPE_EVENT, father);
145   XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
146   new DefineEventTypeEvent(ret);
147   return ret;
148 }
149
150 type_t PJ_type_variable_new (const char *name, const char *color, type_t father)
151 {
152   if (name == nullptr){
153     THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
154   }
155
156   type_t ret = nullptr;
157
158   char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
159   if (not color) {
160     ret = newType (name, name, white, TYPE_VARIABLE, father);
161   }else{
162     ret = newType (name, name, color, TYPE_VARIABLE, father);
163   }
164   XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
165   LogVariableTypeDefinition (ret);
166   return ret;
167 }
168
169 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest)
170 {
171   if (name == nullptr){
172     THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
173   }
174
175   type_t ret = nullptr;
176
177   char key[INSTR_DEFAULT_STR_SIZE];
178   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id, dest->id);
179   ret = newType (name, key, nullptr, TYPE_LINK, father);
180   XBT_DEBUG("LinkType %s(%s), child of %s(%s)  %s(%s)->%s(%s)", ret->name, ret->id, father->name, father->id,
181             source->name, source->id, dest->name, dest->id);
182   LogLinkTypeDefinition(ret, source, dest);
183   return ret;
184 }
185
186 type_t PJ_type_state_new (const char *name, type_t father)
187 {
188   if (name == nullptr){
189     THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
190   }
191
192   type_t ret = nullptr;
193
194   ret = newType (name, name, nullptr, TYPE_STATE, father);
195   XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
196   LogStateTypeDefinition(ret);
197   return ret;
198 }