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 "simgrid/s4u/Storage.hpp"
11 #include "src/surf/PropertyHolder.hpp"
12 #include "surf_interface.hpp"
15 #ifndef STORAGE_INTERFACE_HPP_
16 #define STORAGE_INTERFACE_HPP_
31 /** @ingroup SURF_callbacks
32 * @brief Callbacks handler which emit the callbacks after Storage creation *
33 * @details Callback functions have the following signature: `void(Storage*)`
35 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageImpl*)>) storageCreatedCallbacks;
37 /** @ingroup SURF_callbacks
38 * @brief Callbacks handler which emit the callbacks after Storage destruction *
39 * @details Callback functions have the following signature: `void(StoragePtr)`
41 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageImpl*)>) storageDestructedCallbacks;
43 /** @ingroup SURF_callbacks
44 * @brief Callbacks handler which emit the callbacks after Storage State changed *
45 * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int
48 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageImpl*, int, int)>) storageStateChangedCallbacks;
50 /** @ingroup SURF_callbacks
51 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
52 * @details Callback functions have the following signature: `void(StorageAction *action, simgrid::surf::Action::State
53 * old, simgrid::surf::Action::State current)`
55 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, simgrid::surf::Action::State,
56 simgrid::surf::Action::State)>)
57 storageActionStateChangedCallbacks;
62 /** @ingroup SURF_storage_interface
63 * @brief SURF storage model interface class
64 * @details A model is an object which handle the interactions between its Resources and its Actions
66 class StorageModel : public Model {
71 virtual StorageImpl* createStorage(const char* id, const char* type_id, const char* content_name,
72 const char* attach) = 0;
74 std::vector<StorageImpl*> p_storageList;
80 /** @ingroup SURF_storage_interface
81 * @brief SURF storage interface class
82 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
84 class StorageImpl : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
86 /** @brief Storage constructor */
87 StorageImpl(Model* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite,
88 const char* type_id, const char* content_name, sg_size_t size, const char* attach);
90 ~StorageImpl() override;
93 /** @brief Public interface */
95 static StorageImpl* byName(const char* name);
97 /** @brief Check if the Storage is used (if an action currently uses its resources) */
98 bool isUsed() override;
100 void apply_event(tmgr_trace_event_t event, double value) override;
102 void turnOn() override;
103 void turnOff() override;
108 * @param size The size in bytes to read
109 * @return The StorageAction corresponding to the reading
111 virtual StorageAction* read(sg_size_t size) = 0;
114 * @brief Write a file
116 * @param size The size in bytes to write
117 * @return The StorageAction corresponding to the writing
119 virtual StorageAction* write(sg_size_t size) = 0;
122 * @brief Get the content of the current Storage
124 * @return A xbt_dict_t with path as keys and size in bytes as values
126 virtual std::map<std::string, sg_size_t>* getContent();
129 * @brief Get the available size in bytes of the current Storage
131 * @return The available size in bytes of the current Storage
133 virtual sg_size_t getFreeSize();
136 * @brief Get the used size in bytes of the current Storage
138 * @return The used size in bytes of the current Storage
140 virtual sg_size_t getUsedSize();
141 virtual sg_size_t getSize() { return size_; }
142 virtual std::string getHost() { return attach_; }
144 std::map<std::string, sg_size_t>* parseContent(const char* filename);
145 static std::unordered_map<std::string, StorageImpl*>* storages;
146 static std::unordered_map<std::string, StorageImpl*>* storagesMap() { return StorageImpl::storages; }
148 lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/
149 lmm_constraint_t constraintRead_; /* Constraint for maximum write bandwidth*/
152 sg_size_t usedSize_ = 0;
156 std::map<std::string, sg_size_t>* content_;
157 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
158 // the Host directly.
166 /** @ingroup SURF_storage_interface
167 * @brief The possible type of action for the storage component
170 READ = 0, /**< Read a file */
171 WRITE /**< Write in a file */
172 } e_surf_action_storage_type_t;
174 /** @ingroup SURF_storage_interface
175 * @brief SURF storage action interface class
177 class StorageAction : public Action {
180 * @brief StorageAction constructor
182 * @param model The StorageModel associated to this StorageAction
183 * @param cost The cost of this NetworkAction in [TODO]
184 * @param failed [description]
185 * @param storage The Storage associated to this StorageAction
186 * @param type [description]
188 StorageAction(Model* model, double cost, bool failed, StorageImpl* storage, e_surf_action_storage_type_t type)
189 : Action(model, cost, failed), type_(type), storage_(storage){};
192 * @brief StorageAction constructor
194 * @param model The StorageModel associated to this StorageAction
195 * @param cost The cost of this StorageAction in [TODO]
196 * @param failed [description]
197 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
198 * @param storage The Storage associated to this StorageAction
199 * @param type [description]
201 StorageAction(Model* model, double cost, bool failed, lmm_variable_t var, StorageImpl* storage,
202 e_surf_action_storage_type_t type)
203 : Action(model, cost, failed, var), type_(type), storage_(storage){};
205 void setState(simgrid::surf::Action::State state) override;
207 e_surf_action_storage_type_t type_;
208 StorageImpl* storage_;
209 FileImpl* file_ = nullptr;
214 typedef struct s_storage_type {
218 xbt_dict_t properties;
219 std::map<std::string, std::string>* model_properties;
222 typedef s_storage_type_t* storage_type_t;
224 #endif /* STORAGE_INTERFACE_HPP_ */