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;
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(surf_callback(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(surf_callback(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, e_surf_resource_state_t old, e_surf_resource_state_t current)`
47 XBT_PUBLIC_DATA(surf_callback(void, simgrid::surf::Storage*, e_surf_resource_state_t, e_surf_resource_state_t)) 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, e_surf_action_state_t old, e_surf_action_state_t current)`
53 XBT_PUBLIC_DATA(surf_callback(void, simgrid::surf::StorageAction*, e_surf_action_state_t, e_surf_action_state_t)) 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 {
65 * @brief The storage model constructor
70 * @brief The Storange model destructor
75 * @brief Create a Storage
77 * @param id [description]
78 * @param type_id [description]
79 * @param content_name [description]
80 * @param content_type [description]
81 * @param properties [description]
82 * @param attach [description]
83 * @return The created Storage
85 virtual Storage *createStorage(const char* id,
87 const char* content_name,
88 const char* content_type,
89 xbt_dict_t properties,
90 const char *attach) = 0;
92 bool shareResourcesIsIdempotent() {return true;}
94 xbt_dynar_t p_storageList;
100 /** @ingroup SURF_storage_interface
101 * @brief SURF storage interface class
102 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
104 class Storage : public simgrid::surf::Resource {
107 * @brief Storage constructor
109 * @param model StorageModel associated to this Storage
110 * @param name The name of the Storage
111 * @param props Dictionary of properties associated to this Storage
112 * @param type_id [description]
113 * @param content_name [description]
114 * @param content_type [description]
115 * @param size [description]
117 Storage(Model *model, const char *name, xbt_dict_t props,
118 const char* type_id, char *content_name, char *content_type,
122 * @brief Storage constructor
124 * @param model StorageModel associated to this Storage
125 * @param name The name of the Storage
126 * @param props Dictionary of properties associated to this Storage
127 * @param maxminSystem [description]
128 * @param bread [description]
129 * @param bwrite [description]
130 * @param bconnection [description]
131 * @param type_id [description]
132 * @param content_name [description]
133 * @param content_type [description]
134 * @param size [description]
135 * @param attach [description]
137 Storage(Model *model, const char *name, xbt_dict_t props,
138 lmm_system_t maxminSystem, double bread, double bwrite,
140 const char* type_id, char *content_name, char *content_type,
141 sg_size_t size, char *attach);
144 * @brief Storage destructor
149 * @brief Check if the Storage is used
151 * @return true if the current Storage is used, false otherwise
156 * @brief Update the state of the current Storage
158 * @param event_type [description]
159 * @param value [description]
160 * @param date [description]
162 void updateState(tmgr_trace_event_t event_type, double value, double date);
164 void setState(e_surf_resource_state_t state);
166 xbt_dict_t p_content;
169 sg_size_t m_usedSize;
176 * @param mount The mount point
177 * @param path The path to the file
179 * @return The StorageAction corresponding to the opening
181 virtual StorageAction *open(const char* mount, const char* path)=0;
184 * @brief Close a file
186 * @param fd The file descriptor to close
187 * @return The StorageAction corresponding to the closing
189 virtual StorageAction *close(surf_file_t fd)=0;
194 * @param fd The file descriptor to read
195 * @param size The size in bytes to read
196 * @return The StorageAction corresponding to the reading
198 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
201 * @brief Write a file
203 * @param fd The file descriptor to write
204 * @param size The size in bytes to write
205 * @return The StorageAction corresponding to the writing
207 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
210 * @brief Get the content of the current Storage
212 * @return A xbt_dict_t with path as keys and size in bytes as values
214 virtual xbt_dict_t getContent();
217 * @brief Get the size in bytes of the current Storage
219 * @return The size in bytes of the current Storage
221 virtual sg_size_t getSize();
224 * @brief Get the available size in bytes of the current Storage
226 * @return The available size in bytes of the current Storage
228 virtual sg_size_t getFreeSize();
231 * @brief Get the used size in bytes of the current Storage
233 * @return The used size in bytes of the current Storage
235 virtual sg_size_t getUsedSize();
238 xbt_dict_t parseContent(char *filename);
240 xbt_dynar_t p_writeActions;
242 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
243 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
250 /** @ingroup SURF_storage_interface
251 * @brief The possible type of action for the storage component
254 READ=0, /**< Read a file */
255 WRITE, /**< Write in a file */
256 STAT, /**< Stat a file */
257 OPEN, /**< Open a file */
258 CLOSE /**< Close a file */
259 } e_surf_action_storage_type_t;
261 /** @ingroup SURF_storage_interface
262 * @brief SURF storage action interface class
264 class StorageAction : public Action {
267 * @brief StorageAction constructor
269 * @param model The StorageModel associated to this StorageAction
270 * @param cost The cost of this NetworkAction in [TODO]
271 * @param failed [description]
272 * @param storage The Storage associated to this StorageAction
273 * @param type [description]
275 StorageAction(Model *model, double cost, bool failed, Storage *storage,
276 e_surf_action_storage_type_t type);
279 * @brief StorageAction constructor
281 * @param model The StorageModel associated to this StorageAction
282 * @param cost The cost of this StorageAction in [TODO]
283 * @param failed [description]
284 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
285 * @param storage The Storage associated to this StorageAction
286 * @param type [description]
288 StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
289 Storage *storage, e_surf_action_storage_type_t type);
291 void setState(e_surf_action_state_t state);
293 e_surf_action_storage_type_t m_type;
302 typedef struct s_storage_type {
307 xbt_dict_t properties;
308 xbt_dict_t model_properties;
310 } s_storage_type_t, *storage_type_t;
312 typedef struct s_mount {
315 } s_mount_t, *mount_t;
317 typedef struct surf_file {
321 sg_size_t current_position;
325 #endif /* STORAGE_INTERFACE_HPP_ */