Logo AND Algorithmique Numérique Distribuée

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