Logo AND Algorithmique Numérique Distribuée

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