Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Refactoring of code and documentation.
[simgrid.git] / src / cxx / Simulation.cxx
index 6461932..cc13e94 100644 (file)
@@ -15,26 +15,85 @@ namespace SimGrid
                    }\r
                    \r
                         // initialize the MSG simulator. Must be done before anything else (even logging).\r
-               Simulator::init(argc, argv);\r
+               init(argc, argv);\r
                        \r
                        // the environment to load\r
-                       Environment environment(argv[1]);\r
+                       Environment environment;\r
+                       \r
                        // the application to deploy\r
-                       Application application(argv[2]);\r
+                       Application application;\r
+                       \r
                        // the simulation\r
                        Simulation simulation;\r
                        \r
-                       // load the environment\r
-                       environment.load();\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
+                       }\r
+                       catch(LogicException e)\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
+                               application.deploy(argv[2]);\r
+                       catch(InvalidArgumentException e)\r
+                       {\r
+                               info(e.toString());\r
+                               finalize();\r
+                               return 1;\r
+                       }\r
+                       catch(LogicException e)\r
+                       {\r
+                               info(e.toString());\r
+                               finalize();\r
+                               return 1;\r
+                       }\r
+                       \r
+                       //try to run the simulation the given application on the given environment\r
+                       try\r
+                       {\r
+                               simulation.run(environment, application);\r
+                       }\r
+                       catch(MsgException e)\r
+                       {\r
+                               info(e.toString());\r
+                               finalize();\r
+                               return 1;\r
+                       }\r
                        \r
-                       // deploy the application\r
-                       application.deploy();\r
+                       // finalize the MSG simulator\r
                        \r
-                       // run the simulation\r
-                       simulation.run(environment, application);\r
+                       try\r
+                       {\r
+                               finalize();\r
+                       }\r
+                       catch(MsgExceptio e)\r
+                       {\r
+                               info(e.toString())\r
+                               return 1;\r
+                       }\r
                        \r
-                       // finalize the simulator\r
-                       Simulator::finalize();\r
+                       return 0;\r
+               }\r
+               \r
+               void run(const Environment& rEnvironment, const Application& rApplication)\r
+               throw (MsgException)\r
+               {\r
+                       if(MSG_OK != MSG_main())\r
+                               throw MsgException("MSG_main() failed");\r
                }\r
        } // namespace Msg\r
 } // namespace SimGrid\r