Rename cec_audio_status() to cec_audio_get_status() to avoid conflict with the cec_au...
[deb_libcec.git] / src / lib / LibCECC.cpp
1 /*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011-2012 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., 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 "env.h"
34 #include "cec.h"
35 #include "cecc.h"
36
37 using namespace CEC;
38 using namespace std;
39
40 /*!
41 * C interface implementation
42 */
43 //@{
44 ICECAdapter *cec_parser;
45
46 int cec_initialise(libcec_configuration *configuration)
47 {
48 cec_parser = (ICECAdapter *) CECInitialise(configuration);
49 return (cec_parser != NULL) ? 1 : 0;
50 }
51
52 void cec_destroy(void)
53 {
54 cec_close();
55 CECDestroy(cec_parser);
56 cec_parser = NULL;
57 }
58
59 int cec_open(const char *strPort, uint32_t iTimeout)
60 {
61 if (cec_parser)
62 return cec_parser->Open(strPort, iTimeout);
63 return false;
64 }
65
66 void cec_close(void)
67 {
68 if (cec_parser)
69 cec_parser->Close();
70 }
71
72 int cec_enable_callbacks(void *cbParam, ICECCallbacks *callbacks)
73 {
74 if (cec_parser)
75 return cec_parser->EnableCallbacks(cbParam, callbacks) ? 1 : 0;
76 return -1;
77 }
78
79 int8_t cec_find_adapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
80 {
81 if (cec_parser)
82 return cec_parser->FindAdapters(deviceList, iBufSize, strDevicePath);
83 return -1;
84 }
85
86 int cec_ping_adapters(void)
87 {
88 if (cec_parser)
89 return cec_parser->PingAdapter() ? 1 : 0;
90 return -1;
91 }
92
93 int cec_start_bootloader(void)
94 {
95 if (cec_parser)
96 return cec_parser->StartBootloader() ? 1 : 0;
97 return -1;
98 }
99
100 int cec_transmit(const CEC::cec_command *data)
101 {
102 if (cec_parser)
103 return cec_parser->Transmit(*data) ? 1 : 0;
104 return -1;
105 }
106
107 int cec_set_logical_address(cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */)
108 {
109 if (cec_parser)
110 return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0;
111 return -1;
112 }
113
114 int 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
121 int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */)
122 {
123 if (cec_parser)
124 return cec_parser->PowerOnDevices(address) ? 1 : 0;
125 return -1;
126 }
127
128 int cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
129 {
130 if (cec_parser)
131 return cec_parser->StandbyDevices(address) ? 1 : 0;
132 return -1;
133 }
134
135 int 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
142 int 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
148 int 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
155 int cec_set_inactive_view(void)
156 {
157 if (cec_parser)
158 return cec_parser->SetInactiveView() ? 1 : 0;
159 return -1;
160 }
161
162 int 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
168 int 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
175 int cec_switch_monitoring(int bEnable)
176 {
177 if (cec_parser)
178 return cec_parser->SwitchMonitoring(bEnable == 1) ? 1 : 0;
179 return -1;
180 }
181
182 cec_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
189 int 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
196 uint64_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
203 uint16_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
210 cec_logical_address cec_get_active_source(void)
211 {
212 if (cec_parser)
213 return cec_parser->GetActiveSource();
214 return CECDEVICE_UNKNOWN;
215 }
216
217 int cec_is_active_source(cec_logical_address iAddress)
218 {
219 if (cec_parser)
220 return cec_parser->IsActiveSource(iAddress);
221 return false;
222 }
223
224 cec_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
231 int cec_poll_device(cec_logical_address iLogicalAddress)
232 {
233 if (cec_parser)
234 return cec_parser->PollDevice(iLogicalAddress) ? 1 : 0;
235 return -1;
236 }
237
238 cec_logical_addresses cec_get_active_devices(void)
239 {
240 cec_logical_addresses addresses;
241 addresses.Clear();
242 if (cec_parser)
243 addresses = cec_parser->GetActiveDevices();
244 return addresses;
245 }
246
247 int 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
254 int cec_is_active_device_type(cec_device_type type)
255 {
256 if (cec_parser)
257 return cec_parser->IsActiveDeviceType(type) ? 1 : 0;
258 return -1;
259 }
260
261 int cec_set_hdmi_port(cec_logical_address iBaseDevice, uint8_t iPort)
262 {
263 if (cec_parser)
264 return cec_parser->SetHDMIPort(iBaseDevice, iPort) ? 1 : 0;
265 return -1;
266 }
267
268 int cec_volume_up(int bSendRelease)
269 {
270 if (cec_parser)
271 return cec_parser->VolumeUp(bSendRelease == 1);
272 return -1;
273 }
274
275 int cec_volume_down(int bSendRelease)
276 {
277 if (cec_parser)
278 return cec_parser->VolumeDown(bSendRelease == 1);
279 return -1;
280 }
281
282 int cec_mute_audio(int bSendRelease)
283 {
284 if (cec_parser)
285 return cec_parser->MuteAudio(bSendRelease == 1);
286 return -1;
287 }
288
289 int 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
296 int 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
303 cec_osd_name cec_get_device_osd_name(cec_logical_address iAddress)
304 {
305 cec_osd_name retVal;
306 retVal.device = iAddress;
307 retVal.name[0] = 0;
308
309 if (cec_parser)
310 retVal = cec_parser->GetDeviceOSDName(iAddress);
311
312 return retVal;
313 }
314
315 int cec_set_stream_path_logical(CEC::cec_logical_address iAddress)
316 {
317 return cec_parser ? (cec_parser->SetStreamPath(iAddress) ? 1 : 0) : -1;
318 }
319
320 int cec_set_stream_path_physical(uint16_t iPhysicalAddress)
321 {
322 return cec_parser ? (cec_parser->SetStreamPath(iPhysicalAddress) ? 1 : 0) : -1;
323 }
324
325 cec_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
334 int cec_get_current_configuration(libcec_configuration *configuration)
335 {
336 return cec_parser ? (cec_parser->GetCurrentConfiguration(configuration) ? 1 : 0) : -1;
337 }
338
339 int cec_can_persist_configuration(void)
340 {
341 return cec_parser ? (cec_parser->CanPersistConfiguration() ? 1 : 0) : -1;
342 }
343
344 int cec_persist_configuration(libcec_configuration *configuration)
345 {
346 return cec_parser ? (cec_parser->PersistConfiguration(configuration) ? 1 : 0) : -1;
347 }
348
349 int cec_set_configuration(libcec_configuration *configuration)
350 {
351 return cec_parser ? (cec_parser->SetConfiguration(configuration) ? 1 : 0) : -1;
352 }
353
354 void cec_rescan_devices(void)
355 {
356 if (cec_parser)
357 cec_parser->RescanActiveDevices();
358 }
359
360 int cec_is_libcec_active_source(void)
361 {
362 return cec_parser ? (cec_parser->IsLibCECActiveSource() ? 1 : 0) : -1;
363 }
364
365 int 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
370 const char * cec_get_lib_info(void)
371 {
372 return cec_parser ? cec_parser->GetLibInfo() : NULL;
373 }
374
375 void cec_init_video_standalone(void)
376 {
377 if (cec_parser)
378 cec_parser->InitVideoStandalone();
379 }
380
381 uint16_t cec_get_adapter_vendor_id(void)
382 {
383 return cec_parser ? cec_parser->GetAdapterVendorId() : 0;
384 }
385
386 uint16_t cec_get_adapter_product_id(void)
387 {
388 return cec_parser ? cec_parser->GetAdapterProductId() : 0;
389 }
390
391 uint8_t cec_audio_toggle_mute(void)
392 {
393 return cec_parser ? cec_parser->AudioToggleMute() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
394 }
395
396 uint8_t cec_audio_mute(void)
397 {
398 return cec_parser ? cec_parser->AudioMute() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
399 }
400
401 uint8_t cec_audio_unmute(void)
402 {
403 return cec_parser ? cec_parser->AudioUnmute() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
404 }
405
406 uint8_t cec_audio_get_status(void)
407 {
408 return cec_parser ? cec_parser->AudioStatus() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
409 }
410
411 //@}