1 /* Copyright (c) 2004-2017. 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 "src/surf/PropertyHolder.hpp"
11 #include "surf_interface.hpp"
14 #ifndef STORAGE_INTERFACE_HPP_
15 #define STORAGE_INTERFACE_HPP_
30 /** @ingroup SURF_callbacks
31 * @brief Callbacks handler which emit the callbacks after Storage creation *
32 * @details Callback functions have the following signature: `void(Storage*)`
34 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageImpl*)>) storageCreatedCallbacks;
36 /** @ingroup SURF_callbacks
37 * @brief Callbacks handler which emit the callbacks after Storage destruction *
38 * @details Callback functions have the following signature: `void(StoragePtr)`
40 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageImpl*)>) storageDestructedCallbacks;
42 /** @ingroup SURF_callbacks
43 * @brief Callbacks handler which emit the callbacks after Storage State changed *
44 * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int
47 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageImpl*, int, int)>) storageStateChangedCallbacks;
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
52 * old, simgrid::surf::Action::State current)`
54 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, simgrid::surf::Action::State,
55 simgrid::surf::Action::State)>)
56 storageActionStateChangedCallbacks;
61 /** @ingroup SURF_storage_interface
62 * @brief SURF storage model interface class
63 * @details A model is an object which handle the interactions between its Resources and its Actions
65 class StorageModel : public Model {
70 virtual StorageImpl* createStorage(const char* id, const char* type_id, const char* content_name,
71 const char* attach) = 0;
73 std::vector<StorageImpl*> p_storageList;
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)
83 class StorageImpl : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
85 /** @brief Storage constructor */
86 StorageImpl(Model* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite,
87 const char* type_id, const char* content_name, sg_size_t size, const char* attach);
91 /** @brief Check if the Storage is used (if an action currently uses its resources) */
92 bool isUsed() override;
94 void apply_event(tmgr_trace_event_t event, double value) override;
96 void turnOn() override;
97 void turnOff() override;
99 std::map<std::string, sg_size_t*>* content_;
103 char* attach_; // FIXME: this is the name of the host. Use the host directly
108 * @param mount The mount point
109 * @param path The path to the file
111 * @return The StorageAction corresponding to the opening
113 virtual StorageAction* open(const char* mount, const char* path) = 0;
116 * @brief Close a file
118 * @param fd The file descriptor to close
119 * @return The StorageAction corresponding to the closing
121 virtual StorageAction* close(surf_file_t fd) = 0;
126 * @param fd The file descriptor to read
127 * @param size The size in bytes to read
128 * @return The StorageAction corresponding to the reading
130 virtual StorageAction* read(surf_file_t fd, sg_size_t size) = 0;
133 * @brief Write a file
135 * @param fd The file descriptor to write
136 * @param size The size in bytes to write
137 * @return The StorageAction corresponding to the writing
139 virtual StorageAction* write(surf_file_t fd, sg_size_t size) = 0;
142 * @brief Get the content of the current Storage
144 * @return A xbt_dict_t with path as keys and size in bytes as values
146 virtual std::map<std::string, sg_size_t*>* getContent();
149 * @brief Get the available size in bytes of the current Storage
151 * @return The available size in bytes of the current Storage
153 virtual sg_size_t getFreeSize();
156 * @brief Get the used size in bytes of the current Storage
158 * @return The used size in bytes of the current Storage
160 virtual sg_size_t getUsedSize();
162 std::map<std::string, sg_size_t*>* parseContent(const char* filename);
164 std::vector<StorageAction*> writeActions_;
166 lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/
167 lmm_constraint_t constraintRead_; /* Constraint for maximum write bandwidth*/
174 /** @ingroup SURF_storage_interface
175 * @brief The possible type of action for the storage component
178 READ = 0, /**< Read a file */
179 WRITE, /**< Write in a file */
180 STAT, /**< Stat a file */
181 OPEN, /**< Open a file */
182 CLOSE /**< Close a file */
183 } e_surf_action_storage_type_t;
185 /** @ingroup SURF_storage_interface
186 * @brief SURF storage action interface class
188 class StorageAction : public Action {
191 * @brief StorageAction constructor
193 * @param model The StorageModel associated to this StorageAction
194 * @param cost The cost of this NetworkAction in [TODO]
195 * @param failed [description]
196 * @param storage The Storage associated to this StorageAction
197 * @param type [description]
199 StorageAction(Model* model, double cost, bool failed, StorageImpl* storage, e_surf_action_storage_type_t type);
202 * @brief StorageAction constructor
204 * @param model The StorageModel associated to this StorageAction
205 * @param cost The cost of this StorageAction in [TODO]
206 * @param failed [description]
207 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
208 * @param storage The Storage associated to this StorageAction
209 * @param type [description]
211 StorageAction(Model* model, double cost, bool failed, lmm_variable_t var, StorageImpl* storage,
212 e_surf_action_storage_type_t type);
214 void setState(simgrid::surf::Action::State state) override;
216 e_surf_action_storage_type_t type_;
217 StorageImpl* storage_;
224 typedef struct s_storage_type {
228 xbt_dict_t properties;
229 std::map<std::string, std::string>* model_properties;
232 typedef s_storage_type_t* storage_type_t;
234 typedef struct surf_file {
238 sg_size_t current_position;
241 #endif /* STORAGE_INTERFACE_HPP_ */