Commit | Line | Data |
---|---|---|
e9de9629 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. | |
5 | * libCEC(R) is an original work, containing original code. | |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
33 | #include "CECBusDevice.h" | |
34 | #include "CECProcessor.h" | |
1b5cc4a2 LOK |
35 | #include "implementations/ANCommandHandler.h" |
36 | #include "implementations/CECCommandHandler.h" | |
37 | #include "implementations/SLCommandHandler.h" | |
e9de9629 LOK |
38 | |
39 | using namespace CEC; | |
40 | ||
41 | CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) : | |
42 | m_iPhysicalAddress(iPhysicalAddress), | |
43 | m_iLogicalAddress(iLogicalAddress), | |
44 | m_processor(processor), | |
45 | m_iVendorId(0), | |
46 | m_iVendorClass(0) | |
47 | { | |
48 | m_handler = new CCECCommandHandler(this); | |
49 | } | |
50 | ||
51 | CCECBusDevice::~CCECBusDevice(void) | |
52 | { | |
53 | delete m_handler; | |
54 | } | |
55 | ||
56 | cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const | |
57 | { | |
58 | return m_processor->GetLogicalAddress(); | |
59 | } | |
60 | ||
61 | uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const | |
62 | { | |
63 | return m_processor->GetPhysicalAddress(); | |
64 | } | |
65 | ||
66 | void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage) | |
67 | { | |
68 | m_processor->AddLog(level, strMessage); | |
69 | } | |
70 | ||
71 | void CCECBusDevice::SetVendorId(uint16_t iVendorId, uint8_t iVendorClass /* = 0 */) | |
72 | { | |
73 | delete m_handler; | |
74 | m_iVendorId = iVendorId; | |
75 | m_iVendorClass = iVendorClass; | |
76 | ||
77 | switch (iVendorId) | |
78 | { | |
79 | case CEC_VENDOR_SAMSUNG: | |
80 | m_handler = new CANCommandHandler(this); | |
81 | break; | |
82 | case CEC_VENDOR_LG: | |
83 | m_handler = new CSLCommandHandler(this); | |
84 | break; | |
85 | default: | |
86 | m_handler = new CCECCommandHandler(this); | |
87 | break; | |
88 | } | |
89 | ||
90 | CStdString strLog; | |
91 | strLog.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress, CECVendorIdToString(iVendorId), iVendorId, iVendorClass); | |
92 | m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
93 | } | |
94 | ||
95 | bool CCECBusDevice::HandleCommand(const cec_command &command) | |
96 | { | |
97 | CLockObject lock(&m_mutex); | |
98 | m_handler->HandleCommand(command); | |
99 | return true; | |
100 | } | |
101 | ||
102 | const char *CCECBusDevice::CECVendorIdToString(const uint64_t iVendorId) | |
103 | { | |
104 | switch (iVendorId) | |
105 | { | |
106 | case CEC_VENDOR_SAMSUNG: | |
107 | return "Samsung"; | |
108 | case CEC_VENDOR_LG: | |
109 | return "LG"; | |
110 | default: | |
111 | return "Unknown"; | |
112 | } | |
113 | } |