Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
typo
[simgrid.git] / src / simgrid / module.cpp
index f4ee704..e3095bc 100644 (file)
@@ -7,8 +7,9 @@
 #include <xbt/log.h>
 
 #include "src/simgrid/module.hpp"
-#include "src/surf/surf_interface.hpp"
+#include "src/simgrid/sg_config.hpp"
 
+#include <algorithm>
 #include <sstream>
 
 XBT_LOG_NEW_CATEGORY(plugin, "Common category for the logging of all plugins");
@@ -16,9 +17,40 @@ XBT_LOG_EXTERNAL_CATEGORY(xbt_help);
 
 using namespace simgrid;
 
+void ModuleGroup::create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value,
+                              bool init_now)
+{
+  opt_name_               = opt_name;
+  std::string description = descr + ". Possible values (other compilation flags may activate more " + get_kind() +
+                            "s): " + existing_values() +
+                            ".\n       (use 'help' as a value to see the long description of each one)";
+
+  simgrid::config::declare_flag<std::string>(
+      opt_name, description, default_value, [this, default_value, init_now](const std::string& value) {
+        xbt_assert(_sg_cfg_init_status < 2, "Cannot load a %s after the initialization", kind_.c_str());
+
+        if (value == default_value)
+          return;
+
+        if (value == "help") {
+          help();
+          exit(0);
+        }
+
+        if (init_now)
+          by_name(value).init();
+        else
+          by_name(value); // Simply ensure that this value exists, it will be picked up later
+      });
+}
+void ModuleGroup::init_from_flag_value() const
+{
+  by_name(simgrid::config::get_value<std::string>(opt_name_)).init();
+}
+
 ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function<void()> init)
 {
-  table_.emplace_back(Module(id, desc, init));
+  table_.emplace_back(id, desc, std::move(init));
   return *this;
 }
 
@@ -47,32 +79,3 @@ std::string ModuleGroup::existing_values() const
   }
   return ss.str();
 }
-
-/* -------------------------------------------------------------------------------------------------------------- */
-simgrid::ModuleGroup surf_optimization_mode_description("optimization mode");
-simgrid::ModuleGroup surf_cpu_model_description("CPU model");
-simgrid::ModuleGroup surf_disk_model_description("disk model");
-simgrid::ModuleGroup surf_host_model_description("host model");
-
-void simgrid_create_models()
-{
-  surf_cpu_model_description.add("Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01);
-  surf_disk_model_description.add("S19", "Simplistic disk model.", &surf_disk_model_init_S19);
-
-  surf_host_model_description
-      .add("default",
-           "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
-           &surf_host_model_init_current_default)
-      .add("compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
-           &surf_host_model_init_compound)
-      .add("ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
-           &surf_host_model_init_ptask_L07);
-
-  surf_optimization_mode_description
-      .add("Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr)
-      .add("TI",
-           "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
-           "model for now).",
-           nullptr)
-      .add("Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr);
-}