Changeset 478

Show
Ignore:
Timestamp:
06/02/07 08:06:28 (17 years ago)
Author:
wagi
Message:

- save cache information to $(localstatedir)/cache/libffade
- refactoring of build and load cache function

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/configure.ac

    r470 r478  
    11# configure.ac - Configure script for FFADO. 
    2 # Copyright (C) 2005,06 by Daniel Wagner. 
     2# Copyright (C) 2005,06,07 by Daniel Wagner. 
    33# Copyright (C) 2006,07 by Pieter Palmers. 
    44# 
     
    2626m4_define(ffado_major_version, 1) 
    2727m4_define(ffado_minor_version, 999) 
    28 m4_define(ffado_micro_version, 4
     28m4_define(ffado_micro_version, 5
    2929 
    3030m4_define(ffado_version, ffado_major_version.ffado_minor_version.ffado_micro_version) 
     
    300300 
    301301CFLAGS="$CFLAGS -Wall -std=gnu99" 
    302 CXXFLAGS="$CXXFLAGS -Wall -DDATADIR=\\\"\$(datadir)\\\""  
    303  
     302CXXFLAGS="$CXXFLAGS -Wall -DDATADIR=\\\"\$(datadir)\\\"  -DCACHEDIR=\\\"\$(localstatedir)\\\"" 
    304303if test "${debug}" = true; then 
    305304   CFLAGS="$CFLAGS -g -DDEBUG" 
  • trunk/libffado/src/devicemanager.cpp

    r445 r478  
    486486 
    487487bool 
    488 DeviceManager::saveCache( Glib::ustring fileName ) 
    489 
    490     int i; 
    491     i=0; // avoids unused warning 
    492  
     488DeviceManager::buildCache() 
     489
     490    bool result = true; 
    493491    for ( IAvDeviceVectorIterator it = m_avDevices.begin(); 
    494492          it != m_avDevices.end(); 
    495493          ++it ) 
    496494    { 
    497         IAvDevice* pAvDevice; 
    498         pAvDevice = *it; // avoids unused warning 
    499  
    500         #ifdef ENABLE_BEBOB 
     495        IAvDevice* pAvDevice = *it; 
     496 
    501497        BeBoB::AvDevice* pBeBoBDevice = reinterpret_cast< BeBoB::AvDevice* >( pAvDevice ); 
    502498        if ( pBeBoBDevice ) { 
    503             // Let's use a very simple path to find the devices later. 
    504             // Since under hood there will an xml node name this should 
    505             // adhere the needed naming rules. Of course we could give it 
    506             // a good node name and add an attribute but that would mean 
    507             // we have to expose a bigger interface from IOSerialize/IODesialize, 
    508             // which is just not needed. KISS. 
    509             ostringstream strstrm; 
    510             strstrm << "id" << i; 
    511             Glib::ustring basePath = "BeBoB/" + strstrm.str() + "/"; 
    512  
    513             Util::XMLSerialize ser( fileName ); 
    514             pBeBoBDevice->serialize( basePath, ser ); 
    515  
    516             i++; 
    517             std::cout << "a bebob device serialized" << std::endl; 
    518         } 
    519         #endif 
    520     } 
    521     return true; 
    522 
    523  
    524 bool 
    525 DeviceManager::loadCache( Glib::ustring fileName ) 
    526 
    527     int i; 
    528     i=0; // avoids unused warning 
    529     Util::XMLDeserialize deser( fileName ); 
    530  
    531     typedef std::vector<ConfigRom*> ConfigRomVector; 
    532     ConfigRomVector configRoms; 
    533  
     499            result &= saveCache( pBeBoBDevice ); 
     500        } 
     501    } 
     502 
     503    return result; 
     504
     505 
     506Glib::ustring 
     507DeviceManager::getCachePath() 
     508
     509    Glib::ustring cachePath; 
     510    char* pCachePath; 
     511    if ( asprintf( &pCachePath, "%s/cache/libfreebob/",  CACHEDIR ) < 0 ) { 
     512        debugError( "saveCache: Could not create path string for cache pool (trying '/var/cache/freebob' instead)\n" ); 
     513        cachePath == "/var/cache/freebob/"; 
     514    } else { 
     515        cachePath = pCachePath; 
     516        free( pCachePath ); 
     517    } 
     518    return cachePath; 
     519
     520 
     521bool 
     522DeviceManager::saveCache( IAvDevice* pAvDevice ) 
     523
     524    BeBoB::AvDevice* pBeBoBDevice = reinterpret_cast<BeBoB::AvDevice*>( pAvDevice ); 
     525    if ( !pBeBoBDevice ) { 
     526        return true; 
     527    } 
     528 
     529    Glib::ustring sFileName = getCachePath() + pAvDevice->getConfigRom().getGuidString() + ".xml"; 
     530    debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", sFileName.c_str() ); 
     531 
     532    Util::XMLSerialize ser( sFileName ); 
     533    return pBeBoBDevice->serialize( "/", ser ); 
     534
     535 
     536bool 
     537DeviceManager::loadCache( Glib::ustring cachePath ) 
     538
    534539    for ( fb_nodeid_t nodeId = 0; 
    535540          nodeId < m_1394Service->getNodeCount(); 
     
    550555            continue; 
    551556        } 
    552         configRoms.push_back( pConfigRom ); 
    553     } 
    554  
    555     #ifdef ENABLE_BEBOB 
    556     BeBoB::AvDevice* pBeBoBDevice = 0; 
    557     do { 
    558         ostringstream strstrm; 
    559         strstrm << "id" << i; 
    560         pBeBoBDevice = BeBoB::AvDevice::deserialize( 
    561             "BeBoB/" + strstrm.str() + "/", 
    562             deser, 
    563             *m_1394Service ); 
    564  
    565         ++i; 
    566         if ( pBeBoBDevice ) { 
    567             for (ConfigRomVector::iterator it = configRoms.begin(); 
    568                  it != configRoms.end(); 
    569                  ++it ) 
    570             { 
    571                 ConfigRom* pConfigRom = *it; 
    572  
    573                 if ( pBeBoBDevice->getConfigRom() == *pConfigRom ) { 
    574                     pBeBoBDevice->getConfigRom().setNodeId( pConfigRom->getNodeId() ); 
    575                     // m_avDevices.push_back( pBeBoBDevice ); 
    576  
    577                 } 
    578             } 
    579         } 
    580     } while ( pBeBoBDevice ); 
    581     #endif 
     557 
     558        Glib::ustring sFileName = getCachePath() + pConfigRom->getGuidString() + ".xml"; 
     559 
     560        if ( access( sFileName.c_str(),  R_OK ) == 0 ) { 
     561            debugOutput( DEBUG_LEVEL_NORMAL, "load from %s\n", sFileName.c_str() ); 
     562            Util::XMLDeserialize deser( sFileName ); 
     563 
     564            BeBoB::AvDevice* pBeBoBDevice = BeBoB::AvDevice::deserialize( "/", deser, *m_1394Service ); 
     565            if ( pBeBoBDevice ) { 
     566                debugOutput( DEBUG_LEVEL_NORMAL, "loadCache: could create valid bebob driver from %s\n", sFileName.c_str() ); 
     567                pBeBoBDevice->getConfigRom().setNodeId( pConfigRom->getNodeId() ); 
     568                m_avDevices.push_back( pBeBoBDevice ); 
     569            } 
     570        } 
     571 
     572        // throw away this config rom instance, the deserialize code has created it's own from 
     573        // the cache. 
     574        delete pConfigRom; 
     575    } 
    582576 
    583577    return true; 
  • trunk/libffado/src/devicemanager.h

    r445 r478  
    6969    unsigned int getAvDeviceCount(); 
    7070 
    71     bool saveCache( Glib::ustring fileName ); 
    72     bool loadCache( Glib::ustring fileName ); 
     71    bool buildCache(); 
     72    bool loadCache( Glib::ustring cachePath = "" ); 
    7373 
    7474    Streaming::StreamProcessor *getSyncSource(); 
     
    7878                                   int id ); 
    7979    IAvDevice* getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ) ); 
     80 
     81 
     82    Glib::ustring getCachePath(); 
     83    bool saveCache( IAvDevice* pAvDevice ); 
    8084 
    8185protected: 
  • trunk/libffado/src/libieee1394/configrom.cpp

    r462 r478  
    384384{ 
    385385    return m_guid; 
     386} 
     387 
     388const Glib::ustring 
     389ConfigRom::getGuidString() const 
     390{ 
     391    char* buf; 
     392    asprintf( &buf, "%08x%08x", 
     393              ( unsigned int ) ( getGuid() >> 32 ), 
     394              ( unsigned int ) ( getGuid() & 0xffffffff ) ); 
     395    Glib::ustring result = buf; 
     396    free( buf ); 
     397    return result; 
    386398} 
    387399 
  • trunk/libffado/src/libieee1394/configrom.h

    r445 r478  
    5252    const fb_nodeid_t getNodeId() const; 
    5353    const fb_octlet_t getGuid() const; 
     54    const Glib::ustring getGuidString() const; 
    5455    const Glib::ustring getModelName() const; 
    5556    const Glib::ustring getVendorName() const; 
  • trunk/libffado/src/Makefile.am

    r456 r478  
    173173        maudio/fwap.xml 
    174174 
     175install-data-hook: 
     176        mkdir -p $(localstatedir)/cache/libffado 
     177 
    175178# programs intended for installation in the 'bin' directory 
    176179#  generic 
  • trunk/libffado/src/ser.cpp

    r445 r478  
    2727#include <iostream> 
    2828 
    29 const char FileName[] = "serialize-test.xml"; 
     29const char FileName[] = "bebob.xml"; 
    3030 
    3131static bool 
    32 serialize( const char* pFileName, int port
     32serialize( const char* pFileName
    3333{ 
    3434    DeviceManager devMgr; 
    35     if (!devMgr.initialize( port )) { 
    36         std::cerr << "could not init DeviceManager" << std::endl; 
     35    if ( !devMgr.initialize( 0 ) ) 
    3736        return false; 
    38     } 
    39  
    40 //     devMgr.setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
    41  
    42     if (!devMgr.discover( )) { 
    43         std::cerr << "could not discover devices" << std::endl; 
     37    if ( !devMgr.discover() ) 
    4438        return false; 
    45     } 
    46     return devMgr.saveCache( pFileName ); 
     39    devMgr.setVerboseLevel( 4 ); 
     40    return devMgr.buildCache(); 
    4741} 
    4842 
     
    5145{ 
    5246    DeviceManager devMgr; 
    53     if (!devMgr.initialize( 0 )) { 
    54         std::cerr << "could not init DeviceManager" << std::endl; 
     47    if ( !devMgr.initialize( 0 ) ) 
    5548        return false; 
    56     } 
     49 
     50    devMgr.setVerboseLevel( 4 ); 
    5751    return devMgr.loadCache( pFileName ); 
    5852} 
     
    6155main(  int argc,  char** argv ) 
    6256{ 
    63     int port=0; 
    64     if (argc==2) { 
    65         port=atoi(argv[1]); 
    66     } 
    67  
    68     if ( !serialize( FileName, port ) ) { 
     57    if ( !serialize( FileName ) ) { 
    6958        std::cerr << "serializing failed" << std::endl; 
    7059        return -1;