From: cherierm Date: Fri, 16 May 2008 15:06:13 +0000 (+0000) Subject: Some new files of the cxx version of the MSG API X-Git-Tag: v3.3~501 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/dec242c057a35631bad2c2464580873b0c1200f3?hp=21722d01338d0cf9a704fdb226507d1be787871a Some new files of the cxx version of the MSG API git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5435 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/cxx/Application.cxx b/src/cxx/Application.cxx new file mode 100644 index 0000000000..6e6ea8bd28 --- /dev/null +++ b/src/cxx/Application.cxx @@ -0,0 +1,160 @@ +#include +#include + +#include +#include + +#ifndef S_ISREG + #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) +#endif + +namespace SimGrid +{ + namespace Msg + { + + Application::Application() + { + this->file = NULL; + this->deployed = false; + } + + Application(const Application& rApplication) + { + + this->file = rApplication.getFile(); + this->deployed = rApplication.isDeployed(); + } + + Application::Application(const char* file) + throw(InvalidParameterException) + { + // check parameters + + if(!file) + throw InvalidParameterException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) + throw InvalidParameterException("file (file not found)"); + + this->file = file; + this->deployed = false; + } + + Application::~Application() + { + // NOTHING TODO + } + + Application::deploy(const char* file) + throw(InvalidParameterException, LogicException, MsgException) + { + // check logic + + if(this->deployed) + throw LogicException("application already deployed"); + + // check the parameters + + if(!file) + throw InvalidParameterException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) + throw InvalidParameterException("file (file not found)"); + + surf_parse_reset_parser(); + surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess); + surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg); + surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty); + surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess); + + surf_parse_open(file); + + if(surf_parse()) + throw MsgException("surf_parse() failed"); + + surf_parse_close(); + + this->file = file; + this->deployed = true; + } + + Application::deploy(void) + throw(LogicException, MsgException) + { + // check logic + + if(this->deployed) + throw LogicException("application already deployed"); + + // check the parameters + if(!this->file) + throw LogicException("you must specify the xml file which describe the application\nuse Application::setFile()"); + + surf_parse_reset_parser(); + surfxml_add_callback(STag_surfxml_process_cb_list, ApplicationHandler::onBeginProcess); + surfxml_add_callback(ETag_surfxml_argument_cb_list, ApplicationHandler::onArg); + surfxml_add_callback(STag_surfxml_prop_cb_list, ApplicationHandler::OnProperty); + surfxml_add_callback(ETag_surfxml_process_cb_list, ApplicationHandler::OnEndProcess); + + surf_parse_open(file); + + if(surf_parse()) + throw MsgException("surf_parse() failed"); + + surf_parse_close(); + + this->deployed = true; + } + + bool Application::isDeployed(void) + { + return this->deployed; + } + + void Application::setFile(const char* file) + throw (InvalidParameterException, LogicException) + { + // check logic + + if(this->deployed) + throw LogicException("your are trying to change the file of an already deployed application"); + + // check parameters + + if(!file) + throw InvalidParameterException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) + throw InvalidParameterException("file (file not found)"); + + this->file = file; + + } + + const char* Application::getFile(void) const + { + return this->file; + } + + const Application& Application::operator = (const Application& rApplication) + throw(LogicException) + { + // check logic + + if(this->deployed) + throw LogicException("application already deployed"); + + this->file = rApplication.getFile(); + this->deployed = rApplication.isDeployed(); + + return *this; + } + } // namespace Msg +} // namespace SimGrid \ No newline at end of file diff --git a/src/cxx/Application.hpp b/src/cxx/Application.hpp new file mode 100644 index 0000000000..81cf005676 --- /dev/null +++ b/src/cxx/Application.hpp @@ -0,0 +1,124 @@ +#ifndef MSG_APPLICATION_HPP +#define MSG_APPLICATION_HPP + +#ifndef __cplusplus + #error Application.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +#include +#include + +namespace SimGrid +{ + namespace Msg + { + class Application + { + public: + + // Default constructor. + Application(); + + /*! \brief Copy constructor. + */ + Application(const Application& rApplication); + + /* \brief A constructor which takes as parameter the xml file of the application. + * + * \exception [InvalidParameterException] if the parameter file is invalid + * (NULL or if the file does not exist). + */ + Application(const char* file) + throw(InvalidParameterException); + + /*! \brief Destructor. + */ + virtual ~Application(); + + // Operations. + + /*! \brief Application::deploy() - deploy the appliction. + * + * \return If successfuly the application is deployed. Otherwise + * the method throws an exception listed below. + * + * \exception [LogicException] if the xml file which describes the application + * is not yet specified or if the application is already + * deployed. + * [MsgException] if a internal exception occurs. + * + * \remark Before use this method, you must specify the xml file of the application to + * deploy. + * + * \see Application::setFile() + */ + + void deploy(void) + throw(LogicExeption, MsgException); + + /*! \brief Application::deploy() - deploy the appliction. + * + * \return If successfuly the application is deployed. Otherwise + * the method throws an exception listed below. + * + * \exception [InvalidParameterException] if the parameter file is invalid + * (NULL or not a xml deployment file name). + * [MsgException] if a internal exception occurs. + * [LogicException] if the application is already deployed. + * + * \ + */ + void deploy(const char* file) + throw(InvalidParameterException, LogicException, MsgException); + + /*! \brief Application::isDeployed() - tests if the application is deployed. + * + * \return This method returns true is the application is deployed. + * Otherwise the method returns false. + */ + bool isDeployed(void) const; + + + // Getters/setters + + /*! \brief Application::setFile() - this setter sets the value of the file of the application. + * + * \return If successful, the value of the file of the application is setted. + * Otherwise the method throws on of the exceptions listed below. + * + * \exception [InvalidParameterException] if the parameter file is invalid + * (NULL or does no exist). + * [LogicException] if you try to set the value of the file of an + * application which is already deployed. + */ + void setFile(const char* file) + throw (InvalidParameterException, LogicException); + + /*! \brief Application::getFile() - this getter returns the file of an application object. + */ + const char* getFile(void) const; + + // Operators. + + /*! \brief Assignement operator. + * + * \exception [LogicException] if you try to assign an application already deployed. + */ + const Application& operator = (const Application& rApplication) + throw(LogicException); + + private: + // Attributes. + + // flag : if true the application was deployed. + bool deployed; + // the xml file which describe the application. + const char* file; + + }; + + } // namespace Msg +} // namespace SimGrid + +#endif // !MSG_APPLICATION_HPP \ No newline at end of file diff --git a/src/cxx/Environment.cxx b/src/cxx/Environment.cxx new file mode 100644 index 0000000000..5b0ea8d67e --- /dev/null +++ b/src/cxx/Environment.cxx @@ -0,0 +1,139 @@ +#include + +#include +#include + +#ifndef S_ISREG + #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) +#endif + +namespace SimGrid +{ + namespace Msg + { + Environment::Environment() + { + this->file = NULL; + this->loaded = false; + } + + Environment::Environment(const Environment& rEnvironment); + { + this->file = rEnvironment.getFile(); + this->loaded = rEnvironment.isLoaded(); + } + + Environment::Environment(const char* file) + throw(InvalidArgumentException); + { + // check parameters + + if(!file) + throw InvalidParameterException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) + throw InvalidParameterException("file (file not found)"); + + this->file = file; + this->loaded = false; + } + + Environment::~Environment() + { + // NOTHING TODO + } + + // Operations. + + void Environment::load(void) + throw(LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("environement already loaded"); + + // check the parameters + if(!this->file) + throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()"); + + MSG_create_environment(file); + + this->loaded = true; + } + + void Environment::load(const char* file) + throw(InvalidArgumentException, LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("environment already loaded"); + + // check the parameters + + if(!file) + throw InvalidParameterException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) + throw InvalidParameterException("file (file not found)"); + + MSG_create_environment(file); + + this->file = file; + this->loaded = true; + } + + bool Environment::isLoaded(void) const + { + return this->loaded; + } + + // Getters/setters + void Environment::setFile(const char* file) + throw(InvalidArgumentException, LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("your are trying to change the file of an already loaded environment"); + + // check parameters + + if(!file) + throw InvalidParameterException("file (must not be NULL"); + + struct stat statBuf = {0}; + + if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode)) + throw InvalidParameterException("file (file not found)"); + + this->file = file; + } + + const char* Environment::getFile(void) const + { + return this->file; + } + + + const Environment& Environment::operator = (const Environment& rEnvironment) + throw(LogicException) + { + // check logic + + if(this->loaded) + throw LogicException("environment already loaded"); + + this->file = rEnvironment.getFile(); + this->loaded = rEnvironment.isLoaded(); + + return *this; + } + + } // namespace Msg +} // namespace SimGrid \ No newline at end of file diff --git a/src/cxx/Environment.hpp b/src/cxx/Environment.hpp new file mode 100644 index 0000000000..9eae1e3732 --- /dev/null +++ b/src/cxx/Environment.hpp @@ -0,0 +1,66 @@ +#ifndef MSG_ENVIRONMENT_HPP +#define MSG_ENVIRONMENT_HPP + +#ifndef __cplusplus + #error Environment.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include +#include +#include + + +namespace SimGrid +{ + namespace Msg + { + class Environment + { + public: + + Environment(); + + Environment(const Environment& rEnvironment); + + Environment(const char* file) + throw(InvalidArgumentException); + + virtual ~Environment(); + + // Operations. + + void load(void) + throw(LogicException); + + void load(const char* file) + throw(InvalidArgumentException, LogicException); + + bool isLoaded(void) const; + + // Getters/setters + void setFile(const char* file) + throw(InvalidArgumentException, LogicException); + + const char* getFile(void) const; + + // Operators. + + const Environment& operator = (const Environment& rEnvironment) + throw(LogicException); + + private: + + // Attributes. + + // the xml file which describe the environment of the simulation. + const char* file; + + // flag : is true the environment of the simulation is loaded. + bool loaded. + }; + + } // namespace Msg +} // namespace SimGrid + + +#endif // !MSG_ENVIRONMENT_HPP \ No newline at end of file diff --git a/src/cxx/LogicException.cxx b/src/cxx/LogicException.cxx new file mode 100644 index 0000000000..a7adcf2fd5 --- /dev/null +++ b/src/cxx/LogicException.cxx @@ -0,0 +1,62 @@ +#include "LogicException.hpp" + +#include +#include +#include + +using namespace std; + +namespace SimGrid +{ + namespace Msg + { + + LogicException::LogicException() + { + this->reason = (char*) calloc(strlen("Logic exception : no detail") + 1, sizeof(char)); + strcpy(this->reason, "Logic exception : no detail"); + } + + + LogicException::LogicException(const LogicException& rLogicException) + { + const char* reason = rLogicException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + LogicException::LogicException(const char* detail) + { + this->reason = (char*) calloc(strlen("Logic exception : ") + strlen(detail) + 1, sizeof(char)); + sprintf(this->reason, "Logic exception : %s", detail); + } + + + LogicException::~LogicException() + { + if(this->reason) + free(this->reason); + } + + const char* LogicException::toString(void) const + { + return (const char*)(this->reason); + } + + + const LogicException& LogicException::operator = (const LogicException& rLogicException) + { + const char* reason = rLogicException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/LogicException.hpp b/src/cxx/LogicException.hpp new file mode 100644 index 0000000000..19d2f40f66 --- /dev/null +++ b/src/cxx/LogicException.hpp @@ -0,0 +1,64 @@ +/* + * LogicException.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_LOGICEXCEPTION_HPP +#define MSG_LOGICEXCEPTION_HPP + +#include "Exception.hpp" + +namespace SimGrid +{ + namespace Msg + { + + class LogicException : public Exception + { + public: + + // Default constructor. + LogicException(); + + // Copy constructor. + LogicException(const LogicException& rLogicException); + + // This constructor takes the detail of the logic exception. + LogicException(const char* detail); + + // Destructor. + virtual ~LogicException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Logic exception `detail'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const LogicException& operator = (const LogicException& rLogicException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP diff --git a/src/cxx/Simulation.cxx b/src/cxx/Simulation.cxx new file mode 100644 index 0000000000..64619327f3 --- /dev/null +++ b/src/cxx/Simulation.cxx @@ -0,0 +1,40 @@ +#include + +#include + +namespace SimGrid +{ + namespace Msg + { + int Simulation::execute(int argc, char** argv) + { + if(argc < 3) + { + info("Usage: Msg platform_file deployment_file"); + return 1; + } + + // initialize the MSG simulator. Must be done before anything else (even logging). + Simulator::init(argc, argv); + + // the environment to load + Environment environment(argv[1]); + // the application to deploy + Application application(argv[2]); + // the simulation + Simulation simulation; + + // load the environment + environment.load(); + + // deploy the application + application.deploy(); + + // run the simulation + simulation.run(environment, application); + + // finalize the simulator + Simulator::finalize(); + } + } // namespace Msg +} // namespace SimGrid diff --git a/src/cxx/Simulation.hpp b/src/cxx/Simulation.hpp new file mode 100644 index 0000000000..a0a4e6bd08 --- /dev/null +++ b/src/cxx/Simulation.hpp @@ -0,0 +1,38 @@ +#ifndef MSG_ENVIRONMENT_HPP +#define MSG_ENVIRONMENT_HPP + +#ifndef __cplusplus + #error Sumulation.hpp requires C++ compilation (use a .cxx suffix) +#endif + +namespace SimGrid +{ + namespace Msg + { + class Simulation + { + public : + + Simulation(); + + Simulation(const Simulation& rSimulation); + + virtual ~Simulation(); + + // Operations. + + int execute(int argc, char** argv); + + + // Operators. + + const Simulation& operator = (const Simulation& rSimulation); + + + }; + + } // namespace Msg +} // namespace SimGrid + + +#endif // !MSG_ENVIRONMENT_HPP \ No newline at end of file