00001 /** @file XMLParser.h 00002 * @author Gabor Madl 00003 * @date Created 06/2005 00004 * @brief XML Parser library. 00005 * 00006 * 00007 * ================================================================= 00008 * DREAM License v2.0 00009 * 00010 * DREAM - Distributed Real-time Embedded Analysis Method 00011 * http://dre.sourceforge.net. 00012 * Copyright (c) 2005-2007 Gabor Madl, All Rights Reserved. 00013 * 00014 * This file is part of DREAM. 00015 * 00016 * DREAM is free software; you can redistribute it and/or modify it 00017 * under the terms of the GNU General Public License version 2 as 00018 * published by the Free Software Foundation. No future versions of 00019 * the GPL license may be automatically applied to DREAM. It is in 00020 * the sole discretion of the copyright holder to determine whether 00021 * DREAM may be released under a different license or terms. There 00022 * are no restrictions on the use of DREAM for any purpose. 00023 * 00024 * DREAM is distributed in the hope that it will be useful, 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 * GNU General Public License for more details. 00028 * 00029 * You should have received a copy of the GNU General Public License 00030 * along with this program; if not, write to the Free Software 00031 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00032 * MA 02110-1301, USA. 00033 * 00034 * By submitting comments, suggestions, code, code snippets, 00035 * techniques (including that of usage), and algorithms, submitters 00036 * acknowledge that they have the right to do so, that any such 00037 * submissions are given freely and unreservedly, and that they 00038 * waive any claims to copyright or ownership. In addition, 00039 * submitters acknowledge that any such submission might become 00040 * part of the copyright maintained on the overall body of code, 00041 * which comprises DREAM. By making a submission, submitter agrees 00042 * to these terms. Furthermore, submitters acknowledge that the 00043 * incorporation or modification of such submissions is entirely 00044 * at the discretion of the moderators of the DREAM project. 00045 * 00046 * DREAM links to the Libxml2 third party library. Please see 00047 * COPYING-libxml for the copyright information of Libxml2. 00048 * ================================================================= 00049 */ 00050 00051 #ifndef DREAM_XMLPARSER 00052 #define DREAM_XMLPARSER 00053 00054 #include "../core/System.h" 00055 #include <libxml/xmlreader.h> 00056 00057 namespace DREAM 00058 { 00059 00060 /** XML Parser class. 00061 * Parses an XML file using libxml. 00062 */ 00063 class XMLParser 00064 { 00065 public: 00066 /** Constructor. */ 00067 XMLParser () {}; 00068 00069 /** Destructor. */ 00070 ~XMLParser () {}; 00071 00072 /** Starts the parsing of the XML input into the System root. */ 00073 void parse (char* xmlFile, DREAM::System* system) 00074 throw (DREAM::Exception); 00075 00076 /** Sets the system_ptr_ root pointer for DREAM::System. 00077 * @param system_ptr is the pointer to be set in system_ptr_. 00078 */ 00079 void set_system (DREAM::System* system_ptr); 00080 00081 private: 00082 00083 /** Verifies whether each timer, task and channel is mapped to threads, and whether each thread is mapped to a CPU. */ 00084 void check_mapping () 00085 throw (DREAM::Exception); 00086 00087 /** Looks up a temporarily stored node in node_map_. 00088 * @param name is the name of the node to be searched for. 00089 * @return pointer to the Node. 00090 */ 00091 DREAM::Node* find_node (const std::string& name) 00092 throw (DREAM::Exception); 00093 00094 /** Looks up a temporarily stored node in thread_map_. 00095 * @param name is the name of the thread to be searched for. 00096 * @return pointer to the Thread. 00097 */ 00098 DREAM::Thread* find_thread (const std::string& name) 00099 throw (DREAM::Exception); 00100 00101 /** Handler for libxml. 00102 * This is the entry point for XML parsing. 00103 * @param reader is a pointer to the xmlTextReader. 00104 */ 00105 void process_node (xmlTextReaderPtr reader) 00106 throw (DREAM::Exception); 00107 00108 /** Processes an XML <task/> node. 00109 * This function processes a <task/> node from the XML input and creates the corresponding DREAM representation. 00110 * @param reader is a pointer to the xmlTextReader. 00111 */ 00112 void process_task (xmlTextReaderPtr reader) 00113 throw (DREAM::Exception); 00114 00115 /** Processes an XML <channel/> node. 00116 * This function processes a <channel/> node from the XML input and creates the corresponding DREAM representation. 00117 * @param reader is a pointer to the xmlTextReader. 00118 */ 00119 void process_channel (xmlTextReaderPtr reader) 00120 throw (DREAM::Exception); 00121 00122 /** Processes an XML <timer/> node. 00123 * This function processes a <timer/> node from the XML input and creates the corresponding DREAM representation. 00124 * @param reader is a pointer to the xmlTextReader. 00125 */ 00126 void process_timer (xmlTextReaderPtr reader) 00127 throw (DREAM::Exception); 00128 00129 /** Processes an XML <thread/> node. 00130 * This function processes a <thread/> node from the XML input and creates the corresponding DREAM representation. 00131 * @param reader is a pointer to the xmlTextReader. 00132 */ 00133 void process_thread (xmlTextReaderPtr reader) 00134 throw (DREAM::Exception); 00135 00136 /** Processes an XML <timertotask/> connection. 00137 * This function processes a <timertotask/> connection from the XML input and creates the corresponding connections in the DREAM representation. 00138 * @param reader is a pointer to the xmlTextReader. 00139 */ 00140 void process_timer_to_task (xmlTextReaderPtr reader) 00141 throw (DREAM::Exception); 00142 00143 /** Processes an XML <tasktotask/> connection. 00144 * This function processes a <timertotask/> connection from the XML input and creates the corresponding connections in the DREAM representation. 00145 * @param reader is a pointer to the xmlTextReader. 00146 */ 00147 void process_task_to_task (xmlTextReaderPtr reader) 00148 throw (DREAM::Exception); 00149 00150 /** Processes an XML <tasktochannel/> connection. 00151 * This function processes a <timertotask/> connection from the XML input and creates the corresponding connections in the DREAM representation. 00152 * @param reader is a pointer to the xmlTextReader. 00153 */ 00154 void process_task_to_channel (xmlTextReaderPtr reader) 00155 throw (DREAM::Exception); 00156 00157 /** Processes an XML <channeltotask/> connection. 00158 * This function processes a <timertotask/> connection from the XML input and creates the corresponding connections in the DREAM representation. 00159 * @param reader is a pointer to the xmlTextReader. 00160 */ 00161 void process_channel_to_task (xmlTextReaderPtr reader) 00162 throw (DREAM::Exception); 00163 00164 /** Processes an XML <taskmapping/> mapping. 00165 * This function processes a <taskmapping/> mapping from the XML input and creates the corresponding mappings in the DREAM representation. 00166 * @param reader is a pointer to the xmlTextReader. 00167 */ 00168 void process_task_mapping (xmlTextReaderPtr reader) 00169 throw (DREAM::Exception); 00170 00171 /** Processes an XML <channelmapping/> mapping. 00172 * This function processes a <channelmapping/> mapping from the XML input and creates the corresponding mappings in the DREAM representation. 00173 * @param reader is a pointer to the xmlTextReader. 00174 */ 00175 void process_channel_mapping (xmlTextReaderPtr reader) 00176 throw (DREAM::Exception); 00177 00178 /** Processes an XML <timermapping/> mapping. 00179 * This function processes a <timermapping/> mapping from the XML input and creates the corresponding mappings in the DREAM representation. 00180 * @param reader is a pointer to the xmlTextReader. 00181 */ 00182 void process_timer_mapping (xmlTextReaderPtr reader) 00183 throw (DREAM::Exception); 00184 00185 /** Processes an XML <componentmapping/> mapping. 00186 * This function processes a <componentmapping/> mapping from the XML input and creates the corresponding mappings in the DREAM representation. 00187 * @param reader is a pointer to the xmlTextReader. 00188 * @todo Handling components by the parser. 00189 * @todo Handling power aware tasks by the parser. 00190 */ 00191 void process_component_mapping (xmlTextReaderPtr reader); 00192 00193 /** Processes an XML <CPU/> node. 00194 * This function processes a <CPU/> node from the XML input and creates the corresponding DREAM representation. 00195 * @param reader is a pointer to the xmlTextReader. 00196 */ 00197 void process_CPU (xmlTextReaderPtr reader) 00198 throw (DREAM::Exception); 00199 00200 /** Processes an XML <threadmapping/> mapping. 00201 * This function processes a <threadmapping/> mapping from the XML input and creates the corresponding mappings in the DREAM representation. 00202 * @param reader is a pointer to the xmlTextReader. 00203 */ 00204 void process_thread_mapping (xmlTextReaderPtr reader) 00205 throw (DREAM::Exception); 00206 00207 /** Stores DREAM::Node and inherited implementations. 00208 * Connections between elements are built using this list. 00209 */ 00210 DREAM::NODE_MAP node_map_; 00211 00212 /** Stores DREAM::Thread and inherited implementations. 00213 * Connections between elements are built using this list. 00214 */ 00215 DREAM::THREAD_STR_MAP thread_map_; 00216 00217 /** Pointer to the last Thread used. */ 00218 DREAM::Thread* current_thread_; 00219 00220 /** Pointer to the last Scheduler used. */ 00221 DREAM::Scheduler* current_scheduler_; 00222 00223 /** Pointer to the system root. */ 00224 DREAM::System* system_ptr_; 00225 }; 00226 00227 }; 00228 00229 #endif 00230