4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
\r
5 * All right reserved.
\r
7 * This program is free software; you can redistribute
\r
8 * it and/or modify it under the terms of the license
\r
9 *(GNU LGPL) which comes with this package.
\r
12 #ifndef MSG_HOST_HPP
\r
13 #define MSG_HOST_HPP
\r
16 /*! \brief Host class declaration.
\r
18 * An host instance represents a location (any possible place) where a process may run.
\r
19 * Thus it is represented as a physical resource with computing capabilities, some
\r
20 * mailboxes to enable running process to communicate with remote ones, and some private
\r
21 * data that can be only accessed by local process. An instance of this class is always
\r
22 * binded with the corresponding native host. All the native hosts are automaticaly created
\r
23 * during the call of the static method Msg::createEnvironment(). This method takes as parameter
\r
24 * the platform file which describes all elements of the platform (host, link, root..).
\r
25 * You never need to create an host your self.
\r
27 * The best way to get an host is to call the static method
\r
28 * Host.getByName() which returns a reference.
\r
30 * For example to get the instance of the host. If your platform
\r
31 * file description contains an host named "Jacquelin" :
\r
34 using namespace SimGrid.Msg;
\r
40 jacquelin = Host::getByName("Jacquelin");
\r
42 catch(HostNotFoundException e)
\r
44 cerr << e.toString();
\r
52 #error Host.hpp requires C++ compilation (use a .cxx suffix)
\r
55 #include <InvalidArgumentException.hpp>
\r
56 #include <BadAllocException.hpp>
\r
57 #include <HostNotFoundException.hpp>
\r
59 // namespace SimGrid::Msg
\r
64 // Declaration of the class SimGrid::Msg::Host.
\r
67 // Desable the default constructor.
\r
68 // The best way to get an host instance is to use the static method Host::getByName().
\r
72 // Default constructor (desabled).
\r
77 // Copy constructor (desabled).
\r
78 Host(const Host& rHost);
\r
80 // Destructor (desable).
\r
85 /*! \brief Host::getByName() - returns an host by its name
\r
87 * This static method returns a reference to the host instance associated
\r
88 * with a native host of your platform. This is the best way to get a host.
\r
90 * \param hostName The name of the host.
\r
92 * \return If successful the method returns a reference to the instance
\r
93 * associated with the native host having the name specified
\r
94 * as parameter of your platform. Otherwise the method throws
\r
95 * one of the exceptions detailed below.
\r
97 * \exception [HostNotFoundException] if no host with the specified name
\r
99 * [InvalidParameterException] if the hostName parameter is invalid (NULL).
\r
100 * [BadAllocException] if there is not enough memory to allocate the host.
\r
102 static Host& getByName(const char* hostName)
\r
103 throw(HostNotFoundException, InvalidParameterException, BadAllocException);
\r
105 /*! \brief Host::getNumber() - returns the number of the installed hosts.
\r
107 * \return The number of hosts installed.
\r
109 static int getNumber(void);
\r
112 /*! \brief Host::currentHost() - This static method returns the location on which the current
\r
113 * process is executed.
\r
115 * \return The host of the current process.
\r
117 * \see Process::currentProcess().
\r
119 static Host& currentHost(void)
\r
120 throw(InvalidParameterException, BadAllocException);
\r
122 /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform.
\r
124 * \param hosts A pointer to array of Host pointers that receives all the hosts of the platform.
\r
126 * \param len A pointer to the length of the table of pointers.
\r
128 * \return If successful the hosts table is filled and
\r
129 * the parameter len is set with the number of hosts of the platform.
\r
130 * Otherwise the method throw one of the exception described below.
\r
132 * \exception [InvalidParameterException] if the parameter hosts is invalid or
\r
133 * if the parameter len is negative or
\r
134 * less than the number of hosts installed
\r
135 * on the current platform.
\r
136 * [BadAllocException] If the method can't allocate memory to fill
\r
137 * the table of hosts.
\r
140 * \remark To get the number of hosts installed on your platform use the static method
\r
141 * Host::getNumber().
\r
143 * \see Host::getNumber().
\r
146 * // This example show how to use this method to get the list of hosts installed on your platform.
\r
148 * using namespace SimGrid::Msg;
\r
151 * // (1) get the number of hosts.
\r
152 * int number = Host::getNumber();
\r
154 * // (2) allocate the array that receives the list of hosts.
\r
155 * HostPtr* ar = new HostPtr[number]; // HostPtr is defined as (typedef Host* HostPtr at the end of the
\r
156 * // declaration of this class.
\r
158 * // (3) call the method
\r
161 * Host::all(&ar, &number);
\r
163 * catch(BadAllocException e)
\r
165 * cerr << e.toString() << endl;
\r
168 * catch(InvalidArgumentException e)
\r
170 * cerr << e.toString() << endl;
\r
174 * // (4) use the table of host (for example print all the name of all the hosts);
\r
176 * for(int i = 0; i < number ; i++)
\r
177 * cout << ar[i]->getName() << endl;
\r
181 * // (5) release the allocate table
\r
186 static void all(Host*** hosts /*in|out*/, int* len /*in|out*/);
\r
189 const char* getName(void) const;
\r
191 void setData(void* data);
\r
195 void* getData(void) const;
\r
197 int Host::getRunningTaskNumber(void) const;
\r
199 double getSpeed(void) const;
\r
201 bool hasData(void) const;
\r
203 bool isAvailble(void) const;
\r
205 void put(int channel, const Task& rTask)
\r
206 throw(NativeException);
\r
208 void put(int channel, Task task, double timeout)
\r
209 throw(NativeException);
\r
211 void Host::putBounded(int channel, const Task& rTask, double maxRate)
\r
212 throw(NativeException);
\r
215 void send(const Task& rTask)
\r
216 throw(NativeException);
\r
218 void send(const char* alias, const Task& rTask)
\r
219 throw(NativeException);
\r
221 void send(const Task& rTask, double timeout)
\r
222 throw(NativeException);
\r
224 void send(const char* alias, const Task& rTask, double timeout)
\r
225 throw(NativeException);
\r
227 void sendBounded(const Task& rTask, double maxRate)
\r
228 throw(NativeException);
\r
230 void sendBounded(const char* alias, const Task& rTask, double maxRate)
\r
231 throw(NativeException);
\r
240 * This attribute represents the msg native host object.
\r
241 * It is set automaticatly during the call of the static
\r
242 * method Host::getByName().
\r
244 * @see Host::getByName().
\r
246 m_host_t nativeHost;
\r
255 typedef Host* HostPtr;
\r
257 } // namespace SimGrid
\r
259 #endif // !MSG_HOST_HPP