Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
stringify IO
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 10 Aug 2017 13:08:10 +0000 (15:08 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 10 Aug 2017 13:08:10 +0000 (15:08 +0200)
examples/s4u/actions-storage/s4u_actions-storage.cpp
examples/s4u/io/s4u_io.cpp
include/simgrid/s4u/File.hpp
include/simgrid/s4u/Storage.hpp
src/msg/msg_io.cpp
src/s4u/s4u_file.cpp
src/s4u/s4u_storage.cpp
src/surf/FileImpl.cpp
src/surf/FileImpl.hpp
src/surf/StorageImpl.cpp
src/surf/StorageImpl.hpp

index 85e71e1..85ffb9d 100644 (file)
@@ -29,7 +29,7 @@ static void log_action(const char* const* action, double date)
   }
 }
 
-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;
 
@@ -60,11 +60,11 @@ public:
   /* 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});
@@ -74,7 +74,7 @@ public:
 
   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();
 
@@ -88,12 +88,12 @@ public:
 
   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);
index 378f271..8c60b63 100644 (file)
@@ -16,7 +16,7 @@ public:
     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
@@ -24,8 +24,8 @@ 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, 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);
     }
   }
 
@@ -36,11 +36,11 @@ public:
     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);
@@ -49,22 +49,22 @@ public:
     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
@@ -72,10 +72,10 @@ public:
 
     // 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());
   }
index 18d2926..cdc9b97 100644 (file)
@@ -25,12 +25,12 @@ namespace s4u {
 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);
@@ -53,23 +53,21 @@ public:
   /** 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
index 38e30b7..efad7b8 100644 (file)
@@ -28,7 +28,7 @@ public:
   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();
index 776adfe..3b06983 100644 (file)
@@ -73,7 +73,8 @@ void MSG_file_dump (msg_file_t fd){
            "\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
index 043f6d5..35f59e7 100644 (file)
@@ -17,19 +17,19 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files");
 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*/
@@ -38,10 +38,10 @@ File::File(const char* fullpath, sg_host_t host, void* userdata) : path_(fullpat
     }
   }
   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); });
@@ -84,7 +84,7 @@ sg_size_t File::tell()
   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); });
 }
index 38be665..3890ce3 100644 (file)
@@ -22,7 +22,7 @@ std::map<std::string, Storage*>* allStorages()
   return res;
 }
 
-Storage* Storage::byName(const char* name)
+Storage* Storage::byName(std::string name)
 {
   surf::StorageImpl* res = surf::StorageImpl::byName(name);
   if (res == nullptr)
index fbb70a7..ff0a830 100644 (file)
@@ -92,23 +92,23 @@ int FileImpl::unlink()
   }
 }
 
-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());
   }
 }
 }
index 0478ea1..6b2f9cc 100644 (file)
@@ -28,7 +28,7 @@ public:
   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);
 
index b162a6e..1121989 100644 (file)
@@ -32,7 +32,7 @@ simgrid::xbt::signal<void(StorageAction*, Action::State, Action::State)> storage
 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;
index da1f082..b74d624 100644 (file)
@@ -91,7 +91,7 @@ public:
 
   /** @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;