1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include <xbt/signal.hpp>
10 #include "surf_interface.hpp"
11 #include "src/surf/PropertyHolder.hpp"
13 #ifndef STORAGE_INTERFACE_HPP_
14 #define STORAGE_INTERFACE_HPP_
31 /** @ingroup SURF_callbacks
32 * @brief Callbacks handler which emit the callbacks after Storage creation *
33 * @details Callback functions have the following signature: `void(Storage*)`
35 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*)>) storageCreatedCallbacks;
37 /** @ingroup SURF_callbacks
38 * @brief Callbacks handler which emit the callbacks after Storage destruction *
39 * @details Callback functions have the following signature: `void(StoragePtr)`
41 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*)>) storageDestructedCallbacks;
43 /** @ingroup SURF_callbacks
44 * @brief Callbacks handler which emit the callbacks after Storage State changed *
45 * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int currentlyOn)`
47 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*, int, int)>) storageStateChangedCallbacks;
49 /** @ingroup SURF_callbacks
50 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
51 * @details Callback functions have the following signature: `void(StorageAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)`
53 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)>) storageActionStateChangedCallbacks;
58 /** @ingroup SURF_storage_interface
59 * @brief SURF storage model interface class
60 * @details A model is an object which handle the interactions between its Resources and its Actions
62 class StorageModel : public Model {
67 /** @brief Create a Storage
69 * @param id [description]
70 * @param type_id [description]
71 * @param content_name [description]
72 * @param content_type [description]
73 * @param properties [description]
74 * @param attach [description]
75 * @return The created Storage
77 virtual Storage *createStorage(const char* id, const char* type_id,
78 const char* content_name, const char* content_type,
79 xbt_dict_t properties, const char *attach) = 0;
81 bool next_occuring_event_isIdempotent() {return true;}
83 std::vector<Storage*> p_storageList;
89 /** @ingroup SURF_storage_interface
90 * @brief SURF storage interface class
91 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
93 class Storage : public simgrid::surf::Resource,
94 public simgrid::surf::PropertyHolder {
97 * @brief Storage constructor
99 * @param model StorageModel associated to this Storage
100 * @param name The name of the Storage
101 * @param props Dictionary of properties associated to this Storage
102 * @param type_id [description]
103 * @param content_name [description]
104 * @param content_type [description]
105 * @param size [description]
107 Storage(Model *model, const char *name, xbt_dict_t props,
108 const char* type_id, const char *content_name, const char *content_type,
112 * @brief Storage constructor
114 * @param model StorageModel associated to this Storage
115 * @param name The name of the Storage
116 * @param props Dictionary of properties associated to this Storage
117 * @param maxminSystem [description]
118 * @param bread [description]
119 * @param bwrite [description]
120 * @param bconnection [description]
121 * @param type_id [description]
122 * @param content_name [description]
123 * @param content_type [description]
124 * @param size [description]
125 * @param attach [description]
127 Storage(Model *model, const char *name, xbt_dict_t props,
128 lmm_system_t maxminSystem, double bread, double bwrite,
130 const char* type_id, const char *content_name, const char *content_type,
131 sg_size_t size, const char *attach);
135 /** @brief Check if the Storage is used (if an action currently uses its resources) */
136 bool isUsed() override;
138 void apply_event(tmgr_trace_iterator_t event, double value) override;
140 void turnOn() override;
141 void turnOff() override;
143 xbt_dict_t p_content;
146 sg_size_t m_usedSize;
148 char* p_attach; //FIXME: this is the name of the host. Use the host directly
153 * @param mount The mount point
154 * @param path The path to the file
156 * @return The StorageAction corresponding to the opening
158 virtual StorageAction *open(const char* mount, const char* path)=0;
161 * @brief Close a file
163 * @param fd The file descriptor to close
164 * @return The StorageAction corresponding to the closing
166 virtual StorageAction *close(surf_file_t fd)=0;
171 * @param fd The file descriptor to read
172 * @param size The size in bytes to read
173 * @return The StorageAction corresponding to the reading
175 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
178 * @brief Write a file
180 * @param fd The file descriptor to write
181 * @param size The size in bytes to write
182 * @return The StorageAction corresponding to the writing
184 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
187 * @brief Get the content of the current Storage
189 * @return A xbt_dict_t with path as keys and size in bytes as values
191 virtual xbt_dict_t getContent();
194 * @brief Get the size in bytes of the current Storage
196 * @return The size in bytes of the current Storage
198 virtual sg_size_t getSize();
201 * @brief Get the available size in bytes of the current Storage
203 * @return The available size in bytes of the current Storage
205 virtual sg_size_t getFreeSize();
208 * @brief Get the used size in bytes of the current Storage
210 * @return The used size in bytes of the current Storage
212 virtual sg_size_t getUsedSize();
215 xbt_dict_t parseContent(const char *filename);
217 std::vector<StorageAction*> p_writeActions;
219 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
220 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
227 /** @ingroup SURF_storage_interface
228 * @brief The possible type of action for the storage component
231 READ=0, /**< Read a file */
232 WRITE, /**< Write in a file */
233 STAT, /**< Stat a file */
234 OPEN, /**< Open a file */
235 CLOSE /**< Close a file */
236 } e_surf_action_storage_type_t;
238 /** @ingroup SURF_storage_interface
239 * @brief SURF storage action interface class
241 class StorageAction : public Action {
244 * @brief StorageAction constructor
246 * @param model The StorageModel associated to this StorageAction
247 * @param cost The cost of this NetworkAction in [TODO]
248 * @param failed [description]
249 * @param storage The Storage associated to this StorageAction
250 * @param type [description]
252 StorageAction(Model *model, double cost, bool failed, Storage *storage,
253 e_surf_action_storage_type_t type);
256 * @brief StorageAction constructor
258 * @param model The StorageModel associated to this StorageAction
259 * @param cost The cost of this StorageAction in [TODO]
260 * @param failed [description]
261 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
262 * @param storage The Storage associated to this StorageAction
263 * @param type [description]
265 StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
266 Storage *storage, e_surf_action_storage_type_t type);
268 void setState(simgrid::surf::Action::State state) override;
270 e_surf_action_storage_type_t m_type;
279 typedef struct s_storage_type {
284 xbt_dict_t properties;
285 xbt_dict_t model_properties;
287 } s_storage_type_t, *storage_type_t;
289 typedef struct s_mount {
292 } s_mount_t, *mount_t;
294 typedef struct surf_file {
298 sg_size_t current_position;
301 #endif /* STORAGE_INTERFACE_HPP_ */