Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplication and uniformization
[simgrid.git] / src / surf / StorageImpl.hpp
1 /* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
13
14 #include <map>
15
16 #ifndef STORAGE_INTERFACE_HPP_
17 #define STORAGE_INTERFACE_HPP_
18
19 namespace simgrid {
20 namespace surf {
21
22 /***********
23  * Classes *
24  ***********/
25
26 class StorageAction;
27
28 /*************
29  * Callbacks *
30  *************/
31
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*)`
35  */
36 XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*)> storageCreatedCallbacks;
37
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)`
41  */
42 XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*)> storageDestructedCallbacks;
43
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
47  * currentlyOn)`
48  */
49 XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks;
50
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)`
55  */
56 XBT_PUBLIC_DATA
57 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
58     storageActionStateChangedCallbacks;
59
60 /*********
61  * Model *
62  *********/
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
66  */
67 class StorageModel : public kernel::resource::Model {
68 public:
69   StorageModel();
70   ~StorageModel();
71
72   virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
73                                      std::string attach) = 0;
74 };
75
76 /************
77  * Resource *
78  ************/
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)
82  */
83 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
84 public:
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);
88
89   ~StorageImpl() override;
90
91   /** @brief Public interface */
92   s4u::Storage piface_;
93
94   /** @brief Check if the Storage is used (if an action currently uses its resources) */
95   bool is_used() override;
96
97   void apply_event(tmgr_trace_event_t event, double value) override;
98
99   void turn_on() override;
100   void turn_off() override;
101
102   /**
103    * @brief Read a file
104    *
105    * @param size The size in bytes to read
106    * @return The StorageAction corresponding to the reading
107    */
108   virtual StorageAction* read(sg_size_t size) = 0;
109
110   /**
111    * @brief Write a file
112    *
113    * @param size The size in bytes to write
114    * @return The StorageAction corresponding to the writing
115    */
116   virtual StorageAction* write(sg_size_t size) = 0;
117   virtual std::string getHost() { return attach_; }
118
119   kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
120   kernel::lmm::Constraint* constraintRead_;  /* Constraint for maximum write bandwidth*/
121
122   std::string typeId_;
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
125
126 private:
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.
129   std::string attach_;
130 };
131
132 /**********
133  * Action *
134  **********/
135
136 /** @ingroup SURF_storage_interface
137  * @brief The possible type of action for the storage component
138  */
139 enum e_surf_action_storage_type_t {
140   READ = 0, /**< Read a file */
141   WRITE     /**< Write in a file */
142 };
143
144 /** @ingroup SURF_storage_interface
145  * @brief SURF storage action interface class
146  */
147 class StorageAction : public kernel::resource::Action {
148 public:
149   /**
150    * @brief StorageAction constructor
151    *
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]
157    */
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){};
161
162   /**
163  * @brief StorageAction constructor
164  *
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]
171  */
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){};
175
176   void set_state(simgrid::kernel::resource::Action::State state) override;
177
178   e_surf_action_storage_type_t type_;
179   StorageImpl* storage_;
180 };
181
182 class StorageType {
183 public:
184   std::string id;
185   std::string model;
186   std::string content;
187   std::map<std::string, std::string>* properties;
188   std::map<std::string, std::string>* model_properties;
189   sg_size_t size;
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)
193   {
194   }
195 };
196 }
197 }
198
199 #endif /* STORAGE_INTERFACE_HPP_ */