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. */
9 #include "surf_interface.hpp"
11 #ifndef STORAGE_INTERFACE_HPP_
12 #define STORAGE_INTERFACE_HPP_
14 extern xbt_dynar_t mount_list;
28 /** @ingroup SURF_callbacks
29 * @brief Callbacks handler which emit the callbacks after Storage creation *
30 * @details Callback functions have the following signature: `void(Storage*)`
32 XBT_PUBLIC_DATA(surf_callback(void, Storage*)) storageCreatedCallbacks;
34 /** @ingroup SURF_callbacks
35 * @brief Callbacks handler which emit the callbacks after Storage destruction *
36 * @details Callback functions have the following signature: `void(StoragePtr)`
38 XBT_PUBLIC_DATA(surf_callback(void, Storage*)) storageDestructedCallbacks;
40 /** @ingroup SURF_callbacks
41 * @brief Callbacks handler which emit the callbacks after Storage State changed *
42 * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
44 XBT_PUBLIC_DATA(surf_callback(void, Storage*, e_surf_resource_state_t, e_surf_resource_state_t)) storageStateChangedCallbacks;
46 /** @ingroup SURF_callbacks
47 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
48 * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
50 XBT_PUBLIC_DATA(surf_callback(void, StorageAction*, e_surf_action_state_t, e_surf_action_state_t)) storageActionStateChangedCallbacks;
55 /** @ingroup SURF_storage_interface
56 * @brief SURF storage model interface class
57 * @details A model is an object which handle the interactions between its Resources and its Actions
59 class StorageModel : public Model {
62 * @brief The storage model constructor
67 * @brief The Storange model destructor
72 * @brief Create a Storage
74 * @param id [description]
75 * @param type_id [description]
76 * @param content_name [description]
77 * @param content_type [description]
78 * @param properties [description]
79 * @param attach [description]
80 * @return The created Storage
82 virtual Storage *createStorage(const char* id,
84 const char* content_name,
85 const char* content_type,
86 xbt_dict_t properties,
87 const char *attach) = 0;
89 bool shareResourcesIsIdempotent() {return true;}
91 xbt_dynar_t p_storageList;
97 /** @ingroup SURF_storage_interface
98 * @brief SURF storage interface class
99 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
101 class Storage : public Resource {
104 * @brief Storage constructor
106 * @param model StorageModel associated to this Storage
107 * @param name The name of the Storage
108 * @param props Dictionary of properties associated to this Storage
109 * @param type_id [description]
110 * @param content_name [description]
111 * @param content_type [description]
112 * @param size [description]
114 Storage(Model *model, const char *name, xbt_dict_t props,
115 const char* type_id, char *content_name, char *content_type,
119 * @brief Storage constructor
121 * @param model StorageModel associated to this Storage
122 * @param name The name of the Storage
123 * @param props Dictionary of properties associated to this Storage
124 * @param maxminSystem [description]
125 * @param bread [description]
126 * @param bwrite [description]
127 * @param bconnection [description]
128 * @param type_id [description]
129 * @param content_name [description]
130 * @param content_type [description]
131 * @param size [description]
132 * @param attach [description]
134 Storage(Model *model, const char *name, xbt_dict_t props,
135 lmm_system_t maxminSystem, double bread, double bwrite,
137 const char* type_id, char *content_name, char *content_type,
138 sg_size_t size, char *attach);
141 * @brief Storage destructor
146 * @brief Check if the Storage is used
148 * @return true if the current Storage is used, false otherwise
153 * @brief Update the state of the current Storage
155 * @param event_type [description]
156 * @param value [description]
157 * @param date [description]
159 void updateState(tmgr_trace_event_t event_type, double value, double date);
161 void setState(e_surf_resource_state_t state);
163 xbt_dict_t p_content;
166 sg_size_t m_usedSize;
173 * @param mount The mount point
174 * @param path The path to the file
176 * @return The StorageAction corresponding to the opening
178 virtual StorageAction *open(const char* mount, const char* path)=0;
181 * @brief Close a file
183 * @param fd The file descriptor to close
184 * @return The StorageAction corresponding to the closing
186 virtual StorageAction *close(surf_file_t fd)=0;
191 * @param fd The file descriptor to read
192 * @param size The size in bytes to read
193 * @return The StorageAction corresponding to the reading
195 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
198 * @brief Write a file
200 * @param fd The file descriptor to write
201 * @param size The size in bytes to write
202 * @return The StorageAction corresponding to the writing
204 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
207 * @brief Get the content of the current Storage
209 * @return A xbt_dict_t with path as keys and size in bytes as values
211 virtual xbt_dict_t getContent();
214 * @brief Get the size in bytes of the current Storage
216 * @return The size in bytes of the current Storage
218 virtual sg_size_t getSize();
221 * @brief Get the available size in bytes of the current Storage
223 * @return The available size in bytes of the current Storage
225 virtual sg_size_t getFreeSize();
228 * @brief Get the used size in bytes of the current Storage
230 * @return The used size in bytes of the current Storage
232 virtual sg_size_t getUsedSize();
235 xbt_dict_t parseContent(char *filename);
237 xbt_dynar_t p_writeActions;
239 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
240 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
247 /** @ingroup SURF_storage_interface
248 * @brief The possible type of action for the storage component
251 READ=0, /**< Read a file */
252 WRITE, /**< Write in a file */
253 STAT, /**< Stat a file */
254 OPEN, /**< Open a file */
255 CLOSE /**< Close a file */
256 } e_surf_action_storage_type_t;
258 /** @ingroup SURF_storage_interface
259 * @brief SURF storage action interface class
261 class StorageAction : public Action {
264 * @brief StorageAction constructor
266 * @param model The StorageModel associated to this StorageAction
267 * @param cost The cost of this NetworkAction in [TODO]
268 * @param failed [description]
269 * @param storage The Storage associated to this StorageAction
270 * @param type [description]
272 StorageAction(Model *model, double cost, bool failed, Storage *storage,
273 e_surf_action_storage_type_t type);
276 * @brief StorageAction constructor
278 * @param model The StorageModel associated to this StorageAction
279 * @param cost The cost of this StorageAction in [TODO]
280 * @param failed [description]
281 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
282 * @param storage The Storage associated to this StorageAction
283 * @param type [description]
285 StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
286 Storage *storage, e_surf_action_storage_type_t type);
288 void setState(e_surf_action_state_t state);
290 e_surf_action_storage_type_t m_type;
296 typedef struct s_storage_type {
301 xbt_dict_t properties;
302 xbt_dict_t model_properties;
304 } s_storage_type_t, *storage_type_t;
306 typedef struct s_mount {
309 } s_mount_t, *mount_t;
311 typedef struct surf_file {
315 sg_size_t current_position;
319 #endif /* STORAGE_INTERFACE_HPP_ */