Changeset 372
- Timestamp:
- 01/07/07 07:08:53 (16 years ago)
- Files:
-
- trunk/libfreebob/src/bebob/bebob_avdevice.cpp (modified) (3 diffs)
- trunk/libfreebob/src/bebob/bebob_avdevice.h (modified) (1 diff)
- trunk/libfreebob/src/bebob/bebob_avplug.cpp (modified) (5 diffs)
- trunk/libfreebob/src/bebob/bebob_avplug.h (modified) (6 diffs)
- trunk/libfreebob/src/libutil/serialize.cpp (modified) (1 diff)
- trunk/libfreebob/src/libutil/serialize.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libfreebob/src/bebob/bebob_avdevice.cpp
r371 r372 1273 1273 } 1274 1274 1275 static bool 1276 deserializeUpdatePlugs( Glib::ustring basePath, 1277 Util::IODeserialize& deser, 1278 AvPlugVector& vec ) 1279 { 1280 bool result = true; 1281 for ( AvPlugVector::iterator it = vec.begin(); 1282 it != vec.end(); 1283 ++it ) 1284 { 1285 AvPlug* pPlug = *it; 1286 result &= pPlug->deserializeUpdate( basePath, deser ); 1287 } 1288 return result; 1289 } 1290 1275 1291 bool 1276 1292 AvDevice::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) … … 1287 1303 return result; 1288 1304 } 1289 1290 1305 1291 1306 AvDevice* … … 1311 1326 result &= deserializeVector<AvPlug>( basePath + "PCRPlug", deser, ieee1394Service, *pDev->m_pConfigRom.get(), pDev->m_plugManager, pDev->m_pcrPlugs ); 1312 1327 result &= deserializeVector<AvPlug>( basePath + "ExternalPlug", deser, ieee1394Service, *pDev->m_pConfigRom.get(), pDev->m_plugManager, pDev->m_externalPlugs ); 1328 result &= deserializeUpdatePlugs( basePath + "PCRPlug", deser, pDev->m_pcrPlugs ); 1329 result &= deserializeUpdatePlugs( basePath + "ExternalPlug", deser, pDev->m_externalPlugs ); 1330 1313 1331 1314 1332 // XXX ... trunk/libfreebob/src/bebob/bebob_avdevice.h
r371 r372 147 147 protected: 148 148 std::auto_ptr<ConfigRom>( m_pConfigRom ); 149 Ieee1394Service* m_1394Service; 150 int m_verboseLevel; 151 152 AvPlugVector m_pcrPlugs; 153 AvPlugVector m_externalPlugs; 154 155 AvPlugConnectionVector m_plugConnections; 156 157 AvDeviceSubunitVector m_subunits; 158 159 AvPlugManager m_plugManager; 160 161 SyncInfoVector m_syncInfos; 162 SyncInfo* m_activeSyncInfo; 163 164 unsigned int m_id; 149 Ieee1394Service* m_1394Service; 150 int m_verboseLevel; 151 AvPlugVector m_pcrPlugs; 152 AvPlugVector m_externalPlugs; 153 AvPlugConnectionVector m_plugConnections; 154 AvDeviceSubunitVector m_subunits; 155 AvPlugManager m_plugManager; 156 SyncInfoVector m_syncInfos; 157 SyncInfo* m_activeSyncInfo; 158 unsigned int m_id; 165 159 166 160 // streaming stuff trunk/libfreebob/src/bebob/bebob_avplug.cpp
r371 r372 24 24 #include "libfreebobavc/ieee1394service.h" 25 25 #include "libfreebobavc/avc_serialize.h" 26 27 #include <sstream> 26 28 27 29 namespace BeBoB { … … 1432 1434 1433 1435 bool 1434 AvPlug::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) 1436 AvPlug::serializeChannelInfos( Glib::ustring basePath, 1437 Util::IOSerialize& ser, 1438 const ClusterInfo& clusterInfo ) const 1439 { 1440 bool result = true; 1441 int i = 0; 1442 for ( ChannelInfoVector::const_iterator it = clusterInfo.m_channelInfos.begin(); 1443 it != clusterInfo.m_channelInfos.end(); 1444 ++it ) 1445 { 1446 const ChannelInfo& info = *it; 1447 std::ostringstream strstrm; 1448 strstrm << basePath << i; 1449 1450 result &= ser.write( strstrm.str() + "/m_streamPosition", info.m_streamPosition ); 1451 result &= ser.write( strstrm.str() + "/m_location", info.m_location ); 1452 result &= ser.write( strstrm.str() + "/m_name", info.m_name ); 1453 } 1454 1455 return result; 1456 } 1457 1458 bool 1459 AvPlug::deserializeChannelInfos( Glib::ustring basePath, 1460 Util::IODeserialize& deser, 1461 ClusterInfo& clusterInfo ) 1462 { 1463 int i = 0; 1464 bool bFinished = false; 1465 bool result = true; 1466 do { 1467 std::ostringstream strstrm; 1468 strstrm << basePath << i; 1469 1470 // check for one element to exist. when one exist the other elements 1471 // must also be there. otherwise just return (last) result. 1472 if ( deser.isExisting( strstrm.str() + "/m_streamPosition" ) ) { 1473 ChannelInfo info; 1474 1475 result &= deser.read( strstrm.str() + "/m_streamPosition", info.m_streamPosition ); 1476 result &= deser.read( strstrm.str() + "/m_location", info.m_location ); 1477 result &= deser.read( strstrm.str() + "/m_name", info.m_name ); 1478 1479 if ( result ) { 1480 clusterInfo.m_channelInfos.push_back( info ); 1481 i++; 1482 } else { 1483 bFinished = true; 1484 } 1485 } else { 1486 bFinished = true; 1487 } 1488 } while ( !bFinished ); 1489 1490 return result; 1491 } 1492 1493 1494 bool 1495 AvPlug::serializeClusterInfos( Glib::ustring basePath, 1496 Util::IOSerialize& ser ) const 1497 { 1498 bool result = true; 1499 int i = 0; 1500 for ( ClusterInfoVector::const_iterator it = m_clusterInfos.begin(); 1501 it != m_clusterInfos.end(); 1502 ++it ) 1503 { 1504 const ClusterInfo& info = *it; 1505 std::ostringstream strstrm; 1506 strstrm << basePath << i; 1507 1508 result &= ser.write( strstrm.str() + "/m_index", info.m_index ); 1509 result &= ser.write( strstrm.str() + "/m_portType", info.m_portType ); 1510 result &= ser.write( strstrm.str() + "/m_name", info.m_name ); 1511 result &= ser.write( strstrm.str() + "/m_nrOfChannels", info.m_nrOfChannels ); 1512 result &= serializeChannelInfos( strstrm.str() + "/m_channelInfo", ser, info ); 1513 result &= ser.write( strstrm.str() + "/m_streamFormat", info.m_streamFormat ); 1514 1515 } 1516 1517 return result; 1518 } 1519 1520 bool 1521 AvPlug::deserializeClusterInfos( Glib::ustring basePath, 1522 Util::IODeserialize& deser ) 1523 { 1524 int i = 0; 1525 bool bFinished = false; 1526 bool result = true; 1527 do { 1528 std::ostringstream strstrm; 1529 strstrm << basePath << i; 1530 1531 // check for one element to exist. when one exist the other elements 1532 // must also be there. otherwise just return (last) result. 1533 if ( deser.isExisting( strstrm.str() + "/m_index" ) ) { 1534 ClusterInfo info; 1535 1536 result &= deser.read( strstrm.str() + "/m_index", info.m_index ); 1537 result &= deser.read( strstrm.str() + "/m_portType", info.m_portType ); 1538 result &= deser.read( strstrm.str() + "/m_name", info.m_name ); 1539 result &= deser.read( strstrm.str() + "/m_nrOfChannels", info.m_nrOfChannels ); 1540 result &= deserializeChannelInfos( strstrm.str() + "/m_channelInfo", deser, info ); 1541 result &= deser.read( strstrm.str() + "/m_streamFormat", info.m_streamFormat ); 1542 1543 if ( result ) { 1544 m_clusterInfos.push_back( info ); 1545 i++; 1546 } else { 1547 bFinished = true; 1548 } 1549 } else { 1550 bFinished = true; 1551 } 1552 } while ( !bFinished ); 1553 1554 return result; 1555 } 1556 1557 1558 bool 1559 AvPlug::serializeFormatInfos( Glib::ustring basePath, 1560 Util::IOSerialize& ser ) const 1561 { 1562 bool result = true; 1563 int i = 0; 1564 for ( FormatInfoVector::const_iterator it = m_formatInfos.begin(); 1565 it != m_formatInfos.end(); 1566 ++it ) 1567 { 1568 const FormatInfo& info = *it; 1569 std::ostringstream strstrm; 1570 strstrm << basePath << i; 1571 1572 result &= ser.write( strstrm.str() + "/m_samplingFrequency", info.m_samplingFrequency ); 1573 result &= ser.write( strstrm.str() + "/m_isSyncStream", info.m_isSyncStream ); 1574 result &= ser.write( strstrm.str() + "/m_audioChannels", info.m_audioChannels ); 1575 result &= ser.write( strstrm.str() + "/m_midiChannels", info.m_midiChannels ); 1576 result &= ser.write( strstrm.str() + "/m_index", info.m_index ); 1577 } 1578 return result; 1579 } 1580 1581 bool 1582 AvPlug::deserializeFormatInfos( Glib::ustring basePath, 1583 Util::IODeserialize& deser ) 1584 { 1585 int i = 0; 1586 bool bFinished = false; 1587 bool result = true; 1588 do { 1589 std::ostringstream strstrm; 1590 strstrm << basePath << i; 1591 1592 // check for one element to exist. when one exist the other elements 1593 // must also be there. otherwise just return (last) result. 1594 if ( deser.isExisting( strstrm.str() + "/m_samplingFrequency" ) ) { 1595 FormatInfo info; 1596 1597 result &= deser.read( strstrm.str() + "/m_samplingFrequency", info.m_samplingFrequency ); 1598 result &= deser.read( strstrm.str() + "/m_isSyncStream", info.m_isSyncStream ); 1599 result &= deser.read( strstrm.str() + "/m_audioChannels", info.m_audioChannels ); 1600 result &= deser.read( strstrm.str() + "/m_midiChannels", info.m_midiChannels ); 1601 result &= deser.read( strstrm.str() + "/m_index", info.m_index ); 1602 1603 if ( result ) { 1604 m_formatInfos.push_back( info ); 1605 i++; 1606 } else { 1607 bFinished = true; 1608 } 1609 } else { 1610 bFinished = true; 1611 } 1612 } while ( !bFinished ); 1613 1614 return result; 1615 } 1616 1617 1618 bool 1619 AvPlug::serializeAvPlugVector( Glib::ustring basePath, 1620 Util::IOSerialize& ser, 1621 const AvPlugVector& vec) const 1622 { 1623 bool result = true; 1624 int i = 0; 1625 for ( AvPlugVector::const_iterator it = vec.begin(); 1626 it != vec.end(); 1627 ++it ) 1628 { 1629 const AvPlug* pPlug = *it; 1630 std::ostringstream strstrm; 1631 strstrm << basePath << i; 1632 1633 result &= ser.write( strstrm.str() + "/global_id", pPlug->getGlobalId() ); 1634 } 1635 return result; 1636 } 1637 1638 bool 1639 AvPlug::deserializeAvPlugVector( Glib::ustring basePath, 1640 Util::IODeserialize& deser, 1641 AvPlugVector& vec ) 1642 { 1643 int i = 0; 1644 bool bFinished = false; 1645 bool result = true; 1646 do { 1647 std::ostringstream strstrm; 1648 strstrm << basePath << i; 1649 1650 // check for one element to exist. when one exist the other elements 1651 // must also be there. otherwise just return (last) result. 1652 if ( deser.isExisting( strstrm.str() + "/global_id" ) ) { 1653 unsigned int iPlugId; 1654 result &= deser.read( strstrm.str() + "/global_id", iPlugId ); 1655 1656 if ( result ) { 1657 AvPlug* pPlug = m_plugManager->getPlug( iPlugId ); 1658 if ( pPlug ) { 1659 vec.push_back( pPlug ); 1660 } else { 1661 result = false; 1662 bFinished = true; 1663 } 1664 i++; 1665 } else { 1666 bFinished = true; 1667 } 1668 } else { 1669 bFinished = true; 1670 } 1671 } while ( !bFinished ); 1672 1673 return result; 1674 } 1675 1676 bool 1677 AvPlug::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 1435 1678 { 1436 1679 bool result; 1437 1680 result = ser.write( basePath + "m_subunitType", m_subunitType ); 1438 1681 result &= ser.write( basePath + "m_subunitId", m_subunitId ); 1439 /// XXX ... 1682 result &= ser.write( basePath + "m_functionBlockType", m_functionBlockType); 1683 result &= ser.write( basePath + "m_functionBlockId", m_functionBlockId); 1684 result &= ser.write( basePath + "m_addressType", m_addressType ); 1685 result &= ser.write( basePath + "m_direction", m_direction); 1686 result &= ser.write( basePath + "m_id", m_id); 1687 result &= ser.write( basePath + "m_infoPlugType", m_infoPlugType); 1688 result &= ser.write( basePath + "m_nrOfChannels", m_nrOfChannels); 1689 result &= ser.write( basePath + "m_name", m_name); 1690 result &= serializeClusterInfos( basePath + "m_clusterInfos", ser ); 1691 result &= ser.write( basePath + "m_samplingFrequency", m_samplingFrequency); 1692 result &= serializeFormatInfos( basePath + "m_formatInfo", ser ); 1693 result &= serializeAvPlugVector( basePath + "m_inputConnections", ser, m_inputConnections ); 1694 result &= serializeAvPlugVector( basePath + "m_outputConnections", ser, m_outputConnections ); 1695 result &= ser.write( basePath + "m_verboseLevel", m_verboseLevel); 1696 result &= ser.write( basePath + "m_globalId", m_globalId); 1697 result &= ser.write( basePath + "m_globalIdCounter", m_globalIdCounter ); 1440 1698 1441 1699 return result; … … 1460 1718 result = deser.read( basePath + "m_subunitType", pPlug->m_subunitType ); 1461 1719 result &= deser.read( basePath + "m_subunitId", pPlug->m_subunitId ); 1462 // XXX ... 1720 result &= deser.read( basePath + "m_functionBlockType", pPlug->m_functionBlockType ); 1721 result &= deser.read( basePath + "m_functionBlockId", pPlug->m_functionBlockId ); 1722 result &= deser.read( basePath + "m_addressType", pPlug->m_addressType ); 1723 result &= deser.read( basePath + "m_direction", pPlug->m_direction ); 1724 result &= deser.read( basePath + "m_id", pPlug->m_id ); 1725 result &= deser.read( basePath + "m_infoPlugType", pPlug->m_infoPlugType ); 1726 result &= deser.read( basePath + "m_nrOfChannels", pPlug->m_nrOfChannels ); 1727 result &= deser.read( basePath + "m_name", pPlug->m_name ); 1728 result &= pPlug->deserializeClusterInfos( basePath + "m_clusterInfos", deser ); 1729 result &= deser.read( basePath + "m_samplingFrequency", pPlug->m_samplingFrequency ); 1730 result &= pPlug->deserializeFormatInfos( basePath + "m_formatInfos", deser ); 1731 // input and output connections can't be processed here because not all plugs might 1732 // deserialized at this point. so we do that in deserializeUpdate. 1733 result &= deser.read( basePath + "m_verboseLevel", pPlug->m_verboseLevel ); 1734 result &= deser.read( basePath + "m_globalId", pPlug->m_globalId ); 1735 result &= deser.read( basePath + "m_globalIdCounter", pPlug->m_globalIdCounter ); 1463 1736 1464 1737 if ( !result ) { … … 1468 1741 1469 1742 return pPlug; 1743 } 1744 1745 bool 1746 AvPlug::deserializeUpdate( Glib::ustring basePath, 1747 Util::IODeserialize& deser ) 1748 { 1749 bool result; 1750 result = deserializeAvPlugVector( basePath + "m_inputConnections", deser, m_inputConnections ); 1751 result &= deserializeAvPlugVector( basePath + "m_outputConnections", deser, m_outputConnections ); 1752 return result; 1470 1753 } 1471 1754 … … 1759 2042 } 1760 2043 2044 AvPlug* 2045 AvPlugManager::getPlug( int iGlobalId ) const 2046 { 2047 for ( AvPlugVector::const_iterator it = m_plugs.begin(); 2048 it != m_plugs.end(); 2049 ++it ) 2050 { 2051 AvPlug* pPlug = *it; 2052 if ( pPlug->getGlobalId() == iGlobalId ) { 2053 return pPlug; 2054 } 2055 } 2056 2057 return 0; 2058 } 2059 1761 2060 AvPlugVector 1762 2061 AvPlugManager::getPlugsByType( AVCCommand::ESubunitType subunitType, trunk/libfreebob/src/bebob/bebob_avplug.h
r371 r372 138 138 void showPlug() const; 139 139 140 141 struct ChannelInfo { 142 stream_position_t m_streamPosition; 143 stream_position_location_t m_location; 144 std::string m_name; 145 }; 146 typedef std::vector<ChannelInfo> ChannelInfoVector; 147 148 struct ClusterInfo { 149 int m_index; 150 port_type_t m_portType; 151 std::string m_name; 152 153 nr_of_channels_t m_nrOfChannels; 154 ChannelInfoVector m_channelInfos; 155 stream_format_t m_streamFormat; 156 }; 157 typedef std::vector<ClusterInfo> ClusterInfoVector; 158 ClusterInfoVector& getClusterInfos() 159 { return m_clusterInfos; } 160 161 bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ); 140 bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 162 141 static AvPlug* deserialize( Glib::ustring basePath, 163 142 Util::IODeserialize& deser, … … 165 144 ConfigRom& configRom, 166 145 AvPlugManager& plugManager ); 146 bool deserializeUpdate( Glib::ustring basePath, 147 Util::IODeserialize& deser ); 148 149 public: 150 struct ChannelInfo { 151 stream_position_t m_streamPosition; 152 stream_position_location_t m_location; 153 Glib::ustring m_name; 154 }; 155 typedef std::vector<ChannelInfo> ChannelInfoVector; 156 157 struct ClusterInfo { 158 int m_index; 159 port_type_t m_portType; 160 Glib::ustring m_name; 161 162 nr_of_channels_t m_nrOfChannels; 163 ChannelInfoVector m_channelInfos; 164 stream_format_t m_streamFormat; 165 }; 166 typedef std::vector<ClusterInfo> ClusterInfoVector; 167 168 ClusterInfoVector& getClusterInfos() 169 { return m_clusterInfos; } 170 167 171 protected: 172 AvPlug(); 173 168 174 bool discoverPlugType(); 169 175 bool discoverName(); … … 206 212 EAvPlugDirection toggleDirection( EAvPlugDirection direction ) const; 207 213 214 const ClusterInfo* getClusterInfoByIndex( int index ) const; 215 216 bool serializeChannelInfos( Glib::ustring basePath, 217 Util::IOSerialize& ser, 218 const ClusterInfo& clusterInfo ) const; 219 bool deserializeChannelInfos( Glib::ustring basePath, 220 Util::IODeserialize& deser, 221 ClusterInfo& clusterInfo ); 222 223 bool serializeClusterInfos( Glib::ustring basePath, 224 Util::IOSerialize& ser ) const; 225 bool deserializeClusterInfos( Glib::ustring basePath, 226 Util::IODeserialize& deser ); 227 228 bool serializeFormatInfos( Glib::ustring basePath, 229 Util::IOSerialize& ser ) const; 230 bool deserializeFormatInfos( Glib::ustring basePath, 231 Util::IODeserialize& deser ); 232 233 bool serializeAvPlugVector( Glib::ustring basePath, 234 Util::IOSerialize& ser, 235 const AvPlugVector& vec) const; 236 bool deserializeAvPlugVector( Glib::ustring basePath, 237 Util::IODeserialize& deser, 238 AvPlugVector& vec ); 239 208 240 private: 209 AvPlug();210 211 private:212 Ieee1394Service* m_1394Service;213 ConfigRom* m_pConfigRom;214 AVCCommand::ESubunitType m_subunitType;215 subunit_id_t m_subunitId;216 function_block_type_t m_functionBlockType;217 function_block_id_t m_functionBlockId;218 EAvPlugAddressType m_addressType;219 EAvPlugDirection m_direction;220 plug_id_t m_id;221 222 // Info plug type223 EAvPlugType m_infoPlugType;224 225 // Number of channels226 nr_of_channels_t m_nrOfChannels;227 228 // Plug name229 std::string m_name;230 231 // Channel & Cluster Info232 233 ClusterInfoVector m_clusterInfos;234 235 // Sampling frequency236 sampling_frequency_t m_samplingFrequency;237 238 241 // Supported stream formats 239 242 struct FormatInfo { … … 253 256 typedef std::vector<FormatInfo> FormatInfoVector; 254 257 255 FormatInfoVector m_formatInfos; 256 257 const ClusterInfo* getClusterInfoByIndex( int index ) const; 258 259 AvPlugVector m_inputConnections; 260 AvPlugVector m_outputConnections; 261 262 AvPlugManager* m_plugManager; 263 264 int m_verboseLevel; 265 266 int m_globalId; 267 268 static int m_globalIdCounter; 258 259 Ieee1394Service* m_1394Service; 260 ConfigRom* m_pConfigRom; 261 AVCCommand::ESubunitType m_subunitType; 262 subunit_id_t m_subunitId; 263 function_block_type_t m_functionBlockType; 264 function_block_id_t m_functionBlockId; 265 EAvPlugAddressType m_addressType; 266 EAvPlugDirection m_direction; 267 plug_id_t m_id; 268 EAvPlugType m_infoPlugType; 269 nr_of_channels_t m_nrOfChannels; 270 Glib::ustring m_name; 271 ClusterInfoVector m_clusterInfos; 272 sampling_frequency_t m_samplingFrequency; 273 FormatInfoVector m_formatInfos; 274 AvPlugVector m_inputConnections; 275 AvPlugVector m_outputConnections; 276 AvPlugManager* m_plugManager; 277 int m_verboseLevel; 278 int m_globalId; 279 static int m_globalIdCounter; 269 280 270 281 DECLARE_DEBUG_MODULE; … … 294 305 AvPlug::EAvPlugDirection plugDirection, 295 306 plug_id_t plugId ) const; 307 AvPlug* getPlug( int iGlobalId ) const; 296 308 AvPlugVector getPlugsByType( AVCCommand::ESubunitType subunitType, 297 309 subunit_id_t subunitId, … … 314 326 virtual ~AvPlugCluster(); 315 327 316 std::string m_name; 317 318 AvPlugVector m_avPlugs; 328 Glib::ustring m_name; 329 AvPlugVector m_avPlugs; 319 330 }; 320 331 trunk/libfreebob/src/libutil/serialize.cpp
r365 r372 220 220 return false; 221 221 } 222 223 bool 224 Util::XMLDeserialize::isExisting( std::string strMemberName ) 225 { 226 227 xmlpp::Node* pNode = m_parser.get_document()->get_root_node(); 228 xmlpp::NodeSet nodeSet = pNode->find( strMemberName ); 229 return nodeSet.size() > 0; 230 } trunk/libfreebob/src/libutil/serialize.h
r365 r372 52 52 53 53 template <typename T> bool read( std::string strMemberName, T& value ); 54 55 virtual bool isExisting( std::string strMemberName ) = 0; 54 56 }; 55 57 … … 80 82 virtual bool read( std::string strMemberName, 81 83 Glib::ustring& str ); 84 85 virtual bool isExisting( std::string strMemberName ); 86 82 87 private: 83 88 Glib::ustring m_filepath;