Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Code refactoring on CPP
[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 #include <Simulation.hpp>\r
17 \r
18 namespace SimGrid\r
19 {\r
20         namespace Msg\r
21         {\r
22                 \r
23                 \r
24                 int Simulation::execute(int argc, char** argv)\r
25                 {\r
26                         if(argc < 3) \r
27                         {\r
28                       info("Usage: Msg platform_file deployment_file");\r
29                       return 1;\r
30                     }\r
31                     \r
32                          // initialize the MSG simulator. Must be done before anything else (even logging).\r
33                 init(argc, argv);\r
34                         \r
35                         // the environment to load\r
36                         Environment env;\r
37                         \r
38                         // the application to deploy\r
39                         Application app;\r
40 \r
41                         \r
42                         // try to load the environment described by the xml file (argv[1])\r
43                         try\r
44                         {\r
45                                 env.load(argv[1]);\r
46                         }\r
47                         catch(FileNotFoundException e)\r
48                         {\r
49                                 info(e.toString());\r
50                                 finalize();\r
51                                 return 1;\r
52                         }\r
53                                 \r
54                         // try to deploy the application described by the xml file deployment (argv[2])\r
55                         try\r
56                         {\r
57                                 app.deploy(argv[2]);\r
58                         catch(FileNotFoundException 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                                 this->run();\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                         try\r
79                         {\r
80                                 finalize();\r
81                         }\r
82                         catch(MsgException e)\r
83                         {\r
84                                 info(e.toString())\r
85                                 return 1;\r
86                         }\r
87                         \r
88                         return 0;\r
89                 }\r
90                 \r
91                 void Simulation::run(void)\r
92                 throw (MsgException)\r
93                 {\r
94                         if(MSG_OK != MSG_main())\r
95                                 throw MsgException("MSG_main() failed");\r
96                 }\r
97         } // namespace Msg\r
98 } // namespace SimGrid\r