AERA
settings.h
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ AERA
4 //_/_/ Autocatalytic Endogenous Reflective Architecture
5 //_/_/
6 //_/_/ Copyright (c) 2018-2025 Jeff Thompson
7 //_/_/ Copyright (c) 2018-2025 Kristinn R. Thorisson
8 //_/_/ Copyright (c) 2018-2025 Icelandic Institute for Intelligent Machines
9 //_/_/ http://www.iiim.is
10 //_/_/
11 //_/_/ Copyright (c) 2010-2012 Eric Nivel
12 //_/_/ Center for Analysis and Design of Intelligent Agents
13 //_/_/ Reykjavik University, Menntavegur 1, 102 Reykjavik, Iceland
14 //_/_/ http://cadia.ru.is
15 //_/_/
16 //_/_/ Part of this software was developed by Eric Nivel
17 //_/_/ in the HUMANOBS EU research project, which included
18 //_/_/ the following parties:
19 //_/_/
20 //_/_/ Autonomous Systems Laboratory
21 //_/_/ Technical University of Madrid, Spain
22 //_/_/ http://www.aslab.org/
23 //_/_/
24 //_/_/ Communicative Machines
25 //_/_/ Edinburgh, United Kingdom
26 //_/_/ http://www.cmlabs.com/
27 //_/_/
28 //_/_/ Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
29 //_/_/ University of Lugano and SUPSI, Switzerland
30 //_/_/ http://www.idsia.ch/
31 //_/_/
32 //_/_/ Institute of Cognitive Sciences and Technologies
33 //_/_/ Consiglio Nazionale delle Ricerche, Italy
34 //_/_/ http://www.istc.cnr.it/
35 //_/_/
36 //_/_/ Dipartimento di Ingegneria Informatica
37 //_/_/ University of Palermo, Italy
38 //_/_/ http://diid.unipa.it/roboticslab/
39 //_/_/
40 //_/_/
41 //_/_/ --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
42 //_/_/
43 //_/_/ Redistribution and use in source and binary forms, with or without
44 //_/_/ modification, is permitted provided that the following conditions
45 //_/_/ are met:
46 //_/_/ - Redistributions of source code must retain the above copyright
47 //_/_/ and collaboration notice, this list of conditions and the
48 //_/_/ following disclaimer.
49 //_/_/ - Redistributions in binary form must reproduce the above copyright
50 //_/_/ notice, this list of conditions and the following disclaimer
51 //_/_/ in the documentation and/or other materials provided with
52 //_/_/ the distribution.
53 //_/_/
54 //_/_/ - Neither the name of its copyright holders nor the names of its
55 //_/_/ contributors may be used to endorse or promote products
56 //_/_/ derived from this software without specific prior
57 //_/_/ written permission.
58 //_/_/
59 //_/_/ - CADIA Clause: The license granted in and to the software
60 //_/_/ under this agreement is a limited-use license.
61 //_/_/ The software may not be used in furtherance of:
62 //_/_/ (i) intentionally causing bodily injury or severe emotional
63 //_/_/ distress to any person;
64 //_/_/ (ii) invading the personal privacy or violating the human
65 //_/_/ rights of any person; or
66 //_/_/ (iii) committing or preparing for any act of war.
67 //_/_/
68 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
69 //_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
70 //_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
71 //_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72 //_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
73 //_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
74 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
75 //_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
76 //_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
77 //_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
78 //_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
79 //_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
81 //_/_/ OF SUCH DAMAGE.
82 //_/_/
83 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
84 
85 #ifndef settings_h
86 #define settings_h
87 
88 #include "../submodules/CoreLibrary/CoreLibrary/xml_parser.h"
89 
90 
91 class Settings {
92 public:
93  // IO Device.
94  std::string io_device_;
95 
96  // Load.
97  std::string usr_operator_path_;
98  std::string usr_class_path_;
99  std::string source_file_name_;
100 
101  // Init.
102  core::uint32 base_period_;
103  core::uint32 reduction_core_count_;
104  core::uint32 time_core_count_;
105 
106  // System.
107  core::float32 mdl_inertia_sr_thr_;
108  core::uint32 mdl_inertia_cnt_thr_;
109  core::float32 tpx_dsr_thr_;
110  core::uint32 min_sim_time_horizon_;
111  core::uint32 max_sim_time_horizon_;
112  core::float32 sim_time_horizon_factor_;
113  core::uint32 tpx_time_horizon_;
114  core::uint32 perf_sampling_period_;
115  core::float32 float_tolerance_;
116  core::uint32 time_tolerance_;
117  core::uint64 primary_thz_;
118  core::uint64 secondary_thz_;
119 
120  // Debug.
121  bool debug_;
122  core::uint32 ntf_mk_resilience_;
123  core::uint32 goal_pred_success_resilience_;
124  core::uint32 debug_windows_;
125  std::string runtime_output_file_path_;
126  core::uint32 trace_levels_;
127  bool get_objects_;
128  bool keep_invalidated_objects_;
129  bool decompile_objects_;
130  bool decompile_to_file_;
131  std::string decompilation_file_path_;
132  bool ignore_named_objects_;
133  bool write_objects_;
134  std::string objects_path_;
135  bool test_objects_;
136 
137  //Run.
138  core::uint32 run_time_;
139  core::uint32 probe_level_;
140  bool get_models_;
141  bool decompile_models_;
142  bool ignore_named_models_;
143  bool write_models_;
144  std::string models_path_;
145  bool test_models_;
146 
147  //TCPConfiguration
148  int number_of_servers_;
149  int number_of_clients_;
150  std::vector<std::pair<std::string, std::string> > server_configurations_;
151  std::vector<std::string> client_configurations_;
152 
153  bool load(const char *file_name) {
154 
155  core::XMLNode mainNode = core::XMLNode::openFileHelper(file_name, "AERAConfiguration");
156  if (!mainNode) {
157 
158  std::cerr << "> Error: AERAConfiguration is unreadable" << std::endl;
159  return false;
160  }
161 
162  core::XMLNode mem = mainNode.getChildNode("IODevice");
163  if (!!mem) {
164  io_device_ = mem.getAttribute("io_device");
165  }
166  else {
167  std::cerr << "> Error: Mem section is unreadable" << std::endl;
168  return false;
169  }
170 
171  core::XMLNode load = mainNode.getChildNode("Load");
172  if (!!load) {
173 
174  usr_operator_path_ = load.getAttribute("usr_operator_path");
175  usr_class_path_ = load.getAttribute("usr_class_path");
176  source_file_name_ = load.getAttribute("source_file_name");
177  } else {
178 
179  std::cerr << "> Error: Load section is unreadable" << std::endl;
180  return false;
181  }
182 
183  core::XMLNode init = mainNode.getChildNode("Init");
184  if (!!init) {
185 
186  const char *base_period = init.getAttribute("base_period");
187  const char *reduction_core_count = init.getAttribute("reduction_core_count");
188  const char *time_core_count = init.getAttribute("time_core_count");
189 
190  base_period_ = atoi(base_period);
191  reduction_core_count_ = atoi(reduction_core_count);
192  time_core_count_ = atoi(time_core_count);
193  } else {
194 
195  std::cerr << "> Error: Init section is unreadable" << std::endl;
196  return false;
197  }
198 
199  core::XMLNode system = mainNode.getChildNode("System");
200  if (!!system) {
201 
202  const char *mdl_inertia_sr_thr = system.getAttribute("mdl_inertia_sr_thr");
203  const char *mdl_inertia_cnt_thr = system.getAttribute("mdl_inertia_cnt_thr");
204  const char *tpx_dsr_thr = system.getAttribute("tpx_dsr_thr");
205  const char *min_sim_time_horizon = system.getAttribute("min_sim_time_horizon");
206  const char *max_sim_time_horizon = system.getAttribute("max_sim_time_horizon");
207  const char *sim_time_horizon_factor = system.getAttribute("sim_time_horizon_factor");
208  const char *tpx_time_horizon = system.getAttribute("tpx_time_horizon");
209  const char *perf_sampling_period = system.getAttribute("perf_sampling_period");
210  const char *float_tolerance = system.getAttribute("float_tolerance");
211  const char *time_tolerance = system.getAttribute("time_tolerance");
212  const char *primary_thz = system.getAttribute("primary_thz");
213  const char *secondary_thz = system.getAttribute("secondary_thz");
214 
215  mdl_inertia_sr_thr_ = atof(mdl_inertia_sr_thr);
216  mdl_inertia_cnt_thr_ = atoi(mdl_inertia_cnt_thr);
217  tpx_dsr_thr_ = atof(tpx_dsr_thr);
218  min_sim_time_horizon_ = atoi(min_sim_time_horizon);
219  max_sim_time_horizon_ = atoi(max_sim_time_horizon);
220  sim_time_horizon_factor_ = atof(sim_time_horizon_factor);
221  tpx_time_horizon_ = atoi(tpx_time_horizon);
222  perf_sampling_period_ = atoi(perf_sampling_period);
223  float_tolerance_ = atof(float_tolerance);
224  time_tolerance_ = atoi(time_tolerance);
225  primary_thz_ = atoi(primary_thz);
226  secondary_thz_ = atoi(secondary_thz);
227  } else {
228 
229  std::cerr << "> Error: System section is unreadable" << std::endl;
230  return false;
231  }
232 
233  core::XMLNode debug = mainNode.getChildNode("Debug");
234  if (!!debug) {
235 
236  const char *debug_string = debug.getAttribute("debug");
237  const char *debug_windows = debug.getAttribute("debug_windows");
238  const char *runtime_output_file_path = debug.getAttribute("runtime_output_file_path");
239  const char *trace_levels = debug.getAttribute("trace_levels");
240 
241  debug_ = (strcmp(debug_string, "yes") == 0);
242  debug_windows_ = atoi(debug_windows);
243  runtime_output_file_path_ = runtime_output_file_path;
244  sscanf(trace_levels, "%x", &trace_levels_);
245 
246  core::XMLNode resilience = debug.getChildNode("Resilience");
247  if (!!resilience) {
248 
249  const char *ntf_mk_resilience = resilience.getAttribute("ntf_mk_resilience");
250  const char *goal_pred_success_resilience = resilience.getAttribute("goal_pred_success_resilience");
251 
252  ntf_mk_resilience_ = atoi(ntf_mk_resilience);
253  goal_pred_success_resilience_ = atoi(goal_pred_success_resilience);
254  } else {
255 
256  std::cerr << "> Error: Debug/Resilience section is unreadable" << std::endl;
257  return false;
258  }
259  core::XMLNode objects = debug.getChildNode("Objects");
260  if (!!objects) {
261 
262  const char *get_objects = objects.getAttribute("get_objects");
263  const char *keep_invalidated_objects = objects.getAttribute("keep_invalidated_objects");
264  const char *decompile_objects = objects.getAttribute("decompile_objects");
265  const char *decompile_to_file = objects.getAttribute("decompile_to_file");
266  decompilation_file_path_ = objects.getAttribute("decompilation_file_path");
267  const char *ignore_named_objects = objects.getAttribute("ignore_named_objects");
268  const char *write_objects = objects.getAttribute("write_objects");
269  const char *test_objects = objects.getAttribute("test_objects");
270 
271  get_objects_ = (strcmp(get_objects, "yes") == 0);
272  keep_invalidated_objects_ = (strcmp(keep_invalidated_objects, "yes") == 0);
273  decompile_objects_ = (strcmp(decompile_objects, "yes") == 0);
274  decompile_to_file_ = (strcmp(decompile_to_file, "yes") == 0);
275  ignore_named_objects_ = (strcmp(ignore_named_objects, "yes") == 0);
276  write_objects_ = (strcmp(write_objects, "yes") == 0);
277  if (write_objects_) {
278 
279  objects_path_ = objects.getAttribute("objects_path");
280  test_objects_ = (strcmp(test_objects, "yes") == 0);
281  }
282  } else {
283 
284  std::cerr << "> Error: Debug/Objects section is unreadable" << std::endl;
285  return false;
286  }
287  } else {
288 
289  std::cerr << "> Error: Debug section is unreadable" << std::endl;
290  return false;
291  }
292 
293  core::XMLNode run = mainNode.getChildNode("Run");
294  if (!!run) {
295 
296  const char *run_time = run.getAttribute("run_time");
297  const char *probe_level = run.getAttribute("probe_level");
298 
299  run_time_ = atoi(run_time);
300  probe_level_ = atoi(probe_level);
301 
302  core::XMLNode models = run.getChildNode("Models");
303  if (!!models) {
304 
305  const char *get_models = models.getAttribute("get_models");
306  const char *decompile_models = models.getAttribute("decompile_models");
307  const char *ignore_named_models = models.getAttribute("ignore_named_models");
308  const char *write_models = models.getAttribute("write_models");
309  const char *test_models = models.getAttribute("test_models");
310 
311  get_models_ = (strcmp(get_models, "yes") == 0);
312  decompile_models_ = (strcmp(decompile_models, "yes") == 0);
313  ignore_named_models_ = (strcmp(ignore_named_models, "yes") == 0);
314  write_models_ = (strcmp(write_models, "yes") == 0);
315  if (write_models_) {
316 
317  models_path_ = models.getAttribute("models_path");
318  test_models_ = (strcmp(test_models, "yes") == 0);
319  }
320  } else {
321 
322  std::cerr << "> Error: Run/Models section is unreadable" << std::endl;
323  return false;
324  }
325  } else {
326 
327  std::cerr << "> Error: Run section is unreadable" << std::endl;
328  return false;
329  }
330 
331  core::XMLNode tcpConfiguration = mainNode.getChildNode("TCPConfiguration");
332 
333  if (!tcpConfiguration) {
334 
335  if (io_device_.compare("tcp_io_device") == 0) {
336 
337  std::cerr << "> Error: Using IODevice tcp_io_device without specifying TCPConfiguration in settings.xml" << std::endl;
338  return false;
339  }
340 
341  return true;
342  }
343 
344  const char* number_of_servers = tcpConfiguration.getAttribute("number_of_servers");
345  const char* number_of_clients = tcpConfiguration.getAttribute("number_of_clients");
346 
347  number_of_servers_ = atoi(number_of_servers);
348  number_of_clients_ = atoi(number_of_clients);
349 
350  std::string server_configurations = tcpConfiguration.getAttribute("server_configurations");
351  std::string client_configurations = tcpConfiguration.getAttribute("client_configurations");
352 
353  size_t last = 0;
354  size_t next = server_configurations.find(",", last);
355  do
356  {
357  std::string current;
358  if (next == std::string::npos) {
359  current = server_configurations.substr(last);
360  }
361  else
362  {
363  current = server_configurations.substr(last, next - last);
364  }
365  size_t colon = current.find(":", 0);
366  std::string ipAdress = current.substr(0, colon);
367  std::string port = current.substr(colon + 1);
368  server_configurations_.push_back(std::make_pair(ipAdress, port));
369  last = next + 1;
370  } while ((next = server_configurations.find(",", last)) != std::string::npos);
371 
372 
373 
374  last = 0;
375  next = client_configurations.find(",", last);
376  do
377  {
378  std::string port;
379  if (next == std::string::npos) {
380  port = client_configurations.substr(last);
381  }
382  else
383  {
384  port = client_configurations.substr(last, next - last);
385  }
386  client_configurations_.push_back(port);
387  last = next + 1;
388  } while ((next = client_configurations.find(",", last)) != std::string::npos);
389 
390  return true;
391  }
392 };
393 
394 
395 #endif
Settings
Definition: settings.h:91
core::XMLNode
Definition: xml_parser.h:172