Logo AND Algorithmique Numérique Distribuée

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