15 Host::Host(const Host& rHost)
\r
17 this->nativeHost = rHost.nativeHost;
\r
18 this->data = rHost.getData();
\r
27 Host& Host::getByName(const char* hostName)
\r
28 throw(HostNotFoundException, InvalidParameterException, BadAllocException)
\r
30 // check the parameters
\r
32 throw InvalidParmeterException("hostName");
\r
34 m_host_t nativeHost = NULL; // native host.
\r
35 Host* host = NULL; // wrapper host.
\r
37 if(!(nativeHost = MSG_get_host_by_name(hostName)))
\r
38 throw HostNotFoundException(hostName);
\r
40 if(!nativeHost->data)
\r
41 { // native host not associated yet with its wrapper
\r
43 // instanciate a new wrapper
\r
44 if(!(host = new Host())
\r
45 throw BadAllocException(hostName);
\r
47 host->nativeHost = nativeHost;
\r
49 // the native host data field is set with its wrapper returned
\r
50 nativeHost->data = (void*)host;
\r
53 // return the reference to cxx wrapper
\r
54 return *((Host*)nativeHost->data);
\r
57 int Host::getNumber(void)
\r
59 return MSG_get_host_number();
\r
62 Host& Host::currentHost(void)
\r
65 m_host_t nativeHost = MSG_host_self();
\r
67 if(!nativeHost->data)
\r
69 // the native host not yet associated with its wrapper
\r
71 // instanciate a new wrapper
\r
74 host->nativeHost = nativeHost;
\r
76 nativeHost->data = (void*)host;
\r
80 host = (Host*)nativeHost->data;
\r
86 void Host::all(Host*** hosts, int* len)
\r
87 throw(InvalidParameterException, BadAllocException)
\r
89 /* check the parameters */
\r
91 throw InvalidParameterException("hosts");
\r
94 throw InvalidParameterException("len parameter must be positive");
\r
96 int count = xbt_fifo_size(msg_global->host);
\r
99 throw InvalidParameterException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)");
\r
102 m_host_t nativeHost;
\r
105 m_host_t* table = (m_host_t *)xbt_fifo_to_array(msg_global->host);
\r
107 for(index = 0; index < count; index++)
\r
109 nativeHost = table[index];
\r
110 host = (Host*)(nativeHost->data);
\r
114 if(!(host = new Host())
\r
116 // release all allocated memory.
\r
117 for(int i = 0; i < index; i++)
\r
118 delete (*(hosts)[i]);
\r
120 throw BadAllocException("to fill the table of the hosts installed on your platform");
\r
123 host->nativeHost = nativeHost;
\r
124 nativeHost->data = (void*)host;
\r
127 (*hosts)[index] = host;
\r
134 const char* Host::getName(void) const
\r
136 return nativeHost->name;
\r
140 void Host::setData(void* data)
\r
147 void* Host::getData(void) const
\r
152 int Host::getRunningTaskNumber(void) const
\r
154 return MSG_get_host_msgload(nativeHost);
\r
157 double Host::getSpeed(void) const
\r
159 return MSG_get_host_speed(nativeHost->simdata->smx_host);
\r
162 bool Host::hasData(void) const
\r
164 return (NULL != this->data);
\r
167 bool Host::isAvailable(void) const
\r
169 return (bool)SIMIX_host_get_state(nativeHost->simdata->smx_host);
\r
172 void Host::put(int channel, const Task& rTask)
\r
173 throw(NativeException)
\r
175 if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , -1.0))
\r
177 // TODO throw NativeException
\r
181 void Host::put(int channel, const Task& rTask, double timeout)
\r
182 throw(NativeException)
\r
184 if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , timeout))
\r
186 // TODO throw NativeException
\r
190 void Host::putBounded(int channel, const Task& rTask, double maxRate)
\r
191 throw(NativeException)
\r
193 MsgNative.hostPutBounded(this, channel, task, maxrate);
\r
195 if(MSG_OK != MSG_task_put_bounded(rTask.nativeTask, nativeHost, channel, maxRate))
\r
197 // TODO throw NativeException
\r
201 void Host::send(const Task& rTask)
\r
202 throw(NativeException)
\r
206 char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);
\r
207 sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());
\r
210 rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0);
\r
216 // TODO throw NativeException
\r
220 void Host::send(const char* alias, const Task& rTask)
\r
221 throw(NativeException)
\r
224 if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0))
\r
226 // TODO throw NativeException
\r
230 void Host::send(const Task& rTask, double timeout)
\r
231 throw(NativeException)
\r
235 char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);
\r
236 sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());
\r
239 rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout);
\r
245 // TODO throw NativeException
\r
249 void Host::send(const char* alias, const Task& rTask, double timeout)
\r
250 throw(NativeException)
\r
252 if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout))
\r
254 // TODO throw NativeException
\r
259 void Host::sendBounded(const Task& rTask, double maxRate)
\r
260 throw(NativeException)
\r
265 char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);
\r
266 sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());
\r
268 rv = MSG_task_send_bounded(rTask.nativeTask, alias, maxRate);
\r
274 // TODO throw NativeException
\r
278 void Host::sendBounded(const char* alias, const Task& rTask, double maxRate)
\r
279 throw(NativeException)
\r
281 if(MSG_OK != MSG_task_send_bounded(rTask.nativeTask, alias, maxRate))
\r
283 // TODO throw NativeException
\r
289 } // namespace SimGrid