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