Logo AND Algorithmique Numérique Distribuée

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