+/*\r
+ * Host.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */ \r
#ifndef MSG_HOST_HPP\r
#define MSG_HOST_HPP\r
\r
\r
-// Compilation C++ recquise\r
+/*! \brief Host class declaration.\r
+ *\r
+ * An host instance represents a location (any possible place) where a process may run. \r
+ * Thus it is represented as a physical resource with computing capabilities, some \r
+ * mailboxes to enable running process to communicate with remote ones, and some private \r
+ * data that can be only accessed by local process. An instance of this class is always \r
+ * binded with the corresponding native host. All the native hosts are automaticaly created \r
+ * during the call of the static method Msg::createEnvironment(). This method takes as parameter\r
+ * the platform file which describes all elements of the platform (host, link, root..).\r
+ * You never need to create an host your self.\r
+ *\r
+ * The best way to get an host is to call the static method \r
+ * Host.getByName() which returns a reference.\r
+ *\r
+ * For example to get the instance of the host. If your platform\r
+ * file description contains an host named "Jacquelin" :\r
+ *\r
+ * \verbatim\r
+using namespace SimGrid.Msg;\r
+\r
+Host jacquelin;\r
+\r
+try \r
+{ \r
+ jacquelin = Host::getByName("Jacquelin");\r
+}\r
+catch(HostNotFoundException e) \r
+{\r
+ cerr << e.toString();\r
+}\r
+...\r
+\endverbatim\r
+ *\r
+ */\r
+\r
#ifndef __cplusplus\r
#error Host.hpp requires C++ compilation (use a .cxx suffix)\r
#endif\r
\r
-namespace msg\r
-{\r
-class Host\r
-{\r
- private :\r
- // Default constructor.\r
- Host();\r
- \r
- // Copy constructor.\r
- Host(const Host& rHost);\r
- \r
- // Destructor.\r
- virtual ~Host();\r
- \r
- public: \r
- \r
- // Operations\r
- \r
- static Host& getByName(const char* hostName)\r
- throw(HostNotFoundException);\r
- \r
- static int getNumber(void);\r
- \r
- static Host& currentHost(void);\r
- \r
- static int all(Host** hosts);\r
- \r
- \r
- const char* getName(void) const;\r
- \r
- void setData(void* data);\r
- \r
- // Getters/setters\r
- \r
- void* getData(void) const;\r
- \r
- int Host::getRunningTaskNumber(void) const;\r
- \r
- double getSpeed(void) const;\r
- \r
- bool hasData(void) const;\r
- \r
- bool isAvailble(void) const;\r
- \r
- void put(int channel, const Task& rTask)\r
- throw(NativeException);\r
- \r
- void put(int channel, Task task, double timeout) \r
- throw(NativeException);\r
- \r
- void Host::putBounded(int channel, const Task& rTask, double maxRate) \r
- throw(NativeException);\r
+#include <InvalidArgumentException.hpp>\r
+#include <BadAllocException.hpp>\r
+#include <HostNotFoundException.hpp>\r
\r
- \r
- void send(const Task& rTask) \r
- throw(NativeException);\r
- \r
- void send(const char* alias, const Task& rTask) \r
- throw(NativeException);\r
- \r
- void send(const Task& rTask, double timeout) \r
- throw(NativeException);\r
- \r
- void send(const char* alias, const Task& rTask, double timeout) \r
- throw(NativeException);\r
- \r
- void sendBounded(const Task& rTask, double maxRate) \r
- throw(NativeException);\r
- \r
- void sendBounded(const char* alias, const Task& rTask, double maxRate) \r
- throw(NativeException); \r
- \r
- \r
- private:\r
- // Attributes.\r
- \r
- m_host_t nativeHost;\r
+// namespace SimGrid::Msg\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ // Declaration of the class SimGrid::Msg::Host.\r
+ class Host\r
+ {\r
+ // Desable the default constructor.\r
+ // The best way to get an host instance is to use the static method Host::getByName().\r
+ \r
+ private :\r
+ \r
+ // Default constructor (desabled).\r
+ Host();\r
+ \r
+ public: \r
+ \r
+ // Copy constructor (desabled).\r
+ Host(const Host& rHost);\r
+ \r
+ // Destructor (desable).\r
+ virtual ~Host();\r
+ \r
+ // Operations\r
+ \r
+ /*! \brief Host::getByName() - returns an host by its name\r
+ *\r
+ * This static method returns a reference to the host instance associated \r
+ * with a native host of your platform. This is the best way to get a host.\r
+ *\r
+ * \param hostName The name of the host.\r
+ *\r
+ * \return If successful the method returns a reference to the instance\r
+ * associated with the native host having the name specified\r
+ * as parameter of your platform. Otherwise the method throws\r
+ * one of the exceptions detailed below.\r
+ *\r
+ * \exception [HostNotFoundException] if no host with the specified name\r
+ * was found.\r
+ * [InvalidParameterException] if the hostName parameter is invalid (NULL).\r
+ * [BadAllocException] if there is not enough memory to allocate the host.\r
+ */ \r
+ static Host& getByName(const char* hostName)\r
+ throw(HostNotFoundException, InvalidParameterException, BadAllocException);\r
+ \r
+ /*! \brief Host::getNumber() - returns the number of the installed hosts.\r
+ *\r
+ * \return The number of hosts installed.\r
+ */\r
+ static int getNumber(void);\r
+ \r
+ \r
+ /*! \brief Host::currentHost() - This static method returns the location on which the current \r
+ * process is executed.\r
+ *\r
+ * \return The host of the current process.\r
+ *\r
+ * \see Process::currentProcess().\r
+ */\r
+ static Host& currentHost(void)\r
+ throw(InvalidParameterException, BadAllocException);\r
+ \r
+ /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform.\r
+ *\r
+ * \param hosts A pointer to array of Host pointers that receives all the hosts of the platform.\r
+ *\r
+ * \param len A pointer to the length of the table of pointers.\r
+ *\r
+ * \return If successful the hosts table is filled and\r
+ * the parameter len is set with the number of hosts of the platform.\r
+ * Otherwise the method throw one of the exception described below.\r
+ *\r
+ * \exception [InvalidParameterException] if the parameter hosts is invalid or\r
+ * if the parameter len is negative or\r
+ * less than the number of hosts installed\r
+ * on the current platform.\r
+ * [BadAllocException] If the method can't allocate memory to fill\r
+ * the table of hosts.\r
+ *\r
+ *\r
+ * \remark To get the number of hosts installed on your platform use the static method\r
+ * Host::getNumber().\r
+ *\r
+ * \see Host::getNumber().\r
+ *\r
+ *\verbatim\r
+ * // This example show how to use this method to get the list of hosts installed on your platform.\r
+ *\r
+ * using namespace SimGrid::Msg;\r
+ * using <iostream>\r
+ *\r
+ * // (1) get the number of hosts.\r
+ * int number = Host::getNumber();\r
+ * \r
+ * // (2) allocate the array that receives the list of hosts.\r
+ * HostPtr* ar = new HostPtr[number]; // HostPtr is defined as (typedef Host* HostPtr at the end of the\r
+ * // declaration of this class.\r
+ *\r
+ * // (3) call the method\r
+ * try\r
+ * {\r
+ * Host::all(&ar, &number);\r
+ * }\r
+ * catch(BadAllocException e)\r
+ * {\r
+ * cerr << e.toString() << endl;\r
+ * ...\r
+ * }\r
+ * catch(InvalidArgumentException e)\r
+ * {\r
+ * cerr << e.toString() << endl;\r
+ * ..\r
+ * } \r
+ *\r
+ * // (4) use the table of host (for example print all the name of all the hosts);\r
+ * \r
+ * for(int i = 0; i < number ; i++)\r
+ * cout << ar[i]->getName() << endl;\r
+ *\r
+ * ...\r
+ * \r
+ * // (5) release the allocate table\r
+ * \r
+ * delete[] ar;\r
+ *\r
+ */ \r
+ static void all(Host*** hosts /*in|out*/, int* len /*in|out*/);\r
+ \r
+ \r
+ const char* getName(void) const;\r
+ \r
+ void setData(void* data);\r
+ \r
+ // Getters/setters\r
+ \r
+ void* getData(void) const;\r
+ \r
+ int Host::getRunningTaskNumber(void) const;\r
+ \r
+ double getSpeed(void) const;\r
+ \r
+ bool hasData(void) const;\r
+ \r
+ bool isAvailble(void) const;\r
+ \r
+ void put(int channel, const Task& rTask)\r
+ throw(NativeException);\r
+ \r
+ void put(int channel, Task task, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void Host::putBounded(int channel, const Task& rTask, double maxRate) \r
+ throw(NativeException);\r
+ \r
+ \r
+ void send(const Task& rTask) \r
+ throw(NativeException);\r
+ \r
+ void send(const char* alias, const Task& rTask) \r
+ throw(NativeException);\r
+ \r
+ void send(const Task& rTask, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void send(const char* alias, const Task& rTask, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void sendBounded(const Task& rTask, double maxRate) \r
+ throw(NativeException);\r
+ \r
+ void sendBounded(const char* alias, const Task& rTask, double maxRate) \r
+ throw(NativeException);\r
+ \r
+ \r
+ \r
+ \r
+ protected:\r
+ // Attributes.\r
+ \r
+ /**\r
+ * This attribute represents the msg native host object. \r
+ * It is set automaticatly during the call of the static \r
+ * method Host::getByName().\r
+ *\r
+ * @see Host::getByName().\r
+ */ \r
+ m_host_t nativeHost;\r
+ \r
+ private:\r
+ /**\r
+ * User host data. \r
+ */ \r
+ void* data;\r
+ };\r
\r
- void* data;\r
- };\r
-}\r
+ typedef Host* HostPtr;\r
+ } // namespace Msg\r
+} // namespace SimGrid\r
\r
#endif // !MSG_HOST_HPP
\ No newline at end of file