Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some new files of the cxx version of the MSG API
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 16 May 2008 15:06:13 +0000 (15:06 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 16 May 2008 15:06:13 +0000 (15:06 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5435 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/cxx/Application.cxx [new file with mode: 0644]
src/cxx/Application.hpp [new file with mode: 0644]
src/cxx/Environment.cxx [new file with mode: 0644]
src/cxx/Environment.hpp [new file with mode: 0644]
src/cxx/LogicException.cxx [new file with mode: 0644]
src/cxx/LogicException.hpp [new file with mode: 0644]
src/cxx/Simulation.cxx [new file with mode: 0644]
src/cxx/Simulation.hpp [new file with mode: 0644]

diff --git a/src/cxx/Application.cxx b/src/cxx/Application.cxx
new file mode 100644 (file)
index 0000000..6e6ea8b
--- /dev/null
@@ -0,0 +1,160 @@
+#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
diff --git a/src/cxx/Application.hpp b/src/cxx/Application.hpp
new file mode 100644 (file)
index 0000000..81cf005
--- /dev/null
@@ -0,0 +1,124 @@
+#ifndef MSG_APPLICATION_HPP\r
+#define MSG_APPLICATION_HPP\r
+\r
+#ifndef __cplusplus\r
+       #error Application.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+#include <InvalidParameterException.hpp>\r
+#include <LogicException.hpp>\r
+#include <MsgException.hpp>\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               class Application\r
+               {\r
+               public:\r
+                       \r
+               // Default constructor.\r
+                       Application();\r
+                       \r
+                       /*! \brief Copy constructor.\r
+                        */\r
+                       Application(const Application& rApplication);\r
+                       \r
+                       /* \brief A constructor which takes as parameter the xml file of the application.\r
+                        *\r
+                        * \exception           [InvalidParameterException]     if the parameter file is invalid\r
+                        *                                      (NULL or if the file does not exist).\r
+                        */\r
+                       Application(const char* file)\r
+                       throw(InvalidParameterException);\r
+                       \r
+                       /*! \brief Destructor.\r
+                        */\r
+                       virtual ~Application();\r
+                       \r
+               // Operations.\r
+                       \r
+                       /*! \brief Application::deploy() - deploy the appliction.\r
+                        *\r
+                        * \return                      If successfuly the application is deployed. Otherwise\r
+                        *                                      the method throws an exception listed below.\r
+                        *\r
+                        * \exception           [LogicException]                        if the xml file which describes the application\r
+                        *                                                                                              is not yet specified or if the application is already\r
+                        *                                                                                              deployed.\r
+                        *                                      [MsgException]                          if a internal exception occurs.\r
+                        *\r
+                        * \remark                      Before use this method, you must specify the xml file of the application to\r
+                        *                                      deploy.\r
+                        *\r
+                        * \see                         Application::setFile()\r
+                        */\r
+                        \r
+                       void deploy(void)\r
+                       throw(LogicExeption, MsgException);\r
+                       \r
+                       /*! \brief Application::deploy() - deploy the appliction.\r
+                        *\r
+                        * \return                      If successfuly the application is deployed. Otherwise\r
+                        *                                      the method throws an exception listed below.\r
+                        *\r
+                        * \exception           [InvalidParameterException]     if the parameter file is invalid\r
+                        *                                      (NULL or not a xml deployment file name).\r
+                        *                                      [MsgException]                          if a internal exception occurs.\r
+                        *                                      [LogicException]                        if the application is already deployed.\r
+                        *\r
+                        * \\r
+                        */\r
+                       void deploy(const char* file)\r
+                       throw(InvalidParameterException, LogicException, MsgException);\r
+                       \r
+                       /*! \brief Application::isDeployed() - tests if the application is deployed.\r
+                        *\r
+                        * \return                      This method returns true is the application is deployed.\r
+                        *                                      Otherwise the method returns false.\r
+                        */\r
+                       bool isDeployed(void) const;\r
+                       \r
+                       \r
+               // Getters/setters\r
+                       \r
+                       /*! \brief Application::setFile() - this setter sets the value of the file of the application.\r
+                        *\r
+                        * \return                      If successful, the value of the file of the application is setted.\r
+                        *                                      Otherwise the method throws on of the exceptions listed below.\r
+                        *\r
+                        * \exception           [InvalidParameterException]     if the parameter file is invalid\r
+                        *                                                                                              (NULL or does no exist).\r
+                        *                                      [LogicException]                        if you try to set the value of the file of an\r
+                        *                                                                                              application which is already deployed.\r
+                        */\r
+                       void setFile(const char* file)\r
+                       throw (InvalidParameterException, LogicException);\r
+                       \r
+                       /*! \brief Application::getFile() - this getter returns the file of an application object.\r
+                        */\r
+                       const char* getFile(void) const;\r
+                       \r
+               // Operators.\r
+                       \r
+                       /*! \brief Assignement operator.\r
+                        *\r
+                        * \exception           [LogicException]                        if you try to assign an application already deployed.\r
+                        */\r
+                       const Application& operator = (const Application& rApplication)\r
+                       throw(LogicException);\r
+                       \r
+               private:\r
+               // Attributes.\r
+                       \r
+                       // flag : if true the application was deployed.\r
+                       bool deployed;\r
+                       // the xml file which describe the application.\r
+                       const char* file;\r
+                       \r
+               };\r
+               \r
+       } // namespace Msg\r
+} // namespace SimGrid\r
+\r
+#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 (file)
index 0000000..5b0ea8d
--- /dev/null
@@ -0,0 +1,139 @@
+#include <Environment.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
+               Environment::Environment()\r
+               {\r
+                       this->file = NULL;\r
+                       this->loaded = false;\r
+               }\r
+                               \r
+               Environment::Environment(const Environment& rEnvironment);\r
+               {\r
+                       this->file = rEnvironment.getFile();\r
+                       this->loaded = rEnvironment.isLoaded();\r
+               }\r
+               \r
+               Environment::Environment(const char* file)\r
+               throw(InvalidArgumentException);\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->loaded = false;\r
+               }\r
+               \r
+               Environment::~Environment()\r
+               {\r
+                       // NOTHING TODO\r
+               }\r
+               \r
+               // Operations.\r
+               \r
+               void Environment::load(void)\r
+               throw(LogicException)\r
+               {\r
+                       // check logic\r
+                       \r
+                       if(this->loaded)\r
+                               throw LogicException("environement already loaded");\r
+                       \r
+                       // check the parameters\r
+                       if(!this->file)\r
+                               throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()"); \r
+                       \r
+                       MSG_create_environment(file);\r
+                       \r
+                       this->loaded = true;            \r
+               }\r
+               \r
+               void Environment::load(const char* file)\r
+               throw(InvalidArgumentException, LogicException)\r
+               {\r
+                       // check logic\r
+                       \r
+                       if(this->loaded)\r
+                               throw LogicException("environment already loaded");\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
+                       MSG_create_environment(file);\r
+                       \r
+                       this->file = file;\r
+                       this->loaded = true;    \r
+               }\r
+               \r
+               bool Environment::isLoaded(void) const\r
+               {\r
+                       return this->loaded;\r
+               }\r
+               \r
+               // Getters/setters\r
+               void Environment::setFile(const char* file)\r
+               throw(InvalidArgumentException, LogicException)\r
+               {\r
+                       // check logic\r
+                       \r
+                       if(this->loaded)\r
+                               throw LogicException("your are trying to change the file of an already loaded environment");\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
+               const char* Environment::getFile(void) const\r
+               {\r
+                       return this->file;\r
+               }\r
+       \r
+               \r
+               const Environment& Environment::operator = (const Environment& rEnvironment)\r
+               throw(LogicException)\r
+               {\r
+                       // check logic\r
+                       \r
+                       if(this->loaded)\r
+                               throw LogicException("environment already loaded");\r
+                       \r
+                       this->file = rEnvironment.getFile();\r
+                       this->loaded = rEnvironment.isLoaded();\r
+                       \r
+                       return *this;\r
+               }\r
+                               \r
+       } // namespace Msg\r
+} // namespace SimGrid
\ No newline at end of file
diff --git a/src/cxx/Environment.hpp b/src/cxx/Environment.hpp
new file mode 100644 (file)
index 0000000..9eae1e3
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef MSG_ENVIRONMENT_HPP\r
+#define MSG_ENVIRONMENT_HPP\r
+\r
+#ifndef __cplusplus\r
+       #error Environment.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+#include <InvalidParameterException.hpp>\r
+#include <LogicException.hpp>\r
+#include <MsgException.hpp>\r
+\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               class Environment\r
+               {\r
+                       public:\r
+                               \r
+                               Environment();\r
+                               \r
+                               Environment(const Environment& rEnvironment);\r
+                               \r
+                               Environment(const char* file)\r
+                               throw(InvalidArgumentException);\r
+                               \r
+                               virtual ~Environment();\r
+                               \r
+                               // Operations.\r
+                               \r
+                               void load(void)\r
+                               throw(LogicException);\r
+                               \r
+                               void load(const char* file)\r
+                               throw(InvalidArgumentException, LogicException);\r
+                               \r
+                               bool isLoaded(void) const;\r
+                               \r
+                               // Getters/setters\r
+                               void setFile(const char* file)\r
+                               throw(InvalidArgumentException, LogicException);\r
+                               \r
+                               const char* getFile(void) const;\r
+                               \r
+                               // Operators.\r
+                               \r
+                               const Environment& operator = (const Environment& rEnvironment)\r
+                               throw(LogicException);\r
+                               \r
+                       private:\r
+                               \r
+                               // Attributes.\r
+                               \r
+                               // the xml file which describe the environment of the simulation.\r
+                               const char* file;\r
+                               \r
+                               // flag : is true the environment of the simulation is loaded.\r
+                               bool loaded.\r
+               };\r
+               \r
+       } // namespace Msg\r
+} // namespace SimGrid\r
+\r
+\r
+#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 (file)
index 0000000..a7adcf2
--- /dev/null
@@ -0,0 +1,62 @@
+#include "LogicException.hpp"\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+using namespace std;\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+                       LogicException::LogicException()\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Logic exception : no detail") + 1, sizeof(char));\r
+                               strcpy(this->reason, "Logic exception : no detail");\r
+                       }\r
+               \r
+               \r
+                       LogicException::LogicException(const LogicException& rLogicException)\r
+                       {\r
+                               const char* reason = rLogicException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               strcpy(this->reason, reason);\r
+                               \r
+                       }\r
+               \r
+               \r
+                       LogicException::LogicException(const char* detail)\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Logic exception : ") + strlen(detail) + 1, sizeof(char));\r
+                               sprintf(this->reason, "Logic exception : %s", detail);\r
+                       }\r
+               \r
+               \r
+                       LogicException::~LogicException()\r
+                       {\r
+                               if(this->reason)\r
+                                       free(this->reason);\r
+                       }\r
+                               \r
+                       const char* LogicException::toString(void) const\r
+                       {\r
+                               return (const char*)(this->reason);     \r
+                       }\r
+               \r
+               \r
+                       const LogicException& LogicException::operator = (const LogicException& rLogicException)\r
+                       {\r
+                               const char* reason = rLogicException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               \r
+                               return *this;\r
+                       }\r
+               \r
+       } // namespace Msg      \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r
diff --git a/src/cxx/LogicException.hpp b/src/cxx/LogicException.hpp
new file mode 100644 (file)
index 0000000..19d2f40
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ * LogicException.hpp\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
+#ifndef MSG_LOGICEXCEPTION_HPP\r
+#define MSG_LOGICEXCEPTION_HPP\r
+\r
+#include "Exception.hpp"\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+               class LogicException : public Exception\r
+               {\r
+                       public:\r
+                       \r
+                       // Default constructor.\r
+                               LogicException();\r
+                       \r
+                       // Copy constructor.\r
+                               LogicException(const LogicException& rLogicException);\r
+                       \r
+                       // This constructor takes the detail of the logic exception.\r
+                               LogicException(const char* detail);\r
+                       \r
+                       // Destructor.\r
+                               virtual ~LogicException();\r
+                               \r
+                       // Operations.\r
+                                       \r
+                                       // Returns the reason of the exception :\r
+                                       // the message "Logic exception `detail'"\r
+                                       const char* toString(void) const;\r
+                       \r
+                       // Operators.\r
+                               \r
+                               // Assignement.\r
+                               const LogicException& operator = (const LogicException& rLogicException);\r
+                               \r
+                       private :\r
+                       \r
+                       // Attributes.\r
+                               \r
+                               // A buffer used to build the message returned by the methode toString().\r
+                               char* reason;\r
+               };\r
+               \r
+               \r
+       } // namespace Msg      \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP\r
diff --git a/src/cxx/Simulation.cxx b/src/cxx/Simulation.cxx
new file mode 100644 (file)
index 0000000..6461932
--- /dev/null
@@ -0,0 +1,40 @@
+#include <Simulation.hpp>\r
+\r
+#include <Simulator.hpp>\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               int Simulation::execute(int argc, char** argv)\r
+               {\r
+                       if(argc < 3) \r
+                       {\r
+                     info("Usage: Msg platform_file deployment_file");\r
+                     return 1;\r
+                   }\r
+                   \r
+                        // initialize the MSG simulator. Must be done before anything else (even logging).\r
+               Simulator::init(argc, argv);\r
+                       \r
+                       // the environment to load\r
+                       Environment environment(argv[1]);\r
+                       // the application to deploy\r
+                       Application application(argv[2]);\r
+                       // the simulation\r
+                       Simulation simulation;\r
+                       \r
+                       // load the environment\r
+                       environment.load();\r
+                       \r
+                       // deploy the application\r
+                       application.deploy();\r
+                       \r
+                       // run the simulation\r
+                       simulation.run(environment, application);\r
+                       \r
+                       // finalize the simulator\r
+                       Simulator::finalize();\r
+               }\r
+       } // namespace Msg\r
+} // namespace SimGrid\r
diff --git a/src/cxx/Simulation.hpp b/src/cxx/Simulation.hpp
new file mode 100644 (file)
index 0000000..a0a4e6b
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef MSG_ENVIRONMENT_HPP\r
+#define MSG_ENVIRONMENT_HPP\r
+\r
+#ifndef __cplusplus\r
+       #error Sumulation.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               class Simulation\r
+               {\r
+                       public :\r
+                       \r
+                               Simulation();\r
+                               \r
+                               Simulation(const Simulation& rSimulation);\r
+                               \r
+                               virtual ~Simulation();\r
+                               \r
+                       // Operations.\r
+                       \r
+                               int execute(int argc, char** argv);\r
+                               \r
+                               \r
+                       // Operators.\r
+                       \r
+                               const Simulation& operator = (const Simulation& rSimulation);\r
+                       \r
+                       \r
+               };\r
+               \r
+       } // namespace Msg\r
+} // namespace SimGrid\r
+\r
+\r
+#endif // !MSG_ENVIRONMENT_HPP
\ No newline at end of file