1 /* s4u::Engine Simulation Engine and global functions. */
3 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "instr/instr_interface.h"
9 #include "simgrid/simix.h"
11 #include "simgrid/s4u/As.hpp"
12 #include "simgrid/s4u/engine.hpp"
13 #include "simgrid/s4u/Mailbox.hpp"
14 #include "simgrid/s4u/storage.hpp"
15 #include "simgrid/simix.h"
16 #include "src/kernel/EngineImpl.hpp"
18 #include "surf/surf.h" // routing_platf. FIXME:KILLME. SOON
19 #include "src/surf/surf_routing.hpp" // routing_platf. FIXME:KILLME. SOON
21 XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface");
26 Engine *Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */
29 Engine::Engine(int *argc, char **argv) {
30 xbt_assert(s4u::Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine");
31 s4u::Engine::instance_ = this;
32 pimpl = new kernel::EngineImpl();
34 TRACE_global_init(argc, argv);
35 SIMIX_global_init(argc, argv);
38 Engine *Engine::instance() {
39 if (s4u::Engine::instance_ == nullptr)
40 new Engine(0,nullptr);
41 return s4u::Engine::instance_;
44 void Engine::shutdown() {
45 delete s4u::Engine::instance_;
46 s4u::Engine::instance_ = nullptr;
47 delete s4u::Storage::storages_;
50 double Engine::getClock()
52 return SIMIX_get_clock();
55 void Engine::loadPlatform(const char *platf)
57 SIMIX_create_environment(platf);
60 void Engine::registerFunction(const char*name, int (*code)(int,char**))
62 SIMIX_function_register(name,code);
64 void Engine::registerDefault(int (*code)(int,char**))
66 SIMIX_function_register_default(code);
68 void Engine::loadDeployment(const char *deploy)
70 SIMIX_launch_application(deploy);
81 s4u::As *Engine::rootAs()
83 return routing_platf->root_; // FIXME: get the root into the Engine directly (and kill the platf)
84 // return pimpl->rootAs_;
87 static s4u::As *asByNameRecursive(s4u::As *current, const char *name)
89 if(!strcmp(current->name(), name))
92 xbt_dict_cursor_t cursor = nullptr;
95 xbt_dict_foreach(current->children(), cursor, key, elem) {
96 simgrid::s4u::As *tmp = asByNameRecursive(elem, name);
103 /** @brief Retrieve the AS of the given name (or nullptr if not found) */
104 As *Engine::asByNameOrNull(const char *name) {
105 return asByNameRecursive(rootAs(),name);