1 #include <Application.hpp>
\r
2 #include <ApplicationHandler.hpp>
\r
4 #include <sys/types.h>
\r
5 #include <sys/stat.h>
\r
8 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
16 Application::Application()
\r
19 this->deployed = false;
\r
22 Application(const Application& rApplication)
\r
25 this->file = rApplication.getFile();
\r
26 this->deployed = rApplication.isDeployed();
\r
29 Application::Application(const char* file)
\r
30 throw(InvalidParameterException)
\r
35 throw InvalidParameterException("file (must not be NULL");
\r
37 struct stat statBuf = {0};
\r
39 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
40 throw InvalidParameterException("file (file not found)");
\r
43 this->deployed = false;
\r
46 Application::~Application()
\r
51 Application::deploy(const char* file)
\r
52 throw(InvalidParameterException, LogicException, MsgException)
\r
57 throw LogicException("application already deployed");
\r
59 // check the parameters
\r
62 throw InvalidParameterException("file (must not be NULL");
\r
64 struct stat statBuf = {0};
\r
66 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
67 throw InvalidParameterException("file (file not found)");
\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
75 surf_parse_open(file);
\r
78 throw MsgException("surf_parse() failed");
\r
80 surf_parse_close();
\r
83 this->deployed = true;
\r
86 Application::deploy(void)
\r
87 throw(LogicException, MsgException)
\r
92 throw LogicException("application already deployed");
\r
94 // check the parameters
\r
96 throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()");
\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
104 surf_parse_open(file);
\r
107 throw MsgException("surf_parse() failed");
\r
109 surf_parse_close();
\r
111 this->deployed = true;
\r
114 bool Application::isDeployed(void)
\r
116 return this->deployed;
\r
119 void Application::setFile(const char* file)
\r
120 throw (InvalidParameterException, LogicException)
\r
125 throw LogicException("your are trying to change the file of an already deployed application");
\r
127 // check parameters
\r
130 throw InvalidParameterException("file (must not be NULL");
\r
132 struct stat statBuf = {0};
\r
134 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
135 throw InvalidParameterException("file (file not found)");
\r
141 const char* Application::getFile(void) const
\r
146 const Application& Application::operator = (const Application& rApplication)
\r
147 throw(LogicException)
\r
152 throw LogicException("application already deployed");
\r
154 this->file = rApplication.getFile();
\r
155 this->deployed = rApplication.isDeployed();
\r
160 } // namespace SimGrid