3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
34 #include "../../../include/cectypes.h"
36 #include "../platform/threads/mutex.h"
37 #include "../platform/util/StdString.h"
43 class CCECCommandHandler
;
44 class CCECAudioSystem
;
45 class CCECPlaybackDevice
;
46 class CCECRecordingDevice
;
52 friend class CCECProcessor
;
55 CCECBusDevice(CCECProcessor
*processor
, cec_logical_address address
, uint16_t iPhysicalAddress
= CEC_INVALID_PHYSICAL_ADDRESS
);
56 virtual ~CCECBusDevice(void);
58 virtual bool ReplaceHandler(bool bActivateSource
= true);
59 virtual CCECCommandHandler
* GetHandler(void) const { return m_handler
; };
60 virtual CCECProcessor
* GetProcessor(void) const { return m_processor
; }
61 virtual uint64_t GetLastActive(void) const { return m_iLastActive
; }
62 virtual cec_device_type
GetType(void) const { return m_type
; }
63 virtual cec_logical_address
GetLogicalAddress(void) const { return m_iLogicalAddress
; }
64 virtual const char* GetLogicalAddressName(void) const;
65 virtual bool IsPresent(void);
66 virtual bool IsHandledByLibCEC(void);
68 virtual bool HandleCommand(const cec_command
&command
);
69 virtual bool IsUnsupportedFeature(cec_opcode opcode
);
70 virtual void SetUnsupportedFeature(cec_opcode opcode
);
72 virtual bool TransmitKeypress(const cec_logical_address initiator
, cec_user_control_code key
, bool bWait
= true);
73 virtual bool TransmitKeyRelease(const cec_logical_address initiator
, bool bWait
= true);
75 virtual cec_version
GetCecVersion(const cec_logical_address initiator
, bool bUpdate
= false);
76 virtual void SetCecVersion(const cec_version newVersion
);
77 virtual bool RequestCecVersion(const cec_logical_address initiator
, bool bWaitForResponse
= true);
78 virtual bool TransmitCECVersion(const cec_logical_address destination
);
80 virtual cec_menu_language
& GetMenuLanguage(const cec_logical_address initiator
, bool bUpdate
= false);
81 virtual void SetMenuLanguage(const char *strLanguage
);
82 virtual void SetMenuLanguage(const cec_menu_language
&menuLanguage
);
83 virtual bool RequestMenuLanguage(const cec_logical_address initiator
, bool bWaitForResponse
= true);
84 virtual bool TransmitSetMenuLanguage(const cec_logical_address destination
);
86 virtual bool TransmitOSDString(const cec_logical_address destination
, cec_display_control duration
, const char *strMessage
);
88 virtual CStdString
GetCurrentOSDName(void);
89 virtual CStdString
GetOSDName(const cec_logical_address initiator
, bool bUpdate
= false);
90 virtual void SetOSDName(CStdString strName
);
91 virtual bool RequestOSDName(const cec_logical_address source
, bool bWaitForResponse
= true);
92 virtual bool TransmitOSDName(const cec_logical_address destination
);
94 virtual uint16_t GetCurrentPhysicalAddress(void);
95 virtual bool HasValidPhysicalAddress(void);
96 virtual uint16_t GetPhysicalAddress(const cec_logical_address initiator
, bool bSuppressUpdate
= false);
97 virtual bool SetPhysicalAddress(uint16_t iNewAddress
);
98 virtual bool RequestPhysicalAddress(const cec_logical_address initiator
, bool bWaitForResponse
= true);
99 virtual bool TransmitPhysicalAddress(void);
101 virtual cec_power_status
GetCurrentPowerStatus(void);
102 virtual cec_power_status
GetPowerStatus(const cec_logical_address initiator
, bool bUpdate
= false);
103 virtual void SetPowerStatus(const cec_power_status powerStatus
);
104 virtual bool RequestPowerStatus(const cec_logical_address initiator
, bool bWaitForResponse
= true);
105 virtual bool TransmitPowerState(const cec_logical_address destination
);
107 virtual cec_vendor_id
GetCurrentVendorId(void);
108 virtual cec_vendor_id
GetVendorId(const cec_logical_address initiator
, bool bUpdate
= false);
109 virtual const char * GetVendorName(const cec_logical_address initiator
, bool bUpdate
= false);
110 virtual bool SetVendorId(uint64_t iVendorId
);
111 virtual bool RequestVendorId(const cec_logical_address initiator
, bool bWaitForResponse
= true);
112 virtual bool TransmitVendorID(const cec_logical_address destination
, bool bSendAbort
= true);
114 virtual cec_bus_device_status
GetCurrentStatus(void) { return GetStatus(false, true); }
115 virtual cec_bus_device_status
GetStatus(bool bForcePoll
= false, bool bSuppressPoll
= false);
116 virtual void SetDeviceStatus(const cec_bus_device_status newStatus
);
117 virtual void ResetDeviceStatus(void);
118 virtual bool TransmitPoll(const cec_logical_address destination
);
119 virtual void HandlePoll(const cec_logical_address destination
);
120 virtual void HandlePollFrom(const cec_logical_address initiator
);
121 virtual bool HandleReceiveFailed(void);
123 virtual cec_menu_state
GetMenuState(const cec_logical_address initiator
);
124 virtual void SetMenuState(const cec_menu_state state
);
125 virtual bool TransmitMenuState(const cec_logical_address destination
);
127 virtual bool ActivateSource(void);
128 virtual bool IsActiveSource(void) const { return m_bActiveSource
; }
129 virtual bool RequestActiveSource(bool bWaitForResponse
= true);
130 virtual void MarkAsActiveSource(void);
131 virtual void MarkAsInactiveSource(void);
132 virtual bool TransmitActiveSource(void);
133 virtual bool TransmitImageViewOn(void);
134 virtual bool TransmitInactiveSource(void);
135 virtual bool TransmitPendingActiveSourceCommands(void);
136 virtual void SetStreamPath(uint16_t iNewAddress
, uint16_t iOldAddress
= CEC_INVALID_PHYSICAL_ADDRESS
);
138 virtual bool PowerOn(const cec_logical_address initiator
);
139 virtual bool Standby(const cec_logical_address initiator
);
141 virtual bool TryLogicalAddress(void);
143 CCECClient
* GetClient(void);
145 CCECAudioSystem
* AsAudioSystem(void);
146 static CCECAudioSystem
* AsAudioSystem(CCECBusDevice
*device
);
147 CCECPlaybackDevice
* AsPlaybackDevice(void);
148 static CCECPlaybackDevice
* AsPlaybackDevice(CCECBusDevice
*device
);
149 CCECRecordingDevice
* AsRecordingDevice(void);
150 static CCECRecordingDevice
* AsRecordingDevice(CCECBusDevice
*device
);
151 CCECTuner
* AsTuner(void);
152 static CCECTuner
* AsTuner(CCECBusDevice
*device
);
154 static CCECTV
* AsTV(CCECBusDevice
*device
);
157 void CheckVendorIdRequested(const cec_logical_address source
);
159 void MarkReady(void);
161 bool NeedsPoll(void);
163 cec_device_type m_type
;
164 CStdString m_strDeviceName
;
165 uint16_t m_iPhysicalAddress
;
166 uint16_t m_iStreamPath
;
167 cec_logical_address m_iLogicalAddress
;
168 cec_power_status m_powerStatus
;
169 cec_menu_language m_menuLanguage
;
170 CCECProcessor
* m_processor
;
171 CCECCommandHandler
* m_handler
;
172 cec_vendor_id m_vendor
;
173 bool m_bReplaceHandler
;
174 cec_menu_state m_menuState
;
175 bool m_bActiveSource
;
176 uint64_t m_iLastActive
;
177 uint64_t m_iLastPowerStateUpdate
;
178 cec_version m_cecVersion
;
179 cec_bus_device_status m_deviceStatus
;
180 std::set
<cec_opcode
> m_unsupportedFeatures
;
181 PLATFORM::CMutex m_mutex
;
182 PLATFORM::CMutex m_handlerMutex
;
183 PLATFORM::CEvent m_replacing
;
184 unsigned m_iHandlerUseCount
;
185 bool m_bAwaitingReceiveFailed
;
186 bool m_bVendorIdRequested
;