Logo AND Algorithmique Numérique Distribuée

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