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. */
6 #include "simgrid/kernel/resource/Action.hpp"
7 #include "simgrid/kernel/resource/Model.hpp"
8 #include "simgrid/kernel/resource/Resource.hpp"
9 #include "simgrid/s4u/Storage.hpp"
10 #include "src/surf/PropertyHolder.hpp"
11 #include "src/surf/trace_mgr.hpp"
12 #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,
54 * simgrid::kernel::resource::Action::State old, simgrid::kernel::resource::Action::State current)`
57 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
58 storageActionStateChangedCallbacks;
63 /** @ingroup SURF_storage_interface
64 * @brief SURF storage model interface class
65 * @details A model is an object which handle the interactions between its Resources and its Actions
67 class StorageModel : public kernel::resource::Model {
72 virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
73 std::string attach) = 0;
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 kernel::resource::Resource, public PropertyHolder {
85 /** @brief Storage constructor */
86 StorageImpl(kernel::resource::Model* model, std::string name, kernel::lmm::System* maxminSystem, double bread,
87 double bwrite, std::string type_id, std::string content_name, sg_size_t size, std::string attach);
89 ~StorageImpl() override;
91 /** @brief Public interface */
94 /** @brief Check if the Storage is used (if an action currently uses its resources) */
95 bool is_used() override;
97 void apply_event(tmgr_trace_event_t event, double value) override;
99 void turn_on() override;
100 void turn_off() override;
105 * @param size The size in bytes to read
106 * @return The StorageAction corresponding to the reading
108 virtual StorageAction* read(sg_size_t size) = 0;
111 * @brief Write a file
113 * @param size The size in bytes to write
114 * @return The StorageAction corresponding to the writing
116 virtual StorageAction* write(sg_size_t size) = 0;
117 virtual std::string getHost() { return attach_; }
119 kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
120 kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/
123 std::string content_name; // Only used at parsing time then goes to the FileSystemExtension
124 sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
127 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
128 // the Host directly.
136 /** @ingroup SURF_storage_interface
137 * @brief The possible type of action for the storage component
139 enum e_surf_action_storage_type_t {
140 READ = 0, /**< Read a file */
141 WRITE /**< Write in a file */
144 /** @ingroup SURF_storage_interface
145 * @brief SURF storage action interface class
147 class StorageAction : public kernel::resource::Action {
150 * @brief StorageAction constructor
152 * @param model The StorageModel associated to this StorageAction
153 * @param cost The cost of this StorageAction in bytes
154 * @param failed [description]
155 * @param storage The Storage associated to this StorageAction
156 * @param type [description]
158 StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
159 e_surf_action_storage_type_t type)
160 : Action(model, cost, failed), type_(type), storage_(storage){};
163 * @brief StorageAction constructor
165 * @param model The StorageModel associated to this StorageAction
166 * @param cost The cost of this StorageAction in [TODO]
167 * @param failed [description]
168 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
169 * @param storage The Storage associated to this StorageAction
170 * @param type [description]
172 StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
173 StorageImpl* storage, e_surf_action_storage_type_t type)
174 : Action(model, cost, failed, var), type_(type), storage_(storage){};
176 void set_state(simgrid::kernel::resource::Action::State state) override;
178 e_surf_action_storage_type_t type_;
179 StorageImpl* storage_;
187 std::map<std::string, std::string>* properties;
188 std::map<std::string, std::string>* model_properties;
190 StorageType(std::string id, std::string model, std::string content, std::map<std::string, std::string>* properties,
191 std::map<std::string, std::string>* model_properties, sg_size_t size)
192 : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
199 #endif /* STORAGE_INTERFACE_HPP_ */