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"
46 CCECDeviceMap::CCECDeviceMap(CCECProcessor
*processor
) :
47 m_processor(processor
)
49 for (uint8_t iPtr
= CECDEVICE_TV
; iPtr
<= CECDEVICE_BROADCAST
; iPtr
++)
53 case CECDEVICE_AUDIOSYSTEM
:
54 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECAudioSystem(processor
, (cec_logical_address
) iPtr
)));
56 case CECDEVICE_PLAYBACKDEVICE1
:
57 case CECDEVICE_PLAYBACKDEVICE2
:
58 case CECDEVICE_PLAYBACKDEVICE3
:
59 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECPlaybackDevice(processor
, (cec_logical_address
) iPtr
)));
61 case CECDEVICE_RECORDINGDEVICE1
:
62 case CECDEVICE_RECORDINGDEVICE2
:
63 case CECDEVICE_RECORDINGDEVICE3
:
64 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECRecordingDevice(processor
, (cec_logical_address
) iPtr
)));
66 case CECDEVICE_TUNER1
:
67 case CECDEVICE_TUNER2
:
68 case CECDEVICE_TUNER3
:
69 case CECDEVICE_TUNER4
:
70 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECTuner(processor
, (cec_logical_address
) iPtr
)));
73 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECTV(processor
, (cec_logical_address
) iPtr
)));
76 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECBusDevice(processor
, (cec_logical_address
) iPtr
)));
81 CCECDeviceMap::~CCECDeviceMap(void)
86 CECDEVICEMAP::iterator
CCECDeviceMap::Begin(void)
88 return m_busDevices
.begin();
91 CECDEVICEMAP::iterator
CCECDeviceMap::End(void)
93 return m_busDevices
.end();
96 void CCECDeviceMap::ResetDeviceStatus(void)
98 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
99 it
->second
->ResetDeviceStatus();
102 CCECBusDevice
*CCECDeviceMap::operator[] (cec_logical_address iAddress
) const
107 CCECBusDevice
*CCECDeviceMap::operator[] (uint8_t iAddress
) const
112 CCECBusDevice
*CCECDeviceMap::At(cec_logical_address iAddress
) const
114 return At((uint8_t) iAddress
);
117 CCECBusDevice
*CCECDeviceMap::At(uint8_t iAddress
) const
119 CECDEVICEMAP::const_iterator it
= m_busDevices
.find((cec_logical_address
)iAddress
);
120 if (it
!= m_busDevices
.end())
125 void CCECDeviceMap::Clear(void)
127 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
129 m_busDevices
.clear();
132 CCECBusDevice
*CCECDeviceMap::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
134 CCECBusDevice
*device(NULL
);
136 // check each device until we found a match
137 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); !device
&& it
!= m_busDevices
.end(); it
++)
139 if (it
->second
->GetPhysicalAddress(m_processor
->GetLogicalAddress(), bSuppressUpdate
) == iPhysicalAddress
)
146 void CCECDeviceMap::Get(CECDEVICEVEC
&devices
) const
148 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
149 devices
.push_back(it
->second
);
152 void CCECDeviceMap::GetByLogicalAddresses(CECDEVICEVEC
&devices
, const cec_logical_addresses
&addresses
)
154 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
156 if (addresses
.IsSet(it
->first
))
157 devices
.push_back(it
->second
);
161 void CCECDeviceMap::GetByType(const cec_device_type type
, CECDEVICEVEC
&devices
) const
163 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
164 if (it
->second
->GetType() == type
)
165 devices
.push_back(it
->second
);
168 void CCECDeviceMap::GetLibCECControlled(CECDEVICEVEC
&devices
) const
170 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
171 if (it
->second
->IsHandledByLibCEC())
172 devices
.push_back(it
->second
);
175 void CCECDeviceMap::GetActive(CECDEVICEVEC
&devices
) const
177 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
179 cec_bus_device_status status
= it
->second
->GetStatus();
180 if (status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
||
181 status
== CEC_DEVICE_STATUS_PRESENT
)
182 devices
.push_back(it
->second
);
186 void CCECDeviceMap::GetPowerOffDevices(const libcec_configuration
&configuration
, CECDEVICEVEC
&devices
) const
188 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
190 if (configuration
.powerOffDevices
[(uint8_t)it
->first
])
191 devices
.push_back(it
->second
);
195 void CCECDeviceMap::GetWakeDevices(const libcec_configuration
&configuration
, CECDEVICEVEC
&devices
) const
197 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
199 if (configuration
.wakeDevices
[(uint8_t)it
->first
])
200 devices
.push_back(it
->second
);
204 CCECBusDevice
*CCECDeviceMap::GetActiveSource(void) const
206 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
208 if (it
->second
->IsActiveSource())
214 void CCECDeviceMap::FilterLibCECControlled(CECDEVICEVEC
&devices
)
216 CECDEVICEVEC newDevices
;
217 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
219 if ((*it
)->IsHandledByLibCEC())
220 newDevices
.push_back(*it
);
222 devices
= newDevices
;
225 void CCECDeviceMap::FilterActive(CECDEVICEVEC
&devices
)
227 CECDEVICEVEC newDevices
;
228 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
230 cec_bus_device_status status
= (*it
)->GetCurrentStatus();
231 if (status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
||
232 status
== CEC_DEVICE_STATUS_PRESENT
)
233 newDevices
.push_back(*it
);
235 devices
= newDevices
;
238 void CCECDeviceMap::FilterTypes(const cec_device_type_list
&types
, CECDEVICEVEC
&devices
)
240 cec_device_type_list
t(types
);//silly, but needed to retain abi
241 CECDEVICEVEC newDevices
;
242 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
244 if (t
.IsSet((*it
)->GetType()))
245 newDevices
.push_back(*it
);
247 devices
= newDevices
;
250 void CCECDeviceMap::FilterType(const cec_device_type type
, CECDEVICEVEC
&devices
)
252 CECDEVICEVEC newDevices
;
253 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
255 if ((*it
)->GetType() == type
)
256 newDevices
.push_back(*it
);
258 devices
= newDevices
;
261 cec_logical_addresses
CCECDeviceMap::ToLogicalAddresses(const CECDEVICEVEC
&devices
)
263 cec_logical_addresses addresses
;
265 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
266 addresses
.Set((*it
)->GetLogicalAddress());