Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Last Changes of CPP version of Msg
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 3 Jul 2008 16:56:29 +0000 (16:56 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 3 Jul 2008 16:56:29 +0000 (16:56 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5853 48e7efb5-ca39-0410-a469-dd3cf9ba447f

31 files changed:
src/cxx/Application.cxx
src/cxx/Application.hpp
src/cxx/ApplicationHandler.cxx
src/cxx/ApplicationHandler.hpp
src/cxx/BadAllocException.cxx
src/cxx/BadAllocException.hpp
src/cxx/Environment.cxx
src/cxx/Environment.hpp
src/cxx/Exception.cxx
src/cxx/Exception.hpp
src/cxx/FileNotFoundException.cxx
src/cxx/FileNotFoundException.hpp
src/cxx/Host.cxx
src/cxx/Host.hpp
src/cxx/HostNotFoundException.cxx
src/cxx/HostNotFoundException.hpp
src/cxx/InvalidArgumentException.cxx
src/cxx/InvalidArgumentException.hpp
src/cxx/LogicException.cxx
src/cxx/LogicException.hpp
src/cxx/Msg.cxx
src/cxx/Msg.hpp
src/cxx/MsgException.cxx
src/cxx/MsgException.hpp
src/cxx/Object.cxx
src/cxx/Process.cxx
src/cxx/Process.hpp
src/cxx/Simulation.cxx
src/cxx/Simulation.hpp
src/cxx/Task.cxx
src/cxx/Task.hpp

index e11cab9..e326494 100644 (file)
   */  \r
   \r
 #include <Application.hpp>\r
+\r
+\r
+#include <NullPointerException.hpp>\r
+#include <FileNotFoundException.hpp>\r
+#include <LogicException.hpp>\r
+#include <MsgException.hpp>\r
 #include <ApplicationHandler.hpp>\r
 \r
 #include <sys/types.h>\r
 #include <sys/stat.h>\r
+#include <stdlib.h>\r
+\r
+#include <surf/surfxml_parse.h>\r
 \r
 #ifndef S_ISREG\r
        #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)\r
@@ -34,7 +43,7 @@ namespace SimGrid
                        this->deployed = false;\r
                }\r
                                \r
-               Application(const Application& rApplication)\r
+               Application::Application(const Application& rApplication)\r
                {\r
                                \r
                        this->file = rApplication.getFile();\r
@@ -51,7 +60,7 @@ namespace SimGrid
                        \r
                        struct stat statBuf = {0};\r
                                \r
-                       if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+                       if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
                                throw FileNotFoundException(file);\r
                                \r
                        this->file = file;\r
@@ -63,7 +72,7 @@ namespace SimGrid
                        // NOTHING TODO\r
                }\r
                        \r
-               Application::deploy(const char* file)\r
+               void Application::deploy(const char* file)\r
                throw(NullPointerException, FileNotFoundException, LogicException, MsgException)\r
                {\r
                        // check logic\r
@@ -78,7 +87,7 @@ namespace SimGrid
                        \r
                        struct stat statBuf = {0};\r
                                \r
-                       if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+                       if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
                                throw FileNotFoundException(file);\r
                                        \r
                        surf_parse_reset_parser();\r
@@ -87,13 +96,13 @@ namespace SimGrid
                        surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
                                \r
                        // set the process arg handler\r
-                       surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);\r
+                       surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg);\r
                                \r
                        // set the properties handler\r
                        surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\r
                                \r
                        // set the end of the xml process element handler\r
-                       surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);\r
+                       surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess);\r
 \r
                        surf_parse_open(file);\r
                        \r
@@ -112,7 +121,7 @@ namespace SimGrid
                        this->deployed = true;\r
                }\r
                \r
-               Application::deploy(void)\r
+               void Application::deploy(void)\r
                throw(LogicException, MsgException)\r
                {\r
                        // check logic\r
@@ -126,9 +135,9 @@ namespace SimGrid
                        \r
                        surf_parse_reset_parser();\r
                        surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
-                       surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);\r
+                       surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg);\r
                        surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\r
-                       surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);\r
+                       surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess);\r
 \r
                        surf_parse_open(file);\r
                        \r
@@ -140,7 +149,7 @@ namespace SimGrid
                        this->deployed = true;  \r
                }\r
                \r
-               bool Application::isDeployed(void)\r
+               bool Application::isDeployed(void) const\r
                {\r
                        return this->deployed;\r
                }\r
@@ -160,7 +169,7 @@ namespace SimGrid
                        \r
                        struct stat statBuf = {0};\r
                                \r
-                       if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+                       if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
                                throw FileNotFoundException("file (file not found)");\r
                                \r
                        this->file = file;\r
index 1ca158f..7efe7a2 100644 (file)
        #error Application.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
-#include <NullPointerException.hpp>\r
-#include <FileNotFoundException.hpp>\r
-#include <LogicException.hpp>\r
-#include <MsgException.hpp>\r
+#include <Config.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+               class NullPointerException;\r
+               class FileNotFoundException;\r
+               class LogicException;\r
+               class MsgException;\r
+\r
                // Application wrapper class declaration.\r
-               class Application\r
+               class SIMGRIDX_EXPORT Application\r
                {\r
                public:\r
                        \r
@@ -75,7 +77,7 @@ namespace SimGrid
                         */\r
                         \r
                        void deploy(void)\r
-                       throw(LogicExeption, MsgException);\r
+                       throw(LogicException, MsgException);\r
                        \r
                        /*! \brief Application::deploy() - Deploy the appliction.\r
                         *\r
@@ -141,6 +143,7 @@ namespace SimGrid
                        \r
                        // the xml file which describes the application of the simulation.\r
                        const char* file;\r
+\r
                };\r
                \r
        } // namespace Msg\r
index f1a8077..9be8907 100644 (file)
  \r
  /* ApplicationHandler member functions implementation.\r
   */  \r
-  \r
+\r
 #include <ApplicationHandler.hpp>\r
 \r
+#include <Object.hpp>\r
+#include <ClassNotFoundException.hpp>\r
+#include <HostNotFoundException.hpp>\r
+#include <Host.hpp>\r
+#include <Process.hpp>\r
+\r
+#include <stdlib.h>\r
+\r
+#include <surf/surfxml_parse.h>\r
+#include <xbt/sysdep.h>\r
+\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
 \r
-               ApplicationHandler::ProcessFactory::processFactory = NULL;\r
+               ApplicationHandler::ProcessFactory* ApplicationHandler::processFactory = NULL;\r
                        \r
                // Desable the default constructor, the copy constructor , the assignement operator\r
                // and the destructor of this class. Assume that this class is static.\r
@@ -59,7 +71,7 @@ namespace SimGrid
                {\r
                        // release the handler at the end of the parsing.\r
                        if(processFactory)\r
-                               delete processFactroy;\r
+                               delete processFactory;\r
                }\r
                        \r
                void ApplicationHandler::onBeginProcess(void)\r
@@ -91,7 +103,7 @@ namespace SimGrid
                \r
                ApplicationHandler::ProcessFactory::ProcessFactory() \r
                {\r
-                       this->args = xbt_dynar_new(sizeof(char*),ProcessFactory::freeCstr);\r
+                       this->args = xbt_dynar_new(sizeof(char*),ApplicationHandler::ProcessFactory::freeCstr);\r
                        this->properties = NULL; // TODO instanciate the dictionary\r
                        this->hostName = NULL;\r
                        this->function = NULL;\r
@@ -102,12 +114,14 @@ namespace SimGrid
                throw (ClassNotFoundException, HostNotFoundException)\r
                {\r
                        Host host;\r
+                       Class* c;\r
                        Process* process;\r
                        \r
                        // try to dynamicaly create an instance fo the process from its name (which is specified by the element function\r
                        // in the xml application file.\r
                        // if this static method fails, it throws an exception of the class ClassNotFoundException\r
-                       process = (Process*)Class::fromName(this->function);\r
+                       c = Class::fromName(this->function);\r
+                       process = reinterpret_cast<Process*>(c->createObject());\r
                        \r
                        // try to retrieve the host of the process from its name\r
                        // if this method fails, it throws an exception of the class HostNotFoundException\r
@@ -118,7 +132,7 @@ namespace SimGrid
                        \r
                        char** argv = (char**)calloc(argc, sizeof(char*));\r
                        \r
-                       for(int i = 0; i < argc; i++)\r
+                       for(int i = argc -1; i >= 0; i--)\r
                                xbt_dynar_pop(this->args, &(argv[i]));\r
                        \r
                        // finaly create the process (for more detail on the process creation see Process::create()\r
@@ -129,7 +143,7 @@ namespace SimGrid
                        this->properties = new Properties();*/\r
                }\r
                        \r
-               void ApplicationHandler::ProcessFactory::setProcessIdentity(const string& hostName, const string& function) \r
+               void ApplicationHandler::ProcessFactory::setProcessIdentity(const char* hostName, const char* function) \r
                {\r
                        this->hostName = hostName;\r
                        this->function = function;\r
@@ -144,12 +158,12 @@ namespace SimGrid
                // callback function used by the dynamic array to cleanup all of its elements.\r
                void ApplicationHandler::ProcessFactory::freeCstr(void* cstr)\r
                {\r
-                       free(*(void**)str);\r
+                       free(*(void**)cstr);\r
                }\r
                \r
                void ApplicationHandler::ProcessFactory::registerProcessArg(const char* arg) \r
                {\r
-                       char* cstr = strdup(arg);\r
+                       char* cstr = _strdup(arg);\r
                        xbt_dynar_push(this->args, &cstr);\r
                }\r
                \r
@@ -158,7 +172,7 @@ namespace SimGrid
                        // TODO implement this function;        \r
                }\r
                \r
-               const const char* ApplicationHandler::ProcessFactory::getHostName(void)\r
+               const char* ApplicationHandler::ProcessFactory::getHostName(void)\r
                {\r
                        return this->hostName;\r
                }\r
index 37e5bf1..6c3819b 100644 (file)
        #error ApplicationHandler.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
+#include <xbt/dict.h>\r
+#include <xbt/dynar.h>\r
 \r
-#include <ClassNotFoundException.hpp>\r
-#include <HostNotFoundException.hpp>\r
+#include <Config.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+\r
+               class ClassNotFoundException;\r
+               class HostNotFoundException;\r
+               class Process;\r
+\r
                // Declaration of the class ApplicationHandler (Singleton).\r
-               class ApplicationHandler\r
+               class SIMGRIDX_EXPORT ApplicationHandler\r
                {\r
-               private :\r
-                       \r
-                       // Desable the default constructor, the copy constructor , the assignement operator\r
-                       // and the destructor of this class. Assume that this class is static.\r
-                       \r
-                       // Default constructor.\r
-                       ApplicationHandler();\r
-                       \r
-                       // Copy constructor.\r
-                       ApplicationHandler(const ApplicationHandler& rApplicationHandler);\r
-                       \r
-                       // Destructor\r
-                       virtual ~ApplicationHandler();\r
-                       \r
-                       // Assignement operator.\r
-                       const ApplicationHandler& operator = (const ApplicationHandler& rApplicationHandler);\r
-                       \r
+                       friend Process;\r
+\r
+               public:\r
+\r
                        class ProcessFactory \r
                        {\r
                                public:\r
@@ -66,32 +59,51 @@ namespace SimGrid
                        \r
                                public :\r
                        \r
-                               // Default constructor.\r
-                               ProcessFactory(); \r
-                               \r
-                               // Copy constructor.\r
-                               ProcessFactory(const ProcessFactory& rProcessFactory);\r
-                               \r
-                               // Destructor.\r
-                               virtual ~ProcessFactory();\r
-                               \r
-                               // Set the identity of the current process.\r
-                               void setProcessIdentity(const char* hostName, const char* function);\r
-                       \r
-                       // Register an argument of the current process.\r
-                       void registerProcessArg(const char* arg); \r
-                               \r
-                               // Set the property of the current process.\r
-                               void setProperty(const char* id, const char* value);\r
-                               \r
-                               // Return the host name of the current process.\r
-                               const const char* getHostName(void);\r
-                               \r
-                               // Create the current process.\r
-                       void createProcess(void)\r
-                       throw (ClassNotFoundException, HostNotFoundException); \r
+                                       // Default constructor.\r
+                                       ProcessFactory(); \r
+                                       \r
+                                       // Copy constructor.\r
+                                       ProcessFactory(const ProcessFactory& rProcessFactory);\r
+                                       \r
+                                       // Destructor.\r
+                                       virtual ~ProcessFactory(){}\r
+                                       \r
+                                       // Set the identity of the current process.\r
+                                       void setProcessIdentity(const char* hostName, const char* function);\r
+                               \r
+                               // Register an argument of the current process.\r
+                               void registerProcessArg(const char* arg); \r
+                                       \r
+                                       // Set the property of the current process.\r
+                                       void setProperty(const char* id, const char* value);\r
+                                       \r
+                                       // Return the host name of the current process.\r
+                                       const char* getHostName(void);\r
+                                       \r
+                                       // Create the current process.\r
+                               void createProcess(void)\r
+                               throw (ClassNotFoundException, HostNotFoundException); \r
+\r
+                                       static void freeCstr(void* cstr);\r
                        \r
                        };\r
+\r
+               private :\r
+                       \r
+                       // Desable the default constructor, the copy constructor , the assignement operator\r
+                       // and the destructor of this class. Assume that this class is static.\r
+                       \r
+                       // Default constructor.\r
+                       ApplicationHandler();\r
+                       \r
+                       // Copy constructor.\r
+                       ApplicationHandler(const ApplicationHandler& rApplicationHandler);\r
+                       \r
+                       // Destructor\r
+                       virtual ~ApplicationHandler();\r
+                       \r
+                       // Assignement operator.\r
+                       const ApplicationHandler& operator = (const ApplicationHandler& rApplicationHandler);\r
                        \r
                        // the process factory used by the application handler.\r
                        static ProcessFactory* processFactory;\r
index 07df2b6..d650141 100644 (file)
@@ -1,11 +1,9 @@
-#include "BadAllocException.hpp"\r
+#include <BadAllocException.hpp>\r
 \r
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 \r
-using namespace std;\r
-\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
index df050b8..ac4039f 100644 (file)
  *\r
  */  \r
  \r
-#ifndef MSG_MSGEXCEPTION_HPP\r
-#define MSG_MSGEXCEPTION_HPP\r
+#ifndef MSG_BADALLOCEXCEPTION_HPP\r
+#define MSG_BADALLOCEXCEPTION_HPP\r
 \r
-#include "Exception.hpp"\r
+#include <Exception.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
                \r
-               class BadAllocException : public Exception\r
+               class SIMGRIDX_EXPORT BadAllocException : public Exception\r
                {\r
                        public:\r
                        \r
@@ -61,4 +61,4 @@ namespace SimGrid
 }// namespace SimGrid\r
 \r
 \r
-#endif // !MSG_MSGEXCEPTION_HPP\r
+#endif // !MSG_BADALLOCEXCEPTION_HPP\r
index 489c814..806e868 100644 (file)
   \r
 #include <Environment.hpp>\r
 \r
+#include <NullPointerException.hpp>\r
+#include <FileNotFoundException.hpp>\r
+#include <InvalidArgumentException.hpp>\r
+#include <LogicException.hpp>\r
+#include <MsgException.hpp>\r
+\r
+#include <stdlib.h>\r
+\r
 #include <sys/types.h>\r
 #include <sys/stat.h>\r
 \r
+#include <msg/msg.h>\r
+\r
 #ifndef S_ISREG\r
        #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)\r
 #endif\r
@@ -32,14 +42,14 @@ namespace SimGrid
                        this->loaded = false;\r
                }\r
                                \r
-               Environment::Environment(const Environment& rEnvironment);\r
+               Environment::Environment(const Environment& rEnvironment)\r
                {\r
                        this->file = rEnvironment.getFile();\r
                        this->loaded = rEnvironment.isLoaded();\r
                }\r
                \r
                Environment::Environment(const char* file)\r
-               throw(NullPointerException, InvalidArgumentException);\r
+               throw(NullPointerException, InvalidArgumentException)\r
                {\r
                        // check parameters\r
                        \r
@@ -48,8 +58,8 @@ namespace SimGrid
                        \r
                        struct stat statBuf = {0};\r
                                \r
-                       if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
-                               throw InvalidParameterException("file (file not found)");\r
+                       if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
+                               throw InvalidArgumentException("file (file not found)");\r
                                \r
                        this->file = file;\r
                        this->loaded = false;\r
@@ -94,7 +104,7 @@ namespace SimGrid
                        \r
                        struct stat statBuf = {0};\r
                                \r
-                       if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+                       if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
                                throw FileNotFoundException(file);\r
                                        \r
                        MSG_create_environment(file);\r
@@ -124,7 +134,7 @@ namespace SimGrid
                        \r
                        struct stat statBuf = {0};\r
                                \r
-                       if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+                       if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
                                throw FileNotFoundException("file (file not found)");\r
                                \r
                        this->file = file;\r
index cc21c72..fb2a17b 100644 (file)
        #error Environment.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
-#include <NullPointerException.hpp>\r
-#include <FileNotFoundException.hpp>\r
-#include <LogicException.hpp>\r
-#include <MsgException.hpp>\r
-\r
+#include <Config.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+               class NullPointerException;\r
+               class FileNotFoundException;\r
+               class InvalidArgumentException;\r
+               class LogicException;\r
+               class MsgException;\r
+\r
                // Environment class wrapper declaration\r
-               class Environment\r
+               class SIMGRIDX_EXPORT Environment\r
                {\r
                        public:\r
                                \r
@@ -136,7 +138,7 @@ namespace SimGrid
                                const char* file;\r
                                \r
                                // flag : is true the environment of the simulation is loaded.\r
-                               bool loaded.\r
+                               bool loaded;\r
                };\r
                \r
        } // namespace Msg\r
index 924eab8..5e54f88 100644 (file)
@@ -1,4 +1,4 @@
-#include "Exception.hpp"\r
+#include <Exception.hpp>\r
 \r
 namespace SimGrid\r
 {\r
index ad22e99..c520ae6 100644 (file)
 #ifndef MSG_EXCEPTION_HPP\r
 #define MSG_EXCEPTION_HPP\r
 \r
+#include <Config.hpp>\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
                \r
-               class Exception\r
+               class SIMGRIDX_EXPORT Exception\r
                {\r
                        public:\r
                        \r
index 713c153..d995190 100644 (file)
@@ -4,7 +4,6 @@
 #include <stdlib.h>\r
 #include <stdio.h>\r
 \r
-using namespace std;\r
 \r
 namespace SimGrid\r
 {\r
index 398f153..639accd 100644 (file)
 #ifndef MSG_FILENOTFOUND_HPP\r
 #define MSG_FILENOTFOUND_HPP\r
 \r
-#include <Exception.hp>\r
+#include <Exception.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
                \r
-               class FileNotFoundException : public Exception\r
+               class SIMGRIDX_EXPORT FileNotFoundException : public Exception\r
                {\r
                        public:\r
                        \r
index 07ec58c..db4722b 100644 (file)
   */  \r
 #include <Host.hpp>\r
 \r
+#include <InvalidArgumentException.hpp>\r
+#include <BadAllocException.hpp>\r
+#include <HostNotFoundException.hpp>\r
+#include <MsgException.hpp>\r
+\r
+#include <Task.hpp>\r
+#include <Process.hpp>\r
+\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+#include <msg/msg.h>\r
+#include <msg/private.h>\r
+\r
+#include <xbt/fifo.h>\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
@@ -37,11 +53,11 @@ namespace SimGrid
                \r
                \r
                Host& Host::getByName(const char* hostName)\r
-               throw(HostNotFoundException, InvalidParameterException, BadAllocException)\r
+               throw(HostNotFoundException, InvalidArgumentException, BadAllocException)\r
                {\r
                        // check the parameters\r
                        if(!hostName)\r
-                               throw InvalidParmeterException("hostName");\r
+                               throw InvalidArgumentException("hostName");\r
                                \r
                        m_host_t nativeHost = NULL;     // native host.\r
                        Host* host = NULL;                      // wrapper host.\r
@@ -53,7 +69,7 @@ namespace SimGrid
                        { // native host not associated yet with  its wrapper\r
                        \r
                                // instanciate a new wrapper \r
-                               if(!(host = new Host())\r
+                               if(!(host = new Host()))\r
                                        throw BadAllocException(hostName);\r
                                \r
                                host->nativeHost = nativeHost; \r
@@ -96,19 +112,19 @@ namespace SimGrid
                }\r
                \r
                void Host::all(Host*** hosts, int* len) \r
-               throw(InvalidParameterException, BadAllocException) \r
+               throw(InvalidArgumentException, BadAllocException) \r
                {\r
-                       /* check the parameters */\r
+                       // check the parameters\r
                        if(!hosts)\r
-                               throw InvalidParameterException("hosts");\r
+                               throw InvalidArgumentException("hosts");\r
                                \r
                        if(len < 0)\r
-                               throw InvalidParameterException("len parameter must be positive");\r
+                               throw InvalidArgumentException("len parameter must be positive");\r
                        \r
                        int count = xbt_fifo_size(msg_global->host);\r
                        \r
                        if(*len < count)\r
-                               throw InvalidParameterException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)");\r
+                               throw InvalidArgumentException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)");\r
                        \r
                        int index;\r
                        m_host_t nativeHost;\r
@@ -123,7 +139,7 @@ namespace SimGrid
                        \r
                                if(!host) \r
                                {\r
-                                       if(!(host = new Host())\r
+                                       if(!(host = new Host()))\r
                                        {\r
                                                // release all allocated memory.\r
                                                for(int i = 0; i < index; i++)\r
@@ -164,7 +180,7 @@ namespace SimGrid
                \r
                double Host::getSpeed(void) const\r
                {\r
-                       return MSG_get_host_speed(nativeHost->simdata->smx_host);\r
+                       return MSG_get_host_speed(nativeHost);\r
                }\r
                \r
                bool Host::hasData(void) const\r
@@ -172,31 +188,42 @@ namespace SimGrid
                        return (NULL != this->data);\r
                }\r
                \r
-               bool Host::isAvailable(void) const\r
+               int Host::isAvailable(void) const\r
                {\r
-                       return (bool)SIMIX_host_get_state(nativeHost->simdata->smx_host);\r
+                       return SIMIX_host_get_state(nativeHost->simdata->smx_host);\r
                }\r
                \r
                void Host::put(int channel, const Task& rTask) \r
-               throw(MsgException, InvalidParameterException)\r
+               throw(MsgException, InvalidArgumentException)\r
                {\r
                        // checks the parameters\r
                        if(channel < 0)\r
-                               throw InvalidParameterException("channel (must be more or equal to zero)");\r
+                               throw InvalidArgumentException("channel (must be more or equal to zero)");\r
                                \r
                        if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , -1.0))\r
                                throw MsgException("MSG_task_put_with_timeout() failed");\r
                } \r
+\r
+               void Host::put(int channel, Task* task) \r
+               throw(MsgException, InvalidArgumentException)\r
+               {\r
+                       // checks the parameters\r
+                       if(channel < 0)\r
+                               throw InvalidArgumentException("channel (must be more or equal to zero)");\r
+                               \r
+                       if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, nativeHost, channel , -1.0))\r
+                               throw MsgException("MSG_task_put_with_timeout() failed");\r
+               } \r
                \r
                void Host::put(int channel, const Task& rTask, double timeout) \r
-               throw(MsgException, InvalidParameterException) \r
+               throw(MsgException, InvalidArgumentException) \r
                {\r
                        // checks the parameters\r
                        if(channel < 0)\r
-                               throw InvalidParameterException("channel (must be more or equal to zero)");\r
+                               throw InvalidArgumentException("channel (must be more or equal to zero)");\r
                                \r
                        if(timeout < 0.0 && timeout != -1.0)\r
-                               throw InvalidParameterException("timeout (must be more or equal to zero or equal to -1.0)");    \r
+                               throw InvalidArgumentException("timeout (must be more or equal to zero or equal to -1.0)");     \r
                                \r
                                \r
                    if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , timeout))\r
@@ -204,25 +231,25 @@ namespace SimGrid
                }\r
                \r
                void Host::putBounded(int channel, const Task& rTask, double maxRate) \r
-               throw(MsgException, InvalidParameterException)\r
+               throw(MsgException, InvalidArgumentException)\r
                {\r
                    // checks the parameters\r
                        if(channel < 0)\r
-                               throw InvalidParameterException("channel (must be more or equal to zero)");\r
+                               throw InvalidArgumentException("channel (must be more or equal to zero)");\r
                                \r
                        if(maxRate < 0.0 && maxRate != -1.0)\r
-                               throw InvalidParameterException("maxRate (must be more or equal to zero or equal to -1.0)");    \r
+                               throw InvalidArgumentException("maxRate (must be more or equal to zero or equal to -1.0)");     \r
                    \r
                        if(MSG_OK != MSG_task_put_bounded(rTask.nativeTask, nativeHost, channel, maxRate))\r
                                throw MsgException("MSG_task_put_bounded() failed");\r
                }\r
                \r
                void Host::send(const Task& rTask) \r
-               throw(NativeException)  \r
+               throw(MsgException)  \r
                {       \r
                        MSG_error_t rv;\r
                        \r
-                       char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(this->getName())+ strlen(Process::currentProcess().getName()) + 2, sizeof(char));\r
                                \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -238,25 +265,26 @@ namespace SimGrid
                } \r
                \r
                void Host::send(const char* alias, const Task& rTask) \r
-               throw(InvalidParameterException, MsgException) \r
+               throw(InvalidArgumentException, MsgException) \r
                {\r
                        // check the parameters\r
                        if(!alias)\r
-                               throw InvalidParmeterException("alias (must not be NULL)");\r
+                               throw InvalidArgumentException("alias (must not be NULL)");\r
                        \r
                        if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0))\r
                                throw MsgException("MSG_task_send_with_timeout() failed");\r
                }\r
                \r
                void Host::send(const Task& rTask, double timeout) \r
-               throw(InvalidParameterException, BadAllocException, MsgException) \r
+               throw(InvalidArgumentException, BadAllocException, MsgException) \r
                {\r
                        // check the parameters\r
                        if(timeout < 0 && timeout != -1.0)\r
-                               throw InvalidParameterException("timeout (must be positive or equal to zero or equal to -1.0)");\r
+                               throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)");\r
+                       \r
                        MSG_error_t rv;\r
                        \r
-                       char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char));\r
                                \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -273,15 +301,15 @@ namespace SimGrid
                }\r
                \r
                void Host::send(const char* alias, const Task& rTask, double timeout) \r
-               throw(InvalidParameterException, MsgException) \r
+               throw(InvalidArgumentException, MsgException) \r
                {\r
                        // check the parameter\r
                        \r
                        if(!alias)\r
-                               throw InvalidParmeterException("alias (must not be NULL)");\r
+                               throw InvalidArgumentException("alias (must not be NULL)");\r
                                \r
                        if(timeout < 0 && timeout != -1.0)\r
-                               throw InvalidParameterException("timeout (must be positive or equal to zero or equal to -1.0)");\r
+                               throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)");\r
                                        \r
                        if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout))\r
                                throw MsgException("MSG_task_send_with_timeout() failed");\r
@@ -289,14 +317,14 @@ namespace SimGrid
                \r
                \r
                void Host::sendBounded(const Task& rTask, double maxRate) \r
-               throw(InvalidParameterException, BadAllocException, MsgException) \r
+               throw(InvalidArgumentException, BadAllocException, MsgException) \r
                {\r
                        if(maxRate < 0 && maxRate != -1.0)\r
-                               throw InvalidParameterException("maxRate (must be positive or equal to zero or equal to -1.0)");\r
+                               throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)");\r
                        \r
                        MSG_error_t rv;\r
                        \r
-                       char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -312,18 +340,18 @@ namespace SimGrid
                }  \r
                \r
                void Host::sendBounded(const char* alias, const Task& rTask, double maxRate) \r
-               throw(InvalidParameterException, MsgException) \r
+               throw(InvalidArgumentException, MsgException) \r
                {\r
                        // check the parameters\r
                        if(!alias)\r
-                               throw InvalidParameterException("alias (must not be NULL)");\r
+                               throw InvalidArgumentException("alias (must not be NULL)");\r
                        \r
                        if(maxRate < 0 && maxRate != -1)\r
-                               throw InvalidParameterException("maxRate (must be positive or equal to zero or equal to -1.0)");\r
+                               throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)");\r
                        \r
                        if(MSG_OK != MSG_task_send_bounded(rTask.nativeTask, alias, maxRate))\r
                                throw MsgException("MSG_task_send_bounded() failed");\r
                        \r
-               } \r
+               }\r
        } // namspace Msg\r
 } // namespace SimGrid
\ No newline at end of file
index bb219eb..881bebb 100644 (file)
@@ -52,23 +52,34 @@ catch(HostNotFoundException e)
        #error Host.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
-#include <InvalidArgumentException.hpp>\r
-#include <BadAllocException.hpp>\r
-#include <HostNotFoundException.hpp>\r
-#include <MsgException.hpp>\r
+#include <msg/datatypes.h>\r
+\r
+#include <Config.hpp>\r
+\r
 \r
 // namespace SimGrid::Msg\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+               class InvalidArgumentException;\r
+               class BadAllocException;\r
+               class HostNotFoundException;\r
+               class MsgException;\r
+\r
+               class Task;\r
+               class Process;\r
+\r
                // Declaration of the class SimGrid::Msg::Host.\r
-               class Host // final class.\r
+               class SIMGRIDX_EXPORT Host // final class.\r
                {\r
+                       friend Process;\r
+                       friend Task;\r
+\r
                        // Desable the default constructor.\r
                        // The best way to get an host instance is to use the static method Host::getByName().\r
                        \r
-                       private :\r
+                       public :\r
                                \r
                        // Default constructor (desabled).\r
                                Host();\r
@@ -97,11 +108,11 @@ namespace SimGrid
                                 *\r
                                 * \exception           [HostNotFoundException]         if no host with the specified name\r
                                 *                                                                                              was found.\r
-                                *                                      [InvalidParameterException]     if the hostName parameter is invalid (NULL).\r
+                                *                                      [InvalidArgumentException]      if the hostName parameter is invalid (NULL).\r
                                 *                                      [BadAllocException]                     if there is not enough memory to allocate the host.\r
                                 */ \r
                                static Host& getByName(const char* hostName)\r
-                               throw(HostNotFoundException, InvalidParameterException, BadAllocException);\r
+                               throw(HostNotFoundException, InvalidArgumentException, BadAllocException);\r
                                \r
                                /*! \brief Host::getNumber() - returns the number of the installed hosts.\r
                                 *\r
@@ -118,7 +129,7 @@ namespace SimGrid
                                 * \see                         Process::currentProcess().\r
                                 */\r
                                static Host& currentHost(void)\r
-                               throw(InvalidParameterException, BadAllocException);\r
+                               throw(InvalidArgumentException, BadAllocException);\r
                                \r
                                /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform.\r
                                 *\r
@@ -130,7 +141,7 @@ namespace SimGrid
                                 *                                      the parameter len is set with the number of hosts of the platform.\r
                                 *                                      Otherwise the method throw one of the exception described below.\r
                                 *\r
-                                * \exception           [InvalidParameterException]     if the parameter hosts is invalid or\r
+                                * \exception           [InvalidArgumentException]      if the parameter hosts is invalid or\r
                                 *                                                                                              if the parameter len is negative or\r
                                 *                                                                                              less than the number of hosts installed\r
                                 *                                                                                              on the current platform.\r
@@ -229,9 +240,9 @@ namespace SimGrid
                                /*! \brief Host::isAvailable - tests if an host is availabled.\r
                                 * \r
                                 * \return                      Is the host is availabled the method returns\r
-                                *                                      true. Otherwise the method returns false.\r
+                                *                                      1. Otherwise the method returns 0.\r
                                 */ \r
-                               bool isAvailble(void) const;\r
+                               int isAvailable(void) const;\r
                                \r
                                /* ! \brief Host::put() - put a task on the given channel of a host .\r
                                 *\r
@@ -243,11 +254,14 @@ namespace SimGrid
                                 *                                      the method throws one of the exceptions described below.\r
                                 *\r
                                 * \exception           [MsgException]                          if an internal error occurs.\r
-                                *                                      [InvalidParameterException]     if the value of the channel specified as\r
+                                *                                      [InvalidArgumentException]      if the value of the channel specified as\r
                                 *                                                                                              parameter is negative.\r
                                 */\r
                                void put(int channel, const Task& rTask)\r
-                               throw(MsgException, InvalidParameterException);\r
+                               throw(MsgException, InvalidArgumentException);\r
+\r
+                               void Host::put(int channel, Task* task) \r
+                               throw(MsgException, InvalidArgumentException);\r
                                \r
                                /* ! \brief Host::put() - put a task on the given channel of a host object (waiting at most timeout seconds).\r
                                 *\r
@@ -260,14 +274,14 @@ namespace SimGrid
                                 *                                      the method throws one of the exceptions described below.\r
                                 *\r
                                 * \exception           [MsgException]                          if an internal error occurs.\r
-                                *                                      [InvalidParameterException]     if the value of the channel specified as\r
+                                *                                      [InvalidArgumentException]      if the value of the channel specified as\r
                                 *                                                                                              parameter is negative or if the timeout value\r
                                 *                                                                                              is less than zero and différent of -1.\r
                                 *\r
                                 * \remark                      To specify no timeout set the timeout value with -1.0.\r
                                 */\r
-                               void put(int channel, Task task, double timeout) \r
-                               throw(MsgException, InvalidParameterException);\r
+                               void put(int channel, const Task& rTask, double timeout) \r
+                               throw(MsgException, InvalidArgumentException);\r
                                \r
                                /* ! \brief Host::putBounded() - put a task on the given channel of a host object (capping the emission rate to maxrate).\r
                                 *\r
@@ -280,14 +294,14 @@ namespace SimGrid
                                 *                                      the method throws one of the exceptions described below.\r
                                 *\r
                                 * \exception           [MsgException]                          if an internal error occurs.\r
-                                *                                      [InvalidParameterException]     if the value of the channel specified as\r
+                                *                                      [InvalidArgumentException]      if the value of the channel specified as\r
                                 *                                                                                              parameter is negative or if the maxRate parameter value\r
                                 *                                                                                              is less than zero and différent of -1.0.\r
                                 *\r
                                 * \remark                      To specify no rate set the maxRate parameter value with -1.0.\r
                                 */\r
                                void putBounded(int channel, const Task& rTask, double maxRate) \r
-                               throw(MsgException, InvalidParameterException);\r
+                               throw(MsgException, InvalidArgumentException);\r
                                \r
                                /* ! brief Host::send() - sends the given task to mailbox identified by the default alias.\r
                                 *\r
@@ -311,13 +325,13 @@ namespace SimGrid
                                 * \return                      If successful the task is sended to the default mailbox. Otherwise the\r
                                 *                                      method throws one of the exceptions described below.\r
                                 *\r
-                                * \exception           [InvalidParameterException]     if alias parameter is invalid (NULL).\r
+                                * \exception           [InvalidArgumentException]      if alias parameter is invalid (NULL).\r
                                 *                                      [BadAllocException]                     if there is not enough memory to allocate\r
                                 *                                                                                              the default alias variable.\r
                                 *                                      [MsgException]                          if an internal error occurs.\r
                                 */\r
                                void send(const char* alias, const Task& rTask) \r
-                               throw(InvalidParameterException, BadAllocException, MsgException);\r
+                               throw(InvalidArgumentException, BadAllocException, MsgException);\r
                                \r
                                /* ! brief Host::send() - sends the given task to mailbox identified by the default alias\r
                                 *  (waiting at most timeout seconds).\r
@@ -330,7 +344,7 @@ namespace SimGrid
                                 *\r
                                 * \exception           [BadAllocException]                     if there is not enough memory to allocate\r
                                 *                                                                                              the default alias variable.\r
-                                *                                      [InvalidParameterException]     if the timeout value is negative and different of\r
+                                *                                      [InvalidArgumentException]      if the timeout value is negative and different of\r
                                 *                                                                                              -1.0.                   \r
                                 *                                      [MsgException]                          if an internal error occurs.\r
                                 *\r
@@ -339,7 +353,7 @@ namespace SimGrid
                                 *\r
                                 */\r
                                void send(const Task& rTask, double timeout) \r
-                               throw(NativeException);\r
+                               throw(MsgException);\r
                                \r
                                /* ! brief Host::send() - sends the given task to mailbox identified by the parameter alias\r
                                 *  (waiting at most timeout seconds).\r
@@ -351,7 +365,7 @@ namespace SimGrid
                                 * \return                      If successful the task is sended to the default mailbox. Otherwise the\r
                                 *                                      method throws one of the exceptions described below.\r
                                 *\r
-                                * \exception           [InvalidParameterException]     if the timeout value is negative and different of\r
+                                * \exception           [InvalidArgumentException]      if the timeout value is negative and different of\r
                                 *                                                                                              -1.0 or if the alias parameter is invalid (NULL).                       \r
                                 *                                      [MsgException]                          if an internal error occurs.\r
                                 *\r
@@ -360,7 +374,7 @@ namespace SimGrid
                                 *\r
                                 */\r
                                void send(const char* alias, const Task& rTask, double timeout) \r
-                               throw(InvalidParameterException, MsgException);\r
+                               throw(InvalidArgumentException, MsgException);\r
                                \r
                                /* ! brief Host::sendBounded() - sends the given task to mailbox associated to the default alias\r
                                 *  (capping the emission rate to maxRate).\r
@@ -371,7 +385,7 @@ namespace SimGrid
                                 * \return                      If successful the task is sended to the default mailbox. Otherwise the\r
                                 *                                      method throws one of the exceptions described below.\r
                                 *\r
-                                * \exception           [InvalidParameterException]     if the maximum rate value is negative and different of\r
+                                * \exception           [InvalidArgumentException]      if the maximum rate value is negative and different of\r
                                 *                                                                                              -1.0.                   \r
                                 *                                      [MsgException]                          if an internal error occurs.\r
                                 *                                      [BadAllocException]                     if there is not enough memory to allocate\r
@@ -381,7 +395,7 @@ namespace SimGrid
                                 *\r
                                 */\r
                                void sendBounded(const Task& rTask, double maxRate) \r
-                               throw(InvalidParameterException, BadAllocException, MsgException);\r
+                               throw(InvalidArgumentException, BadAllocException, MsgException);\r
                                \r
                                /* ! brief Host::sendBounded() - sends the given task to mailbox identified by the parameter alias\r
                                 *  (capping the emission rate to maxRate).\r
@@ -393,7 +407,7 @@ namespace SimGrid
                                 * \return                      If successful the task is sended to the default mailbox. Otherwise the\r
                                 *                                      method throws one of the exceptions described below.\r
                                 *\r
-                                * \exception           [InvalidParameterException]     if the maximum rate value is negative and different of\r
+                                * \exception           [InvalidArgumentException]      if the maximum rate value is negative and different of\r
                                 *                                                                                              -1.0 or if the alias parameter is invalid (NULL).                       \r
                                 *                                      [MsgException]                          if an internal error occurs.\r
                                 *\r
@@ -401,7 +415,7 @@ namespace SimGrid
                                 *\r
                                 */\r
                                void sendBounded(const char* alias, const Task& rTask, double maxRate) \r
-                               throw(InvalidParameterException, MsgException);\r
+                               throw(InvalidArgumentException, MsgException);\r
                        \r
                        protected:\r
                        // Attributes.\r
index c0dac52..8f0c476 100644 (file)
@@ -1,11 +1,9 @@
-#include "HostNotFoundException.hpp"\r
+#include <HostNotFoundException.hpp>\r
 \r
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 \r
-using namespace std;\r
-\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
index 25d3330..17f4603 100644 (file)
 #ifndef MSG_HOSTNOTFOUNDEXCEPTION_HPP\r
 #define MSG_HOSTNOTFOUNDEXCEPTION_HPP\r
 \r
-#include "Exception.hpp"\r
+#include <Exception.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
                \r
-               class HostNotFoundException : public Exception\r
+               class SIMGRIDX_EXPORT HostNotFoundException : public Exception\r
                {\r
                        public:\r
                        \r
index ffc1208..2500b83 100644 (file)
@@ -1,11 +1,9 @@
-#include "InvalidArgumentException.hpp"\r
+#include <InvalidArgumentException.hpp>\r
 \r
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 \r
-using namespace std;\r
-\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
index e81fdd4..6c72f8e 100644 (file)
 #ifndef MSG_INVALIDARGUMENTEXCEPTION_HPP\r
 #define MSG_INVALIDARGUMENTEXCEPTION_HPP\r
 \r
-#include "Exception.hpp"\r
+#include <Exception.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
                \r
-               class InvalidArgumentException : public Exception\r
+               class SIMGRIDX_EXPORT InvalidArgumentException : public Exception\r
                {\r
                        public:\r
                        \r
index a7adcf2..3cd0390 100644 (file)
@@ -1,11 +1,9 @@
-#include "LogicException.hpp"\r
+#include <LogicException.hpp>\r
 \r
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 \r
-using namespace std;\r
-\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
index 19d2f40..a39d7b9 100644 (file)
 #ifndef MSG_LOGICEXCEPTION_HPP\r
 #define MSG_LOGICEXCEPTION_HPP\r
 \r
-#include "Exception.hpp"\r
+#include <Exception.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
                \r
-               class LogicException : public Exception\r
+               class SIMGRIDX_EXPORT LogicException : public Exception\r
                {\r
                        public:\r
                        \r
index 94c7e81..20521cd 100644 (file)
  \r
  /* Msg functions implementation.\r
   */  \r
+\r
+#include <MsgException.hpp>\r
 #include <Msg.hpp>\r
 \r
+#include <msg/msg.h>\r
+#include <stdio.h>\r
+\r
+// XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(SimGridX);\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
@@ -35,7 +42,13 @@ namespace SimGrid
                \r
                void info(const char* s)\r
                {\r
-                        INFO1("%s",s);\r
+                        //INFO1("%s",s);\r
+                       printf("[SimGridX/info] %s\n", s);\r
+               }\r
+\r
+               double getClock(void)\r
+               {\r
+                       return MSG_get_clock();\r
                }\r
 \r
        } // namespace Msg\r
index 6125156..3e26478 100644 (file)
        #error Msg.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
-#include <MsgException.hpp>\r
+#include <Config.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+               class MsgException;\r
                \r
                /*! \brief init() - Initialize MSG (This function must be called at the begining of each simulation).\r
                 *\r
                 * \param argv                  A list of arguments.\r
                 * \param argc                  The number of arguments of the list.\r
                 */\r
-               static void init(int argc, char** argv);\r
+               SIMGRIDX_EXPORT void init(int argc, char** argv);\r
                \r
-               /* \brief finalize() - Finalize MSG (This function must be called at the end of each simulation).\r
+               /*! \brief finalize() - Finalize MSG (This function must be called at the end of each simulation).\r
                 *\r
                 * \exception                   If this function fails, it throws a exception describing the cause of the failure.\r
                 */\r
-               static void finalize(void)\r
+               SIMGRIDX_EXPORT void finalize(void)\r
                throw (MsgException);\r
                \r
                /*! \brief info() - Display information (using xbt log format).\r
                 *\r
                 * \param s                             The information to display.\r
                 */\r
-               static void info(const char* s);\r
-               \r
-               \r
-               \r
+               SIMGRIDX_EXPORT void info(const char* s);\r
+\r
+               /*! \brief getClock() -  Retrieve the simulation time\r
+                *\r
+                * \return                              The current simulation time.\r
+                */\r
+               SIMGRIDX_EXPORT double getClock(void);\r
                \r
        } // namespace Msg\r
 } // namespace SimGrid\r
index 5b9bd46..cd18308 100644 (file)
@@ -1,11 +1,9 @@
-#include "MsgException.hpp"\r
+#include <MsgException.hpp>\r
 \r
 #include <string.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 \r
-using namespace std;\r
-\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
index 55d151a..a8f576b 100644 (file)
 #ifndef MSG_MSGEXCEPTION_HPP\r
 #define MSG_MSGEXCEPTION_HPP\r
 \r
-#include "Exception.hpp"\r
+#include <Exception.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
                \r
-               class MsgException : public Exception\r
+               class SIMGRIDX_EXPORT MsgException : public Exception\r
                {\r
                        public:\r
                        \r
index d678d64..3d649a1 100644 (file)
@@ -1,20 +1,24 @@
-#include <object.hpp>\r
+#include <Object.hpp>\r
 #include <string.h>\r
 \r
 \r
 DeclaringClasses* DeclaringClass::declaringClasses = NULL;\r
 \r
 \r
-namespace msg\r
+namespace SimGrid\r
 {\r
-    // Generate static object constructor for class registration\r
-    void DeclareClass(Class* c)\r
-    {\r
-        MSG_DELCARING_CLASSES.lock();\r
-        MSG_DELCARING_CLASSES.addHead(c);\r
-        MSG_DELCARING_CLASSES.unlock();\r
-    }\r
-} \r
+       namespace Msg\r
+       {\r
+\r
+               // Generate static object constructor for class registration\r
+               void DeclareClass(Class* c)\r
+               {\r
+                       MSG_DELCARING_CLASSES.lock();\r
+                       MSG_DELCARING_CLASSES.addHead(c);\r
+                       MSG_DELCARING_CLASSES.unlock();\r
+               }\r
+       } // namespace Msg\r
+} // namespace SimGrid\r
 \r
 //////////////////////////////////////////////////////////////////////////////\r
 // Implémentation des fonctions membre de la classe Class\r
@@ -47,20 +51,18 @@ throw (ClassNotFoundException)
        for(cur = MSG_DELCARING_CLASSES.getHead(); cur; cur = cur->next)\r
        {\r
                if(!strcmp(name,cur->name))\r
-                       break;\r
+                       return cur;\r
+\r
        }\r
 \r
        MSG_DELCARING_CLASSES.unlock();\r
        throw ClassNotFoundException(name);\r
 }\r
 \r
+\r
 Object* Class::createObject(const char* name)\r
 {\r
        Class* c = fromName(name);\r
-       \r
-       if(NULL == c)\r
-               return NULL;\r
-               \r
        return c->createObject();\r
 }\r
 \r
@@ -146,5 +148,12 @@ bool DeclaringClasses::remove(Class* c)
        \r
        return success;\r
 }\r
+\r
+bool Object::isInstanceOf(const char* className)\r
+{\r
+       Class* c = Class::fromName(className);\r
+\r
+       return this->getClass()->isDerivedFrom(c);\r
+}\r
                \r
 \r
index 0ee57ed..bceac32 100644 (file)
@@ -1,11 +1,33 @@
 #include <Process.hpp>\r
 \r
+#include <MsgException.hpp>\r
+#include <NullPointerException.hpp>\r
+#include <HostNotFoundException.hpp>\r
+#include <ProcessNotFoundException.hpp>\r
+#include <InvalidArgumentException.hpp>\r
+#include <BadAllocException.hpp>\r
+#include <LogicException.hpp>\r
+\r
+\r
+#include <ApplicationHandler.hpp>\r
+#include <Host.hpp>\r
+#include <Task.hpp>\r
+\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+#include <msg/msg.h>\r
+#include <msg/private.h>\r
+#include <msg/mailbox.h>\r
+\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
-               Process* Process::currentProcess = NULL;\r
-               \r
+\r
+               MSG_IMPLEMENT_DYNAMIC(Process, Object);\r
+\r
                // Default constructor.\r
                Process::Process()\r
                {\r
@@ -46,11 +68,8 @@ namespace SimGrid
                        if(!name)\r
                                throw NullPointerException("name");\r
                                \r
-                       if(!hostName)\r
-                               throw NullPointerException("hostName");\r
-                               \r
                        if(argc < 0)\r
-                               throw InvalidArgument("argc (must be positive)");\r
+                               throw InvalidArgumentException("argc (must be positive)");\r
                                \r
                        if(!argc && argv)\r
                                throw LogicException("argv is not NULL but argc is zero");\r
@@ -61,7 +80,7 @@ namespace SimGrid
                        create(rHost, name, argc, argv);        \r
                }\r
                \r
-               Process::Process(const char* hostname, const char* name, int argc, char** argv)\r
+               Process::Process(const char* hostName, const char* name, int argc, char** argv)\r
                throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException)\r
                {\r
                        // check the parameters\r
@@ -73,7 +92,7 @@ namespace SimGrid
                                throw NullPointerException("hostName");\r
                                \r
                        if(argc < 0)\r
-                               throw InvalidArgument("argc (must be positive)");\r
+                               throw InvalidArgumentException("argc (must be positive)");\r
                                \r
                        if(!argc && argv)\r
                                throw LogicException("argv is not NULL but argc is zero");\r
@@ -81,7 +100,7 @@ namespace SimGrid
                        if(argc && !argv)\r
                                throw LogicException("argv is NULL but argc is not zero");\r
                                \r
-                       Host host = Host::getByName(hostname);\r
+                       Host host = Host::getByName(hostName);\r
                                \r
                        create(host, name, argc, argv); \r
                }\r
@@ -105,9 +124,9 @@ namespace SimGrid
                                throw MsgException("MSG_process_resume() failed");\r
                }\r
                \r
-               bool Process::isSuspended(void)\r
+               int Process::isSuspended(void)\r
                {\r
-                  return (bool)MSG_process_is_suspended(nativeProcess);\r
+                  return MSG_process_is_suspended(nativeProcess);\r
                }  \r
                \r
                Host& Process::getHost(void) \r
@@ -187,13 +206,13 @@ namespace SimGrid
                void Process::migrate(const Host& rHost)\r
                throw(MsgException)\r
                {\r
-                       if(MSG_OK != MSG_process_change_host(nativeProcess, rHost.nativeHost))\r
+                       if(MSG_OK != MSG_process_change_host(rHost.nativeHost))\r
                                throw MsgException("MSG_process_change_host()");\r
                        \r
                }\r
                \r
                void Process::sleep(double seconds)\r
-               throw(throw(InvalidArgumentException, MsgException))\r
+               throw(InvalidArgumentException, MsgException)\r
                {\r
                        // check the parameters.\r
                        if(seconds <= 0)\r
@@ -328,7 +347,7 @@ namespace SimGrid
                void Process::sendTask(const Task& rTask) \r
                throw(BadAllocException, MsgException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+                       char* alias = (char*)calloc( strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
                                \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -351,7 +370,7 @@ namespace SimGrid
                        if(timeout < 0 && timeout !=-1.0)\r
                                throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
                        \r
-                       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2 , sizeof(char));\r
                                \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -387,7 +406,7 @@ namespace SimGrid
                throw(BadAllocException, MsgException)\r
                {\r
                        \r
-                       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");       \r
@@ -436,7 +455,7 @@ namespace SimGrid
                                throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
                                \r
                        \r
-                       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2,  sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -484,7 +503,7 @@ namespace SimGrid
                        if(timeout < 0 && timeout !=-1.0)\r
                                throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
                        \r
-                       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -524,7 +543,7 @@ namespace SimGrid
                Task& Process::receiveTask(const Host& rHost) \r
                throw(BadAllocException, MsgException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+                       char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
@@ -543,7 +562,7 @@ namespace SimGrid
                        return (*((Task*)nativeTask->data));\r
                }\r
                \r
-               void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
+               /*void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
                throw(HostNotFoundException)\r
                {\r
                        smx_process_t nativeCurrentProcess = NULL;\r
@@ -561,7 +580,7 @@ namespace SimGrid
                                throw HostNotFoundException(rHost.getName());\r
                        \r
                        // realloc the list of the argument to add the pointer to this process instance at the end\r
-                       argv = (char**)realloc(argc + 1, sizeo(char*));\r
+                       argv = (char**)realloc(argc + 1, sizeof(char*));\r
                        \r
                        // add the pointer to this instance at the end of the list of the arguments of the process\r
                        // so the static method Process::run() (passed as argument of the MSG function xbt_context_new())\r
@@ -580,7 +599,7 @@ namespace SimGrid
                        // create the context of the process.\r
                        simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv);\r
                        \r
-                       /* Process structure */\r
+                       // Process structure \r
                        this->nativeProcess->name = xbt_strdup(name);\r
                        this->nativeProcess->simdata = simdata;\r
                        \r
@@ -592,7 +611,7 @@ namespace SimGrid
                        \r
                        xbt_swag_insert(this->nativeProcess, nativeHost->simdata->process_list);\r
                        \r
-                       /* fix current_process, about which xbt_context_start mocks around */\r
+                       // fix current_process, about which xbt_context_start mocks around \r
                        nativeCurrentProcess = simix_global->current_process;\r
                        xbt_context_start(this->nativeProcess->simdata->context);\r
                        simix_global->current_process = nativeCurrentProcess;\r
@@ -600,11 +619,79 @@ namespace SimGrid
                        xbt_swag_insert(this->nativeProcess, simix_global->process_list);\r
                        DEBUG2("Inserting %s(%s) in the to_run list", this->nativeProcess->name, nativeHost->name);\r
                        xbt_swag_insert(this->nativeProcess, simix_global->process_to_run);\r
+               }*/\r
+\r
+               void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
+               throw(InvalidArgumentException)\r
+               {\r
+                       char alias[MAX_ALIAS_NAME + 1] = {0};\r
+                       msg_mailbox_t mailbox;\r
+                       \r
+                       \r
+                       // try to retrieve the host where to createt the process from its name\r
+                       m_host_t nativeHost = rHost.nativeHost;\r
+                       \r
+                       if(!nativeHost)\r
+                               throw InvalidArgumentException("rHost"); \r
+                       \r
+                       /* allocate the data of the simulation */\r
+                       this->nativeProcess = xbt_new0(s_m_process_t,1);\r
+                       this->nativeProcess->simdata = xbt_new0(s_simdata_process_t,1);\r
+                       this->nativeProcess->name = _strdup(name);\r
+                       this->nativeProcess->simdata->m_host = nativeHost;\r
+                       this->nativeProcess->simdata->PID = msg_global->PID++;\r
+                       \r
+                       // realloc the list of the argument to add the pointer to this process instance at the end\r
+                       if(argc)\r
+                               argv = (char**)realloc(argv , (argc + 1) * sizeof(char*));\r
+                       else\r
+                               argv = (char**)calloc(1 ,sizeof(char*));\r
+                       \r
+                       // add the pointer to this instance at the end of the list of the arguments of the process\r
+                       // so the static method Process::run() (passed as argument of the MSG function xbt_context_new())\r
+                       // can retrieve the concerned process object by the run\r
+                       // so Process::run() can call the method main() of the good process\r
+                       // for more detail see Process::run() method\r
+                       argv[argc] = (char*)this;\r
+\r
+                       this->nativeProcess->simdata->argc = argc;\r
+                       this->nativeProcess->simdata->argv = argv;\r
+                       \r
+                       this->nativeProcess->simdata->s_process = SIMIX_process_create(\r
+                                                                       this->nativeProcess->name,\r
+                                                                       Process::run, \r
+                                                                       (void*)this->nativeProcess,\r
+                                                                       nativeHost->name, \r
+                                                                       argc,\r
+                                                                       argv, \r
+                                                                       NULL);\r
+                       \r
+                       if (SIMIX_process_self()) \r
+                       {/* someone created me */\r
+                               this->nativeProcess->simdata->PPID = MSG_process_get_PID((m_process_t)SIMIX_process_self()->data);\r
+                       } \r
+                       else \r
+                       {\r
+                               this->nativeProcess->simdata->PPID = -1;\r
+                       }\r
+                       \r
+                       this->nativeProcess->simdata->last_errno = MSG_OK;\r
+                       \r
+                       /* add the process to the list of the processes of the simulation */\r
+                       xbt_fifo_unshift(msg_global->process_list, this->nativeProcess);\r
+                       \r
+                       sprintf(alias,"%s:%s",(this->nativeProcess->simdata->m_host->simdata->smx_host)->name,this->nativeProcess->name);\r
+                       \r
+                       mailbox = MSG_mailbox_new(alias);\r
+                       \r
+                       MSG_mailbox_set_hostname(mailbox, this->nativeProcess->simdata->m_host->simdata->smx_host->name);\r
+\r
+                       \r
                }\r
                \r
-               Process& Process::fromNativeProcess(m_process_t nativeProcess)\r
+               Process* Process::fromNativeProcess(m_process_t nativeProcess)\r
                {\r
-                       return (*((Process*)(nativeProcess->simdata->arg[nativeProcess->argc])));\r
+                       return ((Process*)(nativeProcess->simdata->argv[nativeProcess->simdata->argc]));\r
                }\r
                \r
                int Process::run(int argc, char** argv)\r
@@ -614,6 +701,11 @@ namespace SimGrid
                        // for mor detail see Process::create() method\r
                        return ((Process*)argv[argc])->main(argc, argv);\r
                }\r
+\r
+               int Process::main(int argc, char** argv)\r
+               {\r
+                       throw LogicException("Process::main() not implemented");\r
+               }\r
                \r
        } // namespace Msg\r
 \r
index 10816ec..bd45c70 100644 (file)
        #error Process.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
+#include <msg/datatypes.h>\r
+\r
+#include <ApplicationHandler.hpp>\r
+#include <Object.hpp>\r
 \r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+               class NullPointerException;\r
+               class HostNotFoundException;\r
+               class ProcessNotFoundException;\r
+               class InvalidArgumentException;\r
+               class BadAllocException;\r
+               class LogicException;\r
+               class MsgException;\r
+\r
+               class ApplicationHandler;\r
+               class Host;\r
+               class Task;\r
+\r
                // SimGrid::Msg::Process class declaration.\r
-               class Process\r
+               class SIMGRIDX_EXPORT Process : public Object\r
                {\r
-                       friend ApplicationHandler;\r
                        \r
-                       private;\r
+                       friend ApplicationHandler::ProcessFactory;\r
                        \r
+                       MSG_DECLARE_DYNAMIC(Process);\r
+\r
+                       public:\r
                                // Disable the default constructor.\r
                                Process();\r
                        \r
-                       public:\r
                        \r
                                /*! \brief  Constructs a process from the name of the host and its name.\r
                                 *\r
@@ -143,10 +160,10 @@ namespace SimGrid
                        \r
                                /*! \brief Process::isSuspend() - Tests if a process is suspended.\r
                                 *\r
-                                * \return                              This method returns true is the process is suspended.\r
-                                *                                              Otherwise the method returns false.\r
+                                * \return                              This method returns 1 is the process is suspended.\r
+                                *                                              Otherwise the method returns 0.\r
                                 */\r
-                               bool isSuspended(void);\r
+                               int isSuspended(void);\r
                        \r
                                /*! \brief Process::getHost() - Retrieves the host of a process object.\r
                                 *\r
@@ -333,7 +350,7 @@ namespace SimGrid
                                 * \remark                              Set the timeout with -1.0 to disable it.\r
                                 */\r
                                Task& getTask(int channel, double timeout, const Host& rHost)\r
-                               throw(InvalidArgumentException MsgException);\r
+                               throw(InvalidArgumentException, MsgException);\r
                        \r
                                /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias\r
                                 * (waiting at most given time).\r
@@ -498,7 +515,7 @@ namespace SimGrid
                                 *\r
                                 *                                                      [MsgException]                          if an internal exception occurs.\r
                                 */\r
-                               Task& Process::receiveTask(double timeout, const Host& rHost) \r
+                               Task& receiveTask(double timeout, const Host& rHost) \r
                                throw(BadAllocException, InvalidArgumentException, MsgException);\r
                        \r
                                /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias\r
@@ -555,7 +572,7 @@ namespace SimGrid
                                 *\r
                                 * \return                              The wrapper associated with the native process specified as parameter.\r
                                 */\r
-                               static Process& fromNativeProcess(m_process_t nativeProcess);\r
+                               static Process* fromNativeProcess(m_process_t nativeProcess);\r
                        \r
                        \r
                        public:\r
@@ -572,7 +589,7 @@ namespace SimGrid
                                 *\r
                                 * \return                              The exit code of the main function.\r
                                 */\r
-                               virtual int main(int argc, char** argv) = 0;\r
+                               virtual int main(int argc, char** argv);\r
                                \r
                        private:\r
                                \r
@@ -584,4 +601,6 @@ namespace SimGrid
        \r
        } //namepace Msg\r
 \r
-} namespace SimGrid
\ No newline at end of file
+} // namespace SimGrid\r
+\r
+#endif // !MSG_PROCESS_HPP
\ No newline at end of file
index b1fd89e..34ee0fd 100644 (file)
   \r
 #include <Simulation.hpp>\r
 \r
+#include <Application.hpp>\r
+#include <Environment.hpp>\r
+\r
+#include <MsgException.hpp>\r
+#include <FileNotFoundException.hpp>\r
+\r
+#include <Msg.hpp>\r
+\r
+#include <msg/msg.h> \r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
-               \r
-               \r
                int Simulation::execute(int argc, char** argv)\r
                {\r
                        if(argc < 3) \r
@@ -55,6 +63,7 @@ namespace SimGrid
                        try\r
                        {\r
                                app.deploy(argv[2]);\r
+                       }\r
                        catch(FileNotFoundException e)\r
                        {\r
                                info(e.toString());\r
@@ -65,7 +74,7 @@ namespace SimGrid
                        //try to run the simulation the given application on the given environment\r
                        try\r
                        {\r
-                               this->run();\r
+                               run();\r
                        }\r
                        catch(MsgException e)\r
                        {\r
@@ -81,7 +90,7 @@ namespace SimGrid
                        }\r
                        catch(MsgException e)\r
                        {\r
-                               info(e.toString())\r
+                               info(e.toString());\r
                                return 1;\r
                        }\r
                        \r
index 00f4ab1..de97d90 100644 (file)
        #error Sumulation.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
+#include <Config.hpp>\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+               class MsgException;\r
+               class FileNotFoundException;\r
+\r
                // Simulation class declaration.\r
-               class Simulation\r
+               class SIMGRIDX_EXPORT Simulation\r
                {\r
                        public :\r
                        \r
-                               Simulation();\r
+                               Simulation(){};\r
                                \r
                                Simulation(const Simulation& rSimulation);\r
                                \r
-                               virtual ~Simulation();\r
+                               virtual ~Simulation(){};\r
                                \r
                        // Operations.\r
                        \r
index c9ef4f0..b0c2ccb 100644 (file)
@@ -1,9 +1,25 @@
 #include <Task.hpp>\r
 \r
+#include <MsgException.hpp>\r
+#include <InvalidArgumentException.hpp>\r
+#include <NullPointerException.hpp>\r
+#include <MsgException.hpp>\r
+#include <BadAllocException.hpp>\r
+\r
+#include <Process.hpp>\r
+#include <Host.hpp>\r
+\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+#include <msg/msg.h>\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+\r
+               MSG_IMPLEMENT_DYNAMIC(Task, Object);\r
        \r
                Task::Task()\r
                {\r
@@ -13,11 +29,12 @@ namespace SimGrid
                \r
                Task::Task(const Task& rTask)\r
                {\r
+                       this->nativeTask = rTask.nativeTask;\r
                }\r
                \r
                \r
                Task::~Task()\r
-               throw(NativeException)\r
+               throw(MsgException)\r
                {\r
                        if(NULL != nativeTask)\r
                                if(MSG_OK != MSG_task_destroy(nativeTask))\r
@@ -28,7 +45,7 @@ namespace SimGrid
                Task::Task(const char* name, double computeDuration, double messageSize)\r
                throw(InvalidArgumentException, NullPointerException)\r
                {\r
-                        \r
+\r
                        if(computeDuration < 0) \r
                                throw InvalidArgumentException("computeDuration");\r
                        \r
@@ -47,7 +64,6 @@ namespace SimGrid
                Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)\r
                throw(NullPointerException, InvalidArgumentException)\r
                {\r
-                       \r
                        // check the parameters\r
                        \r
                        if(!name) \r
@@ -91,7 +107,7 @@ namespace SimGrid
                        \r
                        \r
                        \r
-                       task->data = (void*)this;\r
+                       this->nativeTask->data = (void*)this;\r
                        \r
                }\r
                \r
@@ -102,7 +118,7 @@ namespace SimGrid
                \r
                Process& Task::getSender(void) const\r
                {\r
-                       m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask);\r
+                       m_process_t nativeProcess = MSG_task_get_sender(nativeTask);\r
                        \r
                        return (*((Process*)(nativeProcess->data)));\r
                }\r
@@ -135,7 +151,7 @@ namespace SimGrid
                        MSG_task_set_priority(nativeTask, priority);\r
                }\r
                \r
-               Task& Task::get(int channel) \r
+               /*Task& Task::get(int channel) \r
                throw(InvalidArgumentException, MsgException)\r
                {\r
                        // check the parameters\r
@@ -149,6 +165,22 @@ namespace SimGrid
                                throw MsgException("MSG_task_get_ext() failed");\r
                        \r
                        return (*((Task*)(nativeTask->data)));\r
+               }*/\r
+\r
+               Task* Task::get(int channel) \r
+               throw(InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(channel < 0)\r
+                               throw InvalidArgumentException("channel (must not be negative)");\r
+                               \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) \r
+                               throw MsgException("MSG_task_get_ext() failed");\r
+                       \r
+                       return ((Task*)(nativeTask->data));\r
                }\r
                \r
                Task& Task::get(int channel, const Host& rHost) \r
@@ -188,7 +220,7 @@ namespace SimGrid
                        return (*((Task*)(nativeTask->data)));\r
                }\r
                \r
-               bool static Task::probe(int channel)\r
+               int Task::probe(int channel)\r
                throw(InvalidArgumentException)\r
                {\r
                        // check the parameters\r
@@ -196,7 +228,7 @@ namespace SimGrid
                        if(channel < 0)\r
                                throw InvalidArgumentException("channel (must not be negative)");\r
                                \r
-                       return (bool)MSG_task_Iprobe(channel);\r
+                       return MSG_task_Iprobe(channel);\r
                }\r
                \r
                int Task::probe(int channel, const Host& rHost)\r
@@ -207,7 +239,7 @@ namespace SimGrid
                        if(channel < 0)\r
                                throw InvalidArgumentException("channel (must not be negative)");\r
                                \r
-                       return MSG_task_probe_from_host(chan_id,rHost.nativeHost);\r
+                       return MSG_task_probe_from_host(channel,rHost.nativeHost);\r
                }\r
                \r
                void Task::execute(void) \r
@@ -227,16 +259,16 @@ namespace SimGrid
                void Task::send(void) \r
                throw(BadAllocException, MsgException)\r
                {       \r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                                \r
                        MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0);\r
                \r
-                       free(alias)\r
+                       free(alias);\r
                \r
                        if(MSG_OK != rv)\r
                                throw MsgException("MSG_task_send_with_timeout() failed");\r
@@ -255,23 +287,23 @@ namespace SimGrid
                }\r
                \r
                void Task::send(double timeout) \r
-               throw(BadAllocationException, InvalidArgumentException, MsgException)\r
+               throw(BadAllocException, InvalidArgumentException, MsgException)\r
                {\r
                        // check the parameters\r
                        \r
                        if(timeout < 0  && timeout != -1.0)\r
                                throw InvalidArgumentException("timeout (must not be negative and different than -1.0");\r
                                                \r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                \r
                        MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, timeout);\r
                \r
-                       free(alias)\r
+                       free(alias);\r
                \r
                        if(MSG_OK != rv)\r
                                throw MsgException("MSG_task_send_with_timeout() failed");\r
@@ -301,12 +333,12 @@ namespace SimGrid
                        if(maxRate < 0 && maxRate != -1.0)\r
                                throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");\r
                                        \r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                        \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                        \r
                        MSG_error_t rv = MSG_task_send_bounded(nativeTask, alias, maxRate);\r
                        \r
@@ -332,15 +364,15 @@ namespace SimGrid
                                throw MsgException("MSG_task_send_bounded() failed");\r
                }\r
                \r
-               Task& Task::receive(void) \r
-               throw(throw(BadAllocException, MsgException))\r
+               /*Task& Task::receive(void) \r
+               throw(BadAllocException, MsgException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                                \r
                        m_task_t nativeTask = NULL;\r
                        \r
@@ -352,9 +384,31 @@ namespace SimGrid
                                throw MsgException("MSG_task_receive_ext() failed");\r
                \r
                        return (*((Task*)nativeTask->data));\r
+               }*/\r
+\r
+               Task* Task::receive(void) \r
+               throw(BadAllocException, MsgException)\r
+               {\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
+                       \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");\r
+                               \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
+                               \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);  \r
+               \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK != rv) \r
+                               throw MsgException("MSG_task_receive_ext() failed");\r
+               \r
+                       return ((Task*)nativeTask->data);\r
                }\r
                \r
-               Task& Task::receive(const char* alias) \r
+               /*Task& Task::receive(const char* alias) \r
                throw(NullPointerException, MsgException)\r
                {\r
                        // check the parameters\r
@@ -368,6 +422,22 @@ namespace SimGrid
                                throw MsgException("MSG_task_receive_ext() failed");\r
                \r
                        return (*((Task*)nativeTask->data));\r
+               }*/\r
+\r
+               Task* Task::receive(const char* alias) \r
+               throw(NullPointerException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(!alias)\r
+                               throw NullPointerException("alias");\r
+                               \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) \r
+                               throw MsgException("MSG_task_receive_ext() failed");\r
+               \r
+                       return ((Task*)nativeTask->data);\r
                }\r
                \r
                Task& Task::receive(const char* alias, double timeout) \r
@@ -378,7 +448,7 @@ namespace SimGrid
                        if(!alias)\r
                                throw NullPointerException("alias");\r
                        \r
-                       if(timeout < 0 && alias != -1.0)\r
+                       if(timeout < 0 && timeout != -1.0)\r
                                throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");\r
                                \r
                        m_task_t nativeTask = NULL;\r
@@ -413,7 +483,7 @@ namespace SimGrid
                        if(!alias)\r
                                throw NullPointerException("alias");\r
                        \r
-                       if(timeout < 0 && alias != -1.0)\r
+                       if(timeout < 0 && timeout != -1.0)\r
                                throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");\r
                                \r
                        m_task_t nativeTask = NULL;\r
@@ -425,24 +495,24 @@ namespace SimGrid
                        return (*((Task*)nativeTask->data));\r
                }\r
                \r
-               bool Task::listen(void) \r
+               int Task::listen(void) \r
                throw(BadAllocException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                                \r
                        int rv = MSG_task_listen(alias);\r
                        \r
                        free(alias);\r
                        \r
-                       return (bool)rv;\r
+                       return rv;\r
                }       \r
                \r
-               bool Task::listen(const char* alias) \r
+               int Task::listen(const char* alias) \r
                throw(NullPointerException)\r
                {\r
                        // check the parameters\r
@@ -450,18 +520,18 @@ namespace SimGrid
                        if(!alias)\r
                                throw NullPointerException("alias");\r
                                \r
-                       return (bool)MSG_task_listen(alias);\r
+                       return MSG_task_listen(alias);\r
                }\r
                \r
                int Task::listenFrom(void) \r
                throw(BadAllocException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                        \r
                        int rv = MSG_task_listen_from(alias);\r
                        \r
@@ -483,12 +553,12 @@ namespace SimGrid
                int Task::listenFromHost(const Host& rHost) \r
                throw(BadAllocException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                        \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                        \r
                        int rv = MSG_task_listen_from_host(alias, rHost.nativeHost);\r
                        \r
@@ -506,6 +576,12 @@ namespace SimGrid
                                \r
                        return MSG_task_listen_from_host(alias, rHost.nativeHost);\r
                }       \r
+\r
+               const Task& Task::operator = (const Task& rTask)\r
+               {\r
+                       this->nativeTask = rTask.nativeTask;\r
+                       return *this;\r
+               }\r
        } // namespace Msg                                                                                                                                                                                              \r
 } // namespace SimGrid\r
 \r
index 143f668..a158f4f 100644 (file)
 \r
 // Compilation C++ recquise\r
 #ifndef __cplusplus\r
-       #error Process.hpp requires C++ compilation (use a .cxx suffix)\r
+       #error Task.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
+#include <msg/datatypes.h>\r
+\r
+#include <Config.hpp>\r
+\r
+#include <Object.hpp>\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+               class MsgException;\r
+               class InvalidArgumentException;\r
+               class NullPointerException;\r
+               class MsgException;\r
+               class BadAllocException;\r
+\r
+               class Process;\r
+               class Host;\r
+\r
                // SimGrid::Msg::Task wrapper class declaration.\r
-               class Task\r
+               class SIMGRIDX_EXPORT Task : public Object\r
                {\r
+                       MSG_DECLARE_DYNAMIC(Task);\r
+\r
+                       friend Process;\r
+                       friend Host;\r
+\r
                        protected:\r
                                // Default constructor.\r
                                Task();\r
+\r
+                       class Ref\r
+                       {\r
+                       public:\r
+                               Ref(Task* task)\r
+                               {\r
+                                       count = 1;\r
+                                       this->task = task;\r
+                               }\r
+\r
+                               virtual ~Ref(){}\r
+\r
+                               void operator++(void){\r
+                                       count++;\r
+                                       \r
+                               }\r
+\r
+                               void operator--(void){\r
+                                       if(--count <= 0)\r
+                                               delete p;\r
+                               }\r
+\r
+                       private:\r
+                               int count;\r
+                               Task* task;\r
+\r
+                       };\r
                                \r
                        public:\r
                                /*! \brief Copy constructor.\r
@@ -144,9 +191,12 @@ namespace SimGrid
                                 *                                      \r
                                 *                                                      [MsgException]                          if an internal excpetion occurs.\r
                                 */\r
-                               static Task& get(int channel) \r
-                               throw(InvalidArgumentException, MsgException); \r
-                               \r
+                               /*static Task& get(int channel) \r
+                               throw(InvalidArgumentException, MsgException);*/\r
+\r
+                               static Task* get(int channel) \r
+                               throw(InvalidArgumentException, MsgException);\r
+\r
                                /*! \brief      Task::get() - Gets a task from the given channel number of the given host.      \r
                                 *\r
                                 * \param channel                       The channel number.\r
@@ -184,14 +234,14 @@ namespace SimGrid
                                 *\r
                                 * \param channel                       The channel number.\r
                                 *\r
-                                * \return                                      If there is a waiting task on the channel the method returns true. Otherwise\r
-                                *                                                      the method returns false.\r
+                                * \return                                      If there is a waiting task on the channel the method returns 1. Otherwise\r
+                                *                                                      the method returns 0.\r
                                 *\r
                                 * \exception                           If this method fails, it throws the exception described below:\r
                                 *\r
                                 *                                                      [InvalidArgumentException]      if the parameter channel is negative.\r
                                 */\r
-                               static bool probe(int channel)\r
+                               static int probe(int channel)\r
                                throw(InvalidArgumentException);\r
                                \r
                                /*! \brief Task::probe() - Counts tasks waiting on the given channel of local host and sent by given host.\r
@@ -266,7 +316,7 @@ namespace SimGrid
                                 *                                                      [MsgException]                          if an internal exception occurs.\r
                                 */\r
                                void send(double timeout) \r
-                               throw(BadAllocationException, InvalidArgumentException, MsgException);\r
+                               throw(BadAllocException, InvalidArgumentException, MsgException);\r
                                \r
                                /*! \brief Task::send() - Send the task on the mailbox identified by a given alias\r
                                 * (waiting at most given time).\r
@@ -333,7 +383,10 @@ namespace SimGrid
                                 *\r
                                 *                                                      [MsgException]                          if an internal exception occurs.\r
                                 */\r
-                               static Task& receive(void) \r
+                               /*static Task& receive(void) \r
+                               throw(BadAllocException, MsgException);*/\r
+\r
+                               static Task* receive(void) \r
                                throw(BadAllocException, MsgException);\r
                                \r
                                /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located\r
@@ -349,7 +402,9 @@ namespace SimGrid
                                 *\r
                                 *                                                      [MsgException]                          if an internal exception occurs.\r
                                 */\r
-                               static Task& receive(const char* alias) \r
+                               /*static Task& receive(const char* alias) \r
+                               throw(NullPointerException, MsgException);*/\r
+                               static Task* receive(const char* alias) \r
                                throw(NullPointerException, MsgException);\r
                                \r
                                /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located\r
@@ -420,7 +475,7 @@ namespace SimGrid
                                 *\r
                                 *                                                      [BadAllocException]                     if there is not enough memory to build the default alias.\r
                                 */\r
-                               static bool listen(void) \r
+                               static int listen(void) \r
                                throw(BadAllocException);\r
                                \r
                                /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox \r
@@ -428,14 +483,14 @@ namespace SimGrid
                                 *\r
                                 * \param alias                         The alias of the mailbox.\r
                                 *\r
-                                * \return                                      If there is a waiting task on the mailbox the method returns true.\r
-                                *                                                      Otherwise the method returns false.\r
+                                * \return                                      If there is a waiting task on the mailbox the method returns 1.\r
+                                *                                                      Otherwise the method returns 0.\r
                                 *\r
                                 * \exception                           If this method fails, it throws one of the exceptions described below:\r
                                 *\r
                                 *                                                      [NullPointerException]          if the parameter alias is NULL.\r
                                 */\r
-                               static bool listen(const char* alias) \r
+                               static int listen(const char* alias) \r
                                throw(NullPointerException);\r
                                \r
                                /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox \r
@@ -496,17 +551,23 @@ namespace SimGrid
                                 *                                                      [BadAllocException]                     if there is not enough memory to build the default\r
                                 *                                                                                                              alias.\r
                                 */\r
-                               static bool listenFromHost(const char* alias, const Host& rHost) \r
-                               throw(NullPointerException, NativeException);\r
+                               static int listenFromHost(const char* alias, const Host& rHost) \r
+                               throw(NullPointerException, MsgException);\r
+\r
+                               virtual const Task& operator= (const Task& rTask);\r
                        \r
-                       private:\r
+                       protected:\r
                                \r
                                // Attributes.\r
                                \r
-                                       m_task_t nativeTask;    // the native MSG task.\r
+                               m_task_t nativeTask;    // the native MSG task.\r
+\r
+                               Ref* ref;\r
                };\r
        \r
        } // namespace Msg \r
 } // namespace SimGrid\r
 \r
+typedef Task* TaskPtr;\r
+\r
 #endif // §MSG_TASK_HPP
\ No newline at end of file