+++ /dev/null
-/*\r
- * Application.cxx\r
- *\r
- * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
- * All right reserved. \r
- *\r
- * This program is free software; you can redistribute \r
- * it and/or modify it under the terms of the license \r
- *(GNU LGPL) which comes with this package. \r
- *\r
- */\r
- \r
- /* Application member functions implementation.\r
- */ \r
-\r
-#include <ApplicationHandler.hpp>\r
-\r
-#include <Application.hpp>\r
-\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-#include <stdlib.h>\r
-\r
-#include <surf/surfxml_parse.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::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(NullPointerException, FileNotFoundException)\r
- {\r
- // check parameters\r
- \r
- if(!file)\r
- throw NullPointerException("file");\r
- \r
- struct stat statBuf = {0};\r
- \r
- if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
- throw FileNotFoundException(file);\r
- \r
- this->file = file;\r
- this->deployed = false;\r
- }\r
- \r
- Application::~Application()\r
- {\r
- // NOTHING TODO\r
- }\r
- \r
- void Application::deploy(const char* file)\r
- throw(NullPointerException, FileNotFoundException, 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 NullPointerException("file");\r
- \r
- struct stat statBuf = {0};\r
- \r
- if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
- throw FileNotFoundException(file);\r
- \r
- surf_parse_reset_parser();\r
- \r
- // set the begin of the xml process element handler\r
- surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess);\r
- \r
- // set the process arg handler\r
- surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onProcessArg);\r
- \r
- // set the properties handler\r
- surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty);\r
- \r
- // set the end of the xml process element handler\r
- surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::onEndProcess);\r
-\r
- surf_parse_open(file);\r
- \r
- // initialize the process factory used by the process handler to build the processes.\r
- ApplicationHandler::onStartDocument();\r
- \r
- if(surf_parse())\r
- throw MsgException("surf_parse() failed");\r
- \r
- surf_parse_close();\r
- \r
- // release the process factory\r
- ApplicationHandler::onEndDocument(); \r
- \r
- this->file = file;\r
- this->deployed = true;\r
- }\r
- \r
- void 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::onProcessArg);\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) const\r
- {\r
- return this->deployed;\r
- }\r
- \r
- void Application::setFile(const char* file)\r
- throw (NullPointerException, FileNotFoundException, 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 NullPointerException("file");\r
- \r
- struct stat statBuf = {0};\r
- \r
- if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))\r
- throw FileNotFoundException("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\r
-\r
-\r
-\r