1 /* Copyright (c) 2004-2013. 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 Storage *StoragePtr;
28 typedef StorageAction *StorageActionPtr;
31 typedef StorageAction *StorageActionPtr;
36 /** @ingroup SURF_storage_interface
37 * @brief SURF storage model interface class
38 * @details A model is an object which handle the interactions between its Resources and its Actions
40 class StorageModel : public Model {
43 * @brief The storage model constructor
48 * @brief The Storange model destructor
53 * @brief Create a Storage
55 * @param id [description]
56 * @param type_id [description]
57 * @param content_name [description]
58 * @param content_type [description]
59 * @param properties [description]
60 * @return The created Storage
62 virtual StoragePtr createResource(const char* id, const char* type_id,
63 const char* content_name, const char* content_type, xbt_dict_t properties)=0;
65 xbt_dynar_t p_storageList;
71 /** @ingroup SURF_storage_interface
72 * @brief SURF storage interface class
73 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
75 class Storage : public Resource {
78 * @brief Storage constructor
80 * @param model StorageModel associated to this Storage
81 * @param name The name of the Storage
82 * @param props Dictionary of properties associated to this Storage
83 * @param constraint The lmm constraint associated to this Storage if it is part of a LMM component
84 * @param model [description]
85 * @param name [description]
86 * @param props [description]
87 * @param type_id [description]
88 * @param content_name [description]
89 * @param content_type [description]
90 * @param size [description]
92 Storage(ModelPtr model, const char *name, xbt_dict_t props,
93 const char* type_id, char *content_name, char *content_type, sg_size_t size);
96 * @brief Storage constructor
98 * @param model StorageModel associated to this Storage
99 * @param name The name of the Storage
100 * @param props Dictionary of properties associated to this Storage
101 * @param constraint The lmm constraint associated to this Storage if it is part of a LMM component
102 * @param maxminSystem [description]
103 * @param bread [description]
104 * @param bwrite [description]
105 * @param bconnection [description]
106 * @param type_id [description]
107 * @param content_name [description]
108 * @param content_type [description]
109 * @param size [description]
111 Storage(ModelPtr model, const char *name, xbt_dict_t props,
112 lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
113 const char* type_id, char *content_name, char *content_type, sg_size_t size);
116 * @brief Storage destructor
121 * @brief Check if the Storage is used
123 * @return true if the current Storage is used, false otherwise
128 * @brief Update the state of the current Storage
130 * @param event_type [description]
131 * @param value [description]
132 * @param date [description]
134 void updateState(tmgr_trace_event_t event_type, double value, double date);
136 xbt_dict_t p_content;
139 sg_size_t m_usedSize;
145 * @param mount The mount point
146 * @param path The path to the file
148 * @return The StorageAction corresponding to the opening
150 virtual StorageActionPtr open(const char* mount, const char* path)=0;
153 * @brief Close a file
155 * @param fd The file descriptor to close
156 * @return The StorageAction corresponding to the closing
158 virtual StorageActionPtr close(surf_file_t fd)=0;
161 * @brief List directory contents of a path
162 * @details [long description]
164 * @param path The path to the directory
165 * @return The StorageAction corresponding to the ls action
167 virtual StorageActionPtr ls(const char *path)=0;
172 * @param fd The file descriptor to read
173 * @param size The size in bytes to read
174 * @return The StorageAction corresponding to the reading
176 virtual StorageActionPtr read(surf_file_t fd, sg_size_t size)=0;
179 * @brief Write a file
181 * @param fd The file descriptor to write
182 * @param size The size in bytes to write
183 * @return The StorageAction corresponding to the writing
185 virtual StorageActionPtr write(surf_file_t fd, sg_size_t size)=0;
188 * @brief Rename a path
190 * @param src The old path
191 * @param dest The new path
193 virtual void rename(const char *src, const char *dest)=0;
196 * @brief Get the content of the current Storage
198 * @return A xbt_dict_t with path as keys and size in bytes as values
200 virtual xbt_dict_t getContent();
203 * @brief Get the size in bytes of the current Storage
205 * @return The size in bytes of the current Storage
207 virtual sg_size_t getSize();
209 xbt_dict_t parseContent(char *filename);
211 xbt_dynar_t p_writeActions;
213 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
214 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
221 /** @ingroup SURF_storage_interface
222 * @brief The possible type of action for the storage component
225 READ=0, /**< Read a file */
226 WRITE, /**< Write in a file */
227 STAT, /**< Stat a file */
228 OPEN, /**< Open a file */
229 CLOSE, /**< Close a file */
230 LS /**< List directory contents */
231 } e_surf_action_storage_type_t;
233 /** @ingroup SURF_storage_interface
234 * @brief SURF storage action interface class
236 class StorageAction : public Action {
239 * @brief StorageAction constructor
241 StorageAction() : m_type(READ) {};//FIXME:REMOVE
244 * @brief StorageAction constructor
246 * @param model The StorageModel associated to this StorageAction
247 * @param cost The cost of this NetworkAction in [TODO]
248 * @param failed [description]
249 * @param storage The Storage associated to this StorageAction
250 * @param type [description]
252 StorageAction(ModelPtr model, double cost, bool failed,
253 StoragePtr storage, e_surf_action_storage_type_t type);
256 * @brief StorageAction constructor
258 * @param model The StorageModel associated to this StorageAction
259 * @param cost The cost of this StorageAction in [TODO]
260 * @param failed [description]
261 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
262 * @param storage The Storage associated to this StorageAction
263 * @param type [description]
265 StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
266 StoragePtr storage, e_surf_action_storage_type_t type);
268 e_surf_action_storage_type_t m_type;
269 StoragePtr p_storage;
274 typedef struct s_storage_type {
279 xbt_dict_t properties;
281 } s_storage_type_t, *storage_type_t;
283 typedef struct s_mount {
286 } s_mount_t, *mount_t;
288 typedef struct surf_file {
292 sg_size_t current_position;
296 #endif /* STORAGE_INTERFACE_HPP_ */