4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
\r
5 * All right reserved.
\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
13 /* Application member functions implementation.
\r
16 #include <Application.hpp>
\r
19 #include <NullPointerException.hpp>
\r
20 #include <FileNotFoundException.hpp>
\r
21 #include <LogicException.hpp>
\r
22 #include <MsgException.hpp>
\r
23 #include <ApplicationHandler.hpp>
\r
25 #include <sys/types.h>
\r
26 #include <sys/stat.h>
\r
29 #include <surf/surfxml_parse.h>
\r
32 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
40 Application::Application()
\r
43 this->deployed = false;
\r
46 Application::Application(const Application& rApplication)
\r
49 this->file = rApplication.getFile();
\r
50 this->deployed = rApplication.isDeployed();
\r
53 Application::Application(const char* file)
\r
54 throw(NullPointerException, FileNotFoundException)
\r
59 throw NullPointerException("file");
\r
61 struct stat statBuf = {0};
\r
63 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
64 throw FileNotFoundException(file);
\r
67 this->deployed = false;
\r
70 Application::~Application()
\r
75 void Application::deploy(const char* file)
\r
76 throw(NullPointerException, FileNotFoundException, LogicException, MsgException)
\r
81 throw LogicException("application already deployed");
\r
83 // check the parameters
\r
86 throw NullPointerException("file");
\r
88 struct stat statBuf = {0};
\r
90 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
91 throw FileNotFoundException(file);
\r
93 surf_parse_reset_parser();
\r
95 // set the begin of the xml process element handler
\r
96 surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);
\r
98 // set the process arg handler
\r
99 surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg);
\r
101 // set the properties handler
\r
102 surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);
\r
104 // set the end of the xml process element handler
\r
105 surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess);
\r
107 surf_parse_open(file);
\r
109 // initialize the process factory used by the process handler to build the processes.
\r
110 ApplicationHandler::onStartDocument();
\r
113 throw MsgException("surf_parse() failed");
\r
115 surf_parse_close();
\r
117 // release the process factory
\r
118 ApplicationHandler::onEndDocument();
\r
121 this->deployed = true;
\r
124 void Application::deploy(void)
\r
125 throw(LogicException, MsgException)
\r
130 throw LogicException("application already deployed");
\r
132 // check the parameters
\r
134 throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()");
\r
136 surf_parse_reset_parser();
\r
137 surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);
\r
138 surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg);
\r
139 surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);
\r
140 surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess);
\r
142 surf_parse_open(file);
\r
145 throw MsgException("surf_parse() failed");
\r
147 surf_parse_close();
\r
149 this->deployed = true;
\r
152 bool Application::isDeployed(void) const
\r
154 return this->deployed;
\r
157 void Application::setFile(const char* file)
\r
158 throw (NullPointerException, FileNotFoundException, LogicException)
\r
163 throw LogicException("your are trying to change the file of an already deployed application");
\r
165 // check parameters
\r
168 throw NullPointerException("file");
\r
170 struct stat statBuf = {0};
\r
172 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
173 throw FileNotFoundException("file (file not found)");
\r
179 const char* Application::getFile(void) const
\r
184 const Application& Application::operator = (const Application& rApplication)
\r
185 throw(LogicException)
\r
190 throw LogicException("application already deployed");
\r
192 this->file = rApplication.getFile();
\r
193 this->deployed = rApplication.isDeployed();
\r
198 } // namespace SimGrid