Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / surf / storage_interface.hpp
1 /* Copyright (c) 2004-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "surf_interface.hpp"
8
9 #ifndef STORAGE_INTERFACE_HPP_
10 #define STORAGE_INTERFACE_HPP_
11
12 extern xbt_dynar_t mount_list;
13
14 /***********
15  * Classes *
16  ***********/
17
18 class StorageModel;
19 typedef StorageModel *StorageModelPtr;
20
21 class Storage;
22 typedef Storage *StoragePtr;
23
24 class Storage;
25 typedef Storage *StoragePtr;
26
27 class StorageAction;
28 typedef StorageAction *StorageActionPtr;
29
30 class StorageAction;
31 typedef StorageAction *StorageActionPtr;
32
33 /*************
34  * Callbacks *
35  *************/
36
37 /** @ingroup SURF_callbacks
38  * @brief Callbacks handler which emit the callbacks after Storage creation *
39  * @details Callback functions have the following signature: `void(StoragePtr)`
40  */
41 extern surf_callback(void, StoragePtr) storageCreatedCallbacks;
42
43 /** @ingroup SURF_callbacks
44  * @brief Callbacks handler which emit the callbacks after Storage destruction *
45  * @details Callback functions have the following signature: `void(StoragePtr)`
46  */
47 extern surf_callback(void, StoragePtr) storageDestructedCallbacks;
48
49 /** @ingroup SURF_callbacks
50  * @brief Callbacks handler which emit the callbacks after Storage State changed *
51  * @details Callback functions have the following signature: `void(StorageActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
52  */
53 extern surf_callback(void, StoragePtr, e_surf_resource_state_t, e_surf_resource_state_t) storageStateChangedCallbacks;
54
55 /** @ingroup SURF_callbacks
56  * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
57  * @details Callback functions have the following signature: `void(StorageActionPtr action, e_surf_action_state_t old, e_surf_action_state_t current)`
58  */
59 extern surf_callback(void, StorageActionPtr, e_surf_action_state_t, e_surf_action_state_t) storageActionStateChangedCallbacks;
60
61 /*********
62  * Model *
63  *********/
64 /** @ingroup SURF_storage_interface
65  * @brief SURF storage model interface class
66  * @details A model is an object which handle the interactions between its Resources and its Actions
67  */
68 class StorageModel : public Model {
69 public:
70   /**
71    * @brief The storage model constructor
72    */
73   StorageModel();
74
75   /**
76    * @brief The Storange model destructor
77    */
78   ~StorageModel();
79
80   /**
81    * @brief Create a Storage
82    *
83    * @param id [description]
84    * @param type_id [description]
85    * @param content_name [description]
86    * @param content_type [description]
87    * @param properties [description]
88    * @param attach [description]
89    * @return The created Storage
90    */
91   virtual StoragePtr createResource(const char* id,
92                                     const char* type_id,
93                                     const char* content_name,
94                                     const char* content_type,
95                                     xbt_dict_t properties,
96                                     const char *attach) = 0;
97
98   xbt_dynar_t p_storageList;
99 };
100
101 /************
102  * Resource *
103  ************/
104 /** @ingroup SURF_storage_interface
105  * @brief SURF storage interface class
106  * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
107  */
108 class Storage : public Resource {
109 public:
110   /**
111    * @brief Storage constructor
112    *
113    * @param model StorageModel associated to this Storage
114    * @param name The name of the Storage
115    * @param props Dictionary of properties associated to this Storage
116    * @param type_id [description]
117    * @param content_name [description]
118    * @param content_type [description]
119    * @param size [description]
120    */
121   Storage(ModelPtr model, const char *name, xbt_dict_t props,
122           const char* type_id, char *content_name, char *content_type,
123           sg_size_t size);
124
125   /**
126    * @brief Storage constructor
127    *
128    * @param model StorageModel associated to this Storage
129    * @param name The name of the Storage
130    * @param props Dictionary of properties associated to this Storage
131    * @param maxminSystem [description]
132    * @param bread [description]
133    * @param bwrite [description]
134    * @param bconnection [description]
135    * @param type_id [description]
136    * @param content_name [description]
137    * @param content_type [description]
138    * @param size [description]
139    * @param attach [description]
140    */
141   Storage(ModelPtr model, const char *name, xbt_dict_t props,
142           lmm_system_t maxminSystem, double bread, double bwrite,
143           double bconnection,
144           const char* type_id, char *content_name, char *content_type,
145           sg_size_t size, char *attach);
146
147   /**
148    * @brief Storage destructor
149    */
150   ~Storage();
151
152   /**
153    * @brief Check if the Storage is used
154    *
155    * @return true if the current Storage is used, false otherwise
156    */
157   bool isUsed();
158
159   /**
160    * @brief Update the state of the current Storage
161    *
162    * @param event_type [description]
163    * @param value [description]
164    * @param date [description]
165    */
166   void updateState(tmgr_trace_event_t event_type, double value, double date);
167
168   void setState(e_surf_resource_state_t state);
169
170   xbt_dict_t p_content;
171   char* p_contentType;
172   sg_size_t m_size;
173   sg_size_t m_usedSize;
174   char * p_typeId;
175   char* p_attach;
176
177   /**
178    * @brief Open a file
179    *
180    * @param mount The mount point
181    * @param path The path to the file
182    *
183    * @return The StorageAction corresponding to the opening
184    */
185   virtual StorageActionPtr open(const char* mount, const char* path)=0;
186
187   /**
188    * @brief Close a file
189    *
190    * @param fd The file descriptor to close
191    * @return The StorageAction corresponding to the closing
192    */
193   virtual StorageActionPtr close(surf_file_t fd)=0;
194
195   /**
196    * @brief List directory contents of a path
197    * @details [long description]
198    *
199    * @param path The path to the directory
200    * @return The StorageAction corresponding to the ls action
201    */
202   virtual StorageActionPtr ls(const char *path)=0;
203
204   /**
205    * @brief Read a file
206    *
207    * @param fd The file descriptor to read
208    * @param size The size in bytes to read
209    * @return The StorageAction corresponding to the reading
210    */
211   virtual StorageActionPtr read(surf_file_t fd, sg_size_t size)=0;
212
213   /**
214    * @brief Write a file
215    *
216    * @param fd The file descriptor to write
217    * @param size The size in bytes to write
218    * @return The StorageAction corresponding to the writing
219    */
220   virtual StorageActionPtr write(surf_file_t fd, sg_size_t size)=0;
221
222   /**
223    * @brief Get the content of the current Storage
224    *
225    * @return A xbt_dict_t with path as keys and size in bytes as values
226    */
227   virtual xbt_dict_t getContent();
228
229   /**
230    * @brief Get the size in bytes of the current Storage
231    *
232    * @return The size in bytes of the current Storage
233    */
234   virtual sg_size_t getSize();
235
236   xbt_dict_t parseContent(char *filename);
237
238   xbt_dynar_t p_writeActions;
239
240   lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
241   lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
242 };
243
244 /**********
245  * Action *
246  **********/
247
248 /** @ingroup SURF_storage_interface
249  * @brief The possible type of action for the storage component
250  */
251 typedef enum {
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   LS      /**< List directory contents */
258 } e_surf_action_storage_type_t;
259
260 /** @ingroup SURF_storage_interface
261  * @brief SURF storage action interface class
262  */
263 class StorageAction : public Action {
264 public:
265   /**
266    * @brief StorageAction constructor
267    */
268   StorageAction() : m_type(READ) {};//FIXME:REMOVE
269
270   /**
271    * @brief StorageAction constructor
272    *
273    * @param model The StorageModel associated to this StorageAction
274    * @param cost The cost of this  NetworkAction in [TODO]
275    * @param failed [description]
276    * @param storage The Storage associated to this StorageAction
277    * @param type [description]
278    */
279   StorageAction(ModelPtr model, double cost, bool failed,
280                             StoragePtr storage, e_surf_action_storage_type_t type);
281
282     /**
283    * @brief StorageAction constructor
284    *
285    * @param model The StorageModel associated to this StorageAction
286    * @param cost The cost of this  StorageAction in [TODO]
287    * @param failed [description]
288    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
289    * @param storage The Storage associated to this StorageAction
290    * @param type [description]
291    */
292   StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
293                             StoragePtr storage, e_surf_action_storage_type_t type);
294
295   void setState(e_surf_action_state_t state);
296
297   e_surf_action_storage_type_t m_type;
298   StoragePtr p_storage;
299   surf_file_t p_file;
300   xbt_dict_t p_lsDict;
301 };
302
303 typedef struct s_storage_type {
304   char *model;
305   char *content;
306   char *content_type;
307   char *type_id;
308   xbt_dict_t properties;
309   xbt_dict_t model_properties;
310   sg_size_t size;
311 } s_storage_type_t, *storage_type_t;
312
313 typedef struct s_mount {
314   void *storage;
315   char *name;
316 } s_mount_t, *mount_t;
317
318 typedef struct surf_file {
319   char *name;
320   char *mount;
321   sg_size_t size;
322   sg_size_t current_position;
323 } s_surf_file_t;
324
325
326 #endif /* STORAGE_INTERFACE_HPP_ */