Merge branch 'master' into release
[deb_libcec.git] / src / lib / devices / CECBusDevice.h
CommitLineData
e9de9629
LOK
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
b492c10e 5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
e9de9629
LOK
6 * libCEC(R) is an original work, containing original code.
7 *
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 *
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.
14 *
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.
19 *
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.
23 *
24 *
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
27 *
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/
32 */
33
4c9b9776 34#include "../../../include/cectypes.h"
4d738fe3 35#include <set>
ba65909d
LOK
36#include "../platform/threads/mutex.h"
37#include "../platform/util/StdString.h"
e9de9629
LOK
38
39namespace CEC
40{
004b8382 41 class CCECClient;
e9de9629 42 class CCECProcessor;
1b5cc4a2 43 class CCECCommandHandler;
004b8382
LOK
44 class CCECAudioSystem;
45 class CCECPlaybackDevice;
46 class CCECRecordingDevice;
47 class CCECTuner;
48 class CCECTV;
e9de9629
LOK
49
50 class CCECBusDevice
51 {
787a3cb8
LOK
52 friend class CCECProcessor;
53
e9de9629 54 public:
d2d1660c 55 CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
e9de9629
LOK
56 virtual ~CCECBusDevice(void);
57
004b8382
LOK
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; }
f8ae3295
LOK
63 virtual cec_logical_address GetLogicalAddress(void) const { return m_iLogicalAddress; }
64 virtual const char* GetLogicalAddressName(void) const;
004b8382
LOK
65 virtual bool IsPresent(void);
66 virtual bool IsHandledByLibCEC(void);
67
68 virtual bool HandleCommand(const cec_command &command);
33dd87a9 69 virtual bool IsUnsupportedFeature(cec_opcode opcode);
4d738fe3 70 virtual void SetUnsupportedFeature(cec_opcode opcode);
004b8382
LOK
71
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);
74
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);
79
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);
85
86 virtual bool TransmitOSDString(const cec_logical_address destination, cec_display_control duration, const char *strMessage);
87
c0152c09 88 virtual CStdString GetCurrentOSDName(void);
004b8382
LOK
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);
93
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);
100
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);
106
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);
113
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);
0cfdeb5a 121 virtual bool HandleReceiveFailed(void);
e9de9629 122
004b8382
LOK
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);
126
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);
137
138 virtual bool PowerOn(const cec_logical_address initiator);
139 virtual bool Standby(const cec_logical_address initiator);
140
141 virtual bool TryLogicalAddress(void);
142
143 CCECClient * GetClient(void);
144
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);
153 CCECTV * AsTV(void);
154 static CCECTV * AsTV(CCECBusDevice *device);
5734016c 155
e9de9629 156 protected:
004b8382 157 void CheckVendorIdRequested(const cec_logical_address source);
1344fd1a
LOK
158 void MarkBusy(void);
159 void MarkReady(void);
b64db02e 160
9fd73dd4
LOK
161 bool NeedsPoll(void);
162
f8ae3295
LOK
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;
b64db02e 173 bool m_bReplaceHandler;
f8ae3295
LOK
174 cec_menu_state m_menuState;
175 bool m_bActiveSource;
f8ae3295 176 uint64_t m_iLastActive;
2efa39b7 177 uint64_t m_iLastPowerStateUpdate;
f8ae3295
LOK
178 cec_version m_cecVersion;
179 cec_bus_device_status m_deviceStatus;
4d738fe3 180 std::set<cec_opcode> m_unsupportedFeatures;
f00ff009
LOK
181 PLATFORM::CMutex m_mutex;
182 PLATFORM::CMutex m_handlerMutex;
67b9d205 183 PLATFORM::CEvent m_replacing;
1344fd1a 184 unsigned m_iHandlerUseCount;
ef583662 185 bool m_bAwaitingReceiveFailed;
ebb6ddb3 186 bool m_bVendorIdRequested;
e9de9629
LOK
187 };
188};