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