1 /*
2  * This file is part of the libCEC(R) library.
3  *
4  * libCEC(R) is Copyright (C) 2011-2015 Pulse-Eight Limited.  All rights reserved.
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., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301  USA
23  *
24  *
25  * Alternatively, you can license this library under a commercial license,
26  * please contact Pulse-Eight Licensing for more information.
27  *
28  * For more information contact:
29  * Pulse-Eight Licensing       <license@pulse-eight.com>
30  *     http://www.pulse-eight.com/
31  *     http://www.pulse-eight.net/
32  */
33 
34 #include "env.h"
35 #include "cec.h"
36 #include "cecc.h"
37 #include "LibCEC.h"
38 #include "CECTypeUtils.h"
39 #include <algorithm>
40 
41 using namespace CEC;
42 
43 /*!
44  * C interface implementation
45  */
46 //@{
47 
libcec_initialise(libcec_configuration * configuration)48 libcec_connection_t libcec_initialise(libcec_configuration* configuration)
49 {
50   return (ICECAdapter*) CECInitialise(configuration);
51 }
52 
libcec_destroy(libcec_connection_t connection)53 void libcec_destroy(libcec_connection_t connection)
54 {
55   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
56   if (adapter)
57   {
58     libcec_close(connection);
59     CECDestroy(adapter);
60   }
61 }
62 
libcec_open(libcec_connection_t connection,const char * strPort,uint32_t iTimeout)63 int libcec_open(libcec_connection_t connection, const char* strPort, uint32_t iTimeout)
64 {
65   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
66   return adapter && adapter->Open(strPort, iTimeout);
67 }
68 
libcec_close(libcec_connection_t connection)69 void libcec_close(libcec_connection_t connection)
70 {
71   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
72   if (adapter)
73     adapter->Close();
74 }
75 
libcec_clear_configuration(libcec_configuration * configuration)76 void libcec_clear_configuration(libcec_configuration* configuration)
77 {
78   if (configuration)
79     configuration->Clear();
80 }
81 
82 #if CEC_LIB_VERSION_MAJOR >= 5
libcec_set_callbacks(libcec_connection_t connection,ICECCallbacks * callbacks,void * cbParam)83 int libcec_set_callbacks(libcec_connection_t connection, ICECCallbacks* callbacks, void* cbParam)
84 {
85   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
86   if (adapter)
87     return adapter->SetCallbacks(callbacks, cbParam) ? 1 : 0;
88   return -1;
89 }
90 
libcec_disable_callbacks(libcec_connection_t connection)91 int libcec_disable_callbacks(libcec_connection_t connection)
92 {
93   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
94   if (adapter)
95     return adapter->DisableCallbacks() ? 1 : 0;
96   return -1;
97 }
98 #else
libcec_enable_callbacks(libcec_connection_t connection,void * cbParam,ICECCallbacks * callbacks)99 int libcec_enable_callbacks(libcec_connection_t connection, void* cbParam, ICECCallbacks* callbacks)
100 {
101   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
102   if (adapter)
103     return adapter->EnableCallbacks(cbParam, callbacks) ? 1 : 0;
104   return -1;
105 }
106 #endif
107 
libcec_find_adapters(libcec_connection_t connection,cec_adapter * deviceList,uint8_t iBufSize,const char * strDevicePath)108 int8_t libcec_find_adapters(libcec_connection_t connection, cec_adapter* deviceList, uint8_t iBufSize, const char* strDevicePath)
109 {
110   //TODO change to use DetectAdapters()
111   CLibCEC* adapter = static_cast<CLibCEC*>(connection);
112   return adapter ?
113       adapter->FindAdapters(deviceList, iBufSize, strDevicePath) :
114       -1;
115 }
116 
libcec_ping_adapters(libcec_connection_t connection)117 int libcec_ping_adapters(libcec_connection_t connection)
118 {
119   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
120   return adapter ?
121     (adapter->PingAdapter() ? 1 : 0) :
122     -1;
123 }
124 
libcec_start_bootloader(libcec_connection_t connection)125 int libcec_start_bootloader(libcec_connection_t connection)
126 {
127   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
128   return adapter ?
129       (adapter->StartBootloader() ? 1 : 0) :
130       -1;
131 }
132 
libcec_transmit(libcec_connection_t connection,const CEC::cec_command * data)133 int libcec_transmit(libcec_connection_t connection, const CEC::cec_command* data)
134 {
135   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
136   return adapter ?
137       (adapter->Transmit(*data) ? 1 : 0) :
138       -1;
139 }
140 
libcec_set_logical_address(libcec_connection_t connection,cec_logical_address iLogicalAddress)141 int libcec_set_logical_address(libcec_connection_t connection, cec_logical_address iLogicalAddress)
142 {
143   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
144   return adapter ?
145       (adapter->SetLogicalAddress(iLogicalAddress) ? 1 : 0) :
146       -1;
147 }
148 
libcec_set_physical_address(libcec_connection_t connection,uint16_t iPhysicalAddress)149 int libcec_set_physical_address(libcec_connection_t connection, uint16_t iPhysicalAddress)
150 {
151   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
152   return adapter ?
153       (adapter->SetPhysicalAddress(iPhysicalAddress) ? 1 : 0) :
154       -1;
155 }
156 
libcec_power_on_devices(libcec_connection_t connection,cec_logical_address address)157 int libcec_power_on_devices(libcec_connection_t connection, cec_logical_address address)
158 {
159   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
160   return adapter ?
161       (adapter->PowerOnDevices(address) ? 1 : 0) :
162       -1;
163 }
164 
libcec_standby_devices(libcec_connection_t connection,cec_logical_address address)165 int libcec_standby_devices(libcec_connection_t connection, cec_logical_address address)
166 {
167   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
168   return adapter ?
169       (adapter->StandbyDevices(address) ? 1 : 0) :
170       -1;
171 }
172 
libcec_set_active_source(libcec_connection_t connection,cec_device_type type)173 int libcec_set_active_source(libcec_connection_t connection, cec_device_type type)
174 {
175   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
176   return adapter ?
177       (adapter->SetActiveSource(type) ? 1 : 0) :
178       -1;
179 }
180 
libcec_set_deck_control_mode(libcec_connection_t connection,cec_deck_control_mode mode,int bSendUpdate)181 int libcec_set_deck_control_mode(libcec_connection_t connection, cec_deck_control_mode mode, int bSendUpdate) {
182   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
183   return adapter ?
184       (adapter->SetDeckControlMode(mode, bSendUpdate == 1) ? 1 : 0) :
185       -1;
186 }
187 
libcec_set_deck_info(libcec_connection_t connection,cec_deck_info info,int bSendUpdate)188 int libcec_set_deck_info(libcec_connection_t connection, cec_deck_info info, int bSendUpdate) {
189   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
190   return adapter ?
191       (adapter->SetDeckInfo(info, bSendUpdate == 1) ? 1 : 0) :
192       -1;
193 
194 }
195 
libcec_set_inactive_view(libcec_connection_t connection)196 int libcec_set_inactive_view(libcec_connection_t connection)
197 {
198   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
199   return adapter ?
200       (adapter->SetInactiveView() ? 1 : 0) :
201       -1;
202 }
203 
libcec_set_menu_state(libcec_connection_t connection,cec_menu_state state,int bSendUpdate)204 int libcec_set_menu_state(libcec_connection_t connection, cec_menu_state state, int bSendUpdate) {
205   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
206   return adapter ?
207       (adapter->SetMenuState(state, bSendUpdate == 1) ? 1 : 0) :
208       -1;
209 }
210 
libcec_set_osd_string(libcec_connection_t connection,cec_logical_address iLogicalAddress,cec_display_control duration,const char * strMessage)211 int libcec_set_osd_string(libcec_connection_t connection, cec_logical_address iLogicalAddress, cec_display_control duration, const char* strMessage)
212 {
213   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
214   return adapter ?
215       (adapter->SetOSDString(iLogicalAddress, duration, strMessage) ? 1 : 0) :
216       -1;
217 }
218 
libcec_switch_monitoring(libcec_connection_t connection,int bEnable)219 int libcec_switch_monitoring(libcec_connection_t connection, int bEnable)
220 {
221   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
222   return adapter ?
223       (adapter->SwitchMonitoring(bEnable == 1) ? 1 : 0) :
224       -1;
225 }
226 
libcec_get_device_cec_version(libcec_connection_t connection,cec_logical_address iLogicalAddress)227 cec_version libcec_get_device_cec_version(libcec_connection_t connection, cec_logical_address iLogicalAddress)
228 {
229   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
230   return adapter ?
231       adapter->GetDeviceCecVersion(iLogicalAddress) :
232       CEC_VERSION_UNKNOWN;
233 }
234 
libcec_get_device_menu_language(libcec_connection_t connection,cec_logical_address iLogicalAddress,cec_menu_language language)235 int libcec_get_device_menu_language(libcec_connection_t connection, cec_logical_address iLogicalAddress, cec_menu_language language)
236 {
237   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
238   if (!!adapter)
239   {
240     std::string menuLang(adapter->GetDeviceMenuLanguage(iLogicalAddress));
241     strncpy(language, menuLang.c_str(), 4);
242     return 0;
243   }
244   return -1;
245 }
246 
libcec_get_device_vendor_id(libcec_connection_t connection,cec_logical_address iLogicalAddress)247 uint32_t libcec_get_device_vendor_id(libcec_connection_t connection, cec_logical_address iLogicalAddress)
248 {
249   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
250   return adapter ?
251       adapter->GetDeviceVendorId(iLogicalAddress) :
252       0;
253 }
254 
libcec_get_device_physical_address(libcec_connection_t connection,cec_logical_address iLogicalAddress)255 uint16_t libcec_get_device_physical_address(libcec_connection_t connection, cec_logical_address iLogicalAddress)
256 {
257   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
258   return adapter ?
259       adapter->GetDevicePhysicalAddress(iLogicalAddress) :
260       0;
261 }
262 
libcec_get_active_source(libcec_connection_t connection)263 cec_logical_address libcec_get_active_source(libcec_connection_t connection)
264 {
265   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
266   return adapter ?
267       adapter->GetActiveSource() :
268       CECDEVICE_UNKNOWN;
269 }
270 
libcec_is_active_source(libcec_connection_t connection,cec_logical_address iAddress)271 int libcec_is_active_source(libcec_connection_t connection, cec_logical_address iAddress)
272 {
273   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
274   return adapter ?
275       adapter->IsActiveSource(iAddress) :
276       0;
277 }
278 
libcec_get_device_power_status(libcec_connection_t connection,cec_logical_address iLogicalAddress)279 cec_power_status libcec_get_device_power_status(libcec_connection_t connection, cec_logical_address iLogicalAddress)
280 {
281   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
282   return adapter ?
283       adapter->GetDevicePowerStatus(iLogicalAddress) :
284       CEC_POWER_STATUS_UNKNOWN;
285 }
286 
libcec_poll_device(libcec_connection_t connection,cec_logical_address iLogicalAddress)287 int libcec_poll_device(libcec_connection_t connection, cec_logical_address iLogicalAddress)
288 {
289   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
290   return adapter ?
291       (adapter->PollDevice(iLogicalAddress) ? 1 : 0) :
292       -1;
293 }
294 
libcec_get_active_devices(libcec_connection_t connection)295 cec_logical_addresses libcec_get_active_devices(libcec_connection_t connection)
296 {
297   cec_logical_addresses addresses;
298   addresses.Clear();
299   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
300   if (adapter)
301     addresses = adapter->GetActiveDevices();
302   return addresses;
303 }
304 
libcec_is_active_device(libcec_connection_t connection,cec_logical_address iAddress)305 int libcec_is_active_device(libcec_connection_t connection, cec_logical_address iAddress)
306 {
307   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
308   return adapter ?
309       (adapter->IsActiveDevice(iAddress) ? 1 : 0) :
310       -1;
311 }
312 
libcec_is_active_device_type(libcec_connection_t connection,cec_device_type type)313 int libcec_is_active_device_type(libcec_connection_t connection, cec_device_type type)
314 {
315   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
316   return adapter ?
317       (adapter->IsActiveDeviceType(type) ? 1 : 0) :
318       -1;
319 }
320 
libcec_set_hdmi_port(libcec_connection_t connection,cec_logical_address iBaseDevice,uint8_t iPort)321 int libcec_set_hdmi_port(libcec_connection_t connection, cec_logical_address iBaseDevice, uint8_t iPort)
322 {
323   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
324   return adapter ?
325       (adapter->SetHDMIPort(iBaseDevice, iPort) ? 1 : 0) :
326       -1;
327 }
328 
libcec_volume_up(libcec_connection_t connection,int bSendRelease)329 int libcec_volume_up(libcec_connection_t connection, int bSendRelease)
330 {
331   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
332   return adapter ?
333       adapter->VolumeUp(bSendRelease == 1) :
334       -1;
335 }
336 
libcec_volume_down(libcec_connection_t connection,int bSendRelease)337 int libcec_volume_down(libcec_connection_t connection, int bSendRelease)
338 {
339   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
340   return adapter ?
341       adapter->VolumeDown(bSendRelease == 1) :
342       -1;
343 }
344 
345 #if CEC_LIB_VERSION_MAJOR >= 5
libcec_mute_audio(libcec_connection_t connection,int UNUSED (bSendRelease))346 int libcec_mute_audio(libcec_connection_t connection, int UNUSED(bSendRelease))
347 {
348   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
349   return adapter ?
350       adapter->AudioToggleMute() :
351       -1;
352 }
353 #endif
354 
libcec_send_keypress(libcec_connection_t connection,cec_logical_address iDestination,cec_user_control_code key,int bWait)355 int libcec_send_keypress(libcec_connection_t connection, cec_logical_address iDestination, cec_user_control_code key, int bWait)
356 {
357   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
358   return adapter ?
359       (adapter->SendKeypress(iDestination, key, bWait == 1) ? 1 : 0) :
360       -1;
361 }
362 
libcec_send_key_release(libcec_connection_t connection,cec_logical_address iDestination,int bWait)363 int libcec_send_key_release(libcec_connection_t connection, cec_logical_address iDestination, int bWait)
364 {
365   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
366   return adapter ?
367       (adapter->SendKeyRelease(iDestination, bWait == 1) ? 1 : 0) :
368       -1;
369 }
370 
libcec_get_device_osd_name(libcec_connection_t connection,cec_logical_address iAddress,cec_osd_name name)371 int libcec_get_device_osd_name(libcec_connection_t connection, cec_logical_address iAddress, cec_osd_name name)
372 {
373   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
374   if (!!adapter)
375   {
376     std::string osdName(adapter->GetDeviceOSDName(iAddress));
377     size_t osd_size(osdName.size());
378     memcpy(name, osdName.c_str(), std::min(sizeof(cec_osd_name), osd_size));
379     if (osd_size < sizeof(cec_osd_name))
380       name[osd_size] = (char)0;
381     return 0;
382   }
383   return -1;
384 }
385 
libcec_set_stream_path_logical(libcec_connection_t connection,cec_logical_address iAddress)386 int libcec_set_stream_path_logical(libcec_connection_t connection, cec_logical_address iAddress)
387 {
388   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
389   return adapter ?
390       (adapter->SetStreamPath(iAddress) ? 1 : 0) :
391       -1;
392 }
393 
libcec_set_stream_path_physical(libcec_connection_t connection,uint16_t iPhysicalAddress)394 int libcec_set_stream_path_physical(libcec_connection_t connection, uint16_t iPhysicalAddress)
395 {
396   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
397   return adapter ?
398       (adapter->SetStreamPath(iPhysicalAddress) ? 1 : 0) :
399       -1;
400 }
401 
libcec_get_logical_addresses(libcec_connection_t connection)402 cec_logical_addresses libcec_get_logical_addresses(libcec_connection_t connection)
403 {
404   cec_logical_addresses addr;
405   addr.Clear();
406   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
407   if (adapter)
408     addr = adapter->GetLogicalAddresses();
409   return addr;
410 }
411 
libcec_get_current_configuration(libcec_connection_t connection,libcec_configuration * configuration)412 int libcec_get_current_configuration(libcec_connection_t connection, libcec_configuration* configuration)
413 {
414   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
415   return adapter ?
416       (adapter->GetCurrentConfiguration(configuration) ? 1 : 0) :
417       -1;
418 }
419 
420 #if CEC_LIB_VERSION_MAJOR >= 5
libcec_can_save_configuration(libcec_connection_t connection)421 int libcec_can_save_configuration(libcec_connection_t connection)
422 {
423   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
424   return adapter ?
425     (adapter->CanSaveConfiguration() ? 1 : 0) :
426     -1;
427 }
428 #else
libcec_can_persist_configuration(libcec_connection_t connection)429 int libcec_can_persist_configuration(libcec_connection_t connection)
430 {
431   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
432   return adapter ?
433       (adapter->CanPersistConfiguration() ? 1 : 0) :
434       -1;
435 }
436 #endif
437 
438 #if CEC_LIB_VERSION_MAJOR < 5
libcec_persist_configuration(libcec_connection_t connection,libcec_configuration * configuration)439 int libcec_persist_configuration(libcec_connection_t connection, libcec_configuration* configuration)
440 {
441   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
442   return adapter ?
443       (adapter->PersistConfiguration(configuration) ? 1 : 0) :
444       -1;
445 }
446 #endif
447 
libcec_set_configuration(libcec_connection_t connection,libcec_configuration * configuration)448 int libcec_set_configuration(libcec_connection_t connection, libcec_configuration* configuration)
449 {
450   return libcec_set_configuration(connection, static_cast<const libcec_configuration*>(configuration));
451 }
452 
libcec_set_configuration(libcec_connection_t connection,const libcec_configuration * configuration)453 int libcec_set_configuration(libcec_connection_t connection, const libcec_configuration* configuration)
454 {
455   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
456   return adapter ?
457       (adapter->SetConfiguration(configuration) ? 1 : 0) :
458       -1;
459 }
460 
libcec_rescan_devices(libcec_connection_t connection)461 void libcec_rescan_devices(libcec_connection_t connection)
462 {
463   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
464   if (adapter)
465     adapter->RescanActiveDevices();
466 }
467 
libcec_is_libcec_active_source(libcec_connection_t connection)468 int libcec_is_libcec_active_source(libcec_connection_t connection)
469 {
470   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
471   return adapter ?
472       (adapter->IsLibCECActiveSource() ? 1 : 0) :
473       -1;
474 }
475 
libcec_get_device_information(libcec_connection_t connection,const char * strPort,CEC::libcec_configuration * config,uint32_t iTimeoutMs)476 int libcec_get_device_information(libcec_connection_t connection, const char* strPort, CEC::libcec_configuration* config, uint32_t iTimeoutMs)
477 {
478   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
479   return adapter ?
480       (adapter->GetDeviceInformation(strPort, config, iTimeoutMs) ? 1 : 0) :
481       -1;
482 }
483 
libcec_get_lib_info(libcec_connection_t connection)484 const char* libcec_get_lib_info(libcec_connection_t connection)
485 {
486   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
487   return adapter ?
488       adapter->GetLibInfo() :
489       NULL;
490 }
491 
libcec_init_video_standalone(libcec_connection_t connection)492 void libcec_init_video_standalone(libcec_connection_t connection)
493 {
494   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
495   if (adapter)
496       adapter->InitVideoStandalone();
497 }
498 
libcec_get_adapter_vendor_id(libcec_connection_t connection)499 uint16_t libcec_get_adapter_vendor_id(libcec_connection_t connection)
500 {
501   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
502   return adapter ?
503       adapter->GetAdapterVendorId() :
504       0;
505 }
506 
libcec_get_adapter_product_id(libcec_connection_t connection)507 uint16_t libcec_get_adapter_product_id(libcec_connection_t connection)
508 {
509   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
510   return adapter ?
511       adapter->GetAdapterProductId() :
512       0;
513 }
514 
libcec_audio_toggle_mute(libcec_connection_t connection)515 uint8_t libcec_audio_toggle_mute(libcec_connection_t connection)
516 {
517   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
518   return adapter ?
519       adapter->AudioToggleMute() :
520       (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
521 }
522 
libcec_audio_mute(libcec_connection_t connection)523 uint8_t libcec_audio_mute(libcec_connection_t connection)
524 {
525   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
526   return adapter ?
527       adapter->AudioMute() :
528       (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
529 }
530 
libcec_audio_unmute(libcec_connection_t connection)531 uint8_t libcec_audio_unmute(libcec_connection_t connection)
532 {
533   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
534   return adapter ?
535       adapter->AudioUnmute() :
536       (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
537 }
538 
libcec_audio_get_status(libcec_connection_t connection)539 uint8_t libcec_audio_get_status(libcec_connection_t connection)
540 {
541   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
542   return adapter ?
543       adapter->AudioStatus() :
544       (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
545 }
546 
libcec_detect_adapters(libcec_connection_t connection,cec_adapter_descriptor * deviceList,uint8_t iBufSize,const char * strDevicePath,int bQuickScan)547 int8_t libcec_detect_adapters(libcec_connection_t connection, cec_adapter_descriptor* deviceList, uint8_t iBufSize, const char* strDevicePath, int bQuickScan)
548 {
549   ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
550   return adapter ?
551       adapter->DetectAdapters(deviceList, iBufSize, strDevicePath, bQuickScan == 1) :
552       -1;
553 }
554 
libcec_menu_state_to_string(const CEC_NAMESPACE cec_menu_state state,char * buf,size_t bufsize)555 void libcec_menu_state_to_string(const CEC_NAMESPACE cec_menu_state state, char* buf, size_t bufsize)
556 {
557   std::string strBuf(CCECTypeUtils::ToString(state));
558   strncpy(buf, strBuf.c_str(), bufsize);
559 }
560 
libcec_cec_version_to_string(const CEC_NAMESPACE cec_version version,char * buf,size_t bufsize)561 void libcec_cec_version_to_string(const CEC_NAMESPACE cec_version version, char* buf, size_t bufsize)
562 {
563   std::string strBuf(CCECTypeUtils::ToString(version));
564   strncpy(buf, strBuf.c_str(), bufsize);
565 }
566 
libcec_power_status_to_string(const CEC_NAMESPACE cec_power_status status,char * buf,size_t bufsize)567 void libcec_power_status_to_string(const CEC_NAMESPACE cec_power_status status, char* buf, size_t bufsize)
568 {
569   std::string strBuf(CCECTypeUtils::ToString(status));
570   strncpy(buf, strBuf.c_str(), bufsize);
571 }
572 
libcec_logical_address_to_string(const CEC_NAMESPACE cec_logical_address address,char * buf,size_t bufsize)573 void libcec_logical_address_to_string(const CEC_NAMESPACE cec_logical_address address, char* buf, size_t bufsize)
574 {
575   std::string strBuf(CCECTypeUtils::ToString(address));
576   strncpy(buf, strBuf.c_str(), bufsize);
577 }
578 
libcec_deck_control_mode_to_string(const CEC_NAMESPACE cec_deck_control_mode mode,char * buf,size_t bufsize)579 void libcec_deck_control_mode_to_string(const CEC_NAMESPACE cec_deck_control_mode mode, char* buf, size_t bufsize)
580 {
581   std::string strBuf(CCECTypeUtils::ToString(mode));
582   strncpy(buf, strBuf.c_str(), bufsize);
583 }
584 
libcec_deck_status_to_string(const CEC_NAMESPACE cec_deck_info status,char * buf,size_t bufsize)585 void libcec_deck_status_to_string(const CEC_NAMESPACE cec_deck_info status, char* buf, size_t bufsize)
586 {
587   std::string strBuf(CCECTypeUtils::ToString(status));
588   strncpy(buf, strBuf.c_str(), bufsize);
589 }
590 
libcec_opcode_to_string(const CEC_NAMESPACE cec_opcode opcode,char * buf,size_t bufsize)591 void libcec_opcode_to_string(const CEC_NAMESPACE cec_opcode opcode, char* buf, size_t bufsize)
592 {
593   std::string strBuf(CCECTypeUtils::ToString(opcode));
594   strncpy(buf, strBuf.c_str(), bufsize);
595 }
596 
libcec_system_audio_status_to_string(const CEC_NAMESPACE cec_system_audio_status mode,char * buf,size_t bufsize)597 void libcec_system_audio_status_to_string(const CEC_NAMESPACE cec_system_audio_status mode, char* buf, size_t bufsize)
598 {
599   std::string strBuf(CCECTypeUtils::ToString(mode));
600   strncpy(buf, strBuf.c_str(), bufsize);
601 }
602 
libcec_audio_status_to_string(const CEC_NAMESPACE cec_audio_status status,char * buf,size_t bufsize)603 void libcec_audio_status_to_string(const CEC_NAMESPACE cec_audio_status status, char* buf, size_t bufsize)
604 {
605   std::string strBuf(CCECTypeUtils::ToString(status));
606   strncpy(buf, strBuf.c_str(), bufsize);
607 }
608 
libcec_vendor_id_to_string(const CEC_NAMESPACE cec_vendor_id vendor,char * buf,size_t bufsize)609 void libcec_vendor_id_to_string(const CEC_NAMESPACE cec_vendor_id vendor, char* buf, size_t bufsize)
610 {
611   std::string strBuf(CCECTypeUtils::ToString(vendor));
612   strncpy(buf, strBuf.c_str(), bufsize);
613 }
614 
libcec_user_control_key_to_string(const CEC_NAMESPACE cec_user_control_code key,char * buf,size_t bufsize)615 void libcec_user_control_key_to_string(const CEC_NAMESPACE cec_user_control_code key, char* buf, size_t bufsize)
616 {
617   std::string strBuf(CCECTypeUtils::ToString(key));
618   strncpy(buf, strBuf.c_str(), bufsize);
619 }
620 
libcec_adapter_type_to_string(const CEC_NAMESPACE cec_adapter_type type,char * buf,size_t bufsize)621 void libcec_adapter_type_to_string(const CEC_NAMESPACE cec_adapter_type type, char* buf, size_t bufsize)
622 {
623   std::string strBuf(CCECTypeUtils::ToString(type));
624   strncpy(buf, strBuf.c_str(), bufsize);
625 }
626 
libcec_version_to_string(uint32_t version,char * buf,size_t bufsize)627 void libcec_version_to_string(uint32_t version, char* buf, size_t bufsize)
628 {
629   std::string strBuf(CCECTypeUtils::VersionToString(version));
630   strncpy(buf, strBuf.c_str(), bufsize);
631 }
632 
633 //@}
634