Logo AND Algorithmique Numérique Distribuée

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