Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Last Changes of CPP version of Msg
[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 #include <Application.hpp>\r
19 #include <Environment.hpp>\r
20 \r
21 #include <MsgException.hpp>\r
22 #include <FileNotFoundException.hpp>\r
23 \r
24 #include <Msg.hpp>\r
25 \r
26 #include <msg/msg.h> \r
27 \r
28 namespace SimGrid\r
29 {\r
30         namespace Msg\r
31         {\r
32                 int Simulation::execute(int argc, char** argv)\r
33                 {\r
34                         if(argc < 3) \r
35                         {\r
36                       info("Usage: Msg platform_file deployment_file");\r
37                       return 1;\r
38                     }\r
39                     \r
40                          // initialize the MSG simulator. Must be done before anything else (even logging).\r
41                 init(argc, argv);\r
42                         \r
43                         // the environment to load\r
44                         Environment env;\r
45                         \r
46                         // the application to deploy\r
47                         Application app;\r
48 \r
49                         \r
50                         // try to load the environment described by the xml file (argv[1])\r
51                         try\r
52                         {\r
53                                 env.load(argv[1]);\r
54                         }\r
55                         catch(FileNotFoundException e)\r
56                         {\r
57                                 info(e.toString());\r
58                                 finalize();\r
59                                 return 1;\r
60                         }\r
61                                 \r
62                         // try to deploy the application described by the xml file deployment (argv[2])\r
63                         try\r
64                         {\r
65                                 app.deploy(argv[2]);\r
66                         }\r
67                         catch(FileNotFoundException e)\r
68                         {\r
69                                 info(e.toString());\r
70                                 finalize();\r
71                                 return 1;\r
72                         }\r
73                         \r
74                         //try to run the simulation the given application on the given environment\r
75                         try\r
76                         {\r
77                                 run();\r
78                         }\r
79                         catch(MsgException e)\r
80                         {\r
81                                 info(e.toString());\r
82                                 finalize();\r
83                                 return 1;\r
84                         }\r
85                         \r
86                         // finalize the MSG simulator\r
87                         try\r
88                         {\r
89                                 finalize();\r
90                         }\r
91                         catch(MsgException e)\r
92                         {\r
93                                 info(e.toString());\r
94                                 return 1;\r
95                         }\r
96                         \r
97                         return 0;\r
98                 }\r
99                 \r
100                 void Simulation::run(void)\r
101                 throw (MsgException)\r
102                 {\r
103                         if(MSG_OK != MSG_main())\r
104                                 throw MsgException("MSG_main() failed");\r
105                 }\r
106         } // namespace Msg\r
107 } // namespace SimGrid\r