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/Resource.hpp"
12 #include "src/surf/PropertyHolder.hpp"
13 #include "surf_interface.hpp"
16 #ifndef STORAGE_INTERFACE_HPP_
17 #define STORAGE_INTERFACE_HPP_
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after Storage creation *
34 * @details Callback functions have the following signature: `void(Storage*)`
36 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*)>) storageCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after Storage destruction *
40 * @details Callback functions have the following signature: `void(StoragePtr)`
42 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*)>) storageDestructedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after Storage State changed *
46 * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int
49 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*, int, int)>) storageStateChangedCallbacks;
51 /** @ingroup SURF_callbacks
52 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
53 * @details Callback functions have the following signature: `void(StorageAction *action, simgrid::surf::Action::State
54 * old, simgrid::surf::Action::State current)`
56 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageAction*, Action::State, 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(std::string id, std::string type_id, std::string content_name,
72 std::string 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 kernel::resource::Resource, public PropertyHolder {
86 /** @brief Storage constructor */
87 StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
88 std::string type_id, std::string content_name, sg_size_t size, std::string attach);
90 ~StorageImpl() override;
92 /** @brief Public interface */
94 static StorageImpl* byName(std::string name);
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 static std::unordered_map<std::string, StorageImpl*>* storagesMap() { return StorageImpl::storages; }
123 kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
124 kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/
127 std::string content_name; // Only used at parsing time then goes to the FileSystemExtension
128 sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
131 static std::unordered_map<std::string, StorageImpl*>* storages;
132 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
133 // the Host directly.
141 /** @ingroup SURF_storage_interface
142 * @brief The possible type of action for the storage component
144 enum e_surf_action_storage_type_t {
145 READ = 0, /**< Read a file */
146 WRITE /**< Write in a file */
149 /** @ingroup SURF_storage_interface
150 * @brief SURF storage action interface class
152 class StorageAction : public Action {
155 * @brief StorageAction constructor
157 * @param model The StorageModel associated to this StorageAction
158 * @param cost The cost of this NetworkAction in [TODO]
159 * @param failed [description]
160 * @param storage The Storage associated to this StorageAction
161 * @param type [description]
163 StorageAction(Model* model, double cost, bool failed, StorageImpl* storage, e_surf_action_storage_type_t type)
164 : Action(model, cost, failed), type_(type), storage_(storage){};
167 * @brief StorageAction constructor
169 * @param model The StorageModel associated to this StorageAction
170 * @param cost The cost of this StorageAction in [TODO]
171 * @param failed [description]
172 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
173 * @param storage The Storage associated to this StorageAction
174 * @param type [description]
176 StorageAction(Model* model, double cost, bool failed, kernel::lmm::Variable* var, StorageImpl* storage,
177 e_surf_action_storage_type_t type)
178 : Action(model, cost, failed, var), type_(type), storage_(storage){};
180 void setState(simgrid::surf::Action::State state) override;
182 e_surf_action_storage_type_t type_;
183 StorageImpl* storage_;
191 std::map<std::string, std::string>* properties;
192 std::map<std::string, std::string>* model_properties;
194 StorageType(std::string id, std::string model, std::string content, std::map<std::string, std::string>* properties,
195 std::map<std::string, std::string>* model_properties, sg_size_t size)
196 : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
203 #endif /* STORAGE_INTERFACE_HPP_ */