Merge branch 'master' into release
[deb_libcec.git] / src / lib / adapter / TDA995x / TDA995xCECAdapterCommunication.h
CommitLineData
4d3a7562 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.
4d3a7562 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
51b611bc 34#if defined(HAVE_TDA995X_API)
4d3a7562 35
36#include "lib/platform/threads/mutex.h"
37#include "lib/platform/threads/threads.h"
38#include "lib/platform/sockets/socket.h"
39#include "lib/adapter/AdapterCommunication.h"
40#include <map>
41
79e50026
LOK
42#define TDA995X_ADAPTER_VID 0x0471
43#define TDA995X_ADAPTER_PID 0x1001
4d3a7562 44
45namespace PLATFORM
46{
47 class CCDevSocket;
48};
49
50
51namespace CEC
52{
53 class CAdapterMessageQueueEntry;
54
79e50026 55 class CTDA995xCECAdapterCommunication : public IAdapterCommunication, public PLATFORM::CThread
4d3a7562 56 {
57 public:
58 /*!
59 * @brief Create a new USB-CEC communication handler.
60 * @param callback The callback to use for incoming CEC commands.
61 */
79e50026
LOK
62 CTDA995xCECAdapterCommunication(IAdapterCommunicationCallback *callback);
63 virtual ~CTDA995xCECAdapterCommunication(void);
4d3a7562 64
65 /** @name IAdapterCommunication implementation */
66 ///{
67 bool Open(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT, bool bSkipChecks = false, bool bStartListening = true);
68 void Close(void);
69 bool IsOpen(void);
70 std::string GetError(void) const;
71 cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout, bool bIsReply);
72
73 bool SetLineTimeout(uint8_t UNUSED(iTimeout)) { return true; }
74 bool StartBootloader(void) { return false; }
75 bool SetLogicalAddresses(const cec_logical_addresses &addresses);
76 cec_logical_addresses GetLogicalAddresses(void);
77 bool PingAdapter(void) { return IsInitialised(); }
78 uint16_t GetFirmwareVersion(void);
79 uint32_t GetFirmwareBuildDate(void) { return 0; }
80 bool IsRunningLatestFirmware(void) { return true; }
81 bool PersistConfiguration(const libcec_configuration & UNUSED(configuration)) { return false; }
82 bool GetConfiguration(libcec_configuration & UNUSED(configuration)) { return false; }
79e50026 83 std::string GetPortName(void) { return std::string("TDA995X"); }
4d3a7562 84 uint16_t GetPhysicalAddress(void);
85 bool SetControlledMode(bool UNUSED(controlled)) { return true; }
86 cec_vendor_id GetVendorId(void);
87 bool SupportsSourceLogicalAddress(const cec_logical_address address) { return address > CECDEVICE_TV && address <= CECDEVICE_BROADCAST; }
51b611bc 88 cec_adapter_type GetAdapterType(void) { return ADAPTERTYPE_TDA995x; }
79e50026
LOK
89 uint16_t GetAdapterVendorId(void) const { return TDA995X_ADAPTER_VID; }
90 uint16_t GetAdapterProductId(void) const { return TDA995X_ADAPTER_PID; }
4d3a7562 91 void HandleLogicalAddressLost(cec_logical_address oldAddress);
a582c2bb 92 void SetActiveSource(bool UNUSED(bSetTo), bool UNUSED(bClientUnregistered)) {}
4d3a7562 93 ///}
94
95 /** @name PLATFORM::CThread implementation */
96 ///{
97 void *Process(void);
98 ///}
99
100 private:
101 bool IsInitialised(void) const { return m_dev != 0; };
102
103 std::string m_strError; /**< current error message */
104
105 bool m_bLogicalAddressChanged;
106 cec_logical_addresses m_logicalAddresses;
107
108 PLATFORM::CMutex m_mutex;
51b611bc 109 PLATFORM::CCDevSocket *m_dev; /**< the device connection */
4d3a7562 110
111 PLATFORM::CMutex m_messageMutex;
112 uint32_t m_iNextMessage;
113 std::map<uint32_t, CAdapterMessageQueueEntry *> m_messages;
114 };
115
116};
117
118#endif