Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
API format unification
[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, simgrid::surf::Action::State old, simgrid::surf::Action::State current)`
52  */
53 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)>) 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   virtual Storage *createStorage(const char* id, const char* type_id,
68                                  const char* content_name, const char* content_type,
69                                  xbt_dict_t properties, const char *attach) = 0;
70
71   std::vector<Storage*> p_storageList;
72 };
73
74 /************
75  * Resource *
76  ************/
77 /** @ingroup SURF_storage_interface
78  * @brief SURF storage interface class
79  * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
80  */
81 class Storage : public simgrid::surf::Resource,
82         public simgrid::surf::PropertyHolder {
83 public:
84   /**
85    * @brief Storage constructor
86    *
87    * @param model StorageModel associated to this Storage
88    * @param name The name of the Storage
89    * @param props Dictionary of properties associated to this Storage
90    * @param type_id [description]
91    * @param content_name [description]
92    * @param content_type [description]
93    * @param size [description]
94    */
95   Storage(Model *model, const char *name, xbt_dict_t props,
96           const char* type_id, const char *content_name, const char *content_type,
97           sg_size_t size);
98
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    */
106   Storage(Model *model, const char *name, xbt_dict_t props,
107           lmm_system_t maxminSystem, double bread, double bwrite,
108           double bconnection,
109           const char* type_id, const char *content_name, const char *content_type,
110           sg_size_t size, const char *attach);
111
112   ~Storage();
113
114   /** @brief Check if the Storage is used (if an action currently uses its resources) */
115   bool isUsed() override;
116
117   void apply_event(tmgr_trace_iterator_t event, double value) override;
118
119   void turnOn() override;
120   void turnOff() override;
121
122   xbt_dict_t content_;
123   char* contentType_;
124   sg_size_t size_;
125   sg_size_t usedSize_;
126   char * typeId_;
127   char* attach_; //FIXME: this is the name of the host. Use the host directly
128
129   /**
130    * @brief Open a file
131    *
132    * @param mount The mount point
133    * @param path The path to the file
134    *
135    * @return The StorageAction corresponding to the opening
136    */
137   virtual StorageAction *open(const char* mount, const char* path)=0;
138
139   /**
140    * @brief Close a file
141    *
142    * @param fd The file descriptor to close
143    * @return The StorageAction corresponding to the closing
144    */
145   virtual StorageAction *close(surf_file_t fd)=0;
146
147   /**
148    * @brief Read a file
149    *
150    * @param fd The file descriptor to read
151    * @param size The size in bytes to read
152    * @return The StorageAction corresponding to the reading
153    */
154   virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
155
156   /**
157    * @brief Write a file
158    *
159    * @param fd The file descriptor to write
160    * @param size The size in bytes to write
161    * @return The StorageAction corresponding to the writing
162    */
163   virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
164
165   /**
166    * @brief Get the content of the current Storage
167    *
168    * @return A xbt_dict_t with path as keys and size in bytes as values
169    */
170   virtual xbt_dict_t getContent();
171
172   /**
173    * @brief Get the size in bytes of the current Storage
174    *
175    * @return The size in bytes of the current Storage
176    */
177   virtual sg_size_t getSize();
178
179   /**
180    * @brief Get the available size in bytes of the current Storage
181    *
182    * @return The available size in bytes of the current Storage
183    */
184   virtual sg_size_t getFreeSize();
185
186   /**
187    * @brief Get the used size in bytes of the current Storage
188    *
189    * @return The used size in bytes of the current Storage
190    */
191   virtual sg_size_t getUsedSize();
192
193
194   xbt_dict_t parseContent(const char *filename);
195
196   std::vector<StorageAction*> writeActions_;
197
198   lmm_constraint_t constraintWrite_;    /* Constraint for maximum write bandwidth*/
199   lmm_constraint_t constraintRead_;     /* Constraint for maximum write bandwidth*/
200 };
201
202 /**********
203  * Action *
204  **********/
205
206 /** @ingroup SURF_storage_interface
207  * @brief The possible type of action for the storage component
208  */
209 typedef enum {
210   READ=0, /**< Read a file */
211   WRITE,  /**< Write in a file */
212   STAT,   /**< Stat a file */
213   OPEN,   /**< Open a file */
214   CLOSE  /**< Close a file */
215 } e_surf_action_storage_type_t;
216
217 /** @ingroup SURF_storage_interface
218  * @brief SURF storage action interface class
219  */
220 class StorageAction : public Action {
221 public:
222   /**
223    * @brief StorageAction constructor
224    *
225    * @param model The StorageModel associated to this StorageAction
226    * @param cost The cost of this  NetworkAction in [TODO]
227    * @param failed [description]
228    * @param storage The Storage associated to this StorageAction
229    * @param type [description]
230    */
231   StorageAction(Model *model, double cost, bool failed, Storage *storage,
232       e_surf_action_storage_type_t type);
233
234     /**
235    * @brief StorageAction constructor
236    *
237    * @param model The StorageModel associated to this StorageAction
238    * @param cost The cost of this  StorageAction in [TODO]
239    * @param failed [description]
240    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
241    * @param storage The Storage associated to this StorageAction
242    * @param type [description]
243    */
244   StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
245       Storage *storage, e_surf_action_storage_type_t type);
246
247   void setState(simgrid::surf::Action::State state) override;
248
249   e_surf_action_storage_type_t m_type;
250   Storage *p_storage;
251   surf_file_t p_file;
252   double progress;
253 };
254
255 }
256 }
257
258 typedef struct s_storage_type {
259   char *model;
260   char *content;
261   char *content_type;
262   char *type_id;
263   xbt_dict_t properties;
264   xbt_dict_t model_properties;
265   sg_size_t size;
266 } s_storage_type_t, *storage_type_t;
267
268 typedef struct s_mount {
269   void *storage;
270   char *name;
271 } s_mount_t, *mount_t;
272
273 typedef struct surf_file {
274   char *name;
275   char *mount;
276   sg_size_t size;
277   sg_size_t current_position;
278 } s_surf_file_t;
279
280 #endif /* STORAGE_INTERFACE_HPP_ */