cec: refactor CEC command handling. split up standard and non-standard CEC implementa...
[deb_libcec.git] / src / lib / CECBusDevice.cpp
CommitLineData
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"
35#include "ANCommandHandler.h"
36#include "SLCommandHandler.h"
37
38using namespace CEC;
39
40CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
41 m_iPhysicalAddress(iPhysicalAddress),
42 m_iLogicalAddress(iLogicalAddress),
43 m_processor(processor),
44 m_iVendorId(0),
45 m_iVendorClass(0)
46{
47 m_handler = new CCECCommandHandler(this);
48}
49
50CCECBusDevice::~CCECBusDevice(void)
51{
52 delete m_handler;
53}
54
55cec_logical_address CCECBusDevice::GetMyLogicalAddress(void) const
56{
57 return m_processor->GetLogicalAddress();
58}
59
60uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
61{
62 return m_processor->GetPhysicalAddress();
63}
64
65void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage)
66{
67 m_processor->AddLog(level, strMessage);
68}
69
70void CCECBusDevice::SetVendorId(uint16_t iVendorId, uint8_t iVendorClass /* = 0 */)
71{
72 delete m_handler;
73 m_iVendorId = iVendorId;
74 m_iVendorClass = iVendorClass;
75
76 switch (iVendorId)
77 {
78 case CEC_VENDOR_SAMSUNG:
79 m_handler = new CANCommandHandler(this);
80 break;
81 case CEC_VENDOR_LG:
82 m_handler = new CSLCommandHandler(this);
83 break;
84 default:
85 m_handler = new CCECCommandHandler(this);
86 break;
87 }
88
89 CStdString strLog;
90 strLog.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress, CECVendorIdToString(iVendorId), iVendorId, iVendorClass);
91 m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str());
92}
93
94bool CCECBusDevice::HandleCommand(const cec_command &command)
95{
96 CLockObject lock(&m_mutex);
97 m_handler->HandleCommand(command);
98 return true;
99}
100
101const char *CCECBusDevice::CECVendorIdToString(const uint64_t iVendorId)
102{
103 switch (iVendorId)
104 {
105 case CEC_VENDOR_SAMSUNG:
106 return "Samsung";
107 case CEC_VENDOR_LG:
108 return "LG";
109 default:
110 return "Unknown";
111 }
112}