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
17 #include <ApplicationHandler.hpp>
\r
19 #include <sys/types.h>
\r
20 #include <sys/stat.h>
\r
23 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
31 Application::Application()
\r
34 this->deployed = false;
\r
37 Application(const Application& rApplication)
\r
40 this->file = rApplication.getFile();
\r
41 this->deployed = rApplication.isDeployed();
\r
44 Application::Application(const char* file)
\r
45 throw(NullPointerException, FileNotFoundException)
\r
50 throw NullPointerException("file");
\r
52 struct stat statBuf = {0};
\r
54 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
55 throw FileNotFoundException(file);
\r
58 this->deployed = false;
\r
61 Application::~Application()
\r
66 Application::deploy(const char* file)
\r
67 throw(NullPointerException, FileNotFoundException, LogicException, MsgException)
\r
72 throw LogicException("application already deployed");
\r
74 // check the parameters
\r
77 throw NullPointerException("file");
\r
79 struct stat statBuf = {0};
\r
81 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
82 throw FileNotFoundException(file);
\r
84 surf_parse_reset_parser();
\r
86 // set the begin of the xml process element handler
\r
87 surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);
\r
89 // set the process arg handler
\r
90 surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);
\r
92 // set the properties handler
\r
93 surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);
\r
95 // set the end of the xml process element handler
\r
96 surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);
\r
98 surf_parse_open(file);
\r
100 // initialize the process factory used by the process handler to build the processes.
\r
101 ApplicationHandler::onStartDocument();
\r
104 throw MsgException("surf_parse() failed");
\r
106 surf_parse_close();
\r
108 // release the process factory
\r
109 ApplicationHandler::onEndDocument();
\r
112 this->deployed = true;
\r
115 Application::deploy(void)
\r
116 throw(LogicException, MsgException)
\r
121 throw LogicException("application already deployed");
\r
123 // check the parameters
\r
125 throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()");
\r
127 surf_parse_reset_parser();
\r
128 surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);
\r
129 surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);
\r
130 surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);
\r
131 surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);
\r
133 surf_parse_open(file);
\r
136 throw MsgException("surf_parse() failed");
\r
138 surf_parse_close();
\r
140 this->deployed = true;
\r
143 bool Application::isDeployed(void)
\r
145 return this->deployed;
\r
148 void Application::setFile(const char* file)
\r
149 throw (NullPointerException, FileNotFoundException, LogicException)
\r
154 throw LogicException("your are trying to change the file of an already deployed application");
\r
156 // check parameters
\r
159 throw NullPointerException("file");
\r
161 struct stat statBuf = {0};
\r
163 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
164 throw FileNotFoundException("file (file not found)");
\r
170 const char* Application::getFile(void) const
\r
175 const Application& Application::operator = (const Application& rApplication)
\r
176 throw(LogicException)
\r
181 throw LogicException("application already deployed");
\r
183 this->file = rApplication.getFile();
\r
184 this->deployed = rApplication.isDeployed();
\r
189 } // namespace SimGrid