Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use pointers instead references.
[simgrid.git] / src / cxx / Process.cxx
index 0de536e..856ce5e 100644 (file)
-#include <Process.hpp>\r
-\r
-namespace msg\r
-{\r
-       \r
-Process* Process::currentProcess = NULL;\r
-\r
-// Default constructor.\r
-Process::Process()\r
-{\r
-       this->nativeProcess = NULL;\r
-}\r
-\r
-Process::Process(const char* hostname, const char* name)\r
-throw(HostNotFoundException)\r
-{\r
-       Host host = Host::getByName(hostname);\r
-               \r
-       create(host, name, 0, NULL);    \r
-}\r
-\r
-Process::Process(const char* hostname, const char* name, int argc, char** argv)\r
-throw(HostNotFoundException)\r
-{\r
-       Host host = Host::getByName(hostname);\r
-               \r
-       create(host, name, argc, argv); \r
-}\r
+/*\r
+ * Process.cxx\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
\r
+ /* Process member functions implementation.\r
+  */  \r
 \r
-Process::Process(const Host& rHost, const char* name)\r
-throw(HostNotFoundException)\r
-{\r
-       \r
-       create(rHost, name, 0, NULL);   \r
-}\r
+#include <Process.hpp>\r
 \r
-Process::Process(const Host& rHost, const char* name, int argc, char** argv)\r
-throw(HostNotFoundException)\r
-{\r
-       \r
-       create(rHost, name, argc, argv);        \r
-}\r
 \r
-int Process::run(int argc, char** argv)\r
-{\r
-       Process* process =(Process*)argv[argc];\r
-       \r
-       return process->main(argc, argv);\r
-}\r
+#include <ApplicationHandler.hpp>\r
+#include <Host.hpp>\r
+#include <Task.hpp>\r
 \r
-void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
-throw(HostNotFoundException)\r
-{\r
-       smx_process_t nativeCurrentProcess = NULL;\r
-       nativeProcess = xbt_new0(s_smx_process_t, 1);\r
-       smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1);\r
-       smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName());\r
-       \r
-       argv = (char**)realloc(argc + 1, sizeo(char*));\r
-       \r
-       argv[argc] = (char*)this;\r
-       \r
-       \r
-       // TODO throw HostNotFoundException if host is NULL\r
-       \r
-       // Simulator Data\r
-       simdata->smx_host = nativeHost;\r
-       simdata->mutex = NULL;\r
-       simdata->cond = NULL;\r
-       simdata->argc = argc;\r
-       simdata->argv = argv;\r
-       simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv);\r
-       \r
-       /* Process structure */\r
-       nativeProcess->name = xbt_strdup(name);\r
-       nativeProcess->simdata = simdata;\r
-       \r
-       // Set process data\r
-       nativeProcess->data = NULL;\r
-       \r
-       // Set process properties\r
-       simdata->properties = NULL;\r
-       \r
-       xbt_swag_insert(nativeProcess, nativeHost->simdata->process_list);\r
-       \r
-       /* fix current_process, about which xbt_context_start mocks around */\r
-       nativeCurrentProcess = simix_global->current_process;\r
-       xbt_context_start(nativeProcess->simdata->context);\r
-       simix_global->current_process = nativeCurrentProcess;\r
-       \r
-       xbt_swag_insert(nativeProcess, simix_global->process_list);\r
-       DEBUG2("Inserting %s(%s) in the to_run list", nativeProcess->name, nativeHost->name);\r
-       xbt_swag_insert(nativeProcess, simix_global->process_to_run);\r
-}\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
 \r
+#include <msg/msg.h>\r
+#include <msg/private.h>\r
+#include <msg/mailbox.h>\r
 \r
-int Process::killAll(int resetPID) \r
-{\r
-    return MSG_process_killall(resetPID);\r
-}\r
 \r
-void Process::suspend(void)\r
-throw(NativeException)\r
-{\r
-    if(MSG_OK != MSG_process_suspend(nativeProcess)) \r
-    {\r
-       // TODO throw NativeException.\r
-    }\r
-}\r
 \r
-void Process::resume(void) \r
-throw(NativeException)\r
+namespace SimGrid\r
 {\r
-       if(MSG_OK != MSG_process_resume(nativeProcess))\r
+       namespace Msg\r
        {\r
-               // TODO throw NativeException.\r
-       }\r
-}\r
-\r
-\r
-bool Process::isSuspended(void)\r
-{\r
-   return (bool)MSG_process_is_suspended(nativeProcess);\r
-}  \r
-\r
 \r
-Host& Process::getHost(void) \r
-throw(NativeException) \r
-{\r
-  m_host_t nativeHost = MSG_process_get_host(nativeProcess);\r
-       \r
-  if(!nativeHost->data) \r
-  {\r
-    // TODO throw NativeException.\r
-    return NULL;\r
-  }\r
-\r
-  // return the reference to the Host object\r
-  return (*((Host*)nativeHost->data));\r
-} \r
+               MSG_IMPLEMENT_DYNAMIC(Process, Object);\r
 \r
-Process& Process::fromPID(int PID) \r
-throw(ProcessNotFoundException, NativeException)\r
-{\r
-       Process* process = NULL;\r
-       m_process_t nativeProcess = MSG_process_from_PID(PID);\r
-       \r
-       \r
-       if(!process) \r
-       {\r
-               throw ProcessNotFoundException;\r
-               return NULL;\r
-       }\r
-       \r
-       process = Process::fromNativeProcess(nativeProcess);\r
+               // Default constructor.\r
+               Process::Process()\r
+               {\r
+                       this->nativeProcess = NULL;\r
+               }\r
                \r
-       if(!process) \r
-       {\r
-               //      TODO throw NativeException\r
-               return NULL;\r
-       }\r
-       \r
-       return (*process);   \r
-}\r
-\r
-// TODO implement this method\r
-Process& Process::fromNativeProcess(m_process_t nativeProcess)\r
-{\r
-       \r
-}\r
-\r
-int Process::getPID(void)\r
-{\r
-    return MSG_process_get_PID(nativeProcess);\r
-}\r
-\r
-int Process::getPPID(void)\r
-{\r
-       return MSG_process_get_PPID(nativeProcess);\r
-}\r
-\r
-\r
-Process& Process::currentProcess(void)\r
-throw(NativeException)\r
-{\r
-       Process* currentProcess = NULL;\r
-    m_process_t currentNativeProcess = MSG_process_self();\r
-\r
-\r
-       if(!currentNativeProcess) \r
-       {\r
-       // TODO throw NativeException\r
-       }\r
-       \r
-       currentProcess = Process::fromNativeProcess(currentNativeProcess);\r
-               \r
-       if(!currentProcess) \r
-       {\r
-               //      TODO throw NativeException\r
-               return NULL;\r
-       }\r
-       \r
-       return (*currentProcess);  \r
-}\r
-\r
-int Process::currentProcessPID(void)\r
-{\r
-        return MSG_process_self_PID();\r
-}\r
-\r
-\r
-int Process::currentProcessPPID(void)\r
-{\r
-       return MSG_process_self_PPID();\r
-}\r
-\r
-void Process::migrate(const Host& rHost)\r
-throw(NativeException)\r
-{\r
-       if(MSG_OK != MSG_process_change_host(nativeProcess, rHost.nativeHost))\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
-       \r
-}\r
-\r
-void Process::sleep(double seconds)\r
-throw(NativeException)\r
-{\r
-       if(MSG_OK != MSG_process_sleep(seconds))\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
-       \r
-}\r
-\r
-void Process::putTask(const Host& rHost, int channel, const Task& rTask)\r
-throw( NativeException)\r
-{\r
-       if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, -1.0))\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
-}\r
-\r
-void Process::putTask(const Host& rHost, int channel, const Task& rTask, double timeout) \r
-throw(NativeException)\r
-{\r
-       if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, timeout))\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
-}\r
-\r
-Task& Process::getTask(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 NativeException\r
-               return NULL;\r
-       }\r
-       \r
-       return (*((Task*)(nativeTask->data)));\r
-}\r
-\r
-Task& Process::getTask(int channel, double timeout) \r
-throw(NativeException)\r
-{\r
-       m_task_t nativeTask = NULL;\r
-       \r
-       \r
-       if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, NULL)) \r
-       {\r
-               // TODO throw NativeException\r
-               return NULL;\r
-       }\r
-       \r
-       return (*((Task*)(nativeTask->data)));\r
-}\r
-\r
-Task& Process::getTask(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 NativeException\r
-               return NULL;\r
-       }\r
-       \r
-       return (*((Task*)(nativeTask->data)));\r
-}\r
-\r
-Task& Process::getTask(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 NativeException\r
-               return NULL;\r
-       }\r
-       \r
-       return (*((Task*)(nativeTask->data)));\r
-}\r
-\r
-void Process::sendTask(const char* alias, const Task& rTask, double timeout) \r
-throw(NativeException)\r
-{\r
-       if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout))\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
+               Process::Process(const char* hostName, const char* name)\r
+               throw(NullPointerException, HostNotFoundException, BadAllocException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(!name)\r
+                               throw NullPointerException("name");\r
+                               \r
+                       if(!hostName)\r
+                               throw NullPointerException("hostName");\r
+                       \r
+                       Host host = Host::getByName(hostName);\r
+                               \r
+                       create(host, name, 0, NULL);    \r
+               }\r
                \r
-}\r
-\r
-void Process::sendTask(const char* alias, const Task& rTask) \r
-throw(NativeException)\r
-{\r
-       if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0))\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
-}\r
-\r
-void Process::sendTask(const Task& rTask) \r
-throw(NativeException)\r
-{\r
-       MSG_error_t rv;\r
-       \r
-       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
-       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
-       \r
-       rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0);\r
-       \r
-       free(alias);\r
-       \r
-       if(MSG_OK != rv)\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
-}\r
-\r
-void Process::sendTask(const Task& rTask, double timeout) \r
-throw(NativeException)\r
-{\r
-       MSG_error_t rv;\r
-       \r
-       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
-       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
-       \r
-       rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout);\r
-       \r
-       free(alias);\r
-       \r
-       if(MSG_OK != rv)\r
-       {\r
-               // TODO throw NativeException\r
-       }\r
-}\r
-\r
-Task& Process::receiveTask(const char* alias) \r
-throw(NativeException)\r
-{\r
-       \r
-       m_task_t nativeTask = NULL;\r
-       \r
-       if (MSG_OK !=  MSG_task_receive_ext(&nativeTask,alias, -1.0, NULL)) \r
-       {\r
-               // TODO throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-\r
-Task& Process::receiveTask(void) \r
-throw(NativeException)\r
-{\r
-       m_task_t nativeTask = NULL;\r
-       \r
-       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
-       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
-       \r
-       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);\r
-       \r
-       free(alias);\r
-       \r
-       if(MSG_OK !=  rv) \r
-       {\r
-               //TODO throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-\r
-Task& Process::receiveTask(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 throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-\r
-Task& Process::receiveTask(double timeout) \r
-throw(NativeException)\r
-{\r
-       m_task_t nativeTask = NULL;\r
-       \r
-       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
-       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
-       \r
-       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, NULL);\r
-       \r
-       free(alias);\r
-       \r
-       if(MSG_OK !=  rv) \r
-       {\r
-               //TODO throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-\r
-Task& Process::receiveTask(const char* alias, double timeout, const Host& rHost) \r
-throw(NativeException)\r
-{\r
-       m_task_t nativeTask = NULL;\r
-       \r
-       if(MSG_OK !=  MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) \r
-       {\r
-               //TODO throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-\r
-Task& Process::receiveTask(double timeout, const Host& rHost) \r
-throw(NativeException)\r
-{\r
-       m_task_t nativeTask = NULL;\r
-       \r
-       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
-       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
-       \r
-       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost);\r
-       \r
-       free(alias);\r
-       \r
-       if(MSG_OK !=  rv) \r
-       {\r
-               //TODO throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-\r
-Task& Process::receiveTask(const char* alias, const Host& rHost) \r
-throw(NativeException)\r
-{\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 throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-Task& Process::receiveTask(const Host& rHost) \r
-throw(NativeException)\r
-{\r
-       m_task_t nativeTask = NULL;\r
-       \r
-       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
-       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
-       \r
-       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost);\r
-       \r
-       free(alias);\r
-       \r
-       if(MSG_OK !=  rv) \r
-       {\r
-               //TODO throw NativeException\r
-               return NULL;\r
-       }\r
-\r
-       return (*((Task*)nativeTask->data));\r
-}\r
-\r
-const char* Process::getName(void) const\r
-{\r
-       return nativeProcess->name;\r
-}\r
+               Process::Process(const Host& rHost, const char* name)\r
+               throw(NullPointerException)\r
+               {\r
+                       if(!name)\r
+                               throw NullPointerException("name");\r
+                               \r
+                       create(rHost, name, 0, NULL);   \r
+               }\r
+               \r
+               Process::Process(const Host& rHost, const char* name, int argc, char** argv)\r
+               throw(NullPointerException, InvalidArgumentException, LogicException)\r
+               {\r
+                       \r
+                       // check the parameters\r
+                       \r
+                       if(!name)\r
+                               throw NullPointerException("name");\r
+                               \r
+                       if(argc < 0)\r
+                               throw InvalidArgumentException("argc (must be positive)");\r
+                               \r
+                       if(!argc && argv)\r
+                               throw LogicException("argv is not NULL but argc is zero");\r
+                       \r
+                       if(argc && !argv)\r
+                               throw LogicException("argv is NULL but argc is not zero");\r
+                       \r
+                       create(rHost, name, argc, argv);        \r
+               }\r
+               \r
+               Process::Process(const char* hostName, const char* name, int argc, char** argv)\r
+               throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(!name)\r
+                               throw NullPointerException("name");\r
+                               \r
+                       if(!hostName)\r
+                               throw NullPointerException("hostName");\r
+                               \r
+                       if(argc < 0)\r
+                               throw InvalidArgumentException("argc (must be positive)");\r
+                               \r
+                       if(!argc && argv)\r
+                               throw LogicException("argv is not NULL but argc is zero");\r
+                       \r
+                       if(argc && !argv)\r
+                               throw LogicException("argv is NULL but argc is not zero");\r
+                               \r
+                       Host host = Host::getByName(hostName);\r
+                               \r
+                       create(host, name, argc, argv); \r
+               }\r
+               \r
+               int Process::killAll(int resetPID) \r
+               {\r
+                   return MSG_process_killall(resetPID);\r
+               }\r
+               \r
+               void Process::suspend(void)\r
+               throw(MsgException)\r
+               {\r
+                   if(MSG_OK != MSG_process_suspend(nativeProcess)) \r
+                       throw MsgException("MSG_process_suspend() failed");\r
+               }\r
+               \r
+               void Process::resume(void) \r
+               throw(MsgException)\r
+               {\r
+                       if(MSG_OK != MSG_process_resume(nativeProcess))\r
+                               throw MsgException("MSG_process_resume() failed");\r
+               }\r
+               \r
+               int Process::isSuspended(void)\r
+               {\r
+                  return MSG_process_is_suspended(nativeProcess);\r
+               }  \r
+               \r
+               Host& Process::getHost(void) \r
+               {\r
+                 m_host_t nativeHost = MSG_process_get_host(nativeProcess);\r
+                       \r
+                 // return the reference to the Host object\r
+                 return (*((Host*)nativeHost->data));\r
+               }\r
+               \r
+               Process& Process::fromPID(int PID) \r
+               throw(ProcessNotFoundException, InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(PID < 1)\r
+                               throw InvalidArgumentException("PID (the PID of the process to retrieve is not less than 1)");\r
+                               \r
+                       Process* process = NULL;\r
+                       m_process_t nativeProcess = MSG_process_from_PID(PID);\r
+                       \r
+                       if(!nativeProcess) \r
+                               throw ProcessNotFoundException(PID);\r
+                       \r
+                       process = Process::fromNativeProcess(nativeProcess);\r
+                               \r
+                       if(!process) \r
+                               throw MsgException("Process::fromNativeProcess() failed");\r
+                       \r
+                       return (*process);   \r
+               } \r
+               \r
+               int Process::getPID(void)\r
+               {\r
+                   return MSG_process_get_PID(nativeProcess);\r
+               }\r
+               \r
+               int Process::getPPID(void)\r
+               {\r
+                       return MSG_process_get_PPID(nativeProcess);\r
+               }\r
+               \r
+               const char* Process::getName(void) const\r
+               {\r
+                       return nativeProcess->name;\r
+               }\r
+               \r
+               Process& Process::currentProcess(void)\r
+               throw(MsgException)\r
+               {\r
+                       Process* currentProcess = NULL;\r
+                   m_process_t currentNativeProcess = MSG_process_self();\r
+               \r
+               \r
+                       if(!currentNativeProcess) \r
+                               throw MsgException("MSG_process_self() failed");\r
+                       \r
+                       currentProcess = Process::fromNativeProcess(currentNativeProcess);\r
+                               \r
+                       if(!currentProcess) \r
+                               throw MsgException("Process::fromNativeProcess() failed");\r
+                       \r
+                       return (*currentProcess);  \r
+               }\r
+               \r
+               int Process::currentProcessPID(void)\r
+               {\r
+                        return MSG_process_self_PID();\r
+               }\r
+               \r
+               \r
+               int Process::currentProcessPPID(void)\r
+               {\r
+                       return MSG_process_self_PPID();\r
+               }\r
+               \r
+               void Process::migrate(const Host& rHost)\r
+               throw(MsgException)\r
+               {\r
+                       if(MSG_OK != MSG_process_change_host(rHost.nativeHost))\r
+                               throw MsgException("MSG_process_change_host()");\r
+                       \r
+               }\r
+               \r
+               void Process::sleep(double seconds)\r
+               throw(InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters.\r
+                       if(seconds <= 0)\r
+                               throw InvalidArgumentException("seconds (must not be less or equals to zero");\r
+                               \r
+                       if(MSG_OK != MSG_process_sleep(seconds))\r
+                               throw MsgException("MSG_process_sleep()");\r
+                       \r
+               }\r
+               \r
+               void Process::putTask(const Host& rHost, int channel, Task* task)\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(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, rHost.nativeHost, channel, -1.0))\r
+                               throw MsgException("MSG_task_put_with_timeout()");\r
+               }\r
+               \r
+               void Process::putTask(const Host& rHost, int channel, Task* task, double timeout) \r
+               throw(InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\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 less than zero an different of -1.0)");\r
+                               \r
+                       if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, rHost.nativeHost, channel, timeout))\r
+                               throw MsgException("MSG_task_put_with_timeout() failed");\r
+               }\r
+               \r
+               Task* Process::getTask(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* Process::getTask(int channel, double timeout) \r
+               throw(InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\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 less than zero an different of -1.0)");\r
+                       \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, NULL)) \r
+                               throw MsgException("MSG_task_get_ext() failed");\r
+                       \r
+                       return (Task*)(nativeTask->data);\r
+               }\r
+               \r
+               Task* Process::getTask(int channel, const Host& rHost) \r
+               throw(InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\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, rHost.nativeHost)) \r
+                               throw MsgException("MSG_task_get_ext() failed");\r
+                       \r
+                       return (Task*)(nativeTask->data);\r
+               }\r
+               \r
+               Task* Process::getTask(int channel, double timeout, const Host& rHost)\r
+               throw(InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\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 less than zero an different of -1.0)");\r
+                       \r
+                       m_task_t nativeTask = NULL;     \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
+               void Process::sendTask(const char* alias, Task* task, 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 (the timeout value must not be negative and different than -1.0)");\r
+                       \r
+                       if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias ,timeout))\r
+                               throw MsgException("MSG_task_send_with_timeout()");\r
+                               \r
+               }\r
+               \r
+               void Process::sendTask(const char* alias, Task* task) \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(task->nativeTask, alias ,-1.0))\r
+                               throw MsgException("MSG_task_send_with_timeout()");\r
+               }\r
+               \r
+               void Process::sendTask(Task* task) \r
+               throw(BadAllocException, MsgException)\r
+               {\r
+                       char* alias = (char*)calloc( strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
+                               \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");\r
+                               \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+                       \r
+                       MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0);\r
+                       \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK != rv)\r
+                               throw MsgException("MSG_task_send_with_timeout()");\r
+               }\r
+               \r
+               void Process::sendTask(Task* task, double timeout) \r
+               throw(BadAllocException, InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(timeout < 0 && timeout !=-1.0)\r
+                               throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
+                       \r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2 , sizeof(char));\r
+                               \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");\r
+                               \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+                       \r
+                       MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,timeout);\r
+                       \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK != rv)\r
+                               throw MsgException("MSG_task_send_with_timeout()");     \r
+               }\r
+               \r
+               Task* Process::receiveTask(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
+               \r
+               Task* Process::receiveTask(void) \r
+               throw(BadAllocException, MsgException)\r
+               {\r
+                       \r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
+                       \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");       \r
+                       \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+                       \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);\r
+                       \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK !=  rv) \r
+                               throw MsgException("MSG_task_receive_ext() failed");    \r
+               \r
+                       return (Task*)(nativeTask->data);\r
+               }\r
+               \r
+               \r
+               Task* Process::receiveTask(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 (the timeout value must not be negative and different 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
+               \r
+               Task* Process::receiveTask(double timeout) \r
+               throw(InvalidArgumentException, BadAllocException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(timeout < 0 && timeout !=-1.0)\r
+                               throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
+                               \r
+                       \r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2,  sizeof(char));\r
+                       \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");\r
+                       \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+                       \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, NULL);\r
+                       \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK !=  rv) \r
+                               throw MsgException("MSG_task_receive_ext() failed");    \r
+               \r
+                       return (Task*)(nativeTask->data);\r
+               }\r
+               \r
+               \r
+               Task* Process::receiveTask(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 && timeout !=-1.0)\r
+                               throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
+                               \r
+                       m_task_t nativeTask = NULL;\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
+               \r
+               Task* Process::receiveTask(double timeout, const Host& rHost) \r
+               throw(BadAllocException, InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(timeout < 0 && timeout !=-1.0)\r
+                               throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
+                       \r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
+                       \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");\r
+                               \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+                       \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost);\r
+                       \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK !=  rv) \r
+                               throw MsgException("MSG_task_receive_ext() failed");\r
+               \r
+                       return (Task*)(nativeTask->data);\r
+               }\r
+               \r
+               \r
+               Task* Process::receiveTask(const char* alias, const Host& rHost) \r
+               throw(NullPointerException, MsgException)\r
+               {\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* Process::receiveTask(const Host& rHost) \r
+               throw(BadAllocException, MsgException)\r
+               {\r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
+                       \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");\r
+                       \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+                       \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost);\r
+                       \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK !=  rv) \r
+                               throw MsgException("MSG_task_receive_ext() failed");\r
+               \r
+                       return (Task*)(nativeTask->data);\r
+               }\r
+\r
+               void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
+               throw(InvalidArgumentException)\r
+               {\r
+                       char alias[MAX_ALIAS_NAME + 1] = {0};\r
+                       msg_mailbox_t mailbox;\r
+                       \r
+                       \r
+                       // try to retrieve the host where to createt the process from its name\r
+                       m_host_t nativeHost = rHost.nativeHost;\r
+                       \r
+                       if(!nativeHost)\r
+                               throw InvalidArgumentException("rHost"); \r
+                       \r
+                       /* allocate the data of the simulation */\r
+                       this->nativeProcess = xbt_new0(s_m_process_t,1);\r
+                       this->nativeProcess->simdata = xbt_new0(s_simdata_process_t,1);\r
+                       this->nativeProcess->name = _strdup(name);\r
+                       this->nativeProcess->simdata->m_host = nativeHost;\r
+                       this->nativeProcess->simdata->PID = msg_global->PID++;\r
+                       \r
+                       // realloc the list of the argument to add the pointer to this process instance at the end\r
+                       if(argc)\r
+                               argv = (char**)realloc(argv , (argc + 1) * sizeof(char*));\r
+                       else\r
+                               argv = (char**)calloc(1 ,sizeof(char*));\r
+                       \r
+                       // add the pointer to this instance at the end of the list of the arguments of the process\r
+                       // so the static method Process::run() (passed as argument of the MSG function xbt_context_new())\r
+                       // can retrieve the concerned process object by the run\r
+                       // so Process::run() can call the method main() of the good process\r
+                       // for more detail see Process::run() method\r
+                       argv[argc] = (char*)this;\r
+\r
+                       this->nativeProcess->simdata->argc = argc;\r
+                       this->nativeProcess->simdata->argv = argv;\r
+                       \r
+                       this->nativeProcess->simdata->s_process = SIMIX_process_create(\r
+                                                                       this->nativeProcess->name,\r
+                                                                       Process::run, \r
+                                                                       (void*)this->nativeProcess,\r
+                                                                       nativeHost->name, \r
+                                                                       argc,\r
+                                                                       argv, \r
+                                                                       NULL);\r
+                       \r
+                       if (SIMIX_process_self()) \r
+                       {/* someone created me */\r
+                               this->nativeProcess->simdata->PPID = MSG_process_get_PID((m_process_t)SIMIX_process_self()->data);\r
+                       } \r
+                       else \r
+                       {\r
+                               this->nativeProcess->simdata->PPID = -1;\r
+                       }\r
+                       \r
+                       this->nativeProcess->simdata->last_errno = MSG_OK;\r
+                       \r
+                       /* add the process to the list of the processes of the simulation */\r
+                       xbt_fifo_unshift(msg_global->process_list, this->nativeProcess);\r
+                       \r
+                       sprintf(alias,"%s:%s",(this->nativeProcess->simdata->m_host->simdata->smx_host)->name,this->nativeProcess->name);\r
+                       \r
+                       mailbox = MSG_mailbox_new(alias);\r
+                       \r
+                       MSG_mailbox_set_hostname(mailbox, this->nativeProcess->simdata->m_host->simdata->smx_host->name);       \r
+               }\r
+               \r
+               Process* Process::fromNativeProcess(m_process_t nativeProcess)\r
+               {\r
+                       return ((Process*)(nativeProcess->simdata->argv[nativeProcess->simdata->argc]));\r
+               }\r
+               \r
+               int Process::run(int argc, char** argv)\r
+               {\r
+                       \r
+                       // the last argument of the process is the pointer to the process to run\r
+                       // for more detail see Process::create() method\r
+                       return ((Process*)argv[argc])->main(argc, argv);\r
+               }\r
+\r
+               int Process::main(int argc, char** argv)\r
+               {\r
+                       throw LogicException("Process::main() not implemented");\r
+               }\r
+\r
+               /*void* Process::operator new(size_t size)\r
+               {\r
+                       // TODO\r
+               }\r
+\r
+               void Process::operator delete(void* p)\r
+               {\r
+                       // TODO\r
+               }*/\r
+               \r
+       } // namespace Msg\r
 \r
+} // namespace SimGrid\r
 \r
-}
\ No newline at end of file