Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Install some kernel header files for the users' plugins and more
[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/kernel/resource/Action.hpp"
11 #include "simgrid/kernel/resource/Model.hpp"
12 #include "simgrid/kernel/resource/Resource.hpp"
13 #include "simgrid/s4u/Storage.hpp"
14 #include "src/surf/PropertyHolder.hpp"
15 #include "surf_interface.hpp"
16
17 #include <map>
18
19 #ifndef STORAGE_INTERFACE_HPP_
20 #define STORAGE_INTERFACE_HPP_
21
22 namespace simgrid {
23 namespace surf {
24
25 /***********
26  * Classes *
27  ***********/
28
29 class StorageAction;
30
31 /*************
32  * Callbacks *
33  *************/
34
35 /** @ingroup SURF_callbacks
36  * @brief Callbacks handler which emit the callbacks after Storage creation *
37  * @details Callback functions have the following signature: `void(Storage*)`
38  */
39 XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*)> storageCreatedCallbacks;
40
41 /** @ingroup SURF_callbacks
42  * @brief Callbacks handler which emit the callbacks after Storage destruction *
43  * @details Callback functions have the following signature: `void(StoragePtr)`
44  */
45 XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*)> storageDestructedCallbacks;
46
47 /** @ingroup SURF_callbacks
48  * @brief Callbacks handler which emit the callbacks after Storage State changed *
49  * @details Callback functions have the following signature: `void(StorageAction *action, int previouslyOn, int
50  * currentlyOn)`
51  */
52 XBT_PUBLIC_DATA simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks;
53
54 /** @ingroup SURF_callbacks
55  * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
56  * @details Callback functions have the following signature: `void(StorageAction *action,
57  * simgrid::kernel::resource::Action::State old, simgrid::kernel::resource::Action::State current)`
58  */
59 XBT_PUBLIC_DATA
60 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
61     storageActionStateChangedCallbacks;
62
63 /*********
64  * Model *
65  *********/
66 /** @ingroup SURF_storage_interface
67  * @brief SURF storage model interface class
68  * @details A model is an object which handle the interactions between its Resources and its Actions
69  */
70 class StorageModel : public kernel::resource::Model {
71 public:
72   StorageModel();
73   ~StorageModel();
74
75   virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
76                                      std::string attach) = 0;
77 };
78
79 /************
80  * Resource *
81  ************/
82 /** @ingroup SURF_storage_interface
83  * @brief SURF storage interface class
84  * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
85  */
86 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
87 public:
88   /** @brief Storage constructor */
89   StorageImpl(kernel::resource::Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
90               std::string type_id, std::string content_name, sg_size_t size, std::string attach);
91
92   ~StorageImpl() override;
93
94   /** @brief Public interface */
95   s4u::Storage piface_;
96
97   /** @brief Check if the Storage is used (if an action currently uses its resources) */
98   bool isUsed() override;
99
100   void apply_event(tmgr_trace_event_t event, double value) override;
101
102   void turnOn() override;
103   void turnOff() override;
104
105   /**
106    * @brief Read a file
107    *
108    * @param size The size in bytes to read
109    * @return The StorageAction corresponding to the reading
110    */
111   virtual StorageAction* read(sg_size_t size) = 0;
112
113   /**
114    * @brief Write a file
115    *
116    * @param size The size in bytes to write
117    * @return The StorageAction corresponding to the writing
118    */
119   virtual StorageAction* write(sg_size_t size) = 0;
120   virtual std::string getHost() { return attach_; }
121
122   kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
123   kernel::lmm::Constraint* constraintRead_;  /* Constraint for maximum write bandwidth*/
124
125   std::string typeId_;
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
128
129 private:
130   // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
131   // the Host directly.
132   std::string attach_;
133 };
134
135 /**********
136  * Action *
137  **********/
138
139 /** @ingroup SURF_storage_interface
140  * @brief The possible type of action for the storage component
141  */
142 enum e_surf_action_storage_type_t {
143   READ = 0, /**< Read a file */
144   WRITE     /**< Write in a file */
145 };
146
147 /** @ingroup SURF_storage_interface
148  * @brief SURF storage action interface class
149  */
150 class StorageAction : public kernel::resource::Action {
151 public:
152   /**
153    * @brief StorageAction constructor
154    *
155    * @param model The StorageModel associated to this StorageAction
156    * @param cost The cost of this  NetworkAction in [TODO]
157    * @param failed [description]
158    * @param storage The Storage associated to this StorageAction
159    * @param type [description]
160    */
161   StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
162                 e_surf_action_storage_type_t type)
163       : Action(model, cost, failed), type_(type), storage_(storage){};
164
165   /**
166  * @brief StorageAction constructor
167  *
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]
174  */
175   StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
176                 StorageImpl* storage, e_surf_action_storage_type_t type)
177       : Action(model, cost, failed, var), type_(type), storage_(storage){};
178
179   void setState(simgrid::kernel::resource::Action::State state) override;
180
181   e_surf_action_storage_type_t type_;
182   StorageImpl* storage_;
183 };
184
185 class StorageType {
186 public:
187   std::string id;
188   std::string model;
189   std::string content;
190   std::map<std::string, std::string>* properties;
191   std::map<std::string, std::string>* model_properties;
192   sg_size_t size;
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)
196   {
197   }
198 };
199 }
200 }
201
202 #endif /* STORAGE_INTERFACE_HPP_ */