cec: display an alert message when the firmware of the adapter can be upgraded. bugzi...
[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
LOK
36#include "../LibCEC.h"
37
38#define VL_POWER_CHANGE 0x20
39#define VL_POWERED_UP 0x00
40#define VL_POWERED_DOWN 0x01
bb5b4874
LOK
41
42using namespace CEC;
b78b4e33 43using namespace PLATFORM;
bb5b4874
LOK
44
45CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice) :
b78b4e33
LOK
46 CCECCommandHandler(busDevice),
47 m_bActiveSourcePending(false),
48 m_bPowerUpEventReceived(false)
bb5b4874 49{
cf4931be 50 m_vendorId = CEC_VENDOR_PANASONIC;
b47f66af
LOK
51
52 /* use the VL commandhandler for the primary device that is handled by libCEC */
53 if (busDevice->GetLogicalAddress() == CECDEVICE_TV)
54 {
55 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
56 if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress())
57 {
58 primary->SetVendorId(CEC_VENDOR_PANASONIC);
59 primary->ReplaceHandler(false);
60 }
61 }
bb5b4874 62}
3e61b350
LOK
63
64bool CVLCommandHandler::InitHandler(void)
65{
66 CCECBusDevice *primary = m_processor->GetPrimaryDevice();
67 if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)
3e61b350 68 return m_processor->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
b78b4e33 69
3e61b350
LOK
70 return CCECCommandHandler::InitHandler();
71}
b78b4e33
LOK
72
73bool CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
74{
75 if (command.initiator == CECDEVICE_TV &&
76 command.destination == CECDEVICE_BROADCAST &&
77 command.parameters.At(3) == VL_POWER_CHANGE)
78 {
79 if (command.parameters.At(4) == VL_POWERED_UP)
80 {
81 CLibCEC::AddLog(CEC_LOG_DEBUG, "TV powered up");
82 {
83 CLockObject lock(m_mutex);
84 m_bPowerUpEventReceived = true;
85 }
86 m_processor->TransmitPendingActiveSourceCommands();
87 }
88 else if (command.parameters.At(4) == VL_POWERED_DOWN)
89 CLibCEC::AddLog(CEC_LOG_DEBUG, "TV powered down");
90 else if (command.parameters.At(4) == VL_POWERED_DOWN)
91 CLibCEC::AddLog(CEC_LOG_DEBUG, "unknown vendor command");
92
93 return true;
94 }
95
96 return CCECCommandHandler::HandleDeviceVendorCommandWithId(command);
97}
98
99bool CVLCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
100{
101 bool bPowerUpEventReceived(false);
102
b47f66af
LOK
103 CCECBusDevice *tv = m_processor->m_busDevices[CECDEVICE_TV];
104 if (tv && tv->GetVendorId(false) == CEC_VENDOR_PANASONIC)
b78b4e33 105 {
b47f66af
LOK
106 CVLCommandHandler *handler = static_cast<CVLCommandHandler *>(tv->GetHandler());
107 bPowerUpEventReceived = handler ? handler->PowerUpEventReceived() : false;
b78b4e33
LOK
108 }
109
110 if (!bPowerUpEventReceived)
111 {
112 CLockObject lock(m_mutex);
113 // wait until we received the event
114 m_bActiveSourcePending = true;
115 return true;
116 }
117 else
118 {
119 // transmit standard active source message
120 return CCECCommandHandler::TransmitActiveSource(iInitiator, iPhysicalAddress);
121 }
122}
123
124bool CVLCommandHandler::TransmitPendingActiveSourceCommands(void)
125{
126 bool bTransmitCommand(false);
127 {
128 CLockObject lock(m_mutex);
129 bTransmitCommand = m_bActiveSourcePending;
130 m_bActiveSourcePending = false;
131 }
132
133 if (bTransmitCommand)
134 {
135 CLibCEC::AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command");
0680dab3 136 return CCECCommandHandler::TransmitActiveSource(m_busDevice->GetLogicalAddress(), m_busDevice->GetPhysicalAddress());
b78b4e33
LOK
137 }
138 return true;
139}
b47f66af
LOK
140
141bool CVLCommandHandler::PowerUpEventReceived(void)
142{
143 {
144 CLockObject lock(m_mutex);
145 if (m_bPowerUpEventReceived)
146 return true;
147 }
148
149 cec_power_status powerStatus = m_busDevice->GetPowerStatus();
150
151 CLockObject lock(m_mutex);
152 m_bPowerUpEventReceived = (powerStatus == CEC_POWER_STATUS_ON);
153 return m_bPowerUpEventReceived;
154}