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;
19 typedef StorageModel *StorageModelPtr;
22 typedef Storage *StoragePtr;
25 typedef StorageAction *StorageActionPtr;
31 /** @ingroup SURF_callbacks
32 * @brief Callbacks handler which emit the callbacks after Storage creation *
33 * @details Callback functions have the following signature: `void(StoragePtr)`
35 XBT_PUBLIC_DATA(surf_callback(void, StoragePtr)) 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, StoragePtr)) 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(StorageActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
47 XBT_PUBLIC_DATA(surf_callback(void, StoragePtr, 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(StorageActionPtr action, e_surf_action_state_t old, e_surf_action_state_t current)`
53 XBT_PUBLIC_DATA(surf_callback(void, StorageActionPtr, 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 StoragePtr 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 xbt_dynar_t p_storageList;
98 /** @ingroup SURF_storage_interface
99 * @brief SURF storage interface class
100 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
102 class Storage : public Resource {
105 * @brief Storage constructor
107 * @param model StorageModel associated to this Storage
108 * @param name The name of the Storage
109 * @param props Dictionary of properties associated to this Storage
110 * @param type_id [description]
111 * @param content_name [description]
112 * @param content_type [description]
113 * @param size [description]
115 Storage(ModelPtr model, const char *name, xbt_dict_t props,
116 const char* type_id, char *content_name, char *content_type,
120 * @brief Storage constructor
122 * @param model StorageModel associated to this Storage
123 * @param name The name of the Storage
124 * @param props Dictionary of properties associated to this Storage
125 * @param maxminSystem [description]
126 * @param bread [description]
127 * @param bwrite [description]
128 * @param bconnection [description]
129 * @param type_id [description]
130 * @param content_name [description]
131 * @param content_type [description]
132 * @param size [description]
133 * @param attach [description]
135 Storage(ModelPtr model, const char *name, xbt_dict_t props,
136 lmm_system_t maxminSystem, double bread, double bwrite,
138 const char* type_id, char *content_name, char *content_type,
139 sg_size_t size, char *attach);
142 * @brief Storage destructor
147 * @brief Check if the Storage is used
149 * @return true if the current Storage is used, false otherwise
154 * @brief Update the state of the current Storage
156 * @param event_type [description]
157 * @param value [description]
158 * @param date [description]
160 void updateState(tmgr_trace_event_t event_type, double value, double date);
162 void setState(e_surf_resource_state_t state);
164 xbt_dict_t p_content;
167 sg_size_t m_usedSize;
174 * @param mount The mount point
175 * @param path The path to the file
177 * @return The StorageAction corresponding to the opening
179 virtual StorageActionPtr open(const char* mount, const char* path)=0;
182 * @brief Close a file
184 * @param fd The file descriptor to close
185 * @return The StorageAction corresponding to the closing
187 virtual StorageActionPtr close(surf_file_t fd)=0;
192 * @param fd The file descriptor to read
193 * @param size The size in bytes to read
194 * @return The StorageAction corresponding to the reading
196 virtual StorageActionPtr read(surf_file_t fd, sg_size_t size)=0;
199 * @brief Write a file
201 * @param fd The file descriptor to write
202 * @param size The size in bytes to write
203 * @return The StorageAction corresponding to the writing
205 virtual StorageActionPtr write(surf_file_t fd, sg_size_t size)=0;
208 * @brief Get the content of the current Storage
210 * @return A xbt_dict_t with path as keys and size in bytes as values
212 virtual xbt_dict_t getContent();
215 * @brief Get the size in bytes of the current Storage
217 * @return The size in bytes of the current Storage
219 virtual sg_size_t getSize();
222 * @brief Get the available size in bytes of the current Storage
224 * @return The available size in bytes of the current Storage
226 virtual sg_size_t getFreeSize();
229 * @brief Get the used size in bytes of the current Storage
231 * @return The used size in bytes of the current Storage
233 virtual sg_size_t getUsedSize();
236 xbt_dict_t parseContent(char *filename);
238 xbt_dynar_t p_writeActions;
240 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
241 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
248 /** @ingroup SURF_storage_interface
249 * @brief The possible type of action for the storage component
252 READ=0, /**< Read a file */
253 WRITE, /**< Write in a file */
254 STAT, /**< Stat a file */
255 OPEN, /**< Open a file */
256 CLOSE /**< Close a file */
257 } e_surf_action_storage_type_t;
259 /** @ingroup SURF_storage_interface
260 * @brief SURF storage action interface class
262 class StorageAction : public Action {
265 * @brief StorageAction constructor
267 * @param model The StorageModel associated to this StorageAction
268 * @param cost The cost of this NetworkAction in [TODO]
269 * @param failed [description]
270 * @param storage The Storage associated to this StorageAction
271 * @param type [description]
273 StorageAction(ModelPtr model, double cost, bool failed, StoragePtr storage,
274 e_surf_action_storage_type_t type);
277 * @brief StorageAction constructor
279 * @param model The StorageModel associated to this StorageAction
280 * @param cost The cost of this StorageAction in [TODO]
281 * @param failed [description]
282 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
283 * @param storage The Storage associated to this StorageAction
284 * @param type [description]
286 StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
287 StoragePtr storage, e_surf_action_storage_type_t type);
289 void setState(e_surf_action_state_t state);
291 e_surf_action_storage_type_t m_type;
292 StoragePtr p_storage;
297 typedef struct s_storage_type {
302 xbt_dict_t properties;
303 xbt_dict_t model_properties;
305 } s_storage_type_t, *storage_type_t;
307 typedef struct s_mount {
310 } s_mount_t, *mount_t;
312 typedef struct surf_file {
316 sg_size_t current_position;
320 #endif /* STORAGE_INTERFACE_HPP_ */