Changeset 630

Show
Ignore:
Timestamp:
09/08/07 09:19:40 (16 years ago)
Author:
wagi
Message:

Some more fixing of the cashing code. The loading is still disabled because it seems not to work right. But at least it doesn't crash anymore. Some further debugging is
needed.

Files:

Legend:

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

    r620 r630  
    5757                    std::auto_ptr< ConfigRom >( configRom ) ) 
    5858    : GenericAVC::AvDevice( ieee1394service, configRom ) 
    59     , m_Mixer ( NULL
     59    , m_Mixer ( 0
    6060{ 
    6161    debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::AvDevice (NodeID %d)\n", 
     
    6565AvDevice::~AvDevice() 
    6666{ 
    67     if(m_Mixer != NULL) { 
    68         delete m_Mixer; 
    69     } 
     67    delete m_Mixer; 
    7068} 
    7169 
     
    7876    GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_bebob.txt" ); 
    7977    if ( vendorModel.parse() ) { 
    80         vendorModel.printTable(); 
    8178        return vendorModel.isPresent( vendorId, modelId ); 
    8279    } 
     
    143140    // this removes the mixer if it already exists 
    144141    // note: a mixer self-registers to it's parent 
    145     if(m_Mixer != NULL) { 
    146         delete m_Mixer; 
    147     } 
    148  
    149 //      create the mixer & register it 
     142    delete m_Mixer; 
     143 
     144    // create the mixer & register it 
    150145    if(getAudioSubunit(0) == NULL) { 
    151146        debugWarning("Could not find audio subunit, mixer not available.\n"); 
    152         m_Mixer = NULL
     147        m_Mixer = 0
    153148    } else { 
    154149        m_Mixer = new Mixer(*this); 
     
    221216{ 
    222217    ExtendedStreamFormatCmd extStreamFormatCmd( *m_p1394Service ); 
    223     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 
    224                                      getNodeId() ); 
     218    UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 ); 
    225219    extStreamFormatCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input, 
    226220                                                    PlugAddress::ePAM_Unit, 
     
    335329} 
    336330 
    337  
    338 template <typename T> bool serializeVector( Glib::ustring path, 
    339                                             Util::IOSerialize& ser, 
    340                                             const T& vec ) 
    341 { 
    342     bool result = true; // if vec.size() == 0 
    343     int i = 0; 
    344     for ( typename T::const_iterator it = vec.begin(); it != vec.end(); ++it ) { 
    345         std::ostringstream strstrm; 
    346         strstrm << path << i; 
    347         result &= ( *it )->serialize( strstrm.str() + "/", ser ); 
    348         i++; 
    349     } 
    350     return result; 
    351 } 
    352  
    353 template <typename T, typename VT> bool deserializeVector( Glib::ustring path, 
    354                                                            Util::IODeserialize& deser, 
    355                                                            Unit& avDevice, 
    356                                                            VT& vec ) 
    357 { 
    358     int i = 0; 
    359     bool bFinished = false; 
    360     do { 
    361         std::ostringstream strstrm; 
    362         strstrm << path << i << "/"; 
    363         T* ptr = T::deserialize( strstrm.str(), 
    364                                  deser, 
    365                                  avDevice ); 
    366         if ( ptr ) { 
    367             vec.push_back( ptr ); 
    368             i++; 
    369         } else { 
    370             bFinished = true; 
    371         } 
    372     } while ( !bFinished ); 
    373  
    374     return true; 
    375 } 
    376  
    377331bool 
    378332AvDevice::serialize( Glib::ustring basePath, 
    379333                     Util::IOSerialize& ser ) const 
    380334{ 
    381  
    382335    bool result; 
    383     result  = m_pConfigRom->serialize( basePath + "m_pConfigRom/", ser ); 
    384     result &= ser.write( basePath + "m_verboseLevel", getDebugLevel() ); 
    385     result &= m_pPlugManager->serialize( basePath + "Plug", ser ); // serialize all av plugs 
    386     result &= serializeVector( basePath + "PlugConnection", ser, m_plugConnections ); 
    387     result &= serializeVector( basePath + "Subunit", ser, m_subunits ); 
    388     #warning broken at echoaudio merge 
    389     //result &= serializeSyncInfoVector( basePath + "SyncInfo", ser, m_syncInfos ); 
    390  
    391     int i = 0; 
    392     for ( SyncInfoVector::const_iterator it = m_syncInfos.begin(); 
    393           it != m_syncInfos.end(); 
    394           ++it ) 
    395     { 
    396         const SyncInfo& info = *it; 
    397         if ( m_activeSyncInfo == &info ) { 
    398             result &= ser.write( basePath + "m_activeSyncInfo",  i ); 
    399             break; 
    400         } 
    401         i++; 
    402     } 
    403  
    404     result &= serializeOptions( basePath + "Options", ser ); 
    405  
    406 //     result &= ser.write( basePath + "m_id", id ); 
    407  
     336    result  = GenericAVC::AvDevice::serialize( basePath, ser ); 
    408337    return result; 
    409338} 
    410339 
    411 AvDevice* 
     340bool 
    412341AvDevice::deserialize( Glib::ustring basePath, 
    413                        Util::IODeserialize& deser, 
    414                        Ieee1394Service& ieee1394Service ) 
    415 
    416  
    417 //     ConfigRom *configRom = 
    418 //         ConfigRom::deserialize( basePath + "m_pConfigRom/", deser, ieee1394Service ); 
    419 // 
    420 //     if ( !configRom ) { 
    421 //         return NULL; 
    422 //     } 
    423 // 
    424 //     AvDevice* pDev = new AvDevice( 
    425 //         std::auto_ptr<ConfigRom>(configRom), 
    426 //         ieee1394Service, getConfigRom().getNodeId()); 
    427 // 
    428 //     if ( pDev ) { 
    429 //         bool result; 
    430 //         int verboseLevel; 
    431 //         result  = deser.read( basePath + "m_verboseLevel", verboseLevel ); 
    432 //         setDebugLevel( verboseLevel ); 
    433 // 
    434 //         result &= AVC::Unit::deserialize(basePath, pDev, deser, ieee1394Service); 
    435 // 
    436 //         result &= deserializeOptions( basePath + "Options", deser, *pDev ); 
    437 //     } 
    438 // 
    439 //     return pDev; 
    440     return NULL; 
     342                       Util::IODeserialize& deser ) 
     343
     344    bool result; 
     345    result  = GenericAVC::AvDevice::deserialize( basePath, deser ); 
     346    return result; 
    441347} 
    442348 
     
    446352    Glib::ustring cachePath; 
    447353    char* pCachePath; 
    448     if ( asprintf( &pCachePath, "%s/cache/",  CACHEDIR ) < 0 ) { 
     354 
     355    string path = CACHEDIR; 
     356    if ( path.size() && path[0] == '~' ) { 
     357        path.erase( 0, 1 ); // remove ~ 
     358        path.insert( 0, getenv( "HOME" ) ); // prepend the home path 
     359    } 
     360 
     361    if ( asprintf( &pCachePath, "%s/cache/",  path.c_str() ) < 0 ) { 
    449362        debugError( "Could not create path string for cache pool (trying '/var/cache/libffado' instead)\n" ); 
    450363        cachePath == "/var/cache/libffado/"; 
     
    459372AvDevice::loadFromCache() 
    460373{ 
    461 /*    Glib::ustring sDevicePath = getCachePath() + m_pConfigRom->getGuidString(); 
     374    // XXX disable this part as long it is not correctly working 
     375    return false; 
     376 
     377    Glib::ustring sDevicePath = getCachePath() + m_pConfigRom->getGuidString(); 
    462378 
    463379    char* configId; 
     
    472388    debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", sFileName.c_str() ); 
    473389 
    474     Util::XMLDeserialize deser( sFileName, m_verboseLevel ); 
     390    struct stat buf; 
     391    if ( stat( sFileName.c_str(), &buf ) != 0 ) { 
     392        debugOutput( DEBUG_LEVEL_NORMAL,  "\"%s\" does not exist\n",  sFileName.c_str() ); 
     393        return false; 
     394    } else { 
     395        if ( !S_ISREG( buf.st_mode ) ) { 
     396            debugOutput( DEBUG_LEVEL_NORMAL,  "\"%s\" is not a regular file\n",  sFileName.c_str() ); 
     397            return false; 
     398        } 
     399    } 
     400 
     401    Util::XMLDeserialize deser( sFileName, getDebugLevel() ); 
    475402 
    476403    bool result = deserialize( "", deser ); 
     
    480407    } 
    481408 
    482     return result;*/ 
    483     return false; 
     409    return result; 
    484410} 
    485411 
     
    491417    string tmp_path = getCachePath() + m_pConfigRom->getGuidString(); 
    492418 
    493     // the following piece should do something like 'mkdir -p some/path/with/some/dirs/which/do/not/exist' 
     419    // the following piece should do something like 
     420    // 'mkdir -p some/path/with/some/dirs/which/do/not/exist' 
    494421    vector<string> tokens; 
    495422    tokenize( tmp_path, tokens, "/" ); 
     
    499426          ++it ) 
    500427    { 
    501         if ( path == "" ) { 
    502             if ( *it == "~" ) 
    503                 path = getenv( "HOME" ); 
    504             else 
    505                 path = *it; 
    506         } else { 
    507             path = path + "/" + *it; 
    508         } 
     428        path +=  "/" + *it; 
    509429 
    510430        struct stat buf; 
  • trunk/libffado/src/bebob/bebob_avdevice.h

    r584 r630  
    8787 
    8888public: 
    89     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    90     static AvDevice* deserialize( Glib::ustring basePath, 
    91                                   Util::IODeserialize& deser, 
    92                                   Ieee1394Service& ieee1394Service ); 
     89    virtual bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
     90    virtual bool deserialize( Glib::ustring basePath, Util::IODeserialize& deser ); 
     91 
    9392    int getConfigurationIdSampleRate(); 
    9493    int getConfigurationIdNumberOfChannel( AVC::PlugAddress::EPlugDirection ePlugDirection ); 
  • trunk/libffado/src/genericavc/avc_avdevice.cpp

    r612 r630  
    9696        unsigned int vendorId = m_pConfigRom->getNodeVendorId(); 
    9797        unsigned int modelId = m_pConfigRom->getModelId(); 
    98      
     98 
    9999        GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_genericavc.txt" ); 
    100100        if ( vendorModel.parse() ) { 
    101101            m_model = vendorModel.find( vendorId, modelId ); 
    102102        } 
    103      
     103 
    104104        if (!GenericAVC::VendorModel::isValid(m_model)) { 
    105105            return false; 
     
    591591} 
    592592 
    593 
     593bool 
     594AvDevice::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
     595
     596    bool result; 
     597    result  = AVC::Unit::serialize( basePath, ser ); 
     598    result &= serializeOptions( basePath + "Options", ser ); 
     599    return result; 
     600
     601 
     602bool 
     603AvDevice::deserialize( Glib::ustring basePath, Util::IODeserialize& deser ) 
     604
     605    bool result; 
     606    result = AVC::Unit::deserialize( basePath, deser ); 
     607    return result; 
     608
     609 
     610
  • trunk/libffado/src/genericavc/avc_avdevice.h

    r607 r630  
    5454    virtual bool discover(); 
    5555    static FFADODevice * createDevice( Ieee1394Service& ieee1394Service, 
    56                                         std::auto_ptr<ConfigRom>( configRom )); 
    57      
     56                                       std::auto_ptr<ConfigRom>( configRom )); 
     57 
     58    virtual bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
     59    virtual bool deserialize( Glib::ustring basePath, Util::IODeserialize& deser ); 
     60 
    5861    virtual void setVerboseLevel(int l); 
    5962    virtual void showDevice(); 
     
    7174    virtual bool startStreamByIndex(int i); 
    7275    virtual bool stopStreamByIndex(int i); 
    73      
     76 
    7477    // redefinition to resolve ambiguity 
    7578    virtual Ieee1394Service& get1394Service() 
    7679        { return FFADODevice::get1394Service(); }; 
    77     virtual ConfigRom& getConfigRom() const  
     80    virtual ConfigRom& getConfigRom() const 
    7881        { return FFADODevice::getConfigRom(); }; 
    79          
     82 
    8083protected: 
    8184    virtual bool addPlugToProcessor( AVC::Plug& plug, Streaming::StreamProcessor *processor, 
     
    8487                                   AVC::Plug::EPlugDirection direction, 
    8588                                   AVC::ESamplingFrequency samplingFrequency );*/ 
    86      
     89 
    8790    struct VendorModelEntry m_model; 
    88      
     91 
    8992    // streaming stuff 
    9093    typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector; 
    9194    StreamProcessorVector m_receiveProcessors; 
    9295    StreamProcessorVector m_transmitProcessors; 
    93      
     96 
    9497    DECLARE_DEBUG_MODULE; 
    9598}; 
  • trunk/libffado/src/libavc/general/avc_unit.cpp

    r618 r630  
    103103} 
    104104 
    105 Subunit*  
     105Subunit* 
    106106Unit::createSubunit(Unit& unit, 
    107107                    ESubunitType type, 
    108                     subunit_t id )  
     108                    subunit_t id ) 
    109109{ 
    110110    Subunit* s=NULL; 
     
    222222                return false; 
    223223            } 
    224              
     224 
    225225            subunit->setVerboseLevel(getDebugLevel()); 
    226              
     226 
    227227            if ( !subunit->discover() ) { 
    228228                debugError( "enumerateSubUnits: Could not discover " 
     
    236236                m_subunits.push_back( subunit ); 
    237237            } 
    238              
     238 
    239239            break; 
    240240        case eST_Music: 
     
    244244                return false; 
    245245            } 
    246              
     246 
    247247            subunit->setVerboseLevel(getDebugLevel()); 
    248              
     248 
    249249            if ( !subunit->discover() ) { 
    250250                debugError( "enumerateSubUnits: Could not discover " 
     
    633633 
    634634    } 
    635      
     635 
    636636    PlugVector syncExternalInputPlugs = getPlugsByType( m_externalPlugs, 
    637637                                                    Plug::eAPD_Input, 
     
    809809} 
    810810 
    811 template <typename T> bool serializeVector( Glib::ustring path, 
    812                                             Util::IOSerialize& ser, 
    813                                             const T& vec ) 
     811template <typename T> 
     812bool 
     813serializeVector( Glib::ustring path, 
     814                 Util::IOSerialize& ser, 
     815                 const T& vec ) 
    814816{ 
    815817    bool result = true; // if vec.size() == 0 
     
    824826} 
    825827 
    826 template <typename T, typename VT> bool deserializeVector( Glib::ustring path, 
    827                                                            Util::IODeserialize& deser, 
    828                                                            Unit& unit, 
    829                                                            VT& vec ) 
     828template <typename T, typename VT> 
     829bool 
     830deserializeVector( Glib::ustring path, 
     831                   Util::IODeserialize& deser, 
     832                   Unit& unit, 
     833                   VT& vec ) 
    830834{ 
    831835    int i = 0; 
     
    850854bool 
    851855Unit::serializeSyncInfoVector( Glib::ustring basePath, 
    852                                    Util::IOSerialize& ser, 
    853                                    const SyncInfoVector& vec ) 
     856                               Util::IOSerialize& ser, 
     857                               const SyncInfoVector& vec ) const 
    854858{ 
    855859    bool result = true; 
     
    877881bool 
    878882Unit::deserializeSyncInfoVector( Glib::ustring basePath, 
    879                                      Util::IODeserialize& deser, 
    880                                      SyncInfoVector& vec ) 
     883                                 Util::IODeserialize& deser, 
     884                                 SyncInfoVector& vec ) 
    881885{ 
    882886    int i = 0; 
     
    933937bool 
    934938Unit::serialize( Glib::ustring basePath, 
    935                      Util::IOSerialize& ser ) const 
    936 
    937  
     939                 Util::IOSerialize& ser ) const 
     940
    938941    bool result; 
    939942    result  = ser.write( basePath + "m_verboseLevel_unit", getDebugLevel() ); 
     943    result &= serializeVector( basePath + "Subunit", ser, m_subunits ); 
     944    result &= serializeVector( basePath + "plugConnections", ser, m_plugConnections ); 
    940945    result &= m_pPlugManager->serialize( basePath + "Plug", ser ); // serialize all av plugs 
    941     result &= serializeVector( basePath + "PlugConnection", ser, m_plugConnections ); 
    942     result &= serializeVector( basePath + "Subunit", ser, m_subunits ); 
    943 #warning this fails after the echoaudio merge 
    944 //     result &= serializeSyncInfoVector( basePath + "SyncInfo", ser, m_syncInfos ); 
    945      
     946    result &= serializeSyncInfoVector( basePath + "SyncInfo", ser, m_syncInfos ); 
     947 
    946948    int i = 0; 
    947949    for ( SyncInfoVector::const_iterator it = m_syncInfos.begin(); 
     
    962964bool 
    963965Unit::deserialize( Glib::ustring basePath, 
    964                    Util::IODeserialize& deser, 
    965                    Ieee1394Service& ieee1394Service ) 
     966                   Util::IODeserialize& deser ) 
    966967{ 
    967968    bool result; 
    968      
     969 
    969970    int verboseLevel; 
    970971    result  = deser.read( basePath + "m_verboseLevel_unit", verboseLevel ); 
    971972    setDebugLevel( verboseLevel ); 
    972      
    973     if (m_pPlugManager) delete m_pPlugManager; 
     973 
     974    result &= deserializeVector<Subunit>( basePath + "Subunit", deser, *this,  m_subunits ); 
     975 
     976    if (m_pPlugManager) 
     977        delete m_pPlugManager; 
     978 
    974979    m_pPlugManager = PlugManager::deserialize( basePath + "Plug", deser, *this ); 
    975     if ( !m_pPlugManager ) { 
    976         return false; 
    977     } 
    978      
     980 
     981    if ( !m_pPlugManager ) 
     982        return false; 
     983 
    979984    result &= deserializePlugUpdateConnections( basePath + "Plug", deser, m_pcrPlugs ); 
    980985    result &= deserializePlugUpdateConnections( basePath + "Plug", deser, m_externalPlugs ); 
     
    983988    result &= deserializeSyncInfoVector( basePath + "SyncInfo", deser, m_syncInfos ); 
    984989 
    985  
    986990    unsigned int i; 
    987991    result &= deser.read( basePath + "m_activeSyncInfo", i ); 
  • trunk/libffado/src/libavc/general/avc_unit.h

    r560 r630  
    6060    /// Returns the ConfigRom 
    6161    virtual ConfigRom& getConfigRom() const = 0; 
    62      
     62 
    6363    /// Discovers the unit's internals 
    6464    virtual bool discover(); 
     
    9090    virtual const SyncInfo* getActiveSyncInfo() const 
    9191        { return m_activeSyncInfo; } 
    92          
     92 
    9393    virtual bool setActiveSync( const SyncInfo& syncInfo ); 
    9494 
    95     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    96     bool deserialize( Glib::ustring basePath, 
    97                                  Util::IODeserialize& deser, 
    98                                  Ieee1394Service& ieee1394Service ); 
     95    virtual bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
     96    virtual bool deserialize( Glib::ustring basePath, Util::IODeserialize& deser ); 
     97 
    9998    SubunitAudio* getAudioSubunit( subunit_id_t subunitId ) 
    10099        { return dynamic_cast<SubunitAudio*>( 
     
    133132                                           std::string syncDescription ); 
    134133    virtual Plug* getSyncPlug( int maxPlugId, Plug::EPlugDirection ); 
    135      
     134 
    136135    unsigned int getNrOfSubunits( subunit_type_t subunitType ) const; 
    137136    PlugConnection* getPlugConnection( Plug& srcPlug ) const; 
     
    152151 
    153152    bool serializeSyncInfoVector( Glib::ustring basePath, 
    154                                          Util::IOSerialize& ser, 
    155                                          const SyncInfoVector& vec )
     153                                  Util::IOSerialize& ser, 
     154                                  const SyncInfoVector& vec ) const
    156155    bool deserializeSyncInfoVector( Glib::ustring basePath, 
    157                                            Util::IODeserialize& deser, 
    158                                            SyncInfoVector& vec ); 
     156                                    Util::IODeserialize& deser, 
     157                                    SyncInfoVector& vec ); 
    159158protected: 
    160159    SubunitVector             m_subunits; 
  • trunk/libffado/src/libutil/cmd_serialize.cpp

    r618 r630  
    4141CoutSerializer::write( byte_t d, const char* name ) 
    4242{ 
    43     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:        0x%02x %40s\n", m_cnt, d, name ); 
     43    debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:        0x%02x %-40.40s\n", m_cnt, d, name ); 
    4444    m_cnt += sizeof( byte_t ); 
    4545 
     
    5050CoutSerializer::write( uint16_t d, const char* name ) 
    5151{ 
    52     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:    0x%04x %40s\n", m_cnt, d, name ); 
     52    debugOutput( DEBUG_LEVEL_NORMAL, "  %3d:    0x%04x %-40.40s\n", m_cnt, d, name ); 
    5353    m_cnt += sizeof( uint16_t ); 
    5454 
     
    5959CoutSerializer::write( quadlet_t d, const char* name ) 
    6060{ 
    61     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d: 0x%08x %40s\n", m_cnt, d, name ); 
     61    debugOutput( DEBUG_LEVEL_NORMAL, "  %3d: 0x%08x %-40.40s\n", m_cnt, d, name ); 
    6262    m_cnt += sizeof( quadlet_t ); 
    6363    return true; 
     
    6767CoutSerializer::write( const char * v, size_t len, const char* name ) 
    6868{ 
    69     debugOutput( DEBUG_LEVEL_NORMAL, "  %3d: %s %40s\n", m_cnt, v, name ); 
     69    debugOutput( DEBUG_LEVEL_NORMAL, "  %3d: %s %-40.40s\n", m_cnt, v, name ); 
    7070    m_cnt += len; 
    7171    return true; 
     
    145145    byte_t hi = (value & 0xFF00) >> 8; 
    146146    byte_t lo = value & 0xFF; 
    147      
     147 
    148148    bool result = false; 
    149149    if ( isCurPosValid() ) {