cec: fixed - send a feature abort as reply to vendor commands
[deb_libcec.git] / src / lib / implementations / VLCommandHandler.cpp
CommitLineData
bb5b4874
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
b492c10e 4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
bb5b4874
LOK
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 "VLCommandHandler.h"
34#include "../devices/CECBusDevice.h"
3e61b350 35#include "../CECProcessor.h"
b78b4e33 36#include "../LibCEC.h"
004b8382 37#include "../CECClient.h"
b78b4e33
LOK
38
39#define VL_POWER_CHANGE 0x20
40#define VL_POWERED_UP 0x00
41#define VL_POWERED_DOWN 0x01
bb5b4874
LOK
42
43using namespace CEC;
b78b4e33 44using namespace PLATFORM;
bb5b4874 45
004b8382
LOK
46#define LIB_CEC m_busDevice->GetProcessor()->GetLib()
47#define ToString(p) LIB_CEC->ToString(p)
48
bb5b4874 49CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) :
b78b4e33
LOK
50 CCECCommandHandler(busDevice),
51 m_bActiveSourcePending(false),
52 m_bPowerUpEventReceived(false)
bb5b4874 53{
cf4931be 54 m_vendorId = CEC_VENDOR_PANASONIC;
bb5b4874 55}
3e61b350
LOK
56
57bool CVLCommandHandler::InitHandler(void)
58{
59 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
42d28d15
LOK
60 if (primary && primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED)
61 {
62 /* use the VL commandhandler for the primary device that is handled by libCEC */
63 if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV)
64 {
65 if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
66 {
67 primary->SetVendorId(CEC_VENDOR_PANASONIC);
68 primary->ReplaceHandler(false);
69 }
70 }
71
72 if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)
73 return m_processor->GetPrimaryClient()->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
74 }
b78b4e33 75
3e61b350
LOK
76 return CCECCommandHandler::InitHandler();
77}
b78b4e33
LOK
78
79bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
80{
81 if (command.initiator == CECDEVICE_TV &&
82 command.destination == CECDEVICE_BROADCAST &&
83 command.parameters.At(3) == VL_POWER_CHANGE)
84 {
85 if (command.parameters.At(4) == VL_POWERED_UP)
86 {
004b8382 87 LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV powered up");
b78b4e33
LOK
88 {
89 CLockObject lock(m_mutex);
90 m_bPowerUpEventReceived = true;
91 }
92 m_processor->TransmitPendingActiveSourceCommands();
93 }
94 else if (command.parameters.At(4) == VL_POWERED_DOWN)
004b8382 95 LIB_CEC->AddLog(CEC_LOG_DEBUG, "TV powered down");
b78b4e33 96 else if (command.parameters.At(4) == VL_POWERED_DOWN)
004b8382 97 LIB_CEC->AddLog(CEC_LOG_DEBUG, "unknown vendor command");
b78b4e33
LOK
98
99 return true;
100 }
101
102 return CCECCommandHandler::HandleDeviceVendorCommandWithId(command);
103}
104
105bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
106{
107 bool bPowerUpEventReceived(false);
108
004b8382
LOK
109 CCECBusDevice *tv = m_processor->GetDevice(CECDEVICE_TV);
110 if (tv && tv->GetCurrentVendorId() == CEC_VENDOR_PANASONIC)
b78b4e33 111 {
b47f66af
LOK
112 CVLCommandHandler *handler = static_cast<CVLCommandHandler *>(tv->GetHandler());
113 bPowerUpEventReceived = handler ? handler->PowerUpEventReceived() : false;
91ef4e2d 114 tv->MarkHandlerReady();
b78b4e33
LOK
115 }
116
117 if (!bPowerUpEventReceived)
118 {
119 CLockObject lock(m_mutex);
120 // wait until we received the event
121 m_bActiveSourcePending = true;
122 return true;
123 }
124 else
125 {
126 // transmit standard active source message
e8a6f887 127 return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress);
b78b4e33
LOK
128 }
129}
130
131bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void)
132{
133 bool bTransmitCommand(false);
134 {
135 CLockObject lock(m_mutex);
136 bTransmitCommand = m_bActiveSourcePending;
137 m_bActiveSourcePending = false;
138 }
139
140 if (bTransmitCommand)
141 {
004b8382 142 LIB_CEC->AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command");
6d7c0fa8
LOK
143 return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetCurrentPhysicalAddress()) &&
144 TransmitMenuState(m_busDevice->GetLogicalAddress(), CECDEVICE_TV, CEC_MENU_STATE_ACTIVATED);
b78b4e33
LOK
145 }
146 return true;
147}
b47f66af
LOK
148
149bool CVLCommandHandler::PowerUpEventReceived(void)
150{
151 {
152 CLockObject lock(m_mutex);
153 if (m_bPowerUpEventReceived)
154 return true;
155 }
156
e8a6f887
LOK
157 cec_logical_address sourceLA = m_busDevice->GetLogicalAddress();
158 if (sourceLA == CECDEVICE_TV)
159 sourceLA = m_processor->GetPrimaryDevice()->GetLogicalAddress();
160
161 cec_power_status powerStatus = m_busDevice->GetPowerStatus(sourceLA);
b47f66af
LOK
162
163 CLockObject lock(m_mutex);
164 m_bPowerUpEventReceived = (powerStatus == CEC_POWER_STATUS_ON);
165 return m_bPowerUpEventReceived;
166}