Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e8c223566dfe49e1ca8c7bede2c386859ab8b62b
[simgrid.git] / src / kernel / EngineImpl.cpp
1 /* Copyright (c) 2016-2020. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/kernel/EngineImpl.hpp"
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/kernel/routing/NetPoint.hpp"
9 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
10 #include "simgrid/s4u/Host.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12 #include "src/simix/smx_private.hpp"
13 #include "src/surf/StorageImpl.hpp"
14 #include "src/surf/network_interface.hpp"
15 #include "src/surf/xml/platf.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
16
17 namespace simgrid {
18 namespace kernel {
19
20 EngineImpl::~EngineImpl()
21 {
22   /* Since hosts_ is a std::map, the hosts are destroyed in the lexicographic order, which ensures that the output is
23    * reproducible.
24    */
25   while (not hosts_.empty())
26     hosts_.begin()->second->destroy();
27
28   /* Also delete the other data */
29   delete netzone_root_;
30   for (auto const& kv : netpoints_)
31     delete kv.second;
32
33   for (auto const& kv : storages_)
34     if (kv.second)
35       kv.second->destroy();
36
37   for (auto const& kv : links_)
38     if (kv.second)
39       kv.second->destroy();
40 }
41
42 void EngineImpl::load_deployment(const std::string& file)
43 {
44   sg_platf_exit();
45   sg_platf_init();
46
47   surf_parse_open(file);
48   surf_parse();
49   surf_parse_close();
50 }
51 void EngineImpl::register_function(const std::string& name, int (*code)(int, char**)) // deprecated
52 {
53   simix_global->registered_functions[name] = [code](std::vector<std::string> args) {
54     return xbt::wrap_main(code, std::move(args));
55   };
56 }
57 void EngineImpl::register_function(const std::string& name, xbt_main_func_t code)
58 {
59   simix_global->registered_functions[name] = [code](std::vector<std::string> args) {
60     return xbt::wrap_main(code, std::move(args));
61   };
62 }
63
64 void EngineImpl::register_function(const std::string& name, void (*code)(std::vector<std::string>))
65 {
66   simix_global->registered_functions[name] = [code](std::vector<std::string> args) {
67     return std::bind(std::move(code), std::move(args));
68   };
69 }
70
71 void EngineImpl::register_default(int (*code)(int, char**)) // deprecated
72 {
73   simix_global->default_function = [code](std::vector<std::string> args) {
74     return xbt::wrap_main(code, std::move(args));
75   };
76 }
77 void EngineImpl::register_default(xbt_main_func_t code)
78 {
79   simix_global->default_function = [code](std::vector<std::string> args) {
80     return xbt::wrap_main(code, std::move(args));
81   };
82 }
83
84 } // namespace kernel
85 } // namespace simgrid