----------------------------------------------------------------------------- Save button info into file. -----------------------------------------------------------------------------
| 6452 | // Save button info into file. |
| 6453 | //----------------------------------------------------------------------------- |
| 6454 | void Driver::SaveButtons |
| 6455 | ( |
| 6456 | ) |
| 6457 | { |
| 6458 | char str[16]; |
| 6459 | |
| 6460 | // Create a new XML document to contain the driver configuration |
| 6461 | TiXmlDocument doc; |
| 6462 | TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "utf-8", "" ); |
| 6463 | TiXmlElement* nodesElement = new TiXmlElement( "Nodes" ); |
| 6464 | doc.LinkEndChild( decl ); |
| 6465 | doc.LinkEndChild( nodesElement ); |
| 6466 | |
| 6467 | nodesElement->SetAttribute( "xmlns", "http://code.google.com/p/open-zwave/" ); |
| 6468 | |
| 6469 | snprintf( str, sizeof(str), "%d", 1 ); |
| 6470 | nodesElement->SetAttribute( "version", str); |
| 6471 | LockGuard LG(m_nodeMutex); |
| 6472 | for( int i = 1; i < 256; i++ ) |
| 6473 | { |
| 6474 | if( m_nodes[i] == NULL || m_nodes[i]->m_buttonMap.empty() ) |
| 6475 | { |
| 6476 | continue; |
| 6477 | } |
| 6478 | |
| 6479 | TiXmlElement* nodeElement = new TiXmlElement( "Node" ); |
| 6480 | |
| 6481 | snprintf( str, sizeof(str), "%d", i ); |
| 6482 | nodeElement->SetAttribute( "id", str ); |
| 6483 | |
| 6484 | for( map<uint8,uint8>::iterator it = m_nodes[i]->m_buttonMap.begin(); it != m_nodes[i]->m_buttonMap.end(); ++it ) |
| 6485 | { |
| 6486 | TiXmlElement* valueElement = new TiXmlElement( "Button" ); |
| 6487 | |
| 6488 | snprintf( str, sizeof(str), "%d", it->first ); |
| 6489 | valueElement->SetAttribute( "id", str ); |
| 6490 | |
| 6491 | snprintf( str, sizeof(str), "%d", it->second ); |
| 6492 | TiXmlText* textElement = new TiXmlText( str ); |
| 6493 | valueElement->LinkEndChild( textElement ); |
| 6494 | |
| 6495 | nodeElement->LinkEndChild( valueElement ); |
| 6496 | } |
| 6497 | |
| 6498 | nodesElement->LinkEndChild( nodeElement ); |
| 6499 | } |
| 6500 | |
| 6501 | string userPath; |
| 6502 | Options::Get()->GetOptionAsString( "UserPath", &userPath ); |
| 6503 | |
| 6504 | string filename = userPath + "zwbutton.xml"; |
| 6505 | |
| 6506 | doc.SaveFile( filename.c_str() ); |
| 6507 | } |
| 6508 | //----------------------------------------------------------------------------- |
| 6509 | // <Driver::ReadButtons> |
| 6510 | // Read button info per node from file. |
nothing calls this directly
no test coverage detected