Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some code refactoring
[simgrid.git] / src / cxx / Simulation.cxx
1 /*\r
2  * Simulation.cxx\r
3  *\r
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
5  * All right reserved. \r
6  *\r
7  * This program is free software; you can redistribute \r
8  * it and/or modify it under the terms of the license \r
9  *(GNU LGPL) which comes with this package. \r
10  *\r
11  */\r
12  \r
13  /* Simulation member functions implementation.\r
14   */  \r
15   \r
16 \r
17 #include <Application.hpp>\r
18 #include <Environment.hpp>\r
19 \r
20 #include <Msg.hpp>\r
21 \r
22 #include <Simulation.hpp>\r
23 \r
24 \r
25 #include <msg/msg.h> \r
26 \r
27 namespace SimGrid\r
28 {\r
29         namespace Msg\r
30         {\r
31                 int Simulation::execute(int argc, char** argv)\r
32                 {\r
33                         if(argc < 3) \r
34                         {\r
35                       info("Usage: Msg platform_file deployment_file");\r
36                       return 1;\r
37                     }\r
38                     \r
39                          // initialize the MSG simulator. Must be done before anything else (even logging).\r
40                 init(argc, argv);\r
41                         \r
42                         // the environment to load\r
43                         Environment env;\r
44                         \r
45                         // the application to deploy\r
46                         Application app;\r
47 \r
48                         \r
49                         // try to load the environment described by the xml file (argv[1])\r
50                         try\r
51                         {\r
52                                 env.load(argv[1]);\r
53                         }\r
54                         catch(FileNotFoundException e)\r
55                         {\r
56                                 info(e.toString());\r
57                                 finalize();\r
58                                 return 1;\r
59                         }\r
60                                 \r
61                         // try to deploy the application described by the xml file deployment (argv[2])\r
62                         try\r
63                         {\r
64                                 app.deploy(argv[2]);\r
65                         }\r
66                         catch(FileNotFoundException e)\r
67                         {\r
68                                 info(e.toString());\r
69                                 finalize();\r
70                                 return 1;\r
71                         }\r
72                         \r
73                         //try to run the simulation the given application on the given environment\r
74                         try\r
75                         {\r
76                                 run();\r
77                         }\r
78                         catch(MsgException e)\r
79                         {\r
80                                 info(e.toString());\r
81                                 finalize();\r
82                                 return 1;\r
83                         }\r
84                         \r
85                         // finalize the MSG simulator\r
86                         try\r
87                         {\r
88                                 finalize();\r
89                         }\r
90                         catch(MsgException e)\r
91                         {\r
92                                 info(e.toString());\r
93                                 return 1;\r
94                         }\r
95                         \r
96                         return 0;\r
97                 }\r
98                 \r
99                 void Simulation::run(void)\r
100                 throw (MsgException)\r
101                 {\r
102                         if(MSG_OK != MSG_main())\r
103                                 throw MsgException("MSG_main() failed");\r
104                 }\r
105         } // namespace Msg\r
106 } // namespace SimGrid\r
107 \r
108 \r