Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics: rename a function, deprecate old name
[simgrid.git] / include / simgrid / s4u / Engine.hpp
index 4b39af1..cd42aec 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2018. 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. */
 #include <xbt/base.h>
 #include <xbt/functional.hpp>
 
+#include <simgrid/forward.h>
 #include <simgrid/simix.hpp>
 
-#include <simgrid/s4u/forward.hpp>
+#include <simgrid/s4u/NetZone.hpp>
 
 namespace simgrid {
-namespace kernel {
-class EngineImpl;
-}
 namespace s4u {
 /** @brief Simulation engine
  *
@@ -56,10 +54,22 @@ public:
   /** @brief Load a deployment file and launch the actors that it contains */
   void loadDeployment(const char* deploy);
 
+protected:
+  friend s4u::Host;
+  void addHost(std::string name, simgrid::s4u::Host * host);
+  void delHost(std::string name);
+
+public:
+  simgrid::s4u::Host* hostByName(std::string name);
+  simgrid::s4u::Host* hostByNameOrNull(std::string name);
+
   size_t getHostCount();
   void getHostList(std::vector<Host*> * whereTo);
+  std::vector<Host*> getAllHosts();
+
   size_t getLinkCount();
   void getLinkList(std::vector<Link*> * list);
+  std::vector<Link*> getAllLinks();
 
   /** @brief Run the simulation */
   void run();
@@ -76,6 +86,8 @@ public:
   /** @brief Retrieve the netzone of the given name (or nullptr if not found) */
   simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name);
 
+  /** @brief Retrieves all netzones of the same type than the subtype of the whereto vector */
+  template <class T> void getNetzoneByType(std::vector<T*> * whereto) { netzoneByTypeRecursive(getNetRoot(), whereto); }
   /** @brief Retrieve the netcard of the given name (or nullptr if not found) */
   simgrid::kernel::routing::NetPoint* getNetpointByNameOrNull(std::string name);
   void getNetpointList(std::vector<simgrid::kernel::routing::NetPoint*> * list);
@@ -119,16 +131,25 @@ private:
 
 /** Callback fired when the platform is created (ie, the xml file parsed),
  * right before the actual simulation starts. */
-extern XBT_PRIVATE xbt::signal<void()> onPlatformCreated;
+extern XBT_PUBLIC(xbt::signal<void()>) onPlatformCreated;
 
 /** Callback fired when the main simulation loop ends, just before MSG_run (or similar) ends */
-extern XBT_PRIVATE xbt::signal<void()> onSimulationEnd;
+extern XBT_PUBLIC(xbt::signal<void()>) onSimulationEnd;
 
 /** Callback fired when the time jumps into the future */
-extern XBT_PRIVATE xbt::signal<void(double)> onTimeAdvance;
+extern XBT_PUBLIC(xbt::signal<void(double)>) onTimeAdvance;
 
 /** Callback fired when the time cannot jump because of inter-actors deadlock */
-extern XBT_PRIVATE xbt::signal<void(void)> onDeadlock;
+extern XBT_PUBLIC(xbt::signal<void(void)>) onDeadlock;
+
+template <class T> XBT_PRIVATE void netzoneByTypeRecursive(s4u::NetZone* current, std::vector<T*>* whereto)
+{
+  for (auto const& elem : *(current->getChildren())) {
+    netzoneByTypeRecursive(elem, whereto);
+    if (elem == dynamic_cast<T*>(elem))
+      whereto->push_back(dynamic_cast<T*>(elem));
+  }
+}
 }
 } // namespace simgrid::s4u