Index: /trunk/freebob/src/ieee1394service.h =================================================================== --- /trunk/freebob/src/ieee1394service.h (revision 31) +++ /trunk/freebob/src/ieee1394service.h (revision 42) @@ -57,5 +57,5 @@ static Ieee1394Service* instance(); - FBReturnCodes discoveryDevices(); + FBReturnCodes discoveryDevices( unsigned int iGenerationCount ); unsigned int getGenerationCount(); @@ -72,4 +72,6 @@ void printAvcUnitInfo( int iNodeId ); void printRomDirectory( int iNodeId, rom1394_directory* pRomDir ); + + void avDeviceTests( octlet_t oGuid, int iPort, int iNodeId ); private: Ieee1394Service(); @@ -79,5 +81,5 @@ raw1394handle_t m_handle; raw1394handle_t m_rhHandle; - int m_iPort; + int m_iPort; // XXX dw: port in 1394 service makes no sense bool m_bInitialised; pthread_t m_thread; Index: /trunk/freebob/src/avdevicepool.cpp =================================================================== --- /trunk/freebob/src/avdevicepool.cpp (revision 16) +++ /trunk/freebob/src/avdevicepool.cpp (revision 42) @@ -19,5 +19,10 @@ */ +#include + +#include "avdevice.h" #include "avdevicepool.h" + +AvDevicePool* AvDevicePool::m_pInstance = 0; AvDevicePool::AvDevicePool() @@ -27,4 +32,13 @@ AvDevicePool::~AvDevicePool() { +} + +AvDevicePool* +AvDevicePool::instance() +{ + if ( !m_pInstance ) { + m_pInstance = new AvDevicePool; + } + return m_pInstance; } @@ -58,2 +72,41 @@ } +AvDevice* +AvDevicePool::getAvDevice(octlet_t oGuid) +{ + AvDevice* pAvDevice = 0; + for ( AvDeviceVector::iterator iter = m_avDevices.begin(); + iter != m_avDevices.end(); + ++iter ) + { + if ( ( *iter )->getGuid() == oGuid ) { + pAvDevice = *iter; + break; + } + } + return pAvDevice; +} + +FBReturnCodes +AvDevicePool::removeObsoleteDevices( unsigned int iGeneration ) +{ + // XXX dw: removing elements can be done more elegant. + std::queue< AvDevice* > deleteQueue; + + for ( AvDeviceVector::iterator iter = m_avDevices.begin(); + iter != m_avDevices.end(); + ++iter ) + { + if ( ( *iter )->getGeneration() < iGeneration ) { + deleteQueue.push( *iter ); + } + } + + while ( !deleteQueue.empty() ) { + AvDevice* pAvDevice = deleteQueue.front(); + deleteQueue.pop(); + delete pAvDevice; + } + + return eFBRC_Success; +} Index: /trunk/freebob/src/avdevice.h =================================================================== --- /trunk/freebob/src/avdevice.h (revision 40) +++ /trunk/freebob/src/avdevice.h (revision 42) @@ -19,4 +19,6 @@ * MA 02111-1307 USA. */ +#ifndef AVDEVICE_H +#define AVDEVICE_H #include "ieee1394service.h" @@ -25,19 +27,29 @@ using std::vector; - -#ifndef AVDEVICE_H -#define AVDEVICE_H - class AvDeviceSubunit; class AvDevice { public: - AvDevice(int node,int port); + AvDevice( octlet_t oGuid ); virtual ~AvDevice(); - quadlet_t * avcExecuteTransaction(quadlet_t *request, unsigned int request_len, unsigned int response_len); + void setNodeId( int iNodeId ) + { m_iNodeId = iNodeId; } + int getNodeId() + { return m_iNodeId; } + void setPort( int iPort ) + { m_iPort = iPort; } + void setGeneration( unsigned int iGeneration ) + { m_iGeneration = iGeneration; } + unsigned int getGeneration() + { return m_iGeneration; } + octlet_t getGuid() + { return m_oGuid; } - FBReturnCodes Initialize(); - + quadlet_t * avcExecuteTransaction( quadlet_t *request, + unsigned int request_len, + unsigned int response_len ); + + FBReturnCodes initialize(); bool isInitialised(); @@ -56,6 +68,4 @@ unsigned char getNbExtSourcePlugs() { return iNbExtSourcePlugs; } ; unsigned char getNbExtDestinationPlugs() { return iNbExtDestinationPlugs; } ; - - int getNodeId() { return iNodeId; } ; protected: @@ -63,17 +73,18 @@ private: - int iNodeId; - raw1394handle_t m_handle; - int m_iPort; - bool m_bInitialised; - vector cSubUnits; - - unsigned char iNbAsyncDestinationPlugs; - unsigned char iNbAsyncSourcePlugs; - unsigned char iNbIsoDestinationPlugs; - unsigned char iNbIsoSourcePlugs; - unsigned char iNbExtDestinationPlugs; - unsigned char iNbExtSourcePlugs; - + int m_iNodeId; + raw1394handle_t m_handle; + int m_iPort; + bool m_bInitialised; + octlet_t m_oGuid; + unsigned int m_iGeneration; //Which generation this device belongs to + vector< AvDeviceSubunit * > cSubUnits; + + unsigned char iNbAsyncDestinationPlugs; + unsigned char iNbAsyncSourcePlugs; + unsigned char iNbIsoDestinationPlugs; + unsigned char iNbIsoSourcePlugs; + unsigned char iNbExtDestinationPlugs; + unsigned char iNbExtSourcePlugs; }; Index: /trunk/freebob/src/ieee1394service.cpp =================================================================== --- /trunk/freebob/src/ieee1394service.cpp (revision 40) +++ /trunk/freebob/src/ieee1394service.cpp (revision 42) @@ -24,7 +24,8 @@ #include - #include "ieee1394service.h" +#include "threads.h" #include "debugmodule.h" +#include "avdevicepool.h" #include "avdevice.h" @@ -104,6 +105,8 @@ startRHThread(); - discoveryDevices(); m_bInitialised = true; + + asyncCall( this, &Ieee1394Service::discoveryDevices, + m_iGenerationCount); } return eFBRC_Success; @@ -126,5 +129,5 @@ FBReturnCodes -Ieee1394Service::discoveryDevices() +Ieee1394Service::discoveryDevices( unsigned int iGeneration ) { //scan bus @@ -152,32 +155,28 @@ AVC1394_SUBUNIT_TYPE_AUDIO ) ) { - // XXX - // create avcDevice which discovers itself :) - - // PP: just a static try, don't want to mess with the device manager yet... - // Remark: the AvDevice and AvDescriptor aren't debugged thouroughly yet! - // the following code is the only debug I had time for... to be continued! (later this week) - debugPrint (DEBUG_LEVEL_INFO, " Trying to create an AvDevice...\n"); - - AvDevice *test=new AvDevice(m_iPort, iNodeId); - debugPrint (DEBUG_LEVEL_INFO, " Created...\n"); - test->Initialize(); - if (test->isInitialised()) { - unsigned char fmt; - quadlet_t fdf; - test->getInputPlugSignalFormat(0,&fmt,&fdf); - debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); - test->getInputPlugSignalFormat(1,&fmt,&fdf); - debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); - test->getOutputPlugSignalFormat(0,&fmt,&fdf); - debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); - test->getOutputPlugSignalFormat(1,&fmt,&fdf); - debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); - test->printConnections(); - } - - debugPrint (DEBUG_LEVEL_INFO, " Deleting AvDevice...\n"); - delete test; - + octlet_t oGuid = rom1394_get_guid( m_handle, iNodeId ); + AvDevice* pAvDevice + = AvDevicePool::instance()->getAvDevice( oGuid ); + if ( !pAvDevice ) { + pAvDevice = new AvDevice( oGuid ); + } + pAvDevice->setNodeId( iNodeId ); + pAvDevice->setPort( m_iPort ); + + if ( !pAvDevice->isInitialised() ) { + FBReturnCodes eStatus = pAvDevice->initialize(); + if ( eStatus != eFBRC_Success ) { + debugError( "AvDevice with GUID 0x%08x%08x could " + "not be initialized\n", + (quadlet_t) (oGuid>>32), + (quadlet_t) (oGuid & 0xffffffff) ); + + delete pAvDevice; + return eStatus; + } + } + + // XXX Pieter's test code. + avDeviceTests( oGuid, m_iPort, iNodeId ); } break; @@ -195,6 +194,41 @@ } } + + AvDevicePool::instance()->removeObsoleteDevices( iGeneration ); return eFBRC_Success; } + + +void +Ieee1394Service::avDeviceTests(octlet_t oGuid, int iPort, int iNodeId) +{ + // PP: just a static try, don't want to mess with the device manager yet... + // Remark: the AvDevice and AvDescriptor aren't debugged thouroughly yet! + // the following code is the only debug I had time for... to be continued! (later this week) + debugPrint (DEBUG_LEVEL_INFO, " Trying to create an AvDevice...\n"); + + AvDevice *test=new AvDevice(oGuid); + test->setNodeId( iNodeId ); + test->setPort( iPort ); + debugPrint (DEBUG_LEVEL_INFO, " Created...\n"); + test->initialize(); + if (test->isInitialised()) { + unsigned char fmt; + quadlet_t fdf; + test->getInputPlugSignalFormat(0,&fmt,&fdf); + debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); + test->getInputPlugSignalFormat(1,&fmt,&fdf); + debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); + test->getOutputPlugSignalFormat(0,&fmt,&fdf); + debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); + test->getOutputPlugSignalFormat(1,&fmt,&fdf); + debugPrint (DEBUG_LEVEL_INFO, " fmt=%02X fdf=%08X\n",fmt,fdf); + test->printConnections(); + } + + debugPrint (DEBUG_LEVEL_INFO, " Deleting AvDevice...\n"); + delete test; +} + void @@ -309,4 +343,8 @@ = (Ieee1394Service*) raw1394_get_userdata (handle); pInstance->setGenerationCount( iGeneration ); + + // dw: let's rescan the bus. this might not the correct order + // of commands. + asyncCall( pInstance, &Ieee1394Service::discoveryDevices, iGeneration ); return 0; } Index: /trunk/freebob/src/avdevicepool.h =================================================================== --- /trunk/freebob/src/avdevicepool.h (revision 16) +++ /trunk/freebob/src/avdevicepool.h (revision 42) @@ -23,4 +23,5 @@ #include "freebob.h" #include +#include // octlet_t class AvDevice; @@ -28,11 +29,29 @@ class AvDevicePool { public: + static AvDevicePool* instance(); + + FBReturnCodes registerAvDevice( AvDevice* pAvDevice ); + FBReturnCodes unregisterAvDevice( AvDevice* pAvDevice ); + + AvDevice* getAvDevice( octlet_t oGuid ); + + /** + * Remove devices in pool which where (physically) removed + * from the bus. + * + * All devices which have a lower generation count smaller + * than iGeneration are removed from the pool + * + * @param iGeneration Current generation count. + * @return see FBReturnCodes. + */ + FBReturnCodes removeObsoleteDevices( unsigned int iGeneration ); + private: AvDevicePool(); ~AvDevicePool(); - FBReturnCodes registerAvDevice(AvDevice* pAvDevice); - FBReturnCodes unregisterAvDevice(AvDevice* pAvDevice); - private: - typedef std::vector AvDeviceVector; + static AvDevicePool* m_pInstance; + + typedef std::vector< AvDevice* > AvDeviceVector; AvDeviceVector m_avDevices; }; Index: /trunk/freebob/src/avdevice.cpp =================================================================== --- /trunk/freebob/src/avdevice.cpp (revision 40) +++ /trunk/freebob/src/avdevice.cpp (revision 42) @@ -27,24 +27,13 @@ #include "avdevicemusicsubunit.h" -AvDevice::AvDevice(int port, int node) +AvDevice::AvDevice(octlet_t oGuid) { - iNodeId=node; - m_iPort=port; - - // check to see if a device is really present? - - // probably initialisation would be better done here - - // Port and node id are not distinct. The node id - // can change after a bus reset, therefore the - // device id has to be taken for identifiction. + m_oGuid = oGuid; } FBReturnCodes -AvDevice::Initialize() { - - if (!m_bInitialised) { - - m_handle = raw1394_new_handle(); +AvDevice::initialize() { + if (!m_bInitialised) { + m_handle = raw1394_new_handle(); if ( !m_handle ) { if ( !errno ) { @@ -161,5 +150,5 @@ tmpAvDeviceSubunit->unReserve(); //setDebugLevel(DEBUG_LEVEL_MODERATE); - + } else { @@ -208,5 +197,5 @@ unsigned char *request_pos; unsigned int i; - response = avc1394_transaction_block(m_handle, iNodeId, request, request_len, 2); + response = avc1394_transaction_block(m_handle, m_iNodeId, request, request_len, 2); if (request != NULL) { debugPrint (DEBUG_LEVEL_TRANSFERS, "------- TRANSACTION START -------\n"); @@ -275,7 +264,7 @@ response = avcExecuteTransaction(request, 2, 2); if (response != NULL) { - - } - + + } + return eFBRC_Success; } @@ -292,6 +281,7 @@ *fdf=response[1]& 0x00FFFFFF; } - -} + return eFBRC_Success; +} + FBReturnCodes AvDevice::setOutputPlugSignalFormat(unsigned char plug, unsigned char fmt, quadlet_t fdf) { quadlet_t request[6]; @@ -303,7 +293,7 @@ response = avcExecuteTransaction(request, 2, 2); if (response != NULL) { - - } - + + } + return eFBRC_Success; } @@ -320,5 +310,5 @@ *fdf=response[1]& 0x00FFFFFF; } - + return eFBRC_Success; } @@ -340,6 +330,6 @@ quadlet_t *response; //setDebugLevel(DEBUG_LEVEL_ALL); - - debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: ISO source connections:\n"); + + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: ISO source connections:\n"); for (unsigned int i=0;i> 5; unsigned char conv=(response[0]&0x10) >> 4; unsigned char signal_status=(response[0]&0x0F); - + unsigned int signal_source=((response[1]>>16)&0xFFFF); - + unsigned char source_subunit_type=(signal_source>>11)&0x1F; unsigned char source_subunit_id=(signal_source>>8)&0x07; unsigned char source_plug=signal_source&0xFF; - + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: OPCR 0x%02X <- subunit: 0x%02X/0x%02X, plug: 0x%02X (0x%02X / %d / 0x%02X)\n",i, source_subunit_type,source_subunit_id,source_plug,output_status,conv,signal_status); - // find the subunit this plug is connected to + // find the subunit this plug is connected to AvDeviceSubunit *tmpSubunit=getSubunit(source_subunit_type,source_subunit_id); if(tmpSubunit) { tmpSubunit->printSourcePlugConnections(source_plug); } - - } - } - - debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: External source connections:\n"); + + } + } + + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: External source connections:\n"); for (unsigned int i=0;i> 5; unsigned char conv=(response[0]&0x10) >> 4; unsigned char signal_status=(response[0]&0x0F); - + unsigned int signal_source=((response[1]>>16)&0xFFFF); - + unsigned char source_subunit_type=(signal_source>>11)&0x1F; unsigned char source_subunit_id=(signal_source>>8)&0x07; unsigned char source_plug=signal_source&0xFF; - - debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: EXTOUT 0x%02X <- subunit: 0x%02X/0x%02X, plug: 0x%02X (0x%02X / %d / 0x%02X)\n",i, source_subunit_type,source_subunit_id,source_plug,output_status,conv,signal_status); - - // find the subunit this plug is connected to + + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: EXTOUT 0x%02X <- subunit: 0x%02X/0x%02X, plug: 0x%02X (0x%02X / %d / 0x%02X)\n",i, source_subunit_type,source_subunit_id,source_plug,output_status,conv,signal_status); + + // find the subunit this plug is connected to AvDeviceSubunit *tmpSubunit=getSubunit(source_subunit_type,source_subunit_id); if(tmpSubunit) { tmpSubunit->printSourcePlugConnections(source_plug); - } - } - } - - debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: ISO sink connections:\n"); + } + } + } + + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: ISO sink connections:\n"); for (unsigned int i=0;i> 5; unsigned char conv=(response[0]&0x10) >> 4; unsigned char signal_status=(response[0]&0x0F); - + unsigned int signal_source=((response[1]>>16)&0xFFFF); - + unsigned char source_subunit_type=(signal_source>>11)&0x1F; unsigned char source_subunit_id=(signal_source>>8)&0x07; unsigned char source_plug=signal_source&0xFF; - + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: OPCR 0x%02X <- subunit: 0x%02X/0x%02X, plug: 0x%02X (0x%02X / %d / 0x%02X)\n",i, source_subunit_type,source_subunit_id,source_plug,output_status,conv,signal_status); - // find the subunit this plug is connected to + // find the subunit this plug is connected to AvDeviceSubunit *tmpSubunit=getSubunit(source_subunit_type,source_subunit_id); if(tmpSubunit) { //tmpSubunit->printDestinationPlugConnections(source_plug); } - - } - } - - debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: External sink connections:\n"); + + } + } + + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: External sink connections:\n"); for (unsigned int i=0;i> 5; unsigned char conv=(response[0]&0x10) >> 4; unsigned char signal_status=(response[0]&0x0F); - + unsigned int signal_source=((response[1]>>16)&0xFFFF); - + unsigned char source_subunit_type=(signal_source>>11)&0x1F; unsigned char source_subunit_id=(signal_source>>8)&0x07; unsigned char source_plug=signal_source&0xFF; - - debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: EXTOUT 0x%02X <- subunit: 0x%02X/0x%02X, plug: 0x%02X (0x%02X / %d / 0x%02X)\n",i, source_subunit_type,source_subunit_id,source_plug,output_status,conv,signal_status); - - // find the subunit this plug is connected to + + debugPrint (DEBUG_LEVEL_DEVICE,"AvDevice: EXTOUT 0x%02X <- subunit: 0x%02X/0x%02X, plug: 0x%02X (0x%02X / %d / 0x%02X)\n",i, source_subunit_type,source_subunit_id,source_plug,output_status,conv,signal_status); + + // find the subunit this plug is connected to AvDeviceSubunit *tmpSubunit=getSubunit(source_subunit_type,source_subunit_id); if(tmpSubunit) { //tmpSubunit->printDestinationPlugConnections(source_plug); - } - } - } - -} + } + } + } + +}