Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use pointers instead references.
[simgrid.git] / src / cxx / ApplicationHandler.cxx
index f1a8077..3b48213 100644 (file)
  \r
  /* ApplicationHandler member functions implementation.\r
   */  \r
-  \r
+\r
+\r
+#include <Object.hpp>\r
 #include <ApplicationHandler.hpp>\r
 \r
+#include <Process.hpp>\r
+#include <Host.hpp>\r
+\r
+\r
+\r
+\r
+\r
+#include <stdlib.h>\r
+\r
+#include <surf/surfxml_parse.h>\r
+#include <xbt/sysdep.h>\r
+\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
 \r
-               ApplicationHandler::ProcessFactory::processFactory = NULL;\r
+               ApplicationHandler::ProcessFactory* ApplicationHandler::processFactory = NULL;\r
                        \r
                // Desable the default constructor, the copy constructor , the assignement operator\r
                // and the destructor of this class. Assume that this class is static.\r
@@ -59,7 +74,7 @@ namespace SimGrid
                {\r
                        // release the handler at the end of the parsing.\r
                        if(processFactory)\r
-                               delete processFactroy;\r
+                               delete processFactory;\r
                }\r
                        \r
                void ApplicationHandler::onBeginProcess(void)\r
@@ -91,23 +106,30 @@ namespace SimGrid
                \r
                ApplicationHandler::ProcessFactory::ProcessFactory() \r
                {\r
-                       this->args = xbt_dynar_new(sizeof(char*),ProcessFactory::freeCstr);\r
+                       this->args = xbt_dynar_new(sizeof(char*),ApplicationHandler::ProcessFactory::freeCstr);\r
                        this->properties = NULL; // TODO instanciate the dictionary\r
                        this->hostName = NULL;\r
                        this->function = NULL;\r
-               }      \r
+               } \r
+\r
+               ApplicationHandler::ProcessFactory::~ProcessFactory()\r
+               {\r
+                       xbt_dynar_free(&(this->args));\r
+               }\r
                \r
                // create the cxx process wrapper.\r
                void ApplicationHandler::ProcessFactory::createProcess() \r
                throw (ClassNotFoundException, HostNotFoundException)\r
                {\r
                        Host host;\r
+                       Class* c;\r
                        Process* process;\r
                        \r
                        // try to dynamicaly create an instance fo the process from its name (which is specified by the element function\r
                        // in the xml application file.\r
                        // if this static method fails, it throws an exception of the class ClassNotFoundException\r
-                       process = (Process*)Class::fromName(this->function);\r
+                       c = Class::fromName(this->function);\r
+                       process = reinterpret_cast<Process*>(c->createObject());\r
                        \r
                        // try to retrieve the host of the process from its name\r
                        // if this method fails, it throws an exception of the class HostNotFoundException\r
@@ -118,7 +140,7 @@ namespace SimGrid
                        \r
                        char** argv = (char**)calloc(argc, sizeof(char*));\r
                        \r
-                       for(int i = 0; i < argc; i++)\r
+                       for(int i = argc -1; i >= 0; i--)\r
                                xbt_dynar_pop(this->args, &(argv[i]));\r
                        \r
                        // finaly create the process (for more detail on the process creation see Process::create()\r
@@ -129,7 +151,7 @@ namespace SimGrid
                        this->properties = new Properties();*/\r
                }\r
                        \r
-               void ApplicationHandler::ProcessFactory::setProcessIdentity(const string& hostName, const string& function) \r
+               void ApplicationHandler::ProcessFactory::setProcessIdentity(const char* hostName, const char* function) \r
                {\r
                        this->hostName = hostName;\r
                        this->function = function;\r
@@ -144,12 +166,12 @@ namespace SimGrid
                // callback function used by the dynamic array to cleanup all of its elements.\r
                void ApplicationHandler::ProcessFactory::freeCstr(void* cstr)\r
                {\r
-                       free(*(void**)str);\r
+                       free(*(void**)cstr);\r
                }\r
                \r
                void ApplicationHandler::ProcessFactory::registerProcessArg(const char* arg) \r
                {\r
-                       char* cstr = strdup(arg);\r
+                       char* cstr = _strdup(arg);\r
                        xbt_dynar_push(this->args, &cstr);\r
                }\r
                \r
@@ -158,10 +180,11 @@ namespace SimGrid
                        // TODO implement this function;        \r
                }\r
                \r
-               const const char* ApplicationHandler::ProcessFactory::getHostName(void)\r
+               const char* ApplicationHandler::ProcessFactory::getHostName(void)\r
                {\r
                        return this->hostName;\r
                }\r
 \r
        } // namespace Msg\r
-} // namespace SimGrid
\ No newline at end of file
+} // namespace SimGrid\r
+\r