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::Storage*)>) 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::Storage*)>) 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 currentlyOn)`
46 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*, int, int)>) storageStateChangedCallbacks;
48 /** @ingroup SURF_callbacks
49 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
50 * @details Callback functions have the following signature: `void(StorageAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)`
52 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)>) storageActionStateChangedCallbacks;
57 /** @ingroup SURF_storage_interface
58 * @brief SURF storage model interface class
59 * @details A model is an object which handle the interactions between its Resources and its Actions
61 class StorageModel : public Model {
66 virtual Storage* createStorage(const char* id, const char* type_id, const char* content_name,
67 const char* content_type, const char* attach) = 0;
69 std::vector<Storage*> p_storageList;
75 /** @ingroup SURF_storage_interface
76 * @brief SURF storage interface class
77 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
79 class Storage : public simgrid::surf::Resource,
80 public simgrid::surf::PropertyHolder {
83 /** @brief Storage constructor */
84 Storage(Model* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
85 const char* type_id, const char* content_name, const char* content_type, sg_size_t size, const char* attach);
89 /** @brief Check if the Storage is used (if an action currently uses its resources) */
90 bool isUsed() override;
92 void apply_event(tmgr_trace_iterator_t event, double value) override;
94 void turnOn() override;
95 void turnOff() override;
97 std::map<std::string, sg_size_t*>* content_;
102 char* attach_; //FIXME: this is the name of the host. Use the host directly
107 * @param mount The mount point
108 * @param path The path to the file
110 * @return The StorageAction corresponding to the opening
112 virtual StorageAction *open(const char* mount, const char* path)=0;
115 * @brief Close a file
117 * @param fd The file descriptor to close
118 * @return The StorageAction corresponding to the closing
120 virtual StorageAction *close(surf_file_t fd)=0;
125 * @param fd The file descriptor to read
126 * @param size The size in bytes to read
127 * @return The StorageAction corresponding to the reading
129 virtual StorageAction *read(surf_file_t fd, sg_size_t size)=0;
132 * @brief Write a file
134 * @param fd The file descriptor to write
135 * @param size The size in bytes to write
136 * @return The StorageAction corresponding to the writing
138 virtual StorageAction *write(surf_file_t fd, sg_size_t size)=0;
141 * @brief Get the content of the current Storage
143 * @return A xbt_dict_t with path as keys and size in bytes as values
145 virtual std::map<std::string, sg_size_t*>* getContent();
148 * @brief Get the available size in bytes of the current Storage
150 * @return The available size in bytes of the current Storage
152 virtual sg_size_t getFreeSize();
155 * @brief Get the used size in bytes of the current Storage
157 * @return The used size in bytes of the current Storage
159 virtual sg_size_t getUsedSize();
161 std::map<std::string, sg_size_t*>* parseContent(const char* filename);
163 std::vector<StorageAction*> writeActions_;
165 lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/
166 lmm_constraint_t constraintRead_; /* Constraint for maximum write bandwidth*/
173 /** @ingroup SURF_storage_interface
174 * @brief The possible type of action for the storage component
177 READ=0, /**< Read a file */
178 WRITE, /**< Write in a file */
179 STAT, /**< Stat a file */
180 OPEN, /**< Open a file */
181 CLOSE /**< Close a file */
182 } e_surf_action_storage_type_t;
184 /** @ingroup SURF_storage_interface
185 * @brief SURF storage action interface class
187 class StorageAction : public Action {
190 * @brief StorageAction constructor
192 * @param model The StorageModel associated to this StorageAction
193 * @param cost The cost of this NetworkAction in [TODO]
194 * @param failed [description]
195 * @param storage The Storage associated to this StorageAction
196 * @param type [description]
198 StorageAction(Model *model, double cost, bool failed, Storage *storage,
199 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,
212 Storage *storage, e_surf_action_storage_type_t type);
214 void setState(simgrid::surf::Action::State state) override;
216 e_surf_action_storage_type_t type_;
225 typedef struct s_storage_type {
230 xbt_dict_t properties;
231 std::map<std::string, std::string>* model_properties;
234 typedef s_storage_type_t* storage_type_t;
236 typedef struct s_mount {
240 typedef s_mount_t* mount_t;
242 typedef struct surf_file {
246 sg_size_t current_position;
249 #endif /* STORAGE_INTERFACE_HPP_ */