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