Rename cec_audio_status() to cec_audio_get_status() to avoid conflict with the cec_au...
[deb_libcec.git] / src / lib / LibCECC.cpp
CommitLineData
abbca718
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.
abbca718
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
LOK
33#include "env.h"
34#include "cec.h"
35#include "cecc.h"
abbca718
LOK
36
37using namespace CEC;
38using namespace std;
39
40/*!
41 * C interface implementation
42 */
43//@{
2abe74eb 44ICECAdapter *cec_parser;
abbca718 45
3efda01a 46int cec_initialise(libcec_configuration *configuration)
f8513317 47{
caca2d81
LOK
48 cec_parser = (ICECAdapter *) CECInitialise(configuration);
49 return (cec_parser != NULL) ? 1 : 0;
50}
51
5f39c4d8
LOK
52void cec_destroy(void)
53{
54 cec_close();
25701fa6 55 CECDestroy(cec_parser);
5f39c4d8
LOK
56 cec_parser = NULL;
57}
58
02ee2c68 59int cec_open(const char *strPort, uint32_t iTimeout)
abbca718
LOK
60{
61 if (cec_parser)
62 return cec_parser->Open(strPort, iTimeout);
63 return false;
64}
65
5f39c4d8 66void cec_close(void)
f99bc831 67{
f99bc831 68 if (cec_parser)
5f39c4d8 69 cec_parser->Close();
f99bc831
LOK
70}
71
547b390d 72int cec_enable_callbacks(void *cbParam, ICECCallbacks *callbacks)
fa4798bd
LOK
73{
74 if (cec_parser)
547b390d 75 return cec_parser->EnableCallbacks(cbParam, callbacks) ? 1 : 0;
fa4798bd
LOK
76 return -1;
77}
78
25701fa6 79int8_t cec_find_adapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
abbca718
LOK
80{
81 if (cec_parser)
25701fa6 82 return cec_parser->FindAdapters(deviceList, iBufSize, strDevicePath);
2abe74eb 83 return -1;
abbca718
LOK
84}
85
02ee2c68 86int cec_ping_adapters(void)
abbca718
LOK
87{
88 if (cec_parser)
02ee2c68
LOK
89 return cec_parser->PingAdapter() ? 1 : 0;
90 return -1;
abbca718
LOK
91}
92
02ee2c68 93int cec_start_bootloader(void)
abbca718
LOK
94{
95 if (cec_parser)
02ee2c68
LOK
96 return cec_parser->StartBootloader() ? 1 : 0;
97 return -1;
abbca718
LOK
98}
99
f958766e 100int cec_transmit(const CEC::cec_command *data)
abbca718
LOK
101{
102 if (cec_parser)
f958766e 103 return cec_parser->Transmit(*data) ? 1 : 0;
02ee2c68 104 return -1;
abbca718
LOK
105}
106
2492216a 107int cec_set_logical_address(cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */)
abbca718
LOK
108{
109 if (cec_parser)
02ee2c68
LOK
110 return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0;
111 return -1;
6dfe9213
LOK
112}
113
2492216a
LOK
114int cec_set_physical_address(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
115{
116 if (cec_parser)
117 return cec_parser->SetPhysicalAddress(iPhysicalAddress) ? 1 : 0;
118 return -1;
119}
120
02ee2c68 121int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */)
6dfe9213
LOK
122{
123 if (cec_parser)
02ee2c68
LOK
124 return cec_parser->PowerOnDevices(address) ? 1 : 0;
125 return -1;
abbca718
LOK
126}
127
02ee2c68 128int cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
abbca718
LOK
129{
130 if (cec_parser)
02ee2c68
LOK
131 return cec_parser->StandbyDevices(address) ? 1 : 0;
132 return -1;
abbca718
LOK
133}
134
18203d17
LOK
135int cec_set_active_source(cec_device_type type)
136{
137 if (cec_parser)
138 return cec_parser->SetActiveSource(type) ? 1 : 0;
139 return -1;
140}
141
f2cdbc36
PG
142int cec_set_deck_control_mode(cec_deck_control_mode mode, int bSendUpdate) {
143 if (cec_parser)
144 return cec_parser->SetDeckControlMode(mode, bSendUpdate == 1) ? 1 : 0;
145 return -1;
146}
147
148int cec_set_deck_info(cec_deck_info info, int bSendUpdate) {
149 if (cec_parser)
150 return cec_parser->SetDeckInfo(info, bSendUpdate == 1) ? 1 : 0;
151 return -1;
152
153}
154
02ee2c68 155int cec_set_inactive_view(void)
abbca718
LOK
156{
157 if (cec_parser)
02ee2c68
LOK
158 return cec_parser->SetInactiveView() ? 1 : 0;
159 return -1;
abbca718
LOK
160}
161
f2cdbc36
PG
162int cec_set_menu_state(cec_menu_state state, int bSendUpdate) {
163 if (cec_parser)
164 return cec_parser->SetMenuState(state, bSendUpdate == 1) ? 1 : 0;
165 return -1;
166}
167
1969b140
LOK
168int cec_set_osd_string(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage)
169{
170 if (cec_parser)
171 return cec_parser->SetOSDString(iLogicalAddress, duration, strMessage) ? 1 : 0;
172 return -1;
173}
174
8b7e5ff6
LOK
175int cec_switch_monitoring(int bEnable)
176{
177 if (cec_parser)
178 return cec_parser->SwitchMonitoring(bEnable == 1) ? 1 : 0;
179 return -1;
180}
181
6a1c0009
LOK
182cec_version cec_get_device_cec_version(cec_logical_address iLogicalAddress)
183{
184 if (cec_parser)
185 return cec_parser->GetDeviceCecVersion(iLogicalAddress);
186 return CEC_VERSION_UNKNOWN;
187}
188
a3269a0a
LOK
189int cec_get_device_menu_language(cec_logical_address iLogicalAddress, cec_menu_language *language)
190{
191 if (cec_parser)
192 return cec_parser->GetDeviceMenuLanguage(iLogicalAddress, language) ? 1 : 0;
193 return -1;
194}
195
44c74256
LOK
196uint64_t cec_get_device_vendor_id(cec_logical_address iLogicalAddress)
197{
198 if (cec_parser)
199 return cec_parser->GetDeviceVendorId(iLogicalAddress);
200 return 0;
201}
202
eab72c40
LOK
203uint16_t cec_get_device_physical_address(cec_logical_address iLogicalAddress)
204{
205 if (cec_parser)
206 return cec_parser->GetDevicePhysicalAddress(iLogicalAddress);
207 return 0;
208}
209
b4b1b49b
LOK
210cec_logical_address cec_get_active_source(void)
211{
212 if (cec_parser)
213 return cec_parser->GetActiveSource();
214 return CECDEVICE_UNKNOWN;
215}
216
217int cec_is_active_source(cec_logical_address iAddress)
218{
219 if (cec_parser)
220 return cec_parser->IsActiveSource(iAddress);
221 return false;
222}
223
e55f3f70
LOK
224cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress)
225{
226 if (cec_parser)
227 return cec_parser->GetDevicePowerStatus(iLogicalAddress);
228 return CEC_POWER_STATUS_UNKNOWN;
229}
230
57f45e6c
LOK
231int cec_poll_device(cec_logical_address iLogicalAddress)
232{
233 if (cec_parser)
6d858ba4
LOK
234 return cec_parser->PollDevice(iLogicalAddress) ? 1 : 0;
235 return -1;
236}
237
238cec_logical_addresses cec_get_active_devices(void)
239{
240 cec_logical_addresses addresses;
988de7b9 241 addresses.Clear();
6d858ba4
LOK
242 if (cec_parser)
243 addresses = cec_parser->GetActiveDevices();
244 return addresses;
245}
246
247int cec_is_active_device(cec_logical_address iAddress)
248{
249 if (cec_parser)
250 return cec_parser->IsActiveDevice(iAddress) ? 1 : 0;
251 return -1;
252}
253
254int cec_is_active_device_type(cec_device_type type)
255{
256 if (cec_parser)
257 return cec_parser->IsActiveDeviceType(type) ? 1 : 0;
57f45e6c
LOK
258 return -1;
259}
260
d2f1c157 261int cec_set_hdmi_port(cec_logical_address iBaseDevice, uint8_t iPort)
16b1e052
LOK
262{
263 if (cec_parser)
d2f1c157 264 return cec_parser->SetHDMIPort(iBaseDevice, iPort) ? 1 : 0;
16b1e052
LOK
265 return -1;
266}
267
5c73f7f7 268int cec_volume_up(int bSendRelease)
04e637f9
LOK
269{
270 if (cec_parser)
5c73f7f7 271 return cec_parser->VolumeUp(bSendRelease == 1);
04e637f9
LOK
272 return -1;
273}
274
5c73f7f7 275int cec_volume_down(int bSendRelease)
04e637f9
LOK
276{
277 if (cec_parser)
5c73f7f7 278 return cec_parser->VolumeDown(bSendRelease == 1);
04e637f9
LOK
279 return -1;
280}
281
5c73f7f7 282int cec_mute_audio(int bSendRelease)
04e637f9
LOK
283{
284 if (cec_parser)
5c73f7f7 285 return cec_parser->MuteAudio(bSendRelease == 1);
04e637f9
LOK
286 return -1;
287}
288
a33794d8
LOK
289int cec_send_keypress(cec_logical_address iDestination, cec_user_control_code key, int bWait)
290{
291 if (cec_parser)
292 return cec_parser->SendKeypress(iDestination, key, bWait == 1) ? 1 : 0;
293 return -1;
294}
295
296int cec_send_key_release(cec_logical_address iDestination, int bWait)
297{
298 if (cec_parser)
299 return cec_parser->SendKeyRelease(iDestination, bWait == 1) ? 1 : 0;
300 return -1;
301}
302
f71a1df9 303cec_osd_name cec_get_device_osd_name(cec_logical_address iAddress)
ed21be2a
LOK
304{
305 cec_osd_name retVal;
306 retVal.device = iAddress;
307 retVal.name[0] = 0;
308
309 if (cec_parser)
f71a1df9 310 retVal = cec_parser->GetDeviceOSDName(iAddress);
ed21be2a
LOK
311
312 return retVal;
313}
314
f42d3e0f
LOK
315int cec_set_stream_path_logical(CEC::cec_logical_address iAddress)
316{
317 return cec_parser ? (cec_parser->SetStreamPath(iAddress) ? 1 : 0) : -1;
318}
319
320int cec_set_stream_path_physical(uint16_t iPhysicalAddress)
321{
322 return cec_parser ? (cec_parser->SetStreamPath(iPhysicalAddress) ? 1 : 0) : -1;
323}
324
80b72250
LOK
325cec_logical_addresses cec_get_logical_addresses(void)
326{
327 cec_logical_addresses addr;
328 addr.Clear();
329 if (cec_parser)
330 addr = cec_parser->GetLogicalAddresses();
331 return addr;
332}
333
d40928b5
LOK
334int cec_get_current_configuration(libcec_configuration *configuration)
335{
336 return cec_parser ? (cec_parser->GetCurrentConfiguration(configuration) ? 1 : 0) : -1;
337}
338
224ea877
LOK
339int cec_can_persist_configuration(void)
340{
341 return cec_parser ? (cec_parser->CanPersistConfiguration() ? 1 : 0) : -1;
342}
343
30b4aac0 344int cec_persist_configuration(libcec_configuration *configuration)
224ea877
LOK
345{
346 return cec_parser ? (cec_parser->PersistConfiguration(configuration) ? 1 : 0) : -1;
347}
348
30b4aac0
LOK
349int cec_set_configuration(libcec_configuration *configuration)
350{
351 return cec_parser ? (cec_parser->SetConfiguration(configuration) ? 1 : 0) : -1;
352}
353
3efda01a
LOK
354void cec_rescan_devices(void)
355{
356 if (cec_parser)
357 cec_parser->RescanActiveDevices();
358}
359
c9549d35
LOK
360int cec_is_libcec_active_source(void)
361{
362 return cec_parser ? (cec_parser->IsLibCECActiveSource() ? 1 : 0) : -1;
363}
364
bd624ba8
LOK
365int cec_get_device_information(const char *strPort, CEC::libcec_configuration *config, uint32_t iTimeoutMs)
366{
367 return cec_parser ? (cec_parser->GetDeviceInformation(strPort, config, iTimeoutMs) ? 1 : 0) : -1;
368}
369
2b44051c
LOK
370const char * cec_get_lib_info(void)
371{
372 return cec_parser ? cec_parser->GetLibInfo() : NULL;
373}
374
375void cec_init_video_standalone(void)
376{
377 if (cec_parser)
378 cec_parser->InitVideoStandalone();
379}
380
8768aeca
LOK
381uint16_t cec_get_adapter_vendor_id(void)
382{
47b76f72 383 return cec_parser ? cec_parser->GetAdapterVendorId() : 0;
8768aeca
LOK
384}
385
386uint16_t cec_get_adapter_product_id(void)
387{
47b76f72 388 return cec_parser ? cec_parser->GetAdapterProductId() : 0;
8768aeca
LOK
389}
390
6d2bc8de
LOK
391uint8_t cec_audio_toggle_mute(void)
392{
393 return cec_parser ? cec_parser->AudioToggleMute() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
394}
395
396uint8_t cec_audio_mute(void)
397{
398 return cec_parser ? cec_parser->AudioMute() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
399}
400
401uint8_t cec_audio_unmute(void)
402{
403 return cec_parser ? cec_parser->AudioUnmute() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
404}
405
aa76c116 406uint8_t cec_audio_get_status(void)
6d2bc8de
LOK
407{
408 return cec_parser ? cec_parser->AudioStatus() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
409}
410
abbca718 411//@}