cec: serial port locking on linux
[deb_libcec.git] / src / lib / CECClient.h
CommitLineData
004b8382
LOK
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
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
34#include "../../include/cectypes.h"
35#include "platform/threads/mutex.h"
36#include "platform/util/buffer.h"
37
38#include "devices/CECBusDevice.h"
39
40namespace CEC
41{
42 class CCECProcessor;
43
44 class CCECClient
45 {
46 public:
c0152c09 47 CCECClient(CCECProcessor *processor, const libcec_configuration &configuration);
004b8382
LOK
48 virtual ~CCECClient(void);
49
50 // methods for registration in CCECProcessor
c0152c09
LOK
51 bool OnRegister(void);
52 void OnUnregister(void) { SetRegistered(false); SetInitialised(false); }
53 bool IsInitialised(void);
54 void SetInitialised(bool bSetTo);
55 bool IsRegistered(void);
56 void SetRegistered(bool bSetTo);
57 cec_logical_address GetPrimaryLogicalAdddress(void);
58
59 // device specific methods
60 CCECBusDevice * GetPrimaryDevice(void);
61 CCECPlaybackDevice * GetPlaybackDevice(void);
62 bool AllocateLogicalAddresses(void);
63 bool ChangeDeviceType(const cec_device_type from, const cec_device_type to);
64 CCECBusDevice * GetDeviceByType(const cec_device_type type) const;
65 void ResetPhysicalAddress(void);
66 CStdString GetConnectionInfo(void);
67 void SetTVVendorOverride(const cec_vendor_id id);
68 cec_vendor_id GetTVVendorOverride(void);
69 void SetOSDName(const CStdString &strDeviceName);
70 CStdString GetOSDName(void);
71 void SetWakeDevices(const cec_logical_addresses &addresses);
72 cec_logical_addresses GetWakeDevices(void);
73 bool AutodetectPhysicalAddress(void);
74 void SetClientVersion(const cec_client_version version);
75 cec_client_version GetClientVersion(void);
76 bool SetDeviceTypes(const cec_device_type_list &deviceTypes);
77 cec_device_type_list GetDeviceTypes(void);
004b8382
LOK
78
79 // client-specific part of ICECAdapter
c0152c09
LOK
80 bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks);
81 bool PingAdapter(void);
82 bool GetNextLogMessage(cec_log_message *message); /**< @deprecated will be removed in v2.0 */
83 bool GetNextKeypress(cec_keypress *key); /**< @deprecated will be removed in v2.0 */
84 bool GetNextCommand(cec_command *command); /**< @deprecated will be removed in v2.0 */
85 bool Transmit(const cec_command &data);
86 bool SetLogicalAddress(const cec_logical_address iLogicalAddress);
87 bool SetPhysicalAddress(const uint16_t iPhysicalAddress);
88 bool SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_t iPort, bool bForce = false);
89 bool SendPowerOnDevices(const cec_logical_address address = CECDEVICE_TV);
90 bool SendStandbyDevices(const cec_logical_address address = CECDEVICE_BROADCAST);
91 bool SendSetActiveSource(const cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
92 bool SendSetDeckControlMode(const cec_deck_control_mode mode, bool bSendUpdate = true);
93 bool SendSetDeckInfo(const cec_deck_info info, bool bSendUpdate = true);
94 bool SendSetInactiveView(void);
95 bool SendSetMenuState(const cec_menu_state state, bool bSendUpdate = true);
96 bool SendSetOSDString(const cec_logical_address iLogicalAddress, const cec_display_control duration, const char *strMessage);
97 bool SwitchMonitoring(bool bEnable);
98 cec_version GetDeviceCecVersion(const cec_logical_address iAddress);
99 bool GetDeviceMenuLanguage(const cec_logical_address iAddress, cec_menu_language &language);
100 uint64_t GetDeviceVendorId(const cec_logical_address iAddress);
101 cec_power_status GetDevicePowerStatus(const cec_logical_address iAddress);
102 uint16_t GetDevicePhysicalAddress(const cec_logical_address iAddress);
103 bool PollDevice(const cec_logical_address iAddress);
104 cec_logical_addresses GetActiveDevices(void);
105 bool IsActiveDevice(const cec_logical_address iAddress);
106 bool IsActiveDeviceType(const cec_device_type type);
107 uint8_t SendVolumeUp(bool bSendRelease = true);
108 uint8_t SendVolumeDown(bool bSendRelease = true);
109 uint8_t SendMuteAudio(void);
110 bool SendKeypress(const cec_logical_address iDestination, const cec_user_control_code key, bool bWait = true);
111 bool SendKeyRelease(const cec_logical_address iDestination, bool bWait = true);
112 cec_osd_name GetDeviceOSDName(const cec_logical_address iAddress);
113 cec_logical_address GetActiveSource(void);
114 bool IsActiveSource(const cec_logical_address iAddress);
115 bool SetStreamPath(const cec_logical_address iAddress);
116 bool SetStreamPath(const uint16_t iPhysicalAddress);
117 cec_logical_addresses GetLogicalAddresses(void);
118 void RescanActiveDevices(void);
119 bool IsLibCECActiveSource(void);
004b8382
LOK
120
121 // configuration
122 libcec_configuration *GetConfiguration(void) { return &m_configuration; }
c0152c09
LOK
123 bool GetCurrentConfiguration(libcec_configuration &configuration);
124 bool SetConfiguration(const libcec_configuration &configuration);
125 bool CanPersistConfiguration(void);
126 bool PersistConfiguration(const libcec_configuration &configuration);
127 void SetPhysicalAddress(const libcec_configuration &configuration);
004b8382
LOK
128
129 // callbacks
c0152c09
LOK
130 void AddCommand(const cec_command &command);
131 int MenuStateChanged(const cec_menu_state newState);
132 void Alert(const libcec_alert type, const libcec_parameter &param);
133 void AddLog(const cec_log_message &message);
134 void AddKey(void);
135 void AddKey(const cec_keypress &key);
136 void SetCurrentButton(const cec_user_control_code iButtonCode);
137 void CheckKeypressTimeout(void);
138 void ConfigurationChanged(const libcec_configuration &config);
004b8382
LOK
139
140 protected:
c0152c09
LOK
141 cec_logical_address AllocateLogicalAddressRecordingDevice(void);
142 cec_logical_address AllocateLogicalAddressTuner(void);
143 cec_logical_address AllocateLogicalAddressPlaybackDevice(void);
144 cec_logical_address AllocateLogicalAddressAudioSystem(void);
145
146 bool SetDevicePhysicalAddress(const uint16_t iPhysicalAddress);
004b8382
LOK
147
148 CCECProcessor * m_processor;
149 libcec_configuration m_configuration;
150 bool m_bInitialised;
151 bool m_bRegistered;
152 PLATFORM::CMutex m_mutex;
153 PLATFORM::SyncedBuffer<cec_log_message> m_logBuffer;
154 PLATFORM::CMutex m_logMutex;
155 PLATFORM::SyncedBuffer<cec_keypress> m_keyBuffer;
156 PLATFORM::SyncedBuffer<cec_command> m_commandBuffer;
157 cec_user_control_code m_iCurrentButton;
158 int64_t m_buttontime;
159 };
160}