MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / SaveButtons

Method SaveButtons

cpp/src/Driver.cpp:6454–6507  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Save button info into file. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

6452// Save button info into file.
6453//-----------------------------------------------------------------------------
6454void 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.

Callers

nothing calls this directly

Calls 9

LinkEndChildMethod · 0.80
SetAttributeMethod · 0.80
GetOptionAsStringMethod · 0.80
GetFunction · 0.70
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
SaveFileMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected