Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove useless parameters in header generation
[simgrid.git] / src / instr / instr_paje_types.cpp
1 /* Copyright (c) 2012, 2014-2017. 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 simgrid::instr::Type* rootType = nullptr; /* the root type */
12
13 simgrid::instr::Type* PJ_type_get_root()
14 {
15   return rootType;
16 }
17
18 simgrid::instr::Type::Type(const char* typeNameBuff, const char* key, const char* color, e_entity_types kind,
19                            Type* father)
20     : kind_(kind), father_(father)
21 {
22   if (typeNameBuff == nullptr || key == nullptr){
23     THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
24   }
25
26   this->name_     = xbt_strdup(typeNameBuff);
27   this->children_ = xbt_dict_new_homogeneous(nullptr);
28   this->values_   = xbt_dict_new_homogeneous(nullptr);
29   this->color_    = xbt_strdup(color);
30
31   this->id_ = bprintf("%lld", instr_new_paje_id());
32
33   if (father != nullptr){
34     xbt_dict_set(father->children_, key, this, nullptr);
35     XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name_);
36   }
37 }
38
39 simgrid::instr::Type::~Type()
40 {
41   simgrid::instr::Value* val;
42   char *value_name;
43   xbt_dict_cursor_t cursor = nullptr;
44   xbt_dict_foreach (values_, cursor, value_name, val) {
45     XBT_DEBUG("free value %s, child of %s", val->name_, val->father_->name_);
46     delete val;
47   }
48   xbt_dict_free(&values_);
49   simgrid::instr::Type* child;
50   char *child_name;
51   xbt_dict_foreach (children_, cursor, child_name, child) {
52     delete child;
53   }
54   xbt_dict_free(&children_);
55   xbt_free(name_);
56   xbt_free(id_);
57   xbt_free(color_);
58 }
59
60 simgrid::instr::Type* simgrid::instr::Type::getChild(const char* name)
61 {
62   simgrid::instr::Type* ret = this->getChildOrNull(name);
63   if (ret == nullptr)
64     THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name, this->name_);
65   return ret;
66 }
67
68 simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(const char* name)
69 {
70   xbt_assert(name != nullptr, "can't get type with a nullptr name");
71
72   simgrid::instr::Type* ret = nullptr;
73   simgrid::instr::Type* child;
74   char *child_name;
75   xbt_dict_cursor_t cursor = nullptr;
76   xbt_dict_foreach (children_, cursor, child_name, child) {
77     if (strcmp(child->name_, name) == 0) {
78       if (ret != nullptr) {
79         THROWF (tracing_error, 0, "there are two children types with the same name?");
80       } else {
81         ret = child;
82       }
83     }
84   }
85   return ret;
86 }
87
88 simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgrid::instr::Type* father)
89 {
90   if (name == nullptr){
91     THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
92   }
93
94   simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, nullptr, TYPE_CONTAINER, father);
95   if (father == nullptr) {
96     rootType = ret;
97   } else {
98     XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
99     LogContainerTypeDefinition(ret);
100   }
101   return ret;
102 }
103
104 simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid::instr::Type* father)
105 {
106   if (name == nullptr){
107     THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
108   }
109
110   Type* ret = new Type (name, name, nullptr, TYPE_EVENT, father);
111   XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
112   LogDefineEventType(ret);
113   return ret;
114 }
115
116 simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, const char* color,
117                                                         simgrid::instr::Type* father)
118 {
119   if (name == nullptr){
120     THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
121   }
122
123   Type* ret = nullptr;
124
125   if (not color) {
126     char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
127     ret = new Type (name, name, white, TYPE_VARIABLE, father);
128   }else{
129     ret = new Type (name, name, color, TYPE_VARIABLE, father);
130   }
131   XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
132   LogVariableTypeDefinition (ret);
133   return ret;
134 }
135
136 simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
137 {
138   if (name == nullptr){
139     THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
140   }
141
142   char key[INSTR_DEFAULT_STR_SIZE];
143   snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->id_, dest->id_);
144   Type* ret = new Type(name, key, nullptr, TYPE_LINK, father);
145   XBT_DEBUG("LinkType %s(%s), child of %s(%s)  %s(%s)->%s(%s)", ret->name_, ret->id_, father->name_, father->id_,
146             source->name_, source->id_, dest->name_, dest->id_);
147   LogLinkTypeDefinition(ret, source, dest);
148   return ret;
149 }
150
151 simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* father)
152 {
153   if (name == nullptr){
154     THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
155   }
156
157   Type* ret = new Type(name, name, nullptr, TYPE_STATE, father);
158   XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name_, ret->id_, father->name_, father->id_);
159   LogStateTypeDefinition(ret);
160   return ret;
161 }