2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 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 "CECBusDevice.h"
34 #include "../CECProcessor.h"
35 #include "../implementations/ANCommandHandler.h"
36 #include "../implementations/CECCommandHandler.h"
37 #include "../implementations/SLCommandHandler.h"
38 #include "../implementations/VLCommandHandler.h"
39 #include "../platform/timeutils.h"
43 #define ToString(p) m_processor->ToString(p)
45 CCECBusDevice::CCECBusDevice(CCECProcessor
*processor
, cec_logical_address iLogicalAddress
, uint16_t iPhysicalAddress
) :
46 m_type(CEC_DEVICE_TYPE_RESERVED
),
47 m_iPhysicalAddress(iPhysicalAddress
),
49 m_iLogicalAddress(iLogicalAddress
),
50 m_powerStatus(CEC_POWER_STATUS_UNKNOWN
),
51 m_processor(processor
),
52 m_vendor(CEC_VENDOR_UNKNOWN
),
53 m_bReplaceHandler(false),
54 m_menuState(CEC_MENU_STATE_ACTIVATED
),
55 m_bActiveSource(false),
57 m_cecVersion(CEC_VERSION_UNKNOWN
),
58 m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN
),
61 m_handler
= new CCECCommandHandler(this);
63 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
64 m_menuLanguage
.language
[iPtr
] = '?';
65 m_menuLanguage
.language
[3] = 0;
66 m_menuLanguage
.device
= iLogicalAddress
;
68 m_strDeviceName
= ToString(m_iLogicalAddress
);
71 CCECBusDevice::~CCECBusDevice(void)
76 void CCECBusDevice::AddLog(cec_log_level level
, const CStdString
&strMessage
)
78 m_processor
->AddLog(level
, strMessage
);
81 bool CCECBusDevice::HandleCommand(const cec_command
&command
)
85 /* update "last active" */
87 CLockObject
lock(&m_mutex
);
88 m_iLastActive
= GetTimeMs();
90 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
91 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
94 /* handle the command */
95 bHandled
= m_handler
->HandleCommand(command
);
97 /* change status to present */
100 CLockObject
lock(&m_mutex
);
101 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
103 if (m_deviceStatus
!= CEC_DEVICE_STATUS_PRESENT
)
106 strLog
.Format("device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command
.opcode
));
107 AddLog(CEC_LOG_DEBUG
, strLog
);
109 m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
116 bool CCECBusDevice::PowerOn(void)
119 strLog
.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
120 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
122 if (m_handler
->TransmitImageViewOn(GetMyLogicalAddress(), m_iLogicalAddress
))
125 CLockObject
lock(&m_mutex
);
126 // m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
127 m_powerStatus
= CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
;
129 // cec_power_status status = GetPowerStatus();
130 // if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
132 // /* sending the normal power on command appears to have failed */
133 // CStdString strLog;
134 // strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
135 // AddLog(CEC_LOG_DEBUG, strLog.c_str());
137 // TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
138 // return TransmitKeyRelease();
146 bool CCECBusDevice::Standby(void)
149 strLog
.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress
);
150 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
152 return m_handler
->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress
);
157 cec_version
CCECBusDevice::GetCecVersion(bool bUpdate
/* = false */)
159 bool bRequestUpdate(false);
161 CLockObject
lock(&m_mutex
);
162 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
163 (bUpdate
|| m_cecVersion
== CEC_VERSION_UNKNOWN
));
169 CLockObject
lock(&m_mutex
);
173 bool CCECBusDevice::RequestCecVersion(void)
177 if (!MyLogicalAddressContains(m_iLogicalAddress
))
180 strLog
.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
181 AddLog(CEC_LOG_NOTICE
, strLog
);
183 bReturn
= m_handler
->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress
);
188 const char* CCECBusDevice::GetLogicalAddressName(void) const
190 return ToString(m_iLogicalAddress
);
193 cec_menu_language
&CCECBusDevice::GetMenuLanguage(bool bUpdate
/* = false */)
195 bool bRequestUpdate(false);
197 CLockObject
lock(&m_mutex
);
198 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
199 (bUpdate
|| !strcmp(m_menuLanguage
.language
, "???")));
203 RequestMenuLanguage();
205 CLockObject
lock(&m_mutex
);
206 return m_menuLanguage
;
209 bool CCECBusDevice::RequestMenuLanguage(void)
213 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
214 !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE
))
217 strLog
.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
218 AddLog(CEC_LOG_NOTICE
, strLog
);
219 bReturn
= m_handler
->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress
);
224 cec_logical_address
CCECBusDevice::GetMyLogicalAddress(void) const
226 return m_processor
->GetLogicalAddress();
229 uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
231 return m_processor
->GetPhysicalAddress();
234 CStdString
CCECBusDevice::GetOSDName(bool bUpdate
/* = false */)
236 bool bRequestUpdate(false);
238 CLockObject
lock(&m_mutex
);
239 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
240 (bUpdate
|| m_strDeviceName
.Equals(ToString(m_iLogicalAddress
))) &&
241 m_type
!= CEC_DEVICE_TYPE_TV
);
247 CLockObject
lock(&m_mutex
);
248 return m_strDeviceName
;
251 bool CCECBusDevice::RequestOSDName(void)
255 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
256 !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME
))
259 strLog
.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
260 AddLog(CEC_LOG_NOTICE
, strLog
);
261 bReturn
= m_handler
->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress
);
266 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate
/* = false */)
268 bool bRequestUpdate(false);
270 CLockObject
lock(&m_mutex
);
271 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
272 (m_iPhysicalAddress
== 0xFFFF || bUpdate
));
275 if (bRequestUpdate
&& !RequestPhysicalAddress())
276 AddLog(CEC_LOG_ERROR
, "failed to request the physical address (1)");
278 CLockObject
lock(&m_mutex
);
279 return m_iPhysicalAddress
;
282 bool CCECBusDevice::RequestPhysicalAddress(void)
286 if (!MyLogicalAddressContains(m_iLogicalAddress
))
289 strLog
.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
290 AddLog(CEC_LOG_NOTICE
, strLog
);
291 bReturn
= m_handler
->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress
);
296 cec_power_status
CCECBusDevice::GetPowerStatus(bool bUpdate
/* = false */)
298 bool bRequestUpdate(false);
300 CLockObject
lock(&m_mutex
);
301 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
302 (bUpdate
|| m_powerStatus
== CEC_POWER_STATUS_UNKNOWN
||
303 m_powerStatus
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
));
307 RequestPowerStatus();
309 CLockObject
lock(&m_mutex
);
310 return m_powerStatus
;
313 bool CCECBusDevice::RequestPowerStatus(void)
317 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
318 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
321 strLog
.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
322 AddLog(CEC_LOG_NOTICE
, strLog
);
323 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
328 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
330 bool bRequestUpdate(false);
332 CLockObject
lock(&m_mutex
);
333 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
334 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
340 CLockObject
lock(&m_mutex
);
344 bool CCECBusDevice::RequestVendorId(void)
348 if (!MyLogicalAddressContains(m_iLogicalAddress
))
351 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
352 AddLog(CEC_LOG_NOTICE
, strLog
);
353 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
358 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
360 return ToString(GetVendorId(bUpdate
));
363 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
365 return m_processor
->HasLogicalAddress(address
);
368 bool CCECBusDevice::NeedsPoll(void)
370 bool bSendPoll(false);
371 switch (m_iLogicalAddress
)
373 case CECDEVICE_PLAYBACKDEVICE3
:
374 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
377 case CECDEVICE_PLAYBACKDEVICE2
:
378 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
381 case CECDEVICE_RECORDINGDEVICE3
:
382 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
385 case CECDEVICE_RECORDINGDEVICE2
:
386 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
389 case CECDEVICE_TUNER4
:
390 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
393 case CECDEVICE_TUNER3
:
394 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
397 case CECDEVICE_TUNER2
:
398 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
401 case CECDEVICE_AUDIOSYSTEM
:
402 case CECDEVICE_PLAYBACKDEVICE1
:
403 case CECDEVICE_RECORDINGDEVICE1
:
404 case CECDEVICE_TUNER1
:
415 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
417 CLockObject
lock(&m_mutex
);
418 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
419 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
422 bool bPollAcked(false);
423 if (bForcePoll
|| NeedsPoll())
424 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
427 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
430 return m_deviceStatus
;
437 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
439 m_cecVersion
= newVersion
;
442 strLog
.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
443 AddLog(CEC_LOG_DEBUG
, strLog
);
446 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
448 CLockObject
lock(&m_mutex
);
449 if (language
.device
== m_iLogicalAddress
)
452 strLog
.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
453 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
454 m_menuLanguage
= language
;
458 void CCECBusDevice::SetOSDName(CStdString strName
)
460 CLockObject
lock(&m_mutex
);
461 if (m_strDeviceName
!= strName
)
464 strLog
.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
);
465 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
466 m_strDeviceName
= strName
;
470 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
472 CLockObject
lock(&m_mutex
);
473 if (m_menuState
!= state
)
476 strLog
.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
477 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
482 void CCECBusDevice::SetInactiveSource(void)
485 CLockObject
lock(&m_mutex
);
486 m_bActiveSource
= false;
489 if (MyLogicalAddressContains(m_iLogicalAddress
))
490 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
493 void CCECBusDevice::SetActiveSource(void)
495 CLockObject
lock(&m_mutex
);
497 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
498 if (iPtr
!= m_iLogicalAddress
)
499 m_processor
->m_busDevices
[iPtr
]->SetInactiveSource();
501 m_bActiveSource
= true;
502 m_powerStatus
= CEC_POWER_STATUS_ON
;
505 bool CCECBusDevice::TryLogicalAddress(void)
508 strLog
.Format("trying logical address '%s'", GetLogicalAddressName());
509 AddLog(CEC_LOG_DEBUG
, strLog
);
511 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
512 if (!TransmitPoll(m_iLogicalAddress
))
514 strLog
.Format("using logical address '%s'", GetLogicalAddressName());
515 AddLog(CEC_LOG_NOTICE
, strLog
);
516 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
521 strLog
.Format("logical address '%s' already taken", GetLogicalAddressName());
522 AddLog(CEC_LOG_DEBUG
, strLog
);
523 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
527 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
529 CLockObject
lock(&m_mutex
);
532 case CEC_DEVICE_STATUS_UNKNOWN
:
534 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
535 m_vendor
= CEC_VENDOR_UNKNOWN
;
536 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
537 m_bActiveSource
= false;
539 m_cecVersion
= CEC_VERSION_UNKNOWN
;
540 m_deviceStatus
= newStatus
;
542 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
544 m_powerStatus
= CEC_POWER_STATUS_ON
;
545 m_vendor
= CEC_VENDOR_UNKNOWN
;
546 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
547 m_bActiveSource
= false;
549 m_cecVersion
= CEC_VERSION_1_3A
;
550 m_deviceStatus
= newStatus
;
552 case CEC_DEVICE_STATUS_PRESENT
:
553 case CEC_DEVICE_STATUS_NOT_PRESENT
:
554 m_deviceStatus
= newStatus
;
559 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
561 CLockObject
lock(&m_mutex
);
562 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
565 strLog
.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
566 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
568 m_iPhysicalAddress
= iNewAddress
;
572 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
574 CLockObject
lock(&m_mutex
);
578 strLog
.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
579 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
581 m_iStreamPath
= iNewAddress
;
586 SetPowerStatus(CEC_POWER_STATUS_ON
);
591 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
593 CLockObject
lock(&m_mutex
);
594 if (m_powerStatus
!= powerStatus
)
597 strLog
.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
598 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
599 m_powerStatus
= powerStatus
;
603 bool CCECBusDevice::ReplaceHandler(bool bInitHandler
/* = true */)
605 CLockObject
lock(&m_mutex
);
606 CLockObject
handlerLock(&m_handlerMutex
);
608 if (m_vendor
!= m_handler
->GetVendorId())
610 if (m_handler
->InUse())
617 case CEC_VENDOR_SAMSUNG
:
618 m_handler
= new CANCommandHandler(this);
621 m_handler
= new CSLCommandHandler(this);
623 case CEC_VENDOR_PANASONIC
:
624 m_handler
= new CVLCommandHandler(this);
627 m_handler
= new CCECCommandHandler(this);
631 if (bInitHandler
&& m_processor
->GetLogicalAddresses().IsSet(m_iLogicalAddress
) && m_processor
->IsInitialised())
632 m_handler
->InitHandler();
638 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
, bool bInitHandler
/* = true */)
640 bool bVendorChanged(false);
643 CLockObject
lock(&m_mutex
);
644 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
645 m_vendor
= (cec_vendor_id
)iVendorId
;
646 ReplaceHandler(bInitHandler
);
650 strLog
.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
651 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
653 return bVendorChanged
;
657 /** @name Transmit methods */
659 bool CCECBusDevice::TransmitActiveSource(void)
661 bool bSendActiveSource(false);
664 CLockObject
lock(&m_mutex
);
665 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
668 strLog
.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
669 AddLog(CEC_LOG_DEBUG
, strLog
);
671 else if (m_bActiveSource
)
674 strLog
.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
675 AddLog(CEC_LOG_NOTICE
, strLog
);
676 bSendActiveSource
= true;
681 strLog
.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
682 AddLog(CEC_LOG_DEBUG
, strLog
);
686 if (bSendActiveSource
)
688 m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
689 m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
);
696 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
700 CLockObject
lock(&m_mutex
);
702 strLog
.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
703 AddLog(CEC_LOG_NOTICE
, strLog
);
704 version
= m_cecVersion
;
707 return m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
710 bool CCECBusDevice::TransmitInactiveSource(void)
712 uint16_t iPhysicalAddress
;
714 CLockObject
lock(&m_mutex
);
716 strLog
.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
717 AddLog(CEC_LOG_NOTICE
, strLog
);
718 iPhysicalAddress
= m_iPhysicalAddress
;
721 return m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
724 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
726 cec_menu_state menuState
;
728 CLockObject
lock(&m_mutex
);
730 strLog
.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
731 AddLog(CEC_LOG_NOTICE
, strLog
);
732 menuState
= m_menuState
;
735 return m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
738 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
740 CStdString strDeviceName
;
742 CLockObject
lock(&m_mutex
);
744 strLog
.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
745 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
746 strDeviceName
= m_strDeviceName
;
749 return m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
752 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
754 if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
757 strLog
.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
758 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
760 return m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
765 bool CCECBusDevice::TransmitPhysicalAddress(void)
767 uint16_t iPhysicalAddress
;
768 cec_device_type type
;
770 CLockObject
lock(&m_mutex
);
771 if (m_iPhysicalAddress
== 0xffff)
775 strLog
.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
776 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
778 iPhysicalAddress
= m_iPhysicalAddress
;
782 return m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
785 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
788 if (dest
== CECDEVICE_UNKNOWN
)
789 dest
= m_iLogicalAddress
;
791 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
792 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
796 strLog
.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
797 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
798 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
799 AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
801 CLockObject
lock(&m_mutex
);
804 m_iLastActive
= GetTimeMs();
805 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
808 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
813 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
815 cec_power_status state
;
817 CLockObject
lock(&m_mutex
);
819 strLog
.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
820 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
821 state
= m_powerStatus
;
824 return m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
827 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
831 CLockObject
lock(&m_mutex
);
832 iVendorId
= (uint64_t)m_vendor
;
835 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
840 strLog
.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
841 AddLog(CEC_LOG_NOTICE
, strLog
);
843 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
850 strLog
.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString((cec_vendor_id
)iVendorId
), iVendorId
);
851 AddLog(CEC_LOG_NOTICE
, strLog
);
853 return m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
857 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
, bool bWait
/* = true */)
859 return m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
, bWait
);
862 bool CCECBusDevice::TransmitKeyRelease(bool bWait
/* = true */)
864 return m_handler
->TransmitKeyRelease(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, bWait
);
867 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
) const
869 return m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end();
872 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
874 m_unsupportedFeatures
.insert(opcode
);
877 bool CCECBusDevice::InitHandler(void)
879 CLockObject
lock(&m_mutex
);
880 return m_handler
->InitHandler();