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