1 /* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <xbt/signal.hpp>
9 #include "simgrid/kernel/resource/Action.hpp"
10 #include "simgrid/kernel/resource/Model.hpp"
11 #include "simgrid/kernel/resource/Resource.hpp"
12 #include "simgrid/s4u/Storage.hpp"
13 #include "src/surf/PropertyHolder.hpp"
14 #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;
81 /** @ingroup SURF_storage_interface
82 * @brief SURF storage interface class
83 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
85 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
87 /** @brief Storage constructor */
88 StorageImpl(kernel::resource::Model* model, std::string name, kernel::lmm::System* maxminSystem, double bread,
89 double bwrite, std::string type_id, std::string content_name, sg_size_t size, std::string attach);
91 ~StorageImpl() override;
93 /** @brief Public interface */
96 /** @brief Check if the Storage is used (if an action currently uses its resources) */
97 bool isUsed() override;
99 void apply_event(tmgr_trace_event_t event, double value) override;
101 void turnOn() override;
102 void turnOff() override;
107 * @param size The size in bytes to read
108 * @return The StorageAction corresponding to the reading
110 virtual StorageAction* read(sg_size_t size) = 0;
113 * @brief Write a file
115 * @param size The size in bytes to write
116 * @return The StorageAction corresponding to the writing
118 virtual StorageAction* write(sg_size_t size) = 0;
119 virtual std::string getHost() { return attach_; }
121 kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
122 kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/
125 std::string content_name; // Only used at parsing time then goes to the FileSystemExtension
126 sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
129 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
130 // the Host directly.
138 /** @ingroup SURF_storage_interface
139 * @brief The possible type of action for the storage component
141 enum e_surf_action_storage_type_t {
142 READ = 0, /**< Read a file */
143 WRITE /**< Write in a file */
146 /** @ingroup SURF_storage_interface
147 * @brief SURF storage action interface class
149 class StorageAction : public kernel::resource::Action {
152 * @brief StorageAction constructor
154 * @param model The StorageModel associated to this StorageAction
155 * @param cost The cost of this NetworkAction in [TODO]
156 * @param failed [description]
157 * @param storage The Storage associated to this StorageAction
158 * @param type [description]
160 StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
161 e_surf_action_storage_type_t type)
162 : Action(model, cost, failed), type_(type), storage_(storage){};
165 * @brief StorageAction constructor
167 * @param model The StorageModel associated to this StorageAction
168 * @param cost The cost of this StorageAction in [TODO]
169 * @param failed [description]
170 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
171 * @param storage The Storage associated to this StorageAction
172 * @param type [description]
174 StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
175 StorageImpl* storage, e_surf_action_storage_type_t type)
176 : Action(model, cost, failed, var), type_(type), storage_(storage){};
178 void set_state(simgrid::kernel::resource::Action::State state) override;
180 e_surf_action_storage_type_t type_;
181 StorageImpl* storage_;
189 std::map<std::string, std::string>* properties;
190 std::map<std::string, std::string>* model_properties;
192 StorageType(std::string id, std::string model, std::string content, std::map<std::string, std::string>* properties,
193 std::map<std::string, std::string>* model_properties, sg_size_t size)
194 : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
201 #endif /* STORAGE_INTERFACE_HPP_ */