Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the API between Engine and EngineImpl when registering functions
[simgrid.git] / include / simgrid / s4u / Engine.hpp
index 4158609..e2e0c86 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2020. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -25,6 +25,8 @@ namespace s4u {
  * This is a singleton containing all the main functions of the simulation.
  */
 class XBT_PUBLIC Engine {
+  friend simgrid::kernel::EngineImpl;
+
 public:
   /** Constructor, taking the command line parameters of your main function */
   explicit Engine(int* argc, char** argv);
@@ -48,24 +50,31 @@ public:
 
   void load_platform(const std::string& platf);
 
-  void register_function(const std::string& name, int (*code)(int, char**));
+  XBT_ATTRIB_DEPRECATED_v330("Please change the return code of your actors to void") void register_function(
+      const std::string& name, int (*code)(int, char**));
+
+  void register_function(const std::string& name, void (*code)(int, char**));
   void register_function(const std::string& name, void (*code)(std::vector<std::string>));
-  void register_default(int (*code)(int, char**));
 
+  XBT_ATTRIB_DEPRECATED_v330("Please change the return code of your actors to void") void register_default(
+      int (*code)(int, char**));
+  void register_default(void (*code)(int, char**));
+  void register_default(kernel::actor::ActorCodeFactory factory);
+
+  void register_function(const std::string& name, kernel::actor::ActorCodeFactory factory);
   template <class F> void register_actor(const std::string& name)
   {
-    simix::register_function(name, [](std::vector<std::string> args) {
-      return simix::ActorCode([args] {
+    register_function(name, [](std::vector<std::string> args) {
+      return kernel::actor::ActorCode([args] {
         F code(std::move(args));
         code();
       });
     });
   }
-
   template <class F> void register_actor(const std::string& name, F code)
   {
-    simix::register_function(name, [code](std::vector<std::string> args) {
-      return simix::ActorCode([code, args] { code(std::move(args)); });
+    register_function(name, [code](std::vector<std::string> args) {
+      return kernel::actor::ActorCode([code, args] { code(std::move(args)); });
     });
   }
 
@@ -91,8 +100,13 @@ protected:
 #endif /*DOXYGEN*/
 
 public:
+  /** Returns the amount of hosts existing in the platform. */
   size_t get_host_count();
-  /** @brief Returns the list of all hosts found in the platform */
+  /** Returns a vector of all hosts found in the platform.
+   *
+   * The order is generally different from the creation/declaration order in the XML platform because we use a hash
+   * table internally.
+   */
   std::vector<Host*> get_all_hosts();
   std::vector<Host*> get_filtered_hosts(const std::function<bool(Host*)>& filter);
   Host* host_by_name(const std::string& name);
@@ -137,8 +151,10 @@ public:
   static bool is_initialized();
   /** @brief set a configuration variable
    *
-   * Do --help on any simgrid binary to see the list of currently existing configuration variables (see also @ref
-   * options).
+   * @beginrst
+   * Do --help on any simgrid binary to see the list of currently existing configuration variables
+   * (see also :ref:`options`).
+   * @endrst
    *
    * Example:
    * e->set_config("host/model:ptask_L07");
@@ -168,7 +184,8 @@ private:
 };
 
 #ifndef DOXYGEN /* Internal use only, no need to expose it */
-template <class T> XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone* current, std::vector<T*>* whereto)
+template <class T>
+XBT_PRIVATE void get_filtered_netzones_recursive(const s4u::NetZone* current, std::vector<T*>* whereto)
 {
   static_assert(std::is_base_of<kernel::routing::NetZoneImpl, T>::value,
                 "Filtering netzones is only possible for subclasses of kernel::routing::NetZoneImpl");