1 /* Copyright (c) 2012. The SimGrid Team.
2 * All rights reserved. */
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 #include "instr/instr_private.h"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
12 static type_t rootType = NULL; /* the root type */
13 static xbt_dict_t allTypes = NULL; /* all declared types indexed by name */
17 allTypes = xbt_dict_new_homogeneous (NULL);
20 void PJ_type_release ()
22 xbt_dict_free (&allTypes);
27 type_t PJ_type_get_root ()
32 static type_t newType (const char *typename, const char *key, const char *color, e_entity_types kind, type_t father)
34 if (typename == NULL || key == NULL){
35 THROWF(tracing_error, 0, "can't create a new type with name or key equal NULL");
38 type_t ret = xbt_new0(s_type_t, 1);
39 ret->name = xbt_strdup (typename);
42 ret->children = xbt_dict_new_homogeneous(NULL);
43 ret->values = xbt_dict_new_homogeneous(NULL);
44 ret->color = xbt_strdup (color);
46 char str_id[INSTR_DEFAULT_STR_SIZE];
47 snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
48 ret->id = xbt_strdup (str_id);
51 xbt_dict_set (father->children, key, ret, NULL);
52 XBT_DEBUG("new type %s, child of %s", typename, father->name);
55 xbt_dict_set (allTypes, typename, ret, NULL);
59 void PJ_type_free (type_t type)
61 xbt_dict_remove (allTypes, type->name);
65 xbt_dict_cursor_t cursor = NULL;
66 xbt_dict_foreach(type->values, cursor, value_name, value) {
67 PJ_value_free (value);
69 xbt_dict_free (&type->values);
70 xbt_free (type->name);
72 xbt_free (type->color);
73 xbt_dict_free (&type->children);
78 static void recursiveDestroyType (type_t type)
80 XBT_DEBUG("recursiveDestroyType %s", type->name);
81 xbt_dict_cursor_t cursor = NULL;
84 xbt_dict_foreach(type->children, cursor, child_name, child) {
85 recursiveDestroyType (child);
90 void PJ_type_free_all (void)
92 recursiveDestroyType (PJ_type_get_root());
96 if (xbt_dict_length(allTypes) != 0){
97 THROWF(tracing_error, 0, "some types still present even after destroying all of them");
101 static type_t recursiveGetType (const char *name, type_t root)
103 if (name == NULL || root == NULL){
104 THROWF (tracing_error, 0, "can't get type with a NULL name (or a NULL father given)");
107 if (strcmp (root->name, name) == 0) return root;
109 xbt_dict_cursor_t cursor = NULL;
113 xbt_dict_foreach(root->children, cursor, child_name, child) {
114 type_t found = recursiveGetType(name, child);
119 THROWF(tracing_error, 0, "found two types with the same name");
126 type_t PJ_type_get (const char *name, type_t father)
128 return recursiveGetType (name, father);
131 type_t PJ_type_container_new (const char *name, type_t father)
134 THROWF (tracing_error, 0, "can't create a container type with a NULL name");
137 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
139 THROWF(tracing_error, 1, "container type with name %s already exists", name);
142 ret = newType (name, name, NULL, TYPE_CONTAINER, father);
148 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
149 new_pajeDefineContainerType (ret);
154 type_t PJ_type_event_new (const char *name, const char *color, type_t father)
157 THROWF (tracing_error, 0, "can't create an event type with a NULL name");
160 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
162 THROWF(tracing_error, 1, "event type with name %s already exists", name);
165 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
167 ret = newType (name, name, white, TYPE_EVENT, father);
169 ret = newType (name, name, color, TYPE_EVENT, father);
171 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
172 new_pajeDefineEventType(ret);
176 type_t PJ_type_variable_new (const char *name, const char *color, type_t father)
179 THROWF (tracing_error, 0, "can't create a variable type with a NULL name");
182 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
184 THROWF(tracing_error, 1, "variable type with name %s already exists", name);
187 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
189 ret = newType (name, name, white, TYPE_VARIABLE, father);
191 ret = newType (name, name, color, TYPE_VARIABLE, father);
193 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
194 new_pajeDefineVariableType (ret);
198 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest)
201 THROWF (tracing_error, 0, "can't create a link type with a NULL name");
204 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
206 THROWF(tracing_error, 1, "link type with name %s already exists", name);
209 char key[INSTR_DEFAULT_STR_SIZE];
210 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id, dest->id);
211 ret = newType (name, key, NULL, TYPE_LINK, father);
212 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->name, ret->id, father->name, father->id, source->name, source->id, dest->name, dest->id);
213 new_pajeDefineLinkType(ret, source, dest);
217 type_t PJ_type_state_new (const char *name, type_t father)
220 THROWF (tracing_error, 0, "can't create a state type with a NULL name");
223 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
225 THROWF(tracing_error, 1, "state type with name %s already exists", name);
228 ret = newType (name, name, NULL, TYPE_STATE, father);
229 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
230 new_pajeDefineStateType(ret);