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