#include "simgrid/s4u/File.hpp"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/s4u/Storage.hpp"
-#include "src/msg/msg_private.h"
+#include "src/msg/msg_private.hpp"
#include <numeric>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg, "Logging specific to MSG (io)");
-SG_BEGIN_DECL()
+extern "C" {
/** @addtogroup msg_file
* (#msg_file_t) and the functions for managing it.
"\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
/* Find the host where the file is physically located and read it */
msg_storage_t storage_src = simgrid::s4u::Storage::byName(fd->storageId);
msg_host_t attached_host = storage_src->getHost();
- read_size = fd->read(size); // TODO re-add attached_host
+ read_size = fd->read(size);
if (strcmp(attached_host->getCname(), MSG_host_self()->getCname())) {
/* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */
}
}
/* Write file on local or remote host */
- // sg_size_t offset = fd->tell();
- sg_size_t write_size = fd->write(size); // TODO readd attached_host
+ sg_size_t write_size = fd->write(size);
return write_size;
}
{
msg_file_t fd = new simgrid::s4u::File(fullpath, MSG_host_self());
fd->desc_id = MSG_host_get_file_descriptor_id(MSG_host_self());
+ fd->setUserdata(data);
return fd;
}
msg_host_t dst_host;
size_t longest_prefix_length = 0;
- for (auto elm : host->getMountedStorages()) {
+ for (auto const& elm : host->getMountedStorages()) {
std::string mount_point = std::string(fullpath).substr(0, elm.first.size());
if (mount_point == elm.first && elm.first.length() > longest_prefix_length) {
/* The current mount name is found in the full path and is bigger than the previous*/
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
{
xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = storage->getProperties();
+ std::map<std::string, std::string>* props = storage->getProperties();
if (props == nullptr)
return nullptr;
- for (auto elm : *props) {
+ for (auto const& elm : *props) {
xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
}
return as_dict;
{
std::map<std::string, simgrid::s4u::Storage*>* storage_map = simgrid::s4u::allStorages();
xbt_dynar_t res = xbt_dynar_new(sizeof(msg_storage_t),nullptr);
- for (auto s : *storage_map)
+ for (auto const& s : *storage_map)
xbt_dynar_push(res, &(s.second));
delete storage_map;
return res;
xbt_dict_t MSG_storage_get_content(msg_storage_t storage)
{
std::map<std::string, sg_size_t>* content = storage->getContent();
- xbt_dict_t content_as_dict = xbt_dict_new_homogeneous(xbt_free_f);
+ // Note: ::operator delete is ok here (no destructor called) since the dict elements are of POD type sg_size_t.
+ xbt_dict_t content_as_dict = xbt_dict_new_homogeneous(::operator delete);
- for (auto entry : *content) {
- sg_size_t* psize = static_cast<sg_size_t*>(malloc(sizeof(sg_size_t)));
+ for (auto const& entry : *content) {
+ sg_size_t* psize = new sg_size_t;
*psize = entry.second;
xbt_dict_set(content_as_dict, entry.first.c_str(), psize, nullptr);
}
xbt_assert((storage != nullptr), "Invalid parameters");
return storage->getHost()->getCname();
}
-
-SG_END_DECL()
+}