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 type_t ret = xbt_new0(s_type_t, 1);
35 ret->name = xbt_strdup (typename);
38 ret->children = xbt_dict_new_homogeneous(NULL);
39 ret->values = xbt_dict_new_homogeneous(NULL);
40 ret->color = xbt_strdup (color);
42 char str_id[INSTR_DEFAULT_STR_SIZE];
43 snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
44 ret->id = xbt_strdup (str_id);
47 xbt_dict_set (father->children, key, ret, NULL);
48 XBT_DEBUG("new type %s, child of %s", typename, father->name);
51 xbt_dict_set (allTypes, typename, ret, NULL);
55 void PJ_type_free (type_t type)
57 xbt_dict_remove (allTypes, type->name);
61 xbt_dict_cursor_t cursor = NULL;
62 xbt_dict_foreach(type->values, cursor, value_name, value) {
63 PJ_value_free (value);
65 xbt_dict_free (&type->values);
66 xbt_free (type->name);
68 xbt_free (type->color);
69 xbt_dict_free (&type->children);
74 static void recursiveDestroyType (type_t type)
76 XBT_DEBUG("recursiveDestroyType %s", type->name);
77 xbt_dict_cursor_t cursor = NULL;
80 xbt_dict_foreach(type->children, cursor, child_name, child) {
81 recursiveDestroyType (child);
86 void PJ_type_free_all (void)
88 recursiveDestroyType (PJ_type_get_root());
92 if (xbt_dict_length(allTypes) != 0){
93 THROWF(tracing_error, 0, "some types still present even after destroying all of them");
97 static type_t recursiveGetType (const char *name, type_t root)
99 if (strcmp (root->name, name) == 0) return root;
101 xbt_dict_cursor_t cursor = NULL;
105 xbt_dict_foreach(root->children, cursor, child_name, child) {
106 type_t found = recursiveGetType(name, child);
111 THROWF(tracing_error, 0, "found two types with the same name");
118 type_t PJ_type_get (const char *name, type_t father)
120 return recursiveGetType (name, father);
123 type_t PJ_type_container_new (const char *name, type_t father)
125 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
127 THROWF(tracing_error, 1, "container type with name %s already exists", name);
130 ret = newType (name, name, NULL, TYPE_CONTAINER, father);
136 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
137 new_pajeDefineContainerType (ret);
142 type_t PJ_type_event_new (const char *name, const char *color, type_t father)
144 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
146 THROWF(tracing_error, 1, "event type with name %s already exists", name);
149 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
151 ret = newType (name, name, white, TYPE_EVENT, father);
153 ret = newType (name, name, color, TYPE_EVENT, father);
155 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
156 new_pajeDefineEventType(ret);
160 type_t PJ_type_variable_new (const char *name, const char *color, type_t father)
162 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
164 THROWF(tracing_error, 1, "variable type with name %s already exists", name);
167 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
169 ret = newType (name, name, white, TYPE_VARIABLE, father);
171 ret = newType (name, name, color, TYPE_VARIABLE, father);
173 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
174 new_pajeDefineVariableType (ret);
178 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest)
180 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
182 THROWF(tracing_error, 1, "link type with name %s already exists", name);
185 char key[INSTR_DEFAULT_STR_SIZE];
186 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id, dest->id);
187 ret = newType (name, key, NULL, TYPE_LINK, father);
188 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);
189 new_pajeDefineLinkType(ret, source, dest);
193 type_t PJ_type_state_new (const char *name, type_t father)
195 type_t ret = (type_t)xbt_dict_get_or_null (allTypes, name);
197 THROWF(tracing_error, 1, "state type with name %s already exists", name);
200 ret = newType (name, name, NULL, TYPE_STATE, father);
201 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
202 new_pajeDefineStateType(ret);