-#include <Process.hpp>\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
-#include <MsgException.hpp>\r
-#include <NullPointerException.hpp>\r
-#include <HostNotFoundException.hpp>\r
-#include <ProcessNotFoundException.hpp>\r
-#include <InvalidArgumentException.hpp>\r
-#include <BadAllocException.hpp>\r
-#include <LogicException.hpp>\r
+#include <Process.hpp>\r
\r
\r
#include <ApplicationHandler.hpp>\r
#include <msg/mailbox.h>\r
\r
\r
+\r
namespace SimGrid\r
{\r
namespace Msg\r
}\r
\r
Process::Process(const char* hostName, const char* name)\r
- throw(InvalidArgumentException, HostNotFoundException)\r
+ throw(NullPointerException, HostNotFoundException, BadAllocException)\r
{\r
// check the parameters\r
\r
}\r
\r
Process::Process(const char* hostName, const char* name, int argc, char** argv)\r
- throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException)\r
+ throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException)\r
{\r
// check the parameters\r
\r
\r
}\r
\r
- void Process::putTask(const Host& rHost, int channel, const Task& rTask)\r
+ void Process::putTask(const Host& rHost, int channel, Task* task)\r
throw(InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ 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, const Task& rTask, double timeout) \r
+ void Process::putTask(const Host& rHost, int channel, Task* task, double timeout) \r
throw(InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ 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
+ Task* Process::getTask(int channel) \r
throw(InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
- Task& Process::getTask(int channel, double timeout) \r
+ Task* Process::getTask(int channel, double timeout) \r
throw(InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
- Task& Process::getTask(int channel, const Host& rHost) \r
+ Task* Process::getTask(int channel, const Host& rHost) \r
throw(InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
- Task& Process::getTask(int channel, double timeout, const Host& rHost)\r
+ Task* Process::getTask(int channel, double timeout, const Host& rHost)\r
throw(InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
- void Process::sendTask(const char* alias, const Task& rTask, double timeout) \r
+ void Process::sendTask(const char* alias, Task* task, double timeout) \r
throw(NullPointerException, InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ 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, const Task& rTask) \r
+ void Process::sendTask(const char* alias, Task* task) \r
throw(NullPointerException, MsgException)\r
{\r
// check the parameters\r
if(!alias)\r
throw NullPointerException("alias");\r
\r
- if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0))\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(const Task& rTask) \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
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
+ MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0);\r
\r
free(alias);\r
\r
throw MsgException("MSG_task_send_with_timeout()");\r
}\r
\r
- void Process::sendTask(const Task& rTask, double timeout) \r
+ void Process::sendTask(Task* task, double timeout) \r
throw(BadAllocException, InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,timeout);\r
\r
free(alias);\r
\r
throw MsgException("MSG_task_send_with_timeout()"); \r
}\r
\r
- Task& Process::receiveTask(const char* alias) \r
+ Task* Process::receiveTask(const char* alias) \r
throw(NullPointerException, MsgException)\r
{\r
// check the parameters\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
\r
- Task& Process::receiveTask(void) \r
+ Task* Process::receiveTask(void) \r
throw(BadAllocException, MsgException)\r
{\r
\r
if(MSG_OK != rv) \r
throw MsgException("MSG_task_receive_ext() failed"); \r
\r
- return (*((Task*)nativeTask->data));\r
+ return (Task*)(nativeTask->data);\r
}\r
\r
\r
- Task& Process::receiveTask(const char* alias, double timeout) \r
+ Task* Process::receiveTask(const char* alias, double timeout) \r
throw(NullPointerException, InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
\r
- Task& Process::receiveTask(double timeout) \r
+ Task* Process::receiveTask(double timeout) \r
throw(InvalidArgumentException, BadAllocException, MsgException)\r
{\r
// check the parameters\r
if(MSG_OK != rv) \r
throw MsgException("MSG_task_receive_ext() failed"); \r
\r
- return (*((Task*)nativeTask->data));\r
+ return (Task*)(nativeTask->data);\r
}\r
\r
\r
- Task& Process::receiveTask(const char* alias, double timeout, const Host& rHost) \r
+ Task* Process::receiveTask(const char* alias, double timeout, const Host& rHost) \r
throw(NullPointerException, InvalidArgumentException, MsgException)\r
{\r
// check the parameters\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
\r
- Task& Process::receiveTask(double timeout, const Host& rHost) \r
+ Task* Process::receiveTask(double timeout, const Host& rHost) \r
throw(BadAllocException, InvalidArgumentException, MsgException)\r
{\r
// check the parameters\r
if(MSG_OK != rv) \r
throw MsgException("MSG_task_receive_ext() failed");\r
\r
- return (*((Task*)nativeTask->data));\r
+ return (Task*)(nativeTask->data);\r
}\r
\r
\r
- Task& Process::receiveTask(const char* alias, const Host& rHost) \r
+ Task* Process::receiveTask(const char* alias, const Host& rHost) \r
throw(NullPointerException, MsgException)\r
{\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
+ return (Task*)(nativeTask->data);\r
}\r
\r
- Task& Process::receiveTask(const Host& rHost) \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
if(MSG_OK != rv) \r
throw MsgException("MSG_task_receive_ext() failed");\r
\r
- return (*((Task*)nativeTask->data));\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
- \r
- // allocate the native process\r
- this->nativeProcess = xbt_new0(s_smx_process_t, 1);\r
- \r
- // allocate the simulation data of the native process\r
- smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1);\r
- \r
- // try to retrieve the host where to createt the process from its name\r
- smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName());\r
- \r
- if(!nativeHost)\r
- throw HostNotFoundException(rHost.getName());\r
- \r
- // realloc the list of the argument to add the pointer to this process instance at the end\r
- argv = (char**)realloc(argc + 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
- // Simulator Data\r
- simdata->smx_host = nativeHost;\r
- simdata->mutex = NULL;\r
- simdata->cond = NULL;\r
- simdata->argc = argc;\r
- simdata->argv = argv;\r
- \r
- // create the context of the process.\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
- this->nativeProcess->name = xbt_strdup(name);\r
- this->nativeProcess->simdata = simdata;\r
- \r
- // Set process data\r
- this->nativeProcess->data = NULL;\r
- \r
- // Set process properties\r
- simdata->properties = NULL;\r
- \r
- xbt_swag_insert(this->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(this->nativeProcess->simdata->context);\r
- simix_global->current_process = nativeCurrentProcess;\r
- \r
- xbt_swag_insert(this->nativeProcess, simix_global->process_list);\r
- DEBUG2("Inserting %s(%s) in the to_run list", this->nativeProcess->name, nativeHost->name);\r
- xbt_swag_insert(this->nativeProcess, simix_global->process_to_run);\r
- }*/\r
\r
void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
throw(InvalidArgumentException)\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
+ 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
\r
// the last argument of the process is the pointer to the process to run\r
- // for mor detail see Process::create() method\r
+ // for more detail see Process::create() method\r
return ((Process*)argv[argc])->main(argc, argv);\r
}\r
\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
\ No newline at end of file
+} // namespace SimGrid\r
+\r