Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into adrien
[simgrid.git] / src / kernel / EngineImpl.hpp
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 #ifndef SIMGRID_KERNEL_ENGINEIMPL_HPP
7 #define SIMGRID_KERNEL_ENGINEIMPL_HPP
8
9 #include <simgrid/s4u/Engine.hpp>
10 #include <simgrid/s4u/NetZone.hpp>
11 #include <simgrid/simix.hpp>
12
13 #include <map>
14 #include <string>
15 #include <unordered_map>
16
17 namespace simgrid {
18 namespace kernel {
19
20 class EngineImpl {
21   std::map<std::string, s4u::Host*> hosts_;
22   std::map<std::string, resource::LinkImpl*> links_;
23   std::map<std::string, resource::StorageImpl*> storages_;
24   std::unordered_map<std::string, routing::NetPoint*> netpoints_;
25   std::unordered_map<std::string, actor::ActorCodeFactory> registered_functions; // Maps function names to actor code
26   actor::ActorCodeFactory default_function; // Function to use as a fallback when the provided name matches nothing
27
28   friend s4u::Engine;
29
30 public:
31   EngineImpl() = default;
32
33   EngineImpl(const EngineImpl&) = delete;
34   EngineImpl& operator=(const EngineImpl&) = delete;
35   virtual ~EngineImpl();
36
37   void load_deployment(const std::string& file) const;
38   void register_function(const std::string& name, const actor::ActorCodeFactory& code);
39   void register_default(const actor::ActorCodeFactory& code);
40
41   routing::NetZoneImpl* netzone_root_ = nullptr;
42   static EngineImpl* get_instance() { return simgrid::s4u::Engine::get_instance()->pimpl; }
43   actor::ActorCodeFactory get_function(const std::string& name)
44   {
45     auto res = registered_functions.find(name);
46     if (res == registered_functions.end())
47       return default_function;
48     else
49       return res->second;
50   }
51 };
52
53 } // namespace kernel
54 } // namespace simgrid
55
56 #endif