1 #include <ApplicationHandler.hpp>
\r
8 ApplicationHandler::ProcessFactory::processFactory = NULL;
\r
10 // Desable the default constructor, the copy constructor , the assignement operator
\r
11 // and the destructor of this class. Assume that this class is static.
\r
13 // Default constructor.
\r
14 ApplicationHandler::ApplicationHandler()
\r
19 // Copy constructor.
\r
20 ApplicationHandler::ApplicationHandler(const ApplicationHandler& rApplicationHandler)
\r
26 ApplicationHandler::~ApplicationHandler()
\r
31 // Assignement operator.
\r
32 const ApplicationHandler& ApplicationHandler::operator = (const ApplicationHandler& rApplicationHandler)
\r
37 void ApplicationHandler::onStartDocument(void)
\r
39 // instanciate the factory at the begining of the parsing
\r
40 processFactory = new ProcessFactory();
\r
43 void ApplicationHandler::onEndDocument(void)
\r
45 // release the handler at the end of the parsing.
\r
47 delete processFactroy;
\r
50 void ApplicationHandler::onBeginProcess(void)
\r
52 // set the process identity at the begin of the xml process element.
\r
53 processFactory->setProcessIdentity(A_surfxml_process_host, A_surfxml_process_function);
\r
56 void ApplicationHandler::onProcessArg(void)
\r
58 // register the argument of the current xml process element.
\r
59 processFactory->registerProcessArg(A_surfxml_argument_value);
\r
62 void ApplicationHandler::OnProperty(void)
\r
64 // set the property of the current xml process element.
\r
65 processFactory->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
\r
68 void ApplicationHandler::onEndProcess(void)
\r
70 // at the end of the xml process element create the wrapper process (of the native Msg process)
\r
71 processFactory->createProcess();
\r
74 /////////////////////////////////////////////////////////////////////////////////////////////////
\r
75 // Process factory connected member functions
\r
77 ApplicationHandler::ProcessFactory::ProcessFactory()
\r
79 this->args = xbt_dynar_new(sizeof(char*),ProcessFactory::freeCstr);
\r
80 this->properties = NULL; // TODO instanciate the dictionary
\r
81 this->hostName = NULL;
\r
82 this->function = NULL;
\r
85 // create the cxx process wrapper.
\r
86 void ApplicationHandler::ProcessFactory::createProcess()
\r
88 // dynamic creation of a instance fo the process from its name (which is specified by the element function
\r
89 // in the xml application file.
\r
90 Process* process = (Process*)Class::fromName(this->function);
\r
92 // retrieve the host of the process from its name
\r
93 Host host = Host::getByName(this->hostName);
\r
95 // build the list of the arguments of the newly created process.
\r
96 int argc = xbt_dynar_length(this->args);
\r
98 char** argv = (char**)calloc(argc, sizeof(char*));
\r
100 for(int i = 0; i < argc; i++)
\r
101 xbt_dynar_pop(this->args, &(argv[i]));
\r
103 // finaly create the process (for more detail on the process creation see Process::create()
\r
104 process->create(host, this->function , argc, argv);
\r
106 // TODO add the properties of the process
\r
107 /*process->properties = this->properties;
\r
108 this->properties = new Properties();*/
\r
111 void ApplicationHandler::ProcessFactory::setProcessIdentity(const string& hostName, const string& function)
\r
113 this->hostName = hostName;
\r
114 this->function = function;
\r
116 /*if (!this->args->empty())
\r
117 this->args->clear();
\r
119 if(!this->properties->empty())
\r
120 this->properties->clear();*/
\r
123 // callback function used by the dynamic array to cleanup all of its elements.
\r
124 void ApplicationHandler::ProcessFactory::freeCstr(void* cstr)
\r
126 free(*(void**)str);
\r
129 void ApplicationHandler::ProcessFactory::registerProcessArg(const char* arg)
\r
131 char* cstr = strdup(arg);
\r
132 xbt_dynar_push(this->args, &cstr);
\r
135 void ApplicationHandler::ProcessFactory::setProperty(const char* id, const char* value)
\r
137 // TODO implement this function;
\r
140 const const char* ApplicationHandler::ProcessFactory::getHostName(void)
\r
142 return this->hostName;
\r
146 } // namespace SimGrid