1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
8 #include <xbt/signal.hpp>
10 #include "surf_interface.hpp"
11 #include "src/surf/PropertyHolder.hpp"
13 #ifndef STORAGE_INTERFACE_HPP_
14 #define STORAGE_INTERFACE_HPP_
16 extern xbt_dynar_t mount_list;
33 /** @ingroup SURF_callbacks
34 * @brief Callbacks handler which emit the callbacks after Storage creation *
35 * @details Callback functions have the following signature: `void(Storage*)`
37 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*)>) storageCreatedCallbacks;
39 /** @ingroup SURF_callbacks
40 * @brief Callbacks handler which emit the callbacks after Storage destruction *
41 * @details Callback functions have the following signature: `void(StoragePtr)`
43 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*)>) storageDestructedCallbacks;
45 /** @ingroup SURF_callbacks
46 * @brief Callbacks handler which emit the callbacks after Storage State changed *
47 * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int currentlyOn)`
49 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*, int, int)>) storageStateChangedCallbacks;
51 /** @ingroup SURF_callbacks
52 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
53 * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
55 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, e_surf_action_state_t, e_surf_action_state_t)>) storageActionStateChangedCallbacks;
60 /** @ingroup SURF_storage_interface
61 * @brief SURF storage model interface class
62 * @details A model is an object which handle the interactions between its Resources and its Actions
64 class StorageModel : public Model {
69 /** @brief Create a Storage
71 * @param id [description]
72 * @param type_id [description]
73 * @param content_name [description]
74 * @param content_type [description]
75 * @param properties [description]
76 * @param attach [description]
77 * @return The created Storage
79 virtual Storage *createStorage(const char* id,
81 const char* content_name,
82 const char* content_type,
83 xbt_dict_t properties,
84 const char *attach) = 0;
86 bool next_occuring_event_isIdempotent() {return true;}
88 xbt_dynar_t p_storageList;
94 /** @ingroup SURF_storage_interface
95 * @brief SURF storage interface class
96 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
98 class Storage : public simgrid::surf::Resource,
99 public simgrid::surf::PropertyHolder {
102 * @brief Storage constructor
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 * @param type_id [description]
108 * @param content_name [description]
109 * @param content_type [description]
110 * @param size [description]
112 Storage(Model *model, const char *name, xbt_dict_t props,
113 const char* type_id, const char *content_name, const char *content_type,
117 * @brief Storage constructor
119 * @param model StorageModel associated to this Storage
120 * @param name The name of the Storage
121 * @param props Dictionary of properties associated to this Storage
122 * @param maxminSystem [description]
123 * @param bread [description]
124 * @param bwrite [description]
125 * @param bconnection [description]
126 * @param type_id [description]
127 * @param content_name [description]
128 * @param content_type [description]
129 * @param size [description]
130 * @param attach [description]
132 Storage(Model *model, const char *name, xbt_dict_t props,
133 lmm_system_t maxminSystem, double bread, double bwrite,
135 const char* type_id, const char *content_name, const char *content_type,
136 sg_size_t size, const char *attach);
140 /** @brief Check if the Storage is used (if an action currently uses its resources) */
141 bool isUsed() override;
143 void apply_event(tmgr_trace_iterator_t event, double value) override;
145 void turnOn() override;
146 void turnOff() override;
148 xbt_dict_t p_content;
151 sg_size_t m_usedSize;
153 char* p_attach; //FIXME: this is the name of the host. Use the host directly
158 * @param mount The mount point
159 * @param path The path to the file
161 * @return The StorageAction corresponding to the opening
163 virtual StorageAction *open(const char* mount, const char* path)=0;
166 * @brief Close a file
168 * @param fd The file descriptor to close
169 * @return The StorageAction corresponding to the closing
171 virtual StorageAction *close(surf_file_t fd)=0;
176 * @param fd The file descriptor to read
177 * @param size The size in bytes to read
178 * @return The StorageAction corresponding to the reading
180 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
183 * @brief Write a file
185 * @param fd The file descriptor to write
186 * @param size The size in bytes to write
187 * @return The StorageAction corresponding to the writing
189 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
192 * @brief Get the content of the current Storage
194 * @return A xbt_dict_t with path as keys and size in bytes as values
196 virtual xbt_dict_t getContent();
199 * @brief Get the size in bytes of the current Storage
201 * @return The size in bytes of the current Storage
203 virtual sg_size_t getSize();
206 * @brief Get the available size in bytes of the current Storage
208 * @return The available size in bytes of the current Storage
210 virtual sg_size_t getFreeSize();
213 * @brief Get the used size in bytes of the current Storage
215 * @return The used size in bytes of the current Storage
217 virtual sg_size_t getUsedSize();
220 xbt_dict_t parseContent(const char *filename);
222 xbt_dynar_t p_writeActions;
224 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
225 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
232 /** @ingroup SURF_storage_interface
233 * @brief The possible type of action for the storage component
236 READ=0, /**< Read a file */
237 WRITE, /**< Write in a file */
238 STAT, /**< Stat a file */
239 OPEN, /**< Open a file */
240 CLOSE /**< Close a file */
241 } e_surf_action_storage_type_t;
243 /** @ingroup SURF_storage_interface
244 * @brief SURF storage action interface class
246 class StorageAction : public Action {
249 * @brief StorageAction constructor
251 * @param model The StorageModel associated to this StorageAction
252 * @param cost The cost of this NetworkAction in [TODO]
253 * @param failed [description]
254 * @param storage The Storage associated to this StorageAction
255 * @param type [description]
257 StorageAction(Model *model, double cost, bool failed, Storage *storage,
258 e_surf_action_storage_type_t type);
261 * @brief StorageAction constructor
263 * @param model The StorageModel associated to this StorageAction
264 * @param cost The cost of this StorageAction in [TODO]
265 * @param failed [description]
266 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
267 * @param storage The Storage associated to this StorageAction
268 * @param type [description]
270 StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
271 Storage *storage, e_surf_action_storage_type_t type);
273 void setState(e_surf_action_state_t state);
275 e_surf_action_storage_type_t m_type;
284 typedef struct s_storage_type {
289 xbt_dict_t properties;
290 xbt_dict_t model_properties;
292 } s_storage_type_t, *storage_type_t;
294 typedef struct s_mount {
297 } s_mount_t, *mount_t;
299 typedef struct surf_file {
303 sg_size_t current_position;
307 #endif /* STORAGE_INTERFACE_HPP_ */