1 /* Copyright (c) 2004-2018. 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/kernel/resource/Action.hpp"
12 #include "src/kernel/resource/Model.hpp"
13 #include "src/kernel/resource/Resource.hpp"
14 #include "src/surf/PropertyHolder.hpp"
15 #include "surf_interface.hpp"
18 #ifndef STORAGE_INTERFACE_HPP_
19 #define STORAGE_INTERFACE_HPP_
34 /** @ingroup SURF_callbacks
35 * @brief Callbacks handler which emit the callbacks after Storage creation *
36 * @details Callback functions have the following signature: `void(Storage*)`
38 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*)>) storageCreatedCallbacks;
40 /** @ingroup SURF_callbacks
41 * @brief Callbacks handler which emit the callbacks after Storage destruction *
42 * @details Callback functions have the following signature: `void(StoragePtr)`
44 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*)>) storageDestructedCallbacks;
46 /** @ingroup SURF_callbacks
47 * @brief Callbacks handler which emit the callbacks after Storage State changed *
48 * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int
51 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*, int, int)>) storageStateChangedCallbacks;
53 /** @ingroup SURF_callbacks
54 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
55 * @details Callback functions have the following signature: `void(StorageAction *action,
56 * simgrid::kernel::resource::Action::State old, simgrid::kernel::resource::Action::State current)`
59 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>)
60 storageActionStateChangedCallbacks;
65 /** @ingroup SURF_storage_interface
66 * @brief SURF storage model interface class
67 * @details A model is an object which handle the interactions between its Resources and its Actions
69 class StorageModel : public kernel::resource::Model {
74 virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
75 std::string attach) = 0;
77 std::vector<StorageImpl*> p_storageList;
83 /** @ingroup SURF_storage_interface
84 * @brief SURF storage interface class
85 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
87 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
89 /** @brief Storage constructor */
90 StorageImpl(kernel::resource::Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
91 std::string type_id, std::string content_name, sg_size_t size, std::string attach);
93 ~StorageImpl() override;
95 /** @brief Public interface */
97 static StorageImpl* byName(std::string name);
99 /** @brief Check if the Storage is used (if an action currently uses its resources) */
100 bool isUsed() override;
102 void apply_event(tmgr_trace_event_t event, double value) override;
104 void turnOn() override;
105 void turnOff() override;
110 * @param size The size in bytes to read
111 * @return The StorageAction corresponding to the reading
113 virtual StorageAction* read(sg_size_t size) = 0;
116 * @brief Write a file
118 * @param size The size in bytes to write
119 * @return The StorageAction corresponding to the writing
121 virtual StorageAction* write(sg_size_t size) = 0;
122 virtual std::string getHost() { return attach_; }
124 static std::unordered_map<std::string, StorageImpl*>* storagesMap() { return StorageImpl::storages; }
126 kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
127 kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/
130 std::string content_name; // Only used at parsing time then goes to the FileSystemExtension
131 sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
134 static std::unordered_map<std::string, StorageImpl*>* storages;
135 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
136 // the Host directly.
144 /** @ingroup SURF_storage_interface
145 * @brief The possible type of action for the storage component
147 enum e_surf_action_storage_type_t {
148 READ = 0, /**< Read a file */
149 WRITE /**< Write in a file */
152 /** @ingroup SURF_storage_interface
153 * @brief SURF storage action interface class
155 class StorageAction : public kernel::resource::Action {
158 * @brief StorageAction constructor
160 * @param model The StorageModel associated to this StorageAction
161 * @param cost The cost of this NetworkAction in [TODO]
162 * @param failed [description]
163 * @param storage The Storage associated to this StorageAction
164 * @param type [description]
166 StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
167 e_surf_action_storage_type_t type)
168 : Action(model, cost, failed), type_(type), storage_(storage){};
171 * @brief StorageAction constructor
173 * @param model The StorageModel associated to this StorageAction
174 * @param cost The cost of this StorageAction in [TODO]
175 * @param failed [description]
176 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
177 * @param storage The Storage associated to this StorageAction
178 * @param type [description]
180 StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
181 StorageImpl* storage, e_surf_action_storage_type_t type)
182 : Action(model, cost, failed, var), type_(type), storage_(storage){};
184 void setState(simgrid::kernel::resource::Action::State state) override;
186 e_surf_action_storage_type_t type_;
187 StorageImpl* storage_;
195 std::map<std::string, std::string>* properties;
196 std::map<std::string, std::string>* model_properties;
198 StorageType(std::string id, std::string model, std::string content, std::map<std::string, std::string>* properties,
199 std::map<std::string, std::string>* model_properties, sg_size_t size)
200 : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
207 #endif /* STORAGE_INTERFACE_HPP_ */