X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c84c646bd7234377ccdd7410915f981cc9a95ff0..846b7de4a868bf8dc1270f76a01c33738576694d:/src/cxx/ApplicationHandler.cxx diff --git a/src/cxx/ApplicationHandler.cxx b/src/cxx/ApplicationHandler.cxx index 5d6d3f2142..3b48213267 100644 --- a/src/cxx/ApplicationHandler.cxx +++ b/src/cxx/ApplicationHandler.cxx @@ -1,11 +1,41 @@ +/* + * ApplicationHandler.cxx + * + * 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. + * + */ + + /* ApplicationHandler member functions implementation. + */ + + +#include #include +#include +#include + + + + + +#include + +#include +#include + + namespace SimGrid { namespace Msg { - ApplicationHandler::ProcessFactory::processFactory = NULL; + ApplicationHandler::ProcessFactory* ApplicationHandler::processFactory = NULL; // Desable the default constructor, the copy constructor , the assignement operator // and the destructor of this class. Assume that this class is static. @@ -33,7 +63,7 @@ namespace SimGrid { return *this; } - + void ApplicationHandler::onStartDocument(void) { // instanciate the factory at the begining of the parsing @@ -44,7 +74,7 @@ namespace SimGrid { // release the handler at the end of the parsing. if(processFactory) - delete processFactroy; + delete processFactory; } void ApplicationHandler::onBeginProcess(void) @@ -76,46 +106,41 @@ namespace SimGrid ApplicationHandler::ProcessFactory::ProcessFactory() { - this->args = xbt_dynar_new(sizeof(char*),ProcessFactory::freeCstr); + this->args = xbt_dynar_new(sizeof(char*),ApplicationHandler::ProcessFactory::freeCstr); this->properties = NULL; // TODO instanciate the dictionary this->hostName = NULL; this->function = NULL; - } + } + + ApplicationHandler::ProcessFactory::~ProcessFactory() + { + xbt_dynar_free(&(this->args)); + } // create the cxx process wrapper. void ApplicationHandler::ProcessFactory::createProcess() + throw (ClassNotFoundException, HostNotFoundException) { Host host; + Class* c; Process* process; - // dynamic creation of a instance fo the process from its name (which is specified by the element function + // try to dynamicaly create an instance fo the process from its name (which is specified by the element function // in the xml application file. - try - { - process = (Process*)Class::fromName(this->function); - } - catch(ClassNotFoundException e) - { - cerr << e.toString(); - } + // if this static method fails, it throws an exception of the class ClassNotFoundException + c = Class::fromName(this->function); + process = reinterpret_cast(c->createObject()); // try to retrieve the host of the process from its name - try - { - host = Host::getByName(this->hostName); - } - catch(HostNotFoundException(this->hostName)) - { - cerr << e.toString(); - } - + // if this method fails, it throws an exception of the class HostNotFoundException + host = Host::getByName(this->hostName); // build the list of the arguments of the newly created process. int argc = xbt_dynar_length(this->args); char** argv = (char**)calloc(argc, sizeof(char*)); - for(int i = 0; i < argc; i++) + for(int i = argc -1; i >= 0; i--) xbt_dynar_pop(this->args, &(argv[i])); // finaly create the process (for more detail on the process creation see Process::create() @@ -126,7 +151,7 @@ namespace SimGrid this->properties = new Properties();*/ } - void ApplicationHandler::ProcessFactory::setProcessIdentity(const string& hostName, const string& function) + void ApplicationHandler::ProcessFactory::setProcessIdentity(const char* hostName, const char* function) { this->hostName = hostName; this->function = function; @@ -141,12 +166,12 @@ namespace SimGrid // callback function used by the dynamic array to cleanup all of its elements. void ApplicationHandler::ProcessFactory::freeCstr(void* cstr) { - free(*(void**)str); + free(*(void**)cstr); } void ApplicationHandler::ProcessFactory::registerProcessArg(const char* arg) { - char* cstr = strdup(arg); + char* cstr = _strdup(arg); xbt_dynar_push(this->args, &cstr); } @@ -155,10 +180,11 @@ namespace SimGrid // TODO implement this function; } - const const char* ApplicationHandler::ProcessFactory::getHostName(void) + const char* ApplicationHandler::ProcessFactory::getHostName(void) { return this->hostName; } } // namespace Msg -} // namespace SimGrid \ No newline at end of file +} // namespace SimGrid +