Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Code refactoring on CPP
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 20 Jun 2008 12:23:28 +0000 (12:23 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 20 Jun 2008 12:23:28 +0000 (12:23 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5780 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/cxx/Application.cxx
src/cxx/Application.hpp
src/cxx/ApplicationHandler.cxx
src/cxx/ApplicationHandler.hpp
src/cxx/Environment.cxx
src/cxx/Environment.hpp
src/cxx/Object.cxx
src/cxx/Process.cxx
src/cxx/Simulation.cxx
src/cxx/Simulation.hpp

index 6e6ea8b..e11cab9 100644 (file)
@@ -1,3 +1,18 @@
+/*\r
+ * Application.cxx\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */\r
\r
+ /* Application member functions implementation.\r
+  */  \r
+  \r
 #include <Application.hpp>\r
 #include <ApplicationHandler.hpp>\r
 \r
 #include <Application.hpp>\r
 #include <ApplicationHandler.hpp>\r
 \r
@@ -27,17 +42,17 @@ namespace SimGrid
                }\r
        \r
                Application::Application(const char* file)\r
                }\r
        \r
                Application::Application(const char* file)\r
-               throw(InvalidParameterException)\r
+               throw(NullPointerException, FileNotFoundException)\r
                {\r
                        // check parameters\r
                        \r
                        if(!file)\r
                {\r
                        // check parameters\r
                        \r
                        if(!file)\r
-                               throw InvalidParameterException("file (must not be NULL");\r
+                               throw NullPointerException("file");\r
                        \r
                        struct stat statBuf = {0};\r
                                \r
                        if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
                        \r
                        struct stat statBuf = {0};\r
                                \r
                        if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
-                               throw InvalidParameterException("file (file not found)");\r
+                               throw FileNotFoundException(file);\r
                                \r
                        this->file = file;\r
                        this->deployed = false;\r
                                \r
                        this->file = file;\r
                        this->deployed = false;\r
@@ -49,7 +64,7 @@ namespace SimGrid
                }\r
                        \r
                Application::deploy(const char* file)\r
                }\r
                        \r
                Application::deploy(const char* file)\r
-               throw(InvalidParameterException, LogicException, MsgException)\r
+               throw(NullPointerException, FileNotFoundException, LogicException, MsgException)\r
                {\r
                        // check logic\r
                        \r
                {\r
                        // check logic\r
                        \r
@@ -59,25 +74,39 @@ namespace SimGrid
                        // check the parameters\r
                                \r
                        if(!file)\r
                        // check the parameters\r
                                \r
                        if(!file)\r
-                               throw InvalidParameterException("file (must not be NULL");\r
+                               throw NullPointerException("file");\r
                        \r
                        struct stat statBuf = {0};\r
                                \r
                        if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
                        \r
                        struct stat statBuf = {0};\r
                                \r
                        if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
-                               throw InvalidParameterException("file (file not found)");\r
+                               throw FileNotFoundException(file);\r
                                        \r
                        surf_parse_reset_parser();\r
                                        \r
                        surf_parse_reset_parser();\r
+                       \r
+                       // set the begin of the xml process element handler\r
                        surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
                        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::onArg);\r
+                               \r
+                       // set the properties handler\r
                        surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\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
 \r
                        surf_parse_open(file);\r
                        \r
                        surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);\r
 \r
                        surf_parse_open(file);\r
                        \r
+                       // initialize the process factory used by the process handler to build the processes.\r
+                       ApplicationHandler::onStartDocument();\r
+                               \r
                        if(surf_parse())\r
                                throw MsgException("surf_parse() failed");\r
                        \r
                        if(surf_parse())\r
                                throw MsgException("surf_parse() failed");\r
                        \r
-                       surf_parse_close();     \r
+                       surf_parse_close();\r
+                       \r
+                       // release the process factory\r
+                       ApplicationHandler::onEndDocument();    \r
                        \r
                        this->file = file;\r
                        this->deployed = true;\r
                        \r
                        this->file = file;\r
                        this->deployed = true;\r
@@ -117,7 +146,7 @@ namespace SimGrid
                }\r
                \r
                void Application::setFile(const char* file)\r
                }\r
                \r
                void Application::setFile(const char* file)\r
-               throw (InvalidParameterException, LogicException)\r
+               throw (NullPointerException, FileNotFoundException, LogicException)\r
                {\r
                        // check logic\r
                        \r
                {\r
                        // check logic\r
                        \r
@@ -127,12 +156,12 @@ namespace SimGrid
                        // check parameters\r
                        \r
                        if(!file)\r
                        // check parameters\r
                        \r
                        if(!file)\r
-                               throw InvalidParameterException("file (must not be NULL");\r
+                               throw NullPointerException("file");\r
                        \r
                        struct stat statBuf = {0};\r
                                \r
                        if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
                        \r
                        struct stat statBuf = {0};\r
                                \r
                        if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
-                               throw InvalidParameterException("file (file not found)");\r
+                               throw FileNotFoundException("file (file not found)");\r
                                \r
                        this->file = file;\r
                        \r
                                \r
                        this->file = file;\r
                        \r
index 81cf005..1ca158f 100644 (file)
@@ -1,3 +1,17 @@
+/*\r
+ * Application.hpp\r
+ *\r
+ * This file contains the declaration of the wrapper class of the native MSG task type.\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */  \r
\r
 #ifndef MSG_APPLICATION_HPP\r
 #define MSG_APPLICATION_HPP\r
 \r
 #ifndef MSG_APPLICATION_HPP\r
 #define MSG_APPLICATION_HPP\r
 \r
@@ -5,7 +19,8 @@
        #error Application.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
        #error Application.hpp requires C++ compilation (use a .cxx suffix)\r
 #endif\r
 \r
-#include <InvalidParameterException.hpp>\r
+#include <NullPointerException.hpp>\r
+#include <FileNotFoundException.hpp>\r
 #include <LogicException.hpp>\r
 #include <MsgException.hpp>\r
 \r
 #include <LogicException.hpp>\r
 #include <MsgException.hpp>\r
 \r
@@ -13,11 +28,13 @@ namespace SimGrid
 {\r
        namespace Msg\r
        {\r
 {\r
        namespace Msg\r
        {\r
+               // Application wrapper class declaration.\r
                class Application\r
                {\r
                public:\r
                        \r
                class Application\r
                {\r
                public:\r
                        \r
-               // Default constructor.\r
+                       /*! \brief Default constructor.\r
+                        */\r
                        Application();\r
                        \r
                        /*! \brief Copy constructor.\r
                        Application();\r
                        \r
                        /*! \brief Copy constructor.\r
@@ -26,11 +43,15 @@ namespace SimGrid
                        \r
                        /* \brief A constructor which takes as parameter the xml file of the application.\r
                         *\r
                        \r
                        /* \brief A constructor which takes as parameter the xml file of the application.\r
                         *\r
-                        * \exception           [InvalidParameterException]     if the parameter file is invalid\r
-                        *                                      (NULL or if the file does not exist).\r
+                        * \exception           If this constructor fails, it throws on of the exceptions described\r
+                        *                                      below:\r
+                        *              \r
+                        *                                      [NullPointerException]  if the parameter file is NULL.\r
+                        *\r
+                        *                                      [FileNotFoundException] if the file is not found.\r
                         */\r
                        Application(const char* file)\r
                         */\r
                        Application(const char* file)\r
-                       throw(InvalidParameterException);\r
+                       throw(NullPointerException, FileNotFoundException);\r
                        \r
                        /*! \brief Destructor.\r
                         */\r
                        \r
                        /*! \brief Destructor.\r
                         */\r
@@ -40,8 +61,7 @@ namespace SimGrid
                        \r
                        /*! \brief Application::deploy() - deploy the appliction.\r
                         *\r
                        \r
                        /*! \brief Application::deploy() - deploy the appliction.\r
                         *\r
-                        * \return                      If successfuly the application is deployed. Otherwise\r
-                        *                                      the method throws an exception listed below.\r
+                        * \exception           If this method fails, it throws an exception listed below:\r
                         *\r
                         * \exception           [LogicException]                        if the xml file which describes the application\r
                         *                                                                                              is not yet specified or if the application is already\r
                         *\r
                         * \exception           [LogicException]                        if the xml file which describes the application\r
                         *                                                                                              is not yet specified or if the application is already\r
@@ -57,22 +77,25 @@ namespace SimGrid
                        void deploy(void)\r
                        throw(LogicExeption, MsgException);\r
                        \r
                        void deploy(void)\r
                        throw(LogicExeption, MsgException);\r
                        \r
-                       /*! \brief Application::deploy() - deploy the appliction.\r
+                       /*! \brief Application::deploy() - Deploy the appliction.\r
                         *\r
                         * \return                      If successfuly the application is deployed. Otherwise\r
                         *                                      the method throws an exception listed below.\r
                         *\r
                         *\r
                         * \return                      If successfuly the application is deployed. Otherwise\r
                         *                                      the method throws an exception listed below.\r
                         *\r
-                        * \exception           [InvalidParameterException]     if the parameter file is invalid\r
-                        *                                      (NULL or not a xml deployment file name).\r
+                        * \exception           [NullPointerException]          if the parameter file is NULL.\r
+                        *                                      \r
+                        *                                      [FileNotFoundException]         if the file is not found.\r
+                        *\r
                         *                                      [MsgException]                          if a internal exception occurs.\r
                         *                                      [MsgException]                          if a internal exception occurs.\r
+                        *\r
                         *                                      [LogicException]                        if the application is already deployed.\r
                         *\r
                         * \\r
                         */\r
                        void deploy(const char* file)\r
                         *                                      [LogicException]                        if the application is already deployed.\r
                         *\r
                         * \\r
                         */\r
                        void deploy(const char* file)\r
-                       throw(InvalidParameterException, LogicException, MsgException);\r
+                       throw(NullPointerException, FileNotFoundException, LogicException, MsgException);\r
                        \r
                        \r
-                       /*! \brief Application::isDeployed() - tests if the application is deployed.\r
+                       /*! \brief Application::isDeployed() - Tests if the application is deployed.\r
                         *\r
                         * \return                      This method returns true is the application is deployed.\r
                         *                                      Otherwise the method returns false.\r
                         *\r
                         * \return                      This method returns true is the application is deployed.\r
                         *                                      Otherwise the method returns false.\r
@@ -84,18 +107,20 @@ namespace SimGrid
                        \r
                        /*! \brief Application::setFile() - this setter sets the value of the file of the application.\r
                         *\r
                        \r
                        /*! \brief Application::setFile() - this setter sets the value of the file of the application.\r
                         *\r
-                        * \return                      If successful, the value of the file of the application is setted.\r
-                        *                                      Otherwise the method throws on of the exceptions listed below.\r
+                        * \exception           If this method fails, it throws on of the exceptions listed below:\r
+                        *\r
+                        *                                      [NullPointerException]          if the parameter file is NULL.\r
                         *\r
                         *\r
-                        * \exception           [InvalidParameterException]     if the parameter file is invalid\r
-                        *                                                                                              (NULL or does no exist).\r
+                        *                                      [FileNotFoundException]         if the file is not found.\r
+                        \r
                         *                                      [LogicException]                        if you try to set the value of the file of an\r
                         *                                                                                              application which is already deployed.\r
                         */\r
                        void setFile(const char* file)\r
                         *                                      [LogicException]                        if you try to set the value of the file of an\r
                         *                                                                                              application which is already deployed.\r
                         */\r
                        void setFile(const char* file)\r
-                       throw (InvalidParameterException, LogicException);\r
+                       throw (NullPointerException, FileNotFoundException, LogicException);\r
                        \r
                        \r
-                       /*! \brief Application::getFile() - this getter returns the file of an application object.\r
+                       /*! \brief Application::getFile() - This getter returns the name of the xml file which describes the \r
+                        * application of the simulation.\r
                         */\r
                        const char* getFile(void) const;\r
                        \r
                         */\r
                        const char* getFile(void) const;\r
                        \r
@@ -113,9 +138,9 @@ namespace SimGrid
                        \r
                        // flag : if true the application was deployed.\r
                        bool deployed;\r
                        \r
                        // flag : if true the application was deployed.\r
                        bool deployed;\r
-                       // the xml file which describe the application.\r
-                       const char* file;\r
                        \r
                        \r
+                       // the xml file which describes the application of the simulation.\r
+                       const char* file;\r
                };\r
                \r
        } // namespace Msg\r
                };\r
                \r
        } // namespace Msg\r
index 5d6d3f2..f1a8077 100644 (file)
@@ -1,3 +1,18 @@
+/*\r
+ * ApplicationHandler.cxx\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */\r
\r
+ /* ApplicationHandler member functions implementation.\r
+  */  \r
+  \r
 #include <ApplicationHandler.hpp>\r
 \r
 namespace SimGrid\r
 #include <ApplicationHandler.hpp>\r
 \r
 namespace SimGrid\r
@@ -33,7 +48,7 @@ namespace SimGrid
                {\r
                        return *this;\r
                }\r
                {\r
                        return *this;\r
                }\r
-                       \r
+               \r
                void ApplicationHandler::onStartDocument(void)\r
                {\r
                        // instanciate the factory at the begining of the parsing\r
                void ApplicationHandler::onStartDocument(void)\r
                {\r
                        // instanciate the factory at the begining of the parsing\r
@@ -84,31 +99,19 @@ namespace SimGrid
                \r
                // create the cxx process wrapper.\r
                void ApplicationHandler::ProcessFactory::createProcess() \r
                \r
                // create the cxx process wrapper.\r
                void ApplicationHandler::ProcessFactory::createProcess() \r
+               throw (ClassNotFoundException, HostNotFoundException)\r
                {\r
                        Host host;\r
                        Process* process;\r
                        \r
                {\r
                        Host host;\r
                        Process* process;\r
                        \r
-                       // dynamic creation of a instance fo the process from its name (which is specified by the element function\r
+                       // 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
                        // in the xml application file.\r
-                       try\r
-                       {\r
-                               process = (Process*)Class::fromName(this->function);\r
-                       }\r
-                       catch(ClassNotFoundException e)\r
-                       {\r
-                               cerr << e.toString();   \r
-                       }\r
+                       // if this static method fails, it throws an exception of the class ClassNotFoundException\r
+                       process = (Process*)Class::fromName(this->function);\r
                        \r
                        // try to retrieve the host of the process from its name\r
                        \r
                        // try to retrieve the host of the process from its name\r
-                       try\r
-                       {\r
-                               host = Host::getByName(this->hostName); \r
-                       }\r
-                       catch(HostNotFoundException(this->hostName))\r
-                       {\r
-                               cerr << e.toString();\r
-                       }\r
-                               \r
+                       // if this method fails, it throws an exception of the class HostNotFoundException\r
+                       host = Host::getByName(this->hostName); \r
                        \r
                        // build the list of the arguments of the newly created process.\r
                        int argc = xbt_dynar_length(this->args);\r
                        \r
                        // build the list of the arguments of the newly created process.\r
                        int argc = xbt_dynar_length(this->args);\r
index c33cc76..37e5bf1 100644 (file)
@@ -1,3 +1,17 @@
+/*\r
+ * ApplicationHandler.hpp\r
+ *\r
+ * This file contains the declaration of the wrapper class of the native MSG task type.\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */  \r
\r
 #ifndef MSG_APPLICATION_HANDLER_HPP\r
 #define MSG_APPLICATION_HANDLER_HPP\r
 \r
 #ifndef MSG_APPLICATION_HANDLER_HPP\r
 #define MSG_APPLICATION_HANDLER_HPP\r
 \r
 #endif\r
 \r
 \r
 #endif\r
 \r
 \r
+#include <ClassNotFoundException.hpp>\r
+#include <HostNotFoundException.hpp>\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
-               // Declaration of the class ApplicationHandler.\r
+               // Declaration of the class ApplicationHandler (Singleton).\r
                class ApplicationHandler\r
                {\r
                private :\r
                class ApplicationHandler\r
                {\r
                private :\r
@@ -71,13 +88,15 @@ namespace SimGrid
                                const const char* getHostName(void);\r
                                \r
                                // Create the current process.\r
                                const const char* getHostName(void);\r
                                \r
                                // Create the current process.\r
-                       void createProcess(void); \r
+                       void createProcess(void)\r
+                       throw (ClassNotFoundException, HostNotFoundException); \r
                        \r
                        };\r
                        \r
                        // the process factory used by the application handler.\r
                        static ProcessFactory* processFactory;\r
                        \r
                        \r
                        };\r
                        \r
                        // the process factory used by the application handler.\r
                        static ProcessFactory* processFactory;\r
                        \r
+                       \r
                        public:\r
                        \r
                        // Handle the begining of the parsing of the xml file describing the application.\r
                        public:\r
                        \r
                        // Handle the begining of the parsing of the xml file describing the application.\r
index a44fd2a..489c814 100644 (file)
@@ -1,3 +1,18 @@
+/*\r
+ * Environment.cxx\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */\r
\r
+ /* Environment member functions implementation.\r
+  */  \r
+  \r
 #include <Environment.hpp>\r
 \r
 #include <sys/types.h>\r
 #include <Environment.hpp>\r
 \r
 #include <sys/types.h>\r
index af8657d..cc21c72 100644 (file)
@@ -29,6 +29,7 @@ namespace SimGrid
 {\r
        namespace Msg\r
        {\r
 {\r
        namespace Msg\r
        {\r
+               // Environment class wrapper declaration\r
                class Environment\r
                {\r
                        public:\r
                class Environment\r
                {\r
                        public:\r
index b8159d0..d678d64 100644 (file)
@@ -38,6 +38,7 @@ bool Class::isDerivedFrom(const Class* baseClass) const
 \r
 // Dynamic name lookup and creation\r
 Class* Class::fromName(const char* name)\r
 \r
 // Dynamic name lookup and creation\r
 Class* Class::fromName(const char* name)\r
+throw (ClassNotFoundException)\r
 {\r
        Class* cur;\r
 \r
 {\r
        Class* cur;\r
 \r
index a4dab1a..0ee57ed 100644 (file)
@@ -547,14 +547,27 @@ namespace SimGrid
                throw(HostNotFoundException)\r
                {\r
                        smx_process_t nativeCurrentProcess = NULL;\r
                throw(HostNotFoundException)\r
                {\r
                        smx_process_t nativeCurrentProcess = NULL;\r
-                       nativeProcess = xbt_new0(s_smx_process_t, 1);\r
+                       \r
+                       // allocate the native process\r
+                       this->nativeProcess = xbt_new0(s_smx_process_t, 1);\r
+                       \r
+                       // allocate the simulation data of the native process\r
                        smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1);\r
                        smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1);\r
+                       \r
+                       // try to retrieve the host where to createt the process from its name\r
                        smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName());\r
                        \r
                        smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName());\r
                        \r
-                       throw HostNotFoundException(rHost.getName());\r
+                       if(!nativeHost)\r
+                               throw HostNotFoundException(rHost.getName());\r
                        \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
                        \r
                        argv = (char**)realloc(argc + 1, sizeo(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
                        // Simulator Data\r
                        argv[argc] = (char*)this;\r
                        \r
                        // Simulator Data\r
@@ -563,28 +576,30 @@ namespace SimGrid
                        simdata->cond = NULL;\r
                        simdata->argc = argc;\r
                        simdata->argv = argv;\r
                        simdata->cond = NULL;\r
                        simdata->argc = argc;\r
                        simdata->argv = argv;\r
+                       \r
+                       // 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
                        simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv);\r
                        \r
                        /* Process structure */\r
-                       nativeProcess->name = xbt_strdup(name);\r
-                       nativeProcess->simdata = simdata;\r
+                       this->nativeProcess->name = xbt_strdup(name);\r
+                       this->nativeProcess->simdata = simdata;\r
                        \r
                        // Set process data\r
                        \r
                        // Set process data\r
-                       nativeProcess->data = NULL;\r
+                       this->nativeProcess->data = NULL;\r
                        \r
                        // Set process properties\r
                        simdata->properties = NULL;\r
                        \r
                        \r
                        // Set process properties\r
                        simdata->properties = NULL;\r
                        \r
-                       xbt_swag_insert(nativeProcess, nativeHost->simdata->process_list);\r
+                       xbt_swag_insert(this->nativeProcess, nativeHost->simdata->process_list);\r
                        \r
                        /* fix current_process, about which xbt_context_start mocks around */\r
                        nativeCurrentProcess = simix_global->current_process;\r
                        \r
                        /* fix current_process, about which xbt_context_start mocks around */\r
                        nativeCurrentProcess = simix_global->current_process;\r
-                       xbt_context_start(nativeProcess->simdata->context);\r
+                       xbt_context_start(this->nativeProcess->simdata->context);\r
                        simix_global->current_process = nativeCurrentProcess;\r
                        \r
                        simix_global->current_process = nativeCurrentProcess;\r
                        \r
-                       xbt_swag_insert(nativeProcess, simix_global->process_list);\r
-                       DEBUG2("Inserting %s(%s) in the to_run list", nativeProcess->name, nativeHost->name);\r
-                       xbt_swag_insert(nativeProcess, simix_global->process_to_run);\r
+                       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
                Process& Process::fromNativeProcess(m_process_t nativeProcess)\r
                }\r
                \r
                Process& Process::fromNativeProcess(m_process_t nativeProcess)\r
@@ -594,9 +609,10 @@ namespace SimGrid
                \r
                int Process::run(int argc, char** argv)\r
                {\r
                \r
                int Process::run(int argc, char** argv)\r
                {\r
-                       Process* process =(Process*)argv[argc];\r
                        \r
                        \r
-                       return process->main(argc, argv);\r
+                       // the last argument of the process is the pointer to the process to run\r
+                       // for mor detail see Process::create() method\r
+                       return ((Process*)argv[argc])->main(argc, argv);\r
                }\r
                \r
        } // namespace Msg\r
                }\r
                \r
        } // namespace Msg\r
index cc13e94..b1fd89e 100644 (file)
@@ -1,11 +1,26 @@
+/*\r
+ * Simulation.cxx\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */\r
\r
+ /* Simulation member functions implementation.\r
+  */  \r
+  \r
 #include <Simulation.hpp>\r
 \r
 #include <Simulation.hpp>\r
 \r
-#include <Simulator.hpp>\r
-\r
 namespace SimGrid\r
 {\r
        namespace Msg\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
                int Simulation::execute(int argc, char** argv)\r
                {\r
                        if(argc < 3) \r
@@ -18,44 +33,29 @@ namespace SimGrid
                init(argc, argv);\r
                        \r
                        // the environment to load\r
                init(argc, argv);\r
                        \r
                        // the environment to load\r
-                       Environment environment;\r
+                       Environment env;\r
                        \r
                        // the application to deploy\r
                        \r
                        // the application to deploy\r
-                       Application application;\r
-                       \r
-                       // the simulation\r
-                       Simulation simulation;\r
+                       Application app;\r
+\r
                        \r
                        // try to load the environment described by the xml file (argv[1])\r
                        try\r
                        {\r
                        \r
                        // try to load the environment described by the xml file (argv[1])\r
                        try\r
                        {\r
-                               environment.load(argv[1]);\r
-                       }\r
-                       catch(InvalidArgumentException e)\r
-                       {\r
-                               info(e.toString());\r
-                               finalize();\r
-                               return 1;\r
+                               env.load(argv[1]);\r
                        }\r
                        }\r
-                       catch(LogicException e)\r
+                       catch(FileNotFoundException e)\r
                        {\r
                                info(e.toString());\r
                                finalize();\r
                                return 1;\r
                        }\r
                                \r
                        {\r
                                info(e.toString());\r
                                finalize();\r
                                return 1;\r
                        }\r
                                \r
-                       \r
                        // try to deploy the application described by the xml file deployment (argv[2])\r
                        try\r
                        {\r
                        // try to deploy the application described by the xml file deployment (argv[2])\r
                        try\r
                        {\r
-                               application.deploy(argv[2]);\r
-                       catch(InvalidArgumentException e)\r
-                       {\r
-                               info(e.toString());\r
-                               finalize();\r
-                               return 1;\r
-                       }\r
-                       catch(LogicException e)\r
+                               app.deploy(argv[2]);\r
+                       catch(FileNotFoundException e)\r
                        {\r
                                info(e.toString());\r
                                finalize();\r
                        {\r
                                info(e.toString());\r
                                finalize();\r
@@ -65,7 +65,7 @@ namespace SimGrid
                        //try to run the simulation the given application on the given environment\r
                        try\r
                        {\r
                        //try to run the simulation the given application on the given environment\r
                        try\r
                        {\r
-                               simulation.run(environment, application);\r
+                               this->run();\r
                        }\r
                        catch(MsgException e)\r
                        {\r
                        }\r
                        catch(MsgException e)\r
                        {\r
@@ -75,12 +75,11 @@ namespace SimGrid
                        }\r
                        \r
                        // finalize the MSG simulator\r
                        }\r
                        \r
                        // finalize the MSG simulator\r
-                       \r
                        try\r
                        {\r
                                finalize();\r
                        }\r
                        try\r
                        {\r
                                finalize();\r
                        }\r
-                       catch(MsgExceptio e)\r
+                       catch(MsgException e)\r
                        {\r
                                info(e.toString())\r
                                return 1;\r
                        {\r
                                info(e.toString())\r
                                return 1;\r
@@ -89,7 +88,7 @@ namespace SimGrid
                        return 0;\r
                }\r
                \r
                        return 0;\r
                }\r
                \r
-               void run(const Environment& rEnvironment, const Application& rApplication)\r
+               void Simulation::run(void)\r
                throw (MsgException)\r
                {\r
                        if(MSG_OK != MSG_main())\r
                throw (MsgException)\r
                {\r
                        if(MSG_OK != MSG_main())\r
index 9ad9163..00f4ab1 100644 (file)
@@ -1,5 +1,19 @@
-#ifndef MSG_ENVIRONMENT_HPP\r
-#define MSG_ENVIRONMENT_HPP\r
+/*\r
+ * Simulation.hpp\r
+ *\r
+ * This file contains the declaration of the wrapper class of the native MSG task type.\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */  \r
\r
+#ifndef MSG_SIMULATION_HPP\r
+#define MSG_SIMULATION_HPP\r
 \r
 #ifndef __cplusplus\r
        #error Sumulation.hpp requires C++ compilation (use a .cxx suffix)\r
 \r
 #ifndef __cplusplus\r
        #error Sumulation.hpp requires C++ compilation (use a .cxx suffix)\r
@@ -9,6 +23,7 @@ namespace SimGrid
 {\r
        namespace Msg\r
        {\r
 {\r
        namespace Msg\r
        {\r
+               // Simulation class declaration.\r
                class Simulation\r
                {\r
                        public :\r
                class Simulation\r
                {\r
                        public :\r
@@ -23,19 +38,17 @@ namespace SimGrid
                        \r
                                int execute(int argc, char** argv);\r
                                \r
                        \r
                                int execute(int argc, char** argv);\r
                                \r
-                               void run(const Environment& rEnvironment, const Application& rApplication)\r
+                       private:\r
+                               \r
+                               void run(void)\r
                                throw (MsgException);\r
                                \r
                                \r
                        // Operators.\r
                                throw (MsgException);\r
                                \r
                                \r
                        // Operators.\r
-                       \r
                                const Simulation& operator = (const Simulation& rSimulation);\r
                                const Simulation& operator = (const Simulation& rSimulation);\r
-                       \r
-                       \r
                };\r
                \r
        } // namespace Msg\r
 } // namespace SimGrid\r
 \r
                };\r
                \r
        } // namespace Msg\r
 } // namespace SimGrid\r
 \r
-\r
-#endif // !MSG_ENVIRONMENT_HPP
\ No newline at end of file
+#endif // !MSG_SIMULATION_HPP
\ No newline at end of file