+ 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
+ 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
+ host = Host::getByName(this->hostName); \r
+ \r
+ // build the list of the arguments of the newly created process.\r
+ int argc = xbt_dynar_length(this->args);\r
+ \r
+ char** argv = (char**)calloc(argc, sizeof(char*));\r
+ \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
+ process->create(host, this->function , argc, argv);\r
+ \r
+ // TODO add the properties of the process\r
+ /*process->properties = this->properties;\r
+ this->properties = new Properties();*/\r
+ }\r
+ \r
+ void ApplicationHandler::ProcessFactory::setProcessIdentity(const char* hostName, const char* function) \r
+ {\r
+ this->hostName = hostName;\r
+ this->function = function;\r
+ \r
+ /*if (!this->args->empty())\r
+ this->args->clear();\r
+ \r
+ if(!this->properties->empty())\r
+ this->properties->clear();*/\r
+ }\r
+ \r
+ // callback function used by the dynamic array to cleanup all of its elements.\r
+ void ApplicationHandler::ProcessFactory::freeCstr(void* cstr)\r
+ {\r
+ free(*(void**)cstr);\r
+ }\r
+ \r
+ void ApplicationHandler::ProcessFactory::registerProcessArg(const char* arg) \r
+ {\r
+ char* cstr = _strdup(arg);\r
+ xbt_dynar_push(this->args, &cstr);\r
+ }\r
+ \r
+ void ApplicationHandler::ProcessFactory::setProperty(const char* id, const char* value)\r
+ {\r
+ // TODO implement this function; \r
+ }\r
+ \r
+ const char* ApplicationHandler::ProcessFactory::getHostName(void)\r
+ {\r
+ return this->hostName;\r
+ }\r