Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Refactoring of code and documentation.
[simgrid.git] / src / cxx / Application.cxx
1 #include <Application.hpp>\r
2 #include <ApplicationHandler.hpp>\r
3 \r
4 #include <sys/types.h>\r
5 #include <sys/stat.h>\r
6 \r
7 #ifndef S_ISREG\r
8         #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)\r
9 #endif\r
10 \r
11 namespace SimGrid\r
12 {\r
13         namespace Msg\r
14         {\r
15         \r
16                 Application::Application()\r
17                 {\r
18                         this->file = NULL;\r
19                         this->deployed = false;\r
20                 }\r
21                                 \r
22                 Application(const Application& rApplication)\r
23                 {\r
24                                 \r
25                         this->file = rApplication.getFile();\r
26                         this->deployed = rApplication.isDeployed();\r
27                 }\r
28         \r
29                 Application::Application(const char* file)\r
30                 throw(InvalidParameterException)\r
31                 {\r
32                         // check parameters\r
33                         \r
34                         if(!file)\r
35                                 throw InvalidParameterException("file (must not be NULL");\r
36                         \r
37                         struct stat statBuf = {0};\r
38                                 \r
39                         if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
40                                 throw InvalidParameterException("file (file not found)");\r
41                                 \r
42                         this->file = file;\r
43                         this->deployed = false;\r
44                 }\r
45                 \r
46                 Application::~Application()\r
47                 {\r
48                         // NOTHING TODO\r
49                 }\r
50                         \r
51                 Application::deploy(const char* file)\r
52                 throw(InvalidParameterException, LogicException, MsgException)\r
53                 {\r
54                         // check logic\r
55                         \r
56                         if(this->deployed)\r
57                                 throw LogicException("application already deployed");\r
58                         \r
59                         // check the parameters\r
60                                 \r
61                         if(!file)\r
62                                 throw InvalidParameterException("file (must not be NULL");\r
63                         \r
64                         struct stat statBuf = {0};\r
65                                 \r
66                         if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
67                                 throw InvalidParameterException("file (file not found)");\r
68                                         \r
69                         surf_parse_reset_parser();\r
70                         surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
71                         surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);\r
72                         surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\r
73                         surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);\r
74 \r
75                         surf_parse_open(file);\r
76                         \r
77                         if(surf_parse())\r
78                                 throw MsgException("surf_parse() failed");\r
79                         \r
80                         surf_parse_close();     \r
81                         \r
82                         this->file = file;\r
83                         this->deployed = true;\r
84                 }\r
85                 \r
86                 Application::deploy(void)\r
87                 throw(LogicException, MsgException)\r
88                 {\r
89                         // check logic\r
90                         \r
91                         if(this->deployed)\r
92                                 throw LogicException("application already deployed");\r
93                         \r
94                         // check the parameters\r
95                         if(!this->file)\r
96                                 throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()"); \r
97                         \r
98                         surf_parse_reset_parser();\r
99                         surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
100                         surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);\r
101                         surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\r
102                         surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);\r
103 \r
104                         surf_parse_open(file);\r
105                         \r
106                         if(surf_parse())\r
107                                 throw MsgException("surf_parse() failed");\r
108                         \r
109                         surf_parse_close();\r
110                         \r
111                         this->deployed = true;  \r
112                 }\r
113                 \r
114                 bool Application::isDeployed(void)\r
115                 {\r
116                         return this->deployed;\r
117                 }\r
118                 \r
119                 void Application::setFile(const char* file)\r
120                 throw (InvalidParameterException, LogicException)\r
121                 {\r
122                         // check logic\r
123                         \r
124                         if(this->deployed)\r
125                                 throw LogicException("your are trying to change the file of an already deployed application");\r
126                                 \r
127                         // check parameters\r
128                         \r
129                         if(!file)\r
130                                 throw InvalidParameterException("file (must not be NULL");\r
131                         \r
132                         struct stat statBuf = {0};\r
133                                 \r
134                         if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
135                                 throw InvalidParameterException("file (file not found)");\r
136                                 \r
137                         this->file = file;\r
138                         \r
139                 }\r
140                 \r
141                 const char* Application::getFile(void) const\r
142                 {\r
143                         return this->file;\r
144                 }\r
145                 \r
146                 const Application& Application::operator = (const Application& rApplication)\r
147                 throw(LogicException)\r
148                 {\r
149                         // check logic\r
150                         \r
151                         if(this->deployed)\r
152                                 throw LogicException("application already deployed");\r
153                         \r
154                         this->file = rApplication.getFile();\r
155                         this->deployed = rApplication.isDeployed();\r
156                         \r
157                         return *this;\r
158                 }\r
159         } // namespace Msg\r
160 } // namespace SimGrid