1 /* Copyright (c) 2012, 2014-2017. 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* rootType = nullptr; /* the root type */
13 void PJ_type_release ()
18 type_t PJ_type_get_root ()
23 Type::Type (const char *typeNameBuff, const char *key, const char *color, e_entity_types kind, Type* father)
25 if (typeNameBuff == nullptr || key == nullptr){
26 THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
29 this->name = xbt_strdup (typeNameBuff);
30 this->father = father;
32 this->children = xbt_dict_new_homogeneous(nullptr);
33 this->values = xbt_dict_new_homogeneous(nullptr);
34 this->color = xbt_strdup (color);
36 char str_id[INSTR_DEFAULT_STR_SIZE];
37 snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
38 this->id = xbt_strdup (str_id);
40 if (father != nullptr){
41 xbt_dict_set (father->children, key, this, nullptr);
42 XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name);
46 void PJ_type_free (type_t type)
50 xbt_dict_cursor_t cursor = nullptr;
51 xbt_dict_foreach (type->values, cursor, value_name, val) {
52 XBT_DEBUG("free value %s, child of %s", val->name, val->father->name);
55 xbt_dict_free (&type->values);
56 xbt_free (type->name);
58 xbt_free (type->color);
59 xbt_dict_free (&type->children);
64 void recursiveDestroyType (type_t type)
66 XBT_DEBUG("recursiveDestroyType %s", type->name);
67 xbt_dict_cursor_t cursor = nullptr;
70 xbt_dict_foreach(type->children, cursor, child_name, child) {
71 recursiveDestroyType (child);
76 type_t PJ_type_get (const char *name, Type* father)
78 Type* ret = Type::getOrNull (name, father);
80 THROWF (tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name);
85 type_t Type::getOrNull (const char *name, Type* father)
87 if (name == nullptr || father == nullptr){
88 THROWF (tracing_error, 0, "can't get type with a nullptr name or from a nullptr father");
94 xbt_dict_cursor_t cursor = nullptr;
95 xbt_dict_foreach(father->children, cursor, child_name, child) {
96 if (strcmp (child->name, name) == 0){
98 THROWF (tracing_error, 0, "there are two children types with the same name?");
107 type_t Type::containerNew (const char *name, Type* father)
109 if (name == nullptr){
110 THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
113 Type* ret = new Type (name, name, nullptr, TYPE_CONTAINER, father);
114 if (father == nullptr) {
117 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
118 DefineContainerEvent(ret);
123 type_t Type::eventNew (const char *name, Type* father)
125 if (name == nullptr){
126 THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
129 Type* ret = new Type (name, name, nullptr, TYPE_EVENT, father);
130 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
131 LogDefineEventType(ret);
135 type_t Type::variableNew (const char *name, const char *color, Type* father)
137 if (name == nullptr){
138 THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
144 char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
145 ret = new Type (name, name, white, TYPE_VARIABLE, father);
147 ret = new Type (name, name, color, TYPE_VARIABLE, father);
149 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
150 LogVariableTypeDefinition (ret);
154 type_t Type::linkNew (const char *name, Type* father, Type* source, Type* dest)
156 if (name == nullptr){
157 THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
162 char key[INSTR_DEFAULT_STR_SIZE];
163 snprintf (key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id, dest->id);
164 ret = new Type (name, key, nullptr, TYPE_LINK, father);
165 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->name, ret->id, father->name, father->id,
166 source->name, source->id, dest->name, dest->id);
167 LogLinkTypeDefinition(ret, source, dest);
171 type_t Type::stateNew (const char *name, Type* father)
173 if (name == nullptr){
174 THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
179 ret = new Type (name, name, nullptr, TYPE_STATE, father);
180 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
181 LogStateTypeDefinition(ret);