X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/121e1dc6ee0462b6f6f1f1570b0f48c61ee4ff9a..940de22d7f2af82d58be3e886e6bc22608b4d8ec:/include/simgrid/s4u/Engine.hpp diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 9aab4fe0fa..232f0f0ea6 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -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. */ @@ -13,28 +13,23 @@ #include #include +#include #include -#include +#include namespace simgrid { -namespace kernel { -class EngineImpl; -} namespace s4u { /** @brief Simulation engine * * This class is an interface to the simulation engine. */ -XBT_PUBLIC_CLASS Engine -{ -private: - ~Engine(); - +class XBT_PUBLIC Engine { public: /** Constructor, taking the command line parameters of your main function */ Engine(int* argc, char** argv); + ~Engine(); /** Finalize the default engine and all its dependencies */ static void shutdown(); @@ -58,8 +53,29 @@ public: /** @brief Load a deployment file and launch the actors that it contains */ void loadDeployment(const char* deploy); - size_t hostCount(); - void hostList(std::vector * whereTo); +protected: + friend s4u::Host; + friend s4u::Storage; + void addHost(std::string name, simgrid::s4u::Host * host); + void delHost(std::string name); + void addStorage(std::string name, simgrid::s4u::Storage * storage); + void delStorage(std::string name); + +public: + simgrid::s4u::Host* hostByName(std::string name); + simgrid::s4u::Host* hostByNameOrNull(std::string name); + simgrid::s4u::Storage* storageByName(std::string name); + simgrid::s4u::Storage* storageByNameOrNull(std::string name); + + size_t getHostCount(); + void getHostList(std::vector * whereTo); + std::vector getAllHosts(); + + size_t getLinkCount(); + void getLinkList(std::vector * list); + std::vector getAllLinks(); + + std::vector getAllStorages(); /** @brief Run the simulation */ void run(); @@ -68,17 +84,19 @@ public: static double getClock(); /** @brief Retrieve the engine singleton */ - static s4u::Engine* instance(); + static s4u::Engine* getInstance(); /** @brief Retrieve the root netzone, containing all others */ - simgrid::s4u::NetZone* netRoot(); + simgrid::s4u::NetZone* getNetRoot(); /** @brief Retrieve the netzone of the given name (or nullptr if not found) */ - simgrid::s4u::NetZone* netzoneByNameOrNull(const char* name); + simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name); + /** @brief Retrieves all netzones of the same type than the subtype of the whereto vector */ + template void getNetzoneByType(std::vector * whereto) { netzoneByTypeRecursive(getNetRoot(), whereto); } /** @brief Retrieve the netcard of the given name (or nullptr if not found) */ - simgrid::kernel::routing::NetPoint* netpointByNameOrNull(const char* name); - void netpointList(std::vector * list); + simgrid::kernel::routing::NetPoint* getNetpointByNameOrNull(std::string name); + void getNetpointList(std::vector * list); void netpointRegister(simgrid::kernel::routing::NetPoint * card); void netpointUnregister(simgrid::kernel::routing::NetPoint * card); @@ -102,6 +120,15 @@ public: /** Returns whether SimGrid was initialized yet -- mostly for internal use */ static bool isInitialized(); + /** @brief set a configuration variable + * + * Do --help on any simgrid binary to see the list of currently existing configuration variables (see @ref options). + * + * Example: + * e->setConfig("host/model","ptask_L07"); + */ + void setConfig(std::string str); + simgrid::kernel::EngineImpl* pimpl; private: @@ -110,13 +137,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 onPlatformCreated; +extern XBT_PUBLIC xbt::signal onPlatformCreated; /** Callback fired when the main simulation loop ends, just before MSG_run (or similar) ends */ -extern XBT_PRIVATE xbt::signal onSimulationEnd; +extern XBT_PUBLIC xbt::signal onSimulationEnd; /** Callback fired when the time jumps into the future */ -extern XBT_PRIVATE xbt::signal onTimeAdvance; +extern XBT_PUBLIC xbt::signal onTimeAdvance; + +/** Callback fired when the time cannot jump because of inter-actors deadlock */ +extern XBT_PUBLIC xbt::signal onDeadlock; + +template XBT_PRIVATE void netzoneByTypeRecursive(s4u::NetZone* current, std::vector* whereto) +{ + for (auto const& elem : *(current->getChildren())) { + netzoneByTypeRecursive(elem, whereto); + if (elem == dynamic_cast(elem)) + whereto->push_back(dynamic_cast(elem)); + } +} } } // namespace simgrid::s4u