Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Refactoring of code and documentation.
[simgrid.git] / src / cxx / Simulation.cxx
1 #include <Simulation.hpp>\r
2 \r
3 #include <Simulator.hpp>\r
4 \r
5 namespace SimGrid\r
6 {\r
7         namespace Msg\r
8         {\r
9                 int Simulation::execute(int argc, char** argv)\r
10                 {\r
11                         if(argc < 3) \r
12                         {\r
13                       info("Usage: Msg platform_file deployment_file");\r
14                       return 1;\r
15                     }\r
16                     \r
17                          // initialize the MSG simulator. Must be done before anything else (even logging).\r
18                 init(argc, argv);\r
19                         \r
20                         // the environment to load\r
21                         Environment environment;\r
22                         \r
23                         // the application to deploy\r
24                         Application application;\r
25                         \r
26                         // the simulation\r
27                         Simulation simulation;\r
28                         \r
29                         // try to load the environment described by the xml file (argv[1])\r
30                         try\r
31                         {\r
32                                 environment.load(argv[1]);\r
33                         }\r
34                         catch(InvalidArgumentException e)\r
35                         {\r
36                                 info(e.toString());\r
37                                 finalize();\r
38                                 return 1;\r
39                         }\r
40                         catch(LogicException e)\r
41                         {\r
42                                 info(e.toString());\r
43                                 finalize();\r
44                                 return 1;\r
45                         }\r
46                                 \r
47                         \r
48                         // try to deploy the application described by the xml file deployment (argv[2])\r
49                         try\r
50                         {\r
51                                 application.deploy(argv[2]);\r
52                         catch(InvalidArgumentException e)\r
53                         {\r
54                                 info(e.toString());\r
55                                 finalize();\r
56                                 return 1;\r
57                         }\r
58                         catch(LogicException e)\r
59                         {\r
60                                 info(e.toString());\r
61                                 finalize();\r
62                                 return 1;\r
63                         }\r
64                         \r
65                         //try to run the simulation the given application on the given environment\r
66                         try\r
67                         {\r
68                                 simulation.run(environment, application);\r
69                         }\r
70                         catch(MsgException e)\r
71                         {\r
72                                 info(e.toString());\r
73                                 finalize();\r
74                                 return 1;\r
75                         }\r
76                         \r
77                         // finalize the MSG simulator\r
78                         \r
79                         try\r
80                         {\r
81                                 finalize();\r
82                         }\r
83                         catch(MsgExceptio e)\r
84                         {\r
85                                 info(e.toString())\r
86                                 return 1;\r
87                         }\r
88                         \r
89                         return 0;\r
90                 }\r
91                 \r
92                 void run(const Environment& rEnvironment, const Application& rApplication)\r
93                 throw (MsgException)\r
94                 {\r
95                         if(MSG_OK != MSG_main())\r
96                                 throw MsgException("MSG_main() failed");\r
97                 }\r
98         } // namespace Msg\r
99 } // namespace SimGrid\r