#include <Task.hpp>\r
\r
-namespace msg\r
+namespace SimGrid\r
{\r
- \r
-Task::Task()\r
-{\r
- nativeTask = NULL;\r
-}\r
-\r
-\r
-Task::Task(const Task& rTask)\r
-{\r
-}\r
-\r
-\r
-Task::~Task()\r
-throw(NativeException)\r
-{\r
- if(NULL != nativeTask)\r
+ namespace Msg\r
{\r
- if(MSG_OK != MSG_task_destroy(nativeTask))\r
+ \r
+ Task::Task()\r
+ {\r
+ nativeTask = NULL;\r
+ }\r
+ \r
+ \r
+ Task::Task(const Task& rTask)\r
+ {\r
+ }\r
+ \r
+ \r
+ Task::~Task()\r
+ throw(NativeException)\r
+ {\r
+ if(NULL != nativeTask)\r
+ if(MSG_OK != MSG_task_destroy(nativeTask))\r
+ throw MsgException("MSG_task_destroy() failed");\r
+ }\r
+ \r
+ \r
+ Task::Task(const char* name, double computeDuration, double messageSize)\r
+ throw(InvalidArgumentException, NullPointerException)\r
+ {\r
+ \r
+ if(computeDuration < 0) \r
+ throw InvalidArgumentException("computeDuration");\r
+ \r
+ if(messageSize < 0) \r
+ throw InvalidArgumentException("messageSize");\r
+ \r
+ if(!name) \r
+ throw NullPointerException("name");\r
+ \r
+ // create the task\r
+ nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL);\r
+ \r
+ nativeTask->data = (void*)this;\r
+ }\r
+ \r
+ Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)\r
+ throw(NullPointerException, InvalidArgumentException)\r
+ {\r
+ \r
+ // check the parameters\r
+ \r
+ if(!name) \r
+ throw NullPointerException("name");\r
+ \r
+ if(!hosts) \r
+ throw NullPointerException("hosts");\r
+ \r
+ if(!computeDurations) \r
+ throw NullPointerException("computeDurations");\r
+ \r
+ if(!messageSizes) \r
+ throw NullPointerException("messageSizes");\r
+ \r
+ if(!hostCount)\r
+ throw InvalidArgumentException("hostCount (must not be zero)");\r
+ \r
+ \r
+ m_host_t* nativeHosts;\r
+ double* durations;\r
+ double* sizes;\r
+ \r
+ \r
+ nativeHosts = xbt_new0(m_host_t, hostCount);\r
+ durations = xbt_new0(double,hostCount);\r
+ sizes = xbt_new0(double, hostCount * hostCount);\r
+ \r
+ \r
+ for(int index = 0; index < hostCount; index++) \r
+ {\r
+ \r
+ nativeHosts[index] = hosts[index].nativeHost;\r
+ durations[index] = computeDurations[index];\r
+ }\r
+ \r
+ for(int index = 0; index < hostCount*hostCount; index++) \r
+ sizes[index] = messageSizes[index];\r
+ \r
+ \r
+ nativeTask = MSG_parallel_task_create(name, hostCount, nativeHosts, durations, sizes,NULL);\r
+ \r
+ \r
+ \r
+ task->data = (void*)this;\r
+ \r
+ }\r
+ \r
+ const char* Task::getName(void) const\r
+ {\r
+ return nativeTask->name;\r
+ }\r
+ \r
+ Process& Task::getSender(void) const\r
+ {\r
+ m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask);\r
+ \r
+ return (*((Process*)(nativeProcess->data)));\r
+ }\r
+ \r
+ Host& Task::getSource(void) const \r
+ {\r
+ m_host_t nativeHost = MSG_task_get_source(nativeTask);\r
+ \r
+ return (*((Host*)(nativeHost->data))); \r
+ }\r
+ \r
+ double Task::getComputeDuration(void) const\r
+ {\r
+ return MSG_task_get_compute_duration(nativeTask);\r
+ }\r
+ \r
+ double Task::getRemainingDuration(void) const\r
{\r
- // TODO throw NativeException\r
+ return MSG_task_get_remaining_computation(nativeTask);\r
+ }\r
+ \r
+ void Task::setPriority(double priority)\r
+ throw(InvalidArgumentException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(priority < 0.0)\r
+ throw InvalidArgumentException("priority");\r
+ \r
+ MSG_task_set_priority(nativeTask, priority);\r
+ }\r
+ \r
+ Task& Task::get(int channel) \r
+ throw(InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(channel < 0)\r
+ throw InvalidArgumentException("channel (must not be negative)");\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) \r
+ throw MsgException("MSG_task_get_ext() failed");\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+ }\r
+ \r
+ Task& Task::get(int channel, const Host& rHost) \r
+ throw(InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(channel < 0)\r
+ throw InvalidArgumentException("channel (must not be negative)");\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost)) \r
+ throw MsgException("MSG_task_get_ext() failed");\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+ }\r
+ \r
+ Task& Task::get(int channel, double timeout, const Host& rHost) \r
+ throw(InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(channel < 0)\r
+ throw InvalidArgumentException("channel (must not be negative)");\r
+ \r
+ if(timeout < 0 && timeout !=-1.0)\r
+ throw InvalidArgumentException("timeout (must not be negative and different thant -1.0)"); \r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost)) \r
+ throw MsgException("MSG_task_get_ext() failed");\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+ }\r
+ \r
+ bool static Task::probe(int channel)\r
+ throw(InvalidArgumentException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(channel < 0)\r
+ throw InvalidArgumentException("channel (must not be negative)");\r
+ \r
+ return (bool)MSG_task_Iprobe(channel);\r
+ }\r
+ \r
+ int Task::probe(int channel, const Host& rHost)\r
+ throw(InvalidArgumentException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(channel < 0)\r
+ throw InvalidArgumentException("channel (must not be negative)");\r
+ \r
+ return MSG_task_probe_from_host(chan_id,rHost.nativeHost);\r
+ }\r
+ \r
+ void Task::execute(void) \r
+ throw(MsgException)\r
+ {\r
+ if(MSG_OK != MSG_task_execute(nativeTask))\r
+ throw MsgException("MSG_task_execute() failed");\r
+ }\r
+ \r
+ void Task::cancel(void) \r
+ throw(MsgException)\r
+ {\r
+ if(MSG_OK != MSG_task_cancel(nativeTask))\r
+ throw MsgException("MSG_task_cancel() failed");\r
+ }\r
+ \r
+ void Task::send(void) \r
+ throw(BadAllocException, MsgException)\r
+ { \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ \r
+ if(!alias)\r
+ throw BadAllocException("alias");\r
+ \r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0);\r
+ \r
+ free(alias)\r
+ \r
+ if(MSG_OK != rv)\r
+ throw MsgException("MSG_task_send_with_timeout() failed");\r
+ }\r
+ \r
+ void Task::send(const char* alias) \r
+ throw(NullPointerException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0))\r
+ throw MsgException("MSG_task_send_with_timeout() failed");\r
+ }\r
+ \r
+ void Task::send(double timeout) \r
+ throw(BadAllocationException, InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(timeout < 0 && timeout != -1.0)\r
+ throw InvalidArgumentException("timeout (must not be negative and different than -1.0");\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ \r
+ if(!alias)\r
+ throw BadAllocException("alias");\r
+ \r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, timeout);\r
+ \r
+ free(alias)\r
+ \r
+ if(MSG_OK != rv)\r
+ throw MsgException("MSG_task_send_with_timeout() failed");\r
} \r
- }\r
-}\r
-\r
-\r
-Task::Task(const char* name, double computeDuration, double messageSize)\r
-{\r
- \r
- if(computeDuration < 0) \r
- {\r
- // TODO throw exception\r
- return;\r
- }\r
- \r
- if(messageSize < 0) \r
- {\r
- // TODO throw exception\r
- return;\r
- }\r
- \r
- if(!name) \r
- {\r
- // TODO throw exception\r
- return;\r
- }\r
- \r
- // create the task\r
- nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL);\r
- \r
- nativeTask->data = (void*)this;\r
-}\r
-\r
-Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes)\r
-{\r
- // TODO parallel task create \r
-}\r
-\r
-\r
-const char* Task::getName(void) const\r
-{\r
- return nativeTask->name;\r
-}\r
-\r
-Process& Task::getSender(void) const\r
-{\r
- m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask);\r
- \r
- return (*((Process*)(nativeProcess->data)));\r
-}\r
-\r
-Host& Task::getSource(void) const \r
-throw(NativeException)\r
-{\r
- m_host_t nativeHost = MSG_task_get_source(nativeTask);\r
- \r
- if(!nativeHost->data) \r
- {\r
- // TODO throw the exception\r
- return NULL;\r
- }\r
- \r
- return (*((Host*)(nativeHost->data))); \r
-}\r
-\r
-double Task::getComputeDuration(void) const\r
-{\r
- return MSG_task_get_compute_duration(nativeTask);\r
-}\r
-\r
-double Task::getRemainingDuration(void) const\r
-{\r
- return MSG_task_get_remaining_computation(nativeTask);\r
-}\r
-\r
-void Task::setPriority(double priority)\r
-{\r
- MSG_task_set_priority(nativeTask, priority);\r
-}\r
-\r
-Task& Task::get(int channel) \r
-throw(NativeException)\r
-{\r
- m_task_t nativeTask = NULL;\r
- \r
- \r
- if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) \r
- {\r
- // TODO throw the NativeException\r
- return NULL;\r
- }\r
- \r
- return (*((Task*)(nativeTask->data)));\r
-}\r
-\r
-Task& Task::get(int channel, const Host& rHost) \r
-throw(NativeException)\r
-{\r
- m_task_t nativeTask = NULL;\r
- \r
- \r
- if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost)) \r
- {\r
- // TODO throw the NativeException\r
- return NULL;\r
- }\r
- \r
- return (*((Task*)(nativeTask->data)));\r
-}\r
-\r
-Task& Task::get(int channel, double timeout, const Host& rHost) \r
-throw(NativeException)\r
-{\r
- m_task_t nativeTask = NULL;\r
- \r
- \r
- if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost)) \r
- {\r
- // TODO throw the NativeException\r
- return NULL;\r
- }\r
- \r
- return (*((Task*)(nativeTask->data)));\r
-}\r
-\r
-bool static Task::probe(int channel)\r
-{\r
- return (bool)MSG_task_Iprobe(channel);\r
-}\r
-\r
-int Task::probe(int channel, const Host& rHost)\r
-{\r
- return MSG_task_probe_from_host(chan_id,rHost.nativeHost);\r
-}\r
-\r
-void Task::execute(void) \r
-throw(NativeException)\r
-{\r
- if(MSG_OK != MSG_task_execute(nativeTask))\r
- {\r
- // TODO throw NativeException\r
- } \r
-}\r
-\r
-void Task::cancel(void) \r
-throw(NativeException)\r
-{\r
- if(MSG_OK != MSG_task_cancel(nativeTask))\r
- {\r
- // TODO throw NativeException\r
- } \r
-}\r
-\r
-void Task::send(void) \r
-throw(NativeException)\r
-{\r
- MSG_error_t rv;\r
- \r
- char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
- sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
\r
+ void Task::send(const char* alias, double timeout) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ if(timeout < 0 && timeout != -1.0)\r
+ throw InvalidArgumentException("timeout (must not be negative and different than -1.0");\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout))\r
+ throw MsgException("MSG_task_send_with_timeout() failed");\r
+ }\r
\r
-\r
- rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0);\r
-\r
- free(alias)\r
-\r
- if(MSG_OK != rv)\r
- {\r
- // TODO throw the NativeException\r
- }\r
-}\r
-\r
-\r
-void Task::send(const char* alias) \r
-throw(NativeException)\r
-{\r
-\r
- if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0))\r
- {\r
- // TODO throw the NativeException\r
- }\r
-}\r
-\r
-void Task::send(double timeout) \r
-throw(NativeException)\r
-{\r
- MSG_error_t rv;\r
- \r
- char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
- sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ void Task::sendBounded(double maxRate) \r
+ throw(BadAllocException, InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(maxRate < 0 && maxRate != -1.0)\r
+ throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ \r
+ if(!alias)\r
+ throw BadAllocException("alias");\r
+ \r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ MSG_error_t rv = MSG_task_send_bounded(nativeTask, alias, maxRate);\r
+ \r
+ free(alias); \r
+ \r
+ if(MSG_OK != rv)\r
+ throw MsgException("MSG_task_send_bounded() failed");\r
+ \r
+ }\r
\r
+ void Task::sendBounded(const char* alias, double maxRate) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(maxRate < 0 && maxRate != -1.0)\r
+ throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate))\r
+ throw MsgException("MSG_task_send_bounded() failed");\r
+ }\r
\r
-\r
- rv = MSG_task_send_with_timeout(nativeTask, alias, timeout);\r
-\r
- free(alias)\r
-\r
- if(MSG_OK != rv)\r
- {\r
- // TODO throw the NativeException\r
- }\r
-} \r
-\r
-void Task::send(const char* alias, double timeout) \r
-throw(NativeException)\r
-{\r
- if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout))\r
- {\r
- // TODO throw the NativeException\r
- }\r
-}\r
-\r
-void Task::sendBounded(double maxRate) \r
-throw(NativeException)\r
-{\r
- MSG_error_t rv;\r
- \r
- char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
- sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
- \r
- rv = MSG_task_send_bounded(nativeTask, alias, maxRate);\r
- \r
- free(alias);\r
- \r
- \r
- \r
- if(MSG_OK != rv)\r
- {\r
- // TODO throw the NativeException\r
- }\r
-}\r
-\r
-void Task::sendBounded(const char* alias, double maxRate) \r
-throw(NativeException)\r
-{\r
- if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate))\r
- {\r
- // TODO throw the NativeException\r
- }\r
-}\r
-\r
-Task& Task::receive(void) \r
-throw(NativeException)\r
-{\r
- MSG_error_t rv;\r
- \r
- char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
- sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ Task& Task::receive(void) \r
+ throw(throw(BadAllocException, MsgException))\r
+ {\r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ \r
+ if(!alias)\r
+ throw BadAllocException("alias");\r
+ \r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); \r
\r
- m_task_t nativeTask = NULL;\r
- \r
- rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); \r
-\r
- free(alias);\r
- \r
- if(MSG_OK != rv) \r
- {\r
- // TODO thow NativeException\r
- return NULL;\r
- }\r
-\r
- return (*((Task*)nativeTask->data));\r
-}\r
-\r
-Task& Task::receive(const char* alias) \r
-throw(NativeException)\r
-{\r
- m_task_t nativeTask = NULL;\r
- \r
- if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) \r
- {\r
- // TODO thow NativeException\r
- return NULL;\r
- }\r
-\r
- return (*((Task*)nativeTask->data));\r
-}\r
-\r
-Task& Task::receive(const char* alias, double timeout) \r
-throw(NativeException)\r
-{\r
- m_task_t nativeTask = NULL;\r
- \r
- if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) \r
- {\r
- // TODO thow NativeException\r
- return NULL;\r
- }\r
-\r
- return (*((Task*)nativeTask->data));\r
-}\r
-\r
-Task& Task::receive(const char* alias, const Host& rHost) \r
-throw(NativeException)\r
-{\r
- m_task_t nativeTask = NULL;\r
- \r
- \r
- if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) \r
- {\r
- // TODO thow NativeException\r
- return NULL;\r
- }\r
-\r
- return (*((Task*)nativeTask->data));\r
-} \r
-\r
-Task& Task::receive(const char* alias, double timeout, const Host& rHost) \r
-throw(NativeException)\r
-{\r
- m_task_t nativeTask = NULL;\r
- \r
- \r
- if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) \r
- {\r
- // TODO thow NativeException\r
- return NULL;\r
- }\r
-\r
- return (*((Task*)nativeTask->data));\r
-}\r
-\r
-bool Task::listen(void) \r
-throw(NativeException)\r
-{\r
- int rv;\r
- \r
- char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
- sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv) \r
+ throw MsgException("MSG_task_receive_ext() failed");\r
\r
- rv = MSG_task_listen(alias);\r
- \r
- free(alias);\r
- \r
- return (bool)rv;\r
-} \r
-\r
-bool Task::listen(const char* alias) \r
-throw(NativeException)\r
-{\r
- return (bool)MSG_task_listen(alias);\r
-}\r
-\r
-bool Task::listenFrom(void) \r
-throw(NativeException)\r
-{\r
- int rv;\r
- \r
- char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
- sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
- \r
- rv = MSG_task_listen_from(alias);\r
- \r
- free(alias);\r
- \r
- return (int)rv;\r
-} \r
-\r
-bool Task::listenFrom(const char* alias) \r
-throw(NativeException)\r
-{\r
- return (bool)MSG_task_listen_from(alias);\r
- \r
-}\r
-\r
-bool Task::listenFromHost(const Host& rHost) \r
-throw(NativeException)\r
-{\r
- int rv;\r
- \r
- char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
- sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
- \r
- rv = MSG_task_listen_from_host(alias, rHost.nativeHost);\r
- \r
- free(alias);\r
- \r
- return (bool)rv;\r
-}\r
- \r
-bool Task::listenFromHost(const char* alias, const Host& rHost) \r
-throw(NativeException)\r
-{\r
- return (bool)MSG_task_listen_from_host(alias, rHost.nativeHost);\r
-} \r
-\r
-}\r
+ return (*((Task*)nativeTask->data));\r
+ }\r
+ \r
+ Task& Task::receive(const char* alias) \r
+ throw(NullPointerException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) \r
+ throw MsgException("MSG_task_receive_ext() failed");\r
+ \r
+ return (*((Task*)nativeTask->data));\r
+ }\r
+ \r
+ Task& Task::receive(const char* alias, double timeout) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ if(timeout < 0 && alias != -1.0)\r
+ throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) \r
+ throw MsgException("MSG_task_receive_ext() failed");\r
+ \r
+ return (*((Task*)nativeTask->data));\r
+ }\r
+ \r
+ Task& Task::receive(const char* alias, const Host& rHost) \r
+ throw(NullPointerException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) \r
+ throw MsgException("MSG_task_receive_ext() failed");\r
+ \r
+ return (*((Task*)nativeTask->data));\r
+ } \r
+ \r
+ Task& Task::receive(const char* alias, double timeout, const Host& rHost) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ if(timeout < 0 && alias != -1.0)\r
+ throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) \r
+ throw MsgException("MSG_task_receive_ext() failed");\r
+ \r
+ return (*((Task*)nativeTask->data));\r
+ }\r
+ \r
+ bool Task::listen(void) \r
+ throw(BadAllocException)\r
+ {\r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ \r
+ if(!alias)\r
+ throw BadAllocException("alias");\r
+ \r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ int rv = MSG_task_listen(alias);\r
+ \r
+ free(alias);\r
+ \r
+ return (bool)rv;\r
+ } \r
+ \r
+ bool Task::listen(const char* alias) \r
+ throw(NullPointerException)\r
+ {\r
+ // check the parameters\r
+ \r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ return (bool)MSG_task_listen(alias);\r
+ }\r
+ \r
+ int Task::listenFrom(void) \r
+ throw(BadAllocException)\r
+ {\r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ \r
+ if(!alias)\r
+ throw BadAllocException("alias");\r
+ \r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ int rv = MSG_task_listen_from(alias);\r
+ \r
+ free(alias);\r
+ \r
+ return rv;\r
+ } \r
+ \r
+ int Task::listenFrom(const char* alias) \r
+ throw(NullPointerException)\r
+ {\r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ return MSG_task_listen_from(alias);\r
+ \r
+ }\r
+ \r
+ int Task::listenFromHost(const Host& rHost) \r
+ throw(BadAllocException)\r
+ {\r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ \r
+ if(!alias)\r
+ throw BadAllocException("alias");\r
+ \r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ int rv = MSG_task_listen_from_host(alias, rHost.nativeHost);\r
+ \r
+ free(alias);\r
+ \r
+ return rv;\r
+ }\r
+ \r
+ int Task::listenFromHost(const char* alias, const Host& rHost) \r
+ throw(NullPointerException)\r
+ {\r
+ // check the parameters\r
+ if(!alias)\r
+ throw NullPointerException("alias");\r
+ \r
+ return MSG_task_listen_from_host(alias, rHost.nativeHost);\r
+ } \r
+ } // namespace Msg \r
+} // namespace SimGrid\r
\r