From 846b7de4a868bf8dc1270f76a01c33738576694d Mon Sep 17 00:00:00 2001 From: cherierm Date: Tue, 8 Jul 2008 08:51:27 +0000 Subject: [PATCH] Use pointers instead references. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5856 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/cxx/Application.cxx | 14 +-- src/cxx/Application.hpp | 13 +- src/cxx/ApplicationHandler.cxx | 21 +++- src/cxx/ApplicationHandler.hpp | 12 +- src/cxx/BadAllocException.cxx | 15 +++ src/cxx/BadAllocException.hpp | 5 + src/cxx/ClassNotFoundException.cxx | 15 +++ src/cxx/ClassNotFoundException.hpp | 5 + src/cxx/Config.hpp | 30 ++++- src/cxx/Environment.cxx | 13 +- src/cxx/Environment.hpp | 9 +- src/cxx/Exception.cxx | 16 +++ src/cxx/Exception.hpp | 5 + src/cxx/FileNotFoundException.cxx | 15 +++ src/cxx/FileNotFoundException.hpp | 5 + src/cxx/Host.cxx | 64 ++++------ src/cxx/Host.hpp | 52 ++++---- src/cxx/HostNotFoundException.cxx | 15 +++ src/cxx/HostNotFoundException.hpp | 6 + src/cxx/InvalidArgumentException.cxx | 16 +++ src/cxx/InvalidArgumentException.hpp | 5 + src/cxx/LogicException.cxx | 15 +++ src/cxx/LogicException.hpp | 6 + src/cxx/Msg.cxx | 32 ++++- src/cxx/Msg.hpp | 15 ++- src/cxx/MsgException.cxx | 15 +++ src/cxx/MsgException.hpp | 1 + src/cxx/NullPointerException.cxx | 15 +++ src/cxx/NullPointerException.hpp | 5 + src/cxx/Object.cxx | 20 ++- src/cxx/Object.hpp | 18 ++- src/cxx/Process.cxx | 178 ++++++++++----------------- src/cxx/Process.hpp | 75 ++++++----- src/cxx/ProcessNotFoundException.cxx | 15 +++ src/cxx/ProcessNotFoundException.hpp | 4 + src/cxx/Simulation.cxx | 9 +- src/cxx/Simulation.hpp | 6 +- src/cxx/Task.cxx | 101 +++++---------- src/cxx/Task.hpp | 63 +++------- 39 files changed, 557 insertions(+), 387 deletions(-) diff --git a/src/cxx/Application.cxx b/src/cxx/Application.cxx index e326494d26..ea249e6cbf 100644 --- a/src/cxx/Application.cxx +++ b/src/cxx/Application.cxx @@ -12,16 +12,11 @@ /* Application member functions implementation. */ - -#include - -#include -#include -#include -#include #include +#include + #include #include #include @@ -195,4 +190,7 @@ namespace SimGrid return *this; } } // namespace Msg -} // namespace SimGrid \ No newline at end of file +} // namespace SimGrid + + + diff --git a/src/cxx/Application.hpp b/src/cxx/Application.hpp index 7efe7a2073..c2818701f7 100644 --- a/src/cxx/Application.hpp +++ b/src/cxx/Application.hpp @@ -19,17 +19,15 @@ #error Application.hpp requires C++ compilation (use a .cxx suffix) #endif -#include +#include +#include +#include +#include namespace SimGrid { namespace Msg { - class NullPointerException; - class FileNotFoundException; - class LogicException; - class MsgException; - // Application wrapper class declaration. class SIMGRIDX_EXPORT Application { @@ -149,4 +147,5 @@ namespace SimGrid } // namespace Msg } // namespace SimGrid -#endif // !MSG_APPLICATION_HPP \ No newline at end of file +#endif // !MSG_APPLICATION_HPP + diff --git a/src/cxx/ApplicationHandler.cxx b/src/cxx/ApplicationHandler.cxx index 9be89078f8..3b48213267 100644 --- a/src/cxx/ApplicationHandler.cxx +++ b/src/cxx/ApplicationHandler.cxx @@ -13,13 +13,16 @@ /* ApplicationHandler member functions implementation. */ -#include #include -#include -#include -#include +#include + #include +#include + + + + #include @@ -107,7 +110,12 @@ namespace SimGrid 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() @@ -178,4 +186,5 @@ namespace SimGrid } } // namespace Msg -} // namespace SimGrid \ No newline at end of file +} // namespace SimGrid + diff --git a/src/cxx/ApplicationHandler.hpp b/src/cxx/ApplicationHandler.hpp index 6c3819b7eb..df91691d6c 100644 --- a/src/cxx/ApplicationHandler.hpp +++ b/src/cxx/ApplicationHandler.hpp @@ -23,21 +23,19 @@ #include #include -#include +#include +#include namespace SimGrid { namespace Msg { - - class ClassNotFoundException; - class HostNotFoundException; class Process; // Declaration of the class ApplicationHandler (Singleton). class SIMGRIDX_EXPORT ApplicationHandler { - friend Process; + //friend Process; public: @@ -66,7 +64,7 @@ namespace SimGrid ProcessFactory(const ProcessFactory& rProcessFactory); // Destructor. - virtual ~ProcessFactory(){} + virtual ~ProcessFactory(); // Set the identity of the current process. void setProcessIdentity(const char* hostName, const char* function); @@ -134,4 +132,4 @@ namespace SimGrid } // namespace SimGrid #endif // !MSG_APPLICATION_HANDLER_HPP - \ No newline at end of file + diff --git a/src/cxx/BadAllocException.cxx b/src/cxx/BadAllocException.cxx index d650141a49..265f5de4da 100644 --- a/src/cxx/BadAllocException.cxx +++ b/src/cxx/BadAllocException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/BadAllocException.hpp b/src/cxx/BadAllocException.hpp index ac4039fc97..b5726ee503 100644 --- a/src/cxx/BadAllocException.hpp +++ b/src/cxx/BadAllocException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_BADALLOCEXCEPTION_HPP #define MSG_BADALLOCEXCEPTION_HPP +#ifndef __cplusplus + #error BadAllocException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -62,3 +66,4 @@ namespace SimGrid #endif // !MSG_BADALLOCEXCEPTION_HPP + diff --git a/src/cxx/ClassNotFoundException.cxx b/src/cxx/ClassNotFoundException.cxx index e61bf539e1..236ba2ae25 100644 --- a/src/cxx/ClassNotFoundException.cxx +++ b/src/cxx/ClassNotFoundException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/ClassNotFoundException.hpp b/src/cxx/ClassNotFoundException.hpp index 84b4317b09..bc909701f9 100644 --- a/src/cxx/ClassNotFoundException.hpp +++ b/src/cxx/ClassNotFoundException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_CLASSNOTFOUNDEXCEPTION_HPP #define MSG_CLASSNOTFOUNDEXCEPTION_HPP +#ifndef __cplusplus + #error ClassNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -62,3 +66,4 @@ namespace SimGrid #endif // !MSG_CLASSNOTFOUNDEXCEPTION_HPP + diff --git a/src/cxx/Config.hpp b/src/cxx/Config.hpp index 837946e59d..0fc1e6fb52 100644 --- a/src/cxx/Config.hpp +++ b/src/cxx/Config.hpp @@ -1,15 +1,34 @@ + +/* + * 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) + #if defined(WIN32) && !defined(__MINGW32__) #if defined(SIMGRIDX_EXPORTS) #define SIMGRIDX_EXPORT __declspec(dllexport) #else - #define SIMGRIDX_EXPORT + #define SIMGRIDX_EXPORT __declspec(dllimport) #endif #else #define SIMGRIDX_EXPORT @@ -17,4 +36,9 @@ namespace SimGrid } // namespace Msg } // namespace SimGrid -#endif // MSG_CONFIG_HPP \ No newline at end of file +#ifndef WIN32 +#define _strdup strdup +#endif + +#endif // MSG_CONFIG_HPP + diff --git a/src/cxx/Environment.cxx b/src/cxx/Environment.cxx index 806e868860..71e0acf7aa 100644 --- a/src/cxx/Environment.cxx +++ b/src/cxx/Environment.cxx @@ -15,12 +15,6 @@ #include -#include -#include -#include -#include -#include - #include #include @@ -49,7 +43,7 @@ namespace SimGrid } Environment::Environment(const char* file) - throw(NullPointerException, InvalidArgumentException) + throw(NullPointerException, FileNotFoundException) { // check parameters @@ -59,7 +53,7 @@ namespace SimGrid struct stat statBuf = {0}; if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode)) - throw InvalidArgumentException("file (file not found)"); + throw FileNotFoundException("file (file not found)"); this->file = file; this->loaded = false; @@ -161,4 +155,5 @@ namespace SimGrid } } // namespace Msg -} // namespace SimGrid \ No newline at end of file +} // namespace SimGrid + diff --git a/src/cxx/Environment.hpp b/src/cxx/Environment.hpp index fb2a17b4b2..89f6e4863d 100644 --- a/src/cxx/Environment.hpp +++ b/src/cxx/Environment.hpp @@ -19,7 +19,11 @@ #error Environment.hpp requires C++ compilation (use a .cxx suffix) #endif -#include +#include +#include +#include +#include +#include namespace SimGrid { @@ -145,4 +149,5 @@ namespace SimGrid } // namespace SimGrid -#endif // !MSG_ENVIRONMENT_HPP \ No newline at end of file +#endif // !MSG_ENVIRONMENT_HPP + diff --git a/src/cxx/Exception.cxx b/src/cxx/Exception.cxx index 5e54f88b9d..94ae26e881 100644 --- a/src/cxx/Exception.cxx +++ b/src/cxx/Exception.cxx @@ -1,3 +1,19 @@ +/* + * 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 diff --git a/src/cxx/Exception.hpp b/src/cxx/Exception.hpp index c520ae6970..1b1a8ee5e7 100644 --- a/src/cxx/Exception.hpp +++ b/src/cxx/Exception.hpp @@ -13,6 +13,10 @@ #ifndef MSG_EXCEPTION_HPP #define MSG_EXCEPTION_HPP +#ifndef __cplusplus + #error Exception.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -61,3 +65,4 @@ namespace SimGrid #endif // !MSG_EXCEPTION_HPP + diff --git a/src/cxx/FileNotFoundException.cxx b/src/cxx/FileNotFoundException.cxx index d99519058f..297d60c827 100644 --- a/src/cxx/FileNotFoundException.cxx +++ b/src/cxx/FileNotFoundException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/FileNotFoundException.hpp b/src/cxx/FileNotFoundException.hpp index 639accd7ee..a7ddfbc1b5 100644 --- a/src/cxx/FileNotFoundException.hpp +++ b/src/cxx/FileNotFoundException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_FILENOTFOUND_HPP #define MSG_FILENOTFOUND_HPP +#ifndef __cplusplus + #error FileNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -62,3 +66,4 @@ namespace SimGrid #endif // !MSG_MSGEXCEPTION_HPP + diff --git a/src/cxx/Host.cxx b/src/cxx/Host.cxx index db4722bf45..18997ea5fb 100644 --- a/src/cxx/Host.cxx +++ b/src/cxx/Host.cxx @@ -11,17 +11,13 @@ */ /* Host class member functions implementation. - */ -#include - -#include -#include -#include -#include + */ #include #include +#include + #include #include @@ -53,11 +49,11 @@ namespace SimGrid Host& Host::getByName(const char* hostName) - throw(HostNotFoundException, InvalidArgumentException, BadAllocException) + throw(HostNotFoundException, NullPointerException, BadAllocException) { // check the parameters if(!hostName) - throw InvalidArgumentException("hostName"); + throw NullPointerException("hostName"); m_host_t nativeHost = NULL; // native host. Host* host = NULL; // wrapper host. @@ -193,17 +189,6 @@ namespace SimGrid return SIMIX_host_get_state(nativeHost->simdata->smx_host); } - void Host::put(int channel, const Task& rTask) - 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(rTask.nativeTask, nativeHost, channel , -1.0)) - throw MsgException("MSG_task_put_with_timeout() failed"); - } - void Host::put(int channel, Task* task) throw(MsgException, InvalidArgumentException) { @@ -214,8 +199,8 @@ namespace SimGrid 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, const Task& rTask, double timeout) + + void Host::put(int channel, Task* task, double timeout) throw(MsgException, InvalidArgumentException) { // checks the parameters @@ -226,11 +211,11 @@ namespace SimGrid throw InvalidArgumentException("timeout (must be more or equal to zero or equal to -1.0)"); - if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , timeout)) + 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, const Task& rTask, double maxRate) + void Host::putBounded(int channel, Task* task, double maxRate) throw(MsgException, InvalidArgumentException) { // checks the parameters @@ -240,12 +225,12 @@ namespace SimGrid 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(rTask.nativeTask, nativeHost, channel, maxRate)) + if(MSG_OK != MSG_task_put_bounded(task->nativeTask, nativeHost, channel, maxRate)) throw MsgException("MSG_task_put_bounded() failed"); } - void Host::send(const Task& rTask) - throw(MsgException) + void Host::send(Task* task) + throw(MsgException, BadAllocException) { MSG_error_t rv; @@ -256,7 +241,7 @@ namespace SimGrid sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); - rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0); + rv = MSG_task_send_with_timeout(task->nativeTask, alias, -1.0); free(alias); @@ -264,18 +249,18 @@ namespace SimGrid throw MsgException("MSG_task_send_with_timeout() failed"); } - void Host::send(const char* alias, const Task& rTask) + 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(rTask.nativeTask, alias, -1.0)) + if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias, -1.0)) throw MsgException("MSG_task_send_with_timeout() failed"); } - void Host::send(const Task& rTask, double timeout) + void Host::send(Task* task, double timeout) throw(InvalidArgumentException, BadAllocException, MsgException) { // check the parameters @@ -292,7 +277,7 @@ namespace SimGrid sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); - rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout); + rv = MSG_task_send_with_timeout(task->nativeTask, alias, timeout); free(alias); @@ -300,7 +285,7 @@ namespace SimGrid throw MsgException("MSG_task_send_with_timeout() failed"); } - void Host::send(const char* alias, const Task& rTask, double timeout) + void Host::send(const char* alias, Task* task, double timeout) throw(InvalidArgumentException, MsgException) { // check the parameter @@ -311,12 +296,12 @@ namespace SimGrid 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(rTask.nativeTask, alias, timeout)) + if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias, timeout)) throw MsgException("MSG_task_send_with_timeout() failed"); } - void Host::sendBounded(const Task& rTask, double maxRate) + void Host::sendBounded(Task* task, double maxRate) throw(InvalidArgumentException, BadAllocException, MsgException) { if(maxRate < 0 && maxRate != -1.0) @@ -331,7 +316,7 @@ namespace SimGrid sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName()); - rv = MSG_task_send_bounded(rTask.nativeTask, alias, maxRate); + rv = MSG_task_send_bounded(task->nativeTask, alias, maxRate); free(alias); @@ -339,7 +324,7 @@ namespace SimGrid throw MsgException("MSG_task_send_bounded() failed"); } - void Host::sendBounded(const char* alias, const Task& rTask, double maxRate) + void Host::sendBounded(const char* alias, Task* task, double maxRate) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -349,9 +334,10 @@ namespace SimGrid 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(rTask.nativeTask, alias, maxRate)) + if(MSG_OK != MSG_task_send_bounded(task->nativeTask, alias, maxRate)) throw MsgException("MSG_task_send_bounded() failed"); } } // namspace Msg -} // namespace SimGrid \ No newline at end of file +} // namespace SimGrid + diff --git a/src/cxx/Host.hpp b/src/cxx/Host.hpp index 881bebbdbe..1c18f0dd8a 100644 --- a/src/cxx/Host.hpp +++ b/src/cxx/Host.hpp @@ -54,7 +54,11 @@ catch(HostNotFoundException e) #include -#include +#include +#include +#include +#include + // namespace SimGrid::Msg @@ -62,19 +66,14 @@ namespace SimGrid { namespace Msg { - class InvalidArgumentException; - class BadAllocException; - class HostNotFoundException; - class MsgException; - class Task; class Process; // Declaration of the class SimGrid::Msg::Host. class SIMGRIDX_EXPORT Host // final class. { - friend Process; - friend Task; + 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(). @@ -112,7 +111,7 @@ namespace SimGrid * [BadAllocException] if there is not enough memory to allocate the host. */ static Host& getByName(const char* hostName) - throw(HostNotFoundException, InvalidArgumentException, BadAllocException); + throw(HostNotFoundException, NullPointerException, BadAllocException); /*! \brief Host::getNumber() - returns the number of the installed hosts. * @@ -128,8 +127,7 @@ namespace SimGrid * * \see Process::currentProcess(). */ - static Host& currentHost(void) - throw(InvalidArgumentException, BadAllocException); + static Host& currentHost(void); /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform. * @@ -195,7 +193,8 @@ namespace SimGrid * delete[] ar; * */ - static void all(Host*** hosts /*in|out*/, int* len /*in|out*/); + 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. * @@ -257,10 +256,7 @@ namespace SimGrid * [InvalidArgumentException] if the value of the channel specified as * parameter is negative. */ - void put(int channel, const Task& rTask) - throw(MsgException, InvalidArgumentException); - - void Host::put(int channel, Task* task) + 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). @@ -280,7 +276,7 @@ namespace SimGrid * * \remark To specify no timeout set the timeout value with -1.0. */ - void put(int channel, const Task& rTask, double timeout) + 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). @@ -300,7 +296,7 @@ namespace SimGrid * * \remark To specify no rate set the maxRate parameter value with -1.0. */ - void putBounded(int channel, const Task& rTask, double maxRate) + 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. @@ -314,8 +310,8 @@ namespace SimGrid * the default alias variable. * [MsgException] if an internal error occurs. */ - void send(const Task& rTask) - throw(BadAllocException, MsgException); + void send(Task* task) + throw(MsgException, BadAllocException); /* ! brief Host::send() - sends the given task to mailbox identified by the specified alias parameter. * @@ -330,8 +326,8 @@ namespace SimGrid * the default alias variable. * [MsgException] if an internal error occurs. */ - void send(const char* alias, const Task& rTask) - throw(InvalidArgumentException, BadAllocException, MsgException); + 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). @@ -352,8 +348,8 @@ namespace SimGrid * version of this method. * */ - void send(const Task& rTask, double timeout) - throw(MsgException); + 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). @@ -373,7 +369,7 @@ namespace SimGrid * version of this method. * */ - void send(const char* alias, const Task& rTask, double timeout) + 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 @@ -394,7 +390,7 @@ namespace SimGrid * \remark To specify no rate set its value with -1.0. * */ - void sendBounded(const Task& rTask, double maxRate) + void sendBounded(Task* task, double maxRate) throw(InvalidArgumentException, BadAllocException, MsgException); /* ! brief Host::sendBounded() - sends the given task to mailbox identified by the parameter alias @@ -414,7 +410,7 @@ namespace SimGrid * \remark To specify no rate set its value with -1.0. * */ - void sendBounded(const char* alias, const Task& rTask, double maxRate) + void sendBounded(const char* alias, Task* task, double maxRate) throw(InvalidArgumentException, MsgException); protected: @@ -440,4 +436,4 @@ namespace SimGrid } // namespace Msg } // namespace SimGrid -#endif // !MSG_HOST_HPP \ No newline at end of file +#endif // !MSG_HOST_HPP diff --git a/src/cxx/HostNotFoundException.cxx b/src/cxx/HostNotFoundException.cxx index 8f0c47674b..c2b9211ada 100644 --- a/src/cxx/HostNotFoundException.cxx +++ b/src/cxx/HostNotFoundException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/HostNotFoundException.hpp b/src/cxx/HostNotFoundException.hpp index 17f4603050..a810d04663 100644 --- a/src/cxx/HostNotFoundException.hpp +++ b/src/cxx/HostNotFoundException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_HOSTNOTFOUNDEXCEPTION_HPP #define MSG_HOSTNOTFOUNDEXCEPTION_HPP +#ifndef __cplusplus + #error HostNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -62,3 +66,5 @@ namespace SimGrid #endif // !MSG_HOSTNOTFOUNDEXCEPTION_HPP + + diff --git a/src/cxx/InvalidArgumentException.cxx b/src/cxx/InvalidArgumentException.cxx index 2500b8317b..dc44244c37 100644 --- a/src/cxx/InvalidArgumentException.cxx +++ b/src/cxx/InvalidArgumentException.cxx @@ -1,3 +1,19 @@ +/* + * 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 diff --git a/src/cxx/InvalidArgumentException.hpp b/src/cxx/InvalidArgumentException.hpp index 6c72f8ebb2..fc4b2011d6 100644 --- a/src/cxx/InvalidArgumentException.hpp +++ b/src/cxx/InvalidArgumentException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_INVALIDARGUMENTEXCEPTION_HPP #define MSG_INVALIDARGUMENTEXCEPTION_HPP +#ifndef __cplusplus + #error InvalidArgumentException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -62,3 +66,4 @@ namespace SimGrid #endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP + diff --git a/src/cxx/LogicException.cxx b/src/cxx/LogicException.cxx index 3cd0390e0c..e1594f2ce9 100644 --- a/src/cxx/LogicException.cxx +++ b/src/cxx/LogicException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/LogicException.hpp b/src/cxx/LogicException.hpp index a39d7b9dfb..a3574391f3 100644 --- a/src/cxx/LogicException.hpp +++ b/src/cxx/LogicException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_LOGICEXCEPTION_HPP #define MSG_LOGICEXCEPTION_HPP +#ifndef __cplusplus + #error LogicException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -62,3 +66,5 @@ namespace SimGrid #endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP + + diff --git a/src/cxx/Msg.cxx b/src/cxx/Msg.cxx index 20521cdad7..443ac6b2f9 100644 --- a/src/cxx/Msg.cxx +++ b/src/cxx/Msg.cxx @@ -14,23 +14,28 @@ /* Msg functions implementation. */ -#include + #include #include +#include #include -// XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(SimGridX); + + namespace SimGrid { namespace Msg { + #define SIMGRIDX_DEFAULT_CHANNEL_NUMBER ((int)10) void init(int argc, char** argv) { MSG_global_init(&argc,argv); - MSG_set_channel_number(10); // FIXME: this should not be fixed statically + + if(getMaxChannelNumber() == 0) + setMaxChannelNumber(SIMGRIDX_DEFAULT_CHANNEL_NUMBER); } void finalize(void) @@ -38,6 +43,7 @@ namespace SimGrid { if(MSG_OK != MSG_clean()) throw MsgException("MSG_clean() failed"); + } void info(const char* s) @@ -51,6 +57,24 @@ namespace SimGrid 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 \ No newline at end of file +} // namespace SimGrid + diff --git a/src/cxx/Msg.hpp b/src/cxx/Msg.hpp index 3e26478018..2ed2f96e29 100644 --- a/src/cxx/Msg.hpp +++ b/src/cxx/Msg.hpp @@ -20,13 +20,18 @@ #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). * @@ -53,8 +58,14 @@ namespace SimGrid * \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 \ No newline at end of file +#endif // !MSG_HPP diff --git a/src/cxx/MsgException.cxx b/src/cxx/MsgException.cxx index cd1830838a..891588feea 100644 --- a/src/cxx/MsgException.cxx +++ b/src/cxx/MsgException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/MsgException.hpp b/src/cxx/MsgException.hpp index a8f576b05c..7d978f33dc 100644 --- a/src/cxx/MsgException.hpp +++ b/src/cxx/MsgException.hpp @@ -62,3 +62,4 @@ namespace SimGrid #endif // !MSG_MSGEXCEPTION_HPP + diff --git a/src/cxx/NullPointerException.cxx b/src/cxx/NullPointerException.cxx index e672c66914..79aac802b6 100644 --- a/src/cxx/NullPointerException.cxx +++ b/src/cxx/NullPointerException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/NullPointerException.hpp b/src/cxx/NullPointerException.hpp index a7ce0ea023..659e3adc9d 100644 --- a/src/cxx/NullPointerException.hpp +++ b/src/cxx/NullPointerException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_NULLPOINTEREXCEPTION_HPP #define MSG_NULLPOINTEREXCEPTION_HPP +#ifndef __cplusplus + #error NullPointerException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid @@ -62,3 +66,4 @@ namespace SimGrid #endif // !MSG_NULLPOINTEREXCEPTION_HPP + diff --git a/src/cxx/Object.cxx b/src/cxx/Object.cxx index 3d649a19e6..5d91680c69 100644 --- a/src/cxx/Object.cxx +++ b/src/cxx/Object.cxx @@ -1,10 +1,28 @@ +/* + * 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; +DeclaringClasses* DeclaringClass::declaringClasses = NULL; + namespace SimGrid { namespace Msg diff --git a/src/cxx/Object.hpp b/src/cxx/Object.hpp index 660f4eb0fc..d44ff2b655 100644 --- a/src/cxx/Object.hpp +++ b/src/cxx/Object.hpp @@ -1,4 +1,16 @@ - +/* + * 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 @@ -27,7 +39,7 @@ namespace SimGrid public: \ static Class class##class_name; \ virtual Class* getClass() const; \ - static Object* createObject(); \ + static Object* createObject() \ // The runtime class implementation. #define MSG_IMPLEMENT_CLASS(class_name, base_class_name, pfn,class_init) \ @@ -227,6 +239,8 @@ namespace SimGrid unsigned int count; }; + typedef Object* ObjectPtr; + // Constructor (Add the class in the list). inline DeclaringClass::DeclaringClass(Class* c) diff --git a/src/cxx/Process.cxx b/src/cxx/Process.cxx index bceac3298d..856ce5e842 100644 --- a/src/cxx/Process.cxx +++ b/src/cxx/Process.cxx @@ -1,12 +1,19 @@ -#include +/* + * 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 @@ -21,6 +28,7 @@ #include + namespace SimGrid { namespace Msg @@ -35,7 +43,7 @@ namespace SimGrid } Process::Process(const char* hostName, const char* name) - throw(InvalidArgumentException, HostNotFoundException) + throw(NullPointerException, HostNotFoundException, BadAllocException) { // check the parameters @@ -81,7 +89,7 @@ namespace SimGrid } Process::Process(const char* hostName, const char* name, int argc, char** argv) - throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException) + throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException) { // check the parameters @@ -223,7 +231,7 @@ namespace SimGrid } - void Process::putTask(const Host& rHost, int channel, const Task& rTask) + void Process::putTask(const Host& rHost, int channel, Task* task) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -231,11 +239,11 @@ namespace SimGrid if(channel < 0) throw InvalidArgumentException("channel (must not be negative)"); - if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, -1.0)) + 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, const Task& rTask, double timeout) + void Process::putTask(const Host& rHost, int channel, Task* task, double timeout) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -245,11 +253,11 @@ namespace SimGrid if(timeout < 0 && timeout != -1.0) throw InvalidArgumentException("timeout (must not be less than zero an different of -1.0)"); - if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, timeout)) + 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) + Task* Process::getTask(int channel) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -262,10 +270,10 @@ namespace SimGrid if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, NULL)) throw MsgException("MSG_task_get_ext() failed"); - return (*((Task*)(nativeTask->data))); + return (Task*)(nativeTask->data); } - Task& Process::getTask(int channel, double timeout) + Task* Process::getTask(int channel, double timeout) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -280,10 +288,10 @@ namespace SimGrid if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, NULL)) throw MsgException("MSG_task_get_ext() failed"); - return (*((Task*)(nativeTask->data))); + return (Task*)(nativeTask->data); } - Task& Process::getTask(int channel, const Host& rHost) + Task* Process::getTask(int channel, const Host& rHost) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -295,10 +303,10 @@ namespace SimGrid if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, rHost.nativeHost)) throw MsgException("MSG_task_get_ext() failed"); - return (*((Task*)(nativeTask->data))); + return (Task*)(nativeTask->data); } - Task& Process::getTask(int channel, double timeout, const Host& rHost) + Task* Process::getTask(int channel, double timeout, const Host& rHost) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -313,10 +321,10 @@ namespace SimGrid if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, rHost.nativeHost)) throw MsgException("MSG_task_get_ext() failed"); - return (*((Task*)(nativeTask->data))); + return (Task*)(nativeTask->data); } - void Process::sendTask(const char* alias, const Task& rTask, double timeout) + void Process::sendTask(const char* alias, Task* task, double timeout) throw(NullPointerException, InvalidArgumentException, MsgException) { // check the parameters @@ -327,12 +335,12 @@ namespace SimGrid if(timeout < 0 && timeout !=-1.0) throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)"); - if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout)) + 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, const Task& rTask) + void Process::sendTask(const char* alias, Task* task) throw(NullPointerException, MsgException) { // check the parameters @@ -340,11 +348,11 @@ namespace SimGrid if(!alias) throw NullPointerException("alias"); - if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0)) + if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0)) throw MsgException("MSG_task_send_with_timeout()"); } - void Process::sendTask(const Task& rTask) + void Process::sendTask(Task* task) throw(BadAllocException, MsgException) { char* alias = (char*)calloc( strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); @@ -354,7 +362,7 @@ namespace SimGrid sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - MSG_error_t rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0); + MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0); free(alias); @@ -362,7 +370,7 @@ namespace SimGrid throw MsgException("MSG_task_send_with_timeout()"); } - void Process::sendTask(const Task& rTask, double timeout) + void Process::sendTask(Task* task, double timeout) throw(BadAllocException, InvalidArgumentException, MsgException) { // check the parameters @@ -377,7 +385,7 @@ namespace SimGrid sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name); - MSG_error_t rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout); + MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,timeout); free(alias); @@ -385,7 +393,7 @@ namespace SimGrid throw MsgException("MSG_task_send_with_timeout()"); } - Task& Process::receiveTask(const char* alias) + Task* Process::receiveTask(const char* alias) throw(NullPointerException, MsgException) { // check the parameters @@ -398,11 +406,11 @@ namespace SimGrid if (MSG_OK != MSG_task_receive_ext(&nativeTask,alias, -1.0, NULL)) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Process::receiveTask(void) + Task* Process::receiveTask(void) throw(BadAllocException, MsgException) { @@ -422,11 +430,11 @@ namespace SimGrid if(MSG_OK != rv) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Process::receiveTask(const char* alias, double timeout) + Task* Process::receiveTask(const char* alias, double timeout) throw(NullPointerException, InvalidArgumentException, MsgException) { // check the parameters @@ -442,11 +450,11 @@ namespace SimGrid if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Process::receiveTask(double timeout) + Task* Process::receiveTask(double timeout) throw(InvalidArgumentException, BadAllocException, MsgException) { // check the parameters @@ -471,11 +479,11 @@ namespace SimGrid if(MSG_OK != rv) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Process::receiveTask(const char* alias, double timeout, const Host& rHost) + Task* Process::receiveTask(const char* alias, double timeout, const Host& rHost) throw(NullPointerException, InvalidArgumentException, MsgException) { // check the parameters @@ -491,11 +499,11 @@ namespace SimGrid if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Process::receiveTask(double timeout, const Host& rHost) + Task* Process::receiveTask(double timeout, const Host& rHost) throw(BadAllocException, InvalidArgumentException, MsgException) { // check the parameters @@ -519,11 +527,11 @@ namespace SimGrid if(MSG_OK != rv) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Process::receiveTask(const char* alias, const Host& rHost) + Task* Process::receiveTask(const char* alias, const Host& rHost) throw(NullPointerException, MsgException) { @@ -537,10 +545,10 @@ namespace SimGrid if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Process::receiveTask(const Host& rHost) + Task* Process::receiveTask(const Host& rHost) throw(BadAllocException, MsgException) { char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char)); @@ -559,67 +567,8 @@ namespace SimGrid if(MSG_OK != rv) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - - /*void Process::create(const Host& rHost, const char* name, int argc, char** argv) - throw(HostNotFoundException) - { - smx_process_t nativeCurrentProcess = NULL; - - // allocate the native process - this->nativeProcess = xbt_new0(s_smx_process_t, 1); - - // allocate the simulation data of the native process - smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1); - - // try to retrieve the host where to createt the process from its name - smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName()); - - if(!nativeHost) - throw HostNotFoundException(rHost.getName()); - - // realloc the list of the argument to add the pointer to this process instance at the end - argv = (char**)realloc(argc + 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; - - // Simulator Data - simdata->smx_host = nativeHost; - simdata->mutex = NULL; - simdata->cond = NULL; - simdata->argc = argc; - simdata->argv = argv; - - // create the context of the process. - simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv); - - // Process structure - this->nativeProcess->name = xbt_strdup(name); - this->nativeProcess->simdata = simdata; - - // Set process data - this->nativeProcess->data = NULL; - - // Set process properties - simdata->properties = NULL; - - xbt_swag_insert(this->nativeProcess, nativeHost->simdata->process_list); - - // fix current_process, about which xbt_context_start mocks around - nativeCurrentProcess = simix_global->current_process; - xbt_context_start(this->nativeProcess->simdata->context); - simix_global->current_process = nativeCurrentProcess; - - xbt_swag_insert(this->nativeProcess, simix_global->process_list); - DEBUG2("Inserting %s(%s) in the to_run list", this->nativeProcess->name, nativeHost->name); - xbt_swag_insert(this->nativeProcess, simix_global->process_to_run); - }*/ void Process::create(const Host& rHost, const char* name, int argc, char** argv) throw(InvalidArgumentException) @@ -684,9 +633,7 @@ namespace SimGrid mailbox = MSG_mailbox_new(alias); - MSG_mailbox_set_hostname(mailbox, this->nativeProcess->simdata->m_host->simdata->smx_host->name); - - + MSG_mailbox_set_hostname(mailbox, this->nativeProcess->simdata->m_host->simdata->smx_host->name); } Process* Process::fromNativeProcess(m_process_t nativeProcess) @@ -698,7 +645,7 @@ namespace SimGrid { // the last argument of the process is the pointer to the process to run - // for mor detail see Process::create() method + // for more detail see Process::create() method return ((Process*)argv[argc])->main(argc, argv); } @@ -706,7 +653,18 @@ namespace SimGrid { 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 \ No newline at end of file +} // namespace SimGrid + diff --git a/src/cxx/Process.hpp b/src/cxx/Process.hpp index bd45c70113..5bc46e5190 100644 --- a/src/cxx/Process.hpp +++ b/src/cxx/Process.hpp @@ -23,18 +23,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + namespace SimGrid { namespace Msg { - class NullPointerException; - class HostNotFoundException; - class ProcessNotFoundException; - class InvalidArgumentException; - class BadAllocException; - class LogicException; - class MsgException; - class ApplicationHandler; class Host; class Task; @@ -42,12 +42,12 @@ namespace SimGrid // SimGrid::Msg::Process class declaration. class SIMGRIDX_EXPORT Process : public Object { - - friend ApplicationHandler::ProcessFactory; + friend class ApplicationHandler::ProcessFactory; MSG_DECLARE_DYNAMIC(Process); public: + // Disable the default constructor. Process(); @@ -65,7 +65,7 @@ namespace SimGrid * [HostNotFoundException] if the host is not found. */ Process(const char* hostName, const char* name) - throw(NullPointerException, HostNotFoundException); + throw(NullPointerException, HostNotFoundException, BadAllocException); /*! \brief Constructs a process from a reference to an host object and its name. * @@ -126,7 +126,7 @@ namespace SimGrid * [HostNotFoundException] if the specified host is no found. */ Process(const char* hostName, const char* name, int argc, char** argv) - throw(NullPointerException, HostNotFoundException); + throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException); /*! \brief Process::killAll() - kill all the running processes of the simulation. * @@ -267,7 +267,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - void putTask(const Host& rHost, int channel, const Task& rTask) + 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). @@ -282,7 +282,7 @@ namespace SimGrid * * \remark Set the timeout with -1.0 to disable it. */ - void putTask(const Host& rHost, int channel, const Task& rTask, double timeout) + 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). @@ -297,7 +297,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& getTask(int channel) + Task* getTask(int channel) throw(InvalidArgumentException, MsgException); /*! \brief Process::taskGet() - Retrieves a task from a channel number (waiting at most given time). @@ -314,7 +314,7 @@ namespace SimGrid * zero and different of -1.0. * [MsgException] if an internal exception occurs. */ - Task& getTask(int channel, double timeout) + Task* getTask(int channel, double timeout) throw(InvalidArgumentException, MsgException); /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host. @@ -329,7 +329,7 @@ namespace SimGrid * \exception [InvalidArgumentException] if the channel number is negative. * [MsgException] if an internal exception occurs. */ - Task& getTask(int channel, const Host& rHost) + 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). @@ -349,7 +349,7 @@ namespace SimGrid * * \remark Set the timeout with -1.0 to disable it. */ - Task& getTask(int channel, double timeout, const Host& rHost) + 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 @@ -369,7 +369,7 @@ namespace SimGrid * * \remark Set the timeout with -1.0 to disable it. */ - void sendTask(const char* alias, const Task& rTask, double timeout) + 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. @@ -384,7 +384,7 @@ namespace SimGrid * [MsgException] if an internal exception occurs. * */ - void sendTask(const char* alias, const Task& rTask) + 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. @@ -398,7 +398,7 @@ namespace SimGrid * [MsgException] if an internal exception occurs. * */ - void sendTask(const Task& rTask) + void sendTask(Task* task) throw(BadAllocException, MsgException); /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias @@ -417,7 +417,7 @@ namespace SimGrid * * \remark set the timeout value with -1.0 to disable it. */ - void sendTask(const Task& rTask, double timeout) + 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 @@ -432,7 +432,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& receiveTask(const char* alias) + Task* receiveTask(const char* alias) throw(NullPointerException, MsgException); /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias. @@ -443,7 +443,7 @@ namespace SimGrid * \exception [BadAllocException] if there is not enough memory to build the alias. * [MsgException] if an internal exception occurs. */ - Task& receiveTask(void) + Task* receiveTask(void) throw(BadAllocException, MsgException); /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as @@ -461,7 +461,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& receiveTask(const char* alias, double timeout) + 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 @@ -478,7 +478,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& receiveTask(double timeout) + Task* receiveTask(double timeout) throw(InvalidArgumentException, BadAllocException, MsgException); /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as @@ -497,7 +497,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& receiveTask(const char* alias, double timeout, const Host& rHost) + 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 @@ -515,7 +515,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& receiveTask(double timeout, const Host& rHost) + Task* receiveTask(double timeout, const Host& rHost) throw(BadAllocException, InvalidArgumentException, MsgException); /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias @@ -531,7 +531,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& receiveTask(const char* alias, const Host& rHost) + Task* receiveTask(const char* alias, const Host& rHost) throw(NullPointerException, MsgException); /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias @@ -546,7 +546,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - Task& receiveTask(const Host& rHost) + Task* receiveTask(const Host& rHost) throw(BadAllocException, MsgException); @@ -564,7 +564,7 @@ namespace SimGrid * [HostNotFoundException] if the host specified as parameter doesn't exist. */ void create(const Host& rHost, const char* name, int argc, char** argv) - throw(HostNotFoundException); + throw(InvalidArgumentException); /* Process::fromNativeProcess() - Retrieves the process wrapper associated with a native process. * @@ -590,6 +590,16 @@ namespace SimGrid * \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: @@ -603,4 +613,5 @@ namespace SimGrid } // namespace SimGrid -#endif // !MSG_PROCESS_HPP \ No newline at end of file +#endif // !MSG_PROCESS_HPP + diff --git a/src/cxx/ProcessNotFoundException.cxx b/src/cxx/ProcessNotFoundException.cxx index bae42a3956..2da654afd0 100644 --- a/src/cxx/ProcessNotFoundException.cxx +++ b/src/cxx/ProcessNotFoundException.cxx @@ -1,3 +1,18 @@ +/* + * 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 diff --git a/src/cxx/ProcessNotFoundException.hpp b/src/cxx/ProcessNotFoundException.hpp index 6e8bc6efdd..9e29e0055f 100644 --- a/src/cxx/ProcessNotFoundException.hpp +++ b/src/cxx/ProcessNotFoundException.hpp @@ -13,6 +13,10 @@ #ifndef MSG_PROCESSNOTFOUNDEXCEPTION_HPP #define MSG_PROCESSNOTFOUNDEXCEPTION_HPP +#ifndef __cplusplus + #error ProcessNotFoundException.hpp requires C++ compilation (use a .cxx suffix) +#endif + #include namespace SimGrid diff --git a/src/cxx/Simulation.cxx b/src/cxx/Simulation.cxx index 34ee0fd20b..0697760e74 100644 --- a/src/cxx/Simulation.cxx +++ b/src/cxx/Simulation.cxx @@ -13,16 +13,15 @@ /* Simulation member functions implementation. */ -#include #include #include -#include -#include - #include +#include + + #include namespace SimGrid @@ -105,3 +104,5 @@ namespace SimGrid } } // namespace Msg } // namespace SimGrid + + diff --git a/src/cxx/Simulation.hpp b/src/cxx/Simulation.hpp index de97d90e0c..631cc30c96 100644 --- a/src/cxx/Simulation.hpp +++ b/src/cxx/Simulation.hpp @@ -19,7 +19,8 @@ #error Sumulation.hpp requires C++ compilation (use a .cxx suffix) #endif -#include +#include +#include namespace SimGrid { @@ -56,4 +57,5 @@ namespace SimGrid } // namespace Msg } // namespace SimGrid -#endif // !MSG_SIMULATION_HPP \ No newline at end of file +#endif // !MSG_SIMULATION_HPP + diff --git a/src/cxx/Task.cxx b/src/cxx/Task.cxx index b0c2ccbda3..93e1c68551 100644 --- a/src/cxx/Task.cxx +++ b/src/cxx/Task.cxx @@ -1,14 +1,23 @@ -#include - -#include -#include -#include -#include -#include +/* + * 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 @@ -150,22 +159,6 @@ namespace SimGrid 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) throw(InvalidArgumentException, MsgException) @@ -183,7 +176,7 @@ namespace SimGrid return ((Task*)(nativeTask->data)); } - Task& Task::get(int channel, const Host& rHost) + Task* Task::get(int channel, const Host& rHost) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -197,10 +190,10 @@ namespace SimGrid if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost)) throw MsgException("MSG_task_get_ext() failed"); - return (*((Task*)(nativeTask->data))); + return (Task*)(nativeTask->data); } - Task& Task::get(int channel, double timeout, const Host& rHost) + Task* Task::get(int channel, double timeout, const Host& rHost) throw(InvalidArgumentException, MsgException) { // check the parameters @@ -217,7 +210,7 @@ namespace SimGrid if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost)) throw MsgException("MSG_task_get_ext() failed"); - return (*((Task*)(nativeTask->data))); + return (Task*)(nativeTask->data); } int Task::probe(int channel) @@ -363,28 +356,6 @@ namespace SimGrid 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(void) throw(BadAllocException, MsgException) @@ -405,24 +376,8 @@ namespace SimGrid if(MSG_OK != rv) throw MsgException("MSG_task_receive_ext() failed"); - return ((Task*)nativeTask->data); + 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) throw(NullPointerException, MsgException) @@ -437,10 +392,10 @@ namespace SimGrid if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) throw MsgException("MSG_task_receive_ext() failed"); - return ((Task*)nativeTask->data); + return (Task*)(nativeTask->data); } - Task& Task::receive(const char* alias, double timeout) + Task* Task::receive(const char* alias, double timeout) throw(NullPointerException, InvalidArgumentException, MsgException) { // check the parameters @@ -456,10 +411,10 @@ namespace SimGrid if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Task::receive(const char* alias, const Host& rHost) + Task* Task::receive(const char* alias, const Host& rHost) throw(NullPointerException, MsgException) { // check the parameters @@ -472,10 +427,10 @@ namespace SimGrid if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } - Task& Task::receive(const char* alias, double timeout, const Host& rHost) + Task* Task::receive(const char* alias, double timeout, const Host& rHost) throw(NullPointerException, InvalidArgumentException, MsgException) { // check the parameters @@ -492,7 +447,7 @@ namespace SimGrid if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) throw MsgException("MSG_task_receive_ext() failed"); - return (*((Task*)nativeTask->data)); + return (Task*)(nativeTask->data); } int Task::listen(void) diff --git a/src/cxx/Task.hpp b/src/cxx/Task.hpp index a158f4f29e..e78d9dd67a 100644 --- a/src/cxx/Task.hpp +++ b/src/cxx/Task.hpp @@ -22,7 +22,11 @@ #include -#include +#include +#include +#include +#include +#include #include @@ -30,12 +34,6 @@ namespace SimGrid { namespace Msg { - class MsgException; - class InvalidArgumentException; - class NullPointerException; - class MsgException; - class BadAllocException; - class Process; class Host; @@ -44,39 +42,12 @@ namespace SimGrid { MSG_DECLARE_DYNAMIC(Task); - friend Process; - friend Host; + friend class Process; + friend class Host; protected: // Default constructor. Task(); - - class Ref - { - public: - Ref(Task* task) - { - count = 1; - this->task = task; - } - - virtual ~Ref(){} - - void operator++(void){ - count++; - - } - - void operator--(void){ - if(--count <= 0) - delete p; - } - - private: - int count; - Task* task; - - }; public: /*! \brief Copy constructor. @@ -191,9 +162,6 @@ namespace SimGrid * * [MsgException] if an internal excpetion occurs. */ - /*static Task& get(int channel) - throw(InvalidArgumentException, MsgException);*/ - static Task* get(int channel) throw(InvalidArgumentException, MsgException); @@ -209,7 +177,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - static Task& get(int channel, const Host& rHost) + 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 @@ -227,7 +195,7 @@ namespace SimGrid * different than -1.0. * [MsgException] if an internal exception occurs. */ - static Task& get(int channel, double timeout, const Host& rHost) + 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. @@ -424,7 +392,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - static Task& receive(const char* alias, double timeout) + 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 @@ -441,7 +409,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - static Task& receive(const char* alias, const Host& rHost) + 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 @@ -462,7 +430,7 @@ namespace SimGrid * * [MsgException] if an internal exception occurs. */ - static Task& receive(const char* alias, double timeout, const Host& rHost) + 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 @@ -552,7 +520,7 @@ namespace SimGrid * alias. */ static int listenFromHost(const char* alias, const Host& rHost) - throw(NullPointerException, MsgException); + throw(NullPointerException); virtual const Task& operator= (const Task& rTask); @@ -561,8 +529,6 @@ namespace SimGrid // Attributes. m_task_t nativeTask; // the native MSG task. - - Ref* ref; }; } // namespace Msg @@ -570,4 +536,5 @@ namespace SimGrid typedef Task* TaskPtr; -#endif // §MSG_TASK_HPP \ No newline at end of file +#endif // §MSG_TASK_HPP + -- 2.20.1