1 /* Copyright (c) 2012, 2014-2015. 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. */
7 #include "src/instr/instr_private.h"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
11 static type_t rootType = nullptr; /* the root type */
17 void PJ_type_release ()
22 type_t PJ_type_get_root ()
27 static type_t newType (const char *typeNameBuff, const char *key, const char *color, e_entity_types kind, type_t father)
29 if (typeNameBuff == nullptr || key == nullptr){
30 THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
33 type_t ret = xbt_new0(s_type_t, 1);
34 ret->name = xbt_strdup (typeNameBuff);
37 ret->children = xbt_dict_new_homogeneous(nullptr);
38 ret->values = xbt_dict_new_homogeneous(nullptr);
39 ret->color = xbt_strdup (color);
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);
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);
52 void PJ_type_free (type_t type)
56 xbt_dict_cursor_t cursor = nullptr;
57 xbt_dict_foreach(type->values, cursor, value_name, value) {
58 PJ_value_free (value);
60 xbt_dict_free (&type->values);
61 xbt_free (type->name);
63 xbt_free (type->color);
64 xbt_dict_free (&type->children);
69 static void recursiveDestroyType (type_t type)
71 XBT_DEBUG("recursiveDestroyType %s", type->name);
72 xbt_dict_cursor_t cursor = nullptr;
75 xbt_dict_foreach(type->children, cursor, child_name, child) {
76 recursiveDestroyType (child);
81 void PJ_type_free_all ()
83 recursiveDestroyType (PJ_type_get_root());
87 type_t PJ_type_get (const char *name, type_t father)
89 type_t ret = PJ_type_get_or_null (name, father);
91 THROWF (tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name);
96 type_t PJ_type_get_or_null (const char *name, type_t father)
98 if (name == nullptr || father == nullptr){
99 THROWF (tracing_error, 0, "can't get type with a nullptr name or from a nullptr father");
102 type_t ret = nullptr;
105 xbt_dict_cursor_t cursor = nullptr;
106 xbt_dict_foreach(father->children, cursor, child_name, child) {
107 if (strcmp (child->name, name) == 0){
109 THROWF (tracing_error, 0, "there are two children types with the same name?");
118 type_t PJ_type_container_new (const char *name, type_t father)
120 if (name == nullptr){
121 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
124 type_t ret = nullptr;
126 ret = newType (name, name, nullptr, TYPE_CONTAINER, father);
127 if (father == nullptr){
132 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
133 new DefineContainerEvent(ret);
138 type_t PJ_type_event_new (const char *name, type_t father)
140 if (name == nullptr){
141 THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
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);
150 type_t PJ_type_variable_new (const char *name, const char *color, type_t father)
152 if (name == nullptr){
153 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
156 type_t ret = nullptr;
158 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
160 ret = newType (name, name, white, TYPE_VARIABLE, father);
162 ret = newType (name, name, color, TYPE_VARIABLE, father);
164 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
165 new DefineVariableTypeEvent (ret);
169 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest)
171 if (name == nullptr){
172 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
175 type_t ret = nullptr;
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 new DefineLinkTypeEvent(ret, source, dest);
186 type_t PJ_type_state_new (const char *name, type_t father)
188 if (name == nullptr){
189 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
192 type_t ret = nullptr;
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 new DefineStateTypeEvent(ret);