1 /* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u/Host.hpp"
7 #include "simgrid/s4u/Storage.hpp"
8 #include "src/msg/msg_private.hpp"
9 #include "src/plugins/file_system/FileSystem.hpp"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg, "Logging specific to MSG (io)");
16 /********************************* Storage **************************************/
17 /** @addtogroup msg_storage_management
18 * (#msg_storage_t) and the functions for managing it.
21 /** \ingroup msg_storage_management
23 * \brief Returns the name of the #msg_storage_t.
25 * This functions checks whether a storage is a valid pointer or not and return its name.
27 const char* MSG_storage_get_name(msg_storage_t storage)
29 xbt_assert((storage != nullptr), "Invalid parameters");
30 return storage->getCname();
33 const char* MSG_storage_get_host(msg_storage_t storage)
35 xbt_assert((storage != nullptr), "Invalid parameters");
36 return storage->getHost()->getCname();
39 /** \ingroup msg_storage_management
40 * \brief Returns a xbt_dict_t consisting of the list of properties assigned to this storage
41 * \param storage a storage
42 * \return a dict containing the properties
44 xbt_dict_t MSG_storage_get_properties(msg_storage_t storage)
46 xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
47 xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
48 std::map<std::string, std::string>* props = storage->getProperties();
51 for (auto const& elm : *props) {
52 xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
57 /** \ingroup msg_storage_management
58 * \brief Change the value of a given storage property
60 * \param storage a storage
61 * \param name a property name
62 * \param value what to change the property to
64 void MSG_storage_set_property_value(msg_storage_t storage, const char* name, char* value)
66 storage->setProperty(name, value);
69 /** \ingroup m_storage_management
70 * \brief Returns the value of a given storage property
72 * \param storage a storage
73 * \param name a property name
74 * \return value of a property (or nullptr if property not set)
76 const char *MSG_storage_get_property_value(msg_storage_t storage, const char *name)
78 return storage->getProperty(name);
81 /** \ingroup msg_storage_management
82 * \brief Finds a msg_storage_t using its name.
83 * \param name the name of a storage
84 * \return the corresponding storage
86 msg_storage_t MSG_storage_get_by_name(const char *name)
88 return simgrid::s4u::Storage::byName(name);
91 /** \ingroup msg_storage_management
92 * \brief Returns a dynar containing all the storage elements declared at a given point of time
94 xbt_dynar_t MSG_storages_as_dynar()
96 std::map<std::string, simgrid::s4u::Storage*>* storage_list = new std::map<std::string, simgrid::s4u::Storage*>;
97 simgrid::s4u::getStorageList(storage_list);
98 xbt_dynar_t res = xbt_dynar_new(sizeof(msg_storage_t),nullptr);
99 for (auto const& s : *storage_list)
100 xbt_dynar_push(res, &(s.second));
105 void* MSG_storage_get_data(msg_storage_t storage)
107 xbt_assert((storage != nullptr), "Invalid parameters");
108 return storage->getUserdata();
111 msg_error_t MSG_storage_set_data(msg_storage_t storage, void *data)
113 storage->setUserdata(data);
117 sg_size_t MSG_storage_read(msg_storage_t storage, sg_size_t size)
119 return storage->read(size);
122 sg_size_t MSG_storage_write(msg_storage_t storage, sg_size_t size)
124 return storage->write(size);