}
}
-static simgrid::s4u::File* get_file_descriptor(const char* file_name)
+static simgrid::s4u::File* get_file_descriptor(std::string file_name)
{
std::string full_name = simgrid::s4u::this_actor::getName() + ":" + file_name;
/* My actions */
static void open(const char* const* action)
{
- const char* file_name = action[2];
+ std::string file_name = action[2];
double clock = simgrid::s4u::Engine::getClock();
std::string full_name = simgrid::s4u::this_actor::getName() + ":" + file_name;
- ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
+ ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name.c_str());
simgrid::s4u::File* file = new simgrid::s4u::File(file_name, NULL);
opened_files.insert({full_name, file});
static void read(const char* const* action)
{
- const char* file_name = action[2];
+ std::string file_name = action[2];
sg_size_t size = std::stoul(action[3]);
double clock = simgrid::s4u::Engine::getClock();
static void close(const char* const* action)
{
- const char* file_name = action[2];
+ std::string file_name = action[2];
double clock = simgrid::s4u::Engine::getClock();
simgrid::s4u::File* file = get_file_descriptor(file_name);
- ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name);
+ ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name.c_str());
delete file;
log_action(action, simgrid::s4u::Engine::getClock() - clock);
XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->getCname());
for (const auto&kv : mounts) {
- const char* mountpoint = kv.first.c_str();
+ std::string mountpoint = kv.first;
simgrid::s4u::Storage* storage = kv.second;
// Retrieve disk's information
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, used_size, free_size,
- size);
+ XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", storage->getName(), mountpoint.c_str(), used_size,
+ free_size, size);
}
}
show_info(mounts);
// Open an non-existing file to create it
- const char* filename = "/home/tmp/data.txt";
+ std::string filename = "/home/tmp/data.txt";
simgrid::s4u::File* file = new simgrid::s4u::File(filename, nullptr);
sg_size_t write = file->write(200000); // Write 200,000 bytes
- XBT_INFO("Create a %llu bytes file named '%s' on /sd1", write, filename);
+ XBT_INFO("Create a %llu bytes file named '%s' on /sd1", write, filename.c_str());
// check that sizes have changed
show_info(mounts);
const sg_size_t file_size = file->size();
file->seek(0);
const sg_size_t read = file->read(file_size);
- XBT_INFO("Read %llu bytes on %s", read, filename);
+ XBT_INFO("Read %llu bytes on %s", read, filename.c_str());
// Now write 100,000 bytes in tmp/data.txt
write = file->write(100000); // Write 100,000 bytes
- XBT_INFO("Write %llu bytes on %s", write, filename);
+ XBT_INFO("Write %llu bytes on %s", write, filename.c_str());
simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk4");
// Now rename file from ./tmp/data.txt to ./tmp/simgrid.readme
- const char *newpath = "/home/tmp/simgrid.readme";
- XBT_INFO("Move '%s' to '%s'", file->getPath(), newpath);
+ std::string newpath = "/home/tmp/simgrid.readme";
+ XBT_INFO("Move '%s' to '%s'", file->getPath(), newpath.c_str());
file->move(newpath);
// Test attaching some user data to the file
file->setUserdata(xbt_strdup("777"));
- XBT_INFO("User data attached to the file: %s", (char*)file->getUserdata());
+ XBT_INFO("User data attached to the file: %s", static_cast<char*>(file->getUserdata()));
xbt_free(file->getUserdata());
// Close the file
// Now attach some user data to disk1
XBT_INFO("Get/set data for storage element: %s", storage->getName());
- XBT_INFO(" Uninitialized storage data: '%s'", (char*)storage->getUserdata());
+ XBT_INFO(" Uninitialized storage data: '%s'", static_cast<char*>(storage->getUserdata()));
storage->setUserdata(xbt_strdup("Some user data"));
- XBT_INFO(" Set and get data: '%s'", (char*)storage->getUserdata());
+ XBT_INFO(" Set and get data: '%s'", static_cast<char*>(storage->getUserdata()));
xbt_free(storage->getUserdata());
}
XBT_PUBLIC_CLASS File
{
public:
- File(const char* fullpath, void* userdata);
- File(const char* fullpath, sg_host_t host, void* userdata);
+ File(std::string fullpath, void* userdata);
+ File(std::string fullpath, sg_host_t host, void* userdata);
~File();
/** Retrieves the path to the file */
- const char* getPath() { return path_; }
+ const char* getPath() { return path_.c_str(); }
/** Simulates a local read action. Returns the size of data actually read */
sg_size_t read(sg_size_t size);
/** Retrieves the current file position */
sg_size_t tell();
- /** Rename a file
- *
- * WARNING: It is forbidden to move the file to another mount point */
- void move(const char* fullpath);
+ /** Rename a file. WARNING: It is forbidden to move the file to another mount point */
+ void move(std::string fullpath);
/** Remove a file from disk */
int unlink();
- const char* storage_type;
- const char* storageId;
+ std::string storage_type;
+ std::string storageId;
std::string mount_point;
int desc_id = 0;
private:
surf_file_t pimpl_ = nullptr;
- const char* path_ = nullptr;
- void* userdata_ = nullptr;
+ std::string path_;
+ void* userdata_ = nullptr;
};
}
} // namespace simgrid::s4u
explicit Storage(surf::StorageImpl * pimpl) : pimpl_(pimpl) {}
virtual ~Storage() = default;
/** Retrieve a Storage by its name. It must exist in the platform file */
- static Storage* byName(const char* name);
+ static Storage* byName(std::string name);
const char* getName();
const char* getType();
Host* getHost();
"\t\tStorage Id: '%s'\n"
"\t\tStorage Type: '%s'\n"
"\t\tFile Descriptor Id: %d",
- fd->getPath(), fd->size(), fd->mount_point.c_str(), fd->storageId, fd->storage_type, fd->desc_id);
+ fd->getPath(), fd->size(), fd->mount_point.c_str(), fd->storageId.c_str(), fd->storage_type.c_str(),
+ fd->desc_id);
}
/** \ingroup msg_file
namespace simgrid {
namespace s4u {
-File::File(const char* fullpath, void* userdata) : File(fullpath, Host::current(), userdata){};
+File::File(std::string fullpath, void* userdata) : File(fullpath, Host::current(), userdata){};
-File::File(const char* fullpath, sg_host_t host, void* userdata) : path_(fullpath), userdata_(userdata)
+File::File(std::string fullpath, sg_host_t host, void* userdata) : path_(fullpath), userdata_(userdata)
{
// this cannot fail because we get a xbt_die if the mountpoint does not exist
Storage* st = nullptr;
size_t longest_prefix_length = 0;
std::string path;
- XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath, host->getCname());
+ XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath.c_str(), host->getCname());
for (auto mnt : host->getMountedStorages()) {
XBT_DEBUG("See '%s'", mnt.first.c_str());
- mount_point = std::string(fullpath).substr(0, mnt.first.size());
+ mount_point = fullpath.substr(0, mnt.first.length());
if (mount_point == mnt.first && mnt.first.length() > longest_prefix_length) {
/* The current mount name is found in the full path and is bigger than the previous*/
}
}
if (longest_prefix_length > 0) { /* Mount point found, split fullpath into mount_name and path+filename*/
- mount_point = std::string(fullpath).substr(0, longest_prefix_length);
- path = std::string(fullpath).substr(longest_prefix_length, strlen(fullpath));
+ mount_point = fullpath.substr(0, longest_prefix_length);
+ path = fullpath.substr(longest_prefix_length, fullpath.length());
} else
- xbt_die("Can't find mount point for '%s' on '%s'", fullpath, host->getCname());
+ xbt_die("Can't find mount point for '%s' on '%s'", fullpath.c_str(), host->getCname());
pimpl_ =
simgrid::simix::kernelImmediate([this, st, path] { return new simgrid::surf::FileImpl(st, path, mount_point); });
return simgrid::simix::kernelImmediate([this] { return pimpl_->tell(); });
}
-void File::move(const char* fullpath)
+void File::move(std::string fullpath)
{
simgrid::simix::kernelImmediate([this, fullpath] { pimpl_->move(fullpath); });
}
return res;
}
-Storage* Storage::byName(const char* name)
+Storage* Storage::byName(std::string name)
{
surf::StorageImpl* res = surf::StorageImpl::byName(name);
if (res == nullptr)
}
}
-void FileImpl::move(const char* fullpath)
+void FileImpl::move(std::string fullpath)
{
/* Check if the new full path is on the same mount point */
- if (not strncmp(mount_point_.c_str(), fullpath, mount_point_.size())) {
+ if (not strncmp(mount_point_.c_str(), fullpath.c_str(), mount_point_.size())) {
std::map<std::string, sg_size_t>* content = location_->getContent();
auto sz = content->find(path_);
if (sz != content->end()) { // src file exists
sg_size_t new_size = sz->second;
content->erase(path_);
- std::string path = std::string(fullpath).substr(mount_point_.size(), strlen(fullpath));
+ std::string path = fullpath.substr(mount_point_.length(), fullpath.length());
content->insert({path.c_str(), new_size});
- XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath, new_size);
+ XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath.c_str(), new_size);
} else {
XBT_WARN("File %s doesn't exist", path_.c_str());
}
} else {
- XBT_WARN("New full path %s is not on the same mount point: %s.", fullpath, mount_point_.c_str());
+ XBT_WARN("New full path %s is not on the same mount point: %s.", fullpath.c_str(), mount_point_.c_str());
}
}
}
sg_size_t tell() { return current_position_; }
int seek(sg_offset_t offset, int origin);
int unlink();
- void move(const char* fullpath);
+ void move(std::string fullpath);
Action* read(sg_size_t size);
Action* write(sg_size_t size);
std::unordered_map<std::string, StorageImpl*>* StorageImpl::storages =
new std::unordered_map<std::string, StorageImpl*>();
-StorageImpl* StorageImpl::byName(const char* name)
+StorageImpl* StorageImpl::byName(std::string name)
{
if (storages->find(name) == storages->end())
return nullptr;
/** @brief Public interface */
s4u::Storage piface_;
- static StorageImpl* byName(const char* name);
+ static StorageImpl* byName(std::string name);
/** @brief Check if the Storage is used (if an action currently uses its resources) */
bool isUsed() override;