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/
33 #include "CECDeviceMap.h"
34 #include "CECAudioSystem.h"
35 #include "CECPlaybackDevice.h"
36 #include "CECRecordingDevice.h"
39 #include "../CECProcessor.h"
44 CCECDeviceMap::CCECDeviceMap(CCECProcessor
*processor
) :
45 m_processor(processor
)
47 for (uint8_t iPtr
= CECDEVICE_TV
; iPtr
<= CECDEVICE_BROADCAST
; iPtr
++)
51 case CECDEVICE_AUDIOSYSTEM
:
52 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECAudioSystem(processor
, (cec_logical_address
) iPtr
)));
54 case CECDEVICE_PLAYBACKDEVICE1
:
55 case CECDEVICE_PLAYBACKDEVICE2
:
56 case CECDEVICE_PLAYBACKDEVICE3
:
57 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECPlaybackDevice(processor
, (cec_logical_address
) iPtr
)));
59 case CECDEVICE_RECORDINGDEVICE1
:
60 case CECDEVICE_RECORDINGDEVICE2
:
61 case CECDEVICE_RECORDINGDEVICE3
:
62 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECRecordingDevice(processor
, (cec_logical_address
) iPtr
)));
64 case CECDEVICE_TUNER1
:
65 case CECDEVICE_TUNER2
:
66 case CECDEVICE_TUNER3
:
67 case CECDEVICE_TUNER4
:
68 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECTuner(processor
, (cec_logical_address
) iPtr
)));
71 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECTV(processor
, (cec_logical_address
) iPtr
)));
74 m_busDevices
.insert(make_pair
<cec_logical_address
, CCECBusDevice
*>((cec_logical_address
)iPtr
, new CCECBusDevice(processor
, (cec_logical_address
) iPtr
)));
79 CCECDeviceMap::~CCECDeviceMap(void)
84 CECDEVICEMAP::iterator
CCECDeviceMap::Begin(void)
86 return m_busDevices
.begin();
89 CECDEVICEMAP::iterator
CCECDeviceMap::End(void)
91 return m_busDevices
.end();
94 void CCECDeviceMap::ResetDeviceStatus(void)
96 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
97 it
->second
->ResetDeviceStatus();
100 CCECBusDevice
*CCECDeviceMap::operator[] (cec_logical_address iAddress
) const
105 CCECBusDevice
*CCECDeviceMap::operator[] (uint8_t iAddress
) const
110 CCECBusDevice
*CCECDeviceMap::At(cec_logical_address iAddress
) const
112 return At((uint8_t) iAddress
);
115 CCECBusDevice
*CCECDeviceMap::At(uint8_t iAddress
) const
117 CECDEVICEMAP::const_iterator it
= m_busDevices
.find((cec_logical_address
)iAddress
);
118 if (it
!= m_busDevices
.end())
123 void CCECDeviceMap::Clear(void)
125 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
127 m_busDevices
.clear();
130 CCECBusDevice
*CCECDeviceMap::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
132 CCECBusDevice
*device(NULL
);
134 // check each device until we found a match
135 for (CECDEVICEMAP::iterator it
= m_busDevices
.begin(); !device
&& it
!= m_busDevices
.end(); it
++)
137 if (it
->second
->GetPhysicalAddress(m_processor
->GetLogicalAddress(), bSuppressUpdate
) == iPhysicalAddress
)
144 void CCECDeviceMap::Get(CECDEVICEVEC
&devices
) const
146 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
147 devices
.push_back(it
->second
);
150 void CCECDeviceMap::GetByLogicalAddresses(CECDEVICEVEC
&devices
, const cec_logical_addresses
&addresses
)
152 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
154 if (addresses
.IsSet(it
->first
))
155 devices
.push_back(it
->second
);
159 void CCECDeviceMap::GetByType(const cec_device_type type
, CECDEVICEVEC
&devices
) const
161 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
162 if (it
->second
->GetType() == type
)
163 devices
.push_back(it
->second
);
166 void CCECDeviceMap::GetLibCECControlled(CECDEVICEVEC
&devices
) const
168 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
169 if (it
->second
->IsHandledByLibCEC())
170 devices
.push_back(it
->second
);
173 void CCECDeviceMap::GetActive(CECDEVICEVEC
&devices
) const
175 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
177 cec_bus_device_status status
= it
->second
->GetStatus();
178 if (status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
||
179 status
== CEC_DEVICE_STATUS_PRESENT
)
180 devices
.push_back(it
->second
);
184 void CCECDeviceMap::GetPowerOffDevices(const libcec_configuration
&configuration
, CECDEVICEVEC
&devices
) const
186 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
188 if (configuration
.powerOffDevices
[(uint8_t)it
->first
])
189 devices
.push_back(it
->second
);
193 void CCECDeviceMap::GetWakeDevices(const libcec_configuration
&configuration
, CECDEVICEVEC
&devices
) const
195 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
197 if (configuration
.wakeDevices
[(uint8_t)it
->first
])
198 devices
.push_back(it
->second
);
202 CCECBusDevice
*CCECDeviceMap::GetActiveSource(void) const
204 for (CECDEVICEMAP::const_iterator it
= m_busDevices
.begin(); it
!= m_busDevices
.end(); it
++)
206 if (it
->second
->IsActiveSource())
212 void CCECDeviceMap::FilterLibCECControlled(CECDEVICEVEC
&devices
)
214 CECDEVICEVEC newDevices
;
215 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
217 if ((*it
)->IsHandledByLibCEC())
218 newDevices
.push_back(*it
);
220 devices
= newDevices
;
223 void CCECDeviceMap::FilterActive(CECDEVICEVEC
&devices
)
225 CECDEVICEVEC newDevices
;
226 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
228 cec_bus_device_status status
= (*it
)->GetCurrentStatus();
229 if (status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
||
230 status
== CEC_DEVICE_STATUS_PRESENT
)
231 newDevices
.push_back(*it
);
233 devices
= newDevices
;
236 void CCECDeviceMap::FilterTypes(const cec_device_type_list
&types
, CECDEVICEVEC
&devices
)
238 cec_device_type_list
t(types
);//silly, but needed to retain abi
239 CECDEVICEVEC newDevices
;
240 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
242 if (t
.IsSet((*it
)->GetType()))
243 newDevices
.push_back(*it
);
245 devices
= newDevices
;
248 void CCECDeviceMap::FilterType(const cec_device_type type
, CECDEVICEVEC
&devices
)
250 CECDEVICEVEC newDevices
;
251 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
253 if ((*it
)->GetType() == type
)
254 newDevices
.push_back(*it
);
256 devices
= newDevices
;
259 cec_logical_addresses
CCECDeviceMap::ToLogicalAddresses(const CECDEVICEVEC
&devices
)
261 cec_logical_addresses addresses
;
263 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
264 addresses
.Set((*it
)->GetLogicalAddress());