Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a const reference for parameter.
[simgrid.git] / src / kernel / EngineImpl.hpp
1 /* Copyright (c) 2016-2021. 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/kernel/resource/Model.hpp>
10 #include <simgrid/s4u/Engine.hpp>
11 #include <simgrid/s4u/NetZone.hpp>
12 #include <simgrid/simix.hpp>
13
14 #include <map>
15 #include <string>
16 #include <unordered_map>
17
18 namespace simgrid {
19 namespace kernel {
20
21 class EngineImpl {
22   std::map<std::string, s4u::Host*, std::less<>> hosts_;
23   std::map<std::string, resource::LinkImpl*, std::less<>> links_;
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   std::vector<resource::Model*> models_;
28   struct ModelStruct {
29     int prio;
30     std::shared_ptr<resource::Model> ptr;
31   };
32   std::unordered_map<std::string, struct ModelStruct> models_prio_;
33   routing::NetZoneImpl* netzone_root_ = nullptr;
34
35   friend s4u::Engine;
36
37 public:
38   EngineImpl() = default;
39
40   EngineImpl(const EngineImpl&) = delete;
41   EngineImpl& operator=(const EngineImpl&) = delete;
42   virtual ~EngineImpl();
43
44   void load_deployment(const std::string& file) const;
45   void register_function(const std::string& name, const actor::ActorCodeFactory& code);
46   void register_default(const actor::ActorCodeFactory& code);
47
48   /**
49    * @brief Add a model to engine list
50    *
51    * @param model Pointer to model
52    * @param list  List of dependencies for this model
53    */
54   void add_model(std::shared_ptr<simgrid::kernel::resource::Model> model,
55                  const std::vector<resource::Model*>& dep_models = {});
56
57   /** @brief Get list of all models managed by this engine */
58   const std::vector<resource::Model*>& get_all_models() const { return models_; }
59
60   static EngineImpl* get_instance() { return simgrid::s4u::Engine::get_instance()->pimpl; }
61   actor::ActorCodeFactory get_function(const std::string& name)
62   {
63     auto res = registered_functions.find(name);
64     if (res == registered_functions.end())
65       return default_function;
66     else
67       return res->second;
68   }
69 };
70
71 } // namespace kernel
72 } // namespace simgrid
73
74 #endif