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)`
52  */
53 extern surf_callback(void, StoragePtr) 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)`
58  */
59 extern surf_callback(void, StorageActionPtr) 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    * @return The created Storage
89    */
90   virtual StoragePtr createResource(const char* id, const char* type_id,
91                    const char* content_name, const char* content_type, xbt_dict_t properties)=0;
92
93   xbt_dynar_t p_storageList;
94 };
95
96 /************
97  * Resource *
98  ************/
99 /** @ingroup SURF_storage_interface
100  * @brief SURF storage interface class
101  * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
102  */
103 class Storage : public Resource {
104 public:
105   /**
106    * @brief Storage constructor
107    * 
108    * @param model StorageModel associated to this Storage
109    * @param name The name of the Storage
110    * @param props Dictionary of properties associated to this Storage
111    * @param type_id [description]
112    * @param content_name [description]
113    * @param content_type [description]
114    * @param size [description]
115    */
116   Storage(ModelPtr model, const char *name, xbt_dict_t props,
117           const char* type_id, char *content_name, char *content_type,
118           sg_size_t size);
119
120   /**
121    * @brief Storage constructor
122    * 
123    * @param model StorageModel associated to this Storage
124    * @param name The name of the Storage
125    * @param props Dictionary of properties associated to this Storage
126    * @param maxminSystem [description]
127    * @param bread [description]
128    * @param bwrite [description]
129    * @param bconnection [description]
130    * @param type_id [description]
131    * @param content_name [description]
132    * @param content_type [description]
133    * @param size [description]
134    */
135   Storage(ModelPtr model, const char *name, xbt_dict_t props,
136           lmm_system_t maxminSystem, double bread, double bwrite,
137           double bconnection,
138           const char* type_id, char *content_name, char *content_type,
139           sg_size_t size);
140
141   /**
142    * @brief Storage destructor
143    */
144   ~Storage();
145
146   /**
147    * @brief Check if the Storage is used
148    * 
149    * @return true if the current Storage is used, false otherwise
150    */
151   bool isUsed();
152
153   /**
154    * @brief Update the state of the current Storage
155    * 
156    * @param event_type [description]
157    * @param value [description]
158    * @param date [description]
159    */
160   void updateState(tmgr_trace_event_t event_type, double value, double date);
161
162   void setState(e_surf_resource_state_t state);
163
164   xbt_dict_t p_content;
165   char* p_contentType;
166   sg_size_t m_size;
167   sg_size_t m_usedSize;
168   char * p_typeId;
169
170   /**
171    * @brief Open a file
172    * 
173    * @param mount The mount point
174    * @param path The path to the file
175    * 
176    * @return The StorageAction corresponding to the opening
177    */
178   virtual StorageActionPtr open(const char* mount, const char* path)=0;
179
180   /**
181    * @brief Close a file
182    * 
183    * @param fd The file descriptor to close
184    * @return The StorageAction corresponding to the closing
185    */
186   virtual StorageActionPtr close(surf_file_t fd)=0;
187
188   /**
189    * @brief List directory contents of a path
190    * @details [long description]
191    * 
192    * @param path The path to the directory
193    * @return The StorageAction corresponding to the ls action
194    */
195   virtual StorageActionPtr ls(const char *path)=0;
196
197   /**
198    * @brief Read a file
199    * 
200    * @param fd The file descriptor to read
201    * @param size The size in bytes to read
202    * @return The StorageAction corresponding to the reading
203    */
204   virtual StorageActionPtr read(surf_file_t fd, sg_size_t size)=0;
205
206   /**
207    * @brief Write a file
208    * 
209    * @param fd The file descriptor to write
210    * @param size The size in bytes to write
211    * @return The StorageAction corresponding to the writing
212    */
213   virtual StorageActionPtr write(surf_file_t fd, sg_size_t size)=0;
214
215   /**
216    * @brief Rename a path
217    * 
218    * @param src The old path
219    * @param dest The new path
220    */
221   virtual void rename(const char *src, const char *dest)=0;
222
223   /**
224    * @brief Get the content of the current Storage
225    * 
226    * @return A xbt_dict_t with path as keys and size in bytes as values
227    */
228   virtual xbt_dict_t getContent();
229
230   /**
231    * @brief Get the size in bytes of the current Storage
232    * 
233    * @return The size in bytes of the current Storage
234    */
235   virtual sg_size_t getSize();
236
237   xbt_dict_t parseContent(char *filename);
238
239   xbt_dynar_t p_writeActions;
240
241   lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
242   lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
243 };
244
245 /**********
246  * Action *
247  **********/
248
249 /** @ingroup SURF_storage_interface
250  * @brief The possible type of action for the storage component
251  */
252 typedef enum {
253   READ=0, /**< Read a file */
254   WRITE,  /**< Write in a file */
255   STAT,   /**< Stat a file */
256   OPEN,   /**< Open a file */
257   CLOSE,  /**< Close a file */
258   LS      /**< List directory contents */
259 } e_surf_action_storage_type_t;
260
261 /** @ingroup SURF_storage_interface
262  * @brief SURF storage action interface class
263  */
264 class StorageAction : public Action {
265 public:
266   /**
267    * @brief StorageAction constructor
268    */
269   StorageAction() : m_type(READ) {};//FIXME:REMOVE
270
271   /**
272    * @brief StorageAction constructor
273    * 
274    * @param model The StorageModel associated to this StorageAction
275    * @param cost The cost of this  NetworkAction in [TODO]
276    * @param failed [description]
277    * @param storage The Storage associated to this StorageAction
278    * @param type [description]
279    */
280   StorageAction(ModelPtr model, double cost, bool failed,
281                             StoragePtr storage, e_surf_action_storage_type_t type);
282
283     /**
284    * @brief StorageAction constructor
285    * 
286    * @param model The StorageModel associated to this StorageAction
287    * @param cost The cost of this  StorageAction in [TODO]
288    * @param failed [description]
289    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
290    * @param storage The Storage associated to this StorageAction
291    * @param type [description]
292    */
293   StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
294                             StoragePtr storage, e_surf_action_storage_type_t type);
295
296   void setState(e_surf_action_state_t state);
297
298   e_surf_action_storage_type_t m_type;
299   StoragePtr p_storage;
300   surf_file_t p_file;
301   xbt_dict_t p_lsDict;
302 };
303
304 typedef struct s_storage_type {
305   char *model;
306   char *content;
307   char *content_type;
308   char *type_id;
309   xbt_dict_t 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_ */