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
));
306 RequestPowerStatus();
308 CLockObject
lock(&m_mutex
);
309 return m_powerStatus
;
312 bool CCECBusDevice::RequestPowerStatus(void)
316 if (!MyLogicalAddressContains(m_iLogicalAddress
) &&
317 !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
))
320 strLog
.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
321 AddLog(CEC_LOG_NOTICE
, strLog
);
322 bReturn
= m_handler
->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress
);
327 cec_vendor_id
CCECBusDevice::GetVendorId(bool bUpdate
/* = false */)
329 bool bRequestUpdate(false);
331 CLockObject
lock(&m_mutex
);
332 bRequestUpdate
= (GetStatus() == CEC_DEVICE_STATUS_PRESENT
&&
333 (bUpdate
|| m_vendor
== CEC_VENDOR_UNKNOWN
));
339 CLockObject
lock(&m_mutex
);
343 bool CCECBusDevice::RequestVendorId(void)
347 if (!MyLogicalAddressContains(m_iLogicalAddress
))
350 strLog
.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress
);
351 AddLog(CEC_LOG_NOTICE
, strLog
);
352 bReturn
= m_handler
->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress
);
357 const char *CCECBusDevice::GetVendorName(bool bUpdate
/* = false */)
359 return ToString(GetVendorId(bUpdate
));
362 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address
) const
364 return m_processor
->HasLogicalAddress(address
);
367 bool CCECBusDevice::NeedsPoll(void)
369 bool bSendPoll(false);
370 switch (m_iLogicalAddress
)
372 case CECDEVICE_PLAYBACKDEVICE3
:
373 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
376 case CECDEVICE_PLAYBACKDEVICE2
:
377 if (m_processor
->m_busDevices
[CECDEVICE_PLAYBACKDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
380 case CECDEVICE_RECORDINGDEVICE3
:
381 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
384 case CECDEVICE_RECORDINGDEVICE2
:
385 if (m_processor
->m_busDevices
[CECDEVICE_RECORDINGDEVICE1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
388 case CECDEVICE_TUNER4
:
389 if (m_processor
->m_busDevices
[CECDEVICE_TUNER3
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
392 case CECDEVICE_TUNER3
:
393 if (m_processor
->m_busDevices
[CECDEVICE_TUNER2
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
396 case CECDEVICE_TUNER2
:
397 if (m_processor
->m_busDevices
[CECDEVICE_TUNER1
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
400 case CECDEVICE_AUDIOSYSTEM
:
401 case CECDEVICE_PLAYBACKDEVICE1
:
402 case CECDEVICE_RECORDINGDEVICE1
:
403 case CECDEVICE_TUNER1
:
414 cec_bus_device_status
CCECBusDevice::GetStatus(bool bForcePoll
/* = false */)
416 CLockObject
lock(&m_mutex
);
417 if (m_deviceStatus
!= CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
&&
418 (m_deviceStatus
== CEC_DEVICE_STATUS_UNKNOWN
|| bForcePoll
))
421 bool bPollAcked(false);
422 if (bForcePoll
|| NeedsPoll())
423 bPollAcked
= m_processor
->PollDevice(m_iLogicalAddress
);
426 m_deviceStatus
= bPollAcked
? CEC_DEVICE_STATUS_PRESENT
: CEC_DEVICE_STATUS_NOT_PRESENT
;
429 return m_deviceStatus
;
436 void CCECBusDevice::SetCecVersion(const cec_version newVersion
)
438 m_cecVersion
= newVersion
;
441 strLog
.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(newVersion
));
442 AddLog(CEC_LOG_DEBUG
, strLog
);
445 void CCECBusDevice::SetMenuLanguage(const cec_menu_language
&language
)
447 CLockObject
lock(&m_mutex
);
448 if (language
.device
== m_iLogicalAddress
)
451 strLog
.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, language
.language
);
452 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
453 m_menuLanguage
= language
;
457 void CCECBusDevice::SetOSDName(CStdString strName
)
459 CLockObject
lock(&m_mutex
);
460 if (m_strDeviceName
!= strName
)
463 strLog
.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, strName
);
464 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
465 m_strDeviceName
= strName
;
469 void CCECBusDevice::SetMenuState(const cec_menu_state state
)
471 CLockObject
lock(&m_mutex
);
472 if (m_menuState
!= state
)
475 strLog
.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_menuState
));
476 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
481 void CCECBusDevice::SetInactiveSource(void)
484 CLockObject
lock(&m_mutex
);
485 m_bActiveSource
= false;
488 if (MyLogicalAddressContains(m_iLogicalAddress
))
489 SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
492 void CCECBusDevice::SetActiveSource(void)
494 CLockObject
lock(&m_mutex
);
496 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
497 if (iPtr
!= m_iLogicalAddress
)
498 m_processor
->m_busDevices
[iPtr
]->SetInactiveSource();
500 m_bActiveSource
= true;
501 m_powerStatus
= CEC_POWER_STATUS_ON
;
504 bool CCECBusDevice::TryLogicalAddress(void)
507 strLog
.Format("trying logical address '%s'", GetLogicalAddressName());
508 AddLog(CEC_LOG_DEBUG
, strLog
);
510 m_processor
->SetAckMask(0x1 << m_iLogicalAddress
);
511 if (!TransmitPoll(m_iLogicalAddress
))
513 strLog
.Format("using logical address '%s'", GetLogicalAddressName());
514 AddLog(CEC_LOG_NOTICE
, strLog
);
515 SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
520 strLog
.Format("logical address '%s' already taken", GetLogicalAddressName());
521 AddLog(CEC_LOG_DEBUG
, strLog
);
522 SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT
);
526 void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus
)
528 CLockObject
lock(&m_mutex
);
531 case CEC_DEVICE_STATUS_UNKNOWN
:
533 m_powerStatus
= CEC_POWER_STATUS_UNKNOWN
;
534 m_vendor
= CEC_VENDOR_UNKNOWN
;
535 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
536 m_bActiveSource
= false;
538 m_cecVersion
= CEC_VERSION_UNKNOWN
;
539 m_deviceStatus
= newStatus
;
541 case CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
:
543 m_powerStatus
= CEC_POWER_STATUS_ON
;
544 m_vendor
= CEC_VENDOR_UNKNOWN
;
545 m_menuState
= CEC_MENU_STATE_ACTIVATED
;
546 m_bActiveSource
= false;
548 m_cecVersion
= CEC_VERSION_1_3A
;
549 m_deviceStatus
= newStatus
;
551 case CEC_DEVICE_STATUS_PRESENT
:
552 case CEC_DEVICE_STATUS_NOT_PRESENT
:
553 m_deviceStatus
= newStatus
;
558 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress
)
560 CLockObject
lock(&m_mutex
);
561 if (iNewAddress
> 0 && m_iPhysicalAddress
!= iNewAddress
)
564 strLog
.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
, iNewAddress
);
565 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
567 m_iPhysicalAddress
= iNewAddress
;
571 void CCECBusDevice::SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
/* = 0 */)
573 CLockObject
lock(&m_mutex
);
577 strLog
.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress
, iOldAddress
== 0 ? m_iStreamPath
: iOldAddress
, iNewAddress
);
578 AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
580 m_iStreamPath
= iNewAddress
;
585 SetPowerStatus(CEC_POWER_STATUS_ON
);
590 void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus
)
592 CLockObject
lock(&m_mutex
);
593 if (m_powerStatus
!= powerStatus
)
596 strLog
.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_powerStatus
), ToString(powerStatus
));
597 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
);
598 m_powerStatus
= powerStatus
;
602 bool CCECBusDevice::ReplaceHandler(bool bInitHandler
/* = true */)
604 CLockObject
lock(&m_mutex
);
605 CLockObject
handlerLock(&m_handlerMutex
);
607 if (m_vendor
!= m_handler
->GetVendorId())
609 if (m_handler
->InUse())
616 case CEC_VENDOR_SAMSUNG
:
617 m_handler
= new CANCommandHandler(this);
620 m_handler
= new CSLCommandHandler(this);
622 case CEC_VENDOR_PANASONIC
:
623 m_handler
= new CVLCommandHandler(this);
626 m_handler
= new CCECCommandHandler(this);
630 if (bInitHandler
&& m_processor
->GetLogicalAddresses().IsSet(m_iLogicalAddress
) && m_processor
->IsInitialised())
631 m_handler
->InitHandler();
637 bool CCECBusDevice::SetVendorId(uint64_t iVendorId
, bool bInitHandler
/* = true */)
639 bool bVendorChanged(false);
642 CLockObject
lock(&m_mutex
);
643 bVendorChanged
= (m_vendor
!= (cec_vendor_id
)iVendorId
);
644 m_vendor
= (cec_vendor_id
)iVendorId
;
645 ReplaceHandler(bInitHandler
);
649 strLog
.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(m_vendor
), m_vendor
);
650 m_processor
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
652 return bVendorChanged
;
656 /** @name Transmit methods */
658 bool CCECBusDevice::TransmitActiveSource(void)
660 bool bSendActiveSource(false);
663 CLockObject
lock(&m_mutex
);
664 if (m_powerStatus
!= CEC_POWER_STATUS_ON
)
667 strLog
.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress
);
668 AddLog(CEC_LOG_DEBUG
, strLog
);
670 else if (m_bActiveSource
)
673 strLog
.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
674 AddLog(CEC_LOG_NOTICE
, strLog
);
675 bSendActiveSource
= true;
680 strLog
.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress
);
681 AddLog(CEC_LOG_DEBUG
, strLog
);
685 if (bSendActiveSource
)
687 m_handler
->TransmitActiveSource(m_iLogicalAddress
, m_iPhysicalAddress
);
688 m_handler
->TransmitImageViewOn(m_iLogicalAddress
, CECDEVICE_TV
);
695 bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest
)
699 CLockObject
lock(&m_mutex
);
701 strLog
.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_cecVersion
));
702 AddLog(CEC_LOG_NOTICE
, strLog
);
703 version
= m_cecVersion
;
706 return m_handler
->TransmitCECVersion(m_iLogicalAddress
, dest
, version
);
709 bool CCECBusDevice::TransmitInactiveSource(void)
711 uint16_t iPhysicalAddress
;
713 CLockObject
lock(&m_mutex
);
715 strLog
.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress
);
716 AddLog(CEC_LOG_NOTICE
, strLog
);
717 iPhysicalAddress
= m_iPhysicalAddress
;
720 return m_handler
->TransmitInactiveSource(m_iLogicalAddress
, iPhysicalAddress
);
723 bool CCECBusDevice::TransmitMenuState(cec_logical_address dest
)
725 cec_menu_state menuState
;
727 CLockObject
lock(&m_mutex
);
729 strLog
.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_menuState
));
730 AddLog(CEC_LOG_NOTICE
, strLog
);
731 menuState
= m_menuState
;
734 return m_handler
->TransmitMenuState(m_iLogicalAddress
, dest
, menuState
);
737 bool CCECBusDevice::TransmitOSDName(cec_logical_address dest
)
739 CStdString strDeviceName
;
741 CLockObject
lock(&m_mutex
);
743 strLog
.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, m_strDeviceName
.c_str());
744 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
745 strDeviceName
= m_strDeviceName
;
748 return m_handler
->TransmitOSDName(m_iLogicalAddress
, dest
, strDeviceName
);
751 bool CCECBusDevice::TransmitOSDString(cec_logical_address dest
, cec_display_control duration
, const char *strMessage
)
753 if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING
))
756 strLog
.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, strMessage
);
757 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
759 return m_handler
->TransmitOSDString(m_iLogicalAddress
, dest
, duration
, strMessage
);
764 bool CCECBusDevice::TransmitPhysicalAddress(void)
766 uint16_t iPhysicalAddress
;
767 cec_device_type type
;
769 CLockObject
lock(&m_mutex
);
770 if (m_iPhysicalAddress
== 0xffff)
774 strLog
.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress
, m_iPhysicalAddress
);
775 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
777 iPhysicalAddress
= m_iPhysicalAddress
;
781 return m_handler
->TransmitPhysicalAddress(m_iLogicalAddress
, iPhysicalAddress
, type
);
784 bool CCECBusDevice::TransmitPoll(cec_logical_address dest
)
787 if (dest
== CECDEVICE_UNKNOWN
)
788 dest
= m_iLogicalAddress
;
790 CCECBusDevice
*destDevice
= m_processor
->m_busDevices
[dest
];
791 if (destDevice
->m_deviceStatus
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
795 strLog
.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
796 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
797 bReturn
= m_handler
->TransmitPoll(m_iLogicalAddress
, dest
);
798 AddLog(CEC_LOG_DEBUG
, bReturn
? ">> POLL sent" : ">> POLL not sent");
800 CLockObject
lock(&m_mutex
);
803 m_iLastActive
= GetTimeMs();
804 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_PRESENT
;
807 destDevice
->m_deviceStatus
= CEC_DEVICE_STATUS_NOT_PRESENT
;
812 bool CCECBusDevice::TransmitPowerState(cec_logical_address dest
)
814 cec_power_status state
;
816 CLockObject
lock(&m_mutex
);
818 strLog
.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString(m_powerStatus
));
819 AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
820 state
= m_powerStatus
;
823 return m_handler
->TransmitPowerState(m_iLogicalAddress
, dest
, state
);
826 bool CCECBusDevice::TransmitVendorID(cec_logical_address dest
, bool bSendAbort
/* = true */)
830 CLockObject
lock(&m_mutex
);
831 iVendorId
= (uint64_t)m_vendor
;
834 if (iVendorId
== CEC_VENDOR_UNKNOWN
)
839 strLog
.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
);
840 AddLog(CEC_LOG_NOTICE
, strLog
);
842 m_processor
->TransmitAbort(dest
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
849 strLog
.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress
, ToString(dest
), dest
, ToString((cec_vendor_id
)iVendorId
), iVendorId
);
850 AddLog(CEC_LOG_NOTICE
, strLog
);
852 return m_handler
->TransmitVendorID(m_iLogicalAddress
, iVendorId
);
856 bool CCECBusDevice::TransmitKeypress(cec_user_control_code key
, bool bWait
/* = true */)
858 return m_handler
->TransmitKeypress(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, key
, bWait
);
861 bool CCECBusDevice::TransmitKeyRelease(bool bWait
/* = true */)
863 return m_handler
->TransmitKeyRelease(m_processor
->GetLogicalAddress(), m_iLogicalAddress
, bWait
);
866 bool CCECBusDevice::IsUnsupportedFeature(cec_opcode opcode
) const
868 return m_unsupportedFeatures
.find(opcode
) != m_unsupportedFeatures
.end();
871 void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode
)
873 m_unsupportedFeatures
.insert(opcode
);
876 bool CCECBusDevice::InitHandler(void)
878 CLockObject
lock(&m_mutex
);
879 return m_handler
->InitHandler();