1 /* Copyright (c) 2016-2021. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_KERNEL_ENGINEIMPL_HPP
7 #define SIMGRID_KERNEL_ENGINEIMPL_HPP
9 #include <simgrid/kernel/resource/Model.hpp>
10 #include <simgrid/s4u/Engine.hpp>
11 #include <simgrid/s4u/NetZone.hpp>
12 #include <simgrid/simix.hpp>
16 #include <unordered_map>
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<std::shared_ptr<resource::Model>> models_;
28 std::unordered_map<resource::Model::Type, std::vector<resource::Model*>> models_by_type_;
33 EngineImpl() = default;
35 EngineImpl(const EngineImpl&) = delete;
36 EngineImpl& operator=(const EngineImpl&) = delete;
37 virtual ~EngineImpl();
39 void load_deployment(const std::string& file) const;
40 void register_function(const std::string& name, const actor::ActorCodeFactory& code);
41 void register_default(const actor::ActorCodeFactory& code);
44 * @brief Add a model to engine list
46 * @param type Model type (network, disk, etc)
47 * @param model Pointer to model
48 * @param is_default Is this the default model for this type of resource in this exp
50 void add_model(resource::Model::Type type, std::shared_ptr<resource::Model> model, bool is_default = false);
51 /** @brief Get current default model for a resource type */
52 resource::Model* get_default_model(resource::Model::Type type) const;
54 /** @brief Get list of models created for a resource type */
55 const std::vector<resource::Model*>& get_model_list(resource::Model::Type type);
57 /** @brief Get list of all models managed by this engine */
58 const std::vector<std::shared_ptr<resource::Model>>& get_all_models() const { return models_; }
60 routing::NetZoneImpl* netzone_root_ = nullptr;
61 static EngineImpl* get_instance() { return simgrid::s4u::Engine::get_instance()->pimpl; }
62 actor::ActorCodeFactory get_function(const std::string& name)
64 auto res = registered_functions.find(name);
65 if (res == registered_functions.end())
66 return default_function;
73 } // namespace simgrid