Changeset 490

Show
Ignore:
Timestamp:
07/09/07 13:00:22 (14 years ago)
Author:
wagi
Message:

saveCache: create save path "PATH_TO_CACHE + GUID + CONFIGURATION_ID"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/devicemanager.cpp

    r478 r490  
    3131#include "libieee1394/ieee1394service.h" 
    3232 
     33#include "libstreaming/StreamProcessor.h" 
     34 
    3335#include "debugmodule/debugmodule.h" 
     36 
     37#ifdef ENABLE_BEBOB 
     38#include "bebob/bebob_avdevice.h" 
     39#include "maudio/maudio_avdevice.h" 
     40#endif 
     41 
     42#ifdef ENABLE_BOUNCE 
     43#include "bounce/bounce_avdevice.h" 
     44#include "bounce/bounce_slave_avdevice.h" 
     45#endif 
     46 
     47#ifdef ENABLE_MOTU 
     48#include "motu/motu_avdevice.h" 
     49#endif 
     50 
     51#ifdef ENABLE_RME 
     52#include "rme/rme_avdevice.h" 
     53#endif 
     54 
     55#ifdef ENABLE_DICE 
     56#include "dice/dice_avdevice.h" 
     57#endif 
     58 
     59#ifdef ENABLE_METRIC_HALO 
     60#include "metrichalo/mh_avdevice.h" 
     61#endif 
    3462 
    3563#include <iostream> 
    3664#include <sstream> 
    37  
    3865#include <unistd.h> 
    39  
    40 #include "libstreaming/StreamProcessor.h" 
    41  
    42 #ifdef ENABLE_BEBOB 
    43     #include "bebob/bebob_avdevice.h" 
    44     #include "maudio/maudio_avdevice.h" 
    45 #endif 
    46  
    47 #ifdef ENABLE_BOUNCE 
    48     #include "bounce/bounce_avdevice.h" 
    49     #include "bounce/bounce_slave_avdevice.h" 
    50 #endif 
    51  
    52 #ifdef ENABLE_MOTU 
    53 #include "motu/motu_avdevice.h" 
    54 #endif 
    55  
    56 #ifdef ENABLE_RME 
    57 #include "rme/rme_avdevice.h" 
    58 #endif 
    59  
    60 #ifdef ENABLE_DICE 
    61 #include "dice/dice_avdevice.h" 
    62 #endif 
    63  
    64 #ifdef ENABLE_METRIC_HALO 
    65 #include "metrichalo/mh_avdevice.h" 
    66 #endif 
     66#include <sys/stat.h> 
    6767 
    6868using namespace std; 
     
    494494    { 
    495495        IAvDevice* pAvDevice = *it; 
    496  
    497         BeBoB::AvDevice* pBeBoBDevice = reinterpret_cast< BeBoB::AvDevice* >( pAvDevice ); 
    498         if ( pBeBoBDevice ) { 
    499             result &= saveCache( pBeBoBDevice ); 
    500         } 
     496        result &= saveCache( pAvDevice ); 
    501497    } 
    502498 
     
    509505    Glib::ustring cachePath; 
    510506    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/"; 
     507    if ( asprintf( &pCachePath, "%s/cache/libffado/",  CACHEDIR ) < 0 ) { 
     508        debugError( "Could not create path string for cache pool (trying '/var/cache/libffado' instead)\n" ); 
     509        cachePath == "/var/cache/libffado/"; 
    514510    } else { 
    515511        cachePath = pCachePath; 
     
    522518DeviceManager::saveCache( IAvDevice* pAvDevice ) 
    523519{ 
     520    // so far only BeBoB based devices needed a cache for speed up. 
    524521    BeBoB::AvDevice* pBeBoBDevice = reinterpret_cast<BeBoB::AvDevice*>( pAvDevice ); 
    525522    if ( !pBeBoBDevice ) { 
     
    527524    } 
    528525 
    529     Glib::ustring sFileName = getCachePath() + pAvDevice->getConfigRom().getGuidString() + ".xml"; 
     526    // the path looks like this: 
     527    // PATH_TO_CACHE + GUID + CONFIGURATION_ID 
     528 
     529    Glib::ustring sDevicePath = getCachePath() + pAvDevice->getConfigRom().getGuidString(); 
     530    struct stat buf; 
     531    if ( stat( sDevicePath.c_str(), &buf ) == 0 ) { 
     532        if ( !S_ISDIR( buf.st_mode ) ) { 
     533            debugError( "\"%s\" is not a directory\n",  sDevicePath.c_str() ); 
     534            return false; 
     535        } 
     536    } else { 
     537        if (  mkdir( sDevicePath.c_str(), S_IRWXU | S_IRWXG ) != 0 ) { 
     538            debugError( "Could not create \"%s\" directory\n", sDevicePath.c_str() ); 
     539            return false; 
     540        } 
     541    } 
     542 
     543    char* configId; 
     544    asprintf(&configId, "%08x", pBeBoBDevice->getConfigurationId() ); 
     545    if ( !configId ) { 
     546        debugError( "Could not create id string\n" ); 
     547        return false; 
     548    } 
     549    Glib::ustring sFileName = sDevicePath + "/" + configId + ".xml"; 
     550    free( configId ); 
    530551    debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", sFileName.c_str() ); 
    531552