From 914a96cd544e878a5c2513b800d2327f86ef9119 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 14 Oct 2017 22:52:46 +0200 Subject: [PATCH] Change getName() and add getCname() in s4u::Storage. --- examples/s4u/io/s4u-io.cpp | 4 ++-- include/simgrid/s4u/Storage.hpp | 5 ++++- src/bindings/java/jmsg_host.cpp | 2 +- src/msg/msg_io.cpp | 2 +- src/s4u/s4u_storage.cpp | 7 ++++++- src/simgrid/host.cpp | 2 +- src/surf/HostImpl.cpp | 4 ++-- .../s4u/storage_client_server/storage_client_server.cpp | 8 ++++---- 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/examples/s4u/io/s4u-io.cpp b/examples/s4u/io/s4u-io.cpp index bcade6d748..46a50133c6 100644 --- a/examples/s4u/io/s4u-io.cpp +++ b/examples/s4u/io/s4u-io.cpp @@ -25,7 +25,7 @@ public: sg_size_t used_size = storage->getSizeUsed(); sg_size_t size = storage->getSize(); - XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", storage->getName(), mountpoint.c_str(), used_size, + XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", storage->getCname(), mountpoint.c_str(), used_size, free_size, size); } } @@ -73,7 +73,7 @@ public: delete file; // Now attach some user data to disk1 - XBT_INFO("Get/set data for storage element: %s", storage->getName()); + XBT_INFO("Get/set data for storage element: %s", storage->getCname()); XBT_INFO(" Uninitialized storage data: '%s'", static_cast(storage->getUserdata())); storage->setUserdata(new std::string("Some user data")); diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index efad7b826d..f28f936188 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -29,7 +29,10 @@ public: virtual ~Storage() = default; /** Retrieve a Storage by its name. It must exist in the platform file */ static Storage* byName(std::string name); - const char* getName(); + /** @brief Retrieves the name of that storage as a C++ string */ + std::string const& getName() const; + /** @brief Retrieves the name of that storage as a C string */ + const char* getCname() const; const char* getType(); Host* getHost(); sg_size_t getSize(); /** Retrieve the total amount of space of this storage element */ diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index f51c91da94..22c54da768 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -250,7 +250,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn } for (auto const& elm : mounted_storages) { - jname = env->NewStringUTF(elm.second->getName()); + jname = env->NewStringUTF(elm.second->getCname()); jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname); env->SetObjectArrayElement(jtable, index, jstorage); index++; diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index fd4ad9a032..11de4c7453 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -358,7 +358,7 @@ msg_error_t MSG_file_rmove (msg_file_t file, msg_host_t host, const char* fullpa const char* MSG_storage_get_name(msg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); - return storage->getName(); + return storage->getCname(); } /** \ingroup msg_storage_management diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 0507ac3913..c3066bd3a6 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -30,7 +30,12 @@ Storage* Storage::byName(std::string name) return &res->piface_; } -const char* Storage::getName() +const std::string& Storage::getName() const +{ + return pimpl_->getName(); +} + +const char* Storage::getCname() const { return pimpl_->getCname(); } diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 336e5a356a..5b709b4f27 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -126,7 +126,7 @@ xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){ for (auto const& elm : host->getMountedStorages()) { const char* mount_name = elm.first.c_str(); sg_storage_t storage = elm.second; - xbt_dict_set(res, mount_name, (void*)storage->getName(), nullptr); + xbt_dict_set(res, mount_name, (void*)storage->getCname(), nullptr); } return res; diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 870c6fc3f9..18bf4bcc7e 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2016. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-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. */ @@ -107,7 +107,7 @@ void HostImpl::getAttachedStorageList(std::vector* storages) { for (auto const& s : storage_) if (s.second->getHost() == piface_->getCname()) - storages->push_back(s.second->piface_.getName()); + storages->push_back(s.second->piface_.getCname()); } } diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index 52a69d7817..52d9ace4d2 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -12,7 +12,7 @@ static void display_storage_properties(simgrid::s4u::Storage* storage) { std::map* props = storage->getProperties(); if (not props->empty()) { - XBT_INFO("\tProperties of mounted storage: %s", storage->getName()); + XBT_INFO("\tProperties of mounted storage: %s", storage->getCname()); for (auto const& elm : *props) { XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str()); @@ -60,7 +60,7 @@ static void hsm_put(const char* remote_host, const char* src, const char* dest) static void display_storage_content(simgrid::s4u::Storage* storage) { - XBT_INFO("Print the content of the storage element: %s", storage->getName()); + XBT_INFO("Print the content of the storage element: %s", storage->getCname()); std::map* content = storage->getContent(); if (not content->empty()) { for (auto const& entry : *content) @@ -108,7 +108,7 @@ static void storage_info(simgrid::s4u::Host* host) for (auto const& elm : host->getMountedStorages()) { const char* mount_name = elm.first.c_str(); simgrid::s4u::Storage* storage = elm.second; - XBT_INFO("\tStorage name: %s, mount name: %s", storage->getName(), mount_name); + XBT_INFO("\tStorage name: %s, mount name: %s", storage->getCname(), mount_name); sg_size_t free_size = storage->getSizeFree(); sg_size_t used_size = storage->getSizeUsed(); @@ -117,7 +117,7 @@ static void storage_info(simgrid::s4u::Host* host) XBT_INFO("\t\tUsed size: %llu bytes", used_size); display_storage_properties(storage); - dump_storage_by_name(storage->getName()); + dump_storage_by_name(storage->getCname()); } } -- 2.20.1