#include <ApplicationHandler.hpp>\r
\r
-namespace msg\r
+namespace SimGrid\r
{\r
- \r
-ApplicationHandler::ProcessFactory::processFactory = NULL;\r
- \r
-void ApplicationHandler::onStartDocument(void)\r
-{\r
- processFactory = new ProcessFactory(); \r
-}\r
-\r
-void ApplicationHandler::onEndDocument(void)\r
-{\r
- if(processFactory)\r
- delete processFactroy;\r
-}\r
- \r
-void ApplicationHandler::onBeginProcess(void)\r
-{\r
- processFactory->setProcessIdentity(A_surfxml_process_host, A_surfxml_process_function);\r
-} \r
-\r
-void ApplicationHandler::onProcessArg(void)\r
-{\r
- processFactory->registerProcessArg(A_surfxml_argument_value);\r
-}\r
-\r
-void ApplicationHandler::OnProperty(void)\r
-{\r
- processFactory->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);\r
-}\r
-\r
-void ApplicationHandler::onEndProcess(void)\r
-{\r
- processFactory->createProcess();\r
-}\r
-\r
-void ApplicationHandler::ProcessFactory::createProcess() \r
+ namespace Msg\r
{\r
- Process* process = (Process*)Class::fromName(this->function);\r
- \r
- Host host = Host::getByName(this->hostName);\r
-\r
- process->create();\r
- \r
- Strings* args = processFactory->args;\r
- \r
- int size = args->size();\r
-\r
- for (int index = 0; index < size; index++)\r
- process->args->push_back(args->at(index));\r
- \r
- process->properties = this->properties;\r
- this->properties = new Properties();\r
- }\r
- \r
-void ApplicationHandler::ProcessFactory::setProcessIdentity(const string& hostName, const string& 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
+ ApplicationHandler::ProcessFactory::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
+ \r
+ // Default constructor.\r
+ ApplicationHandler::ApplicationHandler()\r
+ {\r
+ // NOTHING TODO\r
+ }\r
+ \r
+ // Copy constructor.\r
+ ApplicationHandler::ApplicationHandler(const ApplicationHandler& rApplicationHandler)\r
+ {\r
+ // NOTHING TODO\r
+ }\r
+ \r
+ // Destructor\r
+ ApplicationHandler::~ApplicationHandler()\r
+ {\r
+ // NOTHING TODO\r
+ }\r
+ \r
+ // Assignement operator.\r
+ const ApplicationHandler& ApplicationHandler::operator = (const ApplicationHandler& rApplicationHandler)\r
+ {\r
+ return *this;\r
+ }\r
+ \r
+ void ApplicationHandler::onStartDocument(void)\r
+ {\r
+ // instanciate the factory at the begining of the parsing\r
+ processFactory = new ProcessFactory(); \r
+ }\r
+ \r
+ void ApplicationHandler::onEndDocument(void)\r
+ {\r
+ // release the handler at the end of the parsing.\r
+ if(processFactory)\r
+ delete processFactroy;\r
+ }\r
+ \r
+ void ApplicationHandler::onBeginProcess(void)\r
+ {\r
+ // set the process identity at the begin of the xml process element.\r
+ processFactory->setProcessIdentity(A_surfxml_process_host, A_surfxml_process_function);\r
+ } \r
+ \r
+ void ApplicationHandler::onProcessArg(void)\r
+ {\r
+ // register the argument of the current xml process element.\r
+ processFactory->registerProcessArg(A_surfxml_argument_value);\r
+ }\r
+ \r
+ void ApplicationHandler::OnProperty(void)\r
+ {\r
+ // set the property of the current xml process element.\r
+ processFactory->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);\r
+ }\r
+ \r
+ void ApplicationHandler::onEndProcess(void)\r
+ {\r
+ // at the end of the xml process element create the wrapper process (of the native Msg process)\r
+ processFactory->createProcess();\r
+ }\r
+ \r
+ /////////////////////////////////////////////////////////////////////////////////////////////////\r
+ // Process factory connected member functions\r
+ \r
+ ApplicationHandler::ProcessFactory::ProcessFactory() \r
+ {\r
+ this->args = xbt_dynar_new(sizeof(char*),ProcessFactory::freeCstr);\r
+ this->properties = NULL; // TODO instanciate the dictionary\r
+ this->hostName = NULL;\r
+ this->function = NULL;\r
+ } \r
+ \r
+ // create the cxx process wrapper.\r
+ void ApplicationHandler::ProcessFactory::createProcess() \r
+ {\r
+ // dynamic creation of a instance fo the process from its name (which is specified by the element function\r
+ // in the xml application file.\r
+ Process* process = (Process*)Class::fromName(this->function);\r
+ \r
+ // retrieve the host of the process from its name\r
+ Host 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 = 0; i < argc; 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 string& hostName, const string& 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**)str);\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 const char* ApplicationHandler::ProcessFactory::getHostName(void)\r
+ {\r
+ return this->hostName;\r
+ }\r
\r
-}
\ No newline at end of file
+ } // namespace Msg\r
+} // namespace SimGrid
\ No newline at end of file
#error ApplicationHandler.hpp requires C++ compilation (use a .cxx suffix)\r
#endif\r
\r
-#include <vector>\r
-#include <map>\r
\r
-namespace msg\r
+namespace SimGrid\r
{\r
- \r
- struct Compare\r
+ namespace Msg\r
{\r
- public bool operator(const string& first, const string& second)\r
+ // Declaration of the class ApplicationHandler.\r
+ class ApplicationHandler\r
{\r
- return first.compare(second);\r
- }\r
- };\r
- \r
- typedef vector<string> Strings;\r
- \r
- typedef map<string, string, Compare> Properties;\r
- \r
- \r
-class ApplicationHandler\r
-{\r
-private :\r
- // Default constructor.\r
- ApplicationHandler();\r
- \r
- // Copy constructor.\r
- ApplicationHandler(const ApplicationHandler& rApplicationHandler);\r
- \r
- // Destructor\r
- virtual ~ApplicationHandler();\r
- \r
- class ProcessFactory \r
- {\r
- public:\r
- \r
- Strings* args;\r
- Properties* properties;\r
- \r
- private:\r
- string hostName;\r
- string function;\r
- \r
- public :\r
- \r
- ProcessFactory() \r
- {\r
- this->args = new Strings();\r
- this->properties = new Properties();\r
- this->hostName = NULL;\r
- this->function = NULL;\r
- } \r
- \r
- void setProcessIdentity(const string& hostName, const string& function);\r
- \r
- void registerProcessArg(const string& arg) \r
- {\r
- this->args->push_back(arg);\r
- }\r
-\r
- void setProperty(const string& id, const string& value)\r
- {\r
- this->properties->insert(Properties::value_type(id,value)); \r
- }\r
-\r
- const String& getHostName(void)\r
- {\r
- return this->hostName;\r
- }\r
-\r
- void createProcess(void); \r
- \r
- };\r
- \r
- static ProcessFactory* processFactory;\r
- \r
- public:\r
- \r
- static void onStartDocument(void);\r
- \r
- static void onEndDocument(void);\r
- \r
- static void onBeginProcess(void);\r
- \r
- static void onProcessArg(void);\r
- \r
- static void OnProperty(void);\r
- \r
- static void onEndProcess(void);\r
-};\r
+ private :\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
+ \r
+ // Default constructor.\r
+ ApplicationHandler();\r
+ \r
+ // Copy constructor.\r
+ ApplicationHandler(const ApplicationHandler& rApplicationHandler);\r
+ \r
+ // Destructor\r
+ virtual ~ApplicationHandler();\r
+ \r
+ // Assignement operator.\r
+ const ApplicationHandler& operator = (const ApplicationHandler& rApplicationHandler);\r
+ \r
+ class ProcessFactory \r
+ {\r
+ public:\r
+ \r
+ // the list of the argument of the process to create.\r
+ xbt_dynar_t args;\r
+ // the properties of the process to create\r
+ xbt_dict_t properties;\r
+ \r
+ private:\r
+ \r
+ // the current host name parsed\r
+ const char* hostName;\r
+ // the name of the class of the process\r
+ const char* function;\r
+ \r
+ public :\r
+ \r
+ // Default constructor.\r
+ ProcessFactory(); \r
+ \r
+ // Copy constructor.\r
+ ProcessFactory(const ProcessFactory& rProcessFactory);\r
+ \r
+ // Destructor.\r
+ virtual ~ProcessFactory();\r
+ \r
+ // Set the identity of the current process.\r
+ void setProcessIdentity(const char* hostName, const char* function);\r
+ \r
+ // Register an argument of the current process.\r
+ void registerProcessArg(const char* arg); \r
+ \r
+ // Set the property of the current process.\r
+ void setProperty(const char* id, const char* value);\r
+ \r
+ // Return the host name of the current process.\r
+ const const char* getHostName(void);\r
+ \r
+ // Create the current process.\r
+ void createProcess(void); \r
+ \r
+ };\r
+ \r
+ // the process factory used by the application handler.\r
+ static ProcessFactory* processFactory;\r
+ \r
+ public:\r
+ \r
+ // Handle the begining of the parsing of the xml file describing the application.\r
+ static void onStartDocument(void);\r
+ \r
+ // Handle at the end of the parsing.\r
+ static void onEndDocument(void);\r
+ \r
+ // Handle the begining of the parsing of a xml process element.\r
+ static void onBeginProcess(void);\r
+ \r
+ // Handle the parsing of an argument of the current xml process element.\r
+ static void onProcessArg(void);\r
+ \r
+ // Handle the parsing of a property of the currnet xml process element.\r
+ static void OnProperty(void);\r
+ \r
+ // Handle the end of the parsing of a xml process element\r
+ static void onEndProcess(void);\r
+ };\r
\r
-}\r
+ } // namespace Msg\r
+} // namespace SimGrid\r
\r
#endif // !MSG_APPLICATION_HANDLER_HPP\r
\ No newline at end of file