cec: drop no longer needed parameters for CCECCommandHandler::Transmit()
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
CommitLineData
e9de9629
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
b492c10e 4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
e9de9629
LOK
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
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.
13 *
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.
18 *
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.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
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/
31 */
32
33#include "CECBusDevice.h"
eafa9d46
LOK
34#include "../CECProcessor.h"
35#include "../implementations/ANCommandHandler.h"
36#include "../implementations/CECCommandHandler.h"
37#include "../implementations/SLCommandHandler.h"
11621576 38#include "../implementations/VLCommandHandler.h"
5477a250 39#include "../LibCEC.h"
ba65909d 40#include "../platform/util/timeutils.h"
e9de9629
LOK
41
42using namespace CEC;
f00ff009 43using namespace PLATFORM;
e9de9629 44
03ae897d 45#define ToString(p) m_processor->ToString(p)
c4098482 46
e9de9629 47CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
ecc676ca
LOK
48 m_type (CEC_DEVICE_TYPE_RESERVED),
49 m_iPhysicalAddress (iPhysicalAddress),
50 m_iStreamPath (0),
51 m_iLogicalAddress (iLogicalAddress),
52 m_powerStatus (CEC_POWER_STATUS_UNKNOWN),
53 m_processor (processor),
54 m_vendor (CEC_VENDOR_UNKNOWN),
55 m_bReplaceHandler (false),
56 m_menuState (CEC_MENU_STATE_ACTIVATED),
57 m_bActiveSource (false),
58 m_iLastActive (0),
59 m_iLastPowerStateUpdate (0),
60 m_cecVersion (CEC_VERSION_UNKNOWN),
61 m_deviceStatus (CEC_DEVICE_STATUS_UNKNOWN),
62 m_iHandlerUseCount (0),
ebb6ddb3 63 m_bAwaitingReceiveFailed(false),
ecc676ca 64 m_bVendorIdRequested (false)
e9de9629
LOK
65{
66 m_handler = new CCECCommandHandler(this);
51b2a094 67
a3269a0a
LOK
68 for (unsigned int iPtr = 0; iPtr < 4; iPtr++)
69 m_menuLanguage.language[iPtr] = '?';
70 m_menuLanguage.language[3] = 0;
71 m_menuLanguage.device = iLogicalAddress;
1fcf5a3f 72
c4098482 73 m_strDeviceName = ToString(m_iLogicalAddress);
e9de9629
LOK
74}
75
76CCECBusDevice::~CCECBusDevice(void)
77{
78 delete m_handler;
79}
80
93729720 81bool CCECBusDevice::HandleCommand(const cec_command &command)
f8513317 82{
7f919115
LOK
83 bool bHandled(false);
84
85 /* update "last active" */
8fa35473 86 {
f00ff009 87 CLockObject lock(m_mutex);
8fa35473 88 m_iLastActive = GetTimeMs();
f4b7b1dc 89
ba427965 90 /* don't call GetStatus() here, just read the value with the mutex locked */
d297cbd4 91 if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC && command.opcode_set == 1)
f4b7b1dc 92 m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
1344fd1a
LOK
93
94 MarkBusy();
8fa35473
LOK
95 }
96
7f919115
LOK
97 /* handle the command */
98 bHandled = m_handler->HandleCommand(command);
8fa35473 99
7f919115
LOK
100 /* change status to present */
101 if (bHandled)
8d915412 102 {
f00ff009 103 CLockObject lock(m_mutex);
8fa35473 104 if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
8d915412 105 {
8fa35473 106 if (m_deviceStatus != CEC_DEVICE_STATUS_PRESENT)
5477a250 107 CLibCEC::AddLog(CEC_LOG_DEBUG, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command.opcode));
8fa35473 108 m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
8d915412 109 }
8d915412 110 }
7f919115 111
1344fd1a 112 MarkReady();
7f919115 113 return bHandled;
93729720
LOK
114}
115
93729720
LOK
116bool CCECBusDevice::PowerOn(void)
117{
1344fd1a 118 bool bReturn(false);
f4698390 119 GetVendorId(); // ensure that we got the vendor id, because the implementations vary per vendor
c6d7f0e1 120
1344fd1a 121 MarkBusy();
8670c970
LOK
122 cec_power_status currentStatus = GetPowerStatus(false);
123 if (currentStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON &&
124 currentStatus != CEC_POWER_STATUS_ON)
5e5637c6 125 {
8670c970
LOK
126 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
127 if (m_handler->PowerOn(GetMyLogicalAddress(), m_iLogicalAddress))
128 {
129 SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
130 bReturn = true;
131 }
132 }
133 else
134 {
135 CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' (%X) is already '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(currentStatus));
f437e4be
LOK
136 }
137
1344fd1a
LOK
138 MarkReady();
139 return bReturn;
93729720
LOK
140}
141
142bool CCECBusDevice::Standby(void)
143{
5477a250 144 CLibCEC::AddLog(CEC_LOG_DEBUG, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress);
1344fd1a
LOK
145 MarkBusy();
146 bool bReturn = m_handler->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress);
147 MarkReady();
148 return bReturn;
93729720
LOK
149}
150
151/** @name Getters */
152//@{
7f919115 153cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */)
93729720 154{
6bbfc3f7 155 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
97fc4ffb
LOK
156 bool bRequestUpdate(false);
157 {
f00ff009 158 CLockObject lock(m_mutex);
ddb6ac5b 159 bRequestUpdate = bIsPresent &&
6bbfc3f7 160 (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN);
97fc4ffb
LOK
161 }
162
163 if (bRequestUpdate)
ebb6ddb3
LOK
164 {
165 CheckVendorIdRequested();
f294b22f 166 RequestCecVersion();
ebb6ddb3 167 }
f294b22f 168
f00ff009 169 CLockObject lock(m_mutex);
f294b22f
LOK
170 return m_cecVersion;
171}
172
a75e3a5a 173bool CCECBusDevice::RequestCecVersion(bool bWaitForResponse /* = true */)
f294b22f
LOK
174{
175 bool bReturn(false);
b64db02e 176
66c3ef5a
LOK
177 if (!MyLogicalAddressContains(m_iLogicalAddress) &&
178 !IsUnsupportedFeature(CEC_OPCODE_GET_CEC_VERSION))
93729720 179 {
1344fd1a 180 MarkBusy();
5477a250 181 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
8fa35473 182
a75e3a5a 183 bReturn = m_handler->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress, bWaitForResponse);
1344fd1a 184 MarkReady();
93729720 185 }
f294b22f 186 return bReturn;
93729720
LOK
187}
188
62f5527d
LOK
189const char* CCECBusDevice::GetLogicalAddressName(void) const
190{
c4098482 191 return ToString(m_iLogicalAddress);
62f5527d
LOK
192}
193
7f919115 194cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */)
93729720 195{
6bbfc3f7 196 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
97fc4ffb
LOK
197 bool bRequestUpdate(false);
198 {
f00ff009 199 CLockObject lock(m_mutex);
ddb6ac5b 200 bRequestUpdate = (bIsPresent &&
97fc4ffb
LOK
201 (bUpdate || !strcmp(m_menuLanguage.language, "???")));
202 }
203
204 if (bRequestUpdate)
ebb6ddb3
LOK
205 {
206 CheckVendorIdRequested();
f294b22f 207 RequestMenuLanguage();
ebb6ddb3 208 }
5e5637c6 209
f00ff009 210 CLockObject lock(m_mutex);
f294b22f
LOK
211 return m_menuLanguage;
212}
213
a75e3a5a 214bool CCECBusDevice::RequestMenuLanguage(bool bWaitForResponse /* = true */)
f294b22f
LOK
215{
216 bool bReturn(false);
b64db02e 217
4d738fe3
LOK
218 if (!MyLogicalAddressContains(m_iLogicalAddress) &&
219 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE))
93729720 220 {
1344fd1a 221 MarkBusy();
5477a250 222 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
a75e3a5a 223 bReturn = m_handler->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress, bWaitForResponse);
1344fd1a 224 MarkReady();
93729720 225 }
f294b22f 226 return bReturn;
93729720
LOK
227}
228
3e61b350
LOK
229cec_menu_state CCECBusDevice::GetMenuState(void)
230{
f00ff009 231 CLockObject lock(m_mutex);
3e61b350
LOK
232 return m_menuState;
233}
234
93729720
LOK
235cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const
236{
237 return m_processor->GetLogicalAddress();
f8513317
LOK
238}
239
e9de9629
LOK
240uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
241{
242 return m_processor->GetPhysicalAddress();
243}
244
7f919115 245CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */)
ed21be2a 246{
6bbfc3f7 247 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
97fc4ffb
LOK
248 bool bRequestUpdate(false);
249 {
f00ff009 250 CLockObject lock(m_mutex);
ddb6ac5b 251 bRequestUpdate = bIsPresent &&
97fc4ffb 252 (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) &&
ddb6ac5b 253 m_type != CEC_DEVICE_TYPE_TV;
97fc4ffb
LOK
254 }
255
256 if (bRequestUpdate)
ebb6ddb3
LOK
257 {
258 CheckVendorIdRequested();
5e5637c6 259 RequestOSDName();
ebb6ddb3 260 }
5e5637c6 261
f00ff009 262 CLockObject lock(m_mutex);
ed21be2a
LOK
263 return m_strDeviceName;
264}
265
a75e3a5a 266bool CCECBusDevice::RequestOSDName(bool bWaitForResponse /* = true */)
ed21be2a
LOK
267{
268 bool bReturn(false);
b64db02e 269
4d738fe3
LOK
270 if (!MyLogicalAddressContains(m_iLogicalAddress) &&
271 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME))
ed21be2a 272 {
1344fd1a 273 MarkBusy();
5477a250 274 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
a75e3a5a 275 bReturn = m_handler->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress, bWaitForResponse);
1344fd1a 276 MarkReady();
ed21be2a
LOK
277 }
278 return bReturn;
279}
280
0680dab3 281uint16_t CCECBusDevice::GetPhysicalAddress(bool bSuppressUpdate /* = true */)
16b1e052 282{
0680dab3 283 if (!bSuppressUpdate)
16b1e052 284 {
0680dab3
LOK
285 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
286 bool bRequestUpdate(false);
287 {
288 CLockObject lock(m_mutex);
289 bRequestUpdate = bIsPresent && m_iPhysicalAddress == 0xFFFF;
290 }
16b1e052 291
0680dab3
LOK
292 if (bRequestUpdate)
293 {
294 CheckVendorIdRequested();
295 if (!RequestPhysicalAddress())
296 CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address");
297 }
ebb6ddb3 298 }
97fc4ffb 299
f00ff009 300 CLockObject lock(m_mutex);
16b1e052
LOK
301 return m_iPhysicalAddress;
302}
303
a75e3a5a 304bool CCECBusDevice::RequestPhysicalAddress(bool bWaitForResponse /* = true */)
16b1e052
LOK
305{
306 bool bReturn(false);
b64db02e 307
16b1e052
LOK
308 if (!MyLogicalAddressContains(m_iLogicalAddress))
309 {
1344fd1a 310 MarkBusy();
5477a250 311 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
a75e3a5a 312 bReturn = m_handler->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress, bWaitForResponse);
1344fd1a 313 MarkReady();
16b1e052
LOK
314 }
315 return bReturn;
316}
317
7f919115 318cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */)
e9de9629 319{
6bbfc3f7 320 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
97fc4ffb
LOK
321 bool bRequestUpdate(false);
322 {
f00ff009 323 CLockObject lock(m_mutex);
ddb6ac5b 324 bRequestUpdate = (bIsPresent &&
c8f0eef0 325 (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN ||
2efa39b7
LOK
326 m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON ||
327 m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY ||
328 GetTimeMs() - m_iLastPowerStateUpdate >= CEC_POWER_STATE_REFRESH_TIME));
97fc4ffb
LOK
329 }
330
331 if (bRequestUpdate)
ebb6ddb3
LOK
332 {
333 CheckVendorIdRequested();
f294b22f 334 RequestPowerStatus();
ebb6ddb3 335 }
5e5637c6 336
f00ff009 337 CLockObject lock(m_mutex);
f294b22f
LOK
338 return m_powerStatus;
339}
340
a75e3a5a 341bool CCECBusDevice::RequestPowerStatus(bool bWaitForResponse /* = true */)
f294b22f
LOK
342{
343 bool bReturn(false);
b64db02e 344
4d738fe3
LOK
345 if (!MyLogicalAddressContains(m_iLogicalAddress) &&
346 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS))
93729720 347 {
1344fd1a 348 MarkBusy();
5477a250 349 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
a75e3a5a 350 bReturn = m_handler->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress, bWaitForResponse);
1344fd1a 351 MarkReady();
93729720 352 }
f294b22f
LOK
353 return bReturn;
354}
93729720 355
7f919115 356cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */)
f294b22f 357{
6bbfc3f7 358 bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
97fc4ffb
LOK
359 bool bRequestUpdate(false);
360 {
f00ff009 361 CLockObject lock(m_mutex);
ddb6ac5b 362 bRequestUpdate = (bIsPresent &&
97fc4ffb
LOK
363 (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN));
364 }
365
366 if (bRequestUpdate)
f294b22f 367 RequestVendorId();
5e5637c6 368
f00ff009 369 CLockObject lock(m_mutex);
f294b22f 370 return m_vendor;
e9de9629
LOK
371}
372
a75e3a5a 373bool CCECBusDevice::RequestVendorId(bool bWaitForResponse /* = true */)
a3269a0a 374{
f294b22f 375 bool bReturn(false);
b64db02e 376
63b56678 377 if (!MyLogicalAddressContains(m_iLogicalAddress) && GetMyLogicalAddress() != CECDEVICE_UNKNOWN)
a3269a0a 378 {
1344fd1a 379 MarkBusy();
5477a250 380 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
a75e3a5a 381 bReturn = m_handler->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress, bWaitForResponse);
1344fd1a 382 MarkReady();
3e61b350 383
a75e3a5a
LOK
384 if (bWaitForResponse)
385 ReplaceHandler(true);
a3269a0a 386 }
f294b22f 387 return bReturn;
93729720
LOK
388}
389
7f919115 390const char *CCECBusDevice::GetVendorName(bool bUpdate /* = false */)
c4098482 391{
7f919115 392 return ToString(GetVendorId(bUpdate));
c4098482
LOK
393}
394
93729720
LOK
395bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
396{
397 return m_processor->HasLogicalAddress(address);
a3269a0a
LOK
398}
399
9fd73dd4
LOK
400bool CCECBusDevice::NeedsPoll(void)
401{
402 bool bSendPoll(false);
403 switch (m_iLogicalAddress)
404 {
405 case CECDEVICE_PLAYBACKDEVICE3:
c6d7f0e1
LOK
406 {
407 cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_PLAYBACKDEVICE2]->GetStatus();
408 bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
409 }
9fd73dd4
LOK
410 break;
411 case CECDEVICE_PLAYBACKDEVICE2:
c6d7f0e1
LOK
412 {
413 cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_PLAYBACKDEVICE1]->GetStatus();
414 bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
415 }
9fd73dd4
LOK
416 break;
417 case CECDEVICE_RECORDINGDEVICE3:
c6d7f0e1
LOK
418 {
419 cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_RECORDINGDEVICE2]->GetStatus();
420 bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
421 }
9fd73dd4
LOK
422 break;
423 case CECDEVICE_RECORDINGDEVICE2:
c6d7f0e1
LOK
424 {
425 cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_RECORDINGDEVICE1]->GetStatus();
426 bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
427 }
9fd73dd4
LOK
428 break;
429 case CECDEVICE_TUNER4:
c6d7f0e1
LOK
430 {
431 cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_TUNER3]->GetStatus();
432 bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
433 }
9fd73dd4
LOK
434 break;
435 case CECDEVICE_TUNER3:
c6d7f0e1
LOK
436 {
437 cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_TUNER2]->GetStatus();
438 bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
439 }
9fd73dd4
LOK
440 break;
441 case CECDEVICE_TUNER2:
c6d7f0e1
LOK
442 {
443 cec_bus_device_status status = m_processor->m_busDevices[CECDEVICE_TUNER1]->GetStatus();
444 bSendPoll = (status == CEC_DEVICE_STATUS_PRESENT || status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
445 }
9fd73dd4
LOK
446 break;
447 case CECDEVICE_AUDIOSYSTEM:
448 case CECDEVICE_PLAYBACKDEVICE1:
449 case CECDEVICE_RECORDINGDEVICE1:
450 case CECDEVICE_TUNER1:
451 case CECDEVICE_TV:
452 bSendPoll = true;
453 break;
454 default:
455 break;
456 }
457
458 return bSendPoll;
459}
460
a75e3a5a 461cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */, bool bSuppressPoll /* = false */)
f8ae3295 462{
ba427965
LOK
463 cec_bus_device_status status(CEC_DEVICE_STATUS_UNKNOWN);
464 bool bNeedsPoll(false);
465
466 {
467 CLockObject lock(m_mutex);
468 status = m_deviceStatus;
a75e3a5a
LOK
469 bNeedsPoll = !bSuppressPoll &&
470 (bForcePoll || m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN);
ba427965
LOK
471 }
472
473 if (bNeedsPoll)
f8ae3295 474 {
9fd73dd4 475 bool bPollAcked(false);
7b62b76e 476 if (bNeedsPoll && NeedsPoll())
9fd73dd4 477 bPollAcked = m_processor->PollDevice(m_iLogicalAddress);
95a73fa7 478
ba427965
LOK
479 status = bPollAcked ? CEC_DEVICE_STATUS_PRESENT : CEC_DEVICE_STATUS_NOT_PRESENT;
480 SetDeviceStatus(status);
f8ae3295
LOK
481 }
482
ba427965 483 return status;
f8ae3295
LOK
484}
485
93729720
LOK
486//@}
487
488/** @name Setters */
489//@{
e55f3f70 490void CCECBusDevice::SetCecVersion(const cec_version newVersion)
6a1c0009 491{
a20d808d
LOK
492 if (m_cecVersion != newVersion)
493 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion));
6a1c0009 494 m_cecVersion = newVersion;
6a1c0009
LOK
495}
496
93729720
LOK
497void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
498{
f00ff009 499 CLockObject lock(m_mutex);
a20d808d
LOK
500 if (language.device == m_iLogicalAddress &&
501 strcmp(language.language, m_menuLanguage.language))
93729720 502 {
5477a250 503 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language);
93729720
LOK
504 m_menuLanguage = language;
505 }
506}
507
15d1a84c
LOK
508void CCECBusDevice::SetOSDName(CStdString strName)
509{
f00ff009 510 CLockObject lock(m_mutex);
15d1a84c
LOK
511 if (m_strDeviceName != strName)
512 {
5477a250 513 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName.c_str());
15d1a84c
LOK
514 m_strDeviceName = strName;
515 }
516}
517
28fa6c97
LOK
518void CCECBusDevice::SetMenuState(const cec_menu_state state)
519{
f00ff009 520 CLockObject lock(m_mutex);
28fa6c97
LOK
521 if (m_menuState != state)
522 {
5477a250 523 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState));
28fa6c97
LOK
524 m_menuState = state;
525 }
526}
527
3fd2a2b8 528void CCECBusDevice::SetInactiveSource(void)
7856411b 529{
3fd2a2b8 530 {
f00ff009 531 CLockObject lock(m_mutex);
24dd566c
LOK
532 if (m_bActiveSource)
533 CLibCEC::AddLog(CEC_LOG_DEBUG, "marking %s (%X) as inactive source", GetLogicalAddressName(), m_iLogicalAddress);
3fd2a2b8
LOK
534 m_bActiveSource = false;
535 }
536
537 if (MyLogicalAddressContains(m_iLogicalAddress))
538 SetPowerStatus(CEC_POWER_STATUS_STANDBY);
7856411b
LOK
539}
540
37b0c572 541void CCECBusDevice::SetActiveSource(void)
7856411b 542{
f00ff009 543 CLockObject lock(m_mutex);
ff684fef 544 if (!m_bActiveSource)
5477a250 545 CLibCEC::AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress);
7856411b
LOK
546
547 for (int iPtr = 0; iPtr < 16; iPtr++)
548 if (iPtr != m_iLogicalAddress)
3fd2a2b8 549 m_processor->m_busDevices[iPtr]->SetInactiveSource();
7856411b
LOK
550
551 m_bActiveSource = true;
9a2f12df 552 SetPowerStatus(CEC_POWER_STATUS_ON);
7856411b
LOK
553}
554
93fff5c1
LOK
555bool CCECBusDevice::TryLogicalAddress(void)
556{
5477a250 557 CLibCEC::AddLog(CEC_LOG_DEBUG, "trying logical address '%s'", GetLogicalAddressName());
93fff5c1 558
b81f75db 559 m_processor->SetAckMask(0);
93fff5c1
LOK
560 if (!TransmitPoll(m_iLogicalAddress))
561 {
5477a250 562 CLibCEC::AddLog(CEC_LOG_NOTICE, "using logical address '%s'", GetLogicalAddressName());
93fff5c1
LOK
563 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
564
565 return true;
566 }
567
5477a250 568 CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address '%s' already taken", GetLogicalAddressName());
93fff5c1
LOK
569 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT);
570 return false;
571}
572
a20d808d
LOK
573void CCECBusDevice::ResetDeviceStatus(void)
574{
575 CLockObject lock(m_mutex);
576 SetPowerStatus (CEC_POWER_STATUS_UNKNOWN);
577 SetVendorId (CEC_VENDOR_UNKNOWN);
578 SetMenuState (CEC_MENU_STATE_ACTIVATED);
579 SetCecVersion (CEC_VERSION_UNKNOWN);
580 SetStreamPath (0);
581 SetOSDName (ToString(m_iLogicalAddress));
582 SetInactiveSource();
583 m_iLastActive = 0;
584}
585
93fff5c1
LOK
586void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
587{
93fff5c1 588 {
ee17ad58
LOK
589 CLockObject lock(m_mutex);
590 switch (newStatus)
591 {
592 case CEC_DEVICE_STATUS_UNKNOWN:
593 if (m_deviceStatus != newStatus)
594 CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'unknown'", ToString(m_iLogicalAddress));
a20d808d
LOK
595 ResetDeviceStatus();
596 m_deviceStatus = newStatus;
ee17ad58
LOK
597 break;
598 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC:
599 if (m_deviceStatus != newStatus)
600 CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'handled by libCEC'", ToString(m_iLogicalAddress));
a20d808d
LOK
601 SetPowerStatus (CEC_POWER_STATUS_ON);
602 SetVendorId (CEC_VENDOR_UNKNOWN);
603 SetMenuState (CEC_MENU_STATE_ACTIVATED);
604 SetCecVersion (CEC_VERSION_1_3A);
605 SetStreamPath (0);
606 SetInactiveSource();
607 m_iLastActive = 0;
608 m_deviceStatus = newStatus;
ee17ad58
LOK
609 break;
610 case CEC_DEVICE_STATUS_PRESENT:
611 if (m_deviceStatus != newStatus)
612 CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'present'", ToString(m_iLogicalAddress));
613 m_deviceStatus = newStatus;
614 break;
615 case CEC_DEVICE_STATUS_NOT_PRESENT:
616 if (m_deviceStatus != newStatus)
a20d808d 617 {
ee17ad58 618 CLibCEC::AddLog(CEC_LOG_DEBUG, "device status of %s changed into 'not present'", ToString(m_iLogicalAddress));
a20d808d
LOK
619 ResetDeviceStatus();
620 m_deviceStatus = newStatus;
621 }
ee17ad58
LOK
622 break;
623 }
93fff5c1 624 }
ee17ad58
LOK
625
626 if (newStatus == CEC_DEVICE_STATUS_PRESENT)
a75e3a5a 627 RequestVendorId(false);
93fff5c1
LOK
628}
629
9dc04b07 630void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
93729720 631{
f00ff009 632 CLockObject lock(m_mutex);
b8176e3c 633 if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress)
93729720 634 {
5477a250 635 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
93729720
LOK
636 m_iPhysicalAddress = iNewAddress;
637 }
638}
639
9dc04b07
LOK
640void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
641{
f00ff009 642 CLockObject lock(m_mutex);
9dc04b07
LOK
643 if (iNewAddress > 0)
644 {
5477a250 645 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress);
9dc04b07 646 m_iStreamPath = iNewAddress;
96274140 647
a75e3a5a 648 // suppress polls when searching for a device
0680dab3 649 CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress);
0cb55c43
LOK
650 if (device)
651 {
652 // if a device is found with the new physical address, mark it as active, which will automatically mark all other devices as inactive
653 device->SetActiveSource();
654 }
655 else
656 {
657 // try to find the device with the old address, and mark it as inactive when found
0680dab3 658 device = m_processor->GetDeviceByPhysicalAddress(iOldAddress);
0cb55c43
LOK
659 if (device)
660 device->SetInactiveSource();
661 }
662
96274140 663 if (iNewAddress > 0)
81a1e39d 664 {
f00ff009 665 lock.Unlock();
96274140 666 SetPowerStatus(CEC_POWER_STATUS_ON);
81a1e39d 667 }
9dc04b07
LOK
668 }
669}
670
e55f3f70
LOK
671void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
672{
f00ff009 673 CLockObject lock(m_mutex);
b0271d54
LOK
674 if (m_powerStatus != powerStatus)
675 {
2efa39b7 676 m_iLastPowerStateUpdate = GetTimeMs();
5477a250 677 CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus));
b0271d54
LOK
678 m_powerStatus = powerStatus;
679 }
e55f3f70
LOK
680}
681
1344fd1a
LOK
682void CCECBusDevice::MarkBusy(void)
683{
684 CLockObject handlerLock(m_handlerMutex);
685 ++m_iHandlerUseCount;
686}
687
688void CCECBusDevice::MarkReady(void)
689{
690 CLockObject handlerLock(m_handlerMutex);
691 if (m_iHandlerUseCount > 0)
692 --m_iHandlerUseCount;
693}
694
3e61b350 695bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */)
e9de9629 696{
94e9a2af
LOK
697 bool bInitHandler(false);
698 {
699 CTryLockObject lock(m_mutex);
700 if (!lock.IsLocked())
701 return false;
2563e7eb 702
94e9a2af
LOK
703 CLockObject handlerLock(m_handlerMutex);
704 if (m_iHandlerUseCount > 0)
705 return false;
d211708b 706
94e9a2af 707 MarkBusy();
104125dc 708
94e9a2af 709 if (m_vendor != m_handler->GetVendorId())
3e61b350 710 {
94e9a2af 711 if (CCECCommandHandler::HasSpecificHandler(m_vendor))
2e49a6e4 712 {
94e9a2af
LOK
713 CLibCEC::AddLog(CEC_LOG_DEBUG, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
714 delete m_handler;
715
716 switch (m_vendor)
717 {
718 case CEC_VENDOR_SAMSUNG:
719 m_handler = new CANCommandHandler(this);
720 break;
721 case CEC_VENDOR_LG:
722 m_handler = new CSLCommandHandler(this);
723 break;
724 case CEC_VENDOR_PANASONIC:
725 m_handler = new CVLCommandHandler(this);
726 break;
727 default:
728 m_handler = new CCECCommandHandler(this);
729 break;
730 }
731
732 m_handler->SetVendorId(m_vendor);
733 bInitHandler = true;
2e49a6e4 734 }
2e49a6e4 735 }
e9de9629
LOK
736 }
737
104125dc
LOK
738 if (bInitHandler)
739 {
740 m_handler->InitHandler();
741
742 if (bActivateSource && m_processor->GetLogicalAddresses().IsSet(m_iLogicalAddress) && m_processor->IsInitialised() && IsActiveSource())
743 m_handler->ActivateSource();
744 }
745
746 MarkReady();
747
b64db02e
LOK
748 return true;
749}
750
3e61b350 751bool CCECBusDevice::SetVendorId(uint64_t iVendorId)
b64db02e
LOK
752{
753 bool bVendorChanged(false);
754
755 {
f00ff009 756 CLockObject lock(m_mutex);
b64db02e
LOK
757 bVendorChanged = (m_vendor != (cec_vendor_id)iVendorId);
758 m_vendor = (cec_vendor_id)iVendorId;
b64db02e 759 }
8d915412 760
a20d808d
LOK
761 if (bVendorChanged)
762 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor);
8fa35473
LOK
763
764 return bVendorChanged;
e9de9629 765}
93729720 766//@}
e9de9629 767
93729720
LOK
768/** @name Transmit methods */
769//@{
770bool CCECBusDevice::TransmitActiveSource(void)
0f23c85c 771{
8fa35473 772 bool bSendActiveSource(false);
0f23c85c 773
8747dd4f 774 {
f00ff009 775 CLockObject lock(m_mutex);
49c8f2e4 776 if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)
5477a250 777 CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress);
8fa35473
LOK
778 else if (m_bActiveSource)
779 {
5477a250 780 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
8fa35473
LOK
781 bSendActiveSource = true;
782 }
783 else
5477a250 784 CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress);
8747dd4f
LOK
785 }
786
b64db02e
LOK
787 if (bSendActiveSource)
788 {
1344fd1a 789 MarkBusy();
468a1414 790 m_handler->TransmitActiveSource(m_iLogicalAddress, m_iPhysicalAddress);
1344fd1a 791 MarkReady();
b64db02e
LOK
792 return true;
793 }
794
795 return false;
0f23c85c
LOK
796}
797
29912296 798bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
0f23c85c 799{
8fa35473
LOK
800 cec_version version;
801 {
f00ff009 802 CLockObject lock(m_mutex);
5477a250 803 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion));
8fa35473
LOK
804 version = m_cecVersion;
805 }
0f23c85c 806
1344fd1a
LOK
807 MarkBusy();
808 bool bReturn = m_handler->TransmitCECVersion(m_iLogicalAddress, dest, version);
809 MarkReady();
810 return bReturn;
0f23c85c
LOK
811}
812
49c8f2e4
LOK
813bool CCECBusDevice::TransmitImageViewOn(void)
814{
49c8f2e4 815 {
9a2f12df
LOK
816 CLockObject lock(m_mutex);
817 if (m_powerStatus != CEC_POWER_STATUS_ON && m_powerStatus != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON)
818 {
819 CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress);
820 return false;
821 }
49c8f2e4 822 }
9a2f12df
LOK
823
824 MarkBusy();
825 m_handler->TransmitImageViewOn(m_iLogicalAddress, CECDEVICE_TV);
826 MarkReady();
827 return true;
49c8f2e4
LOK
828}
829
ab27363d 830bool CCECBusDevice::TransmitInactiveSource(void)
93729720 831{
8fa35473
LOK
832 uint16_t iPhysicalAddress;
833 {
f00ff009 834 CLockObject lock(m_mutex);
5477a250 835 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress);
8fa35473
LOK
836 iPhysicalAddress = m_iPhysicalAddress;
837 }
93729720 838
1344fd1a
LOK
839 MarkBusy();
840 bool bReturn = m_handler->TransmitInactiveSource(m_iLogicalAddress, iPhysicalAddress);
841 MarkReady();
842 return bReturn;
93729720
LOK
843}
844
29912296 845bool CCECBusDevice::TransmitMenuState(cec_logical_address dest)
0f23c85c 846{
8fa35473
LOK
847 cec_menu_state menuState;
848 {
f00ff009 849 CLockObject lock(m_mutex);
5477a250 850 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState));
8fa35473
LOK
851 menuState = m_menuState;
852 }
0f23c85c 853
1344fd1a
LOK
854 MarkBusy();
855 bool bReturn = m_handler->TransmitMenuState(m_iLogicalAddress, dest, menuState);
856 MarkReady();
857 return bReturn;
0f23c85c
LOK
858}
859
29912296 860bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
0f23c85c 861{
8fa35473
LOK
862 CStdString strDeviceName;
863 {
f00ff009 864 CLockObject lock(m_mutex);
5477a250 865 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str());
8fa35473
LOK
866 strDeviceName = m_strDeviceName;
867 }
0f23c85c 868
1344fd1a
LOK
869 MarkBusy();
870 bool bReturn = m_handler->TransmitOSDName(m_iLogicalAddress, dest, strDeviceName);
871 MarkReady();
872 return bReturn;
0f23c85c
LOK
873}
874
38bdb943
LOK
875bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
876{
1344fd1a 877 bool bReturn(false);
66c3ef5a 878 if (!m_processor->m_busDevices[dest]->IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING))
4d738fe3 879 {
5477a250 880 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage);
1344fd1a
LOK
881 MarkBusy();
882 bReturn = m_handler->TransmitOSDString(m_iLogicalAddress, dest, duration, strMessage);
883 MarkReady();
4d738fe3 884 }
1344fd1a 885 return bReturn;
38bdb943
LOK
886}
887
29912296 888bool CCECBusDevice::TransmitPhysicalAddress(void)
0f23c85c 889{
8fa35473
LOK
890 uint16_t iPhysicalAddress;
891 cec_device_type type;
892 {
f00ff009 893 CLockObject lock(m_mutex);
8fa35473
LOK
894 if (m_iPhysicalAddress == 0xffff)
895 return false;
2bdfdeef 896
5477a250 897 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
8fa35473
LOK
898 iPhysicalAddress = m_iPhysicalAddress;
899 type = m_type;
900 }
0f23c85c 901
1344fd1a
LOK
902 MarkBusy();
903 bool bReturn = m_handler->TransmitPhysicalAddress(m_iLogicalAddress, iPhysicalAddress, type);
904 MarkReady();
905 return bReturn;
0f23c85c
LOK
906}
907
fbdea54c
MK
908bool CCECBusDevice::TransmitSetMenuLanguage(cec_logical_address dest)
909{
910 bool bReturn(false);
911 cec_menu_language language = GetMenuLanguage();
912
913 char lang[3];
914 {
915 CLockObject lock(m_mutex);
916 lang[0] = language.language[0];
917 lang[1] = language.language[1];
918 lang[2] = language.language[2];
919 }
920
921 MarkBusy();
922 if (lang[0] == '?' && lang[1] == '?' && lang[2] == '?')
923 {
924 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): Menu language feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
925 m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
926 bReturn = true;
927 }
928 else
929 {
930 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): Menu language '%s'", GetLogicalAddressName(), m_iLogicalAddress, lang);
931 bReturn = m_handler->TransmitSetMenuLanguage(m_iLogicalAddress, lang);
932 }
933 MarkReady();
934 return bReturn;
935}
936
93729720 937bool CCECBusDevice::TransmitPoll(cec_logical_address dest)
57f45e6c
LOK
938{
939 bool bReturn(false);
93729720
LOK
940 if (dest == CECDEVICE_UNKNOWN)
941 dest = m_iLogicalAddress;
f8513317 942
b750a5c3
LOK
943 CCECBusDevice *destDevice = m_processor->m_busDevices[dest];
944 if (destDevice->m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
945 return bReturn;
946
1344fd1a 947 MarkBusy();
5477a250 948 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
8fa35473 949 bReturn = m_handler->TransmitPoll(m_iLogicalAddress, dest);
5477a250 950 CLibCEC::AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent");
8fa35473 951
f00ff009 952 CLockObject lock(m_mutex);
1674de37 953 if (bReturn)
8fa35473 954 {
1674de37 955 m_iLastActive = GetTimeMs();
b750a5c3 956 destDevice->m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
8fa35473 957 }
b750a5c3
LOK
958 else
959 destDevice->m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT;
1674de37 960
1344fd1a 961 MarkReady();
57f45e6c
LOK
962 return bReturn;
963}
93729720
LOK
964
965bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
966{
8fa35473
LOK
967 cec_power_status state;
968 {
f00ff009 969 CLockObject lock(m_mutex);
bbc71623 970 if (!IsActiveSource())
24dd566c
LOK
971 {
972 CLibCEC::AddLog(CEC_LOG_NOTICE, "power state requested of %s (%X), but we are not the active source. setting power state to standby", GetLogicalAddressName(), m_iLogicalAddress);
bbc71623 973 SetPowerStatus(CEC_POWER_STATUS_STANDBY);
24dd566c 974 }
bbc71623 975
5477a250 976 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus));
8fa35473
LOK
977 state = m_powerStatus;
978 }
93729720 979
1344fd1a
LOK
980 MarkBusy();
981 bool bReturn = m_handler->TransmitPowerState(m_iLogicalAddress, dest, state);
982 MarkReady();
983 return bReturn;
93729720
LOK
984}
985
fe6f8e37 986bool CCECBusDevice::TransmitVendorID(cec_logical_address dest, bool bSendAbort /* = true */)
93729720 987{
1344fd1a 988 bool bReturn(false);
8fa35473
LOK
989 uint64_t iVendorId;
990 {
f00ff009 991 CLockObject lock(m_mutex);
8fa35473
LOK
992 iVendorId = (uint64_t)m_vendor;
993 }
994
1344fd1a 995 MarkBusy();
8fa35473 996 if (iVendorId == CEC_VENDOR_UNKNOWN)
c4098482 997 {
fe6f8e37
LOK
998 if (bSendAbort)
999 {
5477a250 1000 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest);
fe6f8e37 1001 m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
1344fd1a 1002 bReturn = true;
fe6f8e37 1003 }
c4098482
LOK
1004 }
1005 else
1006 {
5477a250 1007 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString((cec_vendor_id)iVendorId), iVendorId);
1344fd1a 1008 bReturn = m_handler->TransmitVendorID(m_iLogicalAddress, iVendorId);
c4098482 1009 }
1344fd1a
LOK
1010 MarkReady();
1011 return bReturn;
93729720 1012}
a33794d8 1013
4bec9d79 1014bool CCECBusDevice::TransmitKeypress(cec_user_control_code key, bool bWait /* = true */)
a33794d8 1015{
1344fd1a
LOK
1016 MarkBusy();
1017 bool bReturn = m_handler->TransmitKeypress(m_processor->GetLogicalAddress(), m_iLogicalAddress, key, bWait);
1018 MarkReady();
1019 return bReturn;
a33794d8
LOK
1020}
1021
4bec9d79 1022bool CCECBusDevice::TransmitKeyRelease(bool bWait /* = true */)
a33794d8 1023{
1344fd1a
LOK
1024 MarkBusy();
1025 bool bReturn = m_handler->TransmitKeyRelease(m_processor->GetLogicalAddress(), m_iLogicalAddress, bWait);
1026 MarkReady();
1027 return bReturn;
a33794d8 1028}
4d738fe3 1029
33dd87a9 1030bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode)
4d738fe3 1031{
33dd87a9 1032 CLockObject lock(m_mutex);
66c3ef5a
LOK
1033 bool bUnsupported = (m_unsupportedFeatures.find(opcode) != m_unsupportedFeatures.end());
1034 if (bUnsupported)
1035 CLibCEC::AddLog(CEC_LOG_NOTICE, "'%s' is marked as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
1036 return bUnsupported;
4d738fe3
LOK
1037}
1038
1039void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode)
1040{
b499cf16
LOK
1041 {
1042 CLockObject lock(m_mutex);
1043 CLibCEC::AddLog(CEC_LOG_DEBUG, "marking opcode '%s' as unsupported feature for device '%s'", ToString(opcode), GetLogicalAddressName());
1044 m_unsupportedFeatures.insert(opcode);
1045 }
1046
1047 // signal threads that are waiting for a reponse
1048 MarkBusy();
1049 m_handler->SignalOpcode(cec_command::GetResponseOpcode(opcode));
1050 MarkReady();
4d738fe3 1051}
b64db02e 1052
3e61b350 1053bool CCECBusDevice::ActivateSource(void)
b64db02e 1054{
e2c644d2 1055 CLibCEC::AddLog(CEC_LOG_DEBUG, "activating source '%s'", ToString(m_iLogicalAddress));
1344fd1a
LOK
1056 MarkBusy();
1057 bool bReturn = m_handler->ActivateSource();
1058 MarkReady();
1059 return bReturn;
b64db02e
LOK
1060}
1061
a75e3a5a
LOK
1062void CCECBusDevice::HandlePoll(cec_logical_address destination)
1063{
1064 if (destination >= 0 && destination < CECDEVICE_BROADCAST)
1065 {
1066 CCECBusDevice *device = m_processor->m_busDevices[destination];
1067 if (device)
1068 device->HandlePollFrom(m_iLogicalAddress);
1069 }
1070}
1071
1072void CCECBusDevice::HandlePollFrom(cec_logical_address initiator)
0cfdeb5a 1073{
a75e3a5a 1074 CLibCEC::AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", ToString(initiator), initiator, ToString(m_iLogicalAddress), m_iLogicalAddress);
ef583662 1075 m_bAwaitingReceiveFailed = true;
0cfdeb5a
LOK
1076}
1077
1078bool CCECBusDevice::HandleReceiveFailed(void)
1079{
ef583662
LOK
1080 bool bReturn = m_bAwaitingReceiveFailed;
1081 m_bAwaitingReceiveFailed = false;
1082 return bReturn;
0cfdeb5a
LOK
1083}
1084
ebb6ddb3
LOK
1085void CCECBusDevice::CheckVendorIdRequested(void)
1086{
1087 bool bRequestVendorId(false);
1088 {
1089 CLockObject lock(m_mutex);
1090 bRequestVendorId = !m_bVendorIdRequested;
1091 m_bVendorIdRequested = true;
1092 }
1093
1094 if (bRequestVendorId)
1095 {
1096 ReplaceHandler(false);
1097 GetVendorId();
1098 }
1099}
1100
b78b4e33
LOK
1101bool CCECBusDevice::TransmitPendingActiveSourceCommands(void)
1102{
1103 MarkBusy();
1104 bool bReturn = m_handler->TransmitPendingActiveSourceCommands();
1105 MarkReady();
1106 return bReturn;
1107}
1108
93729720 1109//@}