Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename AsImpl::getRouteRecursive to AsImpl::getGlobalRoute (+doc improvment)
[simgrid.git] / src / surf / HostImpl.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 #include "src/surf/PropertyHolder.hpp"
12
13 #include <xbt/base.h>
14
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
17
18 /***********
19  * Classes *
20  ***********/
21
22 namespace simgrid {
23 namespace surf {
24
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE HostImpl;
27 class XBT_PRIVATE HostAction;
28 }
29 }
30
31 /*********
32  * Tools *
33  *********/
34
35 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
36
37 /*********
38  * Model *
39  *********/
40
41 namespace simgrid {
42 namespace surf {
43
44 /** @ingroup SURF_host_interface
45  * @brief SURF Host model interface class
46  * @details A model is an object which handle the interactions between its Resources and its Actions
47  */
48 class HostModel : public Model {
49 public:
50   HostModel() : Model() {}
51
52   virtual void adjustWeightOfDummyCpuActions();
53   virtual Action* executeParallelTask(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount,
54                                       double rate);
55 };
56
57 /************
58  * Resource *
59  ************/
60 /** @ingroup SURF_host_interface
61  * @brief SURF Host interface class
62  * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
63  */
64 class HostImpl : public simgrid::surf::PropertyHolder {
65
66 public:
67   HostImpl(s4u::Host* host, xbt_dynar_t storage);
68   virtual ~HostImpl();
69
70 public:
71   /** @brief Return the storage of corresponding mount point */
72   virtual simgrid::surf::Storage* findStorageOnMountList(const char* storage);
73
74   /** @brief Get the xbt_dict_t of mount_point: Storage */
75   virtual xbt_dict_t getMountedStorageList();
76
77   /** @brief Get the xbt_dynar_t of storages attached to the Host */
78   virtual xbt_dynar_t getAttachedStorageList();
79
80   /**
81    * @brief Open a file
82    *
83    * @param fullpath The full path to the file
84    * @return The StorageAction corresponding to the opening
85    */
86   virtual Action* open(const char* fullpath);
87
88   /**
89    * @brief Close a file
90    *
91    * @param fd The file descriptor to close
92    * @return The StorageAction corresponding to the closing
93    */
94   virtual Action* close(surf_file_t fd);
95
96   /**
97    * @brief Unlink a file
98    * @details [long description]
99    *
100    * @param fd [description]
101    * @return [description]
102    */
103   virtual int unlink(surf_file_t fd);
104
105   /**
106    * @brief Get the size in bytes of the file
107    *
108    * @param fd The file descriptor to read
109    * @return The size in bytes of the file
110    */
111   virtual sg_size_t getSize(surf_file_t fd);
112
113   /**
114    * @brief Read a file
115    *
116    * @param fd The file descriptor to read
117    * @param size The size in bytes to read
118    * @return The StorageAction corresponding to the reading
119    */
120   virtual Action* read(surf_file_t fd, sg_size_t size);
121
122   /**
123    * @brief Write a file
124    *
125    * @param fd The file descriptor to write
126    * @param size The size in bytes to write
127    * @return The StorageAction corresponding to the writing
128    */
129   virtual Action* write(surf_file_t fd, sg_size_t size);
130
131   /**
132    * @brief Get the information of a file descriptor
133    * @details The returned xbt_dynar_t contains:
134    *  - the size of the file,
135    *  - the mount point,
136    *  - the storage name,
137    *  - the storage typeId,
138    *  - the storage content type
139    *
140    * @param fd The file descriptor
141    * @return An xbt_dynar_t with the file information
142    */
143   virtual xbt_dynar_t getInfo(surf_file_t fd);
144
145   /**
146    * @brief Get the current position of the file descriptor
147    *
148    * @param fd The file descriptor
149    * @return The current position of the file descriptor
150    */
151   virtual sg_size_t fileTell(surf_file_t fd);
152
153   /**
154    * @brief Set the position indicator associated with the file descriptor to a new position
155    * @details [long description]
156    *
157    * @param fd The file descriptor
158    * @param offset The offset from the origin
159    * @param origin Position used as a reference for the offset
160    *  - SEEK_SET: beginning of the file
161    *  - SEEK_CUR: current position indicator
162    *  - SEEK_END: end of the file
163    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
164    */
165   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
166
167   /**
168    * @brief Move a file to another location on the *same mount point*.
169    * @details [long description]
170    *
171    * @param fd The file descriptor
172    * @param fullpath The new full path
173    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
174    * full path is not on the same mount point
175    */
176   virtual int fileMove(surf_file_t fd, const char* fullpath);
177
178 public:
179   xbt_dynar_t storage_        = nullptr;
180   simgrid::s4u::Host* piface_ = nullptr;
181
182   /** @brief Get the list of virtual machines on the current Host */
183   xbt_dynar_t getVms();
184
185   simgrid::s4u::Host* getHost() { return piface_; }
186 };
187 }
188 }
189
190 #endif /* SURF_Host_INTERFACE_HPP_ */