Changeset 418 for branches

Show
Ignore:
Timestamp:
02/25/07 04:14:33 (17 years ago)
Author:
pieterpalmers
Message:

added serialization support to the OptionContainer?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/bebob/bebob_avdevice.cpp

    r416 r418  
    13721372        i++; 
    13731373    } 
     1374     
     1375    result &= serializeOptions( basePath + "Options", ser ); 
    13741376 
    13751377//     result &= ser.write( basePath + "m_id", id ); 
     
    14161418            } 
    14171419        } 
    1418  
    1419 //         result &= deser.read( basePath + "m_id", pDev->m_id ); 
     1420         
     1421        result &= deserializeOptions( basePath + "Options", deser, *pDev ); 
     1422 
    14201423    } 
    14211424 
  • branches/streaming-rework/src/libutil/OptionContainer.cpp

    r416 r418  
    2828 
    2929#include "OptionContainer.h" 
     30 
     31#include <iostream> 
     32#include <sstream> 
    3033 
    3134namespace FreebobUtil { 
     
    108111void OptionContainer::Option::set(int64_t v)     { m_intValue = v; m_Type=EInt;} 
    109112void OptionContainer::Option::set(uint64_t v)    { m_uintValue = v; m_Type=EUInt;} 
     113 
     114bool 
     115OptionContainer::Option::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
     116{ 
     117    bool result; 
     118    result  = ser.write( basePath + "m_Name", Glib::ustring(m_Name) ); 
     119    result &= ser.write( basePath + "m_stringValue", Glib::ustring(m_stringValue) ); 
     120    result &= ser.write( basePath + "m_boolValue", m_boolValue ); 
     121    result &= ser.write( basePath + "m_doubleValue", m_doubleValue ); 
     122    result &= ser.write( basePath + "m_intValue", m_intValue ); 
     123    result &= ser.write( basePath + "m_uintValue", m_uintValue ); 
     124    result &= ser.write( basePath + "m_Type", m_Type ); 
     125 
     126    return result; 
     127} 
     128 
     129 
     130OptionContainer::Option 
     131OptionContainer::Option::deserialize( Glib::ustring basePath, 
     132                     Util::IODeserialize& deser ) 
     133{ 
     134    bool result; 
     135    Option op=Option(); 
     136    Glib::ustring tmpstr; 
     137     
     138    result  = deser.read( basePath + "m_Name", tmpstr ); 
     139    op.m_Name = tmpstr; 
     140    result &= deser.read( basePath + "m_stringValue", tmpstr ); 
     141    op.m_stringValue = tmpstr; 
     142    result &= deser.read( basePath + "m_boolValue", op.m_boolValue ); 
     143    result &= deser.read( basePath + "m_doubleValue", op.m_doubleValue ); 
     144    result &= deser.read( basePath + "m_intValue", op.m_intValue ); 
     145    result &= deser.read( basePath + "m_uintValue", op.m_uintValue ); 
     146    result &= deser.read( basePath + "m_Type", op.m_Type ); 
     147 
     148    if(result) { 
     149        return op; 
     150    } else { 
     151        return Option(); 
     152    } 
     153} 
    110154 
    111155// ------------------------ 
     
    370414} 
    371415 
     416// serialization support 
     417 
     418bool 
     419OptionContainer::serializeOptions( Glib::ustring basePath, 
     420                                   Util::IOSerialize& ser) const 
     421{ 
     422    bool result = true; 
     423    int i = 0; 
     424 
     425    for ( OptionVector::const_iterator it = m_Options.begin(); 
     426          it != m_Options.end(); 
     427          ++it ) 
     428    { 
     429        const Option& pOption = *it; 
     430 
     431        std::ostringstream strstrm; 
     432        strstrm << basePath << "/" << "Option" << i; 
     433        result &= pOption.serialize( strstrm.str() + "/", ser ); 
     434        i++; 
     435    } 
     436 
     437    return result; 
     438} 
     439 
     440bool 
     441OptionContainer::deserializeOptions( Glib::ustring basePath, 
     442                                     Util::IODeserialize& deser, 
     443                                     OptionContainer& container) 
     444{ 
     445    int i = 0; 
     446    bool bFinished = false; 
     447    bool result=true; 
     448    do { 
     449        std::ostringstream strstrm; 
     450        strstrm << basePath << "/" << "Option" << i; 
     451         
     452        Option pOption = Option::deserialize( strstrm.str() + "/", 
     453                                              deser ); 
     454        if ( pOption.getType() != Option::EInvalid ) { 
     455            result &= container.addOption(pOption); 
     456            i++; 
     457        } else { 
     458            bFinished = true; 
     459        } 
     460    } while ( !bFinished ); 
     461 
     462    return result; 
     463} 
     464 
     465 
    372466} // end of namespace FreebobUtil 
  • branches/streaming-rework/src/libutil/OptionContainer.h

    r416 r418  
    2828 
    2929#include "../debugmodule/debugmodule.h" 
     30#include "libutil/serialize.h" 
    3031 
    3132#include <vector> 
     
    4041    public: 
    4142        enum EType { 
    42             EInvalid
    43             EString
    44             EBool
    45             EDouble
    46             EInt
    47             EUInt
     43            EInvalid = 0
     44            EString = 1
     45            EBool = 2
     46            EDouble = 3
     47            EInt = 4
     48            EUInt = 5
    4849        }; 
    4950     
     
    7374        int64_t getInt() {return m_intValue;}; 
    7475        uint64_t getUInt() {return m_uintValue;}; 
    75          
     76     
     77    public: // serialization support 
     78        bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
     79        static Option deserialize( Glib::ustring basePath, 
     80                                    Util::IODeserialize& deser); 
    7681    private: 
    7782        std::string m_Name; 
     
    148153        return(m_Options.end()); 
    149154    } 
    150      
     155 
     156protected: // serialization support 
     157    bool serializeOptions( Glib::ustring basePath,  
     158                           Util::IOSerialize& ser) const; 
     159    static bool deserializeOptions( Glib::ustring basePath, 
     160                                    Util::IODeserialize& deser, 
     161                                    OptionContainer& container); 
     162 
    151163private: 
    152164    int findOption(Option o); 
  • branches/streaming-rework/src/ser.cpp

    r417 r418  
    77 
    88static bool 
    9 serialize( const char* pFileName
     9serialize( const char* pFileName, int port
    1010{ 
    1111    DeviceManager devMgr; 
    12     if (!devMgr.initialize( 0 )) { 
     12    if (!devMgr.initialize( port )) { 
    1313        std::cerr << "could not init DeviceManager" << std::endl; 
    1414        return false; 
     
    3535main(  int argc,  char** argv ) 
    3636{ 
    37     if ( !serialize( FileName ) ) { 
     37    int port=0; 
     38    if (argc==2) { 
     39        port=atoi(argv[1]); 
     40    } 
     41     
     42    if ( !serialize( FileName, port ) ) { 
    3843        std::cerr << "serializing failed" << std::endl; 
    3944        return -1;