[FreeBSD] update adapter detection
[deb_libcec.git] / src / lib / CECProcessor.h
CommitLineData
abbca718
LOK
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
16f47961 5 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
abbca718
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
25701fa6 34#include <string>
004b8382 35
7bb4ed43 36#include "platform/threads/threads.h"
ba65909d 37#include "platform/util/buffer.h"
004b8382 38
b1f94db1 39#include "adapter/AdapterCommunication.h"
004b8382
LOK
40#include "devices/CECDeviceMap.h"
41#include "CECInputBuffer.h"
abbca718 42
abbca718
LOK
43namespace CEC
44{
2abe74eb 45 class CLibCEC;
7bdb5ccb 46 class IAdapterCommunication;
e9de9629 47 class CCECBusDevice;
004b8382
LOK
48 class CCECAudioSystem;
49 class CCECPlaybackDevice;
50 class CCECRecordingDevice;
51 class CCECTuner;
52 class CCECTV;
53 class CCECClient;
171c7eb0
LOK
54 class CCECProcessor;
55
56 class CCECAllocateLogicalAddress : public PLATFORM::CThread
57 {
58 public:
59 CCECAllocateLogicalAddress(CCECProcessor* processor, CCECClient* client);
60 void* Process(void);
61
62 private:
63 CCECProcessor* m_processor;
64 CCECClient* m_client;
65 };
a4b9f561 66
b1f94db1 67 class CCECProcessor : public PLATFORM::CThread, public IAdapterCommunicationCallback
abbca718
LOK
68 {
69 public:
004b8382 70 CCECProcessor(CLibCEC *libcec);
2abe74eb
LOK
71 virtual ~CCECProcessor(void);
72
b32ffd87 73 bool Start(const char *strPort, uint16_t iBaudRate = CEC_SERIAL_DEFAULT_BAUDRATE, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
e186a843
LOK
74 void *Process(void);
75 void Close(void);
76
004b8382 77 bool RegisterClient(CCECClient *client);
4a01fcd6 78 bool UnregisterClient(CCECClient *client);
004b8382 79 void UnregisterClients(void);
a99c6dea 80 uint16_t GetPhysicalAddressFromEeprom(void);
004b8382
LOK
81 CCECClient *GetPrimaryClient(void);
82 CCECClient *GetClient(const cec_logical_address address);
83
e186a843 84 bool OnCommandReceived(const cec_command &command);
171c7eb0 85 void HandleLogicalAddressLost(cec_logical_address oldAddress);
49ba42d4 86 void HandlePhysicalAddressChanged(uint16_t iNewAddress);
e186a843 87
004b8382
LOK
88 CCECBusDevice * GetDevice(cec_logical_address address) const;
89 CCECAudioSystem * GetAudioSystem(void) const;
90 CCECPlaybackDevice * GetPlaybackDevice(cec_logical_address address) const;
91 CCECRecordingDevice * GetRecordingDevice(cec_logical_address address) const;
92 CCECTuner * GetTuner(cec_logical_address address) const;
93 CCECTV * GetTV(void) const;
94
0680dab3 95 CCECBusDevice * GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate = true);
c0152c09
LOK
96 CCECBusDevice * GetPrimaryDevice(void);
97 cec_logical_address GetLogicalAddress(void);
98 cec_logical_addresses GetLogicalAddresses(void);
e186a843
LOK
99 bool IsPresentDevice(cec_logical_address address);
100 bool IsPresentDeviceType(cec_device_type type);
004b8382 101 uint16_t GetDetectedPhysicalAddress(void) const;
e186a843 102 uint64_t GetLastTransmission(void) const { return m_iLastTransmission; }
5734016c 103 cec_logical_address GetActiveSource(bool bRequestActiveSource = true);
e186a843 104 bool IsActiveSource(cec_logical_address iAddress);
004b8382 105 bool CECInitialised(void);
e186a843 106
004b8382
LOK
107 bool StandbyDevices(const cec_logical_address initiator, const CECDEVICEVEC &devices);
108 bool StandbyDevice(const cec_logical_address initiator, cec_logical_address address);
109 bool PowerOnDevices(const cec_logical_address initiator, const CECDEVICEVEC &devices);
110 bool PowerOnDevice(const cec_logical_address initiator, cec_logical_address address);
111
e186a843 112 bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true);
c0152c09 113 bool ActivateSource(uint16_t iStreamPath);
a582c2bb 114 void SetActiveSource(bool bSetTo, bool bClientUnregistered);
e186a843 115 bool PollDevice(cec_logical_address iAddress);
dcd240b2 116 void SetStandardLineTimeout(uint8_t iTimeout);
c0152c09 117 uint8_t GetStandardLineTimeout(void);
dcd240b2 118 void SetRetryLineTimeout(uint8_t iTimeout);
c0152c09 119 uint8_t GetRetryLineTimeout(void);
e186a843 120 bool CanPersistConfiguration(void);
c0152c09 121 bool PersistConfiguration(const libcec_configuration &configuration);
e186a843 122 void RescanActiveDevices(void);
acec5f48 123
855a3a98
LOK
124 bool SetLineTimeout(uint8_t iTimeout);
125
2b44051c 126 bool Transmit(const cec_command &data, bool bIsReply);
004b8382 127 void TransmitAbort(cec_logical_address source, cec_logical_address destination, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
f8513317 128
e186a843
LOK
129 bool StartBootloader(const char *strPort = NULL);
130 bool PingAdapter(void);
131 void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
132 bool HandleReceiveFailed(cec_logical_address initiator);
1113cb7d 133
b32ffd87 134 bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT);
f80cd208 135
b78b4e33
LOK
136 bool TransmitPendingActiveSourceCommands(void);
137
004b8382
LOK
138 CCECDeviceMap *GetDevices(void) const { return m_busDevices; }
139 CLibCEC *GetLib(void) const { return m_libcec; }
abbca718 140
004b8382
LOK
141 bool IsHandledByLibCEC(const cec_logical_address address) const;
142
2b44051c 143 bool TryLogicalAddress(cec_logical_address address, cec_version libCECSpecVersion = CEC_VERSION_1_4);
c0152c09
LOK
144
145 bool IsRunningLatestFirmware(void);
cc0a2977
LOK
146 void SwitchMonitoring(bool bSwitchTo);
147
171c7eb0 148 bool AllocateLogicalAddresses(CCECClient* client);
8768aeca
LOK
149
150 uint16_t GetAdapterVendorId(void) const;
151 uint16_t GetAdapterProductId(void) const;
cc0a2977 152 private:
f80cd208 153 bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true);
004b8382 154 void SetCECInitialised(bool bSetTo = true);
578c3905 155
a3ffc068 156 void ReplaceHandlers(void);
45b97de7 157 bool PhysicalAddressInUse(uint16_t iPhysicalAddress);
2b44051c
LOK
158
159 bool ClearLogicalAddresses(void);
160 bool SetLogicalAddresses(const cec_logical_addresses &addresses);
f8513317 161
9dee1670 162 void LogOutput(const cec_command &data);
c0152c09
LOK
163 void ProcessCommand(const cec_command &command);
164
165 void ResetMembers(void);
abbca718 166
004b8382
LOK
167 bool m_bInitialised;
168 PLATFORM::CMutex m_mutex;
169 IAdapterCommunication * m_communication;
170 CLibCEC* m_libcec;
004b8382
LOK
171 uint8_t m_iStandardLineTimeout;
172 uint8_t m_iRetryLineTimeout;
173 uint64_t m_iLastTransmission;
174 CCECInputBuffer m_inBuffer;
175 CCECDeviceMap * m_busDevices;
176 std::map<cec_logical_address, CCECClient *> m_clients;
cc0a2977 177 bool m_bMonitor;
171c7eb0 178 CCECAllocateLogicalAddress* m_addrAllocator;
6f99b2bb 179 bool m_bStallCommunication;
7c63a480 180 };
abbca718 181};