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";
// 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<char*>(storage->getUserdata()));
+ XBT_INFO(" Uninitialized storage data: '%s'", static_cast<char*>(storage->get_data()));
- storage->setUserdata(new std::string("Some user data"));
- std::string* storage_data = static_cast<std::string*>(storage->getUserdata());
+ storage->set_data(new std::string("Some user data"));
+ std::string* storage_data = static_cast<std::string*>(storage->get_data());
XBT_INFO(" Set and get data: '%s'", storage_data->c_str());
delete storage_data;
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);
/* - Attach some user data to disk1 */
XBT_INFO("*** Get/set data for storage element: Disk4 ***");
- std::string* data = static_cast<std::string*>(storage->getUserdata());
+ std::string* data = static_cast<std::string*>(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<std::string*>(storage->getUserdata());
+ storage->set_data(new std::string("Some user data"));
+ data = static_cast<std::string*>(storage->get_data());
XBT_INFO("Set and get data: '%s'", data->c_str());
delete data;
}
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<void(s4u::Storage&)> on_creation;
+ /** @brief Callback signal fired when a Storage is destroyed */
+ static simgrid::xbt::signal<void(s4u::Storage&)> on_destruction;
+ /** @brief Callback signal fired when a Storage's state changes */
+ static simgrid::xbt::signal<void(s4u::Storage&)> 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<std::string, std::string>* 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<void(s4u::Storage&)> on_creation;
- /** @brief Callback signal fired when a Storage is destroyed */
- static simgrid::xbt::signal<void(s4u::Storage&)> on_destruction;
- /** @brief Callback signal fired when a Storage's state changes */
- static simgrid::xbt::signal<void(s4u::Storage&)> 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;
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);
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)
"\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)
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_));
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 */
{
/* 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
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<double>(read_size), 0, 0};
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()
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);
}
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<std::string, std::string>* 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); });
}
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
*/
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
*/
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
*/
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
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)
});
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());
});
}
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)
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()));
}
}
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);
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<std::string*>(storage->getUserdata());
+ std::string* data = static_cast<std::string*>(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<std::string*>(storage->getUserdata());
+ storage->set_data(new std::string("Some data"));
+ data = static_cast<std::string*>(storage->get_data());
XBT_INFO("\tSet and get data: '%s'", data->c_str());
delete data;
}
std::vector<simgrid::s4u::Storage*> 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");
}
}