Logo AND Algorithmique Numérique Distribuée

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