Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / surf / StorageImpl.hpp
1 /* Copyright (c) 2004-2018. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <xbt/base.h>
8 #include <xbt/signal.hpp>
9
10 #include "simgrid/s4u/Storage.hpp"
11 #include "src/kernel/resource/Action.hpp"
12 #include "src/kernel/resource/Model.hpp"
13 #include "src/kernel/resource/Resource.hpp"
14 #include "src/surf/PropertyHolder.hpp"
15 #include "surf_interface.hpp"
16 #include <map>
17
18 #ifndef STORAGE_INTERFACE_HPP_
19 #define STORAGE_INTERFACE_HPP_
20
21 namespace simgrid {
22 namespace surf {
23
24 /***********
25  * Classes *
26  ***********/
27
28 class StorageAction;
29
30 /*************
31  * Callbacks *
32  *************/
33
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*)`
37  */
38 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*)>) storageCreatedCallbacks;
39
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)`
43  */
44 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*)>) storageDestructedCallbacks;
45
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
49  * currentlyOn)`
50  */
51 XBT_PUBLIC_DATA(simgrid::xbt::signal<void(StorageImpl*, int, int)>) storageStateChangedCallbacks;
52
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)`
57  */
58 XBT_PUBLIC_DATA(
59     simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>)
60 storageActionStateChangedCallbacks;
61
62 /*********
63  * Model *
64  *********/
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
68  */
69 class StorageModel : public kernel::resource::Model {
70 public:
71   StorageModel();
72   ~StorageModel();
73
74   virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
75                                      std::string attach) = 0;
76 };
77
78 /************
79  * Resource *
80  ************/
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)
84  */
85 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
86 public:
87   /** @brief Storage constructor */
88   StorageImpl(kernel::resource::Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
89               std::string type_id, std::string content_name, sg_size_t size, std::string attach);
90
91   ~StorageImpl() override;
92
93   /** @brief Public interface */
94   s4u::Storage piface_;
95
96   /** @brief Check if the Storage is used (if an action currently uses its resources) */
97   bool isUsed() override;
98
99   void apply_event(tmgr_trace_event_t event, double value) override;
100
101   void turnOn() override;
102   void turnOff() override;
103
104   /**
105    * @brief Read a file
106    *
107    * @param size The size in bytes to read
108    * @return The StorageAction corresponding to the reading
109    */
110   virtual StorageAction* read(sg_size_t size) = 0;
111
112   /**
113    * @brief Write a file
114    *
115    * @param size The size in bytes to write
116    * @return The StorageAction corresponding to the writing
117    */
118   virtual StorageAction* write(sg_size_t size) = 0;
119   virtual std::string getHost() { return attach_; }
120
121   kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
122   kernel::lmm::Constraint* constraintRead_;  /* Constraint for maximum write bandwidth*/
123
124   std::string typeId_;
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
127
128 private:
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.
131   std::string attach_;
132 };
133
134 /**********
135  * Action *
136  **********/
137
138 /** @ingroup SURF_storage_interface
139  * @brief The possible type of action for the storage component
140  */
141 enum e_surf_action_storage_type_t {
142   READ = 0, /**< Read a file */
143   WRITE     /**< Write in a file */
144 };
145
146 /** @ingroup SURF_storage_interface
147  * @brief SURF storage action interface class
148  */
149 class StorageAction : public kernel::resource::Action {
150 public:
151   /**
152    * @brief StorageAction constructor
153    *
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]
159    */
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){};
163
164   /**
165  * @brief StorageAction constructor
166  *
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]
173  */
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){};
177
178   void setState(simgrid::kernel::resource::Action::State state) override;
179
180   e_surf_action_storage_type_t type_;
181   StorageImpl* storage_;
182 };
183
184 class StorageType {
185 public:
186   std::string id;
187   std::string model;
188   std::string content;
189   std::map<std::string, std::string>* properties;
190   std::map<std::string, std::string>* model_properties;
191   sg_size_t size;
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)
195   {
196   }
197 };
198 }
199 }
200
201 #endif /* STORAGE_INTERFACE_HPP_ */