protected:
friend s4u::Host;
+ friend s4u::Storage;
void addHost(std::string name, simgrid::s4u::Host * host);
void delHost(std::string name);
public:
+ void addStorage(std::string name, simgrid::s4u::Storage * storage);
+ void delStorage(std::string name);
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<Host*> * whereTo);
void getLinkList(std::vector<Link*> * list);
std::vector<Link*> getAllLinks();
+ std::vector<Storage*> getAllStorages();
+
/** @brief Run the simulation */
void run();
}
namespace s4u {
-XBT_ATTRIB_PUBLIC void getStorageList(std::map<std::string, Storage*>* whereTo);
+void getStorageList(std::map<std::string, Storage*>* whereTo);
XBT_PUBLIC_CLASS Storage : public simgrid::xbt::Extendable<Storage>
{
friend simgrid::surf::StorageImpl;
public:
- explicit Storage(surf::StorageImpl * pimpl) : pimpl_(pimpl) {}
+ explicit Storage(std::string name, surf::StorageImpl * pimpl);
virtual ~Storage() = default;
/** Retrieve a Storage by its name. It must exist in the platform file */
static Storage* byName(std::string name);
#include "simgrid/s4u/Host.hpp"
#include "src/kernel/routing/NetPoint.hpp"
#include "src/kernel/routing/NetZoneImpl.hpp"
+#include "src/surf/StorageImpl.hpp"
#include <algorithm>
delete netRoot_;
for (auto const& kv : netpoints_)
delete kv.second;
+
+ for (auto const& kv : storages_)
+ if (kv.second)
+ delete kv.second->getImpl();
}
}
}
private:
std::map<std::string, simgrid::s4u::Host*> hosts_;
+ std::map<std::string, simgrid::s4u::Storage*> storages_;
std::unordered_map<std::string, simgrid::kernel::routing::NetPoint*> netpoints_;
friend simgrid::s4u::Engine;
};
for (auto const& kv : pimpl->hosts_)
list->push_back(kv.second);
}
+
/** @brief Returns the list of all hosts found in the platform */
std::vector<Host*> Engine::getAllHosts()
{
res.push_back(kv.second);
return res;
}
+
void Engine::addHost(std::string name, simgrid::s4u::Host* host)
{
pimpl->hosts_[name] = host;
}
+
void Engine::delHost(std::string name)
{
pimpl->hosts_.erase(name);
}
+
simgrid::s4u::Host* Engine::hostByName(std::string name)
{
return pimpl->hosts_.at(name); // Will raise a std::out_of_range if the host does not exist
}
+
simgrid::s4u::Host* Engine::hostByNameOrNull(std::string name)
{
auto host = pimpl->hosts_.find(name);
return host == pimpl->hosts_.end() ? nullptr : host->second;
}
+/** @brief Returns the list of all storages found in the platform */
+std::vector<Storage*> Engine::getAllStorages()
+{
+ std::vector<Storage*> res;
+ for (auto const& kv : pimpl->storages_)
+ res.push_back(kv.second);
+ return res;
+}
+
+simgrid::s4u::Storage* Engine::storageByName(std::string name)
+{
+ return pimpl->storages_.at(name); // Will raise a std::out_of_range if the host does not exist
+}
+
+simgrid::s4u::Storage* Engine::storageByNameOrNull(std::string name)
+{
+ auto storage = pimpl->storages_.find(name);
+ return storage == pimpl->storages_.end() ? nullptr : storage->second;
+}
+
+void Engine::addStorage(std::string name, simgrid::s4u::Storage* storage)
+{
+ pimpl->storages_[name] = storage;
+}
+
+void Engine::delStorage(std::string name)
+{
+ pimpl->storages_.erase(name);
+}
+
/** @brief Returns the amount of links in the platform */
size_t Engine::getLinkCount()
{
return simgrid::surf::LinkImpl::linksCount();
}
+
/** @brief Fills the passed list with all links found in the platform
*
* @deprecated. Prefer Engine::getAllLinks() */
{
simgrid::surf::LinkImpl::linksList(list);
}
+
/** @brief Returns the list of all links found in the platform */
std::vector<Link*> Engine::getAllLinks()
{
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
+#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/s4u/Storage.hpp"
#include "simgrid/simix.hpp"
namespace s4u {
-void getStorageList(std::map<std::string, Storage*>* whereTo)
+void XBT_ATTRIB_DEPRECATED_v322(
+ "simgrid::s4u::getStorageList() is deprecated in favor of Engine::getAllStorages(). Please switch before v3.22")
+ getStorageList(std::map<std::string, Storage*>* whereTo)
{
- for (auto const& s : *surf::StorageImpl::storagesMap())
- whereTo->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface
+ for (auto const& s : simgrid::s4u::Engine::getInstance()->getAllStorages())
+ whereTo->insert({s->getName(), s});
+}
+
+Storage::Storage(std::string name, surf::StorageImpl* pimpl) : pimpl_(pimpl), name_(name)
+{
+ simgrid::s4u::Engine::getInstance()->addStorage(name, this);
}
Storage* Storage::byName(std::string name)
{
- surf::StorageImpl* res = surf::StorageImpl::byName(name);
- if (res == nullptr)
- return nullptr;
- return &res->piface_;
+ return Engine::getInstance()->storageByNameOrNull(name);
}
const std::string& Storage::getName() const
{
- return pimpl_->getName();
+ return name_;
}
const char* Storage::getCname() const
{
- return pimpl_->getCname();
+ return name_.c_str();
}
const char* Storage::getType()
*/
xbt_dynar_t sg_storages_as_dynar()
{
- std::map<std::string, simgrid::s4u::Storage*>* storage_list = new std::map<std::string, simgrid::s4u::Storage*>;
- simgrid::s4u::getStorageList(storage_list);
+ std::vector<simgrid::s4u::Storage*> storage_list = simgrid::s4u::Engine::getInstance()->getAllStorages();
xbt_dynar_t res = xbt_dynar_new(sizeof(sg_storage_t), nullptr);
- for (auto const& s : *storage_list)
- xbt_dynar_push(res, &(s.second));
- delete storage_list;
+ for (auto const& s : storage_list)
+ xbt_dynar_push(res, &s);
return res;
}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "StorageImpl.hpp"
+#include "simgrid/s4u/Engine.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/lmm/maxmin.hpp"
#include "surf_private.hpp"
simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
storageActionStateChangedCallbacks;
-/* List of storages */
-std::unordered_map<std::string, StorageImpl*>* StorageImpl::storages =
- new std::unordered_map<std::string, StorageImpl*>();
-
-StorageImpl* StorageImpl::byName(std::string name)
-{
- if (storages->find(name) == storages->end())
- return nullptr;
- return storages->at(name);
-}
-
/*********
* Model *
*********/
double bwrite, std::string type_id, std::string content_name, sg_size_t size,
std::string attach)
: Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
- , piface_(this)
+ , piface_(name, this)
, typeId_(type_id)
, content_name(content_name)
, size_(size)
XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
constraintRead_ = maxminSystem->constraint_new(this, bread);
constraintWrite_ = maxminSystem->constraint_new(this, bwrite);
- storages->insert({name, this});
}
StorageImpl::~StorageImpl()
storageDestructedCallbacks(this);
}
-
bool StorageImpl::isUsed()
{
THROW_UNIMPLEMENTED;
virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
std::string attach) = 0;
-
- std::vector<StorageImpl*> p_storageList;
};
/************
/** @brief Public interface */
s4u::Storage piface_;
- static StorageImpl* byName(std::string name);
/** @brief Check if the Storage is used (if an action currently uses its resources) */
bool isUsed() override;
virtual StorageAction* write(sg_size_t size) = 0;
virtual std::string getHost() { return attach_; }
- static std::unordered_map<std::string, StorageImpl*>* storagesMap() { return StorageImpl::storages; }
-
kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/
sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
private:
- static std::unordered_map<std::string, StorageImpl*>* storages;
// Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
// the Host directly.
std::string attach_;
if (mount_list.empty())
XBT_DEBUG("Create a Mount list for %s", A_surfxml_host_id);
- mount_list.insert({mount->name, simgrid::surf::StorageImpl::byName(mount->storageId.c_str())});
+ mount_list.insert({mount->name, simgrid::s4u::Engine::getInstance()->storageByName(mount->storageId)->getImpl()});
}
void sg_platf_new_route(RouteCreationArgs* route)
#include "storage_n11.hpp"
#include "simgrid/s4u/Engine.hpp"
+#include "simgrid/s4u/Host.hpp"
#include "src/kernel/lmm/maxmin.hpp"
#include "src/kernel/routing/NetPoint.hpp"
#include "xbt/utility.hpp"
static void check_disk_attachment()
{
- for (auto const& s : *simgrid::surf::StorageImpl::storagesMap()) {
- simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->getHost().c_str());
+ for (auto const& s : simgrid::s4u::Engine::getInstance()->getAllStorages()) {
+ simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s->getImpl()->getHost().c_str());
if (not host_elm)
- surf_parse_error(std::string("Unable to attach storage ") + s.second->getCname() + ": host " +
- s.second->getHost() + " does not exist.");
+ surf_parse_error(std::string("Unable to attach storage ") + s->getCname() + ": host " +
+ s->getImpl()->getHost().c_str() + " does not exist.");
else
- s.second->piface_.attached_to_ = sg_host_by_name(s.second->getHost().c_str());
+ s->attached_to_ = sg_host_by_name(s->getImpl()->getHost().c_str());
}
}
XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tBread '%f'\n", id.c_str(), type_id.c_str(),
Bread);
- p_storageList.push_back(storage);
-
return storage;
}
delete stype->model_properties;
delete stype;
}
- for (auto const& s : *simgrid::surf::StorageImpl::storagesMap())
- delete s.second;
- delete simgrid::surf::StorageImpl::storagesMap();
for (auto const& model : *all_existing_models)
delete model;