1 |
/* avdevicepool.cpp |
---|
2 |
* Copyright (C) 2004 by Daniel Wagner |
---|
3 |
* |
---|
4 |
* This file is part of FreeBob. |
---|
5 |
* |
---|
6 |
* FreeBob is free software; you can redistribute it and/or modify |
---|
7 |
* it under the terms of the GNU General Public License as published by |
---|
8 |
* the Free Software Foundation; either version 2 of the License, or |
---|
9 |
* (at your option) any later version. |
---|
10 |
* FreeBob is distributed in the hope that it will be useful, |
---|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 |
* GNU General Public License for more details. |
---|
14 |
* |
---|
15 |
* You should have received a copy of the GNU General Public License |
---|
16 |
* along with FreeBob; if not, write to the Free Software |
---|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
18 |
* MA 02111-1307 USA. |
---|
19 |
*/ |
---|
20 |
|
---|
21 |
#include <queue> |
---|
22 |
|
---|
23 |
#include "avdevice.h" |
---|
24 |
#include "avdevicepool.h" |
---|
25 |
|
---|
26 |
AvDevicePool* AvDevicePool::m_pInstance = 0; |
---|
27 |
|
---|
28 |
AvDevicePool::AvDevicePool() |
---|
29 |
{ |
---|
30 |
} |
---|
31 |
|
---|
32 |
AvDevicePool::~AvDevicePool() |
---|
33 |
{ |
---|
34 |
} |
---|
35 |
|
---|
36 |
AvDevicePool* |
---|
37 |
AvDevicePool::instance() |
---|
38 |
{ |
---|
39 |
if ( !m_pInstance ) { |
---|
40 |
m_pInstance = new AvDevicePool; |
---|
41 |
} |
---|
42 |
return m_pInstance; |
---|
43 |
} |
---|
44 |
|
---|
45 |
FBReturnCodes |
---|
46 |
AvDevicePool::registerAvDevice(AvDevice* pAvDevice) |
---|
47 |
{ |
---|
48 |
m_avDevices.push_back( pAvDevice ); |
---|
49 |
return eFBRC_Success; |
---|
50 |
} |
---|
51 |
|
---|
52 |
|
---|
53 |
FBReturnCodes |
---|
54 |
AvDevicePool::unregisterAvDevice(AvDevice* pAvDevice) |
---|
55 |
{ |
---|
56 |
AvDeviceVector::iterator iter; |
---|
57 |
for ( iter = m_avDevices.begin(); |
---|
58 |
iter != m_avDevices.end(); |
---|
59 |
++iter ) |
---|
60 |
{ |
---|
61 |
if ( ( *iter ) == pAvDevice ) { |
---|
62 |
m_avDevices.erase( iter ); |
---|
63 |
return eFBRC_Success; |
---|
64 |
} |
---|
65 |
} |
---|
66 |
|
---|
67 |
if ( iter == m_avDevices.end() ) { |
---|
68 |
return eFBRC_AvDeviceNotFound; |
---|
69 |
} |
---|
70 |
|
---|
71 |
return eFBRC_Success; |
---|
72 |
} |
---|
73 |
|
---|
74 |
AvDevice* |
---|
75 |
AvDevicePool::getAvDevice(octlet_t oGuid) |
---|
76 |
{ |
---|
77 |
AvDevice* pAvDevice = 0; |
---|
78 |
for ( AvDeviceVector::iterator iter = m_avDevices.begin(); |
---|
79 |
iter != m_avDevices.end(); |
---|
80 |
++iter ) |
---|
81 |
{ |
---|
82 |
if ( ( *iter )->getGuid() == oGuid ) { |
---|
83 |
pAvDevice = *iter; |
---|
84 |
break; |
---|
85 |
} |
---|
86 |
} |
---|
87 |
return pAvDevice; |
---|
88 |
} |
---|
89 |
|
---|
90 |
FBReturnCodes |
---|
91 |
AvDevicePool::removeObsoleteDevices( unsigned int iGeneration ) |
---|
92 |
{ |
---|
93 |
// XXX dw: removing elements can be done more elegant. |
---|
94 |
std::queue< AvDevice* > deleteQueue; |
---|
95 |
|
---|
96 |
for ( AvDeviceVector::iterator iter = m_avDevices.begin(); |
---|
97 |
iter != m_avDevices.end(); |
---|
98 |
++iter ) |
---|
99 |
{ |
---|
100 |
if ( ( *iter )->getGeneration() < iGeneration ) { |
---|
101 |
deleteQueue.push( *iter ); |
---|
102 |
} |
---|
103 |
} |
---|
104 |
|
---|
105 |
while ( !deleteQueue.empty() ) { |
---|
106 |
AvDevice* pAvDevice = deleteQueue.front(); |
---|
107 |
deleteQueue.pop(); |
---|
108 |
delete pAvDevice; |
---|
109 |
} |
---|
110 |
|
---|
111 |
return eFBRC_Success; |
---|
112 |
} |
---|