cec: don't unregister clients in CLibCEC when disconnecting, but only in CCECProcesso...
[deb_libcec.git] / src / lib / LibCEC.cpp
CommitLineData
2abe74eb
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.
2abe74eb
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 "LibCEC.h"
34
7bb4ed43 35#include "adapter/USBCECAdapterDetection.h"
08d80226 36#include "adapter/USBCECAdapterCommunication.h"
2abe74eb 37#include "CECProcessor.h"
0d800fe5 38#include "CECTypeUtils.h"
004b8382 39#include "devices/CECAudioSystem.h"
0f23c85c 40#include "devices/CECBusDevice.h"
004b8382
LOK
41#include "devices/CECPlaybackDevice.h"
42#include "devices/CECTV.h"
ba65909d
LOK
43#include "platform/util/timeutils.h"
44#include "platform/util/StdString.h"
c9d15485 45#include "platform/util/util.h"
2abe74eb 46
004b8382
LOK
47#include "CECClient.h"
48
2abe74eb
LOK
49using namespace std;
50using namespace CEC;
f00ff009 51using namespace PLATFORM;
2abe74eb 52
c9d15485 53//TODO replace deprecated constructor in 2.0
c30acafa
LOK
54CLibCEC::CLibCEC(const char *UNUSED(strDeviceName), cec_device_type_list UNUSED(types), uint16_t UNUSED(iPhysicalAddress) /* = 0 */) :
55 m_iStartTime(GetTimeMs()),
56 m_client(NULL)
57{
58 m_cec = new CCECProcessor(this);
59}
60
c9d15485 61//TODO replace deprecated constructor in 2.0
c30acafa
LOK
62CLibCEC::CLibCEC(libcec_configuration *UNUSED(configuration)) :
63 m_iStartTime(GetTimeMs()),
64 m_client(NULL)
caca2d81 65{
004b8382 66 m_cec = new CCECProcessor(this);
f8513317
LOK
67}
68
2abe74eb
LOK
69CLibCEC::~CLibCEC(void)
70{
c0152c09
LOK
71 // unregister all clients client
72 UnregisterClients();
73
74 // delete the adapter connection
c9d15485 75 DELETE_AND_NULL(m_cec);
2abe74eb
LOK
76}
77
b32ffd87 78bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
2abe74eb 79{
c0152c09 80 if (!m_cec || !strPort)
99aeafb9
LOK
81 return false;
82
c0152c09 83 // open a new connection
b32ffd87 84 if (!m_cec->Start(strPort, CEC_SERIAL_DEFAULT_BAUDRATE, iTimeoutMs))
2abe74eb
LOK
85 {
86 AddLog(CEC_LOG_ERROR, "could not start CEC communications");
87 return false;
88 }
89
c0152c09 90 // register all clients
004b8382
LOK
91 for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++)
92 {
93 if (!m_cec->RegisterClient(*it))
94 {
95 AddLog(CEC_LOG_ERROR, "failed to register a CEC client");
96 return false;
97 }
98 }
99
2abe74eb
LOK
100 return true;
101}
102
103void CLibCEC::Close(void)
104{
af205cf4
LOK
105 if (!m_cec)
106 return;
107
c0152c09 108 // unregister all clients
af205cf4 109 m_cec->UnregisterClients();
c0152c09
LOK
110
111 // close the connection
af205cf4 112 m_cec->Close();
fa4798bd
LOK
113}
114
25701fa6 115int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
2abe74eb 116{
7bb4ed43 117 return CUSBCECAdapterDetection::FindAdapters(deviceList, iBufSize, strDevicePath);
2abe74eb
LOK
118}
119
2abe74eb
LOK
120bool CLibCEC::StartBootloader(void)
121{
1113cb7d 122 return m_cec ? m_cec->StartBootloader() : false;
2abe74eb
LOK
123}
124
c0152c09 125bool CLibCEC::PingAdapter(void)
2abe74eb 126{
c0152c09 127 return m_client ? m_client->PingAdapter() : false;
2abe74eb
LOK
128}
129
c0152c09 130bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)
a9232a79 131{
c0152c09 132 return m_client ? m_client->EnableCallbacks(cbParam, callbacks) : false;
a9232a79
LOK
133}
134
c0152c09 135bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration)
2abe74eb 136{
c0152c09 137 return m_client ? m_client->GetCurrentConfiguration(*configuration) : false;
2abe74eb
LOK
138}
139
c0152c09 140bool CLibCEC::SetConfiguration(const libcec_configuration *configuration)
28fa6c97 141{
c0152c09 142 return m_client ? m_client->SetConfiguration(*configuration) : false;
28fa6c97
LOK
143}
144
004b8382 145bool CLibCEC::CanPersistConfiguration(void)
1969b140 146{
c0152c09 147 return m_client ? m_client->CanPersistConfiguration() : false;
1969b140
LOK
148}
149
004b8382 150bool CLibCEC::PersistConfiguration(libcec_configuration *configuration)
8b7e5ff6 151{
c0152c09 152 return m_client ? m_client->PersistConfiguration(*configuration) : false;
8b7e5ff6
LOK
153}
154
004b8382 155void CLibCEC::RescanActiveDevices(void)
6a1c0009 156{
c0152c09
LOK
157 if (m_client)
158 m_client->RescanActiveDevices();
44c74256
LOK
159}
160
c0152c09 161bool CLibCEC::IsLibCECActiveSource(void)
eab72c40 162{
c0152c09 163 return m_client ? m_client->IsLibCECActiveSource() : false;
eab72c40
LOK
164}
165
004b8382 166bool CLibCEC::Transmit(const cec_command &data)
b4b1b49b 167{
004b8382 168 return m_client ? m_client->Transmit(data) : false;
b4b1b49b
LOK
169}
170
004b8382 171bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress)
b4b1b49b 172{
004b8382 173 return m_client ? m_client->SetLogicalAddress(iLogicalAddress) : false;
b4b1b49b
LOK
174}
175
004b8382 176bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
e55f3f70 177{
004b8382 178 return m_client ? m_client->SetPhysicalAddress(iPhysicalAddress) : false;
e55f3f70 179}
44c74256 180
004b8382 181bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort /* = CEC_DEFAULT_HDMI_PORT */)
57f45e6c 182{
004b8382 183 return m_client ? m_client->SetHDMIPort(iBaseDevice, iPort) : false;
57f45e6c
LOK
184}
185
004b8382 186bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */)
6d858ba4 187{
004b8382 188 return m_client ? m_client->SendPowerOnDevices(address) : false;
6d858ba4
LOK
189}
190
004b8382 191bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
6d858ba4 192{
004b8382 193 return m_client ? m_client->SendStandbyDevices(address) : false;
6d858ba4
LOK
194}
195
004b8382 196bool CLibCEC::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
6d858ba4 197{
004b8382 198 return m_client ? m_client->SendSetActiveSource(type) : false;
6d858ba4
LOK
199}
200
004b8382 201bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
04e637f9 202{
004b8382 203 return m_client ? m_client->SendSetDeckControlMode(mode, bSendUpdate) : false;
04e637f9
LOK
204}
205
004b8382 206bool CLibCEC::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
04e637f9 207{
004b8382 208 return m_client ? m_client->SendSetDeckInfo(info, bSendUpdate) : false;
04e637f9
LOK
209}
210
004b8382 211bool CLibCEC::SetInactiveView(void)
04e637f9 212{
004b8382 213 return m_client ? m_client->SendSetInactiveView() : false;
04e637f9
LOK
214}
215
004b8382 216bool CLibCEC::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
a33794d8 217{
004b8382 218 return m_client ? m_client->SendSetMenuState(state, bSendUpdate) : false;
a33794d8
LOK
219}
220
004b8382 221bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage)
a33794d8 222{
004b8382 223 return m_client ? m_client->SendSetOSDString(iLogicalAddress, duration, strMessage) : false;
a33794d8
LOK
224}
225
c0152c09
LOK
226bool CLibCEC::SwitchMonitoring(bool bEnable)
227{
228 return m_client ? m_client->SwitchMonitoring(bEnable) : false;
229}
230
004b8382 231cec_version CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress)
ed21be2a 232{
004b8382 233 return m_client ? m_client->GetDeviceCecVersion(iAddress) : CEC_VERSION_UNKNOWN;
ed21be2a
LOK
234}
235
004b8382 236bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
2abe74eb 237{
c0152c09 238 return m_client ? m_client->GetDeviceMenuLanguage(iAddress, *language) : false;
2abe74eb
LOK
239}
240
004b8382 241uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress)
95ba7a09 242{
004b8382 243 return m_client ? m_client->GetDeviceVendorId(iAddress) : (uint64_t)CEC_VENDOR_UNKNOWN;
02e7043e
LOK
244}
245
004b8382 246uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress)
32403cc3 247{
004b8382 248 return m_client ? m_client->GetDevicePhysicalAddress(iAddress) : CEC_INVALID_PHYSICAL_ADDRESS;
32403cc3
LOK
249}
250
004b8382 251cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress)
02e7043e 252{
004b8382 253 return m_client ? m_client->GetDevicePowerStatus(iAddress) : CEC_POWER_STATUS_UNKNOWN;
95ba7a09
LOK
254}
255
c0152c09
LOK
256bool CLibCEC::PollDevice(cec_logical_address iAddress)
257{
258 return m_client ? m_client->PollDevice(iAddress) : false;
259}
260
261cec_logical_addresses CLibCEC::GetActiveDevices(void)
262{
263 cec_logical_addresses addresses;
264 addresses.Clear();
265 if (m_client)
266 addresses = m_client->GetActiveDevices();
267 return addresses;
268}
269
270bool CLibCEC::IsActiveDevice(cec_logical_address iAddress)
271{
272 return m_client ? m_client->IsActiveDevice(iAddress) : false;
273}
274
275bool CLibCEC::IsActiveDeviceType(cec_device_type type)
276{
277 return m_client ? m_client->IsActiveDeviceType(type) : false;
278}
279
004b8382 280uint8_t CLibCEC::VolumeUp(bool bSendRelease /* = true */)
2abe74eb 281{
004b8382 282 return m_client ? m_client->SendVolumeUp(bSendRelease) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
2abe74eb
LOK
283}
284
004b8382 285uint8_t CLibCEC::VolumeDown(bool bSendRelease /* = true */)
2abe74eb 286{
004b8382 287 return m_client ? m_client->SendVolumeDown(bSendRelease) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
2abe74eb
LOK
288}
289
004b8382 290uint8_t CLibCEC::MuteAudio(bool UNUSED(bSendRelease) /* = true */)
b1c47f9d 291{
004b8382 292 return m_client ? m_client->SendMuteAudio() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
b1c47f9d
LOK
293}
294
004b8382 295bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
2abe74eb 296{
004b8382 297 return m_client ? m_client->SendKeypress(iDestination, key, bWait) : false;
2abe74eb
LOK
298}
299
004b8382 300bool CLibCEC::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = true */)
e1804a4e 301{
004b8382 302 return m_client ? m_client->SendKeyRelease(iDestination, bWait) : false;
e1804a4e
LOK
303}
304
004b8382 305cec_osd_name CLibCEC::GetDeviceOSDName(cec_logical_address iAddress)
f42d3e0f 306{
004b8382 307 cec_osd_name retVal;
20505741
LOK
308 retVal.device = CECDEVICE_UNKNOWN;
309 memset(retVal.name, 0, 14);
310
004b8382
LOK
311 if (m_client)
312 retVal = m_client->GetDeviceOSDName(iAddress);
313 return retVal;
f42d3e0f
LOK
314}
315
c0152c09
LOK
316cec_logical_address CLibCEC::GetActiveSource(void)
317{
318 return m_client ? m_client->GetActiveSource() : CECDEVICE_UNKNOWN;
319}
320
321bool CLibCEC::IsActiveSource(cec_logical_address iAddress)
322{
323 return m_client ? m_client->IsActiveSource(iAddress) : false;
324}
325bool CLibCEC::SetStreamPath(cec_logical_address iAddress)
326{
327 return m_client ? m_client->SetStreamPath(iAddress) : false;
328}
329
330bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress)
331{
332 return m_client ? m_client->SetStreamPath(iPhysicalAddress) : false;
333}
334
004b8382 335cec_logical_addresses CLibCEC::GetLogicalAddresses(void)
f42d3e0f 336{
004b8382 337 cec_logical_addresses addresses;
c30acafa 338 addresses.Clear();
c0152c09
LOK
339 if (m_client)
340 m_client->GetLogicalAddresses();
004b8382 341 return addresses;
f42d3e0f
LOK
342}
343
004b8382 344bool CLibCEC::GetNextLogMessage(cec_log_message *message)
80b72250 345{
004b8382 346 return m_client ? m_client->GetNextLogMessage(message) : false;
80b72250
LOK
347}
348
004b8382 349bool CLibCEC::GetNextKeypress(cec_keypress *key)
5477a250 350{
004b8382 351 return m_client ? m_client->GetNextKeypress(key) : false;
5477a250
LOK
352}
353
004b8382 354bool CLibCEC::GetNextCommand(cec_command *command)
5477a250 355{
004b8382 356 return m_client ? m_client->GetNextCommand(command) : false;
5477a250
LOK
357}
358
004b8382 359cec_device_type CLibCEC::GetType(cec_logical_address address)
f8513317 360{
0d800fe5 361 return CCECTypeUtils::GetType(address);
f8513317
LOK
362}
363
004b8382 364uint16_t CLibCEC::GetMaskForType(cec_logical_address address)
caca2d81 365{
0d800fe5 366 return CCECTypeUtils::GetMaskForType(address);
caca2d81
LOK
367}
368
004b8382 369uint16_t CLibCEC::GetMaskForType(cec_device_type type)
a2198e5e 370{
0d800fe5 371 return CCECTypeUtils::GetMaskForType(type);
004b8382 372}
08d80226 373
004b8382
LOK
374bool CLibCEC::IsValidPhysicalAddress(uint16_t iPhysicalAddress)
375{
376 return iPhysicalAddress >= CEC_MIN_PHYSICAL_ADDRESS &&
377 iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS;
a2198e5e
LOK
378}
379
004b8382 380const char *CLibCEC::ToString(const cec_device_type type)
25701fa6 381{
0d800fe5 382 return CCECTypeUtils::ToString(type);
25701fa6 383}
03ae897d
LOK
384
385const char *CLibCEC::ToString(const cec_menu_state state)
386{
0d800fe5 387 return CCECTypeUtils::ToString(state);
03ae897d
LOK
388}
389
390const char *CLibCEC::ToString(const cec_version version)
391{
0d800fe5 392 return CCECTypeUtils::ToString(version);
03ae897d
LOK
393}
394
395const char *CLibCEC::ToString(const cec_power_status status)
396{
0d800fe5 397 return CCECTypeUtils::ToString(status);
03ae897d
LOK
398}
399
400const char *CLibCEC::ToString(const cec_logical_address address)
401{
0d800fe5 402 return CCECTypeUtils::ToString(address);
03ae897d
LOK
403}
404
405const char *CLibCEC::ToString(const cec_deck_control_mode mode)
406{
0d800fe5 407 return CCECTypeUtils::ToString(mode);
03ae897d
LOK
408}
409
410const char *CLibCEC::ToString(const cec_deck_info status)
411{
0d800fe5 412 return CCECTypeUtils::ToString(status);
03ae897d
LOK
413}
414
415const char *CLibCEC::ToString(const cec_opcode opcode)
416{
0d800fe5 417 return CCECTypeUtils::ToString(opcode);
03ae897d
LOK
418}
419
420const char *CLibCEC::ToString(const cec_system_audio_status mode)
421{
0d800fe5 422 return CCECTypeUtils::ToString(mode);
03ae897d
LOK
423}
424
0d800fe5 425const char *CLibCEC::ToString(const cec_audio_status status)
03ae897d 426{
0d800fe5 427 return CCECTypeUtils::ToString(status);
03ae897d
LOK
428}
429
430const char *CLibCEC::ToString(const cec_vendor_id vendor)
431{
0d800fe5 432 return CCECTypeUtils::ToString(vendor);
03ae897d 433}
caca2d81
LOK
434
435const char *CLibCEC::ToString(const cec_client_version version)
436{
0d800fe5 437 return CCECTypeUtils::ToString(version);
caca2d81 438}
d40928b5 439
3efda01a
LOK
440const char *CLibCEC::ToString(const cec_server_version version)
441{
0d800fe5 442 return CCECTypeUtils::ToString(version);
3efda01a
LOK
443}
444
004b8382 445void CLibCEC::CheckKeypressTimeout(void)
a75e3a5a 446{
004b8382
LOK
447 // check all clients
448 for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++)
449 (*it)->CheckKeypressTimeout();
a75e3a5a
LOK
450}
451
004b8382 452void CLibCEC::AddLog(const cec_log_level level, const char *strFormat, ...)
d40928b5 453{
004b8382
LOK
454 CStdString strLog;
455
c0152c09 456 // format the message
004b8382
LOK
457 va_list argList;
458 va_start(argList, strFormat);
459 strLog.FormatV(strFormat, argList);
460 va_end(argList);
461
462 cec_log_message message;
463 message.level = level;
464 message.time = GetTimeMs() - m_iStartTime;
465 snprintf(message.message, sizeof(message.message), "%s", strLog.c_str());
466
467 // send the message to all clients
468 for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++)
469 (*it)->AddLog(message);
224ea877
LOK
470}
471
004b8382 472void CLibCEC::Alert(const libcec_alert type, const libcec_parameter &param)
30b4aac0 473{
004b8382
LOK
474 // send the alert to all clients
475 for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++)
476 (*it)->Alert(type, param);
30b4aac0
LOK
477}
478
004b8382 479bool CLibCEC::SetActiveView(void)
224ea877 480{
004b8382
LOK
481 AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
482 return SetActiveSource();
224ea877
LOK
483}
484
004b8382 485bool CLibCEC::EnablePhysicalAddressDetection(void)
224ea877 486{
004b8382
LOK
487 AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
488 return true;
224ea877 489}
3efda01a 490
c0152c09 491CCECClient *CLibCEC::RegisterClient(libcec_configuration &configuration)
3efda01a 492{
004b8382
LOK
493 if (!m_cec)
494 return NULL;
495
c0152c09 496 // create a new client instance
004b8382
LOK
497 CCECClient *newClient = new CCECClient(m_cec, configuration);
498 if (!newClient)
499 return NULL;
004b8382 500 m_clients.push_back(newClient);
c0152c09
LOK
501
502 // if the default client isn't set, set it
004b8382
LOK
503 if (!m_client)
504 m_client = newClient;
505
c0152c09 506 // register the new client
0b8c7eab 507 if (m_cec->CECInitialised())
004b8382
LOK
508 m_cec->RegisterClient(newClient);
509
99aeafb9 510 return newClient;
3efda01a 511}
c9549d35 512
004b8382 513void CLibCEC::UnregisterClients(void)
c9549d35 514{
c0152c09
LOK
515 if (m_cec)
516 m_cec->UnregisterClients();
517
004b8382 518 m_clients.clear();
c0152c09 519
c9d15485 520 DELETE_AND_NULL(m_client);
c9549d35 521}
9878069e 522
004b8382 523void * CECInitialise(libcec_configuration *configuration)
9878069e 524{
004b8382
LOK
525 if (!configuration)
526 return NULL;
527
c0152c09 528 // create a new libCEC instance
c30acafa 529 CLibCEC *lib = new CLibCEC(NULL);
c0152c09
LOK
530
531 // register a new client
99aeafb9 532 CCECClient *client(NULL);
c0152c09
LOK
533 if (lib && configuration)
534 client = lib->RegisterClient(*configuration);
99aeafb9 535
c0152c09 536 // update the current configuration
99aeafb9 537 if (client)
c0152c09 538 client->GetCurrentConfiguration(*configuration);
99aeafb9
LOK
539
540 // ensure that the correct server version is set
541 configuration->serverVersion = LIBCEC_VERSION_CURRENT;
004b8382
LOK
542
543 return static_cast< void* > (lib);
9878069e 544}
209b7a5c 545
004b8382 546void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint16_t iPhysicalAddress /* = 0 */)
209b7a5c 547{
004b8382 548 libcec_configuration configuration;
004b8382
LOK
549
550 // client version < 1.5.0
551 snprintf(configuration.strDeviceName, 13, "%s", strDeviceName);
552 configuration.deviceTypes = types;
553 configuration.iPhysicalAddress = iPhysicalAddress;
554
555 if (configuration.deviceTypes.IsEmpty())
556 configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
557
558 return CECInitialise(&configuration);
209b7a5c
LOK
559}
560
004b8382 561bool CECStartBootloader(void)
209b7a5c 562{
004b8382
LOK
563 bool bReturn(false);
564 cec_adapter deviceList[1];
565 if (CUSBCECAdapterDetection::FindAdapters(deviceList, 1) > 0)
209b7a5c 566 {
004b8382
LOK
567 CUSBCECAdapterCommunication comm(NULL, deviceList[0].comm);
568 CTimeout timeout(CEC_DEFAULT_CONNECT_TIMEOUT);
569 while (timeout.TimeLeft() > 0 && (bReturn = comm.Open(timeout.TimeLeft() / CEC_CONNECT_TRIES, true)) == false)
209b7a5c 570 {
004b8382
LOK
571 comm.Close();
572 CEvent::Sleep(500);
209b7a5c 573 }
004b8382
LOK
574 if (comm.IsOpen())
575 bReturn = comm.StartBootloader();
209b7a5c 576 }
004b8382
LOK
577
578 return bReturn;
579}
580
581void CECDestroy(CEC::ICECAdapter *instance)
582{
c9d15485 583 DELETE_AND_NULL(instance);
209b7a5c 584}
f80cd208 585
b32ffd87 586bool CLibCEC::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
f80cd208
LOK
587{
588 if (m_cec->IsRunning())
589 return false;
004b8382 590
f80cd208 591 return m_cec->GetDeviceInformation(strPort, config, iTimeoutMs);
a75e3a5a 592}
c30acafa 593
c0152c09 594// no longer being used
c30acafa
LOK
595void CLibCEC::AddKey(const cec_keypress &UNUSED(key)) {}
596void CLibCEC::AddCommand(const cec_command &UNUSED(command)) {}
597void CLibCEC::ConfigurationChanged(const libcec_configuration &UNUSED(config)) {}
598void CLibCEC::SetCurrentButton(cec_user_control_code UNUSED(iButtonCode)) {}
599CLibCEC *CLibCEC::GetInstance(void) { return NULL; }
600void CLibCEC::SetInstance(CLibCEC *UNUSED(instance)) {}