1 /* Copyright (c) 2004-2014. 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. */
7 #include "surf_interface.hpp"
9 #ifndef STORAGE_INTERFACE_HPP_
10 #define STORAGE_INTERFACE_HPP_
12 extern xbt_dynar_t mount_list;
26 /** @ingroup SURF_callbacks
27 * @brief Callbacks handler which emit the callbacks after Storage creation *
28 * @details Callback functions have the following signature: `void(Storage*)`
30 XBT_PUBLIC_DATA(surf_callback(void, Storage*)) storageCreatedCallbacks;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after Storage destruction *
34 * @details Callback functions have the following signature: `void(StoragePtr)`
36 XBT_PUBLIC_DATA(surf_callback(void, Storage*)) storageDestructedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after Storage State changed *
40 * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
42 XBT_PUBLIC_DATA(surf_callback(void, Storage*, e_surf_resource_state_t, e_surf_resource_state_t)) storageStateChangedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
46 * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
48 XBT_PUBLIC_DATA(surf_callback(void, StorageAction*, e_surf_action_state_t, e_surf_action_state_t)) storageActionStateChangedCallbacks;
53 /** @ingroup SURF_storage_interface
54 * @brief SURF storage model interface class
55 * @details A model is an object which handle the interactions between its Resources and its Actions
57 class StorageModel : public Model {
60 * @brief The storage model constructor
65 * @brief The Storange model destructor
70 * @brief Create a Storage
72 * @param id [description]
73 * @param type_id [description]
74 * @param content_name [description]
75 * @param content_type [description]
76 * @param properties [description]
77 * @param attach [description]
78 * @return The created Storage
80 virtual Storage *createStorage(const char* id,
82 const char* content_name,
83 const char* content_type,
84 xbt_dict_t properties,
85 const char *attach) = 0;
87 xbt_dynar_t p_storageList;
93 /** @ingroup SURF_storage_interface
94 * @brief SURF storage interface class
95 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
97 class Storage : public Resource {
100 * @brief Storage constructor
102 * @param model StorageModel associated to this Storage
103 * @param name The name of the Storage
104 * @param props Dictionary of properties associated to this Storage
105 * @param type_id [description]
106 * @param content_name [description]
107 * @param content_type [description]
108 * @param size [description]
110 Storage(Model *model, const char *name, xbt_dict_t props,
111 const char* type_id, char *content_name, char *content_type,
115 * @brief Storage constructor
117 * @param model StorageModel associated to this Storage
118 * @param name The name of the Storage
119 * @param props Dictionary of properties associated to this Storage
120 * @param maxminSystem [description]
121 * @param bread [description]
122 * @param bwrite [description]
123 * @param bconnection [description]
124 * @param type_id [description]
125 * @param content_name [description]
126 * @param content_type [description]
127 * @param size [description]
128 * @param attach [description]
130 Storage(Model *model, const char *name, xbt_dict_t props,
131 lmm_system_t maxminSystem, double bread, double bwrite,
133 const char* type_id, char *content_name, char *content_type,
134 sg_size_t size, char *attach);
137 * @brief Storage destructor
142 * @brief Check if the Storage is used
144 * @return true if the current Storage is used, false otherwise
149 * @brief Update the state of the current Storage
151 * @param event_type [description]
152 * @param value [description]
153 * @param date [description]
155 void updateState(tmgr_trace_event_t event_type, double value, double date);
157 void setState(e_surf_resource_state_t state);
159 xbt_dict_t p_content;
162 sg_size_t m_usedSize;
169 * @param mount The mount point
170 * @param path The path to the file
172 * @return The StorageAction corresponding to the opening
174 virtual StorageAction *open(const char* mount, const char* path)=0;
177 * @brief Close a file
179 * @param fd The file descriptor to close
180 * @return The StorageAction corresponding to the closing
182 virtual StorageAction *close(surf_file_t fd)=0;
187 * @param fd The file descriptor to read
188 * @param size The size in bytes to read
189 * @return The StorageAction corresponding to the reading
191 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
194 * @brief Write a file
196 * @param fd The file descriptor to write
197 * @param size The size in bytes to write
198 * @return The StorageAction corresponding to the writing
200 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
203 * @brief Get the content of the current Storage
205 * @return A xbt_dict_t with path as keys and size in bytes as values
207 virtual xbt_dict_t getContent();
210 * @brief Get the size in bytes of the current Storage
212 * @return The size in bytes of the current Storage
214 virtual sg_size_t getSize();
217 * @brief Get the available size in bytes of the current Storage
219 * @return The available size in bytes of the current Storage
221 virtual sg_size_t getFreeSize();
224 * @brief Get the used size in bytes of the current Storage
226 * @return The used size in bytes of the current Storage
228 virtual sg_size_t getUsedSize();
231 xbt_dict_t parseContent(char *filename);
233 xbt_dynar_t p_writeActions;
235 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
236 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
243 /** @ingroup SURF_storage_interface
244 * @brief The possible type of action for the storage component
247 READ=0, /**< Read a file */
248 WRITE, /**< Write in a file */
249 STAT, /**< Stat a file */
250 OPEN, /**< Open a file */
251 CLOSE /**< Close a file */
252 } e_surf_action_storage_type_t;
254 /** @ingroup SURF_storage_interface
255 * @brief SURF storage action interface class
257 class StorageAction : public Action {
260 * @brief StorageAction constructor
262 * @param model The StorageModel associated to this StorageAction
263 * @param cost The cost of this NetworkAction in [TODO]
264 * @param failed [description]
265 * @param storage The Storage associated to this StorageAction
266 * @param type [description]
268 StorageAction(Model *model, double cost, bool failed, Storage *storage,
269 e_surf_action_storage_type_t type);
272 * @brief StorageAction constructor
274 * @param model The StorageModel associated to this StorageAction
275 * @param cost The cost of this StorageAction in [TODO]
276 * @param failed [description]
277 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
278 * @param storage The Storage associated to this StorageAction
279 * @param type [description]
281 StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
282 Storage *storage, e_surf_action_storage_type_t type);
284 void setState(e_surf_action_state_t state);
286 e_surf_action_storage_type_t m_type;
292 typedef struct s_storage_type {
297 xbt_dict_t properties;
298 xbt_dict_t model_properties;
300 } s_storage_type_t, *storage_type_t;
302 typedef struct s_mount {
305 } s_mount_t, *mount_t;
307 typedef struct surf_file {
311 sg_size_t current_position;
315 #endif /* STORAGE_INTERFACE_HPP_ */