From: cherierm Date: Wed, 21 May 2008 15:11:47 +0000 (+0000) Subject: Refactoring of code and documentation. X-Git-Tag: v3.3~448 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c84c646bd7234377ccdd7410915f981cc9a95ff0?ds=sidebyside Refactoring of code and documentation. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5488 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/cxx/0bject.hpp b/src/cxx/0bject.hpp index 6841835cdf..9c8a169fc4 100644 --- a/src/cxx/0bject.hpp +++ b/src/cxx/0bject.hpp @@ -10,6 +10,8 @@ #include +#include + namespace msg { ////////////////////////////////////////////////////////////////////////////// @@ -97,7 +99,8 @@ namespace msg // Operations // Create the runtime class from its name. - static Class* fromName(const char* name); + static Class* fromName(const char* name) + throw (ClassNotFoundException); // Create an object from the name of the its class. static Object* createObject(const char* name); diff --git a/src/cxx/ApplicationHandler.cxx b/src/cxx/ApplicationHandler.cxx index 425700f2ae..5d6d3f2142 100644 --- a/src/cxx/ApplicationHandler.cxx +++ b/src/cxx/ApplicationHandler.cxx @@ -85,12 +85,30 @@ namespace SimGrid // create the cxx process wrapper. void ApplicationHandler::ProcessFactory::createProcess() { + Host host; + Process* process; + // dynamic creation of a instance fo the process from its name (which is specified by the element function // in the xml application file. - Process* process = (Process*)Class::fromName(this->function); + try + { + process = (Process*)Class::fromName(this->function); + } + catch(ClassNotFoundException e) + { + cerr << e.toString(); + } - // retrieve the host of the process from its name - Host host = Host::getByName(this->hostName); + // try to retrieve the host of the process from its name + try + { + host = Host::getByName(this->hostName); + } + catch(HostNotFoundException(this->hostName)) + { + cerr << e.toString(); + } + // build the list of the arguments of the newly created process. int argc = xbt_dynar_length(this->args); diff --git a/src/cxx/Environment.cxx b/src/cxx/Environment.cxx index 5b0ea8d67e..a44fd2a340 100644 --- a/src/cxx/Environment.cxx +++ b/src/cxx/Environment.cxx @@ -24,12 +24,12 @@ namespace SimGrid } Environment::Environment(const char* file) - throw(InvalidArgumentException); + throw(NullPointerException, InvalidArgumentException); { // check parameters if(!file) - throw InvalidParameterException("file (must not be NULL"); + throw NullPointerException("file (must not be NULL"); struct stat statBuf = {0}; @@ -65,7 +65,7 @@ namespace SimGrid } void Environment::load(const char* file) - throw(InvalidArgumentException, LogicException) + throw(NullPointerException, FileNotFoundException, LogicException) { // check logic @@ -75,12 +75,12 @@ namespace SimGrid // check the parameters if(!file) - throw InvalidParameterException("file (must not be NULL"); + throw NullPointerException("file"); struct stat statBuf = {0}; if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) - throw InvalidParameterException("file (file not found)"); + throw FileNotFoundException(file); MSG_create_environment(file); @@ -95,7 +95,7 @@ namespace SimGrid // Getters/setters void Environment::setFile(const char* file) - throw(InvalidArgumentException, LogicException) + throw(NullPointerException, FileNotFoundException, LogicException) { // check logic @@ -105,12 +105,12 @@ namespace SimGrid // check parameters if(!file) - throw InvalidParameterException("file (must not be NULL"); + throw NullPointerException("file (must not be NULL"); struct stat statBuf = {0}; if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) - throw InvalidParameterException("file (file not found)"); + throw FileNotFoundException("file (file not found)"); this->file = file; } diff --git a/src/cxx/Environment.hpp b/src/cxx/Environment.hpp index 9eae1e3732..af8657df68 100644 --- a/src/cxx/Environment.hpp +++ b/src/cxx/Environment.hpp @@ -1,3 +1,17 @@ +/* + * Environment.hpp + * + * This file contains the declaration of the wrapper class of the native MSG task type. + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + #ifndef MSG_ENVIRONMENT_HPP #define MSG_ENVIRONMENT_HPP @@ -5,7 +19,8 @@ #error Environment.hpp requires C++ compilation (use a .cxx suffix) #endif -#include +#include +#include #include #include @@ -18,33 +33,97 @@ namespace SimGrid { public: + /*! \brief Default constructor. + */ Environment(); + /*! \brief Copy constructor. + */ Environment(const Environment& rEnvironment); + /*! \brief Constructor. + * + * \param file The xml file describing the environment of the simulation. + * + * \exception If this constructor fails, it throws one of the exception + * described below: + * + * [NullPointerException] if the parameter file is NULL. + * + * [FileNotFoundException] if the file is not found. + */ Environment(const char* file) - throw(InvalidArgumentException); + throw(NullPointerException, FileNotFoundException); + /*! \brief Destructor. + */ virtual ~Environment(); - // Operations. + // Operations. + /*! brief Environment::load() - Load the environment of a simulation. + * + * \exception If this method fails, it throws the exception described below: + * + * [LogicException] if the file of the environment is not yet specified or + * if the environment is already loaded. + */ void load(void) throw(LogicException); + /*! \brief Environment::load() - Load the environment of a simulation. + * + * \param file The xml file describing the environment of the simulation. + * + * \exception If this method fails, it throws one of the exceptions described below. + * + * [NullPointerException] if the parameter file is NULL. + * + * [FileNotFoundException] if the specified file is not found. + * + * [LogicException] if the environment is already loaded. + */ void load(const char* file) - throw(InvalidArgumentException, LogicException); + throw(NullPointerException, FileNotFoundException, LogicException); + /*! \brief Environment::isLoaded() - Tests if an environment is loaded. + * + * \return If the environment is loaded, the method returns true. Otherwise the method + * returns false. + */ bool isLoaded(void) const; - // Getters/setters + // Getters/setters + /*! \brief Environment::setFile() - Sets the xml file of the environment. + * + * \param file The file describing the environment. + * + * \exception If the method fails, it throws one of the exceptions described below: + * + * [NullPointerException] if the parameter file is NULL. + * + * [FileNotFoundException] if the file is not found. + * + * [LogicException] if the environment is already loaded. + */ void setFile(const char* file) - throw(InvalidArgumentException, LogicException); + throw(NullPointerException, FileNotFoundException, LogicException); + /*! \brief Environment::getFile() - Gets the xml file environment description. + * + * \return The xml file describing the environment. + * + */ const char* getFile(void) const; - // Operators. + // Operators. + /*! \brief Assignment operator. + * + * \exception If this operator fails, it throws the exception described below: + * + * [LogicException] if you try to assign a loaded environment. + */ const Environment& operator = (const Environment& rEnvironment) throw(LogicException); diff --git a/src/cxx/Host.hpp b/src/cxx/Host.hpp index 53ca4df5a3..bb219ebacc 100644 --- a/src/cxx/Host.hpp +++ b/src/cxx/Host.hpp @@ -286,7 +286,7 @@ namespace SimGrid * * \remark To specify no rate set the maxRate parameter value with -1.0. */ - void Host::putBounded(int channel, const Task& rTask, double maxRate) + void putBounded(int channel, const Task& rTask, double maxRate) throw(MsgException, InvalidParameterException); /* ! brief Host::send() - sends the given task to mailbox identified by the default alias. diff --git a/src/cxx/Object.cxx b/src/cxx/Object.cxx index 2aa26b2892..b8159d0317 100644 --- a/src/cxx/Object.cxx +++ b/src/cxx/Object.cxx @@ -50,7 +50,7 @@ Class* Class::fromName(const char* name) } MSG_DELCARING_CLASSES.unlock(); - return cur; + throw ClassNotFoundException(name); } Object* Class::createObject(const char* name) diff --git a/src/cxx/Process.cxx b/src/cxx/Process.cxx index 0de536e8fb..a4dab1a588 100644 --- a/src/cxx/Process.cxx +++ b/src/cxx/Process.cxx @@ -1,525 +1,604 @@ #include -namespace msg +namespace SimGrid { - -Process* Process::currentProcess = NULL; - -// Default constructor. -Process::Process() -{ - this->nativeProcess = NULL; -} - -Process::Process(const char* hostname, const char* name) -throw(HostNotFoundException) -{ - Host host = Host::getByName(hostname); + namespace Msg + { + Process* Process::currentProcess = NULL; - create(host, name, 0, NULL); -} - -Process::Process(const char* hostname, const char* name, int argc, char** argv) -throw(HostNotFoundException) -{ - Host host = Host::getByName(hostname); + // Default constructor. + Process::Process() + { + this->nativeProcess = NULL; + } - create(host, name, argc, argv); -} - -Process::Process(const Host& rHost, const char* name) -throw(HostNotFoundException) -{ - - create(rHost, name, 0, NULL); -} - -Process::Process(const Host& rHost, const char* name, int argc, char** argv) -throw(HostNotFoundException) -{ - - create(rHost, name, argc, argv); -} - -int Process::run(int argc, char** argv) -{ - Process* process =(Process*)argv[argc]; - - return process->main(argc, argv); -} - -void Process::create(const Host& rHost, const char* name, int argc, char** argv) -throw(HostNotFoundException) -{ - smx_process_t nativeCurrentProcess = NULL; - nativeProcess = xbt_new0(s_smx_process_t, 1); - smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1); - smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName()); - - argv = (char**)realloc(argc + 1, sizeo(char*)); - - argv[argc] = (char*)this; - - - // TODO throw HostNotFoundException if host is NULL - - // Simulator Data - simdata->smx_host = nativeHost; - simdata->mutex = NULL; - simdata->cond = NULL; - simdata->argc = argc; - simdata->argv = argv; - simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv); - - /* Process structure */ - nativeProcess->name = xbt_strdup(name); - nativeProcess->simdata = simdata; - - // Set process data - nativeProcess->data = NULL; - - // Set process properties - simdata->properties = NULL; - - xbt_swag_insert(nativeProcess, nativeHost->simdata->process_list); - - /* fix current_process, about which xbt_context_start mocks around */ - nativeCurrentProcess = simix_global->current_process; - xbt_context_start(nativeProcess->simdata->context); - simix_global->current_process = nativeCurrentProcess; - - xbt_swag_insert(nativeProcess, simix_global->process_list); - DEBUG2("Inserting %s(%s) in the to_run list", nativeProcess->name, nativeHost->name); - xbt_swag_insert(nativeProcess, simix_global->process_to_run); -} - - -int Process::killAll(int resetPID) -{ - return MSG_process_killall(resetPID); -} - -void Process::suspend(void) -throw(NativeException) -{ - if(MSG_OK != MSG_process_suspend(nativeProcess)) - { - // TODO throw NativeException. - } -} - -void Process::resume(void) -throw(NativeException) -{ - if(MSG_OK != MSG_process_resume(nativeProcess)) - { - // TODO throw NativeException. - } -} - - -bool Process::isSuspended(void) -{ - return (bool)MSG_process_is_suspended(nativeProcess); -} - - -Host& Process::getHost(void) -throw(NativeException) -{ - m_host_t nativeHost = MSG_process_get_host(nativeProcess); - - if(!nativeHost->data) - { - // TODO throw NativeException. - return NULL; - } - - // return the reference to the Host object - return (*((Host*)nativeHost->data)); -} - -Process& Process::fromPID(int PID) -throw(ProcessNotFoundException, NativeException) -{ - Process* process = NULL; - m_process_t nativeProcess = MSG_process_from_PID(PID); - - - if(!process) - { - throw ProcessNotFoundException; - return NULL; - } - - process = Process::fromNativeProcess(nativeProcess); + Process::Process(const char* hostName, const char* name) + throw(InvalidArgumentException, HostNotFoundException) + { + // check the parameters + + if(!name) + throw NullPointerException("name"); + + if(!hostName) + throw NullPointerException("hostName"); + + Host host = Host::getByName(hostName); + + create(host, name, 0, NULL); + } - if(!process) - { - // TODO throw NativeException - return NULL; - } - - return (*process); -} - -// TODO implement this method -Process& Process::fromNativeProcess(m_process_t nativeProcess) -{ - -} - -int Process::getPID(void) -{ - return MSG_process_get_PID(nativeProcess); -} - -int Process::getPPID(void) -{ - return MSG_process_get_PPID(nativeProcess); -} - - -Process& Process::currentProcess(void) -throw(NativeException) -{ - Process* currentProcess = NULL; - m_process_t currentNativeProcess = MSG_process_self(); - - - if(!currentNativeProcess) - { - // TODO throw NativeException - } - - currentProcess = Process::fromNativeProcess(currentNativeProcess); - - if(!currentProcess) - { - // TODO throw NativeException - return NULL; - } - - return (*currentProcess); -} - -int Process::currentProcessPID(void) -{ - return MSG_process_self_PID(); -} - - -int Process::currentProcessPPID(void) -{ - return MSG_process_self_PPID(); -} - -void Process::migrate(const Host& rHost) -throw(NativeException) -{ - if(MSG_OK != MSG_process_change_host(nativeProcess, rHost.nativeHost)) - { - // TODO throw NativeException - } - -} - -void Process::sleep(double seconds) -throw(NativeException) -{ - if(MSG_OK != MSG_process_sleep(seconds)) - { - // TODO throw NativeException - } - -} - -void Process::putTask(const Host& rHost, int channel, const Task& rTask) -throw( NativeException) -{ - if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, -1.0)) - { - // TODO throw NativeException - } -} - -void Process::putTask(const Host& rHost, int channel, const Task& rTask, double timeout) -throw(NativeException) -{ - if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, timeout)) - { - // TODO throw NativeException - } -} - -Task& Process::getTask(int channel) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, NULL)) - { - // TODO throw NativeException - return NULL; - } - - return (*((Task*)(nativeTask->data))); -} - -Task& Process::getTask(int channel, double timeout) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, NULL)) - { - // TODO throw NativeException - return NULL; - } - - return (*((Task*)(nativeTask->data))); -} - -Task& Process::getTask(int channel, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, rHost.nativeHost)) - { - // TODO throw NativeException - return NULL; - } - - return (*((Task*)(nativeTask->data))); -} - -Task& Process::getTask(int channel, double timeout, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, rHost.nativeHost)) - { - // TODO throw NativeException - return NULL; - } - - return (*((Task*)(nativeTask->data))); -} - -void Process::sendTask(const char* alias, const Task& rTask, double timeout) -throw(NativeException) -{ - if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout)) - { - // TODO throw NativeException - } + Process::Process(const Host& rHost, const char* name) + throw(NullPointerException) + { + if(!name) + throw NullPointerException("name"); + + create(rHost, name, 0, NULL); + } -} - -void Process::sendTask(const char* alias, const Task& rTask) -throw(NativeException) -{ - if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0)) - { - // TODO throw NativeException - } -} - -void Process::sendTask(const Task& rTask) -throw(NativeException) -{ - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0); - - free(alias); - - if(MSG_OK != rv) - { - // TODO throw NativeException - } -} - -void Process::sendTask(const Task& rTask, double timeout) -throw(NativeException) -{ - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout); - - free(alias); - - if(MSG_OK != rv) - { - // TODO throw NativeException - } -} - -Task& Process::receiveTask(const char* alias) -throw(NativeException) -{ - - m_task_t nativeTask = NULL; - - if (MSG_OK != MSG_task_receive_ext(&nativeTask,alias, -1.0, NULL)) - { - // TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - - -Task& Process::receiveTask(void) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); - - free(alias); - - if(MSG_OK != rv) - { - //TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - - -Task& Process::receiveTask(const char* alias, double timeout) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) - { - //TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - - -Task& Process::receiveTask(double timeout) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, NULL); - - free(alias); - - if(MSG_OK != rv) - { - //TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - - -Task& Process::receiveTask(const char* alias, double timeout, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) - { - //TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - - -Task& Process::receiveTask(double timeout, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost); - - free(alias); - - if(MSG_OK != rv) - { - //TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - - -Task& Process::receiveTask(const char* alias, const Host& rHost) -throw(NativeException) -{ - - m_task_t nativeTask = NULL; - - - if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) - { - //TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - -Task& Process::receiveTask(const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost); - - free(alias); - - if(MSG_OK != rv) - { - //TODO throw NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - -const char* Process::getName(void) const -{ - return nativeProcess->name; -} - + Process::Process(const Host& rHost, const char* name, int argc, char** argv) + throw(NullPointerException, InvalidArgumentException, LogicException) + { + + // check the parameters + + if(!name) + throw NullPointerException("name"); + + if(!hostName) + throw NullPointerException("hostName"); + + if(argc < 0) + throw InvalidArgument("argc (must be positive)"); + + if(!argc && argv) + throw LogicException("argv is not NULL but argc is zero"); + + if(argc && !argv) + throw LogicException("argv is NULL but argc is not zero"); + + create(rHost, name, argc, argv); + } + + Process::Process(const char* hostname, const char* name, int argc, char** argv) + throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException) + { + // check the parameters + + if(!name) + throw NullPointerException("name"); + + if(!hostName) + throw NullPointerException("hostName"); + + if(argc < 0) + throw InvalidArgument("argc (must be positive)"); + + if(!argc && argv) + throw LogicException("argv is not NULL but argc is zero"); + + if(argc && !argv) + throw LogicException("argv is NULL but argc is not zero"); + + Host host = Host::getByName(hostname); + + create(host, name, argc, argv); + } + + int Process::killAll(int resetPID) + { + return MSG_process_killall(resetPID); + } + + void Process::suspend(void) + throw(MsgException) + { + if(MSG_OK != MSG_process_suspend(nativeProcess)) + throw MsgException("MSG_process_suspend() failed"); + } + + void Process::resume(void) + throw(MsgException) + { + if(MSG_OK != MSG_process_resume(nativeProcess)) + throw MsgException("MSG_process_resume() failed"); + } + + bool Process::isSuspended(void) + { + return (bool)MSG_process_is_suspended(nativeProcess); + } + + Host& Process::getHost(void) + { + m_host_t nativeHost = MSG_process_get_host(nativeProcess); + + // return the reference to the Host object + return (*((Host*)nativeHost->data)); + } + + Process& Process::fromPID(int PID) + throw(ProcessNotFoundException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(PID < 1) + throw InvalidArgumentException("PID (the PID of the process to retrieve is not less than 1)"); + + Process* process = NULL; + m_process_t nativeProcess = MSG_process_from_PID(PID); + + if(!nativeProcess) + throw ProcessNotFoundException(PID); + + process = Process::fromNativeProcess(nativeProcess); + + if(!process) + throw MsgException("Process::fromNativeProcess() failed"); + + return (*process); + } + + int Process::getPID(void) + { + return MSG_process_get_PID(nativeProcess); + } + + int Process::getPPID(void) + { + return MSG_process_get_PPID(nativeProcess); + } + + const char* Process::getName(void) const + { + return nativeProcess->name; + } + + Process& Process::currentProcess(void) + throw(MsgException) + { + Process* currentProcess = NULL; + m_process_t currentNativeProcess = MSG_process_self(); + + + if(!currentNativeProcess) + throw MsgException("MSG_process_self() failed"); + + currentProcess = Process::fromNativeProcess(currentNativeProcess); + + if(!currentProcess) + throw MsgException("Process::fromNativeProcess() failed"); + + return (*currentProcess); + } + + int Process::currentProcessPID(void) + { + return MSG_process_self_PID(); + } + + + int Process::currentProcessPPID(void) + { + return MSG_process_self_PPID(); + } + + void Process::migrate(const Host& rHost) + throw(MsgException) + { + if(MSG_OK != MSG_process_change_host(nativeProcess, rHost.nativeHost)) + throw MsgException("MSG_process_change_host()"); + + } + + void Process::sleep(double seconds) + throw(throw(InvalidArgumentException, MsgException)) + { + // check the parameters. + if(seconds <= 0) + throw InvalidArgumentException("seconds (must not be less or equals to zero"); + + if(MSG_OK != MSG_process_sleep(seconds)) + throw MsgException("MSG_process_sleep()"); + + } + + void Process::putTask(const Host& rHost, int channel, const Task& rTask) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, -1.0)) + throw MsgException("MSG_task_put_with_timeout()"); + } + + void Process::putTask(const Host& rHost, int channel, const Task& rTask, double timeout) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + if(timeout < 0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must not be less than zero an different of -1.0)"); + + if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, timeout)) + throw MsgException("MSG_task_put_with_timeout() failed"); + } + + Task& Process::getTask(int channel) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + m_task_t nativeTask = NULL; + + if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, NULL)) + throw MsgException("MSG_task_get_ext() failed"); + + return (*((Task*)(nativeTask->data))); + } + + Task& Process::getTask(int channel, double timeout) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + if(timeout < 0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must not be less than zero an different of -1.0)"); + + m_task_t nativeTask = NULL; + + if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, NULL)) + throw MsgException("MSG_task_get_ext() failed"); + + return (*((Task*)(nativeTask->data))); + } + + Task& Process::getTask(int channel, const Host& rHost) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + m_task_t nativeTask = NULL; + + if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, rHost.nativeHost)) + throw MsgException("MSG_task_get_ext() failed"); + + return (*((Task*)(nativeTask->data))); + } + + Task& Process::getTask(int channel, double timeout, const Host& rHost) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + if(timeout < 0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must not be less than zero an different of -1.0)"); + + m_task_t nativeTask = NULL; + + if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, rHost.nativeHost)) + throw MsgException("MSG_task_get_ext() failed"); + + return (*((Task*)(nativeTask->data))); + } + + void Process::sendTask(const char* alias, const Task& rTask, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(timeout < 0 && timeout !=-1.0) + throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)"); + + if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout)) + throw MsgException("MSG_task_send_with_timeout()"); + + } + + void Process::sendTask(const char* alias, const Task& rTask) + throw(NullPointerException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0)) + throw MsgException("MSG_task_send_with_timeout()"); + } + + void Process::sendTask(const Task& rTask) + throw(BadAllocException, MsgException) + { + char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + MSG_error_t rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_with_timeout()"); + } + + void Process::sendTask(const Task& rTask, double timeout) + throw(BadAllocException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(timeout < 0 && timeout !=-1.0) + throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)"); + + char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + MSG_error_t rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_with_timeout()"); + } + + Task& Process::receiveTask(const char* alias) + throw(NullPointerException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException(alias); + + m_task_t nativeTask = NULL; + + if (MSG_OK != MSG_task_receive_ext(&nativeTask,alias, -1.0, NULL)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + + Task& Process::receiveTask(void) + throw(BadAllocException, MsgException) + { + + char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + m_task_t nativeTask = NULL; + + MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + + Task& Process::receiveTask(const char* alias, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(timeout < 0 && timeout !=-1.0) + throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)"); + + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + + Task& Process::receiveTask(double timeout) + throw(InvalidArgumentException, BadAllocException, MsgException) + { + // check the parameters + + if(timeout < 0 && timeout !=-1.0) + throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)"); + + + char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + m_task_t nativeTask = NULL; + + MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, NULL); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + + Task& Process::receiveTask(const char* alias, double timeout, const Host& rHost) + throw(NullPointerException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(timeout < 0 && timeout !=-1.0) + throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)"); + + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + + Task& Process::receiveTask(double timeout, const Host& rHost) + throw(BadAllocException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(timeout < 0 && timeout !=-1.0) + throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)"); + + char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + m_task_t nativeTask = NULL; + + MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + + Task& Process::receiveTask(const char* alias, const Host& rHost) + throw(NullPointerException, MsgException) + { + + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + Task& Process::receiveTask(const Host& rHost) + throw(BadAllocException, MsgException) + { + char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + m_task_t nativeTask = NULL; + + MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + void Process::create(const Host& rHost, const char* name, int argc, char** argv) + throw(HostNotFoundException) + { + smx_process_t nativeCurrentProcess = NULL; + nativeProcess = xbt_new0(s_smx_process_t, 1); + smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1); + smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName()); + + throw HostNotFoundException(rHost.getName()); + + argv = (char**)realloc(argc + 1, sizeo(char*)); + + argv[argc] = (char*)this; + + // Simulator Data + simdata->smx_host = nativeHost; + simdata->mutex = NULL; + simdata->cond = NULL; + simdata->argc = argc; + simdata->argv = argv; + simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv); + + /* Process structure */ + nativeProcess->name = xbt_strdup(name); + nativeProcess->simdata = simdata; + + // Set process data + nativeProcess->data = NULL; + + // Set process properties + simdata->properties = NULL; + + xbt_swag_insert(nativeProcess, nativeHost->simdata->process_list); + + /* fix current_process, about which xbt_context_start mocks around */ + nativeCurrentProcess = simix_global->current_process; + xbt_context_start(nativeProcess->simdata->context); + simix_global->current_process = nativeCurrentProcess; + + xbt_swag_insert(nativeProcess, simix_global->process_list); + DEBUG2("Inserting %s(%s) in the to_run list", nativeProcess->name, nativeHost->name); + xbt_swag_insert(nativeProcess, simix_global->process_to_run); + } + + Process& Process::fromNativeProcess(m_process_t nativeProcess) + { + return (*((Process*)(nativeProcess->simdata->arg[nativeProcess->argc]))); + } + + int Process::run(int argc, char** argv) + { + Process* process =(Process*)argv[argc]; + + return process->main(argc, argv); + } + + } // namespace Msg -} \ No newline at end of file +} // namespace SimGrid \ No newline at end of file diff --git a/src/cxx/Process.hpp b/src/cxx/Process.hpp index 1ee45b3872..10816ec469 100644 --- a/src/cxx/Process.hpp +++ b/src/cxx/Process.hpp @@ -1,3 +1,15 @@ +/* + * Process.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + #ifndef MSG_PROCESS_HPP #define MSG_PROCESS_HPP @@ -6,143 +18,570 @@ #error Process.hpp requires C++ compilation (use a .cxx suffix) #endif -namespace msg -{ - -class Process + +namespace SimGrid { - - friend ApplicationHandler; - - private; - - // Default constructor. - Process(); - - public: - - // Construct a process from the name of the host and its name. - Process(const char* hostName, const char* name) - throw(HostNotFoundException); - - Process(const Host& rHost, const char* name) - throw(HostNotFoundException); - - Process(const char* hostName, const char* name, int argc, char** argv) - throw(HostNotFoundException); - - Process(const Host& rHost, const char* name, int argc, char** argv) - throw(HostNotFoundException); - - static int killAll(int resetPID); - - void Process::suspend(void) - throw(NativeException); - - void Process::resume(void) - throw(NativeException); - - bool isSuspended(void); - - Host& getHost(void) - throw(NativeException); - - static Process& fromPID(int PID); - - - int getPID(void); - - int getPPID(void); - - const char* getName(void) const; - - static Process& currentProcess(void); - - static int currentProcessPID(void); - - static int currentProcessPPID(void); - - void migrate(const Host& rHost) - throw(NativeException); - - static void sleep(double seconds) - throw(NativeException); - - void putTask(const Host& rHost, int channel, const Task& rTask) - throw( NativeException); - - void putTask(const Host& rHost, int channel, const Task& rTask, double timeout) - throw(NativeException); - - Task& getTask(int channel) - throw(NativeException); - - Task& getTask(int channel, double timeout) - throw(NativeException); - - Task& getTask(int channel, const Host& rHost) - throw(NativeException); - - Task& getTask(int channel, double timeout, const Host& rHost) - throw(NativeException); - - void sendTask(const char* alias, const Task& rTask, double timeout) - throw(NativeException); - - void sendTask(const char* alias, const Task& rTask) - throw(NativeException); - - void sendTask(const Task& rTask) - throw(NativeException); - - void sendTask(const Task& rTask, double timeout) - throw(NativeException); - - Task& receiveTask(const char* alias) - throw(NativeException); - - Task& receiveTask(void) - throw(NativeException); - - Task& receiveTask(const char* alias, double timeout) - throw(NativeException); - - Task& receiveTask(double timeout) - throw(NativeException); - - Task& receiveTask(const char* alias, double timeout, const Host& rHost) - throw(NativeException); - - Task& Process::receiveTask(double timeout, const Host& rHost) - throw(NativeException); - - Task& receiveTask(const char* alias, const Host& rHost) - throw(NativeException); - - Task& receiveTask(const Host& rHost) - throw(NativeException); - - - private: - void create(const Host& rHost, const char* name, int argc, char** argv) - throw(HostNotFoundException); - - - static Process& fromNativeProcess(m_process_t nativeProcess); - - - public: - - static int run(int argc, char** argv); - - virtual int main(int argc, char** argv) = 0; - - private: - - // Attributes. - - m_process_t nativeProcess; // pointer to the native msg process. - -}; + namespace Msg + { + // SimGrid::Msg::Process class declaration. + class Process + { + friend ApplicationHandler; + + private; + + // Disable the default constructor. + Process(); + + public: + + /*! \brief Constructs a process from the name of the host and its name. + * + * \param hostName The host name of the process to create. + * \param name The name of the process to create. + * + * \exception If the constructor failed, it throws one of the exceptions described + * below: + * + * [NullPointerException] if the name of the process is NULL or if the + * name of the host is NULL. + * [HostNotFoundException] if the host is not found. + */ + Process(const char* hostName, const char* name) + throw(NullPointerException, HostNotFoundException); + + /*! \brief Constructs a process from a reference to an host object and its name. + * + * \param rHost A reference to the host object representing the native + * MSG host where to create the process. + * \param name The name of the process to create. + * + * \exception If the constructor failed, it throws the exception described + * below: + * + * [NullPointerException] if the name of process is NULL. + */ + Process(const Host& rHost, const char* name) + throw(NullPointerException); + + /*! brief Construct a proces from reference to an host object and the name of the process. + * This constuctor takes also the list of the arguments of the process. + * + * \param host A reference to the host where to create the process. + * \param name The name of the process to create. + * \param argc The number of the arguments of the process to create. + * \param argv The list of arguments of the process to create. + * + * \exception If the constructor failed, it throws one of the exceptions described + * below: + * + * [NullPointerException] if the name of the host is NULL or + * if the name of the process is NULL. + * [InvalidArgumentException] if the value of the parameter argv is + * negative. + * [LogicException] if the parameter argv is NULL and the + * parameter argc is different than zero + * if the parameter argv is not NULL and + * the parameter argc is zero. + */ + Process(const Host& rHost, const char* name, int argc, char** argv) + throw(NullPointerException, InvalidArgumentException, LogicException); + + /*! brief Constructs a proces from the name of a host and the name of the process. + * This constuctor takes also the list of the arguments of the process. + * + * \param hostName The name of the host where to create the process. + * \param name The name of the process to create. + * \param argc The number of the arguments of the process to create. + * \param argv The list of arguments of the process to create. + * + * \exception If the constructor failed, it throws one of the exceptions described + * below: + * + * [NullPointerException] if the name of the process or if the name + * of the host is NULL. + * [InvalidArgumentException] if the value of the parameter argv is + * negative. + * [LogicException] if the parameter argv is NULL and the + * parameter argc is different than zero + * if the parameter argv is not NULL and + * the parameter argc is zero. + * [HostNotFoundException] if the specified host is no found. + */ + Process(const char* hostName, const char* name, int argc, char** argv) + throw(NullPointerException, HostNotFoundException); + + /*! \brief Process::killAll() - kill all the running processes of the simulation. + * + * \param resetPID Should we reset the PID numbers. A negative number means no reset + * and a positive number will be used to set the PID of the next newly + * created process. + * + * \return The static method returns the PID of the next created process. + */ + static int killAll(int resetPID); + + /*! \brief Process::suspend() - Suspend an MSG process. + * + * \excetpion If this method failed, it throws one the exception described below: + * + * [MsgException] if an internal exception occurs during the operation. + */ + void suspend(void) + throw(MsgException); + + + + /*! \brief Process::resume() - Resume the MSG process. + * + * \exception If this method failed, it throws the exception described below: + * + * [MsgException] if an internal exception occurs during the operation. + */ + void resume(void) + throw(MsgException); + + /*! \brief Process::isSuspend() - Tests if a process is suspended. + * + * \return This method returns true is the process is suspended. + * Otherwise the method returns false. + */ + bool isSuspended(void); + + /*! \brief Process::getHost() - Retrieves the host of a process object. + * + * \return The method returns a reference to the + * host of the process. + * + */ + Host& getHost(void); + + /*! \brief Process::fromPID() - Retrieves a process from its PID. + * + * \param PID The PID of the process to retrieve. + * + * \return If successful the method returns a reference to + * to process. Otherwise, the method throws one of + * the exceptions described below: + * + * \exception [ProcessNotFoundException] if the process is not found (no process with this PID). + * + * [InvalidArgumentException] if the parameter PID is less than 1. + * + * [MsgException] if a native error occurs during the operation. + */ + static Process& fromPID(int PID) + throw(ProcessNotFoundException, InvalidArgumentException, MsgException); + + /*! \brief Process::getPID() - Gets the PID of a process object. + * + * \return This method returns the PID of a process object. + */ + int getPID(void); + + /*! \brief Process::getPPID() - Gets the parent PID of a process object. + * + * \return This method returns the parent PID of a process object. + */ + int getPPID(void); + + /*! \brief Process::getName() - Gets the name of a process object. + * + * \return This method returns the name of a process object. + */ + const char* getName(void) const; + + /*! \brief Process::currentProcess() - Retrieves the current process. + * + * \return This method returns a reference to the current process. Otherwise + * the method throws the excepction described below: + * + * \exception [MsgException] if an internal exception occurs. + */ + static Process& currentProcess(void) + throw (MsgException); + + /*! \brief Process::currentProcessPID() - Retrieves the PID of the current process. + * + * \return This method returns the PID of the current process. + */ + static int currentProcessPID(void); + + /*! \brief Process::currentProcessPPID() - Retrieves the parent PID of the current process. + * + * \return This method returns the parent PID of the current process. + */ + static int currentProcessPPID(void); + + /*! \brief Process::migrate() - Migrate a process object to an another host. + * + * \param rHost A reference to the host to migrate the process to. + * + * \return If successful the method migrate the process to the specified + * host. Otherwise the method throws the exception described + * below: + * + * \exception [MsgException] if an internal exception occurs. + */ + void migrate(const Host& rHost) + throw(MsgException); + + /*! \brief Process::sleep() - Makes the current process sleep until time seconds have elapsed. + * + * \param seconds The number of seconds to sleep. + * + * \execption If this method failed, it throws one of the exceptions described + * below: + * + * [InvalidArgumentException] if the parameter seconds is + * less or equals to zero. + * + * [MsgException] if an internal exception occurs. + */ + static void sleep(double seconds) + throw(InvalidArgumentException, MsgException); + + /*! \brief Process::putTask() - This method puts a task on a given channel of a given host. + * + * \exception If this method failed, it throws one of the exceptions described + * below: + * + * [InvalidArgumentException] if the channel number is negative. + * + * [MsgException] if an internal exception occurs. + */ + void putTask(const Host& rHost, int channel, const Task& rTask) + throw(InvalidArgumentException, MsgException); + + /*! \brief Process::putTask() - This method puts a task on a given channel of a given host (waiting at most given time). + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [MsgException] if an internal error occurs. + * + * [InvalidArgumentException] if the value of the channel specified as + * parameter is negative or if the timeout value + * is less than zero and différent of -1. + * + * \remark Set the timeout with -1.0 to disable it. + */ + void putTask(const Host& rHost, int channel, const Task& rTask, double timeout) + throw(InvalidArgumentException, MsgException); + + /*! \brief Process::getTask() - Retrieves a task from a channel number (waiting at most given time). + * + * \param channel The number of the channel where to get the task. + * + * \return If successful the method returns a reference to + * the getted task. Otherwise the method throws one + * of the exceptions described below: + * + * \exception [InvalidArgumentException] if the channel number is negative. + * + * [MsgException] if an internal exception occurs. + */ + Task& getTask(int channel) + throw(InvalidArgumentException, MsgException); + + /*! \brief Process::taskGet() - Retrieves a task from a channel number (waiting at most given time). + * + * \param channel The number of the channel where to get the task. + * \param timeout The timeout value. + * + * \return If successful the method returns a reference to + * the getted task. Otherwise the method throws one + * of the exceptions described below: + * + * \exception [InvalidArgumentException] if the channel number is negative + * or if the timeout value is less than + * zero and different of -1.0. + * [MsgException] if an internal exception occurs. + */ + Task& getTask(int channel, double timeout) + throw(InvalidArgumentException, MsgException); + + /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host. + * + * \param channel The number of the channel where to get the task. + * \param host The host of the channel to get the task. + * + * \return If successful the method returns a reference to + * the getted task. Otherwise the method throws one + * of the exceptions described below. + * + * \exception [InvalidArgumentException] if the channel number is negative. + * [MsgException] if an internal exception occurs. + */ + Task& getTask(int channel, const Host& rHost) + throw(InvalidArgumentException, MsgException); + + /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host (waiting at most given time). + * + * \param channel The number of the channel where to get the task. + * \param timeout The timeout value. + * \param rHost The host owning the channel. + * + * \return If successful the method returns a reference to + * the getted task. Otherwise the method throws one + * of the exceptions described below: + * + * \exception [InvalidArgumentException] if the channel number is negative or + * if the timeout value is negative and different + * of -1.0. + * [MsgException] if an internal exception occurs. + * + * \remark Set the timeout with -1.0 to disable it. + */ + Task& getTask(int channel, double timeout, const Host& rHost) + throw(InvalidArgumentException MsgException); + + /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias + * (waiting at most given time). + * + * \param alias The alias of the mailbox where to send the task. + * \param rTask A reference to the task object to send. + * \param timeout The timeout value. + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [NullPointerException] if the alias specified as parameter is NULL. + * + * [InvalidArgumentException] if the timeout value is negative and different than + * -1.0 + * [MsgException] if an internal exception occurs. + * + * \remark Set the timeout with -1.0 to disable it. + */ + void sendTask(const char* alias, const Task& rTask, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException); + + /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias. + * + * \param alias The alias of the mailbox where to send the task. + * \param rTask A reference to the task object to send. + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [NullPointerException] if the alias parameter is NULL. + * + * [MsgException] if an internal exception occurs. + * + */ + void sendTask(const char* alias, const Task& rTask) + throw(NullPointerException, MsgException); + + /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias. + * + * \param rTask A reference to the task object to send. + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [BadAllocException] if there is not enough memory to build the default alias. + * + * [MsgException] if an internal exception occurs. + * + */ + void sendTask(const Task& rTask) + throw(BadAllocException, MsgException); + + /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias + * (waiting at most given time). + * + * \param rTask A reference to the task object to send. + * \param timeout The timeout value. + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [BadAllocException] if there is not enough memory to build the default alias. + * + * [InvalidArgumentException] if the timeout value is negative and different than -1.0. + * + * [MsgException] if an internal exception occurs. + * + * \remark set the timeout value with -1.0 to disable it. + */ + void sendTask(const Task& rTask, double timeout) + throw(BadAllocException, InvalidArgumentException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as + * parameter. + * + * \param alias The alias of the mailbox where to retrieve the task. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below: + * + * \exception [NullPointerException] if the parameter alias is NULL. + * + * [MsgException] if an internal exception occurs. + */ + Task& receiveTask(const char* alias) + throw(NullPointerException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below: + * + * \exception [BadAllocException] if there is not enough memory to build the alias. + * [MsgException] if an internal exception occurs. + */ + Task& receiveTask(void) + throw(BadAllocException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as + * parameter(waiting at most given time). + * + * \param alias The alias of the mailbox where to retrieve the task. + * \param timeout The timeout value. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below. + * + * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0. + * + * [NullPointerException] if the parameter alias is NULL. + * + * [MsgException] if an internal exception occurs. + */ + Task& receiveTask(const char* alias, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias + * (waiting at most given time). + * + * \param timeout The timeout value. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below: + * + * \exception [InvalidArgumentException] if the timeout value is negative or different than -1.0. + * + * [BadAllocException] if there is not enough memory to build the alias. + * + * [MsgException] if an internal exception occurs. + */ + Task& receiveTask(double timeout) + throw(InvalidArgumentException, BadAllocException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as + * parameter located on a given host (waiting at most given time). + * + * \param alias The alias of the mailbox where to retrieve the task. + * \param timeout The timeout value. + * \param rHost A reference to the host object owning the mailbox. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below: + * + * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0. + * + * [NullPointerException] if the parameter alias is NULL. + * + * [MsgException] if an internal exception occurs. + */ + Task& receiveTask(const char* alias, double timeout, const Host& rHost) + throw(NullPointerException, InvalidArgumentException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias + * and located on a given host (waiting at most given time). + * + * \param timeout The timeout value. + * \param rHost A reference to the host object owning the mailbox. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below: + * + * \exception [InvalidArgumentException] if the timeout value is negative and different than -1.0. + * + * [BadAllocException] if there is not enough memory to build the default alias. + * + * [MsgException] if an internal exception occurs. + */ + Task& Process::receiveTask(double timeout, const Host& rHost) + throw(BadAllocException, InvalidArgumentException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias + * specified as parameter and located on a given host. + * + * \param alias The alias using to identify the mailbox from which to get the task. + * \param rHost A reference to the host object owning the mailbox. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below: + * + * \exception [NullPointerException] if the parameter alias is NULL. + * + * [MsgException] if an internal exception occurs. + */ + Task& receiveTask(const char* alias, const Host& rHost) + throw(NullPointerException, MsgException); + + /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias + * and located on a given host. + * + * \param rHost A reference to the host object owning the mailbox. + * + * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method + * throws one of the exceptions described below: + * + * \exception [BadAllocException] if there is not enough memory to build the alias. + * + * [MsgException] if an internal exception occurs. + */ + Task& receiveTask(const Host& rHost) + throw(BadAllocException, MsgException); + + + private: + + /* Process::create() - Creates a process on a given host. + * + * param rHost A reference to a host object where to create the process. + * param name The name of the process to create. + * param argc The number of argument to pass to the main function of the process. + * param argv The list of the arguments of the main function of the process. + * + * exception If this method failed, it throws one of the exceptions described below: + * + * [HostNotFoundException] if the host specified as parameter doesn't exist. + */ + void create(const Host& rHost, const char* name, int argc, char** argv) + throw(HostNotFoundException); + + /* Process::fromNativeProcess() - Retrieves the process wrapper associated with a native process. + * + * \param nativeProcess The native process to get the wrapper. + * + * \return The wrapper associated with the native process specified as parameter. + */ + static Process& fromNativeProcess(m_process_t nativeProcess); + + + public: + + /* Process::run() - used to set the field code of the context of the process. + */ + static int run(int argc, char** argv); + + /*! \brief Process::main() - This virtual pure function is the main function of the process. + * You must override this function for each new class of process that you create. + * + * \param argc The number of parameters of the main function. + * \param argv The list of the parameter of the main function. + * + * \return The exit code of the main function. + */ + virtual int main(int argc, char** argv) = 0; + + private: + + // Attributes. + + m_process_t nativeProcess; // pointer to the native msg process. + + }; + + } //namepace Msg -} \ No newline at end of file +} namespace SimGrid \ No newline at end of file diff --git a/src/cxx/Simulation.cxx b/src/cxx/Simulation.cxx index 64619327f3..cc13e943b4 100644 --- a/src/cxx/Simulation.cxx +++ b/src/cxx/Simulation.cxx @@ -15,26 +15,85 @@ namespace SimGrid } // initialize the MSG simulator. Must be done before anything else (even logging). - Simulator::init(argc, argv); + init(argc, argv); // the environment to load - Environment environment(argv[1]); + Environment environment; + // the application to deploy - Application application(argv[2]); + Application application; + // the simulation Simulation simulation; - // load the environment - environment.load(); + // try to load the environment described by the xml file (argv[1]) + try + { + environment.load(argv[1]); + } + catch(InvalidArgumentException e) + { + info(e.toString()); + finalize(); + return 1; + } + catch(LogicException e) + { + info(e.toString()); + finalize(); + return 1; + } + + + // try to deploy the application described by the xml file deployment (argv[2]) + try + { + application.deploy(argv[2]); + catch(InvalidArgumentException e) + { + info(e.toString()); + finalize(); + return 1; + } + catch(LogicException e) + { + info(e.toString()); + finalize(); + return 1; + } + + //try to run the simulation the given application on the given environment + try + { + simulation.run(environment, application); + } + catch(MsgException e) + { + info(e.toString()); + finalize(); + return 1; + } - // deploy the application - application.deploy(); + // finalize the MSG simulator - // run the simulation - simulation.run(environment, application); + try + { + finalize(); + } + catch(MsgExceptio e) + { + info(e.toString()) + return 1; + } - // finalize the simulator - Simulator::finalize(); + return 0; + } + + void run(const Environment& rEnvironment, const Application& rApplication) + throw (MsgException) + { + if(MSG_OK != MSG_main()) + throw MsgException("MSG_main() failed"); } } // namespace Msg } // namespace SimGrid diff --git a/src/cxx/Simulation.hpp b/src/cxx/Simulation.hpp index a0a4e6bd08..9ad91633e7 100644 --- a/src/cxx/Simulation.hpp +++ b/src/cxx/Simulation.hpp @@ -23,6 +23,9 @@ namespace SimGrid int execute(int argc, char** argv); + void run(const Environment& rEnvironment, const Application& rApplication) + throw (MsgException); + // Operators. diff --git a/src/cxx/Task.cxx b/src/cxx/Task.cxx index 2ab132fe98..c9ef4f0a34 100644 --- a/src/cxx/Task.cxx +++ b/src/cxx/Task.cxx @@ -1,412 +1,511 @@ #include -namespace msg +namespace SimGrid { - -Task::Task() -{ - nativeTask = NULL; -} - - -Task::Task(const Task& rTask) -{ -} - - -Task::~Task() -throw(NativeException) -{ - if(NULL != nativeTask) + namespace Msg { - if(MSG_OK != MSG_task_destroy(nativeTask)) + + Task::Task() + { + nativeTask = NULL; + } + + + Task::Task(const Task& rTask) + { + } + + + Task::~Task() + throw(NativeException) + { + if(NULL != nativeTask) + if(MSG_OK != MSG_task_destroy(nativeTask)) + throw MsgException("MSG_task_destroy() failed"); + } + + + Task::Task(const char* name, double computeDuration, double messageSize) + throw(InvalidArgumentException, NullPointerException) + { + + if(computeDuration < 0) + throw InvalidArgumentException("computeDuration"); + + if(messageSize < 0) + throw InvalidArgumentException("messageSize"); + + if(!name) + throw NullPointerException("name"); + + // create the task + nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL); + + nativeTask->data = (void*)this; + } + + Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount) + throw(NullPointerException, InvalidArgumentException) + { + + // check the parameters + + if(!name) + throw NullPointerException("name"); + + if(!hosts) + throw NullPointerException("hosts"); + + if(!computeDurations) + throw NullPointerException("computeDurations"); + + if(!messageSizes) + throw NullPointerException("messageSizes"); + + if(!hostCount) + throw InvalidArgumentException("hostCount (must not be zero)"); + + + m_host_t* nativeHosts; + double* durations; + double* sizes; + + + nativeHosts = xbt_new0(m_host_t, hostCount); + durations = xbt_new0(double,hostCount); + sizes = xbt_new0(double, hostCount * hostCount); + + + for(int index = 0; index < hostCount; index++) + { + + nativeHosts[index] = hosts[index].nativeHost; + durations[index] = computeDurations[index]; + } + + for(int index = 0; index < hostCount*hostCount; index++) + sizes[index] = messageSizes[index]; + + + nativeTask = MSG_parallel_task_create(name, hostCount, nativeHosts, durations, sizes,NULL); + + + + task->data = (void*)this; + + } + + const char* Task::getName(void) const + { + return nativeTask->name; + } + + Process& Task::getSender(void) const + { + m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask); + + return (*((Process*)(nativeProcess->data))); + } + + Host& Task::getSource(void) const + { + m_host_t nativeHost = MSG_task_get_source(nativeTask); + + return (*((Host*)(nativeHost->data))); + } + + double Task::getComputeDuration(void) const + { + return MSG_task_get_compute_duration(nativeTask); + } + + double Task::getRemainingDuration(void) const { - // TODO throw NativeException + return MSG_task_get_remaining_computation(nativeTask); + } + + void Task::setPriority(double priority) + throw(InvalidArgumentException) + { + // check the parameters + + if(priority < 0.0) + throw InvalidArgumentException("priority"); + + MSG_task_set_priority(nativeTask, priority); + } + + Task& Task::get(int channel) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) + throw MsgException("MSG_task_get_ext() failed"); + + return (*((Task*)(nativeTask->data))); + } + + Task& Task::get(int channel, const Host& rHost) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + m_task_t nativeTask = NULL; + + + if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost)) + throw MsgException("MSG_task_get_ext() failed"); + + return (*((Task*)(nativeTask->data))); + } + + Task& Task::get(int channel, double timeout, const Host& rHost) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + if(timeout < 0 && timeout !=-1.0) + throw InvalidArgumentException("timeout (must not be negative and different thant -1.0)"); + + m_task_t nativeTask = NULL; + + + if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost)) + throw MsgException("MSG_task_get_ext() failed"); + + return (*((Task*)(nativeTask->data))); + } + + bool static Task::probe(int channel) + throw(InvalidArgumentException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + return (bool)MSG_task_Iprobe(channel); + } + + int Task::probe(int channel, const Host& rHost) + throw(InvalidArgumentException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + return MSG_task_probe_from_host(chan_id,rHost.nativeHost); + } + + void Task::execute(void) + throw(MsgException) + { + if(MSG_OK != MSG_task_execute(nativeTask)) + throw MsgException("MSG_task_execute() failed"); + } + + void Task::cancel(void) + throw(MsgException) + { + if(MSG_OK != MSG_task_cancel(nativeTask)) + throw MsgException("MSG_task_cancel() failed"); + } + + void Task::send(void) + throw(BadAllocException, MsgException) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0); + + free(alias) + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_with_timeout() failed"); + } + + void Task::send(const char* alias) + throw(NullPointerException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0)) + throw MsgException("MSG_task_send_with_timeout() failed"); + } + + void Task::send(double timeout) + throw(BadAllocationException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(timeout < 0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must not be negative and different than -1.0"); + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, timeout); + + free(alias) + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_with_timeout() failed"); } - } -} - - -Task::Task(const char* name, double computeDuration, double messageSize) -{ - - if(computeDuration < 0) - { - // TODO throw exception - return; - } - - if(messageSize < 0) - { - // TODO throw exception - return; - } - - if(!name) - { - // TODO throw exception - return; - } - - // create the task - nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL); - - nativeTask->data = (void*)this; -} - -Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes) -{ - // TODO parallel task create -} - - -const char* Task::getName(void) const -{ - return nativeTask->name; -} - -Process& Task::getSender(void) const -{ - m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask); - - return (*((Process*)(nativeProcess->data))); -} - -Host& Task::getSource(void) const -throw(NativeException) -{ - m_host_t nativeHost = MSG_task_get_source(nativeTask); - - if(!nativeHost->data) - { - // TODO throw the exception - return NULL; - } - - return (*((Host*)(nativeHost->data))); -} - -double Task::getComputeDuration(void) const -{ - return MSG_task_get_compute_duration(nativeTask); -} - -double Task::getRemainingDuration(void) const -{ - return MSG_task_get_remaining_computation(nativeTask); -} - -void Task::setPriority(double priority) -{ - MSG_task_set_priority(nativeTask, priority); -} - -Task& Task::get(int channel) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) - { - // TODO throw the NativeException - return NULL; - } - - return (*((Task*)(nativeTask->data))); -} - -Task& Task::get(int channel, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost)) - { - // TODO throw the NativeException - return NULL; - } - - return (*((Task*)(nativeTask->data))); -} - -Task& Task::get(int channel, double timeout, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost)) - { - // TODO throw the NativeException - return NULL; - } - - return (*((Task*)(nativeTask->data))); -} - -bool static Task::probe(int channel) -{ - return (bool)MSG_task_Iprobe(channel); -} - -int Task::probe(int channel, const Host& rHost) -{ - return MSG_task_probe_from_host(chan_id,rHost.nativeHost); -} - -void Task::execute(void) -throw(NativeException) -{ - if(MSG_OK != MSG_task_execute(nativeTask)) - { - // TODO throw NativeException - } -} - -void Task::cancel(void) -throw(NativeException) -{ - if(MSG_OK != MSG_task_cancel(nativeTask)) - { - // TODO throw NativeException - } -} - -void Task::send(void) -throw(NativeException) -{ - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); - sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + void Task::send(const char* alias, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(timeout < 0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must not be negative and different than -1.0"); + + + if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout)) + throw MsgException("MSG_task_send_with_timeout() failed"); + } - - rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0); - - free(alias) - - if(MSG_OK != rv) - { - // TODO throw the NativeException - } -} - - -void Task::send(const char* alias) -throw(NativeException) -{ - - if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0)) - { - // TODO throw the NativeException - } -} - -void Task::send(double timeout) -throw(NativeException) -{ - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); - sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + void Task::sendBounded(double maxRate) + throw(BadAllocException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(maxRate < 0 && maxRate != -1.0) + throw InvalidArgumentException("maxRate (must not be negative and different than -1.0"); + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + MSG_error_t rv = MSG_task_send_bounded(nativeTask, alias, maxRate); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_bounded() failed"); + + } + void Task::sendBounded(const char* alias, double maxRate) + throw(NullPointerException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(maxRate < 0 && maxRate != -1.0) + throw InvalidArgumentException("maxRate (must not be negative and different than -1.0"); + + if(!alias) + throw NullPointerException("alias"); + + if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate)) + throw MsgException("MSG_task_send_bounded() failed"); + } - - rv = MSG_task_send_with_timeout(nativeTask, alias, timeout); - - free(alias) - - if(MSG_OK != rv) - { - // TODO throw the NativeException - } -} - -void Task::send(const char* alias, double timeout) -throw(NativeException) -{ - if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout)) - { - // TODO throw the NativeException - } -} - -void Task::sendBounded(double maxRate) -throw(NativeException) -{ - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); - sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); - - rv = MSG_task_send_bounded(nativeTask, alias, maxRate); - - free(alias); - - - - if(MSG_OK != rv) - { - // TODO throw the NativeException - } -} - -void Task::sendBounded(const char* alias, double maxRate) -throw(NativeException) -{ - if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate)) - { - // TODO throw the NativeException - } -} - -Task& Task::receive(void) -throw(NativeException) -{ - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); - sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + Task& Task::receive(void) + throw(throw(BadAllocException, MsgException)) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + m_task_t nativeTask = NULL; + + MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); - m_task_t nativeTask = NULL; - - rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); - - free(alias); - - if(MSG_OK != rv) - { - // TODO thow NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - -Task& Task::receive(const char* alias) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) - { - // TODO thow NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - -Task& Task::receive(const char* alias, double timeout) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) - { - // TODO thow NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - -Task& Task::receive(const char* alias, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) - { - // TODO thow NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - -Task& Task::receive(const char* alias, double timeout, const Host& rHost) -throw(NativeException) -{ - m_task_t nativeTask = NULL; - - - if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) - { - // TODO thow NativeException - return NULL; - } - - return (*((Task*)nativeTask->data)); -} - -bool Task::listen(void) -throw(NativeException) -{ - int rv; - - char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); - sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_receive_ext() failed"); - rv = MSG_task_listen(alias); - - free(alias); - - return (bool)rv; -} - -bool Task::listen(const char* alias) -throw(NativeException) -{ - return (bool)MSG_task_listen(alias); -} - -bool Task::listenFrom(void) -throw(NativeException) -{ - int rv; - - char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); - sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); - - rv = MSG_task_listen_from(alias); - - free(alias); - - return (int)rv; -} - -bool Task::listenFrom(const char* alias) -throw(NativeException) -{ - return (bool)MSG_task_listen_from(alias); - -} - -bool Task::listenFromHost(const Host& rHost) -throw(NativeException) -{ - int rv; - - char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); - sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); - - rv = MSG_task_listen_from_host(alias, rHost.nativeHost); - - free(alias); - - return (bool)rv; -} - -bool Task::listenFromHost(const char* alias, const Host& rHost) -throw(NativeException) -{ - return (bool)MSG_task_listen_from_host(alias, rHost.nativeHost); -} - -} + return (*((Task*)nativeTask->data)); + } + + Task& Task::receive(const char* alias) + throw(NullPointerException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + Task& Task::receive(const char* alias, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(timeout < 0 && alias != -1.0) + throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)"); + + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + Task& Task::receive(const char* alias, const Host& rHost) + throw(NullPointerException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + Task& Task::receive(const char* alias, double timeout, const Host& rHost) + throw(NullPointerException, InvalidArgumentException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(timeout < 0 && alias != -1.0) + throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)"); + + m_task_t nativeTask = NULL; + + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) + throw MsgException("MSG_task_receive_ext() failed"); + + return (*((Task*)nativeTask->data)); + } + + bool Task::listen(void) + throw(BadAllocException) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + int rv = MSG_task_listen(alias); + + free(alias); + + return (bool)rv; + } + + bool Task::listen(const char* alias) + throw(NullPointerException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + return (bool)MSG_task_listen(alias); + } + + int Task::listenFrom(void) + throw(BadAllocException) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + int rv = MSG_task_listen_from(alias); + + free(alias); + + return rv; + } + + int Task::listenFrom(const char* alias) + throw(NullPointerException) + { + if(!alias) + throw NullPointerException("alias"); + + return MSG_task_listen_from(alias); + + } + + int Task::listenFromHost(const Host& rHost) + throw(BadAllocException) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + int rv = MSG_task_listen_from_host(alias, rHost.nativeHost); + + free(alias); + + return rv; + } + + int Task::listenFromHost(const char* alias, const Host& rHost) + throw(NullPointerException) + { + // check the parameters + if(!alias) + throw NullPointerException("alias"); + + return MSG_task_listen_from_host(alias, rHost.nativeHost); + } + } // namespace Msg +} // namespace SimGrid diff --git a/src/cxx/Task.hpp b/src/cxx/Task.hpp index 173f4a73c0..143f66834e 100644 --- a/src/cxx/Task.hpp +++ b/src/cxx/Task.hpp @@ -1,3 +1,17 @@ +/* + * Task.hpp + * + * This file contains the declaration of the wrapper class of the native MSG task type. + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + #ifndef MSG_TASK_HPP #define MSG_TASK_HPP @@ -6,124 +20,493 @@ #error Process.hpp requires C++ compilation (use a .cxx suffix) #endif -namespace msg +namespace SimGrid { -class Task -{ - protected: - // Default constructor. - Task(); - - public: - // Copy constructor. - Task(const Task& rTask); - - // Destructor. - virtual ~Task() - throw(NativeException); - - // Other constructors. - Task(const char* name, double computeDuration, double messageSize); - - Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes); - - - // Getters/setters. - const char* getName(void) const; - - - Process& getSender(void) const; - - Host& getSource(void) const - throw(NativeException); - - double getComputeDuration(void) const; - - double getRemainingDuration(void) const; - - void setPriority(double priority); - - static Task& get(int channel) - throw(NativeException); - - static Task& get(int channel, const Host& rHost) - throw(NativeException); - - static Task& get(int channel, double timeout, const Host& rHost) - throw(NativeException); - - static bool probe(int channel); - - static int probe(int channel, const Host& rHost); - - void execute(void) - throw(NativeException); - - void cancel(void) - throw(NativeException); - - - void send(void) - throw(NativeException); - - void send(const char* alias) - throw(NativeException); - - void send(double timeout) - throw(NativeException); - - void send(const char* alias, double timeout) - throw(NativeException); - - void sendBounded(double maxRate) - throw(NativeException); - - void sendBounded(const char* alias, double maxRate) - throw(NativeException); - - static Task& receive(void) - throw(NativeException); - - static Task& receive(const char* alias) - throw(NativeException); - - static Task& receive(const char* alias, double timeout) - throw(NativeException); - - static Task& receive(const char* alias, const Host& rHost) - throw(NativeException); - - static Task& receive(const char* alias, double timeout, const Host& rHost) - throw(NativeException); - - static bool listen(void) - throw(NativeException); - - static bool listen(const char* alias) - throw(NativeException); - - static bool listenFrom(void) - throw(NativeException); - - static bool listenFrom(const char* alias) - throw(NativeException); - - - static bool listenFromHost(const Host& rHost) - throw(NativeException); - - static bool listenFromHost(const char* alias, const Host& rHost) - throw(NativeException); - - - - private: - - m_task_t nativeTask; - - -}; - -} + namespace Msg + { + // SimGrid::Msg::Task wrapper class declaration. + class Task + { + protected: + // Default constructor. + Task(); + + public: + /*! \brief Copy constructor. + */ + Task(const Task& rTask); + + /*! \brief Destructor. + * + * \exception If the destructor failed, it throw the exception described below: + * + * [MsgException] if a native exception occurs. + */ + virtual ~Task() + throw(MsgException); + + /*! \brief Constructs an new task with the specified processing amount and amount + * of data needed. + * + * \param name Task's name + * \param computeDuration A value of the processing amount (in flop) needed to process the task. + * If 0, then it cannot be executed with the execute() method. + * This value has to be >= 0. + * \param messageSize A value of amount of data (in bytes) needed to transfert this task. + * If 0, then it cannot be transfered with the get() and put() methods. + * This value has to be >= 0. + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [InvalidArgumentException] if the parameter computeDuration or messageSize + * is negative. + * [NullPointerException] if the parameter name is NULL. + * + * [MsgException] if a internal exception occurs. + */ + Task(const char* name, double computeDuration, double messageSize) + throw (InvalidArgumentException, NullPointerException); + + /*! \Constructs an new parallel task with the specified processing amount and amount for each host + * implied. + * + * \param name The name of the parallel task. + * \param hosts The list of hosts implied by the parallel task. + * \param computeDurations The amount of operations to be performed by each host of \a hosts. + * \param messageSizes A matrix describing the amount of data to exchange between hosts. + * \hostCount The number of hosts implied in the parallel task. + * + * \exception If this method fails, it throws one of the exceptions described below: + * + * [NullPointerException] if the parameter name is NULL or + * if the parameter computeDurations is NULL or + * if the parameter messageSizes is NULL + * + * [InvalidArgumentException] if the parameter hostCount is negative or zero. + */ + Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount) + throw(NullPointerException, InvalidArgumentException); + + + /*! \brief Task::getName() - Gets the names of the task. + * + * \return The name of the task. + */ + const char* getName(void) const; + + /*! \brief Task::getSender() - Gets the sender of the task. + * + * \return A reference to the sender of the task. + */ + Process& getSender(void) const; + + /*! \brief Task::getSource() - Gets the source of the task. + * + * \return A reference to the source of the task. + */ + Host& getSource(void) const; + + /*! \brief Task::getComputeDuration() - Get the computing amount of the task. + * + * \return The computing amount of the task. + */ + + double getComputeDuration(void) const; + + /*! \brief Task::getRemainingDuration() - Gets the remaining computation. + * + * \return The remining computation of the task. + */ + double getRemainingDuration(void) const; + + /*! \brief Task::setPrirority() - Sets the priority of the computation of the task. + * The priority doesn't affect the transfert rate. For example a + * priority of 2 will make the task receive two times more cpu than + * the other ones. + * + * \param priority The new priority of the task. + * + * execption If this method fails, it throws the exception described below: + * + * [InvalidArgumentException] if the parameter priority is negative. + */ + void setPriority(double priority) + throw(InvalidArgumentException); + + /*! \brief Task::get() - Gets a task from the specified channel of the host of the current process. + * + * \param channel The channel number to get the task. + * + * \return If successful the method returns the task. Otherwise the method throws one + * of the exceptions described below: + * + * \exception [InvalidArgumentException] if the channel parameter is negative. + * + * [MsgException] if an internal excpetion occurs. + */ + static Task& get(int channel) + throw(InvalidArgumentException, MsgException); + + /*! \brief Task::get() - Gets a task from the given channel number of the given host. + * + * \param channel The channel number. + * \param rHost A reference of the host owning the channel. + * + * \return If successful, the method returns the task. Otherwise the method + * throw one of the exceptions described below: + * + * \exception [InvalidArgumentException] if the channel number is negative. + * + * [MsgException] if an internal exception occurs. + */ + static Task& get(int channel, const Host& rHost) + throw(InvalidArgumentException, MsgException); + + /*! \brief Task::get() - Gets a task from the specified channel of the specified host + * (waiting at most given time). + * + * \param channel The channel number. + * \param timeout The timeout value. + * \param rHost A reference to the host owning the channel. + * + * \return If successful, the method returns the task. Otherwise the method returns + * one of the exceptions described below: + * + * \exception [InvalidArgumentException] if the channel number is negative or + * if the timeout value is negative and + * different than -1.0. + * [MsgException] if an internal exception occurs. + */ + static Task& get(int channel, double timeout, const Host& rHost) + throw(InvalidArgumentException, MsgException); + + /*! \brief Task::probe() - Probes whether there is a waiting task on the given channel of local host. + * + * \param channel The channel number. + * + * \return If there is a waiting task on the channel the method returns true. Otherwise + * the method returns false. + * + * \exception If this method fails, it throws the exception described below: + * + * [InvalidArgumentException] if the parameter channel is negative. + */ + static bool probe(int channel) + throw(InvalidArgumentException); + + /*! \brief Task::probe() - Counts tasks waiting on the given channel of local host and sent by given host. + * + * \param channel The channel id. + * \param rHost A reference to the host that has sent the task. + * + * \return The number of tasks. + * + * \exception [InvalidArgumentException] if the parameter channel is negative. + */ + static int probe(int channel, const Host& rHost) + throw(InvalidArgumentException); + + /*! \brief Task::execute() - This method executes a task on the location on which the + * process is running. + * + * \exception If this method fails, it returns the exception described below: + * + * [MsgException] if an internal exception occurs. + */ + void execute(void) + throw(MsgException); + + /*! \brief Task::cancel() - This method cancels a task. + * + * \exception If this method fails, it returns the exception described below: + * + * [MsgException] if an internal exception occurs. + */ + void cancel(void) + throw(MsgException); + + /*! \brief Task::send() - Send the task on the mailbox identified by the default alias. + * + * \exception If this method failed, it returns one of the exceptions described + * below: + * + * [BadAllocException] if there is not enough memory to build the default alias. + * + * [MsgException] if an internal exception occurs. + */ + void send(void) + throw(BadAllocException, MsgException); + + /*! \brief Task::send() - Send the task on the mailbox identified by the given alias. + * + * \param alias The alias of the mailbox where to send the task. + * + * \exception If this method failed, it returns one of the exceptions described + * below: + * + * [NullPointerException] if there parameter alias is NULL. + * + * [MsgException] if an internal exception occurs. + */ + void send(const char* alias) + throw(NullPointerException, MsgException); + + /*! \brief Task::send() - Send the task on the mailbox identified by the default alias + * (waiting at most given time). + * + * \param timeout The timeout value. + * + * \exception If this method failed, it returns one of the exceptions described + * below: + * + * [BadAllocException] if there is not enough memory to build the default alias. + * + * [InvalidArgumentException] if the timeout value is negative or different -1.0. + * + * [MsgException] if an internal exception occurs. + */ + void send(double timeout) + throw(BadAllocationException, InvalidArgumentException, MsgException); + + /*! \brief Task::send() - Send the task on the mailbox identified by a given alias + * (waiting at most given time). + * + * \param alias The alias of the mailbox where to send the task. + * \param timeout The timeout value. + * + * \exception If this method failed, it returns one of the exceptions described + * below: + * + * [NullPointerException] if alias parameter is NULL. + * + * [InvalidArgumentException] if the timeout value is negative or different -1.0. + * + * [MsgException] if an internal exception occurs. + */ + void send(const char* alias, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException); + + /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the default alias. + * (capping the emision rate to maxrate). + * + * \param maxRate The maximum rate value. + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [BadAllocException] if there is not enough memory to build the default alias. + * + * [InvalidArgumentException] if the parameter maxRate is negative and different + * than -1.0. + * + * [MsgException] if an internal exception occurs. + */ + void sendBounded(double maxRate) + throw(BadAllocException, InvalidArgumentException, MsgException); + + /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the given alias. + * (capping the emision rate to maxrate). + * + *\ param alias The alias of the mailbox where to send the task. + * \param maxRate The maximum rate value. + * + * \exception If this method failed, it throws one of the exceptions described below: + * + * [NullPointerException] if the alias parameter is NULL. + * + * [InvalidArgumentException] if the parameter maxRate is negative and different + * than -1.0. + * + * [MsgException] if an internal exception occurs. + */ + void sendBounded(const char* alias, double maxRate) + throw(NullPointerException, InvalidArgumentException, MsgException); + + + /*! \brief Task::receive() - Receives a task from the mailbox identified by the default alias (located + * on the local host). + * + * \return A reference to the task. + * + * \exception If this method failed, it throws one of the exception described below: + * + * [BadAllocException] if there is not enough memory to build the default alias. + * + * [MsgException] if an internal exception occurs. + */ + static Task& receive(void) + throw(BadAllocException, MsgException); + + /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located + * on the local host). + * + * \alias The alias of the mailbox. + * + * \return A reference to the task. + * + * \exception If this method failed, it throws one of the exception described below: + * + * [NullPointerException] if the alias parameter is NULL. + * + * [MsgException] if an internal exception occurs. + */ + static Task& receive(const char* alias) + throw(NullPointerException, MsgException); + + /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located + * on the local host and waiting at most given time). + * + * \alias The alias of the mailbox. + * \timeout The timeout value. + * + * \return A reference to the task. + * + * \exception If this method failed, it throws one of the exception described below: + * + * [NullPointerException] if the alias parameter is NULL. + * + * [InvalidArgumentException] if the timeout value is negatif and different than + * -1.0. + * + * [MsgException] if an internal exception occurs. + */ + static Task& receive(const char* alias, double timeout) + throw(NullPointerException, InvalidArgumentException, MsgException); + + /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located + * on the given host. + * + * \alias The alias of the mailbox. + * \rHost The location of the mailbox. + * + * \return A reference to the task. + * + * \exception If this method failed, it throws one of the exception described below: + * + * [NullPointerException] if the alias parameter is NULL. + * + * [MsgException] if an internal exception occurs. + */ + static Task& receive(const char* alias, const Host& rHost) + throw(NullPointerException, MsgException); + + /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located + * on the given host (and waiting at most given time). + * + * \alias The alias of the mailbox. + * \timeout The timeout value. + * \rHost The location of the mailbox. + * + * \return A reference to the task. + * + * \exception If this method failed, it throws one of the exception described below: + * + * [NullPointerException] if the alias parameter is NULL. + * + * [InvalidArgumentException] if the timeout value is negatif and different than + * -1.0. + * + * [MsgException] if an internal exception occurs. + */ + static Task& receive(const char* alias, double timeout, const Host& rHost) + throw(NullPointerException, InvalidArgumentException, MsgException); + + /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox + * identified by the default alias of local host. + * + * \return If there is a waiting task on the mailbox the method returns true. + * Otherwise the method returns false. + * + * \exception If this method fails, it throws one of the exceptions described below: + * + * [BadAllocException] if there is not enough memory to build the default alias. + */ + static bool listen(void) + throw(BadAllocException); + + /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox + * identified by the given alias of local host. + * + * \param alias The alias of the mailbox. + * + * \return If there is a waiting task on the mailbox the method returns true. + * Otherwise the method returns false. + * + * \exception If this method fails, it throws one of the exceptions described below: + * + * [NullPointerException] if the parameter alias is NULL. + */ + static bool listen(const char* alias) + throw(NullPointerException); + + /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox + * identified by the default alias, and who sent it. + * + * \return If there is a pending communication on the mailbox, the method returns + * the PID of it sender. Otherwise the method returns -1. + * + * \exception If this method fails, it throws the exception described below: + * + * [BadAllocException] if there is not enough memory to build the default + * alias. + */ + static int listenFrom(void) + throw(BadAllocException); + + /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox + * identified by the specified alias, and who sent it. + * + * \alias The alias of the mailbox. + * + * \return If there is a pending communication on the mailbox, the method returns + * the PID of it sender. Otherwise the method returns -1. + * + * \exception If this method fails, it throws the exception described below: + * + * [NullPointerException] if the alias parameter is NULL. + */ + static int listenFrom(const char* alias) + throw(NullPointerException); + + /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox + * identified by the default alias and located on the host of the current process, and who sent it. + * + * \param rHost The location of the mailbox. + * + * \return If there is a pending communication on the mailbox, the method returns + * the PID of it sender. Otherwise the method returns -1. + * + * \exception If this method fails, it throws the exception described below: + * + * [BadAllocException] if there is not enough memory to build the default + * alias. + */ + static int listenFromHost(const Host& rHost) + throw(BadAllocException); + + /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox + * identified by the default alias and located on the host of the current process, and who sent it. + * + * \param rHost The location of the mailbox. + * + * \return If there is a pending communication on the mailbox, the method returns + * the PID of it sender. Otherwise the method returns -1. + * + * \exception If this method fails, it throws the exception described below: + * + * [BadAllocException] if there is not enough memory to build the default + * alias. + */ + static bool listenFromHost(const char* alias, const Host& rHost) + throw(NullPointerException, NativeException); + + private: + + // Attributes. + + m_task_t nativeTask; // the native MSG task. + }; + + } // namespace Msg +} // namespace SimGrid #endif // §MSG_TASK_HPP \ No newline at end of file