cec: cleanups, documentation and some fixes for the last commits
[deb_libcec.git] / src / lib / CECProcessor.h
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 <string>
35 #include "../../include/cectypes.h"
36
37 #include "platform/threads/threads.h"
38 #include "platform/util/buffer.h"
39
40 #include "adapter/AdapterCommunication.h"
41 #include "devices/CECDeviceMap.h"
42 #include "CECInputBuffer.h"
43
44 namespace CEC
45 {
46 class CLibCEC;
47 class IAdapterCommunication;
48 class CCECBusDevice;
49 class CCECAudioSystem;
50 class CCECPlaybackDevice;
51 class CCECRecordingDevice;
52 class CCECTuner;
53 class CCECTV;
54 class CCECClient;
55
56 class CCECProcessor : public PLATFORM::CThread, public IAdapterCommunicationCallback
57 {
58 public:
59 CCECProcessor(CLibCEC *libcec);
60 virtual ~CCECProcessor(void);
61
62 bool Start(const char *strPort, uint16_t iBaudRate = CEC_SERIAL_DEFAULT_BAUDRATE, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
63 void *Process(void);
64 void Close(void);
65
66 bool RegisterClient(CCECClient *client);
67 void UnregisterClient(CCECClient *client);
68 void UnregisterClients(void);
69 CCECClient *GetPrimaryClient(void);
70 CCECClient *GetClient(const cec_logical_address address);
71
72 bool OnCommandReceived(const cec_command &command);
73
74 bool IsMonitoring(void) const { return m_bMonitor; }
75 CCECBusDevice * GetDevice(cec_logical_address address) const;
76 CCECAudioSystem * GetAudioSystem(void) const;
77 CCECPlaybackDevice * GetPlaybackDevice(cec_logical_address address) const;
78 CCECRecordingDevice * GetRecordingDevice(cec_logical_address address) const;
79 CCECTuner * GetTuner(cec_logical_address address) const;
80 CCECTV * GetTV(void) const;
81
82 CCECBusDevice * GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate = true);
83 CCECBusDevice * GetPrimaryDevice(void);
84 cec_logical_address GetLogicalAddress(void);
85 cec_logical_addresses GetLogicalAddresses(void);
86 bool IsPresentDevice(cec_logical_address address);
87 bool IsPresentDeviceType(cec_device_type type);
88 uint16_t GetDetectedPhysicalAddress(void) const;
89 uint64_t GetLastTransmission(void) const { return m_iLastTransmission; }
90 cec_logical_address GetActiveSource(bool bRequestActiveSource = true);
91 bool IsActiveSource(cec_logical_address iAddress);
92 bool CECInitialised(void);
93 bool SetStreamPath(uint16_t iPhysicalAddress);
94
95 bool StandbyDevices(const cec_logical_address initiator, const CECDEVICEVEC &devices);
96 bool StandbyDevice(const cec_logical_address initiator, cec_logical_address address);
97 bool PowerOnDevices(const cec_logical_address initiator, const CECDEVICEVEC &devices);
98 bool PowerOnDevice(const cec_logical_address initiator, cec_logical_address address);
99
100 bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
101 bool ActivateSource(uint16_t iStreamPath);
102 bool SwitchMonitoring(bool bEnable);
103 bool PollDevice(cec_logical_address iAddress);
104 void SetStandardLineTimeout(uint8_t iTimeout);
105 uint8_t GetStandardLineTimeout(void);
106 void SetRetryLineTimeout(uint8_t iTimeout);
107 uint8_t GetRetryLineTimeout(void);
108 bool CanPersistConfiguration(void);
109 bool PersistConfiguration(const libcec_configuration &configuration);
110 void RescanActiveDevices(void);
111
112 bool SetLineTimeout(uint8_t iTimeout);
113
114 bool Transmit(const cec_command &data);
115 void TransmitAbort(cec_logical_address source, cec_logical_address destination, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
116
117 bool StartBootloader(const char *strPort = NULL);
118 bool PingAdapter(void);
119 void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
120 bool HandleReceiveFailed(cec_logical_address initiator);
121
122 bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
123
124 bool TransmitPendingActiveSourceCommands(void);
125
126 CCECDeviceMap *GetDevices(void) const { return m_busDevices; }
127 CLibCEC *GetLib(void) const { return m_libcec; }
128
129 bool IsHandledByLibCEC(const cec_logical_address address) const;
130
131 bool TryLogicalAddress(cec_logical_address address);
132
133 bool IsRunningLatestFirmware(void);
134 private:
135 bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true);
136 void SetCECInitialised(bool bSetTo = true);
137
138 void ReplaceHandlers(void);
139 bool PhysicalAddressInUse(uint16_t iPhysicalAddress);
140 bool SetAckMask(uint16_t iMask);
141
142 void LogOutput(const cec_command &data);
143 void ProcessCommand(const cec_command &command);
144
145 void ResetMembers(void);
146
147 bool m_bInitialised;
148 PLATFORM::CMutex m_mutex;
149 IAdapterCommunication * m_communication;
150 CLibCEC* m_libcec;
151 bool m_bMonitor;
152 uint16_t m_iPreviousAckMask;
153 uint8_t m_iStandardLineTimeout;
154 uint8_t m_iRetryLineTimeout;
155 uint64_t m_iLastTransmission;
156 CCECInputBuffer m_inBuffer;
157 CCECDeviceMap * m_busDevices;
158 std::map<cec_logical_address, CCECClient *> m_clients;
159 };
160 };