2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
34 #include "CECDeviceMap.h"
36 #include "CECAudioSystem.h"
37 #include "CECPlaybackDevice.h"
38 #include "CECRecordingDevice.h"
41 #include "lib/CECProcessor.h"
42 #include "lib/CECTypeUtils.h"
47 CCECDeviceMap::CCECDeviceMap(CCECProcessor
*processor
) :
48 m_processor(processor
)
50 for (uint8_t iPtr
= CECDEVICE_TV
; iPtr
<= CECDEVICE_BROADCAST
; iPtr
++)
54 case CECDEVICE_AUDIOSYSTEM
:
55 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECAudioSystem(processor
, (cec_logical_address
) iPtr
)));
57 case CECDEVICE_PLAYBACKDEVICE1
:
58 case CECDEVICE_PLAYBACKDEVICE2
:
59 case CECDEVICE_PLAYBACKDEVICE3
:
60 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECPlaybackDevice(processor
, (cec_logical_address
) iPtr
)));
62 case CECDEVICE_RECORDINGDEVICE1
:
63 case CECDEVICE_RECORDINGDEVICE2
:
64 case CECDEVICE_RECORDINGDEVICE3
:
65 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECRecordingDevice(processor
, (cec_logical_address
) iPtr
)));
67 case CECDEVICE_TUNER1
:
68 case CECDEVICE_TUNER2
:
69 case CECDEVICE_TUNER3
:
70 case CECDEVICE_TUNER4
:
71 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECTuner(processor
, (cec_logical_address
) iPtr
)));
74 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECTV(processor
, (cec_logical_address
) iPtr
)));
77 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECBusDevice(processor
, (cec_logical_address
) iPtr
)));
82 CCECDeviceMap::~CCECDeviceMap(void)
87 CECDEVICEMAP::iterator
CCECDeviceMap::Begin(void)
89 return m_busDevices
.begin();
92 CECDEVICEMAP::iterator
CCECDeviceMap::End(void)
94 return m_busDevices
.end();
97 void CCECDeviceMap::ResetDeviceStatus(void)
99 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
100 it
->second
->ResetDeviceStatus();
103 CCECBusDevice
*CCECDeviceMap::operator[] (cec_logical_address iAddress
) const
108 CCECBusDevice
*CCECDeviceMap::operator[] (uint8_t iAddress
) const
113 CCECBusDevice
*CCECDeviceMap::At(cec_logical_address iAddress
) const
115 return At((uint8_t) iAddress
);
118 CCECBusDevice
*CCECDeviceMap::At(uint8_t iAddress
) const
120 CECDEVICEMAP::const_iterator it
= m_busDevices
.find((cec_logical_address
)iAddress
);
121 if (it
!= m_busDevices
.end())
126 void CCECDeviceMap::Clear(void)
128 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
130 m_busDevices
.clear();
133 CCECBusDevice
*CCECDeviceMap::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
135 CCECBusDevice
*device(NULL
);
137 // check each device until we found a match
138 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); !device
&& it
!= m_busDevices
.end(); it
++)
140 if (it
->second
->GetPhysicalAddress(m_processor
->GetLogicalAddress(), bSuppressUpdate
) == iPhysicalAddress
)
147 void CCECDeviceMap::Get(CECDEVICEVEC
&devices
) const
149 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
150 devices
.push_back(it
->second
);
153 void CCECDeviceMap::GetByLogicalAddresses(CECDEVICEVEC
&devices
, const cec_logical_addresses
&addresses
)
155 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
157 if (addresses
.IsSet(it
->first
))
158 devices
.push_back(it
->second
);
162 void CCECDeviceMap::GetByType(const cec_device_type type
, CECDEVICEVEC
&devices
) const
164 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
165 if (it
->second
->GetType() == type
)
166 devices
.push_back(it
->second
);
169 void CCECDeviceMap::GetLibCECControlled(CECDEVICEVEC
&devices
) const
171 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
172 if (it
->second
->IsHandledByLibCEC())
173 devices
.push_back(it
->second
);
176 void CCECDeviceMap::GetActive(CECDEVICEVEC
&devices
) const
178 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
180 cec_bus_device_status status
= it
->second
->GetStatus();
181 if (status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
||
182 status
== CEC_DEVICE_STATUS_PRESENT
)
183 devices
.push_back(it
->second
);
187 void CCECDeviceMap::GetPowerOffDevices(const libcec_configuration
&configuration
, CECDEVICEVEC
&devices
) const
189 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
191 if (configuration
.powerOffDevices
[(uint8_t)it
->first
])
192 devices
.push_back(it
->second
);
196 void CCECDeviceMap::GetWakeDevices(const libcec_configuration
&configuration
, CECDEVICEVEC
&devices
) const
198 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
200 if (configuration
.wakeDevices
[(uint8_t)it
->first
])
201 devices
.push_back(it
->second
);
205 CCECBusDevice
*CCECDeviceMap::GetActiveSource(void) const
207 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
209 if (it
->second
->IsActiveSource())
215 void CCECDeviceMap::FilterLibCECControlled(CECDEVICEVEC
&devices
)
217 CECDEVICEVEC newDevices
;
218 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
220 if ((*it
)->IsHandledByLibCEC())
221 newDevices
.push_back(*it
);
223 devices
= newDevices
;
226 void CCECDeviceMap::FilterActive(CECDEVICEVEC
&devices
)
228 CECDEVICEVEC newDevices
;
229 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
231 cec_bus_device_status status
= (*it
)->GetCurrentStatus();
232 if (status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
||
233 status
== CEC_DEVICE_STATUS_PRESENT
)
234 newDevices
.push_back(*it
);
236 devices
= newDevices
;
239 void CCECDeviceMap::FilterTypes(const cec_device_type_list
&types
, CECDEVICEVEC
&devices
)
241 cec_device_type_list
t(types
);//silly, but needed to retain abi
242 CECDEVICEVEC newDevices
;
243 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
245 if (t
.IsSet((*it
)->GetType()))
246 newDevices
.push_back(*it
);
248 devices
= newDevices
;
251 void CCECDeviceMap::FilterType(const cec_device_type type
, CECDEVICEVEC
&devices
)
253 CECDEVICEVEC newDevices
;
254 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
256 if ((*it
)->GetType() == type
)
257 newDevices
.push_back(*it
);
259 devices
= newDevices
;
262 cec_logical_addresses
CCECDeviceMap::ToLogicalAddresses(const CECDEVICEVEC
&devices
)
264 cec_logical_addresses addresses
;
266 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
267 addresses
.Set((*it
)->GetLogicalAddress());
271 void CCECDeviceMap::GetChildrenOf(CECDEVICEVEC
& devices
, CCECBusDevice
* device
) const
277 uint16_t iPA
= device
->GetCurrentPhysicalAddress();
279 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
281 uint16_t iCurrentPA
= it
->second
->GetCurrentPhysicalAddress();
282 if (CCECTypeUtils::PhysicalAddressIsIncluded(iPA
, iCurrentPA
))
283 devices
.push_back(it
->second
);