Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
56cd22672132d59c6e8e00ae200ea4b5c67902e4
[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 StorageAction;
25 typedef StorageAction *StorageActionPtr;
26
27 /*************
28  * Callbacks *
29  *************/
30
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)`
34  */
35 XBT_PUBLIC_DATA(surf_callback(void, StoragePtr)) storageCreatedCallbacks;
36
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)`
40  */
41 XBT_PUBLIC_DATA(surf_callback(void, StoragePtr)) storageDestructedCallbacks;
42
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)`
46  */
47 XBT_PUBLIC_DATA(surf_callback(void, StoragePtr, e_surf_resource_state_t, e_surf_resource_state_t)) storageStateChangedCallbacks;
48
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)`
52  */
53 XBT_PUBLIC_DATA(surf_callback(void, StorageActionPtr, e_surf_action_state_t, e_surf_action_state_t)) storageActionStateChangedCallbacks;
54
55 /*********
56  * Model *
57  *********/
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
61  */
62 class StorageModel : public Model {
63 public:
64   /**
65    * @brief The storage model constructor
66    */
67   StorageModel();
68
69   /**
70    * @brief The Storange model destructor
71    */
72   ~StorageModel();
73
74   /**
75    * @brief Create a Storage
76    *
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
84    */
85   virtual StoragePtr createStorage(const char* id,
86                                     const char* type_id,
87                                     const char* content_name,
88                                     const char* content_type,
89                                     xbt_dict_t properties,
90                                     const char *attach) = 0;
91
92   xbt_dynar_t p_storageList;
93 };
94
95 /************
96  * Resource *
97  ************/
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)
101  */
102 class Storage : public Resource {
103 public:
104   /**
105    * @brief Storage constructor
106    *
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]
114    */
115   Storage(ModelPtr model, const char *name, xbt_dict_t props,
116           const char* type_id, char *content_name, char *content_type,
117           sg_size_t size);
118
119   /**
120    * @brief Storage constructor
121    *
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]
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, char *attach);
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   char* p_attach;
170
171   /**
172    * @brief Open a file
173    *
174    * @param mount The mount point
175    * @param path The path to the file
176    *
177    * @return The StorageAction corresponding to the opening
178    */
179   virtual StorageActionPtr open(const char* mount, const char* path)=0;
180
181   /**
182    * @brief Close a file
183    *
184    * @param fd The file descriptor to close
185    * @return The StorageAction corresponding to the closing
186    */
187   virtual StorageActionPtr close(surf_file_t fd)=0;
188
189   /**
190    * @brief Read a file
191    *
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
195    */
196   virtual StorageActionPtr read(surf_file_t fd, sg_size_t size)=0;
197
198   /**
199    * @brief Write a file
200    *
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
204    */
205   virtual StorageActionPtr write(surf_file_t fd, sg_size_t size)=0;
206
207   /**
208    * @brief Get the content of the current Storage
209    *
210    * @return A xbt_dict_t with path as keys and size in bytes as values
211    */
212   virtual xbt_dict_t getContent();
213
214   /**
215    * @brief Get the size in bytes of the current Storage
216    *
217    * @return The size in bytes of the current Storage
218    */
219   virtual sg_size_t getSize();
220
221   /**
222    * @brief Get the available size in bytes of the current Storage
223    *
224    * @return The available size in bytes of the current Storage
225    */
226   virtual sg_size_t getFreeSize();
227
228   /**
229    * @brief Get the used size in bytes of the current Storage
230    *
231    * @return The used size in bytes of the current Storage
232    */
233   virtual sg_size_t getUsedSize();
234
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 } e_surf_action_storage_type_t;
258
259 /** @ingroup SURF_storage_interface
260  * @brief SURF storage action interface class
261  */
262 class StorageAction : public Action {
263 public:
264   /**
265    * @brief StorageAction constructor
266    *
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]
272    */
273   StorageAction(ModelPtr model, double cost, bool failed, StoragePtr storage,
274       e_surf_action_storage_type_t type);
275
276     /**
277    * @brief StorageAction constructor
278    *
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]
285    */
286   StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
287       StoragePtr storage, e_surf_action_storage_type_t type);
288
289   void setState(e_surf_action_state_t state);
290
291   e_surf_action_storage_type_t m_type;
292   StoragePtr p_storage;
293   surf_file_t p_file;
294   double progress;
295 };
296
297 typedef struct s_storage_type {
298   char *model;
299   char *content;
300   char *content_type;
301   char *type_id;
302   xbt_dict_t properties;
303   xbt_dict_t model_properties;
304   sg_size_t size;
305 } s_storage_type_t, *storage_type_t;
306
307 typedef struct s_mount {
308   void *storage;
309   char *name;
310 } s_mount_t, *mount_t;
311
312 typedef struct surf_file {
313   char *name;
314   char *mount;
315   sg_size_t size;
316   sg_size_t current_position;
317 } s_surf_file_t;
318
319
320 #endif /* STORAGE_INTERFACE_HPP_ */