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 bool shareResourcesIsIdempotent() {return true;}
89 xbt_dynar_t p_storageList;
95 /** @ingroup SURF_storage_interface
96 * @brief SURF storage interface class
97 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
99 class Storage : public Resource {
102 * @brief Storage constructor
104 * @param model StorageModel associated to this Storage
105 * @param name The name of the Storage
106 * @param props Dictionary of properties associated to this Storage
107 * @param type_id [description]
108 * @param content_name [description]
109 * @param content_type [description]
110 * @param size [description]
112 Storage(Model *model, const char *name, xbt_dict_t props,
113 const char* type_id, char *content_name, char *content_type,
117 * @brief Storage constructor
119 * @param model StorageModel associated to this Storage
120 * @param name The name of the Storage
121 * @param props Dictionary of properties associated to this Storage
122 * @param maxminSystem [description]
123 * @param bread [description]
124 * @param bwrite [description]
125 * @param bconnection [description]
126 * @param type_id [description]
127 * @param content_name [description]
128 * @param content_type [description]
129 * @param size [description]
130 * @param attach [description]
132 Storage(Model *model, const char *name, xbt_dict_t props,
133 lmm_system_t maxminSystem, double bread, double bwrite,
135 const char* type_id, char *content_name, char *content_type,
136 sg_size_t size, char *attach);
139 * @brief Storage destructor
144 * @brief Check if the Storage is used
146 * @return true if the current Storage is used, false otherwise
151 * @brief Update the state of the current Storage
153 * @param event_type [description]
154 * @param value [description]
155 * @param date [description]
157 void updateState(tmgr_trace_event_t event_type, double value, double date);
159 void setState(e_surf_resource_state_t state);
161 xbt_dict_t p_content;
164 sg_size_t m_usedSize;
171 * @param mount The mount point
172 * @param path The path to the file
174 * @return The StorageAction corresponding to the opening
176 virtual StorageAction *open(const char* mount, const char* path)=0;
179 * @brief Close a file
181 * @param fd The file descriptor to close
182 * @return The StorageAction corresponding to the closing
184 virtual StorageAction *close(surf_file_t fd)=0;
189 * @param fd The file descriptor to read
190 * @param size The size in bytes to read
191 * @return The StorageAction corresponding to the reading
193 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
196 * @brief Write a file
198 * @param fd The file descriptor to write
199 * @param size The size in bytes to write
200 * @return The StorageAction corresponding to the writing
202 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
205 * @brief Get the content of the current Storage
207 * @return A xbt_dict_t with path as keys and size in bytes as values
209 virtual xbt_dict_t getContent();
212 * @brief Get the size in bytes of the current Storage
214 * @return The size in bytes of the current Storage
216 virtual sg_size_t getSize();
219 * @brief Get the available size in bytes of the current Storage
221 * @return The available size in bytes of the current Storage
223 virtual sg_size_t getFreeSize();
226 * @brief Get the used size in bytes of the current Storage
228 * @return The used size in bytes of the current Storage
230 virtual sg_size_t getUsedSize();
233 xbt_dict_t parseContent(char *filename);
235 xbt_dynar_t p_writeActions;
237 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
238 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
245 /** @ingroup SURF_storage_interface
246 * @brief The possible type of action for the storage component
249 READ=0, /**< Read a file */
250 WRITE, /**< Write in a file */
251 STAT, /**< Stat a file */
252 OPEN, /**< Open a file */
253 CLOSE /**< Close a file */
254 } e_surf_action_storage_type_t;
256 /** @ingroup SURF_storage_interface
257 * @brief SURF storage action interface class
259 class StorageAction : public Action {
262 * @brief StorageAction constructor
264 * @param model The StorageModel associated to this StorageAction
265 * @param cost The cost of this NetworkAction in [TODO]
266 * @param failed [description]
267 * @param storage The Storage associated to this StorageAction
268 * @param type [description]
270 StorageAction(Model *model, double cost, bool failed, Storage *storage,
271 e_surf_action_storage_type_t type);
274 * @brief StorageAction constructor
276 * @param model The StorageModel associated to this StorageAction
277 * @param cost The cost of this StorageAction in [TODO]
278 * @param failed [description]
279 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
280 * @param storage The Storage associated to this StorageAction
281 * @param type [description]
283 StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
284 Storage *storage, e_surf_action_storage_type_t type);
286 void setState(e_surf_action_state_t state);
288 e_surf_action_storage_type_t m_type;
294 typedef struct s_storage_type {
299 xbt_dict_t properties;
300 xbt_dict_t model_properties;
302 } s_storage_type_t, *storage_type_t;
304 typedef struct s_mount {
307 } s_mount_t, *mount_t;
309 typedef struct surf_file {
313 sg_size_t current_position;
317 #endif /* STORAGE_INTERFACE_HPP_ */