14 Task::Task(const Task& rTask)
\r
20 throw(NativeException)
\r
22 if(NULL != nativeTask)
\r
23 if(MSG_OK != MSG_task_destroy(nativeTask))
\r
24 throw MsgException("MSG_task_destroy() failed");
\r
28 Task::Task(const char* name, double computeDuration, double messageSize)
\r
29 throw(InvalidArgumentException, NullPointerException)
\r
32 if(computeDuration < 0)
\r
33 throw InvalidArgumentException("computeDuration");
\r
35 if(messageSize < 0)
\r
36 throw InvalidArgumentException("messageSize");
\r
39 throw NullPointerException("name");
\r
42 nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL);
\r
44 nativeTask->data = (void*)this;
\r
47 Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)
\r
48 throw(NullPointerException, InvalidArgumentException)
\r
51 // check the parameters
\r
54 throw NullPointerException("name");
\r
57 throw NullPointerException("hosts");
\r
59 if(!computeDurations)
\r
60 throw NullPointerException("computeDurations");
\r
63 throw NullPointerException("messageSizes");
\r
66 throw InvalidArgumentException("hostCount (must not be zero)");
\r
69 m_host_t* nativeHosts;
\r
74 nativeHosts = xbt_new0(m_host_t, hostCount);
\r
75 durations = xbt_new0(double,hostCount);
\r
76 sizes = xbt_new0(double, hostCount * hostCount);
\r
79 for(int index = 0; index < hostCount; index++)
\r
82 nativeHosts[index] = hosts[index].nativeHost;
\r
83 durations[index] = computeDurations[index];
\r
86 for(int index = 0; index < hostCount*hostCount; index++)
\r
87 sizes[index] = messageSizes[index];
\r
90 nativeTask = MSG_parallel_task_create(name, hostCount, nativeHosts, durations, sizes,NULL);
\r
94 task->data = (void*)this;
\r
98 const char* Task::getName(void) const
\r
100 return nativeTask->name;
\r
103 Process& Task::getSender(void) const
\r
105 m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask);
\r
107 return (*((Process*)(nativeProcess->data)));
\r
110 Host& Task::getSource(void) const
\r
112 m_host_t nativeHost = MSG_task_get_source(nativeTask);
\r
114 return (*((Host*)(nativeHost->data)));
\r
117 double Task::getComputeDuration(void) const
\r
119 return MSG_task_get_compute_duration(nativeTask);
\r
122 double Task::getRemainingDuration(void) const
\r
124 return MSG_task_get_remaining_computation(nativeTask);
\r
127 void Task::setPriority(double priority)
\r
128 throw(InvalidArgumentException)
\r
130 // check the parameters
\r
133 throw InvalidArgumentException("priority");
\r
135 MSG_task_set_priority(nativeTask, priority);
\r
138 Task& Task::get(int channel)
\r
139 throw(InvalidArgumentException, MsgException)
\r
141 // check the parameters
\r
144 throw InvalidArgumentException("channel (must not be negative)");
\r
146 m_task_t nativeTask = NULL;
\r
148 if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL))
\r
149 throw MsgException("MSG_task_get_ext() failed");
\r
151 return (*((Task*)(nativeTask->data)));
\r
154 Task& Task::get(int channel, const Host& rHost)
\r
155 throw(InvalidArgumentException, MsgException)
\r
157 // check the parameters
\r
160 throw InvalidArgumentException("channel (must not be negative)");
\r
162 m_task_t nativeTask = NULL;
\r
165 if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost))
\r
166 throw MsgException("MSG_task_get_ext() failed");
\r
168 return (*((Task*)(nativeTask->data)));
\r
171 Task& Task::get(int channel, double timeout, const Host& rHost)
\r
172 throw(InvalidArgumentException, MsgException)
\r
174 // check the parameters
\r
177 throw InvalidArgumentException("channel (must not be negative)");
\r
179 if(timeout < 0 && timeout !=-1.0)
\r
180 throw InvalidArgumentException("timeout (must not be negative and different thant -1.0)");
\r
182 m_task_t nativeTask = NULL;
\r
185 if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost))
\r
186 throw MsgException("MSG_task_get_ext() failed");
\r
188 return (*((Task*)(nativeTask->data)));
\r
191 bool static Task::probe(int channel)
\r
192 throw(InvalidArgumentException)
\r
194 // check the parameters
\r
197 throw InvalidArgumentException("channel (must not be negative)");
\r
199 return (bool)MSG_task_Iprobe(channel);
\r
202 int Task::probe(int channel, const Host& rHost)
\r
203 throw(InvalidArgumentException)
\r
205 // check the parameters
\r
208 throw InvalidArgumentException("channel (must not be negative)");
\r
210 return MSG_task_probe_from_host(chan_id,rHost.nativeHost);
\r
213 void Task::execute(void)
\r
214 throw(MsgException)
\r
216 if(MSG_OK != MSG_task_execute(nativeTask))
\r
217 throw MsgException("MSG_task_execute() failed");
\r
220 void Task::cancel(void)
\r
221 throw(MsgException)
\r
223 if(MSG_OK != MSG_task_cancel(nativeTask))
\r
224 throw MsgException("MSG_task_cancel() failed");
\r
227 void Task::send(void)
\r
228 throw(BadAllocException, MsgException)
\r
230 char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);
\r
233 throw BadAllocException("alias");
\r
235 sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());
\r
237 MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0);
\r
242 throw MsgException("MSG_task_send_with_timeout() failed");
\r
245 void Task::send(const char* alias)
\r
246 throw(NullPointerException, MsgException)
\r
248 // check the parameters
\r
251 throw NullPointerException("alias");
\r
253 if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0))
\r
254 throw MsgException("MSG_task_send_with_timeout() failed");
\r
257 void Task::send(double timeout)
\r
258 throw(BadAllocationException, InvalidArgumentException, MsgException)
\r
260 // check the parameters
\r
262 if(timeout < 0 && timeout != -1.0)
\r
263 throw InvalidArgumentException("timeout (must not be negative and different than -1.0");
\r
265 char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);
\r
268 throw BadAllocException("alias");
\r
270 sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());
\r
272 MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, timeout);
\r
277 throw MsgException("MSG_task_send_with_timeout() failed");
\r
280 void Task::send(const char* alias, double timeout)
\r
281 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
283 // check the parameters
\r
286 throw NullPointerException("alias");
\r
288 if(timeout < 0 && timeout != -1.0)
\r
289 throw InvalidArgumentException("timeout (must not be negative and different than -1.0");
\r
292 if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout))
\r
293 throw MsgException("MSG_task_send_with_timeout() failed");
\r
296 void Task::sendBounded(double maxRate)
\r
297 throw(BadAllocException, InvalidArgumentException, MsgException)
\r
299 // check the parameters
\r
301 if(maxRate < 0 && maxRate != -1.0)
\r
302 throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");
\r
304 char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);
\r
307 throw BadAllocException("alias");
\r
309 sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());
\r
311 MSG_error_t rv = MSG_task_send_bounded(nativeTask, alias, maxRate);
\r
316 throw MsgException("MSG_task_send_bounded() failed");
\r
320 void Task::sendBounded(const char* alias, double maxRate)
\r
321 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
323 // check the parameters
\r
325 if(maxRate < 0 && maxRate != -1.0)
\r
326 throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");
\r
329 throw NullPointerException("alias");
\r
331 if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate))
\r
332 throw MsgException("MSG_task_send_bounded() failed");
\r
335 Task& Task::receive(void)
\r
336 throw(throw(BadAllocException, MsgException))
\r
338 char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);
\r
341 throw BadAllocException("alias");
\r
343 sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());
\r
345 m_task_t nativeTask = NULL;
\r
347 MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);
\r
352 throw MsgException("MSG_task_receive_ext() failed");
\r
354 return (*((Task*)nativeTask->data));
\r
357 Task& Task::receive(const char* alias)
\r
358 throw(NullPointerException, MsgException)
\r
360 // check the parameters
\r
363 throw NullPointerException("alias");
\r
365 m_task_t nativeTask = NULL;
\r
367 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL))
\r
368 throw MsgException("MSG_task_receive_ext() failed");
\r
370 return (*((Task*)nativeTask->data));
\r
373 Task& Task::receive(const char* alias, double timeout)
\r
374 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
376 // check the parameters
\r
379 throw NullPointerException("alias");
\r
381 if(timeout < 0 && alias != -1.0)
\r
382 throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");
\r
384 m_task_t nativeTask = NULL;
\r
386 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL))
\r
387 throw MsgException("MSG_task_receive_ext() failed");
\r
389 return (*((Task*)nativeTask->data));
\r
392 Task& Task::receive(const char* alias, const Host& rHost)
\r
393 throw(NullPointerException, MsgException)
\r
395 // check the parameters
\r
398 throw NullPointerException("alias");
\r
400 m_task_t nativeTask = NULL;
\r
402 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost))
\r
403 throw MsgException("MSG_task_receive_ext() failed");
\r
405 return (*((Task*)nativeTask->data));
\r
408 Task& Task::receive(const char* alias, double timeout, const Host& rHost)
\r
409 throw(NullPointerException, InvalidArgumentException, MsgException)
\r
411 // check the parameters
\r
414 throw NullPointerException("alias");
\r
416 if(timeout < 0 && alias != -1.0)
\r
417 throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");
\r
419 m_task_t nativeTask = NULL;
\r
422 if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost))
\r
423 throw MsgException("MSG_task_receive_ext() failed");
\r
425 return (*((Task*)nativeTask->data));
\r
428 bool Task::listen(void)
\r
429 throw(BadAllocException)
\r
431 char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);
\r
434 throw BadAllocException("alias");
\r
436 sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());
\r
438 int rv = MSG_task_listen(alias);
\r
445 bool Task::listen(const char* alias)
\r
446 throw(NullPointerException)
\r
448 // check the parameters
\r
451 throw NullPointerException("alias");
\r
453 return (bool)MSG_task_listen(alias);
\r
456 int Task::listenFrom(void)
\r
457 throw(BadAllocException)
\r
459 char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);
\r
462 throw BadAllocException("alias");
\r
464 sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());
\r
466 int rv = MSG_task_listen_from(alias);
\r
473 int Task::listenFrom(const char* alias)
\r
474 throw(NullPointerException)
\r
477 throw NullPointerException("alias");
\r
479 return MSG_task_listen_from(alias);
\r
483 int Task::listenFromHost(const Host& rHost)
\r
484 throw(BadAllocException)
\r
486 char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);
\r
489 throw BadAllocException("alias");
\r
491 sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());
\r
493 int rv = MSG_task_listen_from_host(alias, rHost.nativeHost);
\r
500 int Task::listenFromHost(const char* alias, const Host& rHost)
\r
501 throw(NullPointerException)
\r
503 // check the parameters
\r
505 throw NullPointerException("alias");
\r
507 return MSG_task_listen_from_host(alias, rHost.nativeHost);
\r
509 } // namespace Msg
\r
510 } // namespace SimGrid
\r