Changeset 82

Show
Ignore:
Timestamp:
03/30/05 11:36:28 (19 years ago)
Author:
wagi
Message:

Moved from old style string handling to c++ style for getModelName and getVendorName in ConfigRom?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/freebob/src/avdevice.cpp

    r80 r82  
    3232#define AVC1394_GET_RESPONSE_OPERAND(x, n) (((x) & (0xFF000000 >> (((n)%4)*8))) >> (((3-(n))%4)*8)) 
    3333 
    34 AvDevice::AvDevice(const char* modelName, octlet_t oGuid) 
    35     : m_iNodeId( -1 ) 
     34AvDevice::AvDevice(ConfigRom& configRom) 
     35    : m_configRom( ConfigRom( configRom ) ) 
     36    , m_iNodeId( -1 ) 
    3637    , m_iPort( -1 ) 
    3738    , m_bInitialised( false ) 
    38     , m_oGuid( oGuid ) 
    3939    , m_iGeneration( 0 ) 
    4040    , cSubUnits( 0 ) 
     
    4545    , m_iNbExtDestinationPlugs( 0 ) 
    4646    , m_iNbExtSourcePlugs( 0 ) 
    47     , m_modelName( modelName ) 
    4847{ 
    4948    setDebugLevel( DEBUG_LEVEL_MODERATE ); 
  • trunk/freebob/src/avdevice.h

    r80 r82  
     1 
    12/* avdevice.h 
    23 * Copyright (C) 2004 by Daniel Wagner, Pieter Palmers 
     
    2425#include "ieee1394service.h" 
    2526#include "debugmodule.h" 
     27#include "configrom.h" 
    2628 
    2729#include <libxml/tree.h> 
     
    4143    }; 
    4244 
    43     AvDevice( const char* modelName, octlet_t oGuid ); 
     45    AvDevice( ConfigRom& configRom); 
    4446    virtual ~AvDevice(); 
    4547 
     
    5153        { m_iPort = iPort; } 
    5254    octlet_t getGuid() 
    53         { return m_oGuid; } 
    54     const char* getModelName() const 
    55         { return m_modelName; } 
     55        { return m_configRom.getGuid(); } 
     56    const std::string getVendorName() const 
     57        { return m_configRom.getVendorName(); } 
     58    const std::string getModelName() const 
     59        { return m_configRom.getModelName(); } 
     60 
    5661 
    5762    void execute( EStates state ); 
     
    9196 
    9297 protected: 
    93        AvDeviceSubunit *getSubunit(unsigned char type, unsigned char id); 
     98    AvDeviceSubunit *getSubunit(unsigned char type, unsigned char id); 
    9499 
    95        FBReturnCodes create1394RawHandle(); 
    96        FBReturnCodes enumerateSubUnits(); 
     100    FBReturnCodes create1394RawHandle(); 
     101    FBReturnCodes enumerateSubUnits(); 
    97102  
    98103 private: 
     104    ConfigRom m_configRom; 
    99105    int m_iNodeId; 
    100106    int m_iPort; 
  • trunk/freebob/src/cmhandler.cpp

    r80 r82  
    129129    xmlDocSetRootElement( doc,  rootNode ); 
    130130 
    131     char* res; 
    132     if ( asprintf( &res, 
    133                    "Connecton Informaton for %s configuration", 
    134                    pAvDevice->getModelName() ) < 0) 
    135     { 
    136         debugError( "Could't format string\n" ); 
    137         xmlFreeDoc( doc ); 
    138         xmlCleanupParser(); 
    139         return 0; 
    140     } 
     131    std::string res = "Connection Information for " 
     132                      + pAvDevice->getVendorName() 
     133                      +", " 
     134                      + pAvDevice->getModelName() 
     135                      + " configuration"; 
    141136    if ( !xmlNewChild( rootNode, 
    142137                       0, 
    143138                       BAD_CAST "Comment", 
    144                        BAD_CAST res ) ) { 
     139                       BAD_CAST res.c_str() ) ) { 
    145140        debugError( "Couldn't create comment node\n" ); 
    146141        xmlFreeDoc( doc ); 
  • trunk/freebob/src/configrom.cpp

    r80 r82  
    5050    , m_iNodeId( iNodeId ) 
    5151    , m_bAvcDevice( false ) 
    52     , m_vendorName( 0
    53     , m_modelName( 0
     52    , m_vendorName( ""
     53    , m_modelName( ""
    5454    , m_vendorNameKv( 0 ) 
    5555    , m_modelNameKv( 0 ) 
     
    5959ConfigRom::~ConfigRom() 
    6060{ 
    61     delete m_vendorName; 
    62     m_vendorName = 0; 
    63     delete m_modelName; 
    64     m_modelName = 0; 
    65     if ( m_vendorNameKv ) { 
    66         csr1212_release_keyval( m_vendorNameKv ); 
    67     } 
    68     if ( m_modelNameKv ) { 
    69         csr1212_release_keyval( m_modelNameKv ); 
    70     } 
    71     if ( m_csr ) { 
    72         csr1212_destroy_csr(m_csr); 
    73     } 
    7461} 
    7562 
     
    9784    if ( m_vendorNameKv ) { 
    9885        int len = ( m_vendorNameKv->value.leaf.len - 2 ) * sizeof( quadlet_t ); 
    99         m_vendorName = new char[len]; 
    100         memcpy( m_vendorName, 
     86        char* vendorName = new char[len]; 
     87        memcpy( vendorName, 
    10188                ( void* )CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA( m_vendorNameKv ), 
    10289                len ); 
    103         m_vendorName[len] = '\0'; 
    104         printf( "Vendor name: %s\n", m_vendorName ); 
     90        vendorName[len] = '\0'; 
     91        printf( "Vendor name: %s\n", vendorName ); 
     92        m_vendorName = vendorName; 
    10593    } 
    10694    if ( m_modelNameKv ) { 
    10795        int len = ( m_modelNameKv->value.leaf.len - 2 ) * sizeof( quadlet_t ); 
    108         m_modelName = new char[len]; 
    109         memcpy( m_modelName, 
     96        char* modelName = new char[len]; 
     97        memcpy( modelName, 
    11098                ( void* )CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA( m_modelNameKv ), 
    11199                len ); 
    112         m_modelName[len] = '\0'; 
    113         printf( "Model name: %s\n", m_modelName ); 
     100        modelName[len] = '\0'; 
     101        printf( "Model name: %s\n", modelName ); 
     102        m_modelName = modelName; 
    114103    } 
    115104 
     
    117106              | CSR1212_BE32_TO_CPU(m_csr->bus_info_data[4]); 
    118107 
     108    if ( m_vendorNameKv ) { 
     109        csr1212_release_keyval( m_vendorNameKv ); 
     110        m_vendorNameKv = 0; 
     111    } 
     112    if ( m_modelNameKv ) { 
     113        csr1212_release_keyval( m_modelNameKv ); 
     114        m_modelNameKv = 0; 
     115    } 
     116    if ( m_csr ) { 
     117        csr1212_destroy_csr(m_csr); 
     118        m_csr = 0; 
     119    } 
    119120    return true; 
    120121} 
     
    286287} 
    287288 
    288 const char* 
     289const std::string 
    289290ConfigRom::getModelName() const 
    290291{ 
     
    292293} 
    293294 
    294 const char* 
     295const std::string 
    295296ConfigRom::getVendorName() const 
    296297{ 
  • trunk/freebob/src/configrom.h

    r80 r82  
    2121#define CONFIGROM_H 
    2222 
     23#include <string> 
     24 
    2325#include <libraw1394/raw1394.h> 
    2426#include "csr1212.h" 
     27 
    2528 
    2629class ConfigRom { 
     
    3336    const bool isAvcDevice() const; 
    3437    const octlet_t getGuid() const; 
    35     const char* getModelName() const; 
    36     const char* getVendorName() const; 
     38    const std::string getModelName() const; 
     39    const std::string getVendorName() const; 
    3740 
    3841protected: 
     
    4851    bool m_bAvcDevice; 
    4952    octlet_t m_guid; 
    50     char* m_vendorName; 
    51     char* m_modelName; 
     53    std::string m_vendorName; 
     54    std::string m_modelName; 
     55 
     56    /* only used during parsing */ 
    5257    struct csr1212_keyval* m_vendorNameKv; 
    5358    struct csr1212_keyval* m_modelNameKv; 
  • trunk/freebob/src/ieee1394service.cpp

    r80 r82  
    145145                octlet_t oGuid = configRom.getGuid(); 
    146146 
    147                 AvDevice* pAvDevice = new AvDevice( configRom.getModelName(), oGuid ); 
     147                AvDevice* pAvDevice = new AvDevice( configRom ); 
    148148                if ( !pAvDevice ) { 
    149149                    debugError( "Could not create AvDevice instance for "