From: cherierm Date: Tue, 19 Aug 2008 15:48:47 +0000 (+0000) Subject: last change of cpp wrappers for msg X-Git-Tag: v3.3~213 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b9c27830674f1ed54f9553d4cd517842acc1aab1?ds=sidebyside last change of cpp wrappers for msg git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5894 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/cxx/Application.cxx b/src/cxx/Application.cxx index c188ffb854..ca37d24641 100644 --- a/src/cxx/Application.cxx +++ b/src/cxx/Application.cxx @@ -1,199 +1,199 @@ -/* - * Application.cxx - * - * 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. - * - */ - - /* Application member functions implementation. - */ - -#include - -#include - -#include -#include -#include - -#include - -#ifndef S_ISREG - #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) -#endif - -namespace SimGrid -{ - namespace Msg - { - - Application::Application() - { - this->file = NULL; - this->deployed = false; - } - - Application::Application(const Application& rApplication) - { - - this->file = rApplication.getFile(); - this->deployed = rApplication.isDeployed(); - } - - Application::Application(const char* file) - throw(NullPointerException, FileNotFoundException) - { - // check parameters - - if(!file) - throw NullPointerException("file"); - - struct stat statBuf = {0}; - - if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) - throw FileNotFoundException(file); - - this->file = file; - this->deployed = false; - } - - Application::~Application() - { - // NOTHING TODO - } - - void Application::deploy(const char* file) - throw(NullPointerException, FileNotFoundException, LogicException, MsgException) - { - // check logic - - if(this->deployed) - throw LogicException("application already deployed"); - - // check the parameters - - if(!file) - throw NullPointerException("file"); - - struct stat statBuf = {0}; - - if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) - throw FileNotFoundException(file); - - surf_parse_reset_parser(); - - // set the begin of the xml process element handler - surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess); - - // set the process arg handler - surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg); - - // set the properties handler - surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty); - - // set the end of the xml process element handler - surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess); - - surf_parse_open(file); - - // initialize the process factory used by the process handler to build the processes. - ApplicationHandler::onStartDocument(); - - if(surf_parse()) - throw MsgException("surf_parse() failed"); - - surf_parse_close(); - - // release the process factory - ApplicationHandler::onEndDocument(); - - this->file = file; - this->deployed = true; - } - - void Application::deploy(void) - throw(LogicException, MsgException) - { - // check logic - - if(this->deployed) - throw LogicException("application already deployed"); - - // check the parameters - if(!this->file) - throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()"); - - surf_parse_reset_parser(); - surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess); - surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg); - surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty); - surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess); - - // initialize the process factory used by the process handler to build the processes. - ApplicationHandler::onStartDocument(); - - surf_parse_open(file); - - if(surf_parse()) - throw MsgException("surf_parse() failed"); - - surf_parse_close(); - - this->deployed = true; - } - - bool Application::isDeployed(void) const - { - return this->deployed; - } - - void Application::setFile(const char* file) - throw (NullPointerException, FileNotFoundException, LogicException) - { - // check logic - - if(this->deployed) - throw LogicException("your are trying to change the file of an already deployed application"); - - // check parameters - - if(!file) - throw NullPointerException("file"); - - struct stat statBuf = {0}; - - if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) - throw FileNotFoundException("file (file not found)"); - - this->file = file; - - } - - const char* Application::getFile(void) const - { - return this->file; - } - - const Application& Application::operator = (const Application& rApplication) - throw(LogicException) - { - // check logic - - if(this->deployed) - throw LogicException("application already deployed"); - - this->file = rApplication.getFile(); - this->deployed = rApplication.isDeployed(); - - return *this; - } - } // namespace Msg -} // namespace SimGrid - - - +/* + * Application.cxx + * + * 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. + * + */ + + /* Application member functions implementation. + */ + +#include + +#include + +#include +#include +#include + +#include + +#ifndef S_ISREG + #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) +#endif + +namespace SimGrid +{ + namespace Msg + { + + Application::Application() + { + this->file = NULL; + this->deployed = false; + } + + Application::Application(const Application& rApplication) + { + + this->file = rApplication.getFile(); + this->deployed = rApplication.isDeployed(); + } + + Application::Application(const char* file) + throw(NullPointerException, FileNotFoundException) + { + // check parameters + + if(!file) + throw NullPointerException("file"); + + struct stat statBuf = {0}; + + if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) + throw FileNotFoundException(file); + + this->file = file; + this->deployed = false; + } + + Application::~Application() + { + // NOTHING TODO + } + + void Application::deploy(const char* file) + throw(NullPointerException, FileNotFoundException, LogicException, MsgException) + { + // check logic + + if(this->deployed) + throw LogicException("application already deployed"); + + // check the parameters + + if(!file) + throw NullPointerException("file"); + + struct stat statBuf = {0}; + + if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) + throw FileNotFoundException(file); + + surf_parse_reset_parser(); + + // set the begin of the xml process element handler + surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess); + + // set the process arg handler + surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg); + + // set the properties handler + surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty); + + // set the end of the xml process element handler + surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess); + + surf_parse_open(file); + + // initialize the process factory used by the process handler to build the processes. + ApplicationHandler::onStartDocument(); + + if(surf_parse()) + throw MsgException("surf_parse() failed"); + + surf_parse_close(); + + // release the process factory + ApplicationHandler::onEndDocument(); + + this->file = file; + this->deployed = true; + } + + void Application::deploy(void) + throw(LogicException, MsgException) + { + // check logic + + if(this->deployed) + throw LogicException("application already deployed"); + + // check the parameters + if(!this->file) + throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()"); + + surf_parse_reset_parser(); + surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess); + surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg); + surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty); + surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess); + + // initialize the process factory used by the process handler to build the processes. + ApplicationHandler::onStartDocument(); + + surf_parse_open(file); + + if(surf_parse()) + throw MsgException("surf_parse() failed"); + + surf_parse_close(); + + this->deployed = true; + } + + bool Application::isDeployed(void) const + { + return this->deployed; + } + + void Application::setFile(const char* file) + throw (NullPointerException, FileNotFoundException, LogicException) + { + // check logic + + if(this->deployed) + throw LogicException("your are trying to change the file of an already deployed application"); + + // check parameters + + if(!file) + throw NullPointerException("file"); + + struct stat statBuf = {0}; + + if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) + throw FileNotFoundException("file (file not found)"); + + this->file = file; + + } + + const char* Application::getFile(void) const + { + return this->file; + } + + const Application& Application::operator = (const Application& rApplication) + throw(LogicException) + { + // check logic + + if(this->deployed) + throw LogicException("application already deployed"); + + this->file = rApplication.getFile(); + this->deployed = rApplication.isDeployed(); + + return *this; + } + } // namespace Msg +} // namespace SimGrid + + + diff --git a/src/cxx/Application.hpp b/src/cxx/Application.hpp index c2818701f7..925c1efe07 100644 --- a/src/cxx/Application.hpp +++ b/src/cxx/Application.hpp @@ -1,151 +1,151 @@ -/* - * Application.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_APPLICATION_HPP -#define MSG_APPLICATION_HPP - -#ifndef __cplusplus - #error Application.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - // Application wrapper class declaration. - class SIMGRIDX_EXPORT Application - { - public: - - /*! \brief Default constructor. - */ - Application(); - - /*! \brief Copy constructor. - */ - Application(const Application& rApplication); - - /* \brief A constructor which takes as parameter the xml file of the application. - * - * \exception If this constructor fails, it throws on of the exceptions described - * below: - * - * [NullPointerException] if the parameter file is NULL. - * - * [FileNotFoundException] if the file is not found. - */ - Application(const char* file) - throw(NullPointerException, FileNotFoundException); - - /*! \brief Destructor. - */ - virtual ~Application(); - - // Operations. - - /*! \brief Application::deploy() - deploy the appliction. - * - * \exception If this method fails, it throws an exception listed below: - * - * \exception [LogicException] if the xml file which describes the application - * is not yet specified or if the application is already - * deployed. - * [MsgException] if a internal exception occurs. - * - * \remark Before use this method, you must specify the xml file of the application to - * deploy. - * - * \see Application::setFile() - */ - - void deploy(void) - throw(LogicException, MsgException); - - /*! \brief Application::deploy() - Deploy the appliction. - * - * \return If successfuly the application is deployed. Otherwise - * the method throws an exception listed below. - * - * \exception [NullPointerException] if the parameter file is NULL. - * - * [FileNotFoundException] if the file is not found. - * - * [MsgException] if a internal exception occurs. - * - * [LogicException] if the application is already deployed. - * - * \ - */ - void deploy(const char* file) - throw(NullPointerException, FileNotFoundException, LogicException, MsgException); - - /*! \brief Application::isDeployed() - Tests if the application is deployed. - * - * \return This method returns true is the application is deployed. - * Otherwise the method returns false. - */ - bool isDeployed(void) const; - - - // Getters/setters - - /*! \brief Application::setFile() - this setter sets the value of the file of the application. - * - * \exception If this method fails, it throws on of the exceptions listed below: - * - * [NullPointerException] if the parameter file is NULL. - * - * [FileNotFoundException] if the file is not found. - - * [LogicException] if you try to set the value of the file of an - * application which is already deployed. - */ - void setFile(const char* file) - throw (NullPointerException, FileNotFoundException, LogicException); - - /*! \brief Application::getFile() - This getter returns the name of the xml file which describes the - * application of the simulation. - */ - const char* getFile(void) const; - - // Operators. - - /*! \brief Assignement operator. - * - * \exception [LogicException] if you try to assign an application already deployed. - */ - const Application& operator = (const Application& rApplication) - throw(LogicException); - - private: - // Attributes. - - // flag : if true the application was deployed. - bool deployed; - - // the xml file which describes the application of the simulation. - const char* file; - - }; - - } // namespace Msg -} // namespace SimGrid - -#endif // !MSG_APPLICATION_HPP - +/* + * Application.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_APPLICATION_HPP +#define MSG_APPLICATION_HPP + +#ifndef __cplusplus + #error Application.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + // Application wrapper class declaration. + class SIMGRIDX_EXPORT Application + { + public: + + /*! \brief Default constructor. + */ + Application(); + + /*! \brief Copy constructor. + */ + Application(const Application& rApplication); + + /* \brief A constructor which takes as parameter the xml file of the application. + * + * \exception If this constructor fails, it throws on of the exceptions described + * below: + * + * [NullPointerException] if the parameter file is NULL. + * + * [FileNotFoundException] if the file is not found. + */ + Application(const char* file) + throw(NullPointerException, FileNotFoundException); + + /*! \brief Destructor. + */ + virtual ~Application(); + + // Operations. + + /*! \brief Application::deploy() - deploy the appliction. + * + * \exception If this method fails, it throws an exception listed below: + * + * \exception [LogicException] if the xml file which describes the application + * is not yet specified or if the application is already + * deployed. + * [MsgException] if a internal exception occurs. + * + * \remark Before use this method, you must specify the xml file of the application to + * deploy. + * + * \see Application::setFile() + */ + + void deploy(void) + throw(LogicException, MsgException); + + /*! \brief Application::deploy() - Deploy the appliction. + * + * \return If successfuly the application is deployed. Otherwise + * the method throws an exception listed below. + * + * \exception [NullPointerException] if the parameter file is NULL. + * + * [FileNotFoundException] if the file is not found. + * + * [MsgException] if a internal exception occurs. + * + * [LogicException] if the application is already deployed. + * + * \ + */ + void deploy(const char* file) + throw(NullPointerException, FileNotFoundException, LogicException, MsgException); + + /*! \brief Application::isDeployed() - Tests if the application is deployed. + * + * \return This method returns true is the application is deployed. + * Otherwise the method returns false. + */ + bool isDeployed(void) const; + + + // Getters/setters + + /*! \brief Application::setFile() - this setter sets the value of the file of the application. + * + * \exception If this method fails, it throws on of the exceptions listed below: + * + * [NullPointerException] if the parameter file is NULL. + * + * [FileNotFoundException] if the file is not found. + + * [LogicException] if you try to set the value of the file of an + * application which is already deployed. + */ + void setFile(const char* file) + throw (NullPointerException, FileNotFoundException, LogicException); + + /*! \brief Application::getFile() - This getter returns the name of the xml file which describes the + * application of the simulation. + */ + const char* getFile(void) const; + + // Operators. + + /*! \brief Assignement operator. + * + * \exception [LogicException] if you try to assign an application already deployed. + */ + const Application& operator = (const Application& rApplication) + throw(LogicException); + + private: + // Attributes. + + // flag : if true the application was deployed. + bool deployed; + + // the xml file which describes the application of the simulation. + const char* file; + + }; + + } // namespace Msg +} // namespace SimGrid + +#endif // !MSG_APPLICATION_HPP + diff --git a/src/cxx/ApplicationHandler.cxx b/src/cxx/ApplicationHandler.cxx index 3b48213267..2673dbbc29 100644 --- a/src/cxx/ApplicationHandler.cxx +++ b/src/cxx/ApplicationHandler.cxx @@ -1,190 +1,190 @@ -/* - * ApplicationHandler.cxx - * - * 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. - * - */ - - /* ApplicationHandler member functions implementation. - */ - - -#include -#include - -#include -#include - - - - - -#include - -#include -#include - - -namespace SimGrid -{ - namespace Msg - { - - ApplicationHandler::ProcessFactory* ApplicationHandler::processFactory = NULL; - - // Desable the default constructor, the copy constructor , the assignement operator - // and the destructor of this class. Assume that this class is static. - - // Default constructor. - ApplicationHandler::ApplicationHandler() - { - // NOTHING TODO - } - - // Copy constructor. - ApplicationHandler::ApplicationHandler(const ApplicationHandler& rApplicationHandler) - { - // NOTHING TODO - } - - // Destructor - ApplicationHandler::~ApplicationHandler() - { - // NOTHING TODO - } - - // Assignement operator. - const ApplicationHandler& ApplicationHandler::operator = (const ApplicationHandler& rApplicationHandler) - { - return *this; - } - - void ApplicationHandler::onStartDocument(void) - { - // instanciate the factory at the begining of the parsing - processFactory = new ProcessFactory(); - } - - void ApplicationHandler::onEndDocument(void) - { - // release the handler at the end of the parsing. - if(processFactory) - delete processFactory; - } - - void ApplicationHandler::onBeginProcess(void) - { - // set the process identity at the begin of the xml process element. - processFactory->setProcessIdentity(A_surfxml_process_host, A_surfxml_process_function); - } - - void ApplicationHandler::onProcessArg(void) - { - // register the argument of the current xml process element. - processFactory->registerProcessArg(A_surfxml_argument_value); - } - - void ApplicationHandler::OnProperty(void) - { - // set the property of the current xml process element. - processFactory->setProperty(A_surfxml_prop_id, A_surfxml_prop_value); - } - - void ApplicationHandler::onEndProcess(void) - { - // at the end of the xml process element create the wrapper process (of the native Msg process) - processFactory->createProcess(); - } - - ///////////////////////////////////////////////////////////////////////////////////////////////// - // Process factory connected member functions - - ApplicationHandler::ProcessFactory::ProcessFactory() - { - this->args = xbt_dynar_new(sizeof(char*),ApplicationHandler::ProcessFactory::freeCstr); - this->properties = NULL; // TODO instanciate the dictionary - this->hostName = NULL; - this->function = NULL; - } - - ApplicationHandler::ProcessFactory::~ProcessFactory() - { - xbt_dynar_free(&(this->args)); - } - - // create the cxx process wrapper. - void ApplicationHandler::ProcessFactory::createProcess() - throw (ClassNotFoundException, HostNotFoundException) - { - Host host; - Class* c; - Process* process; - - // try to dynamicaly create an instance fo the process from its name (which is specified by the element function - // in the xml application file. - // if this static method fails, it throws an exception of the class ClassNotFoundException - c = Class::fromName(this->function); - process = reinterpret_cast(c->createObject()); - - // try to retrieve the host of the process from its name - // if this method fails, it throws an exception of the class HostNotFoundException - host = Host::getByName(this->hostName); - - // build the list of the arguments of the newly created process. - int argc = xbt_dynar_length(this->args); - - char** argv = (char**)calloc(argc, sizeof(char*)); - - for(int i = argc -1; i >= 0; i--) - xbt_dynar_pop(this->args, &(argv[i])); - - // finaly create the process (for more detail on the process creation see Process::create() - process->create(host, this->function , argc, argv); - - // TODO add the properties of the process - /*process->properties = this->properties; - this->properties = new Properties();*/ - } - - void ApplicationHandler::ProcessFactory::setProcessIdentity(const char* hostName, const char* function) - { - this->hostName = hostName; - this->function = function; - - /*if (!this->args->empty()) - this->args->clear(); - - if(!this->properties->empty()) - this->properties->clear();*/ - } - - // callback function used by the dynamic array to cleanup all of its elements. - void ApplicationHandler::ProcessFactory::freeCstr(void* cstr) - { - free(*(void**)cstr); - } - - void ApplicationHandler::ProcessFactory::registerProcessArg(const char* arg) - { - char* cstr = _strdup(arg); - xbt_dynar_push(this->args, &cstr); - } - - void ApplicationHandler::ProcessFactory::setProperty(const char* id, const char* value) - { - // TODO implement this function; - } - - const char* ApplicationHandler::ProcessFactory::getHostName(void) - { - return this->hostName; - } - - } // namespace Msg -} // namespace SimGrid - +/* + * ApplicationHandler.cxx + * + * 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. + * + */ + + /* ApplicationHandler member functions implementation. + */ + + +#include +#include + +#include +#include + + + + + +#include + +#include +#include + + +namespace SimGrid +{ + namespace Msg + { + + ApplicationHandler::ProcessFactory* ApplicationHandler::processFactory = NULL; + + // Desable the default constructor, the copy constructor , the assignement operator + // and the destructor of this class. Assume that this class is static. + + // Default constructor. + ApplicationHandler::ApplicationHandler() + { + // NOTHING TODO + } + + // Copy constructor. + ApplicationHandler::ApplicationHandler(const ApplicationHandler& rApplicationHandler) + { + // NOTHING TODO + } + + // Destructor + ApplicationHandler::~ApplicationHandler() + { + // NOTHING TODO + } + + // Assignement operator. + const ApplicationHandler& ApplicationHandler::operator = (const ApplicationHandler& rApplicationHandler) + { + return *this; + } + + void ApplicationHandler::onStartDocument(void) + { + // instanciate the factory at the begining of the parsing + processFactory = new ProcessFactory(); + } + + void ApplicationHandler::onEndDocument(void) + { + // release the handler at the end of the parsing. + if(processFactory) + delete processFactory; + } + + void ApplicationHandler::onBeginProcess(void) + { + // set the process identity at the begin of the xml process element. + processFactory->setProcessIdentity(A_surfxml_process_host, A_surfxml_process_function); + } + + void ApplicationHandler::onProcessArg(void) + { + // register the argument of the current xml process element. + processFactory->registerProcessArg(A_surfxml_argument_value); + } + + void ApplicationHandler::OnProperty(void) + { + // set the property of the current xml process element. + processFactory->setProperty(A_surfxml_prop_id, A_surfxml_prop_value); + } + + void ApplicationHandler::onEndProcess(void) + { + // at the end of the xml process element create the wrapper process (of the native Msg process) + processFactory->createProcess(); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////// + // Process factory connected member functions + + ApplicationHandler::ProcessFactory::ProcessFactory() + { + this->args = xbt_dynar_new(sizeof(char*),ApplicationHandler::ProcessFactory::freeCstr); + this->properties = NULL; // TODO instanciate the dictionary + this->hostName = NULL; + this->function = NULL; + } + + ApplicationHandler::ProcessFactory::~ProcessFactory() + { + xbt_dynar_free(&(this->args)); + } + + // create the cxx process wrapper. + void ApplicationHandler::ProcessFactory::createProcess() + throw (ClassNotFoundException, HostNotFoundException) + { + Host host; + Class* c; + Process* process; + + // try to dynamicaly create an instance of the process from its name (which is specified by the element function + // in the xml application file. + // if this static method fails, it throws an exception of the class ClassNotFoundException + c = Class::fromName(this->function); + process = reinterpret_cast(c->createObject()); + + // try to retrieve the host of the process from its name + // if this method fails, it throws an exception of the class HostNotFoundException + host = Host::getByName(this->hostName); + + // build the list of the arguments of the newly created process. + int argc = xbt_dynar_length(this->args); + + char** argv = (char**)calloc(argc, sizeof(char*)); + + for(int i = argc -1; i >= 0; i--) + xbt_dynar_pop(this->args, &(argv[i])); + + // finaly create the process (for more detail on the process creation see Process::create() + process->create(host, this->function , argc, argv); + + // TODO add the properties of the process + /*process->properties = this->properties; + this->properties = new Properties();*/ + } + + void ApplicationHandler::ProcessFactory::setProcessIdentity(const char* hostName, const char* function) + { + this->hostName = hostName; + this->function = function; + + /*if (!this->args->empty()) + this->args->clear(); + + if(!this->properties->empty()) + this->properties->clear();*/ + } + + // callback function used by the dynamic array to cleanup all of its elements. + void ApplicationHandler::ProcessFactory::freeCstr(void* cstr) + { + free(*(void**)cstr); + } + + void ApplicationHandler::ProcessFactory::registerProcessArg(const char* arg) + { + char* cstr = _strdup(arg); + xbt_dynar_push(this->args, &cstr); + } + + void ApplicationHandler::ProcessFactory::setProperty(const char* id, const char* value) + { + // TODO implement this function; + } + + const char* ApplicationHandler::ProcessFactory::getHostName(void) + { + return this->hostName; + } + + } // namespace Msg +} // namespace SimGrid + diff --git a/src/cxx/ApplicationHandler.hpp b/src/cxx/ApplicationHandler.hpp index df91691d6c..46c7c8ad41 100644 --- a/src/cxx/ApplicationHandler.hpp +++ b/src/cxx/ApplicationHandler.hpp @@ -1,135 +1,135 @@ -/* - * ApplicationHandler.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_APPLICATION_HANDLER_HPP -#define MSG_APPLICATION_HANDLER_HPP - -// Compilation C++ recquise -#ifndef __cplusplus - #error ApplicationHandler.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include -#include - -#include -#include - -namespace SimGrid -{ - namespace Msg - { - class Process; - - // Declaration of the class ApplicationHandler (Singleton). - class SIMGRIDX_EXPORT ApplicationHandler - { - //friend Process; - - public: - - class ProcessFactory - { - public: - - // the list of the argument of the process to create. - xbt_dynar_t args; - // the properties of the process to create - xbt_dict_t properties; - - private: - - // the current host name parsed - const char* hostName; - // the name of the class of the process - const char* function; - - public : - - // Default constructor. - ProcessFactory(); - - // Copy constructor. - ProcessFactory(const ProcessFactory& rProcessFactory); - - // Destructor. - virtual ~ProcessFactory(); - - // Set the identity of the current process. - void setProcessIdentity(const char* hostName, const char* function); - - // Register an argument of the current process. - void registerProcessArg(const char* arg); - - // Set the property of the current process. - void setProperty(const char* id, const char* value); - - // Return the host name of the current process. - const char* getHostName(void); - - // Create the current process. - void createProcess(void) - throw (ClassNotFoundException, HostNotFoundException); - - static void freeCstr(void* cstr); - - }; - - private : - - // Desable the default constructor, the copy constructor , the assignement operator - // and the destructor of this class. Assume that this class is static. - - // Default constructor. - ApplicationHandler(); - - // Copy constructor. - ApplicationHandler(const ApplicationHandler& rApplicationHandler); - - // Destructor - virtual ~ApplicationHandler(); - - // Assignement operator. - const ApplicationHandler& operator = (const ApplicationHandler& rApplicationHandler); - - // the process factory used by the application handler. - static ProcessFactory* processFactory; - - - public: - - // Handle the begining of the parsing of the xml file describing the application. - static void onStartDocument(void); - - // Handle at the end of the parsing. - static void onEndDocument(void); - - // Handle the begining of the parsing of a xml process element. - static void onBeginProcess(void); - - // Handle the parsing of an argument of the current xml process element. - static void onProcessArg(void); - - // Handle the parsing of a property of the currnet xml process element. - static void OnProperty(void); - - // Handle the end of the parsing of a xml process element - static void onEndProcess(void); - }; - - } // namespace Msg -} // namespace SimGrid - -#endif // !MSG_APPLICATION_HANDLER_HPP - +/* + * ApplicationHandler.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_APPLICATION_HANDLER_HPP +#define MSG_APPLICATION_HANDLER_HPP + +// Compilation C++ recquise +#ifndef __cplusplus + #error ApplicationHandler.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +#include + +#include +#include + +namespace SimGrid +{ + namespace Msg + { + class Process; + + // Declaration of the class ApplicationHandler (Singleton). + class SIMGRIDX_EXPORT ApplicationHandler + { + //friend Process; + + public: + + class ProcessFactory + { + public: + + // the list of the argument of the process to create. + xbt_dynar_t args; + // the properties of the process to create + xbt_dict_t properties; + + private: + + // the current host name parsed + const char* hostName; + // the name of the class of the process + const char* function; + + public : + + // Default constructor. + ProcessFactory(); + + // Copy constructor. + ProcessFactory(const ProcessFactory& rProcessFactory); + + // Destructor. + virtual ~ProcessFactory(); + + // Set the identity of the current process. + void setProcessIdentity(const char* hostName, const char* function); + + // Register an argument of the current process. + void registerProcessArg(const char* arg); + + // Set the property of the current process. + void setProperty(const char* id, const char* value); + + // Return the host name of the current process. + const char* getHostName(void); + + // Create the current process. + void createProcess(void) + throw (ClassNotFoundException, HostNotFoundException); + + static void freeCstr(void* cstr); + + }; + + private : + + // Desable the default constructor, the copy constructor , the assignement operator + // and the destructor of this class. Assume that this class is static. + + // Default constructor. + ApplicationHandler(); + + // Copy constructor. + ApplicationHandler(const ApplicationHandler& rApplicationHandler); + + // Destructor + virtual ~ApplicationHandler(); + + // Assignement operator. + const ApplicationHandler& operator = (const ApplicationHandler& rApplicationHandler); + + // the process factory used by the application handler. + static ProcessFactory* processFactory; + + + public: + + // Handle the begining of the parsing of the xml file describing the application. + static void onStartDocument(void); + + // Handle at the end of the parsing. + static void onEndDocument(void); + + // Handle the begining of the parsing of a xml process element. + static void onBeginProcess(void); + + // Handle the parsing of an argument of the current xml process element. + static void onProcessArg(void); + + // Handle the parsing of a property of the currnet xml process element. + static void OnProperty(void); + + // Handle the end of the parsing of a xml process element + static void onEndProcess(void); + }; + + } // namespace Msg +} // namespace SimGrid + +#endif // !MSG_APPLICATION_HANDLER_HPP + diff --git a/src/cxx/BadAllocException.cxx b/src/cxx/BadAllocException.cxx index 265f5de4da..24d02793db 100644 --- a/src/cxx/BadAllocException.cxx +++ b/src/cxx/BadAllocException.cxx @@ -1,74 +1,74 @@ -/* - * BadAllocationException.cxx - * - * 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. - * - */ - - /* BadAllocationException member functions implementation. - */ - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - BadAllocException::BadAllocException() - { - this->reason = (char*) calloc(strlen("Not enough memory") + 1, sizeof(char)); - strcpy(this->reason, "Not enough memory"); - } - - - BadAllocException::BadAllocException(const BadAllocException& rBadAllocException) - { - const char* reason = rBadAllocException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - BadAllocException::BadAllocException(const char* objectName) - { - this->reason = (char*) calloc(strlen("Not enough memory to allocate ") + strlen(objectName) + 1, sizeof(char)); - sprintf(this->reason, "Not enough memory to allocate %s", objectName); - } - - - BadAllocException::~BadAllocException() - { - if(this->reason) - free(this->reason); - } - - const char* BadAllocException::toString(void) const - { - return (const char*)(this->reason); - } - - - const BadAllocException& BadAllocException::operator = (const BadAllocException& rBadAllocException) - { - const char* reason = rBadAllocException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * BadAllocationException.cxx + * + * 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. + * + */ + + /* BadAllocationException member functions implementation. + */ + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + BadAllocException::BadAllocException() + { + this->reason = (char*) calloc(strlen("Not enough memory") + 1, sizeof(char)); + strcpy(this->reason, "Not enough memory"); + } + + + BadAllocException::BadAllocException(const BadAllocException& rBadAllocException) + { + const char* reason = rBadAllocException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + BadAllocException::BadAllocException(const char* objectName) + { + this->reason = (char*) calloc(strlen("Not enough memory to allocate ") + strlen(objectName) + 1, sizeof(char)); + sprintf(this->reason, "Not enough memory to allocate %s", objectName); + } + + + BadAllocException::~BadAllocException() + { + if(this->reason) + free(this->reason); + } + + const char* BadAllocException::toString(void) const + { + return (const char*)(this->reason); + } + + + const BadAllocException& BadAllocException::operator = (const BadAllocException& rBadAllocException) + { + const char* reason = rBadAllocException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/BadAllocException.hpp b/src/cxx/BadAllocException.hpp index b5726ee503..69221ce55c 100644 --- a/src/cxx/BadAllocException.hpp +++ b/src/cxx/BadAllocException.hpp @@ -1,69 +1,69 @@ -/* - * BadAllocException.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_BADALLOCEXCEPTION_HPP -#define MSG_BADALLOCEXCEPTION_HPP - -#ifndef __cplusplus - #error BadAllocException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT BadAllocException : public Exception - { - public: - - // Default constructor. - BadAllocException(); - - // Copy constructor. - BadAllocException(const BadAllocException& rBadAllocException); - - // This constructor takes the name of the object of the allocation failure. - BadAllocException(const char* objectName); - - // Destructor. - virtual ~BadAllocException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Not enough memory to allocate : `object name'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const BadAllocException& operator = (const BadAllocException& rBadAllocException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_BADALLOCEXCEPTION_HPP - +/* + * BadAllocException.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_BADALLOCEXCEPTION_HPP +#define MSG_BADALLOCEXCEPTION_HPP + +#ifndef __cplusplus + #error BadAllocException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT BadAllocException : public Exception + { + public: + + // Default constructor. + BadAllocException(); + + // Copy constructor. + BadAllocException(const BadAllocException& rBadAllocException); + + // This constructor takes the name of the object of the allocation failure. + BadAllocException(const char* objectName); + + // Destructor. + virtual ~BadAllocException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Not enough memory to allocate : `object name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const BadAllocException& operator = (const BadAllocException& rBadAllocException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_BADALLOCEXCEPTION_HPP + diff --git a/src/cxx/ClassNotFoundException.cxx b/src/cxx/ClassNotFoundException.cxx index 236ba2ae25..13887a293f 100644 --- a/src/cxx/ClassNotFoundException.cxx +++ b/src/cxx/ClassNotFoundException.cxx @@ -1,75 +1,75 @@ -/* - * ClassNotFoundException.cxx - * - * 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. - * - */ - - /* ClassNotFoundException member functions implementation. - */ - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - ClassNotFoundException::ClassNotFoundException() - { - this->reason = (char*) calloc(strlen("Class not found : unknown") + 1, sizeof(char)); - strcpy(this->reason, "Class not found : unknown"); - } - - - ClassNotFoundException::ClassNotFoundException(const ClassNotFoundException& rClassNotFoundException) - { - const char* reason = rClassNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - - ClassNotFoundException::ClassNotFoundException(const char* name) - { - this->reason = (char*) calloc(strlen("Class not found : ") + strlen(name) + 1, sizeof(char)); - sprintf(this->reason, "Class not found : %s", name); - } - - - ClassNotFoundException::~ClassNotFoundException() - { - if(this->reason) - free(this->reason); - } - - const char* ClassNotFoundException::toString(void) const - { - return (const char*)(this->reason); - } - - - const ClassNotFoundException& ClassNotFoundException::operator = (const ClassNotFoundException& rClassNotFoundException) - { - const char* reason = rClassNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * ClassNotFoundException.cxx + * + * 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. + * + */ + + /* ClassNotFoundException member functions implementation. + */ + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + ClassNotFoundException::ClassNotFoundException() + { + this->reason = (char*) calloc(strlen("Class not found : unknown") + 1, sizeof(char)); + strcpy(this->reason, "Class not found : unknown"); + } + + + ClassNotFoundException::ClassNotFoundException(const ClassNotFoundException& rClassNotFoundException) + { + const char* reason = rClassNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + ClassNotFoundException::ClassNotFoundException(const char* name) + { + this->reason = (char*) calloc(strlen("Class not found : ") + strlen(name) + 1, sizeof(char)); + sprintf(this->reason, "Class not found : %s", name); + } + + + ClassNotFoundException::~ClassNotFoundException() + { + if(this->reason) + free(this->reason); + } + + const char* ClassNotFoundException::toString(void) const + { + return (const char*)(this->reason); + } + + + const ClassNotFoundException& ClassNotFoundException::operator = (const ClassNotFoundException& rClassNotFoundException) + { + const char* reason = rClassNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/ClassNotFoundException.hpp b/src/cxx/ClassNotFoundException.hpp index bc909701f9..36a77b95e9 100644 --- a/src/cxx/ClassNotFoundException.hpp +++ b/src/cxx/ClassNotFoundException.hpp @@ -1,69 +1,69 @@ -/* - * ClassNotFoundException.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_CLASSNOTFOUNDEXCEPTION_HPP -#define MSG_CLASSNOTFOUNDEXCEPTION_HPP - -#ifndef __cplusplus - #error ClassNotFoundException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT ClassNotFoundException : public Exception - { - public: - - // Default constructor. - ClassNotFoundException(); - - // Copy constructor. - ClassNotFoundException(const ClassNotFoundException& rClassNotFoundException); - - // This constructor takes the name of the class not found. - ClassNotFoundException(const char* name); - - // Destructor. - virtual ~ClassNotFoundException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Host not found `host name'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const ClassNotFoundException& operator = (const ClassNotFoundException& rClassNotFoundException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_CLASSNOTFOUNDEXCEPTION_HPP - +/* + * ClassNotFoundException.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_CLASSNOTFOUNDEXCEPTION_HPP +#define MSG_CLASSNOTFOUNDEXCEPTION_HPP + +#ifndef __cplusplus + #error ClassNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT ClassNotFoundException : public Exception + { + public: + + // Default constructor. + ClassNotFoundException(); + + // Copy constructor. + ClassNotFoundException(const ClassNotFoundException& rClassNotFoundException); + + // This constructor takes the name of the class not found. + ClassNotFoundException(const char* name); + + // Destructor. + virtual ~ClassNotFoundException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Host not found `host name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const ClassNotFoundException& operator = (const ClassNotFoundException& rClassNotFoundException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_CLASSNOTFOUNDEXCEPTION_HPP + diff --git a/src/cxx/Config.hpp b/src/cxx/Config.hpp index 0fc1e6fb52..2f9ed2de5d 100644 --- a/src/cxx/Config.hpp +++ b/src/cxx/Config.hpp @@ -1,44 +1,44 @@ - -/* - * Config.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_CONFIG_HPP -#define MSG_CONFIG_HPP - -#ifndef __cplusplus - #error Config.hpp requires C++ compilation (use a .cxx suffix) -#endif - -namespace SimGrid -{ - namespace Msg - { - #if defined(WIN32) && !defined(__MINGW32__) - #if defined(SIMGRIDX_EXPORTS) - #define SIMGRIDX_EXPORT __declspec(dllexport) - #else - #define SIMGRIDX_EXPORT __declspec(dllimport) - #endif - #else - #define SIMGRIDX_EXPORT - #endif - } // namespace Msg -} // namespace SimGrid - -#ifndef WIN32 -#define _strdup strdup -#endif - -#endif // MSG_CONFIG_HPP - + +/* + * Config.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_CONFIG_HPP +#define MSG_CONFIG_HPP + +#ifndef __cplusplus + #error Config.hpp requires C++ compilation (use a .cxx suffix) +#endif + +namespace SimGrid +{ + namespace Msg + { + #if defined(WIN32) && !defined(__MINGW32__) + #if defined(SIMGRIDX_EXPORTS) + #define SIMGRIDX_EXPORT __declspec(dllexport) + #else + #define SIMGRIDX_EXPORT __declspec(dllimport) + #endif + #else + #define SIMGRIDX_EXPORT + #endif + } // namespace Msg +} // namespace SimGrid + +#ifndef WIN32 +#define _strdup strdup +#endif + +#endif // MSG_CONFIG_HPP + diff --git a/src/cxx/Environment.cxx b/src/cxx/Environment.cxx index 71e0acf7aa..0d9b0031af 100644 --- a/src/cxx/Environment.cxx +++ b/src/cxx/Environment.cxx @@ -1,159 +1,159 @@ -/* - * Environment.cxx - * - * 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. - * - */ - - /* Environment member functions implementation. - */ - -#include - -#include - -#include -#include - -#include - -#ifndef S_ISREG - #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) -#endif - -namespace SimGrid -{ - namespace Msg - { - Environment::Environment() - { - this->file = NULL; - this->loaded = false; - } - - Environment::Environment(const Environment& rEnvironment) - { - this->file = rEnvironment.getFile(); - this->loaded = rEnvironment.isLoaded(); - } - - Environment::Environment(const char* file) - throw(NullPointerException, FileNotFoundException) - { - // check parameters - - if(!file) - throw NullPointerException("file (must not be NULL"); - - struct stat statBuf = {0}; - - if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) - throw FileNotFoundException("file (file not found)"); - - this->file = file; - this->loaded = false; - } - - Environment::~Environment() - { - // NOTHING TODO - } - - // Operations. - - void Environment::load(void) - throw(LogicException) - { - // check logic - - if(this->loaded) - throw LogicException("environement already loaded"); - - // check the parameters - if(!this->file) - throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()"); - - MSG_create_environment(file); - - this->loaded = true; - } - - void Environment::load(const char* file) - throw(NullPointerException, FileNotFoundException, LogicException) - { - // check logic - - if(this->loaded) - throw LogicException("environment already loaded"); - - // check the parameters - - if(!file) - throw NullPointerException("file"); - - struct stat statBuf = {0}; - - if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) - throw FileNotFoundException(file); - - MSG_create_environment(file); - - this->file = file; - this->loaded = true; - } - - bool Environment::isLoaded(void) const - { - return this->loaded; - } - - // Getters/setters - void Environment::setFile(const char* file) - throw(NullPointerException, FileNotFoundException, LogicException) - { - // check logic - - if(this->loaded) - throw LogicException("your are trying to change the file of an already loaded environment"); - - // check parameters - - if(!file) - throw NullPointerException("file (must not be NULL"); - - struct stat statBuf = {0}; - - if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) - throw FileNotFoundException("file (file not found)"); - - this->file = file; - } - - const char* Environment::getFile(void) const - { - return this->file; - } - - - const Environment& Environment::operator = (const Environment& rEnvironment) - throw(LogicException) - { - // check logic - - if(this->loaded) - throw LogicException("environment already loaded"); - - this->file = rEnvironment.getFile(); - this->loaded = rEnvironment.isLoaded(); - - return *this; - } - - } // namespace Msg -} // namespace SimGrid - +/* + * Environment.cxx + * + * 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. + * + */ + + /* Environment member functions implementation. + */ + +#include + +#include + +#include +#include + +#include + +#ifndef S_ISREG + #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) +#endif + +namespace SimGrid +{ + namespace Msg + { + Environment::Environment() + { + this->file = NULL; + this->loaded = false; + } + + Environment::Environment(const Environment& rEnvironment) + { + this->file = rEnvironment.getFile(); + this->loaded = rEnvironment.isLoaded(); + } + + Environment::Environment(const char* file) + throw(NullPointerException, FileNotFoundException) + { + // check parameters + + if(!file) + throw NullPointerException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) + throw FileNotFoundException("file (file not found)"); + + this->file = file; + this->loaded = false; + } + + Environment::~Environment() + { + // NOTHING TODO + } + + // Operations. + + void Environment::load(void) + throw(LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("environement already loaded"); + + // check the parameters + if(!this->file) + throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()"); + + MSG_create_environment(file); + + this->loaded = true; + } + + void Environment::load(const char* file) + throw(NullPointerException, FileNotFoundException, LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("environment already loaded"); + + // check the parameters + + if(!file) + throw NullPointerException("file"); + + struct stat statBuf = {0}; + + if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) + throw FileNotFoundException(file); + + MSG_create_environment(file); + + this->file = file; + this->loaded = true; + } + + bool Environment::isLoaded(void) const + { + return this->loaded; + } + + // Getters/setters + void Environment::setFile(const char* file) + throw(NullPointerException, FileNotFoundException, LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("your are trying to change the file of an already loaded environment"); + + // check parameters + + if(!file) + throw NullPointerException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) + throw FileNotFoundException("file (file not found)"); + + this->file = file; + } + + const char* Environment::getFile(void) const + { + return this->file; + } + + + const Environment& Environment::operator = (const Environment& rEnvironment) + throw(LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("environment already loaded"); + + this->file = rEnvironment.getFile(); + this->loaded = rEnvironment.isLoaded(); + + return *this; + } + + } // namespace Msg +} // namespace SimGrid + diff --git a/src/cxx/Environment.hpp b/src/cxx/Environment.hpp index 89f6e4863d..8f8e0a0e28 100644 --- a/src/cxx/Environment.hpp +++ b/src/cxx/Environment.hpp @@ -1,153 +1,153 @@ -/* - * 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 - -#ifndef __cplusplus - #error Environment.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include -#include -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - class NullPointerException; - class FileNotFoundException; - class InvalidArgumentException; - class LogicException; - class MsgException; - - // Environment class wrapper declaration - class SIMGRIDX_EXPORT Environment - { - 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(NullPointerException, FileNotFoundException); - - /*! \brief Destructor. - */ - virtual ~Environment(); - - // 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(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 - /*! \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(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. - - /*! \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); - - private: - - // Attributes. - - // the xml file which describe the environment of the simulation. - const char* file; - - // flag : is true the environment of the simulation is loaded. - bool loaded; - }; - - } // namespace Msg -} // namespace SimGrid - - -#endif // !MSG_ENVIRONMENT_HPP - +/* + * 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 + +#ifndef __cplusplus + #error Environment.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +#include +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + class NullPointerException; + class FileNotFoundException; + class InvalidArgumentException; + class LogicException; + class MsgException; + + // Environment class wrapper declaration + class SIMGRIDX_EXPORT Environment + { + 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(NullPointerException, FileNotFoundException); + + /*! \brief Destructor. + */ + virtual ~Environment(); + + // 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(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 + /*! \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(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. + + /*! \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); + + private: + + // Attributes. + + // the xml file which describe the environment of the simulation. + const char* file; + + // flag : is true the environment of the simulation is loaded. + bool loaded; + }; + + } // namespace Msg +} // namespace SimGrid + + +#endif // !MSG_ENVIRONMENT_HPP + diff --git a/src/cxx/Exception.cxx b/src/cxx/Exception.cxx index 94ae26e881..c314f13f7c 100644 --- a/src/cxx/Exception.cxx +++ b/src/cxx/Exception.cxx @@ -1,64 +1,64 @@ -/* - * Exception.cxx - * - * 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. - * - */ - - /* Exception member functions implementation. - * The base class of all the types of exceptions of SimGrid::Msg. - */ - -#include - -namespace SimGrid -{ - namespace Msg - { - - Exception::Exception() - { - reason = "Unknown reason"; - } - - - Exception::Exception(const Exception& rException) - { - this->reason = rException.toString(); - } - - - Exception::Exception(const char* reason) - { - this->reason = reason; - } - - - Exception::~Exception() - { - // NOTHING TODO - } - - const char* Exception::toString(void) const - { - return this->reason; - } - - - const Exception& Exception::operator = (const Exception& rException) - { - this->reason = rException.toString(); - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * Exception.cxx + * + * 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. + * + */ + + /* Exception member functions implementation. + * The base class of all the types of exceptions of SimGrid::Msg. + */ + +#include + +namespace SimGrid +{ + namespace Msg + { + + Exception::Exception() + { + reason = "Unknown reason"; + } + + + Exception::Exception(const Exception& rException) + { + this->reason = rException.toString(); + } + + + Exception::Exception(const char* reason) + { + this->reason = reason; + } + + + Exception::~Exception() + { + // NOTHING TODO + } + + const char* Exception::toString(void) const + { + return this->reason; + } + + + const Exception& Exception::operator = (const Exception& rException) + { + this->reason = rException.toString(); + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/Exception.hpp b/src/cxx/Exception.hpp index 1b1a8ee5e7..2fc3067809 100644 --- a/src/cxx/Exception.hpp +++ b/src/cxx/Exception.hpp @@ -1,68 +1,68 @@ -/* - * Exception.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_EXCEPTION_HPP -#define MSG_EXCEPTION_HPP - -#ifndef __cplusplus - #error Exception.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT Exception - { - public: - - // Default constructor. - Exception(); - - // Copy constructor. - Exception(const Exception& rException); - - // This constructor takes the reason of the exception. - Exception(const char* reason); - - // Destructor. - virtual ~Exception(); - - // Operations. - - // Returns the reason of the exception. - const char* toString(void) const; - - // Operators. - - // Assignement. - const Exception& operator = (const Exception& rException); - - private : - - // Attributes. - - // The reason of the exceptions. - const char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_EXCEPTION_HPP - +/* + * Exception.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_EXCEPTION_HPP +#define MSG_EXCEPTION_HPP + +#ifndef __cplusplus + #error Exception.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT Exception + { + public: + + // Default constructor. + Exception(); + + // Copy constructor. + Exception(const Exception& rException); + + // This constructor takes the reason of the exception. + Exception(const char* reason); + + // Destructor. + virtual ~Exception(); + + // Operations. + + // Returns the reason of the exception. + const char* toString(void) const; + + // Operators. + + // Assignement. + const Exception& operator = (const Exception& rException); + + private : + + // Attributes. + + // The reason of the exceptions. + const char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_EXCEPTION_HPP + diff --git a/src/cxx/FileNotFoundException.cxx b/src/cxx/FileNotFoundException.cxx index 297d60c827..3ceec071a2 100644 --- a/src/cxx/FileNotFoundException.cxx +++ b/src/cxx/FileNotFoundException.cxx @@ -1,75 +1,75 @@ -/* - * FileNotFoundException.cxx - * - * 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. - * - */ - - /* FileNotFoundException member functions implementation. - */ - -#include - -#include -#include -#include - - -namespace SimGrid -{ - namespace Msg - { - - FileNotFoundException::FileNotFoundException() - { - this->reason = (char*) calloc(strlen("File not found") + 1, sizeof(char)); - strcpy(this->reason, "File not found"); - } - - - FileNotFoundException::FileNotFoundException(const FileNotFoundException& rFileNotFoundException) - { - const char* reason = rFileNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - FileNotFoundException::FileNotFoundException(const char* file) - { - this->reason = (char*) calloc(strlen("File not found ") + strlen(file) + 1, sizeof(char)); - sprintf(this->reason, "File not found %s", file); - } - - - FileNotFoundException::~FileNotFoundException() - { - if(this->reason) - free(this->reason); - } - - const char* FileNotFoundException::toString(void) const - { - return (const char*)(this->reason); - } - - - const FileNotFoundException& FileNotFoundException::operator = (const FileNotFoundException& rFileNotFoundException) - { - const char* reason = rFileNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * FileNotFoundException.cxx + * + * 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. + * + */ + + /* FileNotFoundException member functions implementation. + */ + +#include + +#include +#include +#include + + +namespace SimGrid +{ + namespace Msg + { + + FileNotFoundException::FileNotFoundException() + { + this->reason = (char*) calloc(strlen("File not found") + 1, sizeof(char)); + strcpy(this->reason, "File not found"); + } + + + FileNotFoundException::FileNotFoundException(const FileNotFoundException& rFileNotFoundException) + { + const char* reason = rFileNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + FileNotFoundException::FileNotFoundException(const char* file) + { + this->reason = (char*) calloc(strlen("File not found ") + strlen(file) + 1, sizeof(char)); + sprintf(this->reason, "File not found %s", file); + } + + + FileNotFoundException::~FileNotFoundException() + { + if(this->reason) + free(this->reason); + } + + const char* FileNotFoundException::toString(void) const + { + return (const char*)(this->reason); + } + + + const FileNotFoundException& FileNotFoundException::operator = (const FileNotFoundException& rFileNotFoundException) + { + const char* reason = rFileNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/FileNotFoundException.hpp b/src/cxx/FileNotFoundException.hpp index a7ddfbc1b5..53a6247282 100644 --- a/src/cxx/FileNotFoundException.hpp +++ b/src/cxx/FileNotFoundException.hpp @@ -1,69 +1,69 @@ -/* - * FileNotFoundException.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_FILENOTFOUND_HPP -#define MSG_FILENOTFOUND_HPP - -#ifndef __cplusplus - #error FileNotFoundException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT FileNotFoundException : public Exception - { - public: - - // Default constructor. - FileNotFoundException(); - - // Copy constructor. - FileNotFoundException(const FileNotFoundException& rFileNotFoundException); - - // This constructor takes the name of the file. - FileNotFoundException(const char* file); - - // Destructor. - virtual ~FileNotFoundException(); - - // Operations. - - // Returns the reason of the exception : - // the message "File not found : `object name'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const FileNotFoundException& operator = (const FileNotFoundException& rFileNotFoundException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_MSGEXCEPTION_HPP - +/* + * FileNotFoundException.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_FILENOTFOUND_HPP +#define MSG_FILENOTFOUND_HPP + +#ifndef __cplusplus + #error FileNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT FileNotFoundException : public Exception + { + public: + + // Default constructor. + FileNotFoundException(); + + // Copy constructor. + FileNotFoundException(const FileNotFoundException& rFileNotFoundException); + + // This constructor takes the name of the file. + FileNotFoundException(const char* file); + + // Destructor. + virtual ~FileNotFoundException(); + + // Operations. + + // Returns the reason of the exception : + // the message "File not found : `object name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const FileNotFoundException& operator = (const FileNotFoundException& rFileNotFoundException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_MSGEXCEPTION_HPP + diff --git a/src/cxx/Host.cxx b/src/cxx/Host.cxx index 18997ea5fb..39f40eb1dc 100644 --- a/src/cxx/Host.cxx +++ b/src/cxx/Host.cxx @@ -1,343 +1,343 @@ -/* - * Host.cxx - * - * 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. - * - */ - - /* Host class member functions implementation. - */ - -#include -#include - -#include - -#include -#include - -#include -#include - -#include - -namespace SimGrid -{ - namespace Msg - { - Host::Host() - { - nativeHost = NULL; - data = NULL; - } - - Host::Host(const Host& rHost) - { - this->nativeHost = rHost.nativeHost; - this->data = rHost.getData(); - } - - Host::~Host() - { - // NOTHING TODO - } - - - Host& Host::getByName(const char* hostName) - throw(HostNotFoundException, NullPointerException, BadAllocException) - { - // check the parameters - if(!hostName) - throw NullPointerException("hostName"); - - m_host_t nativeHost = NULL; // native host. - Host* host = NULL; // wrapper host. - - if(!(nativeHost = MSG_get_host_by_name(hostName))) - throw HostNotFoundException(hostName); - - if(!nativeHost->data) - { // native host not associated yet with its wrapper - - // instanciate a new wrapper - if(!(host = new Host())) - throw BadAllocException(hostName); - - host->nativeHost = nativeHost; - - // the native host data field is set with its wrapper returned - nativeHost->data = (void*)host; - } - - // return the reference to cxx wrapper - return *((Host*)nativeHost->data); - } - - int Host::getNumber(void) - { - return MSG_get_host_number(); - } - - Host& Host::currentHost(void) - { - Host* host = NULL; - m_host_t nativeHost = MSG_host_self(); - - if(!nativeHost->data) - { - // the native host not yet associated with its wrapper - - // instanciate a new wrapper - host = new Host(); - - host->nativeHost = nativeHost; - - nativeHost->data = (void*)host; - } - else - { - host = (Host*)nativeHost->data; - } - - return *host; - } - - void Host::all(Host*** hosts, int* len) - throw(InvalidArgumentException, BadAllocException) - { - // check the parameters - if(!hosts) - throw InvalidArgumentException("hosts"); - - if(len < 0) - throw InvalidArgumentException("len parameter must be positive"); - - int count = xbt_fifo_size(msg_global->host); - - if(*len < count) - throw InvalidArgumentException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)"); - - int index; - m_host_t nativeHost; - Host* host; - - m_host_t* table = (m_host_t *)xbt_fifo_to_array(msg_global->host); - - for(index = 0; index < count; index++) - { - nativeHost = table[index]; - host = (Host*)(nativeHost->data); - - if(!host) - { - if(!(host = new Host())) - { - // release all allocated memory. - for(int i = 0; i < index; i++) - delete (*(hosts)[i]); - - throw BadAllocException("to fill the table of the hosts installed on your platform"); - } - - host->nativeHost = nativeHost; - nativeHost->data = (void*)host; - } - - (*hosts)[index] = host; - } - - *len = count; - } - - const char* Host::getName(void) const - { - return nativeHost->name; - } - - void Host::setData(void* data) - { - this->data = data; - } - - void* Host::getData(void) const - { - return this->data; - } - - int Host::getRunningTaskNumber(void) const - { - return MSG_get_host_msgload(nativeHost); - } - - double Host::getSpeed(void) const - { - return MSG_get_host_speed(nativeHost); - } - - bool Host::hasData(void) const - { - return (NULL != this->data); - } - - int Host::isAvailable(void) const - { - return SIMIX_host_get_state(nativeHost->simdata->smx_host); - } - - void Host::put(int channel, Task* task) - throw(MsgException, InvalidArgumentException) - { - // checks the parameters - if(channel < 0) - throw InvalidArgumentException("channel (must be more or equal to zero)"); - - if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, nativeHost, channel , -1.0)) - throw MsgException("MSG_task_put_with_timeout() failed"); - } - - void Host::put(int channel, Task* task, double timeout) - throw(MsgException, InvalidArgumentException) - { - // checks the parameters - if(channel < 0) - throw InvalidArgumentException("channel (must be more or equal to zero)"); - - if(timeout < 0.0 && timeout != -1.0) - throw InvalidArgumentException("timeout (must be more or equal to zero or equal to -1.0)"); - - - if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, nativeHost, channel , timeout)) - throw MsgException("MSG_task_put_with_timeout() failed"); - } - - void Host::putBounded(int channel, Task* task, double maxRate) - throw(MsgException, InvalidArgumentException) - { - // checks the parameters - if(channel < 0) - throw InvalidArgumentException("channel (must be more or equal to zero)"); - - if(maxRate < 0.0 && maxRate != -1.0) - throw InvalidArgumentException("maxRate (must be more or equal to zero or equal to -1.0)"); - - if(MSG_OK != MSG_task_put_bounded(task->nativeTask, nativeHost, channel, maxRate)) - throw MsgException("MSG_task_put_bounded() failed"); - } - - void Host::send(Task* task) - throw(MsgException, BadAllocException) - { - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(this->getName())+ strlen(Process::currentProcess().getName()) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); - - rv = MSG_task_send_with_timeout(task->nativeTask, alias, -1.0); - - free(alias); - - if(MSG_OK != rv) - throw MsgException("MSG_task_send_with_timeout() failed"); - } - - void Host::send(const char* alias, Task* task) - throw(InvalidArgumentException, MsgException) - { - // check the parameters - if(!alias) - throw InvalidArgumentException("alias (must not be NULL)"); - - if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias, -1.0)) - throw MsgException("MSG_task_send_with_timeout() failed"); - } - - void Host::send(Task* task, double timeout) - throw(InvalidArgumentException, BadAllocException, MsgException) - { - // check the parameters - if(timeout < 0 && timeout != -1.0) - throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)"); - - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); - - - rv = MSG_task_send_with_timeout(task->nativeTask, alias, timeout); - - free(alias); - - if(MSG_OK != rv) - throw MsgException("MSG_task_send_with_timeout() failed"); - } - - void Host::send(const char* alias, Task* task, double timeout) - throw(InvalidArgumentException, MsgException) - { - // check the parameter - - if(!alias) - throw InvalidArgumentException("alias (must not be NULL)"); - - if(timeout < 0 && timeout != -1.0) - throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)"); - - if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias, timeout)) - throw MsgException("MSG_task_send_with_timeout() failed"); - } - - - void Host::sendBounded(Task* task, double maxRate) - throw(InvalidArgumentException, BadAllocException, MsgException) - { - if(maxRate < 0 && maxRate != -1.0) - throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)"); - - MSG_error_t rv; - - char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); - - rv = MSG_task_send_bounded(task->nativeTask, alias, maxRate); - - free(alias); - - if(MSG_OK != rv) - throw MsgException("MSG_task_send_bounded() failed"); - } - - void Host::sendBounded(const char* alias, Task* task, double maxRate) - throw(InvalidArgumentException, MsgException) - { - // check the parameters - if(!alias) - throw InvalidArgumentException("alias (must not be NULL)"); - - if(maxRate < 0 && maxRate != -1) - throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)"); - - if(MSG_OK != MSG_task_send_bounded(task->nativeTask, alias, maxRate)) - throw MsgException("MSG_task_send_bounded() failed"); - - } - } // namspace Msg -} // namespace SimGrid - +/* + * Host.cxx + * + * 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. + * + */ + + /* Host class member functions implementation. + */ + +#include +#include + +#include + +#include +#include + +#include +#include + +#include + +namespace SimGrid +{ + namespace Msg + { + Host::Host() + { + nativeHost = NULL; + data = NULL; + } + + Host::Host(const Host& rHost) + { + this->nativeHost = rHost.nativeHost; + this->data = rHost.getData(); + } + + Host::~Host() + { + // NOTHING TODO + } + + + Host& Host::getByName(const char* hostName) + throw(HostNotFoundException, NullPointerException, BadAllocException) + { + // check the parameters + if(!hostName) + throw NullPointerException("hostName"); + + m_host_t nativeHost = NULL; // native host. + Host* host = NULL; // wrapper host. + + if(!(nativeHost = MSG_get_host_by_name(hostName))) + throw HostNotFoundException(hostName); + + if(!nativeHost->data) + { // native host not associated yet with its wrapper + + // instanciate a new wrapper + if(!(host = new Host())) + throw BadAllocException(hostName); + + host->nativeHost = nativeHost; + + // the native host data field is set with its wrapper returned + nativeHost->data = (void*)host; + } + + // return the reference to cxx wrapper + return *((Host*)nativeHost->data); + } + + int Host::getNumber(void) + { + return MSG_get_host_number(); + } + + Host& Host::currentHost(void) + { + Host* host = NULL; + m_host_t nativeHost = MSG_host_self(); + + if(!nativeHost->data) + { + // the native host not yet associated with its wrapper + + // instanciate a new wrapper + host = new Host(); + + host->nativeHost = nativeHost; + + nativeHost->data = (void*)host; + } + else + { + host = (Host*)nativeHost->data; + } + + return *host; + } + + void Host::all(Host*** hosts, int* len) + throw(InvalidArgumentException, BadAllocException) + { + // check the parameters + if(!hosts) + throw InvalidArgumentException("hosts"); + + if(len < 0) + throw InvalidArgumentException("len parameter must be positive"); + + int count = xbt_fifo_size(msg_global->host); + + if(*len < count) + throw InvalidArgumentException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)"); + + int index; + m_host_t nativeHost; + Host* host; + + m_host_t* table = (m_host_t *)xbt_fifo_to_array(msg_global->host); + + for(index = 0; index < count; index++) + { + nativeHost = table[index]; + host = (Host*)(nativeHost->data); + + if(!host) + { + if(!(host = new Host())) + { + // release all allocated memory. + for(int i = 0; i < index; i++) + delete (*(hosts)[i]); + + throw BadAllocException("to fill the table of the hosts installed on your platform"); + } + + host->nativeHost = nativeHost; + nativeHost->data = (void*)host; + } + + (*hosts)[index] = host; + } + + *len = count; + } + + const char* Host::getName(void) const + { + return nativeHost->name; + } + + void Host::setData(void* data) + { + this->data = data; + } + + void* Host::getData(void) const + { + return this->data; + } + + int Host::getRunningTaskNumber(void) const + { + return MSG_get_host_msgload(nativeHost); + } + + double Host::getSpeed(void) const + { + return MSG_get_host_speed(nativeHost); + } + + bool Host::hasData(void) const + { + return (NULL != this->data); + } + + int Host::isAvailable(void) const + { + return SIMIX_host_get_state(nativeHost->simdata->smx_host); + } + + void Host::put(int channel, Task* task) + throw(MsgException, InvalidArgumentException) + { + // checks the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must be more or equal to zero)"); + + if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, nativeHost, channel , -1.0)) + throw MsgException("MSG_task_put_with_timeout() failed"); + } + + void Host::put(int channel, Task* task, double timeout) + throw(MsgException, InvalidArgumentException) + { + // checks the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must be more or equal to zero)"); + + if(timeout < 0.0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must be more or equal to zero or equal to -1.0)"); + + + if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, nativeHost, channel , timeout)) + throw MsgException("MSG_task_put_with_timeout() failed"); + } + + void Host::putBounded(int channel, Task* task, double maxRate) + throw(MsgException, InvalidArgumentException) + { + // checks the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must be more or equal to zero)"); + + if(maxRate < 0.0 && maxRate != -1.0) + throw InvalidArgumentException("maxRate (must be more or equal to zero or equal to -1.0)"); + + if(MSG_OK != MSG_task_put_bounded(task->nativeTask, nativeHost, channel, maxRate)) + throw MsgException("MSG_task_put_bounded() failed"); + } + + void Host::send(Task* task) + throw(MsgException, BadAllocException) + { + MSG_error_t rv; + + char* alias = (char*)calloc(strlen(this->getName())+ strlen(Process::currentProcess().getName()) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); + + rv = MSG_task_send_with_timeout(task->nativeTask, alias, -1.0); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_with_timeout() failed"); + } + + void Host::send(const char* alias, Task* task) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + if(!alias) + throw InvalidArgumentException("alias (must not be NULL)"); + + if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias, -1.0)) + throw MsgException("MSG_task_send_with_timeout() failed"); + } + + void Host::send(Task* task, double timeout) + throw(InvalidArgumentException, BadAllocException, MsgException) + { + // check the parameters + if(timeout < 0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)"); + + MSG_error_t rv; + + char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); + + + rv = MSG_task_send_with_timeout(task->nativeTask, alias, timeout); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_with_timeout() failed"); + } + + void Host::send(const char* alias, Task* task, double timeout) + throw(InvalidArgumentException, MsgException) + { + // check the parameter + + if(!alias) + throw InvalidArgumentException("alias (must not be NULL)"); + + if(timeout < 0 && timeout != -1.0) + throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)"); + + if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias, timeout)) + throw MsgException("MSG_task_send_with_timeout() failed"); + } + + + void Host::sendBounded(Task* task, double maxRate) + throw(InvalidArgumentException, BadAllocException, MsgException) + { + if(maxRate < 0 && maxRate != -1.0) + throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)"); + + MSG_error_t rv; + + char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); + + rv = MSG_task_send_bounded(task->nativeTask, alias, maxRate); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_bounded() failed"); + } + + void Host::sendBounded(const char* alias, Task* task, double maxRate) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + if(!alias) + throw InvalidArgumentException("alias (must not be NULL)"); + + if(maxRate < 0 && maxRate != -1) + throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)"); + + if(MSG_OK != MSG_task_send_bounded(task->nativeTask, alias, maxRate)) + throw MsgException("MSG_task_send_bounded() failed"); + + } + } // namspace Msg +} // namespace SimGrid + diff --git a/src/cxx/Host.hpp b/src/cxx/Host.hpp index 02280975cf..c012513828 100644 --- a/src/cxx/Host.hpp +++ b/src/cxx/Host.hpp @@ -1,440 +1,440 @@ -/* - * Host.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_HOST_HPP -#define MSG_HOST_HPP - - -/*! \brief Host class declaration. - * - * An host instance represents a location (any possible place) where a process may run. - * Thus it is represented as a physical resource with computing capabilities, some - * mailboxes to enable running process to communicate with remote ones, and some private - * data that can be only accessed by local process. An instance of this class is always - * binded with the corresponding native host. All the native hosts are automaticaly created - * during the call of the static method Msg::createEnvironment(). This method takes as parameter - * the platform file which describes all elements of the platform (host, link, root..). - * You never need to create an host your self. - * - * The best way to get an host is to call the static method - * Host.getByName() which returns a reference. - * - * For example to get the instance of the host. If your platform - * file description contains an host named "Jacquelin" : - * - * \verbatim -using namespace SimGrid.Msg; - -Host jacquelin; - -try -{ - jacquelin = Host::getByName("Jacquelin"); -} -catch(HostNotFoundException e) -{ - cerr << e.toString(); -} -... -\endverbatim - * - */ - -#ifndef __cplusplus - #error Host.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -#include -#include -#include -#include -#include - - - -// namespace SimGrid::Msg -namespace SimGrid -{ - namespace Msg - { - class Task; - class Process; - - // Declaration of the class SimGrid::Msg::Host. - class SIMGRIDX_EXPORT Host // final class. - { - friend class Process; - friend class Task; - - // Desable the default constructor. - // The best way to get an host instance is to use the static method Host::getByName(). - - public : - - // Default constructor (desabled). - Host(); - - public: - - // Copy constructor (desabled). - Host(const Host& rHost); - - // Destructor (desable). - virtual ~Host(); - - // Operations - - /*! \brief Host::getByName() - returns an host by its name - * - * This static method returns a reference to the host instance associated - * with a native host of your platform. This is the best way to get a host. - * - * \param hostName The name of the host. - * - * \return If successful the method returns a reference to the instance - * associated with the native host having the name specified - * as parameter of your platform. Otherwise the method throws - * one of the exceptions detailed below. - * - * \exception [HostNotFoundException] if no host with the specified name - * was found. - * [InvalidArgumentException] if the hostName parameter is invalid (NULL). - * [BadAllocException] if there is not enough memory to allocate the host. - */ - static Host& getByName(const char* hostName) - throw(HostNotFoundException, NullPointerException, BadAllocException); - - /*! \brief Host::getNumber() - returns the number of the installed hosts. - * - * \return The number of hosts installed. - */ - static int getNumber(void); - - - /*! \brief Host::currentHost() - This static method returns the location on which the current - * process is executed. - * - * \return The host of the current process. - * - * \see Process::currentProcess(). - */ - static Host& currentHost(void); - - /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform. - * - * \param hosts A pointer to array of Host pointers that receives all the hosts of the platform. - * - * \param len A pointer to the length of the table of pointers. - * - * \return If successful the hosts table is filled and - * the parameter len is set with the number of hosts of the platform. - * Otherwise the method throw one of the exception described below. - * - * \exception [InvalidArgumentException] if the parameter hosts is invalid or - * if the parameter len is negative or - * less than the number of hosts installed - * on the current platform. - * [BadAllocException] If the method can't allocate memory to fill - * the table of hosts. - * - * - * \remark To get the number of hosts installed on your platform use the static method - * Host::getNumber(). - * - * \see Host::getNumber(). - * - *\verbatim - * // This example show how to use this method to get the list of hosts installed on your platform. - * - * using namespace SimGrid::Msg; - * using - * - * // (1) get the number of hosts. - * int number = Host::getNumber(); - * - * // (2) allocate the array that receives the list of hosts. - * HostPtr* ar = new HostPtr[number]; // HostPtr is defined as (typedef Host* HostPtr at the end of the - * // declaration of this class. - * - * // (3) call the method - * try - * { - * Host::all(&ar, &number); - * } - * catch(BadAllocException e) - * { - * cerr << e.toString() << endl; - * ... - * } - * catch(InvalidArgumentException e) - * { - * cerr << e.toString() << endl; - * .. - * } - * - * // (4) use the table of host (for example print all the name of all the hosts); - * - * for(int i = 0; i < number ; i++) - * cout << ar[i]->getName() << endl; - * - * ... - * - * // (5) release the allocate table - * - * delete[] ar; - * - */ - static void all(Host*** hosts /*in|out*/, int* len /*in|out*/) - throw(InvalidArgumentException, BadAllocException) ; - - /*! \brief Host::getName() - This method return the name of the Msg host object. - * - * \return The name of the host object. - */ - const char* getName(void) const; - - /*! \brief Host::setData() - Set the user data of an host object. - * - * \param data The user data to set. - */ - void setData(void* data); - - /*! \brief Host::getData() - Get the user data of a host object. - * - * \return The user data of the host object. - */ - void* getData(void) const; - - /*! \brief Host::hasData() - Test if an host object has some data. - * - * \return This method returns true if the host object has some user data. - * Otherwise the method returns false. - */ - bool hasData(void) const; - - /*! \brief Host::getRunningTaskNumber() - returns the number of tasks currently running on a host. - * - * \return The number of task currently running of the host object. - * - * \remark The external load is not taken in account. - */ - int getRunningTaskNumber(void) const; - - /*! \brief Host::getSpeed() - returns the speed of the processor of a host, - * regardless of the current load of the machine. - * - * \return The speed of the processor of the host in flops. - */ - double getSpeed(void) const; - - /*! \brief Host::isAvailable - tests if an host is availabled. - * - * \return Is the host is availabled the method returns - * 1. Otherwise the method returns 0. - */ - int isAvailable(void) const; - - /* ! \brief Host::put() - put a task on the given channel of a host . - * - * \param channel The channel where to put the task. - * \param rTask A refercence to the task object containing the native task to - * put on the channel specified by the parameter channel. - * - * \return If successful the task is puted on the specified channel. Otherwise - * the method throws one of the exceptions described below. - * - * \exception [MsgException] if an internal error occurs. - * [InvalidArgumentException] if the value of the channel specified as - * parameter is negative. - */ - void put(int channel, Task* task) - throw(MsgException, InvalidArgumentException); - - /* ! \brief Host::put() - put a task on the given channel of a host object (waiting at most timeout seconds). - * - * \param channel The channel where to put the task. - * \param rTask A refercence to the task object containing the native task to - * put on the channel specified by the parameter channel. - * \param timeout The timeout in seconds. - * - * \return If successful the task is puted on the specified channel. Otherwise - * the method throws one of the exceptions described below. - * - * \exception [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 To specify no timeout set the timeout value with -1.0. - */ - void put(int channel, Task* task, double timeout) - throw(MsgException, InvalidArgumentException); - - /* ! \brief Host::putBounded() - put a task on the given channel of a host object (capping the emission rate to maxrate). - * - * \param channel The channel where to put the task. - * \param rTask A refercence to the task object containing the native task to - * put on the channel specified by the parameter channel. - * \param maxRate The maximum rate. - * - * \return If successful the task is puted on the specified channel. Otherwise - * the method throws one of the exceptions described below. - * - * \exception [MsgException] if an internal error occurs. - * [InvalidArgumentException] if the value of the channel specified as - * parameter is negative or if the maxRate parameter value - * is less than zero and différent of -1.0. - * - * \remark To specify no rate set the maxRate parameter value with -1.0. - */ - void putBounded(int channel, Task* task, double maxRate) - throw(MsgException, InvalidArgumentException); - - /* ! brief Host::send() - sends the given task to mailbox identified by the default alias. - * - * \param rTask A reference to the task object containing the native msg task to send. - * - * \return If successful the task is sended to the default mailbox. Otherwise the - * method throws one of the exceptions described below. - * - * \exception [BadAllocException] if there is not enough memory to allocate - * the default alias variable. - * [MsgException] if an internal error occurs. - */ - void send(Task* task) - throw(MsgException, BadAllocException); - - /* ! brief Host::send() - sends the given task to mailbox identified by the specified alias parameter. - * - * \param rTask A reference to the task object containing the native msg task to send. - * \param alias The alias of the mailbox where to send the task. - * - * \return If successful the task is sended to the default mailbox. Otherwise the - * method throws one of the exceptions described below. - * - * \exception [InvalidArgumentException] if alias parameter is invalid (NULL). - * [BadAllocException] if there is not enough memory to allocate - * the default alias variable. - * [MsgException] if an internal error occurs. - */ - void send(const char* alias, Task* task) - throw(InvalidArgumentException, MsgException); - - /* ! brief Host::send() - sends the given task to mailbox identified by the default alias - * (waiting at most timeout seconds). - * - * \param rTask A reference to the task object containing the native msg task to send. - * \param timeout The timeout value to wait for. - * - * \return If successful the task is sended to the default mailbox. Otherwise the - * method throws one of the exceptions described below. - * - * \exception [BadAllocException] if there is not enough memory to allocate - * the default alias variable. - * [InvalidArgumentException] if the timeout value is negative and different of - * -1.0. - * [MsgException] if an internal error occurs. - * - * \remark To specify no timeout set the timeout value with -1.0 or use the previous - * version of this method. - * - */ - void send(Task* task, double timeout) - throw(InvalidArgumentException, BadAllocException, MsgException); - - /* ! brief Host::send() - sends the given task to mailbox identified by the parameter alias - * (waiting at most timeout seconds). - * - * \param alias The alias of the mailbox to send the task. - * \param rTask A reference to the task object containing the native msg task to send. - * \param timeout The timeout value to wait for. - * - * \return If successful the task is sended to the default mailbox. Otherwise the - * method throws one of the exceptions described below. - * - * \exception [InvalidArgumentException] if the timeout value is negative and different of - * -1.0 or if the alias parameter is invalid (NULL). - * [MsgException] if an internal error occurs. - * - * \remark To specify no timeout set the timeout value with -1.0 or use the previous - * version of this method. - * - */ - void send(const char* alias, Task* task, double timeout) - throw(InvalidArgumentException, MsgException); - - /* ! brief Host::sendBounded() - sends the given task to mailbox associated to the default alias - * (capping the emission rate to maxRate). - * - * \param rTask A reference to the task object containing the native msg task to send. - * \param maxRate The maximum rate value. - * - * \return If successful the task is sended to the default mailbox. Otherwise the - * method throws one of the exceptions described below. - * - * \exception [InvalidArgumentException] if the maximum rate value is negative and different of - * -1.0. - * [MsgException] if an internal error occurs. - * [BadAllocException] if there is not enough memory to allocate - * the default alias variable. - * - * \remark To specify no rate set its value with -1.0. - * - */ - void sendBounded(Task* task, double maxRate) - throw(InvalidArgumentException, BadAllocException, MsgException); - - /* ! brief Host::sendBounded() - sends the given task to mailbox identified by the parameter alias - * (capping the emission rate to maxRate). - * - * \param alias The alias of the mailbox where to send the task. - * \param rTask A reference to the task object containing the native msg task to send. - * \param maxRate The maximum rate value. - * - * \return If successful the task is sended to the default mailbox. Otherwise the - * method throws one of the exceptions described below. - * - * \exception [InvalidArgumentException] if the maximum rate value is negative and different of - * -1.0 or if the alias parameter is invalid (NULL). - * [MsgException] if an internal error occurs. - * - * \remark To specify no rate set its value with -1.0. - * - */ - void sendBounded(const char* alias, Task* task, double maxRate) - throw(InvalidArgumentException, MsgException); - - protected: - // Attributes. - - /** - * This attribute represents the msg native host object. - * It is set automaticatly during the call of the static - * method Host::getByName(). - * - * \see Host::getByName(). - */ - m_host_t nativeHost; - - private: - /** - * User host data. - */ - void* data; - }; - - typedef Host* HostPtr; - } // namespace Msg -} // namespace SimGrid - -#endif // !MSG_HOST_HPP +/* + * Host.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_HOST_HPP +#define MSG_HOST_HPP + + +/*! \brief Host class declaration. + * + * An host instance represents a location (any possible place) where a process may run. + * Thus it is represented as a physical resource with computing capabilities, some + * mailboxes to enable running process to communicate with remote ones, and some private + * data that can be only accessed by local process. An instance of this class is always + * binded with the corresponding native host. All the native hosts are automaticaly created + * during the call of the static method Msg::createEnvironment(). This method takes as parameter + * the platform file which describes all elements of the platform (host, link, root..). + * You never need to create an host your self. + * + * The best way to get an host is to call the static method + * Host.getByName() which returns a reference. + * + * For example to get the instance of the host. If your platform + * file description contains an host named "Jacquelin" : + * + * \verbatim +using namespace SimGrid.Msg; + +Host jacquelin; + +try +{ + jacquelin = Host::getByName("Jacquelin"); +} +catch(HostNotFoundException e) +{ + cerr << e.toString(); +} +... +\endverbatim + * + */ + +#ifndef __cplusplus + #error Host.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +#include +#include +#include +#include +#include + + + +// namespace SimGrid::Msg +namespace SimGrid +{ + namespace Msg + { + class Task; + class Process; + + // Declaration of the class SimGrid::Msg::Host. + class SIMGRIDX_EXPORT Host // final class. + { + friend class Process; + friend class Task; + + // Desable the default constructor. + // The best way to get an host instance is to use the static method Host::getByName(). + + public : + + // Default constructor (desabled). + Host(); + + public: + + // Copy constructor (desabled). + Host(const Host& rHost); + + // Destructor (desable). + virtual ~Host(); + + // Operations + + /*! \brief Host::getByName() - returns an host by its name + * + * This static method returns a reference to the host instance associated + * with a native host of your platform. This is the best way to get a host. + * + * \param hostName The name of the host. + * + * \return If successful the method returns a reference to the instance + * associated with the native host having the name specified + * as parameter of your platform. Otherwise the method throws + * one of the exceptions detailed below. + * + * \exception [HostNotFoundException] if no host with the specified name + * was found. + * [InvalidArgumentException] if the hostName parameter is invalid (NULL). + * [BadAllocException] if there is not enough memory to allocate the host. + */ + static Host& getByName(const char* hostName) + throw(HostNotFoundException, NullPointerException, BadAllocException); + + /*! \brief Host::getNumber() - returns the number of the installed hosts. + * + * \return The number of hosts installed. + */ + static int getNumber(void); + + + /*! \brief Host::currentHost() - This static method returns the location on which the current + * process is executed. + * + * \return The host of the current process. + * + * \see Process::currentProcess(). + */ + static Host& currentHost(void); + + /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform. + * + * \param hosts A pointer to array of Host pointers that receives all the hosts of the platform. + * + * \param len A pointer to the length of the table of pointers. + * + * \return If successful the hosts table is filled and + * the parameter len is set with the number of hosts of the platform. + * Otherwise the method throw one of the exception described below. + * + * \exception [InvalidArgumentException] if the parameter hosts is invalid or + * if the parameter len is negative or + * less than the number of hosts installed + * on the current platform. + * [BadAllocException] If the method can't allocate memory to fill + * the table of hosts. + * + * + * \remark To get the number of hosts installed on your platform use the static method + * Host::getNumber(). + * + * \see Host::getNumber(). + * + *\verbatim + * // This example show how to use this method to get the list of hosts installed on your platform. + * + * using namespace SimGrid::Msg; + * using + * + * // (1) get the number of hosts. + * int number = Host::getNumber(); + * + * // (2) allocate the array that receives the list of hosts. + * HostPtr* ar = new HostPtr[number]; // HostPtr is defined as (typedef Host* HostPtr at the end of the + * // declaration of this class. + * + * // (3) call the method + * try + * { + * Host::all(&ar, &number); + * } + * catch(BadAllocException e) + * { + * cerr << e.toString() << endl; + * ... + * } + * catch(InvalidArgumentException e) + * { + * cerr << e.toString() << endl; + * .. + * } + * + * // (4) use the table of host (for example print all the name of all the hosts); + * + * for(int i = 0; i < number ; i++) + * cout << ar[i]->getName() << endl; + * + * ... + * + * // (5) release the allocate table + * + * delete[] ar; + * + */ + static void all(Host*** hosts /*in|out*/, int* len /*in|out*/) + throw(InvalidArgumentException, BadAllocException) ; + + /*! \brief Host::getName() - This method return the name of the Msg host object. + * + * \return The name of the host object. + */ + const char* getName(void) const; + + /*! \brief Host::setData() - Set the user data of an host object. + * + * \param data The user data to set. + */ + void setData(void* data); + + /*! \brief Host::getData() - Get the user data of a host object. + * + * \return The user data of the host object. + */ + void* getData(void) const; + + /*! \brief Host::hasData() - Test if an host object has some data. + * + * \return This method returns true if the host object has some user data. + * Otherwise the method returns false. + */ + bool hasData(void) const; + + /*! \brief Host::getRunningTaskNumber() - returns the number of tasks currently running on a host. + * + * \return The number of task currently running of the host object. + * + * \remark The external load is not taken in account. + */ + int getRunningTaskNumber(void) const; + + /*! \brief Host::getSpeed() - returns the speed of the processor of a host, + * regardless of the current load of the machine. + * + * \return The speed of the processor of the host in flops. + */ + double getSpeed(void) const; + + /*! \brief Host::isAvailable - tests if an host is availabled. + * + * \return Is the host is availabled the method returns + * 1. Otherwise the method returns 0. + */ + int isAvailable(void) const; + + /* ! \brief Host::put() - put a task on the given channel of a host . + * + * \param channel The channel where to put the task. + * \param rTask A refercence to the task object containing the native task to + * put on the channel specified by the parameter channel. + * + * \return If successful the task is puted on the specified channel. Otherwise + * the method throws one of the exceptions described below. + * + * \exception [MsgException] if an internal error occurs. + * [InvalidArgumentException] if the value of the channel specified as + * parameter is negative. + */ + void put(int channel, Task* task) + throw(MsgException, InvalidArgumentException); + + /* ! \brief Host::put() - put a task on the given channel of a host object (waiting at most timeout seconds). + * + * \param channel The channel where to put the task. + * \param rTask A refercence to the task object containing the native task to + * put on the channel specified by the parameter channel. + * \param timeout The timeout in seconds. + * + * \return If successful the task is puted on the specified channel. Otherwise + * the method throws one of the exceptions described below. + * + * \exception [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 To specify no timeout set the timeout value with -1.0. + */ + void put(int channel, Task* task, double timeout) + throw(MsgException, InvalidArgumentException); + + /* ! \brief Host::putBounded() - put a task on the given channel of a host object (capping the emission rate to maxrate). + * + * \param channel The channel where to put the task. + * \param rTask A refercence to the task object containing the native task to + * put on the channel specified by the parameter channel. + * \param maxRate The maximum rate. + * + * \return If successful the task is puted on the specified channel. Otherwise + * the method throws one of the exceptions described below. + * + * \exception [MsgException] if an internal error occurs. + * [InvalidArgumentException] if the value of the channel specified as + * parameter is negative or if the maxRate parameter value + * is less than zero and différent of -1.0. + * + * \remark To specify no rate set the maxRate parameter value with -1.0. + */ + void putBounded(int channel, Task* task, double maxRate) + throw(MsgException, InvalidArgumentException); + + /* ! brief Host::send() - sends the given task to mailbox identified by the default alias. + * + * \param rTask A reference to the task object containing the native msg task to send. + * + * \return If successful the task is sended to the default mailbox. Otherwise the + * method throws one of the exceptions described below. + * + * \exception [BadAllocException] if there is not enough memory to allocate + * the default alias variable. + * [MsgException] if an internal error occurs. + */ + void send(Task* task) + throw(MsgException, BadAllocException); + + /* ! brief Host::send() - sends the given task to mailbox identified by the specified alias parameter. + * + * \param rTask A reference to the task object containing the native msg task to send. + * \param alias The alias of the mailbox where to send the task. + * + * \return If successful the task is sended to the default mailbox. Otherwise the + * method throws one of the exceptions described below. + * + * \exception [InvalidArgumentException] if alias parameter is invalid (NULL). + * [BadAllocException] if there is not enough memory to allocate + * the default alias variable. + * [MsgException] if an internal error occurs. + */ + void send(const char* alias, Task* task) + throw(InvalidArgumentException, MsgException); + + /* ! brief Host::send() - sends the given task to mailbox identified by the default alias + * (waiting at most timeout seconds). + * + * \param rTask A reference to the task object containing the native msg task to send. + * \param timeout The timeout value to wait for. + * + * \return If successful the task is sended to the default mailbox. Otherwise the + * method throws one of the exceptions described below. + * + * \exception [BadAllocException] if there is not enough memory to allocate + * the default alias variable. + * [InvalidArgumentException] if the timeout value is negative and different of + * -1.0. + * [MsgException] if an internal error occurs. + * + * \remark To specify no timeout set the timeout value with -1.0 or use the previous + * version of this method. + * + */ + void send(Task* task, double timeout) + throw(InvalidArgumentException, BadAllocException, MsgException); + + /* ! brief Host::send() - sends the given task to mailbox identified by the parameter alias + * (waiting at most timeout seconds). + * + * \param alias The alias of the mailbox to send the task. + * \param rTask A reference to the task object containing the native msg task to send. + * \param timeout The timeout value to wait for. + * + * \return If successful the task is sended to the default mailbox. Otherwise the + * method throws one of the exceptions described below. + * + * \exception [InvalidArgumentException] if the timeout value is negative and different of + * -1.0 or if the alias parameter is invalid (NULL). + * [MsgException] if an internal error occurs. + * + * \remark To specify no timeout set the timeout value with -1.0 or use the previous + * version of this method. + * + */ + void send(const char* alias, Task* task, double timeout) + throw(InvalidArgumentException, MsgException); + + /* ! brief Host::sendBounded() - sends the given task to mailbox associated to the default alias + * (capping the emission rate to maxRate). + * + * \param rTask A reference to the task object containing the native msg task to send. + * \param maxRate The maximum rate value. + * + * \return If successful the task is sended to the default mailbox. Otherwise the + * method throws one of the exceptions described below. + * + * \exception [InvalidArgumentException] if the maximum rate value is negative and different of + * -1.0. + * [MsgException] if an internal error occurs. + * [BadAllocException] if there is not enough memory to allocate + * the default alias variable. + * + * \remark To specify no rate set its value with -1.0. + * + */ + void sendBounded(Task* task, double maxRate) + throw(InvalidArgumentException, BadAllocException, MsgException); + + /* ! brief Host::sendBounded() - sends the given task to mailbox identified by the parameter alias + * (capping the emission rate to maxRate). + * + * \param alias The alias of the mailbox where to send the task. + * \param rTask A reference to the task object containing the native msg task to send. + * \param maxRate The maximum rate value. + * + * \return If successful the task is sended to the default mailbox. Otherwise the + * method throws one of the exceptions described below. + * + * \exception [InvalidArgumentException] if the maximum rate value is negative and different of + * -1.0 or if the alias parameter is invalid (NULL). + * [MsgException] if an internal error occurs. + * + * \remark To specify no rate set its value with -1.0. + * + */ + void sendBounded(const char* alias, Task* task, double maxRate) + throw(InvalidArgumentException, MsgException); + + protected: + // Attributes. + + /** + * This attribute represents the msg native host object. + * It is set automaticatly during the call of the static + * method Host::getByName(). + * + * \see Host::getByName(). + */ + m_host_t nativeHost; + + private: + /** + * User host data. + */ + void* data; + }; + + typedef Host* HostPtr; + } // namespace Msg +} // namespace SimGrid + +#endif // !MSG_HOST_HPP diff --git a/src/cxx/HostNotFoundException.cxx b/src/cxx/HostNotFoundException.cxx index c2b9211ada..213ab12f40 100644 --- a/src/cxx/HostNotFoundException.cxx +++ b/src/cxx/HostNotFoundException.cxx @@ -1,75 +1,75 @@ -/* - * HostNotFoundException.cxx - * - * 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. - * - */ - - /* HostNotFoundException member functions implementation. - */ - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - HostNotFoundException::HostNotFoundException() - { - this->reason = (char*) calloc(strlen("Host not found : unknown") + 1, sizeof(char)); - strcpy(this->reason, "Host not found : unknown"); - } - - - HostNotFoundException::HostNotFoundException(const HostNotFoundException& rHostNotFoundException) - { - const char* reason = rHostNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - - HostNotFoundException::HostNotFoundException(const char* name) - { - this->reason = (char*) calloc(strlen("Host not found : ") + strlen(name) + 1, sizeof(char)); - sprintf(this->reason, "Host not found : %s", name); - } - - - HostNotFoundException::~HostNotFoundException() - { - if(this->reason) - free(this->reason); - } - - const char* HostNotFoundException::toString(void) const - { - return (const char*)(this->reason); - } - - - const HostNotFoundException& HostNotFoundException::operator = (const HostNotFoundException& rHostNotFoundException) - { - const char* reason = rHostNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * HostNotFoundException.cxx + * + * 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. + * + */ + + /* HostNotFoundException member functions implementation. + */ + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + HostNotFoundException::HostNotFoundException() + { + this->reason = (char*) calloc(strlen("Host not found : unknown") + 1, sizeof(char)); + strcpy(this->reason, "Host not found : unknown"); + } + + + HostNotFoundException::HostNotFoundException(const HostNotFoundException& rHostNotFoundException) + { + const char* reason = rHostNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + HostNotFoundException::HostNotFoundException(const char* name) + { + this->reason = (char*) calloc(strlen("Host not found : ") + strlen(name) + 1, sizeof(char)); + sprintf(this->reason, "Host not found : %s", name); + } + + + HostNotFoundException::~HostNotFoundException() + { + if(this->reason) + free(this->reason); + } + + const char* HostNotFoundException::toString(void) const + { + return (const char*)(this->reason); + } + + + const HostNotFoundException& HostNotFoundException::operator = (const HostNotFoundException& rHostNotFoundException) + { + const char* reason = rHostNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/HostNotFoundException.hpp b/src/cxx/HostNotFoundException.hpp index a810d04663..c8458ba421 100644 --- a/src/cxx/HostNotFoundException.hpp +++ b/src/cxx/HostNotFoundException.hpp @@ -1,70 +1,70 @@ -/* - * HostNotFoundException.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_HOSTNOTFOUNDEXCEPTION_HPP -#define MSG_HOSTNOTFOUNDEXCEPTION_HPP - -#ifndef __cplusplus - #error HostNotFoundException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT HostNotFoundException : public Exception - { - public: - - // Default constructor. - HostNotFoundException(); - - // Copy constructor. - HostNotFoundException(const HostNotFoundException& rHostNotFoundException); - - // This constructor takes the name of the host not found. - HostNotFoundException(const char* name); - - // Destructor. - virtual ~HostNotFoundException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Host not found `host name'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const HostNotFoundException& operator = (const HostNotFoundException& rHostNotFoundException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_HOSTNOTFOUNDEXCEPTION_HPP - - +/* + * HostNotFoundException.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_HOSTNOTFOUNDEXCEPTION_HPP +#define MSG_HOSTNOTFOUNDEXCEPTION_HPP + +#ifndef __cplusplus + #error HostNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT HostNotFoundException : public Exception + { + public: + + // Default constructor. + HostNotFoundException(); + + // Copy constructor. + HostNotFoundException(const HostNotFoundException& rHostNotFoundException); + + // This constructor takes the name of the host not found. + HostNotFoundException(const char* name); + + // Destructor. + virtual ~HostNotFoundException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Host not found `host name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const HostNotFoundException& operator = (const HostNotFoundException& rHostNotFoundException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_HOSTNOTFOUNDEXCEPTION_HPP + + diff --git a/src/cxx/InvalidArgumentException.cxx b/src/cxx/InvalidArgumentException.cxx index dc44244c37..c82d517d1e 100644 --- a/src/cxx/InvalidArgumentException.cxx +++ b/src/cxx/InvalidArgumentException.cxx @@ -1,76 +1,76 @@ -/* - * InvalidArgumentException.cxx - * - * 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. - * - */ - - /* InvalidArgumentException member functions implementation. - */ - - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - InvalidArgumentException::InvalidArgumentException() - { - this->reason = (char*) calloc(strlen("Invalid argument : unknown") + 1, sizeof(char)); - strcpy(this->reason, "Invalid argument : unknown"); - } - - - InvalidArgumentException::InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException) - { - const char* reason = rInvalidArgumentException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - - InvalidArgumentException::InvalidArgumentException(const char* name) - { - this->reason = (char*) calloc(strlen("Invalid argument : ") + strlen(name) + 1, sizeof(char)); - sprintf(this->reason, "Invalid argument : %s", name); - } - - - InvalidArgumentException::~InvalidArgumentException() - { - if(this->reason) - free(this->reason); - } - - const char* InvalidArgumentException::toString(void) const - { - return (const char*)(this->reason); - } - - - const InvalidArgumentException& InvalidArgumentException::operator = (const InvalidArgumentException& rInvalidArgumentException) - { - const char* reason = rInvalidArgumentException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * InvalidArgumentException.cxx + * + * 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. + * + */ + + /* InvalidArgumentException member functions implementation. + */ + + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + InvalidArgumentException::InvalidArgumentException() + { + this->reason = (char*) calloc(strlen("Invalid argument : unknown") + 1, sizeof(char)); + strcpy(this->reason, "Invalid argument : unknown"); + } + + + InvalidArgumentException::InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException) + { + const char* reason = rInvalidArgumentException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + InvalidArgumentException::InvalidArgumentException(const char* name) + { + this->reason = (char*) calloc(strlen("Invalid argument : ") + strlen(name) + 1, sizeof(char)); + sprintf(this->reason, "Invalid argument : %s", name); + } + + + InvalidArgumentException::~InvalidArgumentException() + { + if(this->reason) + free(this->reason); + } + + const char* InvalidArgumentException::toString(void) const + { + return (const char*)(this->reason); + } + + + const InvalidArgumentException& InvalidArgumentException::operator = (const InvalidArgumentException& rInvalidArgumentException) + { + const char* reason = rInvalidArgumentException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/InvalidArgumentException.hpp b/src/cxx/InvalidArgumentException.hpp index fc4b2011d6..5b779b57aa 100644 --- a/src/cxx/InvalidArgumentException.hpp +++ b/src/cxx/InvalidArgumentException.hpp @@ -1,69 +1,69 @@ -/* - * InvalidArgumentException.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_INVALIDARGUMENTEXCEPTION_HPP -#define MSG_INVALIDARGUMENTEXCEPTION_HPP - -#ifndef __cplusplus - #error InvalidArgumentException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT InvalidArgumentException : public Exception - { - public: - - // Default constructor. - InvalidArgumentException(); - - // Copy constructor. - InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException); - - // This constructor takes the name of the invalid argument. - InvalidArgumentException(const char* name); - - // Destructor. - virtual ~InvalidArgumentException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Invalid argument `argument name'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const InvalidArgumentException& operator = (const InvalidArgumentException& rInvalidArgumentException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP - +/* + * InvalidArgumentException.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_INVALIDARGUMENTEXCEPTION_HPP +#define MSG_INVALIDARGUMENTEXCEPTION_HPP + +#ifndef __cplusplus + #error InvalidArgumentException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT InvalidArgumentException : public Exception + { + public: + + // Default constructor. + InvalidArgumentException(); + + // Copy constructor. + InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException); + + // This constructor takes the name of the invalid argument. + InvalidArgumentException(const char* name); + + // Destructor. + virtual ~InvalidArgumentException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Invalid argument `argument name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const InvalidArgumentException& operator = (const InvalidArgumentException& rInvalidArgumentException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP + diff --git a/src/cxx/LogicException.cxx b/src/cxx/LogicException.cxx index e1594f2ce9..b911229cdf 100644 --- a/src/cxx/LogicException.cxx +++ b/src/cxx/LogicException.cxx @@ -1,75 +1,75 @@ -/* - * LogicException.cxx - * - * 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. - * - */ - - /* LogicException member functions implementation. - */ - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - LogicException::LogicException() - { - this->reason = (char*) calloc(strlen("Logic exception : no detail") + 1, sizeof(char)); - strcpy(this->reason, "Logic exception : no detail"); - } - - - LogicException::LogicException(const LogicException& rLogicException) - { - const char* reason = rLogicException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - - LogicException::LogicException(const char* detail) - { - this->reason = (char*) calloc(strlen("Logic exception : ") + strlen(detail) + 1, sizeof(char)); - sprintf(this->reason, "Logic exception : %s", detail); - } - - - LogicException::~LogicException() - { - if(this->reason) - free(this->reason); - } - - const char* LogicException::toString(void) const - { - return (const char*)(this->reason); - } - - - const LogicException& LogicException::operator = (const LogicException& rLogicException) - { - const char* reason = rLogicException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * LogicException.cxx + * + * 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. + * + */ + + /* LogicException member functions implementation. + */ + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + LogicException::LogicException() + { + this->reason = (char*) calloc(strlen("Logic exception : no detail") + 1, sizeof(char)); + strcpy(this->reason, "Logic exception : no detail"); + } + + + LogicException::LogicException(const LogicException& rLogicException) + { + const char* reason = rLogicException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + LogicException::LogicException(const char* detail) + { + this->reason = (char*) calloc(strlen("Logic exception : ") + strlen(detail) + 1, sizeof(char)); + sprintf(this->reason, "Logic exception : %s", detail); + } + + + LogicException::~LogicException() + { + if(this->reason) + free(this->reason); + } + + const char* LogicException::toString(void) const + { + return (const char*)(this->reason); + } + + + const LogicException& LogicException::operator = (const LogicException& rLogicException) + { + const char* reason = rLogicException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/LogicException.hpp b/src/cxx/LogicException.hpp index a3574391f3..fb2ffd9c20 100644 --- a/src/cxx/LogicException.hpp +++ b/src/cxx/LogicException.hpp @@ -1,70 +1,70 @@ -/* - * LogicException.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_LOGICEXCEPTION_HPP -#define MSG_LOGICEXCEPTION_HPP - -#ifndef __cplusplus - #error LogicException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT LogicException : public Exception - { - public: - - // Default constructor. - LogicException(); - - // Copy constructor. - LogicException(const LogicException& rLogicException); - - // This constructor takes the detail of the logic exception. - LogicException(const char* detail); - - // Destructor. - virtual ~LogicException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Logic exception `detail'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const LogicException& operator = (const LogicException& rLogicException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP - - +/* + * LogicException.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_LOGICEXCEPTION_HPP +#define MSG_LOGICEXCEPTION_HPP + +#ifndef __cplusplus + #error LogicException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT LogicException : public Exception + { + public: + + // Default constructor. + LogicException(); + + // Copy constructor. + LogicException(const LogicException& rLogicException); + + // This constructor takes the detail of the logic exception. + LogicException(const char* detail); + + // Destructor. + virtual ~LogicException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Logic exception `detail'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const LogicException& operator = (const LogicException& rLogicException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP + + diff --git a/src/cxx/Msg.cxx b/src/cxx/Msg.cxx index daac88e4b1..eb23f4f7f4 100644 --- a/src/cxx/Msg.cxx +++ b/src/cxx/Msg.cxx @@ -1,152 +1,152 @@ - -/* - * Msg.cxx - * - * 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. - * - */ - - /* Msg functions implementation. - */ - - -#include -#include -#include - - -#include -#include - -#include -using std::cout; -using std::endl; -using std::streamsize; - -#include -using std::setprecision; -using std::setw; - - - -namespace SimGrid -{ - namespace Msg - { - #define SIMGRIDX_DEFAULT_CHANNEL_NUMBER ((int)10) - - void init(int argc, char** argv) - { - MSG_global_init(&argc,argv); - - if(getMaxChannelNumber() == 0) - setMaxChannelNumber(SIMGRIDX_DEFAULT_CHANNEL_NUMBER); - } - - void finalize(void) - throw (MsgException) - { - if(MSG_OK != MSG_clean()) - throw MsgException("MSG_clean() failed"); - - } - - void info(const StringHelper& s) - { - StringHelper clock; - - cout << "["; - cout << Host::currentHost().getName(); - cout << ":"; - cout << Process::currentProcess().getName(); - cout << ":("; - cout << Process::currentProcess().getPID(); - cout << ") " ; - cout << clock.append(getClock(), "%07lf"); - cout << "] [cxx4msg/INFO] "; - cout << s; - cout << endl; - } - - void info(const char* s) - { - StringHelper clock; - - cout << "["; - cout << Host::currentHost().getName(); - cout << ":"; - cout << Process::currentProcess().getName(); - cout << ":("; - cout << Process::currentProcess().getPID(); - cout << ") " ; - cout << clock.append(getClock(), "%07lf"); - cout << "] [cxx4msg/INFO] "; - cout << s; - cout << endl; - } - - void error(const StringHelper& s) - { - StringHelper clock; - - cout << "["; - cout << Host::currentHost().getName(); - cout << ":"; - cout << Process::currentProcess().getName(); - cout << ":("; - cout << Process::currentProcess().getPID(); - cout << ") " ; - cout << clock.append(getClock(), "%07lf"); - cout << "] [cxx4msg/ERROR] "; - cout << s; - cout << endl; - } - - void error(const char* s) - { - StringHelper clock; - - cout << "["; - cout << Host::currentHost().getName(); - cout << ":"; - cout << Process::currentProcess().getName(); - cout << ":("; - cout << Process::currentProcess().getPID(); - cout << ") " ; - cout << clock.append(getClock(), "%07lf"); - cout << "] [cxx4msg/ERROR] "; - cout << s; - cout << endl; - } - - double getClock(void) - { - return MSG_get_clock(); - } - - void setMaxChannelNumber(int number) - throw(InvalidArgumentException, LogicException) - { - if(msg_global->max_channel > 0) - throw LogicException("Max channel number already setted"); - - if(number < 0) - throw InvalidArgumentException("number"); - - msg_global->max_channel = number; - } - - int getMaxChannelNumber(void) - { - return msg_global->max_channel; - } - - } // namespace Msg - -} // namespace SimGrid - + +/* + * Msg.cxx + * + * 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. + * + */ + + /* Msg functions implementation. + */ + + +#include +#include +#include + + +#include +#include + +#include +using std::cout; +using std::endl; +using std::streamsize; + +#include +using std::setprecision; +using std::setw; + + + +namespace SimGrid +{ + namespace Msg + { + #define SIMGRIDX_DEFAULT_CHANNEL_NUMBER ((int)10) + + void init(int argc, char** argv) + { + MSG_global_init(&argc,argv); + + if(getMaxChannelNumber() == 0) + setMaxChannelNumber(SIMGRIDX_DEFAULT_CHANNEL_NUMBER); + } + + void finalize(void) + throw (MsgException) + { + if(MSG_OK != MSG_clean()) + throw MsgException("MSG_clean() failed"); + + } + + void info(const StringHelper& s) + { + StringHelper clock; + + cout << "["; + cout << Host::currentHost().getName(); + cout << ":"; + cout << Process::currentProcess().getName(); + cout << ":("; + cout << Process::currentProcess().getPID(); + cout << ") " ; + cout << clock.append(getClock(), "%07lf"); + cout << "] [cxx4msg/INFO] "; + cout << s; + cout << endl; + } + + void info(const char* s) + { + StringHelper clock; + + cout << "["; + cout << Host::currentHost().getName(); + cout << ":"; + cout << Process::currentProcess().getName(); + cout << ":("; + cout << Process::currentProcess().getPID(); + cout << ") " ; + cout << clock.append(getClock(), "%07lf"); + cout << "] [cxx4msg/INFO] "; + cout << s; + cout << endl; + } + + void error(const StringHelper& s) + { + StringHelper clock; + + cout << "["; + cout << Host::currentHost().getName(); + cout << ":"; + cout << Process::currentProcess().getName(); + cout << ":("; + cout << Process::currentProcess().getPID(); + cout << ") " ; + cout << clock.append(getClock(), "%07lf"); + cout << "] [cxx4msg/ERROR] "; + cout << s; + cout << endl; + } + + void error(const char* s) + { + StringHelper clock; + + cout << "["; + cout << Host::currentHost().getName(); + cout << ":"; + cout << Process::currentProcess().getName(); + cout << ":("; + cout << Process::currentProcess().getPID(); + cout << ") " ; + cout << clock.append(getClock(), "%07lf"); + cout << "] [cxx4msg/ERROR] "; + cout << s; + cout << endl; + } + + double getClock(void) + { + return MSG_get_clock(); + } + + void setMaxChannelNumber(int number) + throw(InvalidArgumentException, LogicException) + { + if(msg_global->max_channel > 0) + throw LogicException("Max channel number already setted"); + + if(number < 0) + throw InvalidArgumentException("number"); + + msg_global->max_channel = number; + } + + int getMaxChannelNumber(void) + { + return msg_global->max_channel; + } + + } // namespace Msg + +} // namespace SimGrid + diff --git a/src/cxx/Msg.hpp b/src/cxx/Msg.hpp index 048e38c7eb..95095fb162 100644 --- a/src/cxx/Msg.hpp +++ b/src/cxx/Msg.hpp @@ -1,80 +1,80 @@ -/* - * Msg.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_HPP -#define MSG_HPP - -// Compilation C++ recquise -#ifndef __cplusplus - #error Msg.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include -#include -#include - -#include - - -namespace SimGrid -{ - namespace Msg - { - class MsgException; - class InvalidArgumentException; - class LogicException; - - /*! \brief init() - Initialize MSG (This function must be called at the begining of each simulation). - * - * \param argv A list of arguments. - * \param argc The number of arguments of the list. - */ - SIMGRIDX_EXPORT void init(int argc, char** argv); - - /*! \brief finalize() - Finalize MSG (This function must be called at the end of each simulation). - * - * \exception If this function fails, it throws a exception describing the cause of the failure. - */ - SIMGRIDX_EXPORT void finalize(void) - throw (MsgException); - - /*! \brief info() - Display information (using xbt log format). - * - * \param s The information to display. - */ - SIMGRIDX_EXPORT void info(const StringHelper& s); - - SIMGRIDX_EXPORT void info(const char* s); - - SIMGRIDX_EXPORT void error(const StringHelper& s); - - SIMGRIDX_EXPORT void error(const char* s); - - - /*! \brief getClock() - Retrieve the simulation time - * - * \return The current simulation time. - */ - SIMGRIDX_EXPORT double getClock(void); - - - SIMGRIDX_EXPORT void setMaxChannelNumber(int number) - throw(InvalidArgumentException, LogicException); - - SIMGRIDX_EXPORT int getMaxChannelNumber(void); - - } // namespace Msg -} // namespace SimGrid - -#endif // !MSG_HPP +/* + * Msg.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_HPP +#define MSG_HPP + +// Compilation C++ recquise +#ifndef __cplusplus + #error Msg.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +#include +#include + +#include + + +namespace SimGrid +{ + namespace Msg + { + class MsgException; + class InvalidArgumentException; + class LogicException; + + /*! \brief init() - Initialize MSG (This function must be called at the begining of each simulation). + * + * \param argv A list of arguments. + * \param argc The number of arguments of the list. + */ + SIMGRIDX_EXPORT void init(int argc, char** argv); + + /*! \brief finalize() - Finalize MSG (This function must be called at the end of each simulation). + * + * \exception If this function fails, it throws a exception describing the cause of the failure. + */ + SIMGRIDX_EXPORT void finalize(void) + throw (MsgException); + + /*! \brief info() - Display information (using xbt log format). + * + * \param s The information to display. + */ + SIMGRIDX_EXPORT void info(const StringHelper& s); + + SIMGRIDX_EXPORT void info(const char* s); + + SIMGRIDX_EXPORT void error(const StringHelper& s); + + SIMGRIDX_EXPORT void error(const char* s); + + + /*! \brief getClock() - Retrieve the simulation time + * + * \return The current simulation time. + */ + SIMGRIDX_EXPORT double getClock(void); + + + SIMGRIDX_EXPORT void setMaxChannelNumber(int number) + throw(InvalidArgumentException, LogicException); + + SIMGRIDX_EXPORT int getMaxChannelNumber(void); + + } // namespace Msg +} // namespace SimGrid + +#endif // !MSG_HPP diff --git a/src/cxx/MsgException.cxx b/src/cxx/MsgException.cxx index 891588feea..25c1ab2644 100644 --- a/src/cxx/MsgException.cxx +++ b/src/cxx/MsgException.cxx @@ -1,74 +1,74 @@ -/* - * MsgException.cxx - * - * 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. - * - */ - - /* MsgException member functions implementation. - */ - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - MsgException::MsgException() - { - this->reason = (char*) calloc(strlen("Internal exception : unknown reason") + 1, sizeof(char)); - strcpy(this->reason, "Internal exception : unknown reason"); - } - - - MsgException::MsgException(const MsgException& rMsgException) - { - const char* reason = rMsgException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - MsgException::MsgException(const char* reason) - { - this->reason = (char*) calloc(strlen("Internal exception : ") + strlen(reason) + 1, sizeof(char)); - sprintf(this->reason, "Invalid exception : %s", reason); - } - - - MsgException::~MsgException() - { - if(this->reason) - free(this->reason); - } - - const char* MsgException::toString(void) const - { - return (const char*)(this->reason); - } - - - const MsgException& MsgException::operator = (const MsgException& rMsgException) - { - const char* reason = rMsgException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * MsgException.cxx + * + * 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. + * + */ + + /* MsgException member functions implementation. + */ + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + MsgException::MsgException() + { + this->reason = (char*) calloc(strlen("Internal exception : unknown reason") + 1, sizeof(char)); + strcpy(this->reason, "Internal exception : unknown reason"); + } + + + MsgException::MsgException(const MsgException& rMsgException) + { + const char* reason = rMsgException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + MsgException::MsgException(const char* reason) + { + this->reason = (char*) calloc(strlen("Internal exception : ") + strlen(reason) + 1, sizeof(char)); + sprintf(this->reason, "Invalid exception : %s", reason); + } + + + MsgException::~MsgException() + { + if(this->reason) + free(this->reason); + } + + const char* MsgException::toString(void) const + { + return (const char*)(this->reason); + } + + + const MsgException& MsgException::operator = (const MsgException& rMsgException) + { + const char* reason = rMsgException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/MsgException.hpp b/src/cxx/MsgException.hpp index 7d978f33dc..b39fc12dd5 100644 --- a/src/cxx/MsgException.hpp +++ b/src/cxx/MsgException.hpp @@ -1,65 +1,65 @@ -/* - * MsgException.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_MSGEXCEPTION_HPP -#define MSG_MSGEXCEPTION_HPP - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT MsgException : public Exception - { - public: - - // Default constructor. - MsgException(); - - // Copy constructor. - MsgException(const MsgException& rMsgException); - - // This constructor takes the reason of the exception. - MsgException(const char* reason); - - // Destructor. - virtual ~MsgException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Internal exception `reason'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const MsgException& operator = (const MsgException& rMsgException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_MSGEXCEPTION_HPP - +/* + * MsgException.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_MSGEXCEPTION_HPP +#define MSG_MSGEXCEPTION_HPP + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT MsgException : public Exception + { + public: + + // Default constructor. + MsgException(); + + // Copy constructor. + MsgException(const MsgException& rMsgException); + + // This constructor takes the reason of the exception. + MsgException(const char* reason); + + // Destructor. + virtual ~MsgException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Internal exception `reason'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const MsgException& operator = (const MsgException& rMsgException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_MSGEXCEPTION_HPP + diff --git a/src/cxx/NullPointerException.cxx b/src/cxx/NullPointerException.cxx index 79aac802b6..df42ea3fa8 100644 --- a/src/cxx/NullPointerException.cxx +++ b/src/cxx/NullPointerException.cxx @@ -1,75 +1,75 @@ -/* - * NullPointerException.cxx - * - * 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. - * - */ - - /* NullPointerException member functions implementation. - */ - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - NullPointerException::NullPointerException() - { - this->reason = (char*) calloc(strlen("Null pointer : unknown") + 1, sizeof(char)); - strcpy(this->reason, "Null pointer : unknown"); - } - - - NullPointerException::NullPointerException(const NullPointerException& rNullPointerException) - { - const char* reason = rNullPointerException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - - NullPointerException::NullPointerException(const char* name) - { - this->reason = (char*) calloc(strlen("Null pointer : ") + strlen(name) + 1, sizeof(char)); - sprintf(this->reason, "Null pointer : %s", name); - } - - - NullPointerException::~NullPointerException() - { - if(this->reason) - free(this->reason); - } - - const char* NullPointerException::toString(void) const - { - return (const char*)(this->reason); - } - - - const NullPointerException& NullPointerException::operator = (const NullPointerException& rNullPointerException) - { - const char* reason = rNullPointerException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * NullPointerException.cxx + * + * 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. + * + */ + + /* NullPointerException member functions implementation. + */ + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + NullPointerException::NullPointerException() + { + this->reason = (char*) calloc(strlen("Null pointer : unknown") + 1, sizeof(char)); + strcpy(this->reason, "Null pointer : unknown"); + } + + + NullPointerException::NullPointerException(const NullPointerException& rNullPointerException) + { + const char* reason = rNullPointerException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + NullPointerException::NullPointerException(const char* name) + { + this->reason = (char*) calloc(strlen("Null pointer : ") + strlen(name) + 1, sizeof(char)); + sprintf(this->reason, "Null pointer : %s", name); + } + + + NullPointerException::~NullPointerException() + { + if(this->reason) + free(this->reason); + } + + const char* NullPointerException::toString(void) const + { + return (const char*)(this->reason); + } + + + const NullPointerException& NullPointerException::operator = (const NullPointerException& rNullPointerException) + { + const char* reason = rNullPointerException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/NullPointerException.hpp b/src/cxx/NullPointerException.hpp index 659e3adc9d..d23f8c68af 100644 --- a/src/cxx/NullPointerException.hpp +++ b/src/cxx/NullPointerException.hpp @@ -1,69 +1,69 @@ -/* - * NullPointerException.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_NULLPOINTEREXCEPTION_HPP -#define MSG_NULLPOINTEREXCEPTION_HPP - -#ifndef __cplusplus - #error NullPointerException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT NullPointerException : public Exception - { - public: - - // Default constructor. - NullPointerException(); - - // Copy constructor. - NullPointerException(const NullPointerException& rNullPointerException); - - // This constructor takes the name of the invalid argument. - NullPointerException(const char* name); - - // Destructor. - virtual ~NullPointerException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Null pointer `pointer name'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const NullPointerException& operator = (const NullPointerException& rNullPointerException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_NULLPOINTEREXCEPTION_HPP - +/* + * NullPointerException.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_NULLPOINTEREXCEPTION_HPP +#define MSG_NULLPOINTEREXCEPTION_HPP + +#ifndef __cplusplus + #error NullPointerException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT NullPointerException : public Exception + { + public: + + // Default constructor. + NullPointerException(); + + // Copy constructor. + NullPointerException(const NullPointerException& rNullPointerException); + + // This constructor takes the name of the invalid argument. + NullPointerException(const char* name); + + // Destructor. + virtual ~NullPointerException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Null pointer `pointer name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const NullPointerException& operator = (const NullPointerException& rNullPointerException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_NULLPOINTEREXCEPTION_HPP + diff --git a/src/cxx/Object.cxx b/src/cxx/Object.cxx index 5d91680c69..b7ca4b46c8 100644 --- a/src/cxx/Object.cxx +++ b/src/cxx/Object.cxx @@ -1,177 +1,179 @@ -/* - * Object.cxx - * - * 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. - * - */ - - /* SimGrid::Msg RTTI implementation. - */ - -#include -#include - -#include - - - - -DeclaringClasses* DeclaringClass::declaringClasses = NULL; - -namespace SimGrid -{ - namespace Msg - { - - // Generate static object constructor for class registration - void DeclareClass(Class* c) - { - MSG_DELCARING_CLASSES.lock(); - MSG_DELCARING_CLASSES.addHead(c); - MSG_DELCARING_CLASSES.unlock(); - } - } // namespace Msg -} // namespace SimGrid - -////////////////////////////////////////////////////////////////////////////// -// Implémentation des fonctions membre de la classe Class - -// true if the class is derived from base classe referenced -// by pBaseClass -bool Class::isDerivedFrom(const Class* baseClass) const -{ - const Class* cur = this; - - while(cur) - { - if(cur == baseClass) - return true; - - cur = cur->baseClass; - } - - return false; -} - -// Dynamic name lookup and creation -Class* Class::fromName(const char* name) -throw (ClassNotFoundException) -{ - Class* cur; - - MSG_DELCARING_CLASSES.lock(); - - for(cur = MSG_DELCARING_CLASSES.getHead(); cur; cur = cur->next) - { - if(!strcmp(name,cur->name)) - return cur; - - } - - MSG_DELCARING_CLASSES.unlock(); - throw ClassNotFoundException(name); -} - - -Object* Class::createObject(const char* name) -{ - Class* c = fromName(name); - return c->createObject(); -} - - -////////////////////////////////////////////////////////////////////////////// -// Object members implementation - -// Special runtime-class structure for Object (no base class) -const struct Class Object::classObject = -{ - "Object", // name - sizeof(Object), // typeSize - NULL, // baseClass - NULL, // next - NULL // declaringClass -}; - - -////////////////////////////////////////////////////////////////////////////// -// DeclaringClasses members implementation -// - -DeclaringClasses::DeclaringClasses() -{ - head = NULL; - count = 0; -} - - -// Ajoute une nouvelle classe en tête de liste -void DeclaringClasses::addHead(Class* c) -{ - if(NULL != head) - c->next = head; - - head = c; - count++; -} - -// Retourne la tête de liste et la retire de la liste -Class* DeclaringClasses::removeHead(void) -{ - Class* c = NULL; - - if(NULL != head) - { - c = head; - head = head->next; - count--; - } - - return c; -} - -// Retire la classe pClasse de la liste, mais ne la détruit pas -bool DeclaringClasses::remove(Class* c) -{ - if(NULL == head) - return false; - - bool success = false; - - if(head == c) - { - head = c->next; - count--; - success = true; - } - else - { - Class* cur = head; - - while((NULL != cur) && (cur->next!= c)) - cur = cur->next; - - if(NULL != cur) - { - cur->next = c->next; - count--; - success = true; - } - } - - return success; -} - -bool Object::isInstanceOf(const char* className) -{ - Class* c = Class::fromName(className); - - return this->getClass()->isDerivedFrom(c); -} - - +/* + * Object.cxx + * + * 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. + * + */ + + /* SimGrid::Msg RTTI implementation. + */ + +#include +#include + +#include + + + + +DeclaringClasses* DeclaringClass::declaringClasses = NULL; + +namespace SimGrid +{ + namespace Msg + { + + // Generate static object constructor for class registration + void DeclareClass(Class* c) + { + MSG_DELCARING_CLASSES.lock(); + MSG_DELCARING_CLASSES.addHead(c); + MSG_DELCARING_CLASSES.unlock(); + } + } // namespace Msg +} // namespace SimGrid + +////////////////////////////////////////////////////////////////////////////// +// Implémentation des fonctions membre de la classe Class + +// true if the class is derived from base classe referenced +// by pBaseClass +bool Class::isDerivedFrom(const Class* baseClass) const +{ + const Class* cur = this; + + while(cur) + { + if(cur == baseClass) + return true; + + cur = cur->baseClass; + } + + return false; +} + +// Dynamic name lookup and creation +Class* Class::fromName(const char* name) +throw (ClassNotFoundException) +{ + Class* cur; + + MSG_DELCARING_CLASSES.lock(); + + for(cur = MSG_DELCARING_CLASSES.getHead(); cur; cur = cur->next) + { + if(!strcmp(name,cur->name)) + { + MSG_DELCARING_CLASSES.unlock(); + return cur; + } + } + + MSG_DELCARING_CLASSES.unlock(); + throw ClassNotFoundException(name); +} + + +Object* Class::createObject(const char* name) +{ + Class* c = fromName(name); + return c->createObject(); +} + + +////////////////////////////////////////////////////////////////////////////// +// Object members implementation + +// Special runtime-class structure for Object (no base class) +const struct Class Object::classObject = +{ + "Object", // name + sizeof(Object), // typeSize + NULL, // baseClass + NULL, // next + NULL // declaringClass +}; + + +////////////////////////////////////////////////////////////////////////////// +// DeclaringClasses members implementation +// + +DeclaringClasses::DeclaringClasses() +{ + head = NULL; + count = 0; +} + + +// Ajoute une nouvelle classe en tête de liste +void DeclaringClasses::addHead(Class* c) +{ + if(NULL != head) + c->next = head; + + head = c; + count++; +} + +// Retourne la tête de liste et la retire de la liste +Class* DeclaringClasses::removeHead(void) +{ + Class* c = NULL; + + if(NULL != head) + { + c = head; + head = head->next; + count--; + } + + return c; +} + +// Retire la classe pClasse de la liste, mais ne la détruit pas +bool DeclaringClasses::remove(Class* c) +{ + if(NULL == head) + return false; + + bool success = false; + + if(head == c) + { + head = c->next; + count--; + success = true; + } + else + { + Class* cur = head; + + while((NULL != cur) && (cur->next!= c)) + cur = cur->next; + + if(NULL != cur) + { + cur->next = c->next; + count--; + success = true; + } + } + + return success; +} + +bool Object::isInstanceOf(const char* className) +{ + Class* c = Class::fromName(className); + + return this->getClass()->isDerivedFrom(c); +} + + diff --git a/src/cxx/Object.hpp b/src/cxx/Object.hpp index d44ff2b655..fc89d91fa1 100644 --- a/src/cxx/Object.hpp +++ b/src/cxx/Object.hpp @@ -1,299 +1,299 @@ -/* - * Object.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_OBJECT_H -#define MSG_OBJECT_H - -// Compilation C++ recquise -#ifndef __cplusplus - #error Object.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -#include - -namespace SimGrid -{ - namespace Msg - { - ////////////////////////////////////////////////////////////////////////////// - // Macros - - // Returns the runtime class of the class_name object. - #define MSG_GET_CLASS(class_name) \ - ((Class*)(&class_name::class##class_name)) - - // Declare the class class_name as dynamic - #define MSG_DECLARE_DYNAMIC(class_name) \ - public: \ - static Class class##class_name; \ - virtual Class* getClass() const; \ - static Object* createObject() \ - - // The runtime class implementation. - #define MSG_IMPLEMENT_CLASS(class_name, base_class_name, pfn,class_init) \ - Class class_name::class##class_name = { \ - #class_name, sizeof(class class_name),pfn, \ - MSG_GET_CLASS(base_class_name), NULL,class_init}; \ - Class* class_name::getClass() const \ - { return MSG_GET_CLASS(class_name); } \ - - // CreateObject implementation. - #define MSG_IMPLEMENT_DYNAMIC(class_name, base_class_name) \ - Object* class_name::createObject() \ - { return (Object*)(new class_name); } \ - DeclaringClass _declaringClass_##class_name(MSG_GET_CLASS(class_name)); \ - MSG_IMPLEMENT_CLASS(class_name, base_class_name, \ - class_name::createObject, &_declaringClass_##class_name) \ - - ////////////////////////////////////////////////////////////////////////////// - // Classes declared in this file. - - class Object; // The msg object. - - ////////////////////////////////////////////////////////////////////////////// - // Structures declared in this files. - - struct Class; // used during the rtti operations - struct DeclaringClass; // used during the instances registration. - - - class DeclaringClasses; - - ////////////////////////////////////////////////////////////////////////////// - // Global functions - - // Used during the registration. - void DeclareClass(Class* c); - - ////////////////////////////////////////////////////////////////////////////// - // DeclaringClass - - struct SIMGRIDX_EXPORT DeclaringClass - { - // Constructor : add the runtime classe in the list. - DeclaringClass(Class* c); - - // Destructor - virtual ~DeclaringClass(void); - - // Attributes : - // the list of runtime classes. - static DeclaringClasses* declaringClasses; - }; - - #define MSG_DELCARING_CLASSES (*(DeclaringClass::declaringClasses)) - - - struct SIMGRIDX_EXPORT Class - { - - // Attributes - - const char* name; // class name. - size_t typeSize; // type size. - Object* (*createObjectFn)(void); // pointer to the create object function. - Class* baseClass; // the runtime class of the runtime class. - Class* next; // the next runtime class in the list. - const DeclaringClass* declaringClass; // used during the registration of the class. - - // Operations - - // Create the runtime class from its 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); - - // Create an instance of the class. - Object* createObject(void); - - // Return true is the class is dervived from the base class baseClass. - bool isDerivedFrom(const Class* baseClass) const; - - }; - - // Create an instance of the class. - inline Object* Class::createObject(void) - { - return (*createObjectFn)(); - } - - - class SIMGRIDX_EXPORT Object - { - public: - - // Default constructor. - Object(){} - - // Destructor. - virtual ~Object(){} - - // Operations. - - // Get the runtime class. - virtual Class* getClass(void) const; - - // Returns true if the class is derived from the class baseClass. Otherwise - // the method returns false. - bool isDerivedFrom(const Class* baseClass) const; - - // Returns true if the object is valid. Otherwise the method returns false. - virtual bool isValid(void) const; - - // Returns true is the object is an instance of the class specified as parameter. - bool isInstanceOf(const char* className); - - // Operators. - - // Attributes. - - // The runtime class. - static const Class classObject; - }; - - // inline member functions of the class Object. - - // Returns the runtime class of the object. - inline Class* Object::getClass(void) const - { - return MSG_GET_CLASS(Object); - } - - // Returns true if the class is derived from the class pBaseClass. Otherwise - // the method returns false. - inline bool Object::isDerivedFrom(const Class* baseClass) const - { - return (getClass()->isDerivedFrom(baseClass)); - } - - // Returns true if the object is valid. Otherwise the method returns false. - inline bool Object::isValid(void) const - { - // returns always true. - return true; - } - - - class DeclaringClasses - { - public: - - // Constructor. - DeclaringClasses(); - - // Destructor. - virtual ~DeclaringClasses(){} - - // Operations. - - // Add the class at the head of the list. - void addHead(Class* c); - - // Get the runtime class of the head of the list. - Class* getHead(void) const ; - - // Remove the class from the list (don't destroy it). - bool remove(Class* c); - - // Remove the head of the list. - Class* removeHead(void); - - // Return true if the list is empty. - - bool isEmpty(void) const; - - // Remove of the elements of the list. - void removeAll(void); - - // Get the number of classes in the list. - unsigned int getCount(void); - - void lock(void){} - - void unlock(void){} - - //Attributes - - // The head of the list. - Class* head; - - private: - - // Attributes - - // The number of elements of the list. - unsigned int count; - }; - - typedef Object* ObjectPtr; - - - // Constructor (Add the class in the list). - inline DeclaringClass::DeclaringClass(Class* c) - { - if(!declaringClasses) - declaringClasses = new DeclaringClasses(); - - DeclareClass(c); - } - - // Destructor. - inline DeclaringClass::~DeclaringClass() - { - /*if(NULL != declaringClasses) - delete declaringClasses; - - declaringClasses=NULL;*/ - - } - - // Returns the number of elements of the list. - inline unsigned int DeclaringClasses::getCount() - { - return count; - } - - // Returns the head of the list. - inline Class* DeclaringClasses::getHead() const - { - return head; - } - - // Returns true if the list is empty. Otherwise this function - // returns false. - inline bool DeclaringClasses::isEmpty() const - { - return(!head); - } - - // Removes all the elements of the list. - inline void DeclaringClasses::removeAll() - { - head = 0; - count=0; - } - - } // namespace Msg -} // namespace SimGrid - - -using namespace SimGrid::Msg; - -#define instanceOf(class_name) reinterpret_cast(Class::createObject(#class_name)) - -#endif // !MSG_OBJECT_H - +/* + * Object.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_OBJECT_H +#define MSG_OBJECT_H + +// Compilation C++ recquise +#ifndef __cplusplus + #error Object.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +#include + +namespace SimGrid +{ + namespace Msg + { + ////////////////////////////////////////////////////////////////////////////// + // Macros + + // Returns the runtime class of the class_name object. + #define MSG_GET_CLASS(class_name) \ + ((Class*)(&class_name::class##class_name)) + + // Declare the class class_name as dynamic + #define MSG_DECLARE_DYNAMIC(class_name) \ + public: \ + static Class class##class_name; \ + virtual Class* getClass() const; \ + static Object* createObject() \ + + // The runtime class implementation. + #define MSG_IMPLEMENT_CLASS(class_name, base_class_name, pfn,class_init) \ + Class class_name::class##class_name = { \ + #class_name, sizeof(class class_name),pfn, \ + MSG_GET_CLASS(base_class_name), NULL,class_init}; \ + Class* class_name::getClass() const \ + { return MSG_GET_CLASS(class_name); } \ + + // CreateObject implementation. + #define MSG_IMPLEMENT_DYNAMIC(class_name, base_class_name) \ + Object* class_name::createObject() \ + { return (Object*)(new class_name); } \ + DeclaringClass _declaringClass_##class_name(MSG_GET_CLASS(class_name)); \ + MSG_IMPLEMENT_CLASS(class_name, base_class_name, \ + class_name::createObject, &_declaringClass_##class_name) \ + + ////////////////////////////////////////////////////////////////////////////// + // Classes declared in this file. + + class Object; // The msg object. + + ////////////////////////////////////////////////////////////////////////////// + // Structures declared in this files. + + struct Class; // used during the rtti operations + struct DeclaringClass; // used during the instances registration. + + + class DeclaringClasses; + + ////////////////////////////////////////////////////////////////////////////// + // Global functions + + // Used during the registration. + void DeclareClass(Class* c); + + ////////////////////////////////////////////////////////////////////////////// + // DeclaringClass + + struct SIMGRIDX_EXPORT DeclaringClass + { + // Constructor : add the runtime classe in the list. + DeclaringClass(Class* c); + + // Destructor + virtual ~DeclaringClass(void); + + // Attributes : + // the list of runtime classes. + static DeclaringClasses* declaringClasses; + }; + + #define MSG_DELCARING_CLASSES (*(DeclaringClass::declaringClasses)) + + + struct SIMGRIDX_EXPORT Class + { + + // Attributes + + const char* name; // class name. + size_t typeSize; // type size. + Object* (*createObjectFn)(void); // pointer to the create object function. + Class* baseClass; // the runtime class of the runtime class. + Class* next; // the next runtime class in the list. + const DeclaringClass* declaringClass; // used during the registration of the class. + + // Operations + + // Create the runtime class from its 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); + + // Create an instance of the class. + Object* createObject(void); + + // Return true is the class is dervived from the base class baseClass. + bool isDerivedFrom(const Class* baseClass) const; + + }; + + // Create an instance of the class. + inline Object* Class::createObject(void) + { + return (*createObjectFn)(); + } + + + class SIMGRIDX_EXPORT Object + { + public: + + // Default constructor. + Object(){} + + // Destructor. + virtual ~Object(){} + + // Operations. + + // Get the runtime class. + virtual Class* getClass(void) const; + + // Returns true if the class is derived from the class baseClass. Otherwise + // the method returns false. + bool isDerivedFrom(const Class* baseClass) const; + + // Returns true if the object is valid. Otherwise the method returns false. + virtual bool isValid(void) const; + + // Returns true is the object is an instance of the class specified as parameter. + bool isInstanceOf(const char* className); + + // Operators. + + // Attributes. + + // The runtime class. + static const Class classObject; + }; + + // inline member functions of the class Object. + + // Returns the runtime class of the object. + inline Class* Object::getClass(void) const + { + return MSG_GET_CLASS(Object); + } + + // Returns true if the class is derived from the class pBaseClass. Otherwise + // the method returns false. + inline bool Object::isDerivedFrom(const Class* baseClass) const + { + return (getClass()->isDerivedFrom(baseClass)); + } + + // Returns true if the object is valid. Otherwise the method returns false. + inline bool Object::isValid(void) const + { + // returns always true. + return true; + } + + + class DeclaringClasses + { + public: + + // Constructor. + DeclaringClasses(); + + // Destructor. + virtual ~DeclaringClasses(){} + + // Operations. + + // Add the class at the head of the list. + void addHead(Class* c); + + // Get the runtime class of the head of the list. + Class* getHead(void) const ; + + // Remove the class from the list (don't destroy it). + bool remove(Class* c); + + // Remove the head of the list. + Class* removeHead(void); + + // Return true if the list is empty. + + bool isEmpty(void) const; + + // Remove of the elements of the list. + void removeAll(void); + + // Get the number of classes in the list. + unsigned int getCount(void); + + void lock(void){} + + void unlock(void){} + + //Attributes + + // The head of the list. + Class* head; + + private: + + // Attributes + + // The number of elements of the list. + unsigned int count; + }; + + typedef Object* ObjectPtr; + + + // Constructor (Add the class in the list). + inline DeclaringClass::DeclaringClass(Class* c) + { + if(!declaringClasses) + declaringClasses = new DeclaringClasses(); + + DeclareClass(c); + } + + // Destructor. + inline DeclaringClass::~DeclaringClass() + { + /*if(NULL != declaringClasses) + delete declaringClasses; + + declaringClasses=NULL;*/ + + } + + // Returns the number of elements of the list. + inline unsigned int DeclaringClasses::getCount() + { + return count; + } + + // Returns the head of the list. + inline Class* DeclaringClasses::getHead() const + { + return head; + } + + // Returns true if the list is empty. Otherwise this function + // returns false. + inline bool DeclaringClasses::isEmpty() const + { + return(!head); + } + + // Removes all the elements of the list. + inline void DeclaringClasses::removeAll() + { + head = 0; + count=0; + } + + } // namespace Msg +} // namespace SimGrid + + +using namespace SimGrid::Msg; + +#define instanceOf(class_name) reinterpret_cast(Class::createObject(#class_name)) + +#endif // !MSG_OBJECT_H + diff --git a/src/cxx/OutOfBoundsException.cxx b/src/cxx/OutOfBoundsException.cxx index 3fb9412d82..fe2570e526 100644 --- a/src/cxx/OutOfBoundsException.cxx +++ b/src/cxx/OutOfBoundsException.cxx @@ -1,81 +1,81 @@ -/* - * OutOfBoundsException.cxx - * - * 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. - * - */ - - /* OutOfBoundsException member functions implementation. - */ - -#include - -#include -#include -#include - - -namespace SimGrid -{ - namespace Msg - { - - OutOfBoundsException::OutOfBoundsException() - { - this->reason = (char*) calloc(strlen("Out of bounds") + 1, sizeof(char)); - strcpy(this->reason, "Out of bounds"); - } - - - OutOfBoundsException::OutOfBoundsException(const OutOfBoundsException& rOutOfBoundsException) - { - const char* reason = rOutOfBoundsException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - OutOfBoundsException::OutOfBoundsException(int pos) - { - this->reason = (char*) calloc(strlen("Out of bounds ") + 21 + 1, sizeof(char)); - sprintf(this->reason, "Out of bounds %d", pos); - } - - OutOfBoundsException::OutOfBoundsException(int pos1, int pos2) - { - this->reason = (char*) calloc(strlen("Out of bounds ") + (2*21) + 1, sizeof(char)); - sprintf(this->reason, "Out of bounds %d : %d", pos1, pos2); - } - - - OutOfBoundsException::~OutOfBoundsException() - { - if(this->reason) - free(this->reason); - } - - const char* OutOfBoundsException::toString(void) const - { - return (const char*)(this->reason); - } - - - const OutOfBoundsException& OutOfBoundsException::operator = (const OutOfBoundsException& rOutOfBoundsException) - { - const char* reason = rOutOfBoundsException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * OutOfBoundsException.cxx + * + * 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. + * + */ + + /* OutOfBoundsException member functions implementation. + */ + +#include + +#include +#include +#include + + +namespace SimGrid +{ + namespace Msg + { + + OutOfBoundsException::OutOfBoundsException() + { + this->reason = (char*) calloc(strlen("Out of bounds") + 1, sizeof(char)); + strcpy(this->reason, "Out of bounds"); + } + + + OutOfBoundsException::OutOfBoundsException(const OutOfBoundsException& rOutOfBoundsException) + { + const char* reason = rOutOfBoundsException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + OutOfBoundsException::OutOfBoundsException(int pos) + { + this->reason = (char*) calloc(strlen("Out of bounds ") + 21 + 1, sizeof(char)); + sprintf(this->reason, "Out of bounds %d", pos); + } + + OutOfBoundsException::OutOfBoundsException(int pos1, int pos2) + { + this->reason = (char*) calloc(strlen("Out of bounds ") + (2*21) + 1, sizeof(char)); + sprintf(this->reason, "Out of bounds %d : %d", pos1, pos2); + } + + + OutOfBoundsException::~OutOfBoundsException() + { + if(this->reason) + free(this->reason); + } + + const char* OutOfBoundsException::toString(void) const + { + return (const char*)(this->reason); + } + + + const OutOfBoundsException& OutOfBoundsException::operator = (const OutOfBoundsException& rOutOfBoundsException) + { + const char* reason = rOutOfBoundsException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/OutOfBoundsException.hpp b/src/cxx/OutOfBoundsException.hpp index 379c76856a..2b89c7b644 100644 --- a/src/cxx/OutOfBoundsException.hpp +++ b/src/cxx/OutOfBoundsException.hpp @@ -1,71 +1,71 @@ -/* - * OutOfBoundsException.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_OUTOFBOUNDSEXCEPTION_HPP -#define MSG_OUTOFBOUNDSEXCEPTION_HPP - -#ifndef __cplusplus - #error OutOfBoundsException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT OutOfBoundsException : public Exception - { - public: - - // Default constructor. - OutOfBoundsException(); - - // Copy constructor. - OutOfBoundsException(const OutOfBoundsException& rOutOfBoundsException); - - // This constructor takes the position in the range. - OutOfBoundsException(int pos); - - OutOfBoundsException(int pos1, int pos2); - - // Destructor. - virtual ~OutOfBoundsException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Out of bounds : `pos'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const OutOfBoundsException& operator = (const OutOfBoundsException& rOutOfBoundsException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_MSGEXCEPTION_HPP - +/* + * OutOfBoundsException.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_OUTOFBOUNDSEXCEPTION_HPP +#define MSG_OUTOFBOUNDSEXCEPTION_HPP + +#ifndef __cplusplus + #error OutOfBoundsException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT OutOfBoundsException : public Exception + { + public: + + // Default constructor. + OutOfBoundsException(); + + // Copy constructor. + OutOfBoundsException(const OutOfBoundsException& rOutOfBoundsException); + + // This constructor takes the position in the range. + OutOfBoundsException(int pos); + + OutOfBoundsException(int pos1, int pos2); + + // Destructor. + virtual ~OutOfBoundsException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Out of bounds : `pos'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const OutOfBoundsException& operator = (const OutOfBoundsException& rOutOfBoundsException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_MSGEXCEPTION_HPP + diff --git a/src/cxx/Process.cxx b/src/cxx/Process.cxx index a43b2ea4e5..d22fe22969 100644 --- a/src/cxx/Process.cxx +++ b/src/cxx/Process.cxx @@ -1,670 +1,677 @@ -/* - * Process.cxx - * - * 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. - * - */ - - /* Process member functions implementation. - */ - -#include - - -#include -#include -#include - -#include -#include - -#include -#include -#include - - - -namespace SimGrid -{ - namespace Msg - { - - MSG_IMPLEMENT_DYNAMIC(Process, Object); - - // Default constructor. - Process::Process() - { - this->nativeProcess = NULL; - } - - Process::Process(const char* hostName, const char* name) - throw(NullPointerException, HostNotFoundException, BadAllocException) - { - // check the parameters - - if(!name) - throw NullPointerException("name"); - - if(!hostName) - throw NullPointerException("hostName"); - - Host host = Host::getByName(hostName); - - create(host, name, 0, NULL); - } - - Process::Process(const Host& rHost, const char* name) - throw(NullPointerException) - { - if(!name) - throw NullPointerException("name"); - - create(rHost, name, 0, NULL); - } - - 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(argc < 0) - throw InvalidArgumentException("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, BadAllocException) - { - // check the parameters - - if(!name) - throw NullPointerException("name"); - - if(!hostName) - throw NullPointerException("hostName"); - - if(argc < 0) - throw InvalidArgumentException("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"); - } - - int Process::isSuspended(void) - { - return 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(rHost.nativeHost)) - throw MsgException("MSG_process_change_host()"); - - } - - void Process::sleep(double seconds) - 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, Task* task) - throw(InvalidArgumentException, MsgException) - { - // check the parameters - - if(channel < 0) - throw InvalidArgumentException("channel (must not be negative)"); - - if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, rHost.nativeHost, channel, -1.0)) - throw MsgException("MSG_task_put_with_timeout()"); - } - - void Process::putTask(const Host& rHost, int channel, Task* task, 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(task->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, Task* task, 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(task->nativeTask, alias ,timeout)) - throw MsgException("MSG_task_send_with_timeout()"); - - } - - void Process::sendTask(const char* alias, Task* task) - throw(NullPointerException, MsgException) - { - // check the parameters - - if(!alias) - throw NullPointerException("alias"); - - if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0)) - throw MsgException("MSG_task_send_with_timeout()"); - } - - void Process::sendTask(Task* task) - throw(BadAllocException, MsgException) - { - char* alias = (char*)calloc( strlen(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0); - - free(alias); - - if(MSG_OK != rv) - throw MsgException("MSG_task_send_with_timeout()"); - } - - void Process::sendTask(Task* task, 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - - MSG_error_t rv = MSG_task_send_with_timeout(task->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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); - - 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); - - 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); - - 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); - - 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(InvalidArgumentException) - { - char alias[MAX_ALIAS_NAME + 1] = {0}; - msg_mailbox_t mailbox; - - - // try to retrieve the host where to createt the process from its name - m_host_t nativeHost = rHost.nativeHost; - - if(!nativeHost) - throw InvalidArgumentException("rHost"); - - /* allocate the data of the simulation */ - this->nativeProcess = xbt_new0(s_m_process_t,1); - this->nativeProcess->simdata = xbt_new0(s_simdata_process_t,1); - this->nativeProcess->name = _strdup(name); - this->nativeProcess->simdata->m_host = nativeHost; - this->nativeProcess->simdata->PID = msg_global->PID++; - - // realloc the list of the argument to add the pointer to this process instance at the end - if(argc) - argv = (char**)realloc(argv , (argc + 1) * sizeof(char*)); - else - argv = (char**)calloc(1 ,sizeof(char*)); - - // add the pointer to this instance at the end of the list of the arguments of the process - // so the static method Process::run() (passed as argument of the MSG function xbt_context_new()) - // can retrieve the concerned process object by the run - // so Process::run() can call the method main() of the good process - // for more detail see Process::run() method - argv[argc] = (char*)this; - - this->nativeProcess->simdata->argc = argc; - this->nativeProcess->simdata->argv = argv; - - this->nativeProcess->simdata->s_process = SIMIX_process_create( - this->nativeProcess->name, - Process::run, - (void*)this->nativeProcess, - nativeHost->name, - argc, - argv, - NULL); - - if (SIMIX_process_self()) - {/* someone created me */ - this->nativeProcess->simdata->PPID = MSG_process_get_PID((m_process_t)SIMIX_process_self()->data); - } - else - { - this->nativeProcess->simdata->PPID = -1; - } - - this->nativeProcess->simdata->last_errno = MSG_OK; - - /* add the process to the list of the processes of the simulation */ - xbt_fifo_unshift(msg_global->process_list, this->nativeProcess); - - sprintf(alias,"%s:%s",(this->nativeProcess->simdata->m_host->simdata->smx_host)->name,this->nativeProcess->name); - - mailbox = MSG_mailbox_new(alias); - - MSG_mailbox_set_hostname(mailbox, this->nativeProcess->simdata->m_host->simdata->smx_host->name); - } - - Process* Process::fromNativeProcess(m_process_t nativeProcess) - { - return ((Process*)(nativeProcess->simdata->argv[nativeProcess->simdata->argc])); - } - - int Process::run(int argc, char** argv) - { - - // the last argument of the process is the pointer to the process to run - // for more detail see Process::create() method - return ((Process*)argv[argc])->main(argc, argv); - } - - int Process::main(int argc, char** argv) - { - throw LogicException("Process::main() not implemented"); - } - - /*void* Process::operator new(size_t size) - { - // TODO - } - - void Process::operator delete(void* p) - { - // TODO - }*/ - - } // namespace Msg - -} // namespace SimGrid - +/* + * Process.cxx + * + * 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. + * + */ + + /* Process member functions implementation. + */ + +#include + + +#include +#include +#include + +#include +#include + +#include +#include +#include + + + +namespace SimGrid +{ + namespace Msg + { + + MSG_IMPLEMENT_DYNAMIC(Process, Object) + + // Default constructor. + Process::Process() + { + this->nativeProcess = NULL; + } + + Process::Process(const char* hostName, const char* name) + throw(NullPointerException, HostNotFoundException, BadAllocException) + { + // check the parameters + + if(!name) + throw NullPointerException("name"); + + if(!hostName) + throw NullPointerException("hostName"); + + Host host = Host::getByName(hostName); + + create(host, name, 0, NULL); + } + + Process::Process(const Host& rHost, const char* name) + throw(NullPointerException) + { + if(!name) + throw NullPointerException("name"); + + create(rHost, name, 0, NULL); + } + + 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(argc < 0) + throw InvalidArgumentException("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, BadAllocException) + { + // check the parameters + + if(!name) + throw NullPointerException("name"); + + if(!hostName) + throw NullPointerException("hostName"); + + if(argc < 0) + throw InvalidArgumentException("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"); + } + + int Process::isSuspended(void) + { + return 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 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(rHost.nativeHost)) + throw MsgException("MSG_process_change_host()"); + + } + + void Process::sleep(double seconds) + 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, Task* task) + throw(InvalidArgumentException, MsgException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, rHost.nativeHost, channel, -1.0)) + throw MsgException("MSG_task_put_with_timeout()"); + } + + void Process::putTask(const Host& rHost, int channel, Task* task, 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 and different of -1.0)"); + + if(MSG_OK != MSG_task_put_with_timeout(task->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 and 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 and 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, Task* task, 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(task->nativeTask, alias ,timeout)) + throw MsgException("MSG_task_send_with_timeout()"); + + } + + void Process::sendTask(const char* alias, Task* task) + throw(NullPointerException, MsgException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0)) + throw MsgException("MSG_task_send_with_timeout()"); + } + + void Process::sendTask(Task* task) + throw(BadAllocException, MsgException) + { + char* alias = (char*)calloc( strlen(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0); + + free(alias); + + if(MSG_OK != rv) + throw MsgException("MSG_task_send_with_timeout()"); + } + + void Process::sendTask(Task* task, 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); + + MSG_error_t rv = MSG_task_send_with_timeout(task->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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); + + 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); + + 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); + + 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(this->getHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); + + 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(InvalidArgumentException) + { + char alias[MAX_ALIAS_NAME + 1] = {0}; + msg_mailbox_t mailbox; + + + // try to retrieve the host where to create the process from its name + m_host_t nativeHost = rHost.nativeHost; + + if(!nativeHost) + throw InvalidArgumentException("rHost"); + + /* allocate the data of the simulation */ + this->nativeProcess = xbt_new0(s_m_process_t,1); + this->nativeProcess->simdata = xbt_new0(s_simdata_process_t,1); + this->nativeProcess->name = _strdup(name); + this->nativeProcess->simdata->m_host = nativeHost; + this->nativeProcess->simdata->PID = msg_global->PID++; + + // realloc the list of the arguments to add the pointer to this process instance at the end + if(argc) + { + argv = (char**)realloc(argv , (argc + 2) * sizeof(char*)); + } + else + { + argv = (char**)calloc(2 ,sizeof(char*)); + } + + // add the pointer to this instance at the end of the list of the arguments of the process + // so the static method Process::run() (passed as argument of the MSG function xbt_context_new()) + // can retrieve the concerned process object by the run + // so Process::run() can call the method main() of the good process + // for more detail see Process::run() method + argv[argc] = NULL; + argv[argc + 1] = (char*)this; + + this->nativeProcess->simdata->argc = argc; + this->nativeProcess->simdata->argv = argv; + + this->nativeProcess->simdata->s_process = SIMIX_process_create( + this->nativeProcess->name, + Process::run, + (void*)this->nativeProcess, + nativeHost->name, + argc, + argv, + NULL); + + if (SIMIX_process_self()) + {/* someone created me */ + this->nativeProcess->simdata->PPID = MSG_process_get_PID((m_process_t)SIMIX_process_self()->data); + } + else + { + this->nativeProcess->simdata->PPID = -1; + } + + this->nativeProcess->simdata->last_errno = MSG_OK; + + /* add the process to the list of the processes of the simulation */ + xbt_fifo_unshift(msg_global->process_list, this->nativeProcess); + + sprintf(alias,"%s:%s",(this->nativeProcess->simdata->m_host->simdata->smx_host)->name,this->nativeProcess->name); + + mailbox = MSG_mailbox_new(alias); + + MSG_mailbox_set_hostname(mailbox, this->nativeProcess->simdata->m_host->simdata->smx_host->name); + } + + Process* Process::fromNativeProcess(m_process_t nativeProcess) + { + return ((Process*)(nativeProcess->simdata->argv[nativeProcess->simdata->argc + 1])); + + } + + int Process::run(int argc, char** argv) + { + + // the last argument of the process is the pointer to the process to run + // for more detail see Process::create() method + return ((Process*)argv[argc + 1])->main(argc, argv); + + } + + int Process::main(int argc, char** argv) + { + throw LogicException("Process::main() not implemented"); + } + + /*void* Process::operator new(size_t size) + { + // TODO + } + + void Process::operator delete(void* p) + { + // TODO + }*/ + + } // namespace Msg + +} // namespace SimGrid + diff --git a/src/cxx/Process.hpp b/src/cxx/Process.hpp index 5bc46e5190..4bc5f3e6f8 100644 --- a/src/cxx/Process.hpp +++ b/src/cxx/Process.hpp @@ -1,617 +1,617 @@ -/* - * 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 - -// Compilation C++ recquise -#ifndef __cplusplus - #error Process.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - class ApplicationHandler; - class Host; - class Task; - - // SimGrid::Msg::Process class declaration. - class SIMGRIDX_EXPORT Process : public Object - { - friend class ApplicationHandler::ProcessFactory; - - MSG_DECLARE_DYNAMIC(Process); - - public: - - // Disable the default constructor. - Process(); - - - /*! \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, BadAllocException); - - /*! \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, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException); - - /*! \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 1 is the process is suspended. - * Otherwise the method returns 0. - */ - int 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, Task* task) - 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, Task* task, 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, Task* task, 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, Task* task) - 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(Task* task) - 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(Task* task, 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* 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(InvalidArgumentException); - - /* 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); - - // Operators. - - /* - // Override the operator new(). - void* operator new(size_t size); - - // Override the operator delete(). - void operator delete(void* p); - */ - - private: - - // Attributes. - - m_process_t nativeProcess; // pointer to the native msg process. - - }; - - } //namepace Msg - -} // namespace SimGrid - -#endif // !MSG_PROCESS_HPP - +/* + * 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 + +// Compilation C++ recquise +#ifndef __cplusplus + #error Process.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + class ApplicationHandler; + class Host; + class Task; + + // SimGrid::Msg::Process class declaration. + class SIMGRIDX_EXPORT Process : public Object + { + friend class ApplicationHandler::ProcessFactory; + + MSG_DECLARE_DYNAMIC(Process); + + public: + + // Disable the default constructor. + Process(); + + + /*! \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, BadAllocException); + + /*! \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, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException); + + /*! \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 1 is the process is suspended. + * Otherwise the method returns 0. + */ + int 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, Task* task) + 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, Task* task, 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, Task* task, 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, Task* task) + 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(Task* task) + 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(Task* task, 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* 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(InvalidArgumentException); + + /* 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); + + // Operators. + + /* + // Override the operator new(). + void* operator new(size_t size); + + // Override the operator delete(). + void operator delete(void* p); + */ + + private: + + // Attributes. + + m_process_t nativeProcess; // pointer to the native msg process. + + }; + + } //namepace Msg + +} // namespace SimGrid + +#endif // !MSG_PROCESS_HPP + diff --git a/src/cxx/ProcessNotFoundException.cxx b/src/cxx/ProcessNotFoundException.cxx index 2da654afd0..1215b2a378 100644 --- a/src/cxx/ProcessNotFoundException.cxx +++ b/src/cxx/ProcessNotFoundException.cxx @@ -1,77 +1,81 @@ -/* - * ProcessNotFoundException.cxx - * - * 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. - * - */ - - /* ProcessNotFoundException member functions implementation. - */ - -#include - -#include -#include -#include - -namespace SimGrid -{ - namespace Msg - { - - ProcessNotFoundException::ProcessNotFoundException() - { - this->reason = (char*) calloc(strlen("Host not found : unknown") + 1, sizeof(char)); - strcpy(this->reason, "Host not found : unknown"); - } - - - ProcessNotFoundException::ProcessNotFoundException(const ProcessNotFoundException& rProcessNotFoundException) - { - const char* reason = rProcessNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - strcpy(this->reason, reason); - - } - - - ProcessNotFoundException::ProcessNotFoundException(int PID) - { - char buff[7] = {0}; - _itoa(PID, buff, 10); - this->reason = (char*) calloc(strlen("Process not found : ") + strlen(buff) + 1, sizeof(char)); - sprintf(this->reason, "Host not found : %s", buff); - } - - - ProcessNotFoundException::~ProcessNotFoundException() - { - if(this->reason) - free(this->reason); - } - - const char* ProcessNotFoundException::toString(void) const - { - return (const char*)(this->reason); - } - - - const ProcessNotFoundException& ProcessNotFoundException::operator = (const ProcessNotFoundException& rProcessNotFoundException) - { - const char* reason = rProcessNotFoundException.toString(); - this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); - - return *this; - } - - } // namespace Msg - -}// namespace SimGrid - - - +/* + * ProcessNotFoundException.cxx + * + * 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. + * + */ + + /* ProcessNotFoundException member functions implementation. + */ + +#include + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + + ProcessNotFoundException::ProcessNotFoundException() + { + this->reason = (char*) calloc(strlen("Host not found : unknown") + 1, sizeof(char)); + strcpy(this->reason, "Host not found : unknown"); + } + + + ProcessNotFoundException::ProcessNotFoundException(const ProcessNotFoundException& rProcessNotFoundException) + { + const char* reason = rProcessNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + ProcessNotFoundException::ProcessNotFoundException(int PID) + { + char buff[7] = {0}; + #ifdef WIN32 + _itoa(PID, buff, 10); + #else + sprintf(buff,"%d",PID); + #endif + this->reason = (char*) calloc(strlen("Process not found : ") + strlen(buff) + 1, sizeof(char)); + sprintf(this->reason, "Host not found : %s", buff); + } + + + ProcessNotFoundException::~ProcessNotFoundException() + { + if(this->reason) + free(this->reason); + } + + const char* ProcessNotFoundException::toString(void) const + { + return (const char*)(this->reason); + } + + + const ProcessNotFoundException& ProcessNotFoundException::operator = (const ProcessNotFoundException& rProcessNotFoundException) + { + const char* reason = rProcessNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/ProcessNotFoundException.hpp b/src/cxx/ProcessNotFoundException.hpp index 9e29e0055f..bdf56752b1 100644 --- a/src/cxx/ProcessNotFoundException.hpp +++ b/src/cxx/ProcessNotFoundException.hpp @@ -1,68 +1,68 @@ -/* - * ProcessNotFoundException.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_PROCESSNOTFOUNDEXCEPTION_HPP -#define MSG_PROCESSNOTFOUNDEXCEPTION_HPP - -#ifndef __cplusplus - #error ProcessNotFoundException.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -namespace SimGrid -{ - namespace Msg - { - - class SIMGRIDX_EXPORT ProcessNotFoundException : public Exception - { - public: - - // Default constructor. - ProcessNotFoundException(); - - // Copy constructor. - ProcessNotFoundException(const ProcessNotFoundException& rProcessNotFoundException); - - // This constructor takes PID of the process. - ProcessNotFoundException(int PID); - - // Destructor. - virtual ~ProcessNotFoundException(); - - // Operations. - - // Returns the reason of the exception : - // the message "Process not found `PID'" - const char* toString(void) const; - - // Operators. - - // Assignement. - const ProcessNotFoundException& operator = (const ProcessNotFoundException& rProcessNotFoundException); - - private : - - // Attributes. - - // A buffer used to build the message returned by the methode toString(). - char* reason; - }; - - - } // namespace Msg - -}// namespace SimGrid - - -#endif // !MSG_PROCESSNOTFOUNDEXCEPTION_HPP +/* + * ProcessNotFoundException.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_PROCESSNOTFOUNDEXCEPTION_HPP +#define MSG_PROCESSNOTFOUNDEXCEPTION_HPP + +#ifndef __cplusplus + #error ProcessNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + class SIMGRIDX_EXPORT ProcessNotFoundException : public Exception + { + public: + + // Default constructor. + ProcessNotFoundException(); + + // Copy constructor. + ProcessNotFoundException(const ProcessNotFoundException& rProcessNotFoundException); + + // This constructor takes PID of the process. + ProcessNotFoundException(int PID); + + // Destructor. + virtual ~ProcessNotFoundException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Process not found `PID'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const ProcessNotFoundException& operator = (const ProcessNotFoundException& rProcessNotFoundException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_PROCESSNOTFOUNDEXCEPTION_HPP diff --git a/src/cxx/Simulation.cxx b/src/cxx/Simulation.cxx index 0697760e74..713baed2c0 100644 --- a/src/cxx/Simulation.cxx +++ b/src/cxx/Simulation.cxx @@ -1,108 +1,108 @@ -/* - * Simulation.cxx - * - * 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. - * - */ - - /* Simulation member functions implementation. - */ - - -#include -#include - -#include - -#include - - -#include - -namespace SimGrid -{ - namespace Msg - { - int Simulation::execute(int argc, char** argv) - { - if(argc < 3) - { - info("Usage: Msg platform_file deployment_file"); - return 1; - } - - // initialize the MSG simulator. Must be done before anything else (even logging). - init(argc, argv); - - // the environment to load - Environment env; - - // the application to deploy - Application app; - - - // try to load the environment described by the xml file (argv[1]) - try - { - env.load(argv[1]); - } - catch(FileNotFoundException e) - { - info(e.toString()); - finalize(); - return 1; - } - - // try to deploy the application described by the xml file deployment (argv[2]) - try - { - app.deploy(argv[2]); - } - catch(FileNotFoundException e) - { - info(e.toString()); - finalize(); - return 1; - } - - //try to run the simulation the given application on the given environment - try - { - run(); - } - catch(MsgException e) - { - info(e.toString()); - finalize(); - return 1; - } - - // finalize the MSG simulator - try - { - finalize(); - } - catch(MsgException e) - { - info(e.toString()); - return 1; - } - - return 0; - } - - void Simulation::run(void) - throw (MsgException) - { - if(MSG_OK != MSG_main()) - throw MsgException("MSG_main() failed"); - } - } // namespace Msg -} // namespace SimGrid - - +/* + * Simulation.cxx + * + * 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. + * + */ + + /* Simulation member functions implementation. + */ + + +#include +#include + +#include + +#include + + +#include + +namespace SimGrid +{ + namespace Msg + { + int Simulation::execute(int argc, char** argv) + { + if(argc < 3) + { + info("Usage: Msg platform_file deployment_file"); + return 1; + } + + // initialize the MSG simulator. Must be done before anything else (even logging). + init(argc, argv); + + // the environment to load + Environment env; + + // the application to deploy + Application app; + + + // try to load the environment described by the xml file (argv[1]) + try + { + env.load(argv[1]); + } + catch(FileNotFoundException e) + { + info(e.toString()); + finalize(); + return 1; + } + + // try to deploy the application described by the xml file deployment (argv[2]) + try + { + app.deploy(argv[2]); + } + catch(FileNotFoundException e) + { + info(e.toString()); + finalize(); + return 1; + } + + //try to run the simulation the given application on the given environment + try + { + run(); + } + catch(MsgException e) + { + info(e.toString()); + finalize(); + return 1; + } + + // finalize the MSG simulator + try + { + finalize(); + } + catch(MsgException e) + { + info(e.toString()); + return 1; + } + + return 0; + } + + void Simulation::run(void) + 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 631cc30c96..c2eeefbc61 100644 --- a/src/cxx/Simulation.hpp +++ b/src/cxx/Simulation.hpp @@ -1,61 +1,61 @@ -/* - * Simulation.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_SIMULATION_HPP -#define MSG_SIMULATION_HPP - -#ifndef __cplusplus - #error Sumulation.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include -#include - -namespace SimGrid -{ - namespace Msg - { - class MsgException; - class FileNotFoundException; - - // Simulation class declaration. - class SIMGRIDX_EXPORT Simulation - { - public : - - Simulation(){}; - - Simulation(const Simulation& rSimulation); - - virtual ~Simulation(){}; - - // Operations. - - int execute(int argc, char** argv); - - private: - - void run(void) - throw (MsgException); - - - // Operators. - const Simulation& operator = (const Simulation& rSimulation); - }; - - } // namespace Msg -} // namespace SimGrid - -#endif // !MSG_SIMULATION_HPP - +/* + * Simulation.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_SIMULATION_HPP +#define MSG_SIMULATION_HPP + +#ifndef __cplusplus + #error Sumulation.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +#include + +namespace SimGrid +{ + namespace Msg + { + class MsgException; + class FileNotFoundException; + + // Simulation class declaration. + class SIMGRIDX_EXPORT Simulation + { + public : + + Simulation(){}; + + Simulation(const Simulation& rSimulation); + + virtual ~Simulation(){}; + + // Operations. + + int execute(int argc, char** argv); + + private: + + void run(void) + throw (MsgException); + + + // Operators. + const Simulation& operator = (const Simulation& rSimulation); + }; + + } // namespace Msg +} // namespace SimGrid + +#endif // !MSG_SIMULATION_HPP + diff --git a/src/cxx/StringHelper.cxx b/src/cxx/StringHelper.cxx index c64c6c1ce9..f8b8952f8f 100644 --- a/src/cxx/StringHelper.cxx +++ b/src/cxx/StringHelper.cxx @@ -1,824 +1,825 @@ -#include - -#include -#include -#include -#include - -#ifndef BUFF_MAX -#define BUFF_MAX ((size_t)260) -#endif // BUFF_MAX - - -// namespace SimGrid::Msg -namespace SimGrid -{ - namespace Msg - { - - #define DEFAULT_STRING_HELPER_CAPACITY ((int)128) - - - void StringHelper::init(void) - { - capacity = DEFAULT_STRING_HELPER_CAPACITY; - - if(!(content = (char*) calloc(capacity + 1, sizeof(char)))) - throw BadAllocException(); - - len = 0; - } - - // Default constructor - StringHelper::StringHelper() - { - init(); - } - - StringHelper::StringHelper(char c) - { - init(); - append(c); - - } - - StringHelper::StringHelper(char c, int n) - { - init(); - append(c, n); - } - - StringHelper::StringHelper(const char* cstr) - { - init(); - append(cstr); - } - - StringHelper::StringHelper(const char* cstr, int n) - { - init(); - append(cstr, n); - } - - StringHelper::StringHelper(const char* cstr, int pos, int n) - { - init(); - append(cstr, pos, n); - } - - StringHelper::StringHelper(const string& rstr) - { - init(); - append(rstr); - } - - StringHelper::StringHelper(const string& rstr, int n) - { - init(); - append(rstr, n); - } - - StringHelper::StringHelper(const string& rstr, int pos, int n) - { - init(); - append(rstr, pos, n); - } - - StringHelper::StringHelper(short si) - { - init(); - append(si); - } - - StringHelper::StringHelper(int i) - { - init(); - append(i); - } - - StringHelper::StringHelper(long l) - { - init(); - append(l); - } - - StringHelper::StringHelper(float f) - { - init(); - append(f); - } - - StringHelper::StringHelper(double d) - { - init(); - append(d); - } - - StringHelper::StringHelper(double d, const char* format) - { - char toAppend[BUFF_MAX + 1] = {0}; - - sprintf(toAppend,format,d); - - init(); - - append(toAppend); - } - - StringHelper::StringHelper(unsigned short usi) - { - init(); - append(usi); - } - - StringHelper::StringHelper(unsigned int ui) - { - init(); - append(ui); - } - - StringHelper::StringHelper(unsigned long ul) - { - init(); - append(ul); - } - - // Copy constructor - StringHelper::StringHelper(const StringHelper& rStringHelper) - { - if(this != &rStringHelper && rStringHelper.size()) - { - clear(); - append(rStringHelper.cstr()); - } - } - - // Destructor - StringHelper::~StringHelper() - { - if(content) - free(content); - } - - // Operations - - void StringHelper::clear(void) - { - if(len) - memset(content, 0, len); - - len = 0; - } - - bool StringHelper::empty(void) - { - return len == 0; - } - - StringHelper& StringHelper::append(unsigned char c) - { - if(capacity < len + 1) - { - int new_capacity = (capacity << 1) ; - - if(!(content = (char*) realloc(content, new_capacity))) - throw BadAllocException(); - - capacity = new_capacity; - } - - - content[len] = c; - len++; - - content[len] = '\0'; - - return *this; - } - - StringHelper& StringHelper::append(unsigned char c, int n) - { - if(n <=0) - throw InvalidArgumentException("n"); - - char* toAppend = (char*) calloc(n + 1, sizeof(char)); - - if(!toAppend) - throw BadAllocException(); - - memset(toAppend, c, n); - - append(toAppend); - - free(toAppend); - - return *this; - } - - - StringHelper& StringHelper::append(char c) - { - if(capacity < len + 1) - { - int new_capacity = (capacity << 1) ; - - if(!(content = (char*) realloc(content, new_capacity))) - throw BadAllocException(); - - capacity = new_capacity; - } - - - content[len] = c; - len++; - - content[len] = '\0'; - - return *this; - } - - StringHelper& StringHelper::append(char c, int n) - { - if(n <=0) - throw InvalidArgumentException("n"); - - char* toAppend = (char*) calloc(n + 1, sizeof(char)); - - if(!toAppend) - throw BadAllocException(); - - memset(toAppend, c, n); - - append(toAppend); - - free(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(const char* cstr) - { - if(!cstr) - throw NullPointerException("cstr"); - - int l = (int) strlen(cstr); - - if(capacity < len + l) - { - int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1; - - if(!(content = (char*) realloc(content, new_capacity))) - throw BadAllocException(); - - strcat(content, cstr); - - capacity = new_capacity; - } - else - { - strcat(content, cstr); - } - - len += l; - content[len] = '\0'; - - return *this; - - } - - StringHelper& StringHelper::append(const char* cstr, int n) - { - if(!cstr) - throw NullPointerException("cstr"); - - if(n <= 0) - throw InvalidArgumentException("n"); - - - int l = ((int) strlen(cstr)) * n; - - if(capacity < len + l) - { - int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1; - - if(!(content = (char*) realloc(content, new_capacity))) - throw BadAllocException(); - - for(int i = 0; i < n; i++) - strcat(content, cstr); - - capacity = new_capacity; - } - else - { - for(int i = 0; i < n; i++) - strcat(content, cstr); - } - - len += l; - content[len] = '\0'; - - return *this; - - } - - StringHelper& StringHelper::append(const char* cstr, int pos, int n) - { - if(!cstr) - throw NullPointerException("cstr"); - - if(n <= 0) - throw InvalidArgumentException("n"); - - if(pos < 0 || pos >= (int)strlen(cstr) ) - throw OutOfBoundsException(pos); - - if(pos + n >= (int)strlen(cstr)) - throw OutOfBoundsException(pos, n); - - - char* toAppend = (char*) calloc(n + 1, sizeof(char)); - - strncpy(toAppend, cstr + pos, n); - - append(toAppend); - - free(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(const string& rstr) - { - append(rstr.c_str()); - return *this; - } - - StringHelper& StringHelper::append(const string& rstr, int n) - { - if(rstr.empty()) - throw NullPointerException("rstr"); - - if(n <= 0) - throw InvalidArgumentException("n"); - - - int l = ((int) rstr.size()) * n; - - if(capacity < len + l) - { - int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1; - - if(!(content = (char*) realloc(content, new_capacity))) - throw BadAllocException(); - - for(int i = 0; i < n; i++) - strcat(content, rstr.c_str()); - - capacity = new_capacity; - } - else - { - for(int i = 0; i < n; i++) - strcat(content, rstr.c_str()); - } - - len += l; - content[len] = '\0'; - - return *this; - } - - StringHelper& StringHelper::append(const string& rstr, int pos, int n) - { - if(rstr.empty()) - throw InvalidArgumentException("rstr"); - - if(n <= 0) - throw InvalidArgumentException("n"); - - if(pos < 0 || pos >= (int) rstr.size() ) - throw OutOfBoundsException(pos); - - if(pos + n >= (int) rstr.size()) - throw OutOfBoundsException(pos, n); - - - char* toAppend = (char*) calloc(n + 1, sizeof(char)); - - strncpy(toAppend, rstr.c_str() + pos, n); - - append(toAppend); - - free(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(short si) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%hd",si); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(int i) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%d",i); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(long l) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%ld",l); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(float f) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%f",f); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(double d) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%lf",d); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(double d, const char* format) - { - char toAppend[BUFF_MAX + 1] = {0}; - - sprintf(toAppend, format, d); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(unsigned short usi) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%hu",usi); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(unsigned int ui) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%u",ui); - - append(toAppend); - - return *this; - } - - StringHelper& StringHelper::append(unsigned long ul) - { - char toAppend[26] = {0}; - - sprintf(toAppend, "%lu",ul); - - append(toAppend); - - return *this; - } - - const char& StringHelper::at(int pos) const - { - if(pos < 0 || pos >= len) - throw OutOfBoundsException(pos); - - return content[pos]; - } - - char& StringHelper::at(int pos) - { - if(pos < 0 || pos >= len) - throw OutOfBoundsException(pos); - - return content[pos]; - } - - const char* StringHelper::cstr(void) const - { - return (const char*)content; - } - - string& StringHelper::toString(void) - { - string* s = new string(); - s->append(content); - return *s; - } - - int StringHelper::size(void) const - { - return len; - } - - // Operators - - // Assignement - StringHelper& StringHelper::operator = (const StringHelper& rStringHelper) - { - - if(this !=&rStringHelper && rStringHelper.size()) - { - clear(); - append(rStringHelper.cstr()); - } - - return *this; - } - - StringHelper& StringHelper::operator = (const char* cstr) - { - clear(); - append(cstr); - return *this; - } - - StringHelper& StringHelper::operator = (const string& str) - { - clear(); - append(str); - return *this; - } - - StringHelper& StringHelper::operator = (short n) - { - clear(); - append(n); - return *this; - } - - StringHelper& StringHelper::operator = (int n) - { - clear(); - append(n); - return *this; - } - - StringHelper& StringHelper::operator = (long n) - { - clear(); - append(n); - return *this; - } - - StringHelper& StringHelper::operator = (float n) - { - clear(); - append(n); - return *this; - } - - StringHelper& StringHelper::operator = (double n) - { - clear(); - append(n); - return *this; - } - - StringHelper& StringHelper::operator = (unsigned short n) - { - clear(); - append(n); - return *this; - } - - StringHelper& StringHelper::operator = (unsigned int n) - { - clear(); - append(n); - return *this; - } - - StringHelper& StringHelper::operator = (unsigned long n) - { - clear(); - append(n); - return *this; - } - - char& StringHelper::operator[](int pos) - { - if(pos < 0 || pos >= len) - throw OutOfBoundsException(pos); - - return content[pos]; - } - - char StringHelper::operator[](int pos) const - { - if(pos < 0 || pos >= len) - throw OutOfBoundsException(pos); - - return content[pos]; - } - - StringHelper& StringHelper::operator += (short n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (int n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (long n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (float n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (double n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (unsigned short n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (unsigned int n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (unsigned long n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator += (const StringHelper& rStringHelper) - { - append(rStringHelper.content); - return *this; - } - - StringHelper& StringHelper::operator += (const string& rstr) - { - append(rstr.c_str()); - return *this; - } - - StringHelper& StringHelper::operator += (const char* cstr) - { - append(cstr); - return *this; - } - - StringHelper& StringHelper::operator += (char c) - { - append(c); - return *this; - } - - StringHelper& StringHelper::operator + (short n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator + (int n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator + (long n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator + (float n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator + (double n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator + (unsigned short n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator + (unsigned int n) - { - append(n); - return *this; - } - - StringHelper& StringHelper::operator + (unsigned long n) - { - append(n); - return *this; - } - - - StringHelper& StringHelper::operator + (const StringHelper& rStringHelper) - { - append(rStringHelper.content); - return *this; - } - - StringHelper& StringHelper::operator + (const string& rstr) - { - append(rstr.c_str()); - return *this; - } - - StringHelper& StringHelper::operator + (const char* cstr) - { - append(cstr); - return *this; - } - - StringHelper& StringHelper::operator + (char c) - { - append(c); - return *this; - } - - StringHelper::operator char *() - { - return content; - } - - StringHelper::operator const char *() - { - return content; - } - - ostream& operator<<(ostream& stream, const StringHelper& s) - { - stream << s.cstr(); - return stream; - } - - istream& operator<<(istream& stream, StringHelper& s) - { - char buff[256] = {0}; - - stream >> buff; - - s.append(buff); - - return stream; - } - - } // namespace Msg -} // namespace SimGrid \ No newline at end of file +#include + +#include +#include +#include +#include + +#ifndef BUFF_MAX +#define BUFF_MAX ((size_t)260) +#endif // BUFF_MAX + + +// namespace SimGrid::Msg +namespace SimGrid +{ + namespace Msg + { + + #define DEFAULT_STRING_HELPER_CAPACITY ((int)128) + + + void StringHelper::init(void) + { + capacity = DEFAULT_STRING_HELPER_CAPACITY; + + if(!(content = (char*) calloc(capacity + 1, sizeof(char)))) + throw BadAllocException(); + + len = 0; + } + + // Default constructor + StringHelper::StringHelper() + { + init(); + } + + StringHelper::StringHelper(char c) + { + init(); + append(c); + + } + + StringHelper::StringHelper(char c, int n) + { + init(); + append(c, n); + } + + StringHelper::StringHelper(const char* cstr) + { + init(); + append(cstr); + } + + StringHelper::StringHelper(const char* cstr, int n) + { + init(); + append(cstr, n); + } + + StringHelper::StringHelper(const char* cstr, int pos, int n) + { + init(); + append(cstr, pos, n); + } + + StringHelper::StringHelper(const string& rstr) + { + init(); + append(rstr); + } + + StringHelper::StringHelper(const string& rstr, int n) + { + init(); + append(rstr, n); + } + + StringHelper::StringHelper(const string& rstr, int pos, int n) + { + init(); + append(rstr, pos, n); + } + + StringHelper::StringHelper(short si) + { + init(); + append(si); + } + + StringHelper::StringHelper(int i) + { + init(); + append(i); + } + + StringHelper::StringHelper(long l) + { + init(); + append(l); + } + + StringHelper::StringHelper(float f) + { + init(); + append(f); + } + + StringHelper::StringHelper(double d) + { + init(); + append(d); + } + + StringHelper::StringHelper(double d, const char* format) + { + char toAppend[BUFF_MAX + 1] = {0}; + + sprintf(toAppend,format,d); + + init(); + + append(toAppend); + } + + StringHelper::StringHelper(unsigned short usi) + { + init(); + append(usi); + } + + StringHelper::StringHelper(unsigned int ui) + { + init(); + append(ui); + } + + StringHelper::StringHelper(unsigned long ul) + { + init(); + append(ul); + } + + // Copy constructor + StringHelper::StringHelper(const StringHelper& rStringHelper) + { + if(this != &rStringHelper && rStringHelper.size()) + { + clear(); + append(rStringHelper.cstr()); + } + } + + // Destructor + StringHelper::~StringHelper() + { + if(content) + free(content); + } + + // Operations + + void StringHelper::clear(void) + { + if(len) + memset(content, 0, len); + + len = 0; + } + + bool StringHelper::empty(void) + { + return len == 0; + } + + StringHelper& StringHelper::append(unsigned char c) + { + if(capacity < len + 1) + { + int new_capacity = (capacity << 1) ; + + if(!(content = (char*) realloc(content, new_capacity))) + throw BadAllocException(); + + capacity = new_capacity; + } + + + content[len] = c; + len++; + + content[len] = '\0'; + + return *this; + } + + StringHelper& StringHelper::append(unsigned char c, int n) + { + if(n <=0) + throw InvalidArgumentException("n"); + + char* toAppend = (char*) calloc(n + 1, sizeof(char)); + + if(!toAppend) + throw BadAllocException(); + + memset(toAppend, c, n); + + append(toAppend); + + free(toAppend); + + return *this; + } + + + StringHelper& StringHelper::append(char c) + { + if(capacity < len + 1) + { + int new_capacity = (capacity << 1) ; + + if(!(content = (char*) realloc(content, new_capacity))) + throw BadAllocException(); + + capacity = new_capacity; + } + + + content[len] = c; + len++; + + content[len] = '\0'; + + return *this; + } + + StringHelper& StringHelper::append(char c, int n) + { + if(n <=0) + throw InvalidArgumentException("n"); + + char* toAppend = (char*) calloc(n + 1, sizeof(char)); + + if(!toAppend) + throw BadAllocException(); + + memset(toAppend, c, n); + + append(toAppend); + + free(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(const char* cstr) + { + if(!cstr) + throw NullPointerException("cstr"); + + int l = (int) strlen(cstr); + + if(capacity < len + l) + { + int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1; + + if(!(content = (char*) realloc(content, new_capacity))) + throw BadAllocException(); + + strcat(content, cstr); + + capacity = new_capacity; + } + else + { + strcat(content, cstr); + } + + len += l; + content[len] = '\0'; + + return *this; + + } + + StringHelper& StringHelper::append(const char* cstr, int n) + { + if(!cstr) + throw NullPointerException("cstr"); + + if(n <= 0) + throw InvalidArgumentException("n"); + + + int l = ((int) strlen(cstr)) * n; + + if(capacity < len + l) + { + int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1; + + if(!(content = (char*) realloc(content, new_capacity))) + throw BadAllocException(); + + for(int i = 0; i < n; i++) + strcat(content, cstr); + + capacity = new_capacity; + } + else + { + for(int i = 0; i < n; i++) + strcat(content, cstr); + } + + len += l; + content[len] = '\0'; + + return *this; + + } + + StringHelper& StringHelper::append(const char* cstr, int pos, int n) + { + if(!cstr) + throw NullPointerException("cstr"); + + if(n <= 0) + throw InvalidArgumentException("n"); + + if(pos < 0 || pos >= (int)strlen(cstr) ) + throw OutOfBoundsException(pos); + + if(pos + n >= (int)strlen(cstr)) + throw OutOfBoundsException(pos, n); + + + char* toAppend = (char*) calloc(n + 1, sizeof(char)); + + strncpy(toAppend, cstr + pos, n); + + append(toAppend); + + free(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(const string& rstr) + { + append(rstr.c_str()); + return *this; + } + + StringHelper& StringHelper::append(const string& rstr, int n) + { + if(rstr.empty()) + throw NullPointerException("rstr"); + + if(n <= 0) + throw InvalidArgumentException("n"); + + + int l = ((int) rstr.size()) * n; + + if(capacity < len + l) + { + int new_capacity = (capacity << 1) < (len + l) ? (len + l) << 1 : capacity << 1; + + if(!(content = (char*) realloc(content, new_capacity))) + throw BadAllocException(); + + for(int i = 0; i < n; i++) + strcat(content, rstr.c_str()); + + capacity = new_capacity; + } + else + { + for(int i = 0; i < n; i++) + strcat(content, rstr.c_str()); + } + + len += l; + content[len] = '\0'; + + return *this; + } + + StringHelper& StringHelper::append(const string& rstr, int pos, int n) + { + if(rstr.empty()) + throw InvalidArgumentException("rstr"); + + if(n <= 0) + throw InvalidArgumentException("n"); + + if(pos < 0 || pos >= (int) rstr.size() ) + throw OutOfBoundsException(pos); + + if(pos + n >= (int) rstr.size()) + throw OutOfBoundsException(pos, n); + + + char* toAppend = (char*) calloc(n + 1, sizeof(char)); + + strncpy(toAppend, rstr.c_str() + pos, n); + + append(toAppend); + + free(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(short si) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%hd",si); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(int i) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%d",i); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(long l) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%ld",l); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(float f) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%f",f); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(double d) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%e",d); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(double d, const char* format) + { + char toAppend[BUFF_MAX + 1] = {0}; + + sprintf(toAppend, format, d); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(unsigned short usi) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%hu",usi); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(unsigned int ui) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%u",ui); + + append(toAppend); + + return *this; + } + + StringHelper& StringHelper::append(unsigned long ul) + { + char toAppend[26] = {0}; + + sprintf(toAppend, "%lu",ul); + + append(toAppend); + + return *this; + } + + const char& StringHelper::at(int pos) const + { + if(pos < 0 || pos >= len) + throw OutOfBoundsException(pos); + + return content[pos]; + } + + char& StringHelper::at(int pos) + { + if(pos < 0 || pos >= len) + throw OutOfBoundsException(pos); + + return content[pos]; + } + + const char* StringHelper::cstr(void) const + { + return (const char*)content; + } + + string& StringHelper::toString(void) + { + string* s = new string(); + s->append(content); + return *s; + } + + int StringHelper::size(void) const + { + return len; + } + + // Operators + + // Assignement + StringHelper& StringHelper::operator = (const StringHelper& rStringHelper) + { + + if(this !=&rStringHelper && rStringHelper.size()) + { + clear(); + append(rStringHelper.cstr()); + } + + return *this; + } + + StringHelper& StringHelper::operator = (const char* cstr) + { + clear(); + append(cstr); + return *this; + } + + StringHelper& StringHelper::operator = (const string& str) + { + clear(); + append(str); + return *this; + } + + StringHelper& StringHelper::operator = (short n) + { + clear(); + append(n); + return *this; + } + + StringHelper& StringHelper::operator = (int n) + { + clear(); + append(n); + return *this; + } + + StringHelper& StringHelper::operator = (long n) + { + clear(); + append(n); + return *this; + } + + StringHelper& StringHelper::operator = (float n) + { + clear(); + append(n); + return *this; + } + + StringHelper& StringHelper::operator = (double n) + { + clear(); + append(n); + return *this; + } + + StringHelper& StringHelper::operator = (unsigned short n) + { + clear(); + append(n); + return *this; + } + + StringHelper& StringHelper::operator = (unsigned int n) + { + clear(); + append(n); + return *this; + } + + StringHelper& StringHelper::operator = (unsigned long n) + { + clear(); + append(n); + return *this; + } + + char& StringHelper::operator[](int pos) + { + if(pos < 0 || pos >= len) + throw OutOfBoundsException(pos); + + return content[pos]; + } + + char StringHelper::operator[](int pos) const + { + if(pos < 0 || pos >= len) + throw OutOfBoundsException(pos); + + return content[pos]; + } + + StringHelper& StringHelper::operator += (short n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (int n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (long n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (float n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (double n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (unsigned short n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (unsigned int n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (unsigned long n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator += (const StringHelper& rStringHelper) + { + append(rStringHelper.content); + return *this; + } + + StringHelper& StringHelper::operator += (const string& rstr) + { + append(rstr.c_str()); + return *this; + } + + StringHelper& StringHelper::operator += (const char* cstr) + { + append(cstr); + return *this; + } + + StringHelper& StringHelper::operator += (char c) + { + append(c); + return *this; + } + + StringHelper& StringHelper::operator + (short n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator + (int n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator + (long n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator + (float n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator + (double n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator + (unsigned short n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator + (unsigned int n) + { + append(n); + return *this; + } + + StringHelper& StringHelper::operator + (unsigned long n) + { + append(n); + return *this; + } + + + StringHelper& StringHelper::operator + (const StringHelper& rStringHelper) + { + append(rStringHelper.content); + return *this; + } + + StringHelper& StringHelper::operator + (const string& rstr) + { + append(rstr.c_str()); + return *this; + } + + StringHelper& StringHelper::operator + (const char* cstr) + { + append(cstr); + return *this; + } + + StringHelper& StringHelper::operator + (char c) + { + append(c); + return *this; + } + + StringHelper::operator char *() + { + return content; + } + + StringHelper::operator const char *() + { + return content; + } + + ostream& operator<<(ostream& stream, const StringHelper& s) + { + stream << s.cstr(); + return stream; + } + + istream& operator<<(istream& stream, StringHelper& s) + { + char buff[256] = {0}; + + stream >> buff; + + s.append(buff); + + return stream; + } + + } // namespace Msg +} // namespace SimGrid + diff --git a/src/cxx/StringHelper.hpp b/src/cxx/StringHelper.hpp index a1675d327c..ebf3a8b95b 100644 --- a/src/cxx/StringHelper.hpp +++ b/src/cxx/StringHelper.hpp @@ -1,245 +1,246 @@ -/* - * StringHelper.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 STRING_HELPER_HPP -#define STRING_HELPER_HPP - - #ifndef __cplusplus - #error StringHelper.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include -using std::string; - -#include -using std::ostream; -using std::istream; - -#include - -// namespace SimGrid::Msg -namespace SimGrid -{ - namespace Msg - { - class SIMGRIDX_EXPORT StringHelper - { - public: - - // Default constructor - StringHelper(); - - StringHelper(unsigned char c); - - StringHelper(unsigned char c, int n); - - StringHelper(char c); - - StringHelper(char c, int n); - - StringHelper(const char* cstr); - - StringHelper(const char* cstr, int n); - - StringHelper(const char* cstr, int pos, int n); - - StringHelper(const string& rstr); - - StringHelper(const string& rstr, int n); - - StringHelper(const string& rstr, int pos, int n); - - StringHelper(short si); - - StringHelper(int i); - - StringHelper(long l); - - StringHelper(float f); - - StringHelper(double d); - - StringHelper(double d, const char* format); - - StringHelper(unsigned short usi); - - StringHelper(unsigned int ui); - - StringHelper(unsigned long ul); - - // Copy constructor - StringHelper(const StringHelper& rStringHelper); - - // Destructor - ~StringHelper(); - - // Operations - - StringHelper& append(unsigned char c); - - StringHelper& append(unsigned char c, int n); - - StringHelper& append(char c); - - StringHelper& append(char c, int n); - - StringHelper& append(const char* cstr); - - StringHelper& append(const char* cstr, int n); - - StringHelper& append(const char* cstr, int pos, int n); - - StringHelper& append(const string& rstr); - - StringHelper& append(const string& rstr, int n); - - StringHelper& append(const string& rstr, int pos, int n); - - StringHelper& append(short si); - - StringHelper& append(int i); - - StringHelper& append(long l); - - StringHelper& append(float f); - - StringHelper& append(double d); - - StringHelper& append(double d, const char* format); - - StringHelper& append(unsigned short usi); - - StringHelper& append(unsigned int ui); - - StringHelper& append(unsigned long ul); - - const char& at(int pos) const; - - char& at(int pos); - - const char* cstr(void) const; - - string& toString(void); - - int size(void) const; - - void clear(void); - - bool empty(void); - - // Operators - - // Assignement - StringHelper& operator = (const StringHelper& rStringHelper); - - StringHelper& operator = (const char* cstr); - - StringHelper& operator = (const string& str); - - StringHelper& operator = (short n); - - StringHelper& operator = (int n); - - StringHelper& operator = (long n); - - StringHelper& operator = (float n); - - StringHelper& operator = (double n); - - StringHelper& operator = (unsigned short n); - - StringHelper& operator = (unsigned int n); - - StringHelper& operator = (unsigned long n); - - char& operator[](int pos); - - char operator[](int pos) const; - - StringHelper& operator += (short n); - - StringHelper& operator += (int n); - - StringHelper& operator += (long n); - - StringHelper& operator += (float n); - - StringHelper& operator += (double n); - - StringHelper& operator += (unsigned short n); - - StringHelper& operator += (unsigned int n); - - StringHelper& operator += (unsigned long n); - - StringHelper& operator += (const StringHelper& rStringHelper); - - StringHelper& operator += (const string& rstr); - - StringHelper& operator += (const char* cstr); - - StringHelper& operator += (char c); - - StringHelper& operator + (short n); - - StringHelper& operator + (int n); - - StringHelper& operator + (long n); - - StringHelper& operator + (float n); - - StringHelper& operator + (double n); - - StringHelper& operator + (unsigned short n); - - StringHelper& operator + (unsigned int n); - - StringHelper& operator + (unsigned long n); - - StringHelper& operator + (const StringHelper& rStringHelper); - - StringHelper& operator + (const string& rstr); - - StringHelper& operator + (const char* cstr); - - StringHelper& operator + (char c); - - operator char *(); - - operator const char *(); - - friend SIMGRIDX_EXPORT ostream& operator<<(ostream& stream, const StringHelper& s); - - friend SIMGRIDX_EXPORT istream& operator<<(istream& stream, StringHelper& s); - - private: - - // Methods - void init(void); - - // Attributes - - char* content; - int capacity; - int len; - }; - - typedef class StringHelper* StringHelperPtr; - - #define TEXT_(___x) StringHelper((___x)) - - - } // namespace Msg -} // namespace SimGrid - - -#endif // !STRING_HELPER_HPP \ No newline at end of file +/* + * StringHelper.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 STRING_HELPER_HPP +#define STRING_HELPER_HPP + + #ifndef __cplusplus + #error StringHelper.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +using std::string; + +#include +using std::ostream; +using std::istream; + +#include + +// namespace SimGrid::Msg +namespace SimGrid +{ + namespace Msg + { + class SIMGRIDX_EXPORT StringHelper + { + public: + + // Default constructor + StringHelper(); + + StringHelper(unsigned char c); + + StringHelper(unsigned char c, int n); + + StringHelper(char c); + + StringHelper(char c, int n); + + StringHelper(const char* cstr); + + StringHelper(const char* cstr, int n); + + StringHelper(const char* cstr, int pos, int n); + + StringHelper(const string& rstr); + + StringHelper(const string& rstr, int n); + + StringHelper(const string& rstr, int pos, int n); + + StringHelper(short si); + + StringHelper(int i); + + StringHelper(long l); + + StringHelper(float f); + + StringHelper(double d); + + StringHelper(double d, const char* format); + + StringHelper(unsigned short usi); + + StringHelper(unsigned int ui); + + StringHelper(unsigned long ul); + + // Copy constructor + StringHelper(const StringHelper& rStringHelper); + + // Destructor + ~StringHelper(); + + // Operations + + StringHelper& append(unsigned char c); + + StringHelper& append(unsigned char c, int n); + + StringHelper& append(char c); + + StringHelper& append(char c, int n); + + StringHelper& append(const char* cstr); + + StringHelper& append(const char* cstr, int n); + + StringHelper& append(const char* cstr, int pos, int n); + + StringHelper& append(const string& rstr); + + StringHelper& append(const string& rstr, int n); + + StringHelper& append(const string& rstr, int pos, int n); + + StringHelper& append(short si); + + StringHelper& append(int i); + + StringHelper& append(long l); + + StringHelper& append(float f); + + StringHelper& append(double d); + + StringHelper& append(double d, const char* format); + + StringHelper& append(unsigned short usi); + + StringHelper& append(unsigned int ui); + + StringHelper& append(unsigned long ul); + + const char& at(int pos) const; + + char& at(int pos); + + const char* cstr(void) const; + + string& toString(void); + + int size(void) const; + + void clear(void); + + bool empty(void); + + // Operators + + // Assignement + StringHelper& operator = (const StringHelper& rStringHelper); + + StringHelper& operator = (const char* cstr); + + StringHelper& operator = (const string& str); + + StringHelper& operator = (short n); + + StringHelper& operator = (int n); + + StringHelper& operator = (long n); + + StringHelper& operator = (float n); + + StringHelper& operator = (double n); + + StringHelper& operator = (unsigned short n); + + StringHelper& operator = (unsigned int n); + + StringHelper& operator = (unsigned long n); + + char& operator[](int pos); + + char operator[](int pos) const; + + StringHelper& operator += (short n); + + StringHelper& operator += (int n); + + StringHelper& operator += (long n); + + StringHelper& operator += (float n); + + StringHelper& operator += (double n); + + StringHelper& operator += (unsigned short n); + + StringHelper& operator += (unsigned int n); + + StringHelper& operator += (unsigned long n); + + StringHelper& operator += (const StringHelper& rStringHelper); + + StringHelper& operator += (const string& rstr); + + StringHelper& operator += (const char* cstr); + + StringHelper& operator += (char c); + + StringHelper& operator + (short n); + + StringHelper& operator + (int n); + + StringHelper& operator + (long n); + + StringHelper& operator + (float n); + + StringHelper& operator + (double n); + + StringHelper& operator + (unsigned short n); + + StringHelper& operator + (unsigned int n); + + StringHelper& operator + (unsigned long n); + + StringHelper& operator + (const StringHelper& rStringHelper); + + StringHelper& operator + (const string& rstr); + + StringHelper& operator + (const char* cstr); + + StringHelper& operator + (char c); + + operator char *(); + + operator const char *(); + + friend SIMGRIDX_EXPORT ostream& operator<<(ostream& stream, const StringHelper& s); + + friend SIMGRIDX_EXPORT istream& operator<<(istream& stream, StringHelper& s); + + private: + + // Methods + void init(void); + + // Attributes + + char* content; + int capacity; + int len; + }; + + typedef class StringHelper* StringHelperPtr; + + #define TEXT_(___x) StringHelper((___x)) + + + } // namespace Msg +} // namespace SimGrid + + +#endif // !STRING_HELPER_HPP + diff --git a/src/cxx/Task.cxx b/src/cxx/Task.cxx index 93e1c68551..3c3dcca73f 100644 --- a/src/cxx/Task.cxx +++ b/src/cxx/Task.cxx @@ -1,542 +1,542 @@ -/* - * Task.cxx - * - * 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. - * - */ - - /* Task member functions implementation. - */ - -#include -#include - -#include - -#include -#include - -#include - -namespace SimGrid -{ - namespace Msg - { - - MSG_IMPLEMENT_DYNAMIC(Task, Object); - - Task::Task() - { - nativeTask = NULL; - } - - - Task::Task(const Task& rTask) - { - this->nativeTask = rTask.nativeTask; - } - - - Task::~Task() - throw(MsgException) - { - 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); - - - - this->nativeTask->data = (void*)this; - - } - - const char* Task::getName(void) const - { - return nativeTask->name; - } - - Process& Task::getSender(void) const - { - m_process_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 - { - 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); - } - - int Task::probe(int channel) - throw(InvalidArgumentException) - { - // check the parameters - - if(channel < 0) - throw InvalidArgumentException("channel (must not be negative)"); - - return 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(channel,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, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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(BadAllocException, 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, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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"); - } - - 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"); - } - - 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, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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"); - } - - Task* Task::receive(void) - throw(BadAllocException, MsgException) - { - char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName()); - - 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* 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 && timeout != -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 && timeout != -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); - } - - int Task::listen(void) - throw(BadAllocException) - { - char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName()); - - int rv = MSG_task_listen(alias); - - free(alias); - - return rv; - } - - int Task::listen(const char* alias) - throw(NullPointerException) - { - // check the parameters - - if(!alias) - throw NullPointerException("alias"); - - return MSG_task_listen(alias); - } - - int Task::listenFrom(void) - throw(BadAllocException) - { - char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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, sizeof(char)); - - if(!alias) - throw BadAllocException("alias"); - - sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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); - } - - const Task& Task::operator = (const Task& rTask) - { - this->nativeTask = rTask.nativeTask; - return *this; - } - } // namespace Msg -} // namespace SimGrid - +/* + * Task.cxx + * + * 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. + * + */ + + /* Task member functions implementation. + */ + +#include +#include + +#include + +#include +#include + +#include + +namespace SimGrid +{ + namespace Msg + { + + MSG_IMPLEMENT_DYNAMIC(Task, Object) + + Task::Task() + { + nativeTask = NULL; + } + + + Task::Task(const Task& rTask) + { + this->nativeTask = rTask.nativeTask; + } + + + Task::~Task() + throw(MsgException) + { + 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); + + + + this->nativeTask->data = (void*)this; + + } + + const char* Task::getName(void) const + { + return nativeTask->name; + } + + Process& Task::getSender(void) const + { + m_process_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 + { + 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); + } + + int Task::probe(int channel) + throw(InvalidArgumentException) + { + // check the parameters + + if(channel < 0) + throw InvalidArgumentException("channel (must not be negative)"); + + return 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(channel,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, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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(BadAllocException, 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, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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"); + } + + 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"); + } + + 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, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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"); + } + + Task* Task::receive(void) + throw(BadAllocException, MsgException) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName()); + + 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* 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 && timeout != -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 && timeout != -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); + } + + int Task::listen(void) + throw(BadAllocException) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName()); + + int rv = MSG_task_listen(alias); + + free(alias); + + return rv; + } + + int Task::listen(const char* alias) + throw(NullPointerException) + { + // check the parameters + + if(!alias) + throw NullPointerException("alias"); + + return MSG_task_listen(alias); + } + + int Task::listenFrom(void) + throw(BadAllocException) + { + char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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, sizeof(char)); + + if(!alias) + throw BadAllocException("alias"); + + sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().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); + } + + const Task& Task::operator = (const Task& rTask) + { + this->nativeTask = rTask.nativeTask; + return *this; + } + } // namespace Msg +} // namespace SimGrid + diff --git a/src/cxx/Task.hpp b/src/cxx/Task.hpp index e78d9dd67a..e8bfd38d16 100644 --- a/src/cxx/Task.hpp +++ b/src/cxx/Task.hpp @@ -1,540 +1,540 @@ -/* - * 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 - -// Compilation C++ recquise -#ifndef __cplusplus - #error Task.hpp requires C++ compilation (use a .cxx suffix) -#endif - -#include - -#include -#include -#include -#include -#include - -#include - -namespace SimGrid -{ - namespace Msg - { - class Process; - class Host; - - // SimGrid::Msg::Task wrapper class declaration. - class SIMGRIDX_EXPORT Task : public Object - { - MSG_DECLARE_DYNAMIC(Task); - - friend class Process; - friend class Host; - - 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 1. Otherwise - * the method returns 0. - * - * \exception If this method fails, it throws the exception described below: - * - * [InvalidArgumentException] if the parameter channel is negative. - */ - static int 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(BadAllocException, 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);*/ - - 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);*/ - 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 int 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 1. - * Otherwise the method returns 0. - * - * \exception If this method fails, it throws one of the exceptions described below: - * - * [NullPointerException] if the parameter alias is NULL. - */ - static int 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 int listenFromHost(const char* alias, const Host& rHost) - throw(NullPointerException); - - virtual const Task& operator= (const Task& rTask); - - protected: - - // Attributes. - - m_task_t nativeTask; // the native MSG task. - }; - - } // namespace Msg -} // namespace SimGrid - -typedef Task* TaskPtr; - -#endif // §MSG_TASK_HPP - +/* + * 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 + +// Compilation C++ recquise +#ifndef __cplusplus + #error Task.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +#include +#include +#include +#include +#include + +#include + +namespace SimGrid +{ + namespace Msg + { + class Process; + class Host; + + // SimGrid::Msg::Task wrapper class declaration. + class SIMGRIDX_EXPORT Task : public Object + { + MSG_DECLARE_DYNAMIC(Task); + + friend class Process; + friend class Host; + + 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 1. Otherwise + * the method returns 0. + * + * \exception If this method fails, it throws the exception described below: + * + * [InvalidArgumentException] if the parameter channel is negative. + */ + static int 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(BadAllocException, 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);*/ + + 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);*/ + 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 int 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 1. + * Otherwise the method returns 0. + * + * \exception If this method fails, it throws one of the exceptions described below: + * + * [NullPointerException] if the parameter alias is NULL. + */ + static int 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 int listenFromHost(const char* alias, const Host& rHost) + throw(NullPointerException); + + virtual const Task& operator= (const Task& rTask); + + protected: + + // Attributes. + + m_task_t nativeTask; // the native MSG task. + }; + + } // namespace Msg +} // namespace SimGrid + +typedef Task* TaskPtr; + +#endif // §MSG_TASK_HPP +