\r
#include <stdlib.h>\r
\r
+#include <ClassNotFoundException.hpp>\r
+\r
namespace msg\r
{\r
//////////////////////////////////////////////////////////////////////////////\r
// Operations\r
\r
// Create the runtime class from its name.\r
- static Class* fromName(const char* name);\r
+ static Class* fromName(const char* name)\r
+ throw (ClassNotFoundException);\r
\r
// Create an object from the name of the its class.\r
static Object* createObject(const char* name);\r
// create the cxx process wrapper.\r
void ApplicationHandler::ProcessFactory::createProcess() \r
{\r
+ Host host;\r
+ Process* process;\r
+ \r
// dynamic creation of a instance fo the process from its name (which is specified by the element function\r
// in the xml application file.\r
- Process* process = (Process*)Class::fromName(this->function);\r
+ try\r
+ {\r
+ process = (Process*)Class::fromName(this->function);\r
+ }\r
+ catch(ClassNotFoundException e)\r
+ {\r
+ cerr << e.toString(); \r
+ }\r
\r
- // retrieve the host of the process from its name\r
- Host host = Host::getByName(this->hostName);\r
+ // try to retrieve the host of the process from its name\r
+ try\r
+ {\r
+ host = Host::getByName(this->hostName); \r
+ }\r
+ catch(HostNotFoundException(this->hostName))\r
+ {\r
+ cerr << e.toString();\r
+ }\r
+ \r
\r
// build the list of the arguments of the newly created process.\r
int argc = xbt_dynar_length(this->args);\r
}\r
\r
Environment::Environment(const char* file)\r
- throw(InvalidArgumentException);\r
+ throw(NullPointerException, InvalidArgumentException);\r
{\r
// check parameters\r
\r
if(!file)\r
- throw InvalidParameterException("file (must not be NULL");\r
+ throw NullPointerException("file (must not be NULL");\r
\r
struct stat statBuf = {0};\r
\r
}\r
\r
void Environment::load(const char* file)\r
- throw(InvalidArgumentException, LogicException)\r
+ throw(NullPointerException, FileNotFoundException, LogicException)\r
{\r
// check logic\r
\r
// check the parameters\r
\r
if(!file)\r
- throw InvalidParameterException("file (must not be NULL");\r
+ throw NullPointerException("file");\r
\r
struct stat statBuf = {0};\r
\r
if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
- throw InvalidParameterException("file (file not found)");\r
+ throw FileNotFoundException(file);\r
\r
MSG_create_environment(file);\r
\r
\r
// Getters/setters\r
void Environment::setFile(const char* file)\r
- throw(InvalidArgumentException, LogicException)\r
+ throw(NullPointerException, FileNotFoundException, LogicException)\r
{\r
// check logic\r
\r
// check parameters\r
\r
if(!file)\r
- throw InvalidParameterException("file (must not be NULL");\r
+ throw NullPointerException("file (must not be NULL");\r
\r
struct stat statBuf = {0};\r
\r
if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
- throw InvalidParameterException("file (file not found)");\r
+ throw FileNotFoundException("file (file not found)");\r
\r
this->file = file;\r
}\r
+/*\r
+ * Environment.hpp\r
+ *\r
+ * This file contains the declaration of the wrapper class of the native MSG task type.\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
#ifndef MSG_ENVIRONMENT_HPP\r
#define MSG_ENVIRONMENT_HPP\r
\r
#error Environment.hpp requires C++ compilation (use a .cxx suffix)\r
#endif\r
\r
-#include <InvalidParameterException.hpp>\r
+#include <NullPointerException.hpp>\r
+#include <FileNotFoundException.hpp>\r
#include <LogicException.hpp>\r
#include <MsgException.hpp>\r
\r
{\r
public:\r
\r
+ /*! \brief Default constructor.\r
+ */\r
Environment();\r
\r
+ /*! \brief Copy constructor.\r
+ */\r
Environment(const Environment& rEnvironment);\r
\r
+ /*! \brief Constructor.\r
+ *\r
+ * \param file The xml file describing the environment of the simulation.\r
+ *\r
+ * \exception If this constructor fails, it throws one of the exception\r
+ * described below:\r
+ *\r
+ * [NullPointerException] if the parameter file is NULL.\r
+ *\r
+ * [FileNotFoundException] if the file is not found.\r
+ */\r
Environment(const char* file)\r
- throw(InvalidArgumentException);\r
+ throw(NullPointerException, FileNotFoundException);\r
\r
+ /*! \brief Destructor.\r
+ */\r
virtual ~Environment();\r
\r
- // Operations.\r
+ // Operations.\r
\r
+ /*! brief Environment::load() - Load the environment of a simulation.\r
+ *\r
+ * \exception If this method fails, it throws the exception described below:\r
+ *\r
+ * [LogicException] if the file of the environment is not yet specified or\r
+ * if the environment is already loaded.\r
+ */\r
void load(void)\r
throw(LogicException);\r
\r
+ /*! \brief Environment::load() - Load the environment of a simulation.\r
+ *\r
+ * \param file The xml file describing the environment of the simulation.\r
+ *\r
+ * \exception If this method fails, it throws one of the exceptions described below.\r
+ *\r
+ * [NullPointerException] if the parameter file is NULL.\r
+ *\r
+ * [FileNotFoundException] if the specified file is not found.\r
+ *\r
+ * [LogicException] if the environment is already loaded.\r
+ */\r
void load(const char* file)\r
- throw(InvalidArgumentException, LogicException);\r
+ throw(NullPointerException, FileNotFoundException, LogicException);\r
\r
+ /*! \brief Environment::isLoaded() - Tests if an environment is loaded.\r
+ *\r
+ * \return If the environment is loaded, the method returns true. Otherwise the method\r
+ * returns false.\r
+ */\r
bool isLoaded(void) const;\r
\r
- // Getters/setters\r
+ // Getters/setters\r
+ /*! \brief Environment::setFile() - Sets the xml file of the environment.\r
+ *\r
+ * \param file The file describing the environment.\r
+ *\r
+ * \exception If the method fails, it throws one of the exceptions described below:\r
+ *\r
+ * [NullPointerException] if the parameter file is NULL.\r
+ * \r
+ * [FileNotFoundException] if the file is not found.\r
+ *\r
+ * [LogicException] if the environment is already loaded.\r
+ */\r
void setFile(const char* file)\r
- throw(InvalidArgumentException, LogicException);\r
+ throw(NullPointerException, FileNotFoundException, LogicException);\r
\r
+ /*! \brief Environment::getFile() - Gets the xml file environment description.\r
+ *\r
+ * \return The xml file describing the environment. \r
+ *\r
+ */\r
const char* getFile(void) const;\r
\r
- // Operators.\r
+ // Operators.\r
\r
+ /*! \brief Assignment operator.\r
+ *\r
+ * \exception If this operator fails, it throws the exception described below:\r
+ *\r
+ * [LogicException] if you try to assign a loaded environment.\r
+ */\r
const Environment& operator = (const Environment& rEnvironment)\r
throw(LogicException);\r
\r
*\r
* \remark To specify no rate set the maxRate parameter value with -1.0.\r
*/\r
- void Host::putBounded(int channel, const Task& rTask, double maxRate) \r
+ void putBounded(int channel, const Task& rTask, double maxRate) \r
throw(MsgException, InvalidParameterException);\r
\r
/* ! brief Host::send() - sends the given task to mailbox identified by the default alias.\r
}\r
\r
MSG_DELCARING_CLASSES.unlock();\r
- return cur;\r
+ throw ClassNotFoundException(name);\r
}\r
\r
Object* Class::createObject(const char* name)\r
#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
+/*\r
+ * Process.hpp\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
#ifndef MSG_PROCESS_HPP\r
#define MSG_PROCESS_HPP\r
\r
#error Process.hpp requires C++ compilation (use a .cxx suffix)\r
#endif\r
\r
-namespace msg\r
-{\r
- \r
-class Process\r
+\r
+namespace SimGrid\r
{\r
- \r
- friend ApplicationHandler;\r
- \r
- private;\r
- \r
- // Default constructor.\r
- Process();\r
- \r
- public:\r
- \r
- // Construct a process from the name of the host and its name. \r
- Process(const char* hostName, const char* name)\r
- throw(HostNotFoundException);\r
- \r
- Process(const Host& rHost, const char* name)\r
- throw(HostNotFoundException);\r
- \r
- Process(const char* hostName, const char* name, int argc, char** argv)\r
- throw(HostNotFoundException);\r
- \r
- Process(const Host& rHost, const char* name, int argc, char** argv)\r
- throw(HostNotFoundException);\r
- \r
- static int killAll(int resetPID);\r
- \r
- void Process::suspend(void)\r
- throw(NativeException);\r
- \r
- void Process::resume(void) \r
- throw(NativeException);\r
- \r
- bool isSuspended(void);\r
- \r
- Host& getHost(void) \r
- throw(NativeException);\r
- \r
- static Process& fromPID(int PID); \r
- \r
- \r
- int getPID(void);\r
- \r
- int getPPID(void);\r
- \r
- const char* getName(void) const;\r
- \r
- static Process& currentProcess(void);\r
- \r
- static int currentProcessPID(void);\r
- \r
- static int currentProcessPPID(void);\r
- \r
- void migrate(const Host& rHost)\r
- throw(NativeException);\r
- \r
- static void sleep(double seconds)\r
- throw(NativeException);\r
- \r
- void putTask(const Host& rHost, int channel, const Task& rTask)\r
- throw( NativeException);\r
- \r
- void putTask(const Host& rHost, int channel, const Task& rTask, double timeout) \r
- throw(NativeException);\r
- \r
- Task& getTask(int channel) \r
- throw(NativeException);\r
- \r
- Task& getTask(int channel, double timeout) \r
- throw(NativeException);\r
- \r
- Task& getTask(int channel, const Host& rHost) \r
- throw(NativeException);\r
- \r
- Task& getTask(int channel, double timeout, const Host& rHost)\r
- throw(NativeException);\r
- \r
- void sendTask(const char* alias, const Task& rTask, double timeout) \r
- throw(NativeException);\r
- \r
- void sendTask(const char* alias, const Task& rTask) \r
- throw(NativeException);\r
- \r
- void sendTask(const Task& rTask) \r
- throw(NativeException);\r
- \r
- void sendTask(const Task& rTask, double timeout) \r
- throw(NativeException);\r
- \r
- Task& receiveTask(const char* alias) \r
- throw(NativeException);\r
- \r
- Task& receiveTask(void) \r
- throw(NativeException);\r
- \r
- Task& receiveTask(const char* alias, double timeout) \r
- throw(NativeException);\r
- \r
- Task& receiveTask(double timeout) \r
- throw(NativeException);\r
- \r
- Task& receiveTask(const char* alias, double timeout, const Host& rHost) \r
- throw(NativeException);\r
- \r
- Task& Process::receiveTask(double timeout, const Host& rHost) \r
- throw(NativeException);\r
- \r
- Task& receiveTask(const char* alias, const Host& rHost) \r
- throw(NativeException);\r
- \r
- Task& receiveTask(const Host& rHost) \r
- throw(NativeException);\r
- \r
- \r
- private:\r
- void create(const Host& rHost, const char* name, int argc, char** argv) \r
- throw(HostNotFoundException);\r
- \r
- \r
- static Process& fromNativeProcess(m_process_t nativeProcess);\r
- \r
- \r
- public:\r
- \r
- static int run(int argc, char** argv);\r
- \r
- virtual int main(int argc, char** argv) = 0;\r
- \r
- private:\r
- \r
- // Attributes.\r
- \r
- m_process_t nativeProcess; // pointer to the native msg process.\r
- \r
-};\r
+ namespace Msg\r
+ {\r
+ // SimGrid::Msg::Process class declaration.\r
+ class Process\r
+ {\r
+ friend ApplicationHandler;\r
+ \r
+ private;\r
+ \r
+ // Disable the default constructor.\r
+ Process();\r
+ \r
+ public:\r
+ \r
+ /*! \brief Constructs a process from the name of the host and its name.\r
+ *\r
+ * \param hostName The host name of the process to create.\r
+ * \param name The name of the process to create.\r
+ *\r
+ * \exception If the constructor failed, it throws one of the exceptions described\r
+ * below:\r
+ * \r
+ * [NullPointerException] if the name of the process is NULL or if the\r
+ * name of the host is NULL.\r
+ * [HostNotFoundException] if the host is not found.\r
+ */ \r
+ Process(const char* hostName, const char* name)\r
+ throw(NullPointerException, HostNotFoundException);\r
+ \r
+ /*! \brief Constructs a process from a reference to an host object and its name.\r
+ *\r
+ * \param rHost A reference to the host object representing the native\r
+ * MSG host where to create the process.\r
+ * \param name The name of the process to create.\r
+ *\r
+ * \exception If the constructor failed, it throws the exception described\r
+ * below:\r
+ *\r
+ * [NullPointerException] if the name of process is NULL.\r
+ */ \r
+ Process(const Host& rHost, const char* name)\r
+ throw(NullPointerException);\r
+ \r
+ /*! brief Construct a proces from reference to an host object and the name of the process.\r
+ * This constuctor takes also the list of the arguments of the process.\r
+ *\r
+ * \param host A reference to the host where to create the process.\r
+ * \param name The name of the process to create.\r
+ * \param argc The number of the arguments of the process to create.\r
+ * \param argv The list of arguments of the process to create.\r
+ *\r
+ * \exception If the constructor failed, it throws one of the exceptions described\r
+ * below:\r
+ *\r
+ * [NullPointerException] if the name of the host is NULL or\r
+ * if the name of the process is NULL.\r
+ * [InvalidArgumentException] if the value of the parameter argv is\r
+ * negative.\r
+ * [LogicException] if the parameter argv is NULL and the \r
+ * parameter argc is different than zero\r
+ * if the parameter argv is not NULL and \r
+ * the parameter argc is zero.\r
+ */\r
+ Process(const Host& rHost, const char* name, int argc, char** argv)\r
+ throw(NullPointerException, InvalidArgumentException, LogicException);\r
+ \r
+ /*! brief Constructs a proces from the name of a host and the name of the process.\r
+ * This constuctor takes also the list of the arguments of the process.\r
+ *\r
+ * \param hostName The name of the host where to create the process.\r
+ * \param name The name of the process to create.\r
+ * \param argc The number of the arguments of the process to create.\r
+ * \param argv The list of arguments of the process to create.\r
+ *\r
+ * \exception If the constructor failed, it throws one of the exceptions described\r
+ * below:\r
+ * \r
+ * [NullPointerException] if the name of the process or if the name\r
+ * of the host is NULL.\r
+ * [InvalidArgumentException] if the value of the parameter argv is\r
+ * negative.\r
+ * [LogicException] if the parameter argv is NULL and the \r
+ * parameter argc is different than zero\r
+ * if the parameter argv is not NULL and \r
+ * the parameter argc is zero.\r
+ * [HostNotFoundException] if the specified host is no found.\r
+ */\r
+ Process(const char* hostName, const char* name, int argc, char** argv)\r
+ throw(NullPointerException, HostNotFoundException);\r
+ \r
+ /*! \brief Process::killAll() - kill all the running processes of the simulation.\r
+ *\r
+ * \param resetPID Should we reset the PID numbers. A negative number means no reset\r
+ * and a positive number will be used to set the PID of the next newly\r
+ * created process.\r
+ *\r
+ * \return The static method returns the PID of the next created process.\r
+ */ \r
+ static int killAll(int resetPID);\r
+ \r
+ /*! \brief Process::suspend() - Suspend an MSG process.\r
+ * \r
+ * \excetpion If this method failed, it throws one the exception described below:\r
+ *\r
+ * [MsgException] if an internal exception occurs during the operation.\r
+ */\r
+ void suspend(void)\r
+ throw(MsgException);\r
+ \r
+ \r
+ \r
+ /*! \brief Process::resume() - Resume the MSG process.\r
+ *\r
+ * \exception If this method failed, it throws the exception described below:\r
+ *\r
+ * [MsgException] if an internal exception occurs during the operation.\r
+ */\r
+ void resume(void) \r
+ throw(MsgException);\r
+ \r
+ /*! \brief Process::isSuspend() - Tests if a process is suspended.\r
+ *\r
+ * \return This method returns true is the process is suspended.\r
+ * Otherwise the method returns false.\r
+ */\r
+ bool isSuspended(void);\r
+ \r
+ /*! \brief Process::getHost() - Retrieves the host of a process object.\r
+ *\r
+ * \return The method returns a reference to the\r
+ * host of the process.\r
+ *\r
+ */\r
+ Host& getHost(void); \r
+ \r
+ /*! \brief Process::fromPID() - Retrieves a process from its PID.\r
+ *\r
+ * \param PID The PID of the process to retrieve.\r
+ *\r
+ * \return If successful the method returns a reference to\r
+ * to process. Otherwise, the method throws one of\r
+ * the exceptions described below:\r
+ *\r
+ * \exception [ProcessNotFoundException] if the process is not found (no process with this PID).\r
+ *\r
+ * [InvalidArgumentException] if the parameter PID is less than 1.\r
+ *\r
+ * [MsgException] if a native error occurs during the operation.\r
+ */\r
+ static Process& fromPID(int PID)\r
+ throw(ProcessNotFoundException, InvalidArgumentException, MsgException); \r
+ \r
+ /*! \brief Process::getPID() - Gets the PID of a process object.\r
+ *\r
+ * \return This method returns the PID of a process object.\r
+ */\r
+ int getPID(void);\r
+ \r
+ /*! \brief Process::getPPID() - Gets the parent PID of a process object.\r
+ *\r
+ * \return This method returns the parent PID of a process object.\r
+ */\r
+ int getPPID(void);\r
+ \r
+ /*! \brief Process::getName() - Gets the name of a process object.\r
+ *\r
+ * \return This method returns the name of a process object.\r
+ */\r
+ const char* getName(void) const;\r
+ \r
+ /*! \brief Process::currentProcess() - Retrieves the current process.\r
+ *\r
+ * \return This method returns a reference to the current process. Otherwise\r
+ * the method throws the excepction described below:\r
+ *\r
+ * \exception [MsgException] if an internal exception occurs.\r
+ */\r
+ static Process& currentProcess(void)\r
+ throw (MsgException);\r
+ \r
+ /*! \brief Process::currentProcessPID() - Retrieves the PID of the current process.\r
+ *\r
+ * \return This method returns the PID of the current process.\r
+ */\r
+ static int currentProcessPID(void);\r
+ \r
+ /*! \brief Process::currentProcessPPID() - Retrieves the parent PID of the current process.\r
+ *\r
+ * \return This method returns the parent PID of the current process.\r
+ */\r
+ static int currentProcessPPID(void);\r
+ \r
+ /*! \brief Process::migrate() - Migrate a process object to an another host.\r
+ *\r
+ * \param rHost A reference to the host to migrate the process to.\r
+ *\r
+ * \return If successful the method migrate the process to the specified\r
+ * host. Otherwise the method throws the exception described\r
+ * below:\r
+ *\r
+ * \exception [MsgException] if an internal exception occurs.\r
+ */\r
+ void migrate(const Host& rHost)\r
+ throw(MsgException);\r
+ \r
+ /*! \brief Process::sleep() - Makes the current process sleep until time seconds have elapsed. \r
+ *\r
+ * \param seconds The number of seconds to sleep.\r
+ *\r
+ * \execption If this method failed, it throws one of the exceptions described\r
+ * below: \r
+ *\r
+ * [InvalidArgumentException] if the parameter seconds is\r
+ * less or equals to zero.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static void sleep(double seconds)\r
+ throw(InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::putTask() - This method puts a task on a given channel of a given host.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described\r
+ * below:\r
+ *\r
+ * [InvalidArgumentException] if the channel number is negative.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void putTask(const Host& rHost, int channel, const Task& rTask)\r
+ throw(InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::putTask() - This method puts a task on a given channel of a given host (waiting at most given time).\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [MsgException] if an internal error occurs.\r
+ *\r
+ * [InvalidArgumentException] if the value of the channel specified as\r
+ * parameter is negative or if the timeout value\r
+ * is less than zero and différent of -1.\r
+ *\r
+ * \remark Set the timeout with -1.0 to disable it.\r
+ */\r
+ void putTask(const Host& rHost, int channel, const Task& rTask, double timeout) \r
+ throw(InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::getTask() - Retrieves a task from a channel number (waiting at most given time).\r
+ *\r
+ * \param channel The number of the channel where to get the task.\r
+ *\r
+ * \return If successful the method returns a reference to \r
+ * the getted task. Otherwise the method throws one\r
+ * of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the channel number is negative.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& getTask(int channel) \r
+ throw(InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::taskGet() - Retrieves a task from a channel number (waiting at most given time).\r
+ *\r
+ * \param channel The number of the channel where to get the task.\r
+ * \param timeout The timeout value.\r
+ *\r
+ * \return If successful the method returns a reference to \r
+ * the getted task. Otherwise the method throws one\r
+ * of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the channel number is negative\r
+ * or if the timeout value is less than\r
+ * zero and different of -1.0.\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& getTask(int channel, double timeout) \r
+ throw(InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host.\r
+ *\r
+ * \param channel The number of the channel where to get the task.\r
+ * \param host The host of the channel to get the task.\r
+ *\r
+ * \return If successful the method returns a reference to \r
+ * the getted task. Otherwise the method throws one\r
+ * of the exceptions described below.\r
+ *\r
+ * \exception [InvalidArgumentException] if the channel number is negative.\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& getTask(int channel, const Host& rHost) \r
+ throw(InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host (waiting at most given time).\r
+ *\r
+ * \param channel The number of the channel where to get the task.\r
+ * \param timeout The timeout value.\r
+ * \param rHost The host owning the channel.\r
+ *\r
+ * \return If successful the method returns a reference to \r
+ * the getted task. Otherwise the method throws one\r
+ * of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the channel number is negative or\r
+ * if the timeout value is negative and different\r
+ * of -1.0.\r
+ * [MsgException] if an internal exception occurs.\r
+ *\r
+ * \remark Set the timeout with -1.0 to disable it.\r
+ */\r
+ Task& getTask(int channel, double timeout, const Host& rHost)\r
+ throw(InvalidArgumentException MsgException);\r
+ \r
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias\r
+ * (waiting at most given time).\r
+ *\r
+ * \param alias The alias of the mailbox where to send the task.\r
+ * \param rTask A reference to the task object to send.\r
+ * \param timeout The timeout value.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [NullPointerException] if the alias specified as parameter is NULL.\r
+ * \r
+ * [InvalidArgumentException] if the timeout value is negative and different than\r
+ * -1.0\r
+ * [MsgException] if an internal exception occurs.\r
+ *\r
+ * \remark Set the timeout with -1.0 to disable it.\r
+ */\r
+ void sendTask(const char* alias, const Task& rTask, double timeout) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias.\r
+ *\r
+ * \param alias The alias of the mailbox where to send the task.\r
+ * \param rTask A reference to the task object to send.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [NullPointerException] if the alias parameter is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ *\r
+ */\r
+ void sendTask(const char* alias, const Task& rTask) \r
+ throw(NullPointerException, MsgException);\r
+ \r
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias.\r
+ *\r
+ * \param rTask A reference to the task object to send.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ * \r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ *\r
+ */\r
+ void sendTask(const Task& rTask) \r
+ throw(BadAllocException, MsgException);\r
+ \r
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias\r
+ * (waiting at most given time).\r
+ *\r
+ * \param rTask A reference to the task object to send.\r
+ * \param timeout The timeout value.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ *\r
+ * [InvalidArgumentException] if the timeout value is negative and different than -1.0.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ *\r
+ * \remark set the timeout value with -1.0 to disable it.\r
+ */\r
+ void sendTask(const Task& rTask, double timeout) \r
+ throw(BadAllocException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as\r
+ * parameter.\r
+ *\r
+ * \param alias The alias of the mailbox where to retrieve the task.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below:\r
+ *\r
+ * \exception [NullPointerException] if the parameter alias is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& receiveTask(const char* alias) \r
+ throw(NullPointerException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below:\r
+ *\r
+ * \exception [BadAllocException] if there is not enough memory to build the alias. \r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& receiveTask(void) \r
+ throw(BadAllocException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as\r
+ * parameter(waiting at most given time).\r
+ *\r
+ * \param alias The alias of the mailbox where to retrieve the task.\r
+ * \param timeout The timeout value.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below.\r
+ *\r
+ * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.\r
+ *\r
+ * [NullPointerException] if the parameter alias is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& receiveTask(const char* alias, double timeout) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias\r
+ * (waiting at most given time).\r
+ *\r
+ * \param timeout The timeout value.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the timeout value is negative or different than -1.0.\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the alias.\r
+ * \r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& receiveTask(double timeout) \r
+ throw(InvalidArgumentException, BadAllocException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as\r
+ * parameter located on a given host (waiting at most given time).\r
+ *\r
+ * \param alias The alias of the mailbox where to retrieve the task.\r
+ * \param timeout The timeout value.\r
+ * \param rHost A reference to the host object owning the mailbox.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.\r
+ *\r
+ * [NullPointerException] if the parameter alias is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& receiveTask(const char* alias, double timeout, const Host& rHost) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias\r
+ * and located on a given host (waiting at most given time).\r
+ *\r
+ * \param timeout The timeout value.\r
+ * \param rHost A reference to the host object owning the mailbox.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the timeout value is negative and different than -1.0.\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& Process::receiveTask(double timeout, const Host& rHost) \r
+ throw(BadAllocException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias\r
+ * specified as parameter and located on a given host.\r
+ *\r
+ * \param alias The alias using to identify the mailbox from which to get the task.\r
+ * \param rHost A reference to the host object owning the mailbox.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below:\r
+ *\r
+ * \exception [NullPointerException] if the parameter alias is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& receiveTask(const char* alias, const Host& rHost) \r
+ throw(NullPointerException, MsgException);\r
+ \r
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias\r
+ * and located on a given host.\r
+ *\r
+ * \param rHost A reference to the host object owning the mailbox.\r
+ *\r
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
+ * throws one of the exceptions described below:\r
+ *\r
+ * \exception [BadAllocException] if there is not enough memory to build the alias.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ Task& receiveTask(const Host& rHost) \r
+ throw(BadAllocException, MsgException);\r
+ \r
+ \r
+ private:\r
+ \r
+ /* Process::create() - Creates a process on a given host.\r
+ *\r
+ * param rHost A reference to a host object where to create the process.\r
+ * param name The name of the process to create.\r
+ * param argc The number of argument to pass to the main function of the process.\r
+ * param argv The list of the arguments of the main function of the process.\r
+ *\r
+ * exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [HostNotFoundException] if the host specified as parameter doesn't exist.\r
+ */\r
+ void create(const Host& rHost, const char* name, int argc, char** argv) \r
+ throw(HostNotFoundException);\r
+ \r
+ /* Process::fromNativeProcess() - Retrieves the process wrapper associated with a native process.\r
+ *\r
+ * \param nativeProcess The native process to get the wrapper.\r
+ *\r
+ * \return The wrapper associated with the native process specified as parameter.\r
+ */\r
+ static Process& fromNativeProcess(m_process_t nativeProcess);\r
+ \r
+ \r
+ public:\r
+ \r
+ /* Process::run() - used to set the field code of the context of the process.\r
+ */ \r
+ static int run(int argc, char** argv);\r
+ \r
+ /*! \brief Process::main() - This virtual pure function is the main function of the process.\r
+ * You must override this function for each new class of process that you create.\r
+ *\r
+ * \param argc The number of parameters of the main function.\r
+ * \param argv The list of the parameter of the main function.\r
+ *\r
+ * \return The exit code of the main function.\r
+ */\r
+ virtual int main(int argc, char** argv) = 0;\r
+ \r
+ private:\r
+ \r
+ // Attributes.\r
+ \r
+ m_process_t nativeProcess; // pointer to the native msg process.\r
+ \r
+ };\r
+ \r
+ } //namepace Msg\r
\r
-}
\ No newline at end of file
+} namespace SimGrid
\ No newline at end of file
}\r
\r
// initialize the MSG simulator. Must be done before anything else (even logging).\r
- Simulator::init(argc, argv);\r
+ init(argc, argv);\r
\r
// the environment to load\r
- Environment environment(argv[1]);\r
+ Environment environment;\r
+ \r
// the application to deploy\r
- Application application(argv[2]);\r
+ Application application;\r
+ \r
// the simulation\r
Simulation simulation;\r
\r
- // load the environment\r
- environment.load();\r
+ // try to load the environment described by the xml file (argv[1])\r
+ try\r
+ {\r
+ environment.load(argv[1]);\r
+ }\r
+ catch(InvalidArgumentException e)\r
+ {\r
+ info(e.toString());\r
+ finalize();\r
+ return 1;\r
+ }\r
+ catch(LogicException e)\r
+ {\r
+ info(e.toString());\r
+ finalize();\r
+ return 1;\r
+ }\r
+ \r
+ \r
+ // try to deploy the application described by the xml file deployment (argv[2])\r
+ try\r
+ {\r
+ application.deploy(argv[2]);\r
+ catch(InvalidArgumentException e)\r
+ {\r
+ info(e.toString());\r
+ finalize();\r
+ return 1;\r
+ }\r
+ catch(LogicException e)\r
+ {\r
+ info(e.toString());\r
+ finalize();\r
+ return 1;\r
+ }\r
+ \r
+ //try to run the simulation the given application on the given environment\r
+ try\r
+ {\r
+ simulation.run(environment, application);\r
+ }\r
+ catch(MsgException e)\r
+ {\r
+ info(e.toString());\r
+ finalize();\r
+ return 1;\r
+ }\r
\r
- // deploy the application\r
- application.deploy();\r
+ // finalize the MSG simulator\r
\r
- // run the simulation\r
- simulation.run(environment, application);\r
+ try\r
+ {\r
+ finalize();\r
+ }\r
+ catch(MsgExceptio e)\r
+ {\r
+ info(e.toString())\r
+ return 1;\r
+ }\r
\r
- // finalize the simulator\r
- Simulator::finalize();\r
+ return 0;\r
+ }\r
+ \r
+ void run(const Environment& rEnvironment, const Application& rApplication)\r
+ throw (MsgException)\r
+ {\r
+ if(MSG_OK != MSG_main())\r
+ throw MsgException("MSG_main() failed");\r
}\r
} // namespace Msg\r
} // namespace SimGrid\r
\r
int execute(int argc, char** argv);\r
\r
+ void run(const Environment& rEnvironment, const Application& rApplication)\r
+ throw (MsgException);\r
+ \r
\r
// Operators.\r
\r
#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
+/*\r
+ * Task.hpp\r
+ *\r
+ * This file contains the declaration of the wrapper class of the native MSG task type.\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
#ifndef MSG_TASK_HPP\r
#define MSG_TASK_HPP\r
\r
#error Process.hpp requires C++ compilation (use a .cxx suffix)\r
#endif\r
\r
-namespace msg\r
+namespace SimGrid\r
{\r
-class Task\r
-{\r
- protected:\r
- // Default constructor.\r
- Task();\r
- \r
- public:\r
- // Copy constructor.\r
- Task(const Task& rTask);\r
- \r
- // Destructor.\r
- virtual ~Task()\r
- throw(NativeException);\r
- \r
- // Other constructors.\r
- Task(const char* name, double computeDuration, double messageSize);\r
- \r
- Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes);\r
- \r
- \r
- // Getters/setters.\r
- const char* getName(void) const;\r
- \r
- \r
- Process& getSender(void) const;\r
- \r
- Host& getSource(void) const \r
- throw(NativeException);\r
- \r
- double getComputeDuration(void) const;\r
- \r
- double getRemainingDuration(void) const;\r
- \r
- void setPriority(double priority);\r
- \r
- static Task& get(int channel) \r
- throw(NativeException); \r
- \r
- static Task& get(int channel, const Host& rHost) \r
- throw(NativeException);\r
- \r
- static Task& get(int channel, double timeout, const Host& rHost) \r
- throw(NativeException); \r
- \r
- static bool probe(int channel);\r
- \r
- static int probe(int channel, const Host& rHost);\r
- \r
- void execute(void) \r
- throw(NativeException);\r
- \r
- void cancel(void) \r
- throw(NativeException);\r
- \r
- \r
- void send(void) \r
- throw(NativeException);\r
- \r
- void send(const char* alias) \r
- throw(NativeException);\r
- \r
- void send(double timeout) \r
- throw(NativeException);\r
- \r
- void send(const char* alias, double timeout) \r
- throw(NativeException);\r
- \r
- void sendBounded(double maxRate) \r
- throw(NativeException);\r
- \r
- void sendBounded(const char* alias, double maxRate) \r
- throw(NativeException);\r
- \r
- static Task& receive(void) \r
- throw(NativeException);\r
- \r
- static Task& receive(const char* alias) \r
- throw(NativeException);\r
- \r
- static Task& receive(const char* alias, double timeout) \r
- throw(NativeException);\r
- \r
- static Task& receive(const char* alias, const Host& rHost) \r
- throw(NativeException);\r
- \r
- static Task& receive(const char* alias, double timeout, const Host& rHost) \r
- throw(NativeException);\r
- \r
- static bool listen(void) \r
- throw(NativeException);\r
- \r
- static bool listen(const char* alias) \r
- throw(NativeException);\r
- \r
- static bool listenFrom(void) \r
- throw(NativeException);\r
- \r
- static bool listenFrom(const char* alias) \r
- throw(NativeException);\r
- \r
- \r
- static bool listenFromHost(const Host& rHost) \r
- throw(NativeException);\r
- \r
- static bool listenFromHost(const char* alias, const Host& rHost) \r
- throw(NativeException);\r
- \r
- \r
- \r
- private:\r
- \r
- m_task_t nativeTask;\r
- \r
- \r
-};\r
-\r
-}\r
+ namespace Msg\r
+ {\r
+ // SimGrid::Msg::Task wrapper class declaration.\r
+ class Task\r
+ {\r
+ protected:\r
+ // Default constructor.\r
+ Task();\r
+ \r
+ public:\r
+ /*! \brief Copy constructor.\r
+ */\r
+ Task(const Task& rTask);\r
+ \r
+ /*! \brief Destructor.\r
+ *\r
+ * \exception If the destructor failed, it throw the exception described below:\r
+ *\r
+ * [MsgException] if a native exception occurs.\r
+ */\r
+ virtual ~Task()\r
+ throw(MsgException);\r
+ \r
+ /*! \brief Constructs an new task with the specified processing amount and amount\r
+ * of data needed.\r
+ *\r
+ * \param name Task's name\r
+ * \param computeDuration A value of the processing amount (in flop) needed to process the task. \r
+ * If 0, then it cannot be executed with the execute() method.\r
+ * This value has to be >= 0.\r
+ * \param messageSize A value of amount of data (in bytes) needed to transfert this task.\r
+ * If 0, then it cannot be transfered with the get() and put() methods.\r
+ * This value has to be >= 0.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [InvalidArgumentException] if the parameter computeDuration or messageSize\r
+ * is negative.\r
+ * [NullPointerException] if the parameter name is NULL.\r
+ *\r
+ * [MsgException] if a internal exception occurs.\r
+ */\r
+ Task(const char* name, double computeDuration, double messageSize)\r
+ throw (InvalidArgumentException, NullPointerException);\r
+ \r
+ /*! \Constructs an new parallel task with the specified processing amount and amount for each host\r
+ * implied.\r
+ *\r
+ * \param name The name of the parallel task.\r
+ * \param hosts The list of hosts implied by the parallel task.\r
+ * \param computeDurations The amount of operations to be performed by each host of \a hosts.\r
+ * \param messageSizes A matrix describing the amount of data to exchange between hosts.\r
+ * \hostCount The number of hosts implied in the parallel task.\r
+ * \r
+ * \exception If this method fails, it throws one of the exceptions described below:\r
+ *\r
+ * [NullPointerException] if the parameter name is NULL or\r
+ * if the parameter computeDurations is NULL or\r
+ * if the parameter messageSizes is NULL\r
+ *\r
+ * [InvalidArgumentException] if the parameter hostCount is negative or zero. \r
+ */\r
+ Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)\r
+ throw(NullPointerException, InvalidArgumentException);\r
+ \r
+ \r
+ /*! \brief Task::getName() - Gets the names of the task.\r
+ *\r
+ * \return The name of the task.\r
+ */\r
+ const char* getName(void) const;\r
+ \r
+ /*! \brief Task::getSender() - Gets the sender of the task.\r
+ *\r
+ * \return A reference to the sender of the task.\r
+ */\r
+ Process& getSender(void) const;\r
+ \r
+ /*! \brief Task::getSource() - Gets the source of the task.\r
+ * \r
+ * \return A reference to the source of the task.\r
+ */\r
+ Host& getSource(void) const;\r
+ \r
+ /*! \brief Task::getComputeDuration() - Get the computing amount of the task.\r
+ *\r
+ * \return The computing amount of the task.\r
+ */\r
+ \r
+ double getComputeDuration(void) const;\r
+ \r
+ /*! \brief Task::getRemainingDuration() - Gets the remaining computation.\r
+ *\r
+ * \return The remining computation of the task.\r
+ */\r
+ double getRemainingDuration(void) const;\r
+ \r
+ /*! \brief Task::setPrirority() - Sets the priority of the computation of the task.\r
+ * The priority doesn't affect the transfert rate. For example a\r
+ * priority of 2 will make the task receive two times more cpu than\r
+ * the other ones.\r
+ *\r
+ * \param priority The new priority of the task.\r
+ *\r
+ * execption If this method fails, it throws the exception described below:\r
+ *\r
+ * [InvalidArgumentException] if the parameter priority is negative.\r
+ */\r
+ void setPriority(double priority)\r
+ throw(InvalidArgumentException);\r
+ \r
+ /*! \brief Task::get() - Gets a task from the specified channel of the host of the current process.\r
+ *\r
+ * \param channel The channel number to get the task.\r
+ *\r
+ * \return If successful the method returns the task. Otherwise the method throws one\r
+ * of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the channel parameter is negative.\r
+ * \r
+ * [MsgException] if an internal excpetion occurs.\r
+ */\r
+ static Task& get(int channel) \r
+ throw(InvalidArgumentException, MsgException); \r
+ \r
+ /*! \brief Task::get() - Gets a task from the given channel number of the given host. \r
+ *\r
+ * \param channel The channel number.\r
+ * \param rHost A reference of the host owning the channel.\r
+ *\r
+ * \return If successful, the method returns the task. Otherwise the method\r
+ * throw one of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the channel number is negative.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static Task& get(int channel, const Host& rHost) \r
+ throw(InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Task::get() - Gets a task from the specified channel of the specified host\r
+ * (waiting at most given time).\r
+ *\r
+ * \param channel The channel number.\r
+ * \param timeout The timeout value.\r
+ * \param rHost A reference to the host owning the channel.\r
+ *\r
+ * \return If successful, the method returns the task. Otherwise the method returns\r
+ * one of the exceptions described below:\r
+ *\r
+ * \exception [InvalidArgumentException] if the channel number is negative or\r
+ * if the timeout value is negative and \r
+ * different than -1.0.\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static Task& get(int channel, double timeout, const Host& rHost) \r
+ throw(InvalidArgumentException, MsgException); \r
+ \r
+ /*! \brief Task::probe() - Probes whether there is a waiting task on the given channel of local host.\r
+ *\r
+ * \param channel The channel number.\r
+ *\r
+ * \return If there is a waiting task on the channel the method returns true. Otherwise\r
+ * the method returns false.\r
+ *\r
+ * \exception If this method fails, it throws the exception described below:\r
+ *\r
+ * [InvalidArgumentException] if the parameter channel is negative.\r
+ */\r
+ static bool probe(int channel)\r
+ throw(InvalidArgumentException);\r
+ \r
+ /*! \brief Task::probe() - Counts tasks waiting on the given channel of local host and sent by given host.\r
+ *\r
+ * \param channel The channel id.\r
+ * \param rHost A reference to the host that has sent the task.\r
+ *\r
+ * \return The number of tasks.\r
+ *\r
+ * \exception [InvalidArgumentException] if the parameter channel is negative.\r
+ */\r
+ static int probe(int channel, const Host& rHost)\r
+ throw(InvalidArgumentException);\r
+ \r
+ /*! \brief Task::execute() - This method executes a task on the location on which the\r
+ * process is running.\r
+ *\r
+ * \exception If this method fails, it returns the exception described below:\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void execute(void) \r
+ throw(MsgException);\r
+ \r
+ /*! \brief Task::cancel() - This method cancels a task.\r
+ *\r
+ * \exception If this method fails, it returns the exception described below:\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void cancel(void) \r
+ throw(MsgException);\r
+ \r
+ /*! \brief Task::send() - Send the task on the mailbox identified by the default alias.\r
+ *\r
+ * \exception If this method failed, it returns one of the exceptions described\r
+ * below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void send(void) \r
+ throw(BadAllocException, MsgException);\r
+ \r
+ /*! \brief Task::send() - Send the task on the mailbox identified by the given alias.\r
+ *\r
+ * \param alias The alias of the mailbox where to send the task.\r
+ *\r
+ * \exception If this method failed, it returns one of the exceptions described\r
+ * below:\r
+ *\r
+ * [NullPointerException] if there parameter alias is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */ \r
+ void send(const char* alias) \r
+ throw(NullPointerException, MsgException);\r
+ \r
+ /*! \brief Task::send() - Send the task on the mailbox identified by the default alias\r
+ * (waiting at most given time).\r
+ *\r
+ * \param timeout The timeout value.\r
+ *\r
+ * \exception If this method failed, it returns one of the exceptions described\r
+ * below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ *\r
+ * [InvalidArgumentException] if the timeout value is negative or different -1.0.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void send(double timeout) \r
+ throw(BadAllocationException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Task::send() - Send the task on the mailbox identified by a given alias\r
+ * (waiting at most given time).\r
+ *\r
+ * \param alias The alias of the mailbox where to send the task.\r
+ * \param timeout The timeout value.\r
+ *\r
+ * \exception If this method failed, it returns one of the exceptions described\r
+ * below:\r
+ *\r
+ * [NullPointerException] if alias parameter is NULL.\r
+ *\r
+ * [InvalidArgumentException] if the timeout value is negative or different -1.0.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void send(const char* alias, double timeout) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the default alias.\r
+ * (capping the emision rate to maxrate).\r
+ *\r
+ * \param maxRate The maximum rate value.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ *\r
+ * [InvalidArgumentException] if the parameter maxRate is negative and different\r
+ * than -1.0.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void sendBounded(double maxRate) \r
+ throw(BadAllocException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the given alias.\r
+ * (capping the emision rate to maxrate).\r
+ *\r
+ *\ param alias The alias of the mailbox where to send the task.\r
+ * \param maxRate The maximum rate value.\r
+ *\r
+ * \exception If this method failed, it throws one of the exceptions described below:\r
+ *\r
+ * [NullPointerException] if the alias parameter is NULL.\r
+ *\r
+ * [InvalidArgumentException] if the parameter maxRate is negative and different\r
+ * than -1.0.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ void sendBounded(const char* alias, double maxRate) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException);\r
+ \r
+ \r
+ /*! \brief Task::receive() - Receives a task from the mailbox identified by the default alias (located\r
+ * on the local host).\r
+ *\r
+ * \return A reference to the task.\r
+ *\r
+ * \exception If this method failed, it throws one of the exception described below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static Task& receive(void) \r
+ throw(BadAllocException, MsgException);\r
+ \r
+ /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located\r
+ * on the local host).\r
+ *\r
+ * \alias The alias of the mailbox.\r
+ *\r
+ * \return A reference to the task.\r
+ *\r
+ * \exception If this method failed, it throws one of the exception described below:\r
+ *\r
+ * [NullPointerException] if the alias parameter is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static Task& receive(const char* alias) \r
+ throw(NullPointerException, MsgException);\r
+ \r
+ /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located\r
+ * on the local host and waiting at most given time).\r
+ *\r
+ * \alias The alias of the mailbox.\r
+ * \timeout The timeout value.\r
+ *\r
+ * \return A reference to the task.\r
+ *\r
+ * \exception If this method failed, it throws one of the exception described below:\r
+ *\r
+ * [NullPointerException] if the alias parameter is NULL.\r
+ *\r
+ * [InvalidArgumentException] if the timeout value is negatif and different than\r
+ * -1.0.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static Task& receive(const char* alias, double timeout) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located\r
+ * on the given host.\r
+ *\r
+ * \alias The alias of the mailbox.\r
+ * \rHost The location of the mailbox.\r
+ *\r
+ * \return A reference to the task.\r
+ *\r
+ * \exception If this method failed, it throws one of the exception described below:\r
+ *\r
+ * [NullPointerException] if the alias parameter is NULL.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static Task& receive(const char* alias, const Host& rHost) \r
+ throw(NullPointerException, MsgException);\r
+ \r
+ /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located\r
+ * on the given host (and waiting at most given time).\r
+ *\r
+ * \alias The alias of the mailbox.\r
+ * \timeout The timeout value.\r
+ * \rHost The location of the mailbox.\r
+ *\r
+ * \return A reference to the task.\r
+ *\r
+ * \exception If this method failed, it throws one of the exception described below:\r
+ *\r
+ * [NullPointerException] if the alias parameter is NULL.\r
+ *\r
+ * [InvalidArgumentException] if the timeout value is negatif and different than\r
+ * -1.0.\r
+ *\r
+ * [MsgException] if an internal exception occurs.\r
+ */\r
+ static Task& receive(const char* alias, double timeout, const Host& rHost) \r
+ throw(NullPointerException, InvalidArgumentException, MsgException);\r
+ \r
+ /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox \r
+ * identified by the default alias of local host.\r
+ *\r
+ * \return If there is a waiting task on the mailbox the method returns true.\r
+ * Otherwise the method returns false.\r
+ *\r
+ * \exception If this method fails, it throws one of the exceptions described below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default alias.\r
+ */\r
+ static bool listen(void) \r
+ throw(BadAllocException);\r
+ \r
+ /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox \r
+ * identified by the given alias of local host.\r
+ *\r
+ * \param alias The alias of the mailbox.\r
+ *\r
+ * \return If there is a waiting task on the mailbox the method returns true.\r
+ * Otherwise the method returns false.\r
+ *\r
+ * \exception If this method fails, it throws one of the exceptions described below:\r
+ *\r
+ * [NullPointerException] if the parameter alias is NULL.\r
+ */\r
+ static bool listen(const char* alias) \r
+ throw(NullPointerException);\r
+ \r
+ /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox \r
+ * identified by the default alias, and who sent it.\r
+ *\r
+ * \return If there is a pending communication on the mailbox, the method returns\r
+ * the PID of it sender. Otherwise the method returns -1.\r
+ *\r
+ * \exception If this method fails, it throws the exception described below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default\r
+ * alias.\r
+ */\r
+ static int listenFrom(void) \r
+ throw(BadAllocException);\r
+ \r
+ /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox \r
+ * identified by the specified alias, and who sent it.\r
+ *\r
+ * \alias The alias of the mailbox.\r
+ *\r
+ * \return If there is a pending communication on the mailbox, the method returns\r
+ * the PID of it sender. Otherwise the method returns -1.\r
+ *\r
+ * \exception If this method fails, it throws the exception described below:\r
+ *\r
+ * [NullPointerException] if the alias parameter is NULL.\r
+ */\r
+ static int listenFrom(const char* alias) \r
+ throw(NullPointerException);\r
+ \r
+ /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox \r
+ * identified by the default alias and located on the host of the current process, and who sent it.\r
+ *\r
+ * \param rHost The location of the mailbox.\r
+ *\r
+ * \return If there is a pending communication on the mailbox, the method returns\r
+ * the PID of it sender. Otherwise the method returns -1.\r
+ *\r
+ * \exception If this method fails, it throws the exception described below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default\r
+ * alias.\r
+ */\r
+ static int listenFromHost(const Host& rHost) \r
+ throw(BadAllocException);\r
+ \r
+ /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox \r
+ * identified by the default alias and located on the host of the current process, and who sent it.\r
+ *\r
+ * \param rHost The location of the mailbox.\r
+ *\r
+ * \return If there is a pending communication on the mailbox, the method returns\r
+ * the PID of it sender. Otherwise the method returns -1.\r
+ *\r
+ * \exception If this method fails, it throws the exception described below:\r
+ *\r
+ * [BadAllocException] if there is not enough memory to build the default\r
+ * alias.\r
+ */\r
+ static bool listenFromHost(const char* alias, const Host& rHost) \r
+ throw(NullPointerException, NativeException);\r
+ \r
+ private:\r
+ \r
+ // Attributes.\r
+ \r
+ m_task_t nativeTask; // the native MSG task.\r
+ };\r
+ \r
+ } // namespace Msg \r
+} // namespace SimGrid\r
\r
#endif // §MSG_TASK_HPP
\ No newline at end of file