+#include <Application.hpp>\r
+#include <ApplicationHandler.hpp>\r
+\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+\r
+#ifndef S_ISREG\r
+ #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)\r
+#endif\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ Application::Application()\r
+ {\r
+ this->file = NULL;\r
+ this->deployed = false;\r
+ }\r
+ \r
+ Application(const Application& rApplication)\r
+ {\r
+ \r
+ this->file = rApplication.getFile();\r
+ this->deployed = rApplication.isDeployed();\r
+ }\r
+ \r
+ Application::Application(const char* file)\r
+ throw(InvalidParameterException)\r
+ {\r
+ // check parameters\r
+ \r
+ if(!file)\r
+ throw InvalidParameterException("file (must not be NULL");\r
+ \r
+ struct stat statBuf = {0};\r
+ \r
+ if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+ throw InvalidParameterException("file (file not found)");\r
+ \r
+ this->file = file;\r
+ this->deployed = false;\r
+ }\r
+ \r
+ Application::~Application()\r
+ {\r
+ // NOTHING TODO\r
+ }\r
+ \r
+ Application::deploy(const char* file)\r
+ throw(InvalidParameterException, LogicException, MsgException)\r
+ {\r
+ // check logic\r
+ \r
+ if(this->deployed)\r
+ throw LogicException("application already deployed");\r
+ \r
+ // check the parameters\r
+ \r
+ if(!file)\r
+ throw InvalidParameterException("file (must not be NULL");\r
+ \r
+ struct stat statBuf = {0};\r
+ \r
+ if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+ throw InvalidParameterException("file (file not found)");\r
+ \r
+ surf_parse_reset_parser();\r
+ surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
+ surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);\r
+ surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\r
+ surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);\r
+\r
+ surf_parse_open(file);\r
+ \r
+ if(surf_parse())\r
+ throw MsgException("surf_parse() failed");\r
+ \r
+ surf_parse_close(); \r
+ \r
+ this->file = file;\r
+ this->deployed = true;\r
+ }\r
+ \r
+ Application::deploy(void)\r
+ throw(LogicException, MsgException)\r
+ {\r
+ // check logic\r
+ \r
+ if(this->deployed)\r
+ throw LogicException("application already deployed");\r
+ \r
+ // check the parameters\r
+ if(!this->file)\r
+ throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()"); \r
+ \r
+ surf_parse_reset_parser();\r
+ surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
+ surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg);\r
+ surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\r
+ surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess);\r
+\r
+ surf_parse_open(file);\r
+ \r
+ if(surf_parse())\r
+ throw MsgException("surf_parse() failed");\r
+ \r
+ surf_parse_close();\r
+ \r
+ this->deployed = true; \r
+ }\r
+ \r
+ bool Application::isDeployed(void)\r
+ {\r
+ return this->deployed;\r
+ }\r
+ \r
+ void Application::setFile(const char* file)\r
+ throw (InvalidParameterException, LogicException)\r
+ {\r
+ // check logic\r
+ \r
+ if(this->deployed)\r
+ throw LogicException("your are trying to change the file of an already deployed application");\r
+ \r
+ // check parameters\r
+ \r
+ if(!file)\r
+ throw InvalidParameterException("file (must not be NULL");\r
+ \r
+ struct stat statBuf = {0};\r
+ \r
+ if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
+ throw InvalidParameterException("file (file not found)");\r
+ \r
+ this->file = file;\r
+ \r
+ }\r
+ \r
+ const char* Application::getFile(void) const\r
+ {\r
+ return this->file;\r
+ }\r
+ \r
+ const Application& Application::operator = (const Application& rApplication)\r
+ throw(LogicException)\r
+ {\r
+ // check logic\r
+ \r
+ if(this->deployed)\r
+ throw LogicException("application already deployed");\r
+ \r
+ this->file = rApplication.getFile();\r
+ this->deployed = rApplication.isDeployed();\r
+ \r
+ return *this;\r
+ }\r
+ } // namespace Msg\r
+} // namespace SimGrid
\ No newline at end of file