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 <ApplicationHandler.hpp>
\r
18 #include <Application.hpp>
\r
20 #include <sys/types.h>
\r
21 #include <sys/stat.h>
\r
24 #include <surf/surfxml_parse.h>
\r
27 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
35 Application::Application()
\r
38 this->deployed = false;
\r
41 Application::Application(const Application& rApplication)
\r
44 this->file = rApplication.getFile();
\r
45 this->deployed = rApplication.isDeployed();
\r
48 Application::Application(const char* file)
\r
49 throw(NullPointerException, FileNotFoundException)
\r
54 throw NullPointerException("file");
\r
56 struct stat statBuf = {0};
\r
58 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
59 throw FileNotFoundException(file);
\r
62 this->deployed = false;
\r
65 Application::~Application()
\r
70 void Application::deploy(const char* file)
\r
71 throw(NullPointerException, FileNotFoundException, LogicException, MsgException)
\r
76 throw LogicException("application already deployed");
\r
78 // check the parameters
\r
81 throw NullPointerException("file");
\r
83 struct stat statBuf = {0};
\r
85 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
86 throw FileNotFoundException(file);
\r
88 surf_parse_reset_parser();
\r
90 // set the begin of the xml process element handler
\r
91 surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);
\r
93 // set the process arg handler
\r
94 surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg);
\r
96 // set the properties handler
\r
97 surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);
\r
99 // set the end of the xml process element handler
\r
100 surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess);
\r
102 surf_parse_open(file);
\r
104 // initialize the process factory used by the process handler to build the processes.
\r
105 ApplicationHandler::onStartDocument();
\r
108 throw MsgException("surf_parse() failed");
\r
110 surf_parse_close();
\r
112 // release the process factory
\r
113 ApplicationHandler::onEndDocument();
\r
116 this->deployed = true;
\r
119 void Application::deploy(void)
\r
120 throw(LogicException, MsgException)
\r
125 throw LogicException("application already deployed");
\r
127 // check the parameters
\r
129 throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()");
\r
131 surf_parse_reset_parser();
\r
132 surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);
\r
133 surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg);
\r
134 surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);
\r
135 surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess);
\r
137 // initialize the process factory used by the process handler to build the processes.
\r
138 ApplicationHandler::onStartDocument();
\r
140 surf_parse_open(file);
\r
143 throw MsgException("surf_parse() failed");
\r
145 surf_parse_close();
\r
147 this->deployed = true;
\r
150 bool Application::isDeployed(void) const
\r
152 return this->deployed;
\r
155 void Application::setFile(const char* file)
\r
156 throw (NullPointerException, FileNotFoundException, LogicException)
\r
161 throw LogicException("your are trying to change the file of an already deployed application");
\r
163 // check parameters
\r
166 throw NullPointerException("file");
\r
168 struct stat statBuf = {0};
\r
170 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
171 throw FileNotFoundException("file (file not found)");
\r
177 const char* Application::getFile(void) const
\r
182 const Application& Application::operator = (const Application& rApplication)
\r
183 throw(LogicException)
\r
188 throw LogicException("application already deployed");
\r
190 this->file = rApplication.getFile();
\r
191 this->deployed = rApplication.isDeployed();
\r
196 } // namespace SimGrid
\r