1 /* Copyright (c) 2004-2023. 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_MODULE_HPP
7 #define SIMGRID_MODULE_HPP
19 const char* description_;
20 std::function<void()> init;
21 Module(const char* id, const char* desc, std::function<void()> init_fun)
22 : name_(id), description_(desc), init(init_fun)
28 std::vector<Module> table_;
29 const std::string kind_; // either 'plugin' or 'CPU model' or whatever. Used in error messages only
30 std::string opt_name_;
33 ModuleGroup(const std::string& kind) : kind_(kind) {}
35 ModuleGroup& add(const char* id, const char* desc, std::function<void()> init);
36 Module const& by_name(const std::string& name) const;
38 const std::string get_kind() const { return kind_; }
39 std::string existing_values() const;
40 void create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value,
42 void init_from_flag_value();
45 }; // namespace simgrid
47 #define SIMGRID_REGISTER_PLUGIN(id, desc, init) \
48 static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)() \
50 simgrid_plugins().add(_XBT_STRINGIFY(id), (desc), (init)); \
52 /** @brief The list of all available plugins */
53 inline auto& simgrid_plugins() // Function to avoid static initialization order fiasco
55 static simgrid::ModuleGroup plugins("plugin");
59 #define SIMGRID_REGISTER_NETWORK_MODEL(id, desc, init) \
60 static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _network_model_register)() \
62 simgrid_network_models().add(_XBT_STRINGIFY(id), (desc), (init)); \
64 /** @brief The list of all available network models (pick one with --cfg=network/model) */
65 inline auto& simgrid_network_models() // Function to avoid static initialization order fiasco
67 static simgrid::ModuleGroup models("network model");
71 #define SIMGRID_REGISTER_CPU_MODEL(id, desc, init) \
72 static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _cpu_model_register)() \
74 simgrid_cpu_models().add(_XBT_STRINGIFY(id), (desc), (init)); \
76 /** @brief The list of all available CPU models (pick one with --cfg=cpu/model) */
77 inline auto& simgrid_cpu_models() // Function to avoid static initialization order fiasco
79 static simgrid::ModuleGroup models("CPU model");
83 #define SIMGRID_REGISTER_DISK_MODEL(id, desc, init) \
84 static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _disk_model_register)() \
86 simgrid_disk_models().add(_XBT_STRINGIFY(id), (desc), (init)); \
88 /** @brief The list of all available disk models (pick one with --cfg=disk/model) */
89 inline auto& simgrid_disk_models() // Function to avoid static initialization order fiasco
91 static simgrid::ModuleGroup models("disk model");
95 #define SIMGRID_REGISTER_HOST_MODEL(id, desc, init) \
96 static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _host_model_register)() \
98 simgrid_host_models().add(_XBT_STRINGIFY(id), (desc), (init)); \
100 /** @brief The list of all available host models (pick one with --cfg=host/model) */
101 inline auto& simgrid_host_models() // Function to avoid static initialization order fiasco
103 static simgrid::ModuleGroup models("host model");