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 shareResourcesIsIdempotent() {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) */
144 * @brief Update the state of the current Storage
146 * @param event_type [description]
147 * @param value [description]
148 * @param date [description]
150 void updateState(tmgr_trace_event_t event_type, double value, double date);
152 void turnOn() override;
153 void turnOff() override;
155 xbt_dict_t p_content;
158 sg_size_t m_usedSize;
160 char* p_attach; //FIXME: this is the name of the host. Use the host directly
165 * @param mount The mount point
166 * @param path The path to the file
168 * @return The StorageAction corresponding to the opening
170 virtual StorageAction *open(const char* mount, const char* path)=0;
173 * @brief Close a file
175 * @param fd The file descriptor to close
176 * @return The StorageAction corresponding to the closing
178 virtual StorageAction *close(surf_file_t fd)=0;
183 * @param fd The file descriptor to read
184 * @param size The size in bytes to read
185 * @return The StorageAction corresponding to the reading
187 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
190 * @brief Write a file
192 * @param fd The file descriptor to write
193 * @param size The size in bytes to write
194 * @return The StorageAction corresponding to the writing
196 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
199 * @brief Get the content of the current Storage
201 * @return A xbt_dict_t with path as keys and size in bytes as values
203 virtual xbt_dict_t getContent();
206 * @brief Get the size in bytes of the current Storage
208 * @return The size in bytes of the current Storage
210 virtual sg_size_t getSize();
213 * @brief Get the available size in bytes of the current Storage
215 * @return The available size in bytes of the current Storage
217 virtual sg_size_t getFreeSize();
220 * @brief Get the used size in bytes of the current Storage
222 * @return The used size in bytes of the current Storage
224 virtual sg_size_t getUsedSize();
227 xbt_dict_t parseContent(const char *filename);
229 xbt_dynar_t p_writeActions;
231 lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
232 lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
239 /** @ingroup SURF_storage_interface
240 * @brief The possible type of action for the storage component
243 READ=0, /**< Read a file */
244 WRITE, /**< Write in a file */
245 STAT, /**< Stat a file */
246 OPEN, /**< Open a file */
247 CLOSE /**< Close a file */
248 } e_surf_action_storage_type_t;
250 /** @ingroup SURF_storage_interface
251 * @brief SURF storage action interface class
253 class StorageAction : public Action {
256 * @brief StorageAction constructor
258 * @param model The StorageModel associated to this StorageAction
259 * @param cost The cost of this NetworkAction in [TODO]
260 * @param failed [description]
261 * @param storage The Storage associated to this StorageAction
262 * @param type [description]
264 StorageAction(Model *model, double cost, bool failed, Storage *storage,
265 e_surf_action_storage_type_t type);
268 * @brief StorageAction constructor
270 * @param model The StorageModel associated to this StorageAction
271 * @param cost The cost of this StorageAction in [TODO]
272 * @param failed [description]
273 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
274 * @param storage The Storage associated to this StorageAction
275 * @param type [description]
277 StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
278 Storage *storage, e_surf_action_storage_type_t type);
280 void setState(e_surf_action_state_t state);
282 e_surf_action_storage_type_t m_type;
291 typedef struct s_storage_type {
296 xbt_dict_t properties;
297 xbt_dict_t model_properties;
299 } s_storage_type_t, *storage_type_t;
301 typedef struct s_mount {
304 } s_mount_t, *mount_t;
306 typedef struct surf_file {
310 sg_size_t current_position;
314 #endif /* STORAGE_INTERFACE_HPP_ */