#include <Process.hpp>\r
\r
-namespace msg\r
+namespace SimGrid\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
+ namespace Msg\r
+ {\r
+ Process* Process::currentProcess = NULL;\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
+ // Default constructor.\r
+ Process::Process()\r
+ {\r
+ this->nativeProcess = NULL;\r
+ }\r
\r
- create(host, name, argc, argv); \r
-}\r
-\r
-Process::Process(const Host& rHost, const char* name)\r
-throw(HostNotFoundException)\r
-{\r
- \r
- create(rHost, name, 0, NULL); \r
-}\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
-\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
-\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
-{\r
- if(MSG_OK != MSG_process_resume(nativeProcess))\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
-\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
+ Process::Process(const char* hostName, const char* name)\r
+ throw(InvalidArgumentException, HostNotFoundException)\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
- 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 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
-}\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
-\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(!hostName)\r
+ throw NullPointerException("hostName");\r
+ \r
+ if(argc < 0)\r
+ throw InvalidArgument("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)\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 InvalidArgument("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
+ bool Process::isSuspended(void)\r
+ {\r
+ return (bool)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(nativeProcess, rHost.nativeHost))\r
+ throw MsgException("MSG_process_change_host()");\r
+ \r
+ }\r
+ \r
+ void Process::sleep(double seconds)\r
+ throw(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, const Task& rTask)\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(rTask.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, const Task& rTask, 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(rTask.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, const Task& rTask, 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(rTask.nativeTask, alias ,timeout))\r
+ throw MsgException("MSG_task_send_with_timeout()");\r
+ \r
+ }\r
+ \r
+ void Process::sendTask(const char* alias, const Task& rTask) \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(rTask.nativeTask, alias ,-1.0))\r
+ throw MsgException("MSG_task_send_with_timeout()");\r
+ }\r
+ \r
+ void Process::sendTask(const Task& rTask) \r
+ throw(BadAllocException, MsgException)\r
+ {\r
+ char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\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(rTask.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(const Task& rTask, 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);\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(rTask.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);\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);\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);\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);\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(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
+ throw HostNotFoundException(rHost.getName());\r
+ \r
+ argv = (char**)realloc(argc + 1, sizeo(char*));\r
+ \r
+ argv[argc] = (char*)this;\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
+ \r
+ Process& Process::fromNativeProcess(m_process_t nativeProcess)\r
+ {\r
+ return (*((Process*)(nativeProcess->simdata->arg[nativeProcess->argc])));\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
+ \r
+ } // namespace Msg\r
\r
-}
\ No newline at end of file
+} // namespace SimGrid
\ No newline at end of file