Logo AND Algorithmique Numérique Distribuée

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