#include <Host.hpp>\r
\r
-namespace msg\r
+namespace SimGrid\r
{\r
-// Default constructor.\r
+namespace Msg\r
+{\r
+\r
+\r
Host::Host()\r
{\r
nativeHost = NULL;\r
data = NULL;\r
}\r
\r
-// Copy constructor.\r
Host::Host(const Host& rHost)\r
{\r
+ this->nativeHost = rHost.nativeHost;\r
+ this->data = rHost.getData(); \r
}\r
\r
-// Destructor.\r
Host::~Host()\r
{\r
- nativeHost = NULL;\r
+ // NOTHING TODO\r
}\r
\r
-// Operations\r
\r
Host& Host::getByName(const char* hostName)\r
-throw(HostNotFoundException)\r
+throw(HostNotFoundException, InvalidParameterException, BadAllocException)\r
{\r
- m_host_t nativeHost; // native host.\r
- Host* host = NULL; // wrapper host.\r
- \r
- /* get the host by name (the hosts are created during the grid resolution) */\r
- nativeHost = MSG_get_host_by_name(name);\r
- DEBUG2("MSG gave %p as native host (simdata=%p)",nativeHost,nativeHost->simdata);\r
+ // check the parameters\r
+ if(!hostName)\r
+ throw InvalidParmeterException("hostName");\r
+ \r
+ m_host_t nativeHost = NULL; // native host.\r
+ Host* host = NULL; // wrapper host.\r
\r
- if(!nativeHost) \r
- {// invalid host name\r
- // TODO throw HostNotFoundException\r
- return NULL;\r
- }\r
+ if(!(nativeHost = MSG_get_host_by_name(hostName))) \r
+ throw HostNotFoundException(hostName);\r
\r
if(!nativeHost->data) \r
{ // native host not associated yet with its wrapper\r
\r
// instanciate a new wrapper \r
- host = new Host();\r
- \r
+ if(!(host = new Host())\r
+ throw BadAllocException(hostName);\r
+ \r
host->nativeHost = nativeHost; \r
\r
// the native host data field is set with its wrapper returned \r
- \r
nativeHost->data = (void*)host;\r
}\r
\r
return *host;\r
}\r
\r
-int Host::all(Host** hosts) \r
+void Host::all(Host*** hosts, int* len) \r
+throw(InvalidParameterException, BadAllocException) \r
{\r
+ /* check the parameters */\r
+ if(!hosts)\r
+ throw InvalidParameterException("hosts");\r
+ \r
+ if(len < 0)\r
+ throw InvalidParameterException("len parameter must be positive");\r
+ \r
int count = xbt_fifo_size(msg_global->host);\r
\r
- *hosts = new Host[count];\r
+ if(*len < count)\r
+ throw InvalidParameterException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)");\r
+ \r
int index;\r
m_host_t nativeHost;\r
Host* host;\r
\r
if(!host) \r
{\r
- host = new Host();\r
+ if(!(host = new Host())\r
+ {\r
+ // release all allocated memory.\r
+ for(int i = 0; i < index; i++)\r
+ delete (*(hosts)[i]);\r
+ \r
+ throw BadAllocException("to fill the table of the hosts installed on your platform");\r
+ }\r
\r
host->nativeHost = nativeHost;\r
nativeHost->data = (void*)host;\r
}\r
\r
- hosts[index] = host;\r
+ (*hosts)[index] = host;\r
}\r
\r
- return count; \r
+ *len = count; \r
}\r
\r
\r
}\r
}\r
\r
-\r
-\r
-\r
- \r
-\r
void Host::send(const Task& rTask) \r
throw(NativeException) \r
{ \r
} \r
\r
\r
-}
\ No newline at end of file
+} // namspace Msg\r
+} // namespace SimGrid
\ No newline at end of file