Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix process_killall. Closes #186.
[simgrid.git] / src / s4u / s4u_storage.cpp
index afc3401..092afea 100644 (file)
@@ -1,59 +1,90 @@
-/* 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 "../surf/StorageImpl.hpp"
+#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Storage.hpp"
+#include "simgrid/simix.hpp"
+#include <unordered_map>
 
 namespace simgrid {
 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()
+{
+  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::byName(std::string name)
+{
+  surf::StorageImpl* res = surf::StorageImpl::byName(name);
+  if (res == nullptr)
+    return nullptr;
+  return &res->piface_;
+}
+
+const char* Storage::getName()
+{
+  return pimpl_->cname();
+}
+
+const char* Storage::getType()
+{
+  return pimpl_->typeId_.c_str();
+}
 
-  storages_->insert({name, this});
+Host* Storage::getHost()
+{
+  return attached_to_;
 }
 
-Storage::~Storage() {
-  // TODO Auto-generated destructor stub
+sg_size_t Storage::getSizeFree()
+{
+  return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); });
 }
 
-smx_storage_t Storage::inferior() {
-  return pimpl_;
+sg_size_t Storage::getSizeUsed()
+{
+  return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); });
 }
-Storage &Storage::byName(const char*name) {
-  s4u::Storage *res = NULL;
-  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 == NULL)
-      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;
+sg_size_t Storage::getSize()
+{
+  return pimpl_->getSize();
 }
 
-const char*Storage::name() {
-  return name_.c_str();
+std::map<std::string, std::string>* Storage::getProperties()
+{
+  return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
 }
 
-sg_size_t Storage::sizeFree() {
-  return simcall_storage_get_free_size(pimpl_);
+const char* Storage::getProperty(const char* key)
+{
+  return this->pimpl_->getProperty(key);
 }
-sg_size_t Storage::sizeUsed() {
-  return simcall_storage_get_used_size(pimpl_);
+
+void Storage::setProperty(const char* key, const char* value)
+{
+  simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
 }
-sg_size_t Storage::size() {
-  return SIMIX_storage_get_size(pimpl_);
+
+std::map<std::string, sg_size_t>* Storage::getContent()
+{
+  return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); });
 }
 
+/*************
+ * Callbacks *
+ *************/
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
+
 } /* namespace s4u */
 } /* namespace simgrid */