Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / msg / msg_io.cpp
1 /* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
10 #include <numeric>
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_io, msg, "Logging specific to MSG (io)");
13
14 extern "C" {
15
16 /********************************* Storage **************************************/
17 /** @addtogroup msg_storage_management
18  * (#msg_storage_t) and the functions for managing it.
19  */
20
21 /** \ingroup msg_storage_management
22  *
23  * \brief Returns the name of the #msg_storage_t.
24  *
25  * This functions checks whether a storage is a valid pointer or not and return its name.
26  */
27 const char* MSG_storage_get_name(msg_storage_t storage)
28 {
29   xbt_assert((storage != nullptr), "Invalid parameters");
30   return storage->getCname();
31 }
32
33 const char* MSG_storage_get_host(msg_storage_t storage)
34 {
35   xbt_assert((storage != nullptr), "Invalid parameters");
36   return storage->getHost()->getCname();
37 }
38
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
43  */
44 xbt_dict_t MSG_storage_get_properties(msg_storage_t storage)
45 {
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();
49   if (props == nullptr)
50     return nullptr;
51   for (auto const& elm : *props) {
52     xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
53   }
54   return as_dict;
55 }
56
57 /** \ingroup msg_storage_management
58  * \brief Change the value of a given storage property
59  *
60  * \param storage a storage
61  * \param name a property name
62  * \param value what to change the property to
63  */
64 void MSG_storage_set_property_value(msg_storage_t storage, const char* name, char* value)
65 {
66   storage->setProperty(name, value);
67 }
68
69 /** \ingroup m_storage_management
70  * \brief Returns the value of a given storage property
71  *
72  * \param storage a storage
73  * \param name a property name
74  * \return value of a property (or nullptr if property not set)
75  */
76 const char *MSG_storage_get_property_value(msg_storage_t storage, const char *name)
77 {
78   return storage->getProperty(name);
79 }
80
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
85  */
86 msg_storage_t MSG_storage_get_by_name(const char *name)
87 {
88   return simgrid::s4u::Storage::byName(name);
89 }
90
91 /** \ingroup msg_storage_management
92  * \brief Returns a dynar containing all the storage elements declared at a given point of time
93  */
94 xbt_dynar_t MSG_storages_as_dynar()
95 {
96   std::map<std::string, simgrid::s4u::Storage*>* storage_map = simgrid::s4u::allStorages();
97   xbt_dynar_t res = xbt_dynar_new(sizeof(msg_storage_t),nullptr);
98   for (auto const& s : *storage_map)
99     xbt_dynar_push(res, &(s.second));
100   delete storage_map;
101   return res;
102 }
103
104 void* MSG_storage_get_data(msg_storage_t storage)
105 {
106   xbt_assert((storage != nullptr), "Invalid parameters");
107   return storage->getUserdata();
108 }
109
110 msg_error_t MSG_storage_set_data(msg_storage_t storage, void *data)
111 {
112   storage->setUserdata(data);
113   return MSG_OK;
114 }
115
116 sg_size_t MSG_storage_read(msg_storage_t storage, sg_size_t size)
117 {
118   return storage->read(size);
119 }
120
121 sg_size_t MSG_storage_write(msg_storage_t storage, sg_size_t size)
122 {
123   return storage->write(size);
124 }
125
126 }