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(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(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(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(StorageAction*, Action::State, Action::State)>)
56 storageActionStateChangedCallbacks;
61 /** @ingroup SURF_storage_interface
62 * @brief SURF storage model interface class
63 * @details A model is an object which handle the interactions between its Resources and its Actions
65 class StorageModel : public Model {
70 virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
71 std::string attach) = 0;
73 std::vector<StorageImpl*> p_storageList;
79 /** @ingroup SURF_storage_interface
80 * @brief SURF storage interface class
81 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
83 class StorageImpl : public Resource, public PropertyHolder {
85 /** @brief Storage constructor */
86 StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
87 std::string type_id, std::string content_name, sg_size_t size, std::string attach);
89 ~StorageImpl() override;
91 /** @brief Public interface */
93 static StorageImpl* byName(std::string name);
95 /** @brief Check if the Storage is used (if an action currently uses its resources) */
96 bool isUsed() override;
98 void apply_event(tmgr_trace_event_t event, double value) override;
100 void turnOn() override;
101 void turnOff() override;
106 * @param size The size in bytes to read
107 * @return The StorageAction corresponding to the reading
109 virtual StorageAction* read(sg_size_t size) = 0;
112 * @brief Write a file
114 * @param size The size in bytes to write
115 * @return The StorageAction corresponding to the writing
117 virtual StorageAction* write(sg_size_t size) = 0;
118 virtual std::string getHost() { return attach_; }
120 static std::unordered_map<std::string, StorageImpl*>* storagesMap() { return StorageImpl::storages; }
122 lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/
123 lmm_constraint_t constraintRead_; /* Constraint for maximum write bandwidth*/
126 std::string content_name; // Only used at parsing time then goes to the FileSystemExtension
127 sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
130 static std::unordered_map<std::string, StorageImpl*>* storages;
131 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
132 // the Host directly.
140 /** @ingroup SURF_storage_interface
141 * @brief The possible type of action for the storage component
143 enum e_surf_action_storage_type_t {
144 READ = 0, /**< Read a file */
145 WRITE /**< Write in a file */
148 /** @ingroup SURF_storage_interface
149 * @brief SURF storage action interface class
151 class StorageAction : public Action {
154 * @brief StorageAction constructor
156 * @param model The StorageModel associated to this StorageAction
157 * @param cost The cost of this NetworkAction in [TODO]
158 * @param failed [description]
159 * @param storage The Storage associated to this StorageAction
160 * @param type [description]
162 StorageAction(Model* model, double cost, bool failed, StorageImpl* storage, e_surf_action_storage_type_t type)
163 : Action(model, cost, failed), type_(type), storage_(storage){};
166 * @brief StorageAction constructor
168 * @param model The StorageModel associated to this StorageAction
169 * @param cost The cost of this StorageAction in [TODO]
170 * @param failed [description]
171 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
172 * @param storage The Storage associated to this StorageAction
173 * @param type [description]
175 StorageAction(Model* model, double cost, bool failed, lmm_variable_t var, StorageImpl* storage,
176 e_surf_action_storage_type_t type)
177 : Action(model, cost, failed, var), type_(type), storage_(storage){};
179 void setState(simgrid::surf::Action::State state) override;
181 e_surf_action_storage_type_t type_;
182 StorageImpl* storage_;
190 std::map<std::string, std::string>* properties;
191 std::map<std::string, std::string>* model_properties;
193 StorageType(std::string id, std::string model, std::string content, std::map<std::string, std::string>* properties,
194 std::map<std::string, std::string>* model_properties, sg_size_t size)
195 : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
202 #endif /* STORAGE_INTERFACE_HPP_ */