Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3ba65bf50b3ba682f2f66b918757af3a87468e95
[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 #include <xbt/signal.hpp>
9
10 #include "surf_interface.hpp"
11 #include "src/surf/PropertyHolder.hpp"
12
13 #ifndef STORAGE_INTERFACE_HPP_
14 #define STORAGE_INTERFACE_HPP_
15
16 namespace simgrid {
17 namespace surf {
18
19 /***********
20  * Classes *
21  ***********/
22
23 class StorageModel;
24 class Storage;
25 class StorageAction;
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(Storage*)`
34  */
35 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*)>) 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(simgrid::xbt::signal<void(simgrid::surf::Storage*)>) 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(StorageAction *action, int previouslyOn, int currentlyOn)`
46  */
47 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*, int, int)>) 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(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
52  */
53 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, 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   StorageModel();
65   ~StorageModel();
66
67   /** @brief Create a Storage
68    *
69    * @param id [description]
70    * @param type_id [description]
71    * @param content_name [description]
72    * @param content_type [description]
73    * @param properties [description]
74    * @param attach [description]
75    * @return The created Storage
76    */
77   virtual Storage *createStorage(const char* id,
78                                     const char* type_id,
79                                     const char* content_name,
80                                     const char* content_type,
81                                     xbt_dict_t properties,
82                                     const char *attach) = 0;
83
84   bool next_occuring_event_isIdempotent() {return true;}
85
86   xbt_dynar_t p_storageList;
87 };
88
89 /************
90  * Resource *
91  ************/
92 /** @ingroup SURF_storage_interface
93  * @brief SURF storage interface class
94  * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
95  */
96 class Storage : public simgrid::surf::Resource,
97         public simgrid::surf::PropertyHolder {
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, const char *content_name, const 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, const char *content_name, const char *content_type,
134           sg_size_t size, const char *attach);
135
136   ~Storage();
137
138   /** @brief Check if the Storage is used (if an action currently uses its resources) */
139   bool isUsed() override;
140
141   void apply_event(tmgr_trace_iterator_t event, double value) override;
142
143   void turnOn() override;
144   void turnOff() override;
145
146   xbt_dict_t p_content;
147   char* p_contentType;
148   sg_size_t m_size;
149   sg_size_t m_usedSize;
150   char * p_typeId;
151   char* p_attach; //FIXME: this is the name of the host. Use the host directly
152
153   /**
154    * @brief Open a file
155    *
156    * @param mount The mount point
157    * @param path The path to the file
158    *
159    * @return The StorageAction corresponding to the opening
160    */
161   virtual StorageAction *open(const char* mount, const char* path)=0;
162
163   /**
164    * @brief Close a file
165    *
166    * @param fd The file descriptor to close
167    * @return The StorageAction corresponding to the closing
168    */
169   virtual StorageAction *close(surf_file_t fd)=0;
170
171   /**
172    * @brief Read a file
173    *
174    * @param fd The file descriptor to read
175    * @param size The size in bytes to read
176    * @return The StorageAction corresponding to the reading
177    */
178   virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
179
180   /**
181    * @brief Write a file
182    *
183    * @param fd The file descriptor to write
184    * @param size The size in bytes to write
185    * @return The StorageAction corresponding to the writing
186    */
187   virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
188
189   /**
190    * @brief Get the content of the current Storage
191    *
192    * @return A xbt_dict_t with path as keys and size in bytes as values
193    */
194   virtual xbt_dict_t getContent();
195
196   /**
197    * @brief Get the size in bytes of the current Storage
198    *
199    * @return The size in bytes of the current Storage
200    */
201   virtual sg_size_t getSize();
202
203   /**
204    * @brief Get the available size in bytes of the current Storage
205    *
206    * @return The available size in bytes of the current Storage
207    */
208   virtual sg_size_t getFreeSize();
209
210   /**
211    * @brief Get the used size in bytes of the current Storage
212    *
213    * @return The used size in bytes of the current Storage
214    */
215   virtual sg_size_t getUsedSize();
216
217
218   xbt_dict_t parseContent(const char *filename);
219
220   xbt_dynar_t p_writeActions;
221
222   lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
223   lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
224 };
225
226 /**********
227  * Action *
228  **********/
229
230 /** @ingroup SURF_storage_interface
231  * @brief The possible type of action for the storage component
232  */
233 typedef enum {
234   READ=0, /**< Read a file */
235   WRITE,  /**< Write in a file */
236   STAT,   /**< Stat a file */
237   OPEN,   /**< Open a file */
238   CLOSE  /**< Close a file */
239 } e_surf_action_storage_type_t;
240
241 /** @ingroup SURF_storage_interface
242  * @brief SURF storage action interface class
243  */
244 class StorageAction : public Action {
245 public:
246   /**
247    * @brief StorageAction constructor
248    *
249    * @param model The StorageModel associated to this StorageAction
250    * @param cost The cost of this  NetworkAction in [TODO]
251    * @param failed [description]
252    * @param storage The Storage associated to this StorageAction
253    * @param type [description]
254    */
255   StorageAction(Model *model, double cost, bool failed, Storage *storage,
256       e_surf_action_storage_type_t type);
257
258     /**
259    * @brief StorageAction constructor
260    *
261    * @param model The StorageModel associated to this StorageAction
262    * @param cost The cost of this  StorageAction in [TODO]
263    * @param failed [description]
264    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
265    * @param storage The Storage associated to this StorageAction
266    * @param type [description]
267    */
268   StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
269       Storage *storage, e_surf_action_storage_type_t type);
270
271   void setState(e_surf_action_state_t state);
272
273   e_surf_action_storage_type_t m_type;
274   Storage *p_storage;
275   surf_file_t p_file;
276   double progress;
277 };
278
279 }
280 }
281
282 typedef struct s_storage_type {
283   char *model;
284   char *content;
285   char *content_type;
286   char *type_id;
287   xbt_dict_t properties;
288   xbt_dict_t model_properties;
289   sg_size_t size;
290 } s_storage_type_t, *storage_type_t;
291
292 typedef struct s_mount {
293   void *storage;
294   char *name;
295 } s_mount_t, *mount_t;
296
297 typedef struct surf_file {
298   char *name;
299   char *mount;
300   sg_size_t size;
301   sg_size_t current_position;
302 } s_surf_file_t;
303
304
305 #endif /* STORAGE_INTERFACE_HPP_ */