Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
actually rename s4u::Process into s4u::Actor
[simgrid.git] / include / simgrid / s4u / host.hpp
1 /* Copyright (c) 2006-2015. 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 #ifndef SIMGRID_S4U_HOST_HPP
7 #define SIMGRID_S4U_HOST_HPP
8
9 #include <boost/unordered_map.hpp>
10
11 #include "simgrid/simix.h"
12
13 namespace simgrid {
14 namespace s4u {
15
16 class Actor;
17
18 /** @brief Simulated machine that can host some actors
19  *
20  * It represents some physical resource with computing and networking capabilities.
21  *
22  * All hosts are automatically created during the call of the method
23  * @link{simgrid::s4u::Engine::loadPlatform()}.
24  * You cannot create a host yourself.
25  *
26  * You can retrieve a particular host using @link{simgrid::s4u::Host.byName()},
27  * and actors can retrieve the host on which they run using @link{simgrid::s4u::Host.current()}.
28  */
29 class Host {
30 private:
31         Host(const char *name);
32 public:
33         /** Retrieves an host from its name. */
34         static s4u::Host *byName(std::string name);
35         /** Retrieves the host on which the current actor is running */
36         static s4u::Host *current();
37
38         const char* getName();
39
40         /** Turns that host on if it was previously off
41          *
42          * All actors on that host which were marked autorestart will be restarted automatically.
43          * This call does nothing if the host is already on.
44          */
45         void turnOn();
46         /** Turns that host off. All actors are forcefully stopped. */
47         void turnOff();
48         /** Returns if that host is currently up and running */
49         bool isOn();
50
51
52         /** Allows to store user data on that host */
53         void setData(void *data) {p_userdata = data;}
54         /** Retrieves the previously stored data */
55         void* getData() {return p_userdata;}
56
57 protected:
58         friend Actor;
59         sg_host_t getInferior() {return p_sghost;}
60 private:
61         void*p_userdata=NULL;
62         sg_host_t p_sghost;
63         static boost::unordered_map<std::string, s4u::Host *> *hosts;
64 };
65
66 }} // namespace simgrid::s4u
67
68 #endif /* SIMGRID_S4U_HOST_HPP */
69
70 #if 0
71 /* Bindings to the MSG hosts */
72
73 /* Copyright (c) 2006-2014. The SimGrid Team.
74  * All rights reserved.                                                     */
75
76 /* This program is free software; you can redistribute it and/or modify it
77  * under the terms of the license (GNU LGPL) which comes with this package. */
78
79 package org.simgrid.msg;
80
81 import org.simgrid.msg.Storage;
82
83 /*
84 Host jacquelin;
85
86 try { 
87         jacquelin = Host.getByName("Jacquelin");
88 } catch(HostNotFoundException e) {
89         System.err.println(e.toString());
90 }
91 ...
92 \endverbatim
93  *
94  */ 
95 public class Host {
96         /**
97          * This static method returns all of the hosts of the installed platform.
98          *
99          * @return                      An array containing all the hosts installed.
100          *
101          */ 
102         public native static Host[] all();
103
104         /** 
105          * This static method sets a mailbox to receive in asynchronous mode.
106          * 
107          * All messages sent to this mailbox will be transferred to 
108          * the receiver without waiting for the receive call. 
109          * The receive call will still be necessary to use the received data.
110          * If there is a need to receive some messages asynchronously, and some not, 
111          * two different mailboxes should be used.
112          *
113          * @param mailboxName The name of the mailbox
114          */
115         public static native void setAsyncMailbox(String mailboxName);
116
117         /**
118          * This method returns the number of tasks currently running on a host.
119          * The external load (comming from an availability trace) is not taken in account.
120          *
121          * @return                      The number of tasks currently running on a host.
122          */ 
123         public native int getLoad();
124
125         /**
126          * This method returns the speed of the processor of a host,
127          * regardless of the current load of the machine.
128          *
129          * @return                      The speed of the processor of the host in flops.
130          *
131          */ 
132         public native double getSpeed();
133
134         /**
135          * This method returns the number of core of a host.
136          *
137          * @return                      The speed of the processor of the host in flops.
138          *
139          */ 
140         public native double getCoreNumber();
141
142         /**
143          * Returns the value of a given host property (set from the platform file).
144          */
145         public native String getProperty(String name);
146
147         /**
148          * Change the value of a given host property. 
149          */
150         public native void setProperty(String name, String value);
151
152         /** This methods returns the list of mount point names on an host
153          * @return An array containing all mounted storages on the host
154          */
155         public native Storage[] getMountedStorage();
156
157         /** This methods returns the list of storages attached to an host
158          * @return An array containing all storages (name) attached to the host
159          */
160         public native String[] getAttachedStorage();
161
162
163
164 #endif