Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Detect/fix conflicting visibility and fix visibility wrt lua/java bindings
[simgrid.git] / src / surf / host_interface.hpp
1 /* Copyright (c) 2004-2015. 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 "surf_interface.hpp"
8 #include "storage_interface.hpp"
9 #include "cpu_interface.hpp"
10 #include "network_interface.hpp"
11
12 #include <xbt/base.h>
13
14 #ifndef SURF_HOST_INTERFACE_HPP_
15 #define SURF_HOST_INTERFACE_HPP_
16
17 /***********
18  * Classes *
19  ***********/
20
21 class XBT_PRIVATE HostModel;
22 class XBT_PRIVATE Host;
23 class XBT_PRIVATE HostAction;
24
25 /*************
26  * Callbacks *
27  *************/
28
29 /** @ingroup SURF_callbacks
30  * @brief Callbacks fired after Host creation. Signature: `void(Host*)`
31  */
32 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostCreatedCallbacks;
33
34 /** @ingroup SURF_callbacks
35  * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
36  */
37 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostDestructedCallbacks;
38
39 /** @ingroup SURF_callbacks
40  * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)`
41  */
42 XBT_PUBLIC_DATA(surf_callback(void, Host*, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
43
44 /** @ingroup SURF_callbacks
45  * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)`
46  */
47 XBT_PUBLIC_DATA(surf_callback(void, HostAction*, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
48
49 /*********
50  * Tools *
51  *********/
52 XBT_PUBLIC_DATA(HostModel*) surf_host_model;
53 XBT_PUBLIC(void) host_parse_init(sg_platf_host_cbarg_t host);
54 XBT_PUBLIC(void) host_add_traces();
55
56 /*********
57  * Model *
58  *********/
59 /** @ingroup SURF_host_interface
60  * @brief SURF Host model interface class
61  * @details A model is an object which handle the interactions between its Resources and its Actions
62  */
63 class HostModel : public Model {
64 public:
65   HostModel() : Model() {}
66   ~HostModel() {}
67
68   virtual Host *createHost(const char *name)=0;
69   void addTraces(){DIE_IMPOSSIBLE;}
70
71   virtual void adjustWeightOfDummyCpuActions();
72   virtual Action *executeParallelTask(int host_nb,
73                                       sg_host_t *host_list,
74                                                                           double *flops_amount,
75                                                                           double *bytes_amount,
76                                                                           double rate)=0;
77
78   bool shareResourcesIsIdempotent() {return true;}
79 };
80
81 /************
82  * Resource *
83  ************/
84 /** @ingroup SURF_host_interface
85  * @brief SURF Host interface class
86  * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
87  */
88 class Host : public Resource {
89 public:
90   /**
91    * @brief Host constructor
92    *
93    * @param model HostModel associated to this Host
94    * @param name The name of the Host
95    * @param props Dictionary of properties associated to this Host
96    * @param storage The Storage associated to this Host
97    * @param netElm The RoutingEdge associated to this Host
98    * @param cpu The Cpu associated to this Host
99    */
100   Host(Model *model, const char *name, xbt_dict_t props,
101                       xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
102
103   /**
104    * @brief Host constructor
105    *
106    * @param model HostModel associated to this Host
107    * @param name The name of the Host
108    * @param props Dictionary of properties associated to this Host
109    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
110    * @param storage The Storage associated to this Host
111    * @param netElm The RoutingEdge associated to this Host
112    * @param cpu The Cpu associated to this Host
113    */
114   Host(Model *model, const char *name, xbt_dict_t props,
115       lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
116       Cpu *cpu);
117
118   /** @brief Host destructor */
119   ~ Host();
120
121   void setState(e_surf_resource_state_t state);
122
123   /**
124    * @brief Get the properties of the current Host
125    *
126    * @return The properties of the current Host
127    */
128   xbt_dict_t getProperties();
129
130   /**
131    * @brief Execute some quantity of computation
132    *
133    * @param flops_amount The value of the processing amount (in flop) needed to process
134    * @return The CpuAction corresponding to the processing
135    * @see Cpu
136    */
137   virtual Action *execute(double flops_amount)=0;
138
139   /**
140    * @brief Make a process sleep for duration seconds
141    *
142    * @param duration The number of seconds to sleep
143    * @return The CpuAction corresponding to the sleeping
144    * @see Cpu
145    */
146   virtual Action *sleep(double duration)=0;
147
148   /** @brief Return the storage of corresponding mount point */
149   virtual Storage *findStorageOnMountList(const char* storage);
150
151   /** @brief Get the xbt_dict_t of mount_point: Storage */
152   virtual xbt_dict_t getMountedStorageList();
153
154   /** @brief Get the xbt_dynar_t of storages attached to the Host */
155   virtual xbt_dynar_t getAttachedStorageList();
156
157   /**
158    * @brief Open a file
159    *
160    * @param fullpath The full path to the file
161    *
162    * @return The StorageAction corresponding to the opening
163    */
164   virtual Action *open(const char* fullpath);
165
166   /**
167    * @brief Close a file
168    *
169    * @param fd The file descriptor to close
170    * @return The StorageAction corresponding to the closing
171    */
172   virtual Action *close(surf_file_t fd);
173
174   /**
175    * @brief Unlink a file
176    * @details [long description]
177    *
178    * @param fd [description]
179    * @return [description]
180    */
181   virtual int unlink(surf_file_t fd);
182
183   /**
184    * @brief Get the size in bytes of the file
185    *
186    * @param fd The file descriptor to read
187    * @return The size in bytes of the file
188    */
189   virtual sg_size_t getSize(surf_file_t fd);
190
191   /**
192    * @brief Read a file
193    *
194    * @param fd The file descriptor to read
195    * @param size The size in bytes to read
196    * @return The StorageAction corresponding to the reading
197    */
198   virtual Action *read(surf_file_t fd, sg_size_t size);
199
200   /**
201    * @brief Write a file
202    *
203    * @param fd The file descriptor to write
204    * @param size The size in bytes to write
205    * @return The StorageAction corresponding to the writing
206    */
207   virtual Action *write(surf_file_t fd, sg_size_t size);
208
209   /**
210    * @brief Get the informations of a file descriptor
211    * @details The returned xbt_dynar_t contains:
212    *  - the size of the file,
213    *  - the mount point,
214    *  - the storage name,
215    *  - the storage typeId,
216    *  - the storage content type
217    *
218    * @param fd The file descriptor
219    * @return An xbt_dynar_t with the file informations
220    */
221   virtual xbt_dynar_t getInfo(surf_file_t fd);
222
223   /**
224    * @brief Get the current position of the file descriptor
225    *
226    * @param fd The file descriptor
227    * @return The current position of the file descriptor
228    */
229   virtual sg_size_t fileTell(surf_file_t fd);
230
231   /**
232    * @brief Set the position indicator associated with the file descriptor to a new position
233    * @details [long description]
234    *
235    * @param fd The file descriptor
236    * @param offset The offset from the origin
237    * @param origin Position used as a reference for the offset
238    *  - SEEK_SET: beginning of the file
239    *  - SEEK_CUR: current position indicator
240    *  - SEEK_END: end of the file
241    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
242    */
243   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
244
245   /**
246    * @brief Move a file to another location on the *same mount point*.
247    * @details [long description]
248    *
249    * @param fd The file descriptor
250    * @param fullpath The new full path
251    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
252    * full path is not on the same mount point
253    */
254   virtual int fileMove(surf_file_t fd, const char* fullpath);
255
256   xbt_dynar_t p_storage;
257   RoutingEdge *p_netElm;
258   Cpu *p_cpu;
259
260   /** @brief Get the list of virtual machines on the current Host */
261   xbt_dynar_t getVms();
262
263   /* common with vm */
264   /** @brief Retrieve a copy of the parameters of that VM/PM
265    *  @details The ramsize and overcommit fields are used on the PM too */
266   void getParams(vm_params_t params);
267   /** @brief Sets the params of that VM/PM */
268   void setParams(vm_params_t params);
269 private:
270   s_vm_params_t p_params;
271 };
272
273 /**********
274  * Action *
275  **********/
276
277 /** @ingroup SURF_host_interface
278  * @brief SURF host action interface class
279  */
280 class HostAction : public Action {
281 public:
282   /**
283    * @brief HostAction constructor
284    *
285    * @param model The HostModel associated to this HostAction
286    * @param cost The cost of this HostAction in [TODO]
287    * @param failed [description]
288    */
289   HostAction(Model *model, double cost, bool failed)
290   : Action(model, cost, failed) {}
291
292   /**
293    * @brief HostAction constructor
294    *
295    * @param model The HostModel associated to this HostAction
296    * @param cost The cost of this HostAction in [TODO]
297    * @param failed [description]
298    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
299    */
300   HostAction(Model *model, double cost, bool failed, lmm_variable_t var)
301   : Action(model, cost, failed, var) {}
302
303   void setState(e_surf_action_state_t state);
304 };
305
306
307 #endif /* SURF_Host_INTERFACE_HPP_ */