Changeset 116 for osgVisual/src/extLink
- Timestamp:
- Aug 19, 2010, 8:58:29 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/src/extLink/dataIO_extLinkVCL.cpp
r88 r116 35 35 OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL init()" << std::endl; 36 36 37 std::string VCLConfigFilename = "osgVisual.xml"; 37 VCLConfigFilename = "osgVisual.xml"; 38 38 39 if ( osgDB::fileExists( VCLConfigFilename ) ) 39 40 { 40 41 CVCLIO::GetInstance().LoadProject(VCLConfigFilename.c_str()); 42 43 parseVCLConfig(); 41 44 bool error = false; 42 45 … … 145 148 return true; 146 149 } 150 151 bool dataIO_extLinkVCL::parseVCLConfig() 152 { 153 configFileValid = false; 154 xmlDoc *doc = NULL; 155 xmlNode *root_element = NULL; 156 157 doc = xmlReadFile(VCLConfigFilename.c_str(), NULL, 0); 158 if (doc == NULL) 159 { 160 configFileValid = false; 161 std::cout << "error: could not parse file" << VCLConfigFilename; 162 } 163 else 164 { 165 // Get the root element node 166 root_element = xmlDocGetRootElement(doc); 167 168 checkXMLNode(root_element); 169 170 // free the document 171 xmlFreeDoc(doc);; 172 } 173 // Free the global variables that may have been allocated by the parser. 174 xmlCleanupParser(); 175 176 if(!configFileValid) 177 OSG_ALWAYS << "ERROR: XML file seems not to be a valid VCL configuration file!" << std::endl; 178 179 return true; 180 } 181 182 void dataIO_extLinkVCL::checkXMLNode(xmlNode * a_node) 183 { 184 for (xmlNode *cur_node = a_node; cur_node; cur_node = cur_node->next) 185 { 186 std::string node_name=reinterpret_cast<const char*>(cur_node->name); 187 if(cur_node->type == XML_ELEMENT_NODE && node_name == "CONFIGURATION") 188 { 189 std::cout << "XML node CONFIGURATION found" << std::endl; 190 configFileValid = true; 191 } 192 193 if (cur_node->type == XML_ELEMENT_NODE && node_name == "CHANNEL") 194 { 195 std::cout << "XML node CHANNEL found" << std::endl; 196 197 // Extract channel infos like name, direction and extract channels 198 std::string name; 199 dataIO_slot::dataDirection direction; 200 xmlAttr *attr = cur_node->properties; 201 while ( attr ) 202 { 203 std::string attr_name=reinterpret_cast<const char*>(attr->name); 204 if( attr_name == "name" ) 205 name = reinterpret_cast<const char*>(attr->children->content); 206 if( attr_name == "multicast_in_group" ) 207 direction = dataIO_slot::TO_OBJ; 208 if( attr_name == "multicast_out_group" ) 209 direction = dataIO_slot::FROM_OBJ; 210 //std::cout << "Attribute name: " << attr->name << " value: " << attr->children->content << std::endl; 211 attr = attr->next; 212 } 213 addChannels(cur_node->children, name, direction ); 214 215 //printf("node type: Element, name: %s\n", cur_node->name); 216 std::cout << "Processing children at " << cur_node->children << std::endl; 217 } // IF(CHANNEL) END 218 219 // Iterate to the next nodes to find channels. 220 checkXMLNode(cur_node->children); 221 } // FOR END 222 } 223 224 void dataIO_extLinkVCL::addChannels(xmlNode * a_node, std::string channelName_, dataIO_slot::dataDirection direction_ ) 225 { 226 if(!a_node) 227 return; 228 229 OSG_ALWAYS << "Processing channels for channel " << channelName_ << " with the direction " << direction_ << std::endl; 230 231 for (xmlNode *cur_node = a_node; cur_node; cur_node = cur_node->next) 232 { 233 OSG_ALWAYS << "Found entry!" << std::endl; 234 235 // Extract ENTRY - name 236 std::string entryName; 237 xmlAttr *attr = cur_node->properties; 238 while ( attr ) 239 { 240 std::string attr_name=reinterpret_cast<const char*>(attr->name); 241 if( attr_name == "name" ) 242 entryName = reinterpret_cast<const char*>(attr->children->content); 243 //std::cout << "Attribute name: " << attr->name << " value: " << attr->children->content << std::endl; 244 attr = attr->next; 245 } 246 247 // Store VCL variable 248 CVCLVariable<double>* tmp = new CVCLVariable<double>; 249 extLinkChannels.push_back(tmp); 250 251 // Attach VCL variable to channel: 252 if( !tmp->Attach(channelName_.c_str(), entryName.c_str() ) ) 253 OSG_ALWAYS << "ERROR - dataIO_extLinkVCL::addChannels(): unable to attach VCL variable entryName: " << entryName << " to channel: " << channelName_ << std::endl; 254 255 // Set SLOT data and store SLOT pointer 256 extLinkSlots.push_back( osgVisual::visual_dataIO::getInstance()->setSlotData( entryName, direction_, 0 ) ); 257 } // FOR each ENTRY END 258 }
Note: See TracChangeset
for help on using the changeset viewer.