From: Frederic Suter Date: Wed, 6 Jun 2018 18:20:32 +0000 (+0200) Subject: snake case storage X-Git-Tag: v3.20~141 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d1428a44b2e13f8c22afcb04c3315b6adbe6be85 snake case storage --- diff --git a/examples/s4u/io-file-system/s4u-io-file-system.cpp b/examples/s4u/io-file-system/s4u-io-file-system.cpp index 3f18c14691..2c34333f94 100644 --- a/examples/s4u/io-file-system/s4u-io-file-system.cpp +++ b/examples/s4u/io-file-system/s4u-io-file-system.cpp @@ -54,7 +54,7 @@ public: write = file->write(100000); // Write 100,000 bytes XBT_INFO("Write %llu bytes on %s", write, filename.c_str()); - simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk4"); + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name("Disk4"); // Now rename file from ./tmp/data.txt to ./tmp/simgrid.readme std::string newpath = "/home/tmp/simgrid.readme"; @@ -72,10 +72,10 @@ public: // Now attach some user data to disk1 XBT_INFO("Get/set data for storage element: %s", storage->get_cname()); - XBT_INFO(" Uninitialized storage data: '%s'", static_cast(storage->getUserdata())); + XBT_INFO(" Uninitialized storage data: '%s'", static_cast(storage->get_data())); - storage->setUserdata(new std::string("Some user data")); - std::string* storage_data = static_cast(storage->getUserdata()); + storage->set_data(new std::string("Some user data")); + std::string* storage_data = static_cast(storage->get_data()); XBT_INFO(" Set and get data: '%s'", storage_data->c_str()); delete storage_data; diff --git a/examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp b/examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp index bb8e1c5162..e594a1e083 100644 --- a/examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp +++ b/examples/s4u/io-storage-raw/s4u-io-storage-raw.cpp @@ -23,7 +23,7 @@ static void host() XBT_INFO("Storage name: %s, mount name: %s", kv.second->get_cname(), kv.first.c_str()); /* - Write 200,000 bytes on Disk4 */ - simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk4"); + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name("Disk4"); sg_size_t write = storage->write(200000); XBT_INFO("Wrote %llu bytes on 'Disk4'", write); @@ -34,12 +34,12 @@ static void host() /* - Attach some user data to disk1 */ XBT_INFO("*** Get/set data for storage element: Disk4 ***"); - std::string* data = static_cast(storage->getUserdata()); + std::string* data = static_cast(storage->get_data()); XBT_INFO("Get storage data: '%s'", data ? data->c_str() : "No user data"); - storage->setUserdata(new std::string("Some user data")); - data = static_cast(storage->getUserdata()); + storage->set_data(new std::string("Some user data")); + data = static_cast(storage->get_data()); XBT_INFO("Set and get data: '%s'", data->c_str()); delete data; } diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index 13ae9be296..6a9704f9f7 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -30,43 +30,63 @@ class XBT_PUBLIC Storage : public simgrid::xbt::Extendable { public: explicit Storage(std::string name, surf::StorageImpl * pimpl); + +protected: virtual ~Storage() = default; - /** Retrieve a Storage by its name. It must exist in the platform file */ - static Storage* byName(std::string name); - XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_name()") std::string const& getName() const { return get_name(); } - XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_cname()") const char* getCname() const { return get_cname(); } +public: + /** @brief Callback signal fired when a new Storage is created */ + static simgrid::xbt::signal on_creation; + /** @brief Callback signal fired when a Storage is destroyed */ + static simgrid::xbt::signal on_destruction; + /** @brief Callback signal fired when a Storage's state changes */ + static simgrid::xbt::signal on_state_change; + + /** Retrieve a Storage by its name. It must exist in the platform file */ + static Storage* by_name(std::string name); /** @brief Retrieves the name of that storage as a C++ string */ std::string const& get_name() const; /** @brief Retrieves the name of that storage as a C string */ const char* get_cname() const; - const char* getType(); - Host* getHost(); + const char* get_type(); + Host* get_host() { return attached_to_; }; + void set_host(Host* host) { attached_to_ = host; } std::map* getProperties(); - const char* getProperty(std::string key); - void setProperty(std::string, std::string value); + const char* get_property(std::string key); + void set_property(std::string, std::string value); - void setUserdata(void* data) { userdata_ = data; } - void* getUserdata() { return userdata_; } + void set_data(void* data) { userdata_ = data; } + void* get_data() { return userdata_; } sg_size_t read(sg_size_t size); sg_size_t write(sg_size_t size); - surf::StorageImpl* getImpl() { return pimpl_; } - - /* The signals */ - /** @brief Callback signal fired when a new Storage is created */ - static simgrid::xbt::signal on_creation; - /** @brief Callback signal fired when a Storage is destroyed */ - static simgrid::xbt::signal on_destruction; - /** @brief Callback signal fired when a Storage's state changes */ - static simgrid::xbt::signal on_state_change; + surf::StorageImpl* get_impl() { return pimpl_; } - Host* attached_to_ = nullptr; + // Deprecated functions + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::by_name()") Storage* byName(std::string name) + { + return by_name(name); + } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_name()") std::string const& getName() const { return get_name(); } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_cname()") const char* getCname() const { return get_cname(); } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_type()") const char* getType() { return get_type(); } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_host()") Host* getHost() { return get_host(); } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_property()") const char* getProperty(const char* key) + { + return get_property(key); + } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_property()") void setProperty(std::string key, std::string value) + { + set_property(key, value); + } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_data()") void setUserdata(void* data) { set_data(data); } + XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_data()") void* getUserdata() { return get_data(); } private: + Host* attached_to_ = nullptr; surf::StorageImpl* const pimpl_ = nullptr; std::string name_; void* userdata_ = nullptr; diff --git a/src/bindings/java/jmsg_storage.cpp b/src/bindings/java/jmsg_storage.cpp index 15fedd9ba4..1ade9fc287 100644 --- a/src/bindings/java/jmsg_storage.cpp +++ b/src/bindings/java/jmsg_storage.cpp @@ -166,7 +166,7 @@ Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject const char *name = env->GetStringUTFChars((jstring) jname, 0); const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0); - storage->setProperty(name, std::string(value_java)); + storage->set_property(name, std::string(value_java)); env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 401e3a764b..34efc84bb0 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -41,7 +41,7 @@ EngineImpl::~EngineImpl() for (auto const& kv : storages_) if (kv.second) - kv.second->getImpl()->destroy(); + kv.second->get_impl()->destroy(); for (auto const& kv : links_) if (kv.second) diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 59574591c4..0dd328719d 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -87,7 +87,7 @@ void File::dump() "\t\tStorage Id: '%s'\n" "\t\tStorage Type: '%s'\n" "\t\tFile Descriptor Id: %d", - get_path(), size_, mount_point_.c_str(), local_storage_->get_cname(), local_storage_->getType(), desc_id); + get_path(), size_, mount_point_.c_str(), local_storage_->get_cname(), local_storage_->get_type(), desc_id); } sg_size_t File::read(sg_size_t size) @@ -96,7 +96,7 @@ sg_size_t File::read(sg_size_t size) return 0; /* Find the host where the file is physically located and read it */ - Host* host = local_storage_->getHost(); + Host* host = local_storage_->get_host(); XBT_DEBUG("READ %s on disk '%s'", get_path(), local_storage_->get_cname()); // if the current position is close to the end of the file, we may not be able to read the requested size sg_size_t read_size = local_storage_->read(std::min(size, size_ - current_position_)); @@ -127,7 +127,7 @@ sg_size_t File::write(sg_size_t size) return 0; /* Find the host where the file is physically located (remote or local)*/ - Host* host = local_storage_->getHost(); + Host* host = local_storage_->get_host(); if (strcmp(host->get_cname(), Host::current()->get_cname())) { /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ @@ -234,7 +234,7 @@ int File::remote_copy(sg_host_t host, const char* fullpath) { /* Find the host where the file is physically located and read it */ Storage* storage_src = local_storage_; - Host* src_host = storage_src->getHost(); + Host* src_host = storage_src->get_host(); seek(0, SEEK_SET); XBT_DEBUG("READ %s on disk '%s'", get_path(), local_storage_->get_cname()); // if the current position is close to the end of the file, we may not be able to read the requested size @@ -257,14 +257,14 @@ int File::remote_copy(sg_host_t host, const char* fullpath) if (storage_dest != nullptr) { /* Mount point found, retrieve the host the storage is attached to */ - dst_host = storage_dest->getHost(); + dst_host = storage_dest->get_host(); } else { XBT_WARN("Can't find mount point for '%s' on destination host '%s'", fullpath, host->get_cname()); return -1; } XBT_DEBUG("Initiate data transfer of %llu bytes between %s and %s.", read_size, src_host->get_cname(), - storage_dest->getHost()->get_cname()); + storage_dest->get_host()->get_cname()); Host* m_host_list[] = {src_host, dst_host}; double* flops_amount = new double[2]{0, 0}; double* bytes_amount = new double[4]{0, static_cast(read_size), 0, 0}; @@ -289,8 +289,8 @@ int File::remote_move(sg_host_t host, const char* fullpath) FileSystemStorageExt::FileSystemStorageExt(simgrid::s4u::Storage* ptr) { - content_ = parse_content(ptr->getImpl()->content_name); - size_ = ptr->getImpl()->size_; + content_ = parse_content(ptr->get_impl()->content_name); + size_ = ptr->get_impl()->size_; } FileSystemStorageExt::~FileSystemStorageExt() diff --git a/src/s4u/s4u_Storage.cpp b/src/s4u/s4u_Storage.cpp index aa0904d859..cf8b3ca75f 100644 --- a/src/s4u/s4u_Storage.cpp +++ b/src/s4u/s4u_Storage.cpp @@ -30,7 +30,7 @@ Storage::Storage(std::string name, surf::StorageImpl* pimpl) : pimpl_(pimpl), na simgrid::s4u::Engine::get_instance()->storage_register(name, this); } -Storage* Storage::byName(std::string name) +Storage* Storage::by_name(std::string name) { return Engine::get_instance()->storage_by_name_or_null(name); } @@ -45,27 +45,22 @@ const char* Storage::get_cname() const return name_.c_str(); } -const char* Storage::getType() +const char* Storage::get_type() { return pimpl_->typeId_.c_str(); } -Host* Storage::getHost() -{ - return attached_to_; -} - std::map* Storage::getProperties() { return simgrid::simix::simcall([this] { return pimpl_->get_properties(); }); } -const char* Storage::getProperty(std::string key) +const char* Storage::get_property(std::string key) { return this->pimpl_->get_property(key); } -void Storage::setProperty(std::string key, std::string value) +void Storage::set_property(std::string key, std::string value) { simgrid::simix::simcall([this, key, value] { this->pimpl_->set_property(key, value); }); } @@ -111,7 +106,7 @@ const char* sg_storage_get_name(sg_storage_t storage) const char* sg_storage_get_host(sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); - return storage->getHost()->get_cname(); + return storage->get_host()->get_cname(); } /** \ingroup sg_storage_management @@ -141,7 +136,7 @@ xbt_dict_t sg_storage_get_properties(sg_storage_t storage) */ void sg_storage_set_property_value(sg_storage_t storage, const char* name, const char* value) { - storage->setProperty(name, value); + storage->set_property(name, value); } /** \ingroup sg_storage_management @@ -153,7 +148,7 @@ void sg_storage_set_property_value(sg_storage_t storage, const char* name, const */ const char* sg_storage_get_property_value(sg_storage_t storage, const char* name) { - return storage->getProperty(name); + return storage->get_property(name); } /** \ingroup sg_storage_management @@ -163,7 +158,7 @@ const char* sg_storage_get_property_value(sg_storage_t storage, const char* name */ sg_storage_t sg_storage_get_by_name(const char* name) { - return simgrid::s4u::Storage::byName(name); + return simgrid::s4u::Storage::by_name(name); } /** \ingroup sg_storage_management @@ -181,12 +176,12 @@ xbt_dynar_t sg_storages_as_dynar() void* sg_storage_get_data(sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); - return storage->getUserdata(); + return storage->get_data(); } void sg_storage_set_data(sg_storage_t storage, void* data) { - storage->setUserdata(data); + storage->set_data(data); } sg_size_t sg_storage_read(sg_storage_t storage, sg_size_t size) diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 667e50aea7..4f05ede58c 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -216,7 +216,7 @@ void SIMIX_global_init(int *argc, char **argv) }); simgrid::s4u::Storage::on_creation.connect([](simgrid::s4u::Storage& storage) { - sg_storage_t s = simgrid::s4u::Storage::byName(storage.get_cname()); + sg_storage_t s = simgrid::s4u::Storage::by_name(storage.get_cname()); xbt_assert(s != nullptr, "Storage not found for name %s", storage.get_cname()); }); } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 2f0997cf29..6498e13057 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -393,7 +393,7 @@ void sg_platf_new_mount(simgrid::kernel::routing::MountCreationArgs* mount) if (mount_list.empty()) XBT_DEBUG("Create a Mount list for %s", A_surfxml_host_id); - mount_list.insert({mount->name, simgrid::s4u::Engine::get_instance()->storage_by_name(mount->storageId)->getImpl()}); + mount_list.insert({mount->name, simgrid::s4u::Engine::get_instance()->storage_by_name(mount->storageId)->get_impl()}); } void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route) diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index c9bcc38cb4..78ac82e2d3 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -20,12 +20,12 @@ extern std::map storage_types; void check_disk_attachment() { for (auto const& s : simgrid::s4u::Engine::get_instance()->get_all_storages()) { - simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s->getImpl()->getHost().c_str()); + simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s->get_impl()->getHost().c_str()); if (not host_elm) surf_parse_error(std::string("Unable to attach storage ") + s->get_cname() + ": host " + - s->getImpl()->getHost().c_str() + " does not exist."); + s->get_impl()->getHost().c_str() + " does not exist."); else - s->attached_to_ = sg_host_by_name(s->getImpl()->getHost().c_str()); + s->set_host(sg_host_by_name(s->get_impl()->getHost().c_str())); } } diff --git a/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp b/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp index de5f855b8f..66fbe1e0df 100644 --- a/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp +++ b/teshsuite/s4u/concurrent_rw/concurrent_rw.cpp @@ -9,7 +9,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test"); static void host() { - simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk1"); + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name("Disk1"); int id = simgrid::s4u::this_actor::get_pid(); XBT_INFO("process %d is writing!", id); storage->write(3000000); diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index 813b037344..b91d2cc433 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -72,19 +72,19 @@ static void display_storage_content(simgrid::s4u::Storage* storage) static void dump_storage_by_name(const std::string& name) { XBT_INFO("*** Dump a storage element ***"); - simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName(name); + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name(name); display_storage_content(storage); } static void get_set_storage_data(const std::string& storage_name) { XBT_INFO("*** GET/SET DATA for storage element: %s ***", storage_name.c_str()); - simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName(storage_name); + simgrid::s4u::Storage* storage = simgrid::s4u::Storage::by_name(storage_name); - std::string* data = static_cast(storage->getUserdata()); + std::string* data = static_cast(storage->get_data()); XBT_INFO("Get data: '%s'", data ? data->c_str() : "No User Data"); - storage->setUserdata(new std::string("Some data")); - data = static_cast(storage->getUserdata()); + storage->set_data(new std::string("Some data")); + data = static_cast(storage->get_data()); XBT_INFO("\tSet and get data: '%s'", data->c_str()); delete data; } @@ -94,8 +94,8 @@ static void dump_platform_storages() std::vector storages = simgrid::s4u::Engine::get_instance()->get_all_storages(); for (auto const& s : storages) { - XBT_INFO("Storage %s is attached to %s", s->get_cname(), s->getHost()->get_cname()); - s->setProperty("other usage", "gpfs"); + XBT_INFO("Storage %s is attached to %s", s->get_cname(), s->get_host()->get_cname()); + s->set_property("other usage", "gpfs"); } }