-/* Copyright (c) 2006-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2006-2017. 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 "simgrid/s4u/storage.hpp"
-
-#include "xbt/lib.h"
-extern xbt_lib_t storage_lib;
+#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Storage.hpp"
+#include "simgrid/simix.hpp"
+#include "src/plugins/file_system/FileSystem.hpp"
+#include "src/surf/StorageImpl.hpp"
+#include <unordered_map>
namespace simgrid {
+namespace xbt {
+template class Extendable<simgrid::s4u::Storage>;
+}
+
namespace s4u {
-boost::unordered_map <std::string, Storage *> *Storage::storages_ = new boost::unordered_map<std::string, Storage*> ();
-Storage::Storage(std::string name, smx_storage_t inferior) :
- name_(name), pimpl_(inferior)
+std::map<std::string, Storage*>* allStorages()
{
- size_ = SIMIX_storage_get_size(pimpl_);
- storages_->insert({name, this});
+ std::unordered_map<std::string, surf::StorageImpl*>* map = surf::StorageImpl::storagesMap();
+ std::map<std::string, Storage*>* res = new std::map<std::string, Storage*>;
+ for (auto const& s : *map)
+ res->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface
+
+ return res;
}
-Storage::~Storage() = default;
+Storage* Storage::byName(std::string name)
+{
+ surf::StorageImpl* res = surf::StorageImpl::byName(name);
+ if (res == nullptr)
+ return nullptr;
+ return &res->piface_;
+}
-smx_storage_t Storage::inferior() {
- return pimpl_;
+const std::string& Storage::getName() const
+{
+ return pimpl_->getName();
}
-Storage &Storage::byName(const char*name) {
- s4u::Storage *res = nullptr;
- try {
- res = storages_->at(name);
- } catch (std::out_of_range& e) {
- smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
- if (inferior == nullptr)
- xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
-
- res = new Storage(name,inferior);
- }
- return *res;
+
+const char* Storage::getCname() const
+{
+ return pimpl_->getCname();
}
-const char* Storage::name()
+const char* Storage::getType()
{
- return name_.c_str();
+ return pimpl_->typeId_.c_str();
}
-sg_size_t Storage::sizeFree()
+Host* Storage::getHost()
{
- return simcall_storage_get_free_size(pimpl_);
+ return attached_to_;
}
-sg_size_t Storage::sizeUsed()
+
+std::map<std::string, std::string>* Storage::getProperties()
{
- return simcall_storage_get_used_size(pimpl_);
+ return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
}
-sg_size_t Storage::size() {
- return size_;
+const char* Storage::getProperty(std::string key)
+{
+ return this->pimpl_->getProperty(key);
}
-xbt_dict_t Storage::properties()
+void Storage::setProperty(std::string key, std::string value)
{
- return simcall_storage_get_properties(pimpl_);
+ simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
}
-xbt_dict_t Storage::content()
+sg_size_t Storage::read(sg_size_t size)
{
- return simcall_storage_get_content(pimpl_);
+ return simcall_storage_read(pimpl_, size);
}
+sg_size_t Storage::write(sg_size_t size)
+{
+ return simcall_storage_write(pimpl_, size);
+}
+
+/*************
+ * Callbacks *
+ *************/
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
+
} /* namespace s4u */
} /* namespace simgrid */