| 1 |
/* devicemanager.cpp |
/* devicemanager.cpp |
| 2 |
* Copyright (C) 2005 by Daniel Wagner |
* Copyright (C) 2005,06 by Daniel Wagner |
| 3 |
* |
* |
| 4 |
* This file is part of FreeBob. |
* This file is part of FreeBob. |
| 5 |
* |
* |
| 21 |
#include "fbtypes.h" |
#include "fbtypes.h" |
| 22 |
|
|
| 23 |
#include "devicemanager.h" |
#include "devicemanager.h" |
| 24 |
#include "avdevice.h" |
#include "iavdevice.h" |
| 25 |
#include "configrom.h" |
#include "configrom.h" |
| 26 |
|
|
| 27 |
#include "libfreebobavc/ieee1394service.h" |
#include "libfreebobavc/ieee1394service.h" |
| 28 |
#include "debugmodule/debugmodule.h" |
#include "debugmodule/debugmodule.h" |
| 29 |
|
#include "bebob/bebob_avdevice.h" |
| 30 |
|
#include "bounce/bounce_avdevice.h" |
| 31 |
|
|
| 32 |
#include <iostream> |
#include <iostream> |
| 33 |
|
|
| 34 |
using namespace std; |
using namespace std; |
| 35 |
|
|
| 36 |
IMPL_DEBUG_MODULE( DeviceManager, DeviceManager, DEBUG_LEVEL_VERBOSE ); |
IMPL_DEBUG_MODULE( DeviceManager, DeviceManager, DEBUG_LEVEL_NORMAL ); |
| 37 |
|
|
| 38 |
DeviceManager::DeviceManager() |
DeviceManager::DeviceManager() |
| 39 |
: m_1394Service( 0 ) |
: m_1394Service( 0 ) |
| 40 |
{ |
{ |
| 41 |
|
m_probeList.push_back( probeBeBoB ); |
| 42 |
|
m_probeList.push_back( probeBounce ); |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
DeviceManager::~DeviceManager() |
DeviceManager::~DeviceManager() |
| 46 |
{ |
{ |
| 47 |
for ( AvDeviceVectorIterator it = m_avDevices.begin(); |
for ( IAvDeviceVectorIterator it = m_avDevices.begin(); |
| 48 |
it != m_avDevices.end(); |
it != m_avDevices.end(); |
| 49 |
++it ) |
++it ) |
| 50 |
{ |
{ |
| 55 |
} |
} |
| 56 |
|
|
| 57 |
bool |
bool |
| 58 |
DeviceManager::initialize(int port) |
DeviceManager::initialize( int port ) |
| 59 |
{ |
{ |
| 60 |
m_1394Service = new Ieee1394Service(); |
m_1394Service = new Ieee1394Service(); |
| 61 |
if ( !m_1394Service ) { |
if ( !m_1394Service ) { |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
bool |
bool |
| 77 |
DeviceManager::discover() |
DeviceManager::discover( int verboseLevel ) |
| 78 |
{ |
{ |
| 79 |
for ( AvDeviceVectorIterator it = m_avDevices.begin(); |
if ( verboseLevel ) { |
| 80 |
|
setDebugLevel( DEBUG_LEVEL_VERBOSE ); |
| 81 |
|
} |
| 82 |
|
for ( IAvDeviceVectorIterator it = m_avDevices.begin(); |
| 83 |
it != m_avDevices.end(); |
it != m_avDevices.end(); |
| 84 |
++it ) |
++it ) |
| 85 |
{ |
{ |
| 91 |
nodeId < m_1394Service->getNodeCount(); |
nodeId < m_1394Service->getNodeCount(); |
| 92 |
++nodeId ) |
++nodeId ) |
| 93 |
{ |
{ |
| 94 |
ConfigRom* configRom = new ConfigRom( m_1394Service, nodeId ); |
ConfigRom configRom( m_1394Service, nodeId ); |
| 95 |
if ( !configRom->initialize() ) { |
if ( !configRom.initialize() ) { |
| 96 |
// \todo If a PHY on the bus in power safe mode than |
// \todo If a PHY on the bus in power safe mode than |
| 97 |
// the config rom is missing. So this might be just |
// the config rom is missing. So this might be just |
| 98 |
// such a case and we can safely skip it. But it might |
// such a case and we can safely skip it. But it might |
| 102 |
"Could not read config rom from device (noe id %d). " |
"Could not read config rom from device (noe id %d). " |
| 103 |
"Skip device discovering for this node\n", |
"Skip device discovering for this node\n", |
| 104 |
nodeId ); |
nodeId ); |
|
delete configRom; |
|
| 105 |
continue; |
continue; |
| 106 |
} |
} |
| 107 |
|
|
| 108 |
if ( !configRom->isAvcDevice() ) { |
if ( !configRom.isAvcDevice() ) { |
|
delete configRom; |
|
| 109 |
continue; |
continue; |
| 110 |
} |
} |
| 111 |
|
|
| 112 |
AvDevice* avDevice = new AvDevice( m_1394Service, configRom, nodeId ); |
for ( ProbeFunctionVector::iterator it = m_probeList.begin(); |
| 113 |
if ( !avDevice ) { |
it != m_probeList.end(); |
| 114 |
debugError( "discover: Could not allocate AvDevice\n" ); |
++it ) |
| 115 |
delete configRom; |
{ |
| 116 |
return false; |
ProbeFunction func = *it; |
| 117 |
} |
IAvDevice* avDevice = func(*m_1394Service, nodeId, verboseLevel); |
| 118 |
|
if ( avDevice ) { |
| 119 |
if ( !avDevice->discover() ) { |
m_avDevices.push_back( avDevice ); |
| 120 |
debugError( "discover: Could not discover device (node id %d)\n", |
if ( verboseLevel ) { |
| 121 |
nodeId ); |
avDevice->showDevice(); |
| 122 |
delete avDevice; |
} |
| 123 |
return false; |
break; |
| 124 |
|
} |
| 125 |
} |
} |
| 126 |
|
|
|
m_avDevices.push_back( avDevice ); |
|
| 127 |
} |
} |
| 128 |
|
|
| 129 |
return true; |
return true; |
| 130 |
} |
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
IAvDevice* |
| 134 |
|
DeviceManager::probeBeBoB(Ieee1394Service& service, int id, int level) |
| 135 |
|
{ |
| 136 |
|
IAvDevice* avDevice = new BeBoB::AvDevice( service, id, level ); |
| 137 |
|
if ( !avDevice ) { |
| 138 |
|
return 0; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
if ( !avDevice->discover() ) { |
| 142 |
|
delete avDevice; |
| 143 |
|
return 0; |
| 144 |
|
} |
| 145 |
|
return avDevice; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
IAvDevice* |
| 149 |
|
DeviceManager::probeBounce(Ieee1394Service& service, int id, int level) |
| 150 |
|
{ |
| 151 |
|
IAvDevice* avDevice = new Bounce::BounceDevice( service, id, level ); |
| 152 |
|
if ( !avDevice ) { |
| 153 |
|
return 0; |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
if ( !avDevice->discover() ) { |
| 157 |
|
delete avDevice; |
| 158 |
|
return 0; |
| 159 |
|
} |
| 160 |
|
return avDevice; |
| 161 |
|
} |
| 162 |
|
|
| 163 |
bool |
bool |
| 164 |
DeviceManager::isValidNode(int node) |
DeviceManager::isValidNode(int node) |
| 165 |
{ |
{ |
| 166 |
for ( AvDeviceVectorIterator it = m_avDevices.begin(); |
for ( IAvDeviceVectorIterator it = m_avDevices.begin(); |
| 167 |
it != m_avDevices.end(); |
it != m_avDevices.end(); |
| 168 |
++it ) |
++it ) |
| 169 |
{ |
{ |
| 170 |
AvDevice* avDevice = *it; |
IAvDevice* avDevice = *it; |
| 171 |
|
|
| 172 |
if (avDevice->getNodeId() == node) { |
if (avDevice->getConfigRom().getNodeId() == node) { |
| 173 |
return true; |
return true; |
|
} |
|
| 174 |
} |
} |
| 175 |
return false; |
} |
| 176 |
|
return false; |
| 177 |
} |
} |
| 178 |
|
|
| 179 |
int |
int |
| 190 |
return -1; |
return -1; |
| 191 |
} |
} |
| 192 |
|
|
| 193 |
AvDevice* avDevice = m_avDevices.at( deviceNr ); |
IAvDevice* avDevice = m_avDevices.at( deviceNr ); |
| 194 |
|
|
| 195 |
if ( !avDevice ) { |
if ( !avDevice ) { |
| 196 |
debugError( "Could not get device at position (%d)\n", deviceNr ); |
debugError( "Could not get device at position (%d)\n", deviceNr ); |
| 197 |
} |
} |
| 198 |
|
|
| 199 |
return avDevice->getNodeId(); |
return avDevice->getConfigRom().getNodeId(); |
| 200 |
} |
} |
| 201 |
|
|
| 202 |
AvDevice* |
IAvDevice* |
| 203 |
DeviceManager::getAvDevice( int nodeId ) |
DeviceManager::getAvDevice( int nodeId ) |
| 204 |
{ |
{ |
| 205 |
for ( AvDeviceVectorIterator it = m_avDevices.begin(); |
for ( IAvDeviceVectorIterator it = m_avDevices.begin(); |
| 206 |
it != m_avDevices.end(); |
it != m_avDevices.end(); |
| 207 |
++it ) |
++it ) |
| 208 |
{ |
{ |
| 209 |
AvDevice* avDevice = *it; |
IAvDevice* avDevice = *it; |
| 210 |
if ( avDevice->getNodeId() == nodeId ) { |
if ( avDevice->getConfigRom().getNodeId() == nodeId ) { |
| 211 |
return avDevice; |
return avDevice; |
| 212 |
} |
} |
| 213 |
} |
} |
| 233 |
} |
} |
| 234 |
xmlDocSetRootElement( doc, rootNode ); |
xmlDocSetRootElement( doc, rootNode ); |
| 235 |
|
|
| 236 |
for ( AvDeviceVectorIterator it = m_avDevices.begin(); |
for ( IAvDeviceVectorIterator it = m_avDevices.begin(); |
| 237 |
it != m_avDevices.end(); |
it != m_avDevices.end(); |
| 238 |
++it ) |
++it ) |
| 239 |
{ |
{ |
| 240 |
AvDevice* avDevice = *it; |
IAvDevice* avDevice = *it; |
| 241 |
|
|
| 242 |
xmlNodePtr deviceNode = xmlNewChild( rootNode, 0, |
xmlNodePtr deviceNode = xmlNewChild( rootNode, 0, |
| 243 |
BAD_CAST "Device", 0 ); |
BAD_CAST "Device", 0 ); |
| 249 |
} |
} |
| 250 |
|
|
| 251 |
char* result; |
char* result; |
| 252 |
asprintf( &result, "%d", avDevice->getNodeId() ); |
asprintf( &result, "%d", avDevice->getConfigRom().getNodeId() ); |
| 253 |
if ( !xmlNewChild( deviceNode, 0, |
if ( !xmlNewChild( deviceNode, 0, |
| 254 |
BAD_CAST "NodeId", BAD_CAST result ) ) |
BAD_CAST "NodeId", BAD_CAST result ) ) |
| 255 |
{ |
{ |
| 258 |
} |
} |
| 259 |
|
|
| 260 |
std::string res = "Connection Information for " |
std::string res = "Connection Information for " |
| 261 |
+ avDevice->getVendorName() |
+ avDevice->getConfigRom().getVendorName() |
| 262 |
+", " |
+", " |
| 263 |
+ avDevice->getModelName() |
+ avDevice->getConfigRom().getModelName() |
| 264 |
+ " configuration"; |
+ " configuration"; |
| 265 |
if ( !xmlNewChild( deviceNode, |
if ( !xmlNewChild( deviceNode, |
| 266 |
0, |
0, |
| 272 |
return 0; |
return 0; |
| 273 |
} |
} |
| 274 |
|
|
| 275 |
res = avDevice->getVendorName(); |
res = avDevice->getConfigRom().getVendorName(); |
| 276 |
|
|
| 277 |
if ( !xmlNewChild( deviceNode, |
if ( !xmlNewChild( deviceNode, |
| 278 |
0, |
0, |
| 284 |
return 0; |
return 0; |
| 285 |
} |
} |
| 286 |
|
|
| 287 |
res = avDevice->getModelName(); |
res = avDevice->getConfigRom().getModelName(); |
| 288 |
|
|
| 289 |
if ( !xmlNewChild( deviceNode, |
if ( !xmlNewChild( deviceNode, |
| 290 |
0, |
0, |
| 297 |
} |
} |
| 298 |
|
|
| 299 |
asprintf( &result, "%08x%08x", |
asprintf( &result, "%08x%08x", |
| 300 |
( quadlet_t )( avDevice->getGuid() >> 32 ), |
( quadlet_t )( avDevice->getConfigRom().getGuid() >> 32 ), |
| 301 |
( quadlet_t )( avDevice->getGuid() & 0xfffffff ) ); |
( quadlet_t )( avDevice->getConfigRom().getGuid() & 0xfffffff ) ); |
| 302 |
if ( !xmlNewChild( deviceNode, 0, |
if ( !xmlNewChild( deviceNode, 0, |
| 303 |
BAD_CAST "GUID", BAD_CAST result ) ) { |
BAD_CAST "GUID", BAD_CAST result ) ) { |
| 304 |
debugError( "Couldn't create 'GUID' node\n" ); |
debugError( "Couldn't create 'GUID' node\n" ); |