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