Merge branch 'master' into release
[deb_libcec.git] / src / lib / LibCECC.cpp
CommitLineData
abbca718
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 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
2abe74eb 33#include "LibCEC.h"
abbca718
LOK
34
35using namespace CEC;
36using namespace std;
37
38/*!
39 * C interface implementation
40 */
41//@{
2abe74eb 42ICECAdapter *cec_parser;
abbca718 43
df7339c6 44bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
abbca718 45{
2abe74eb 46 cec_parser = (ICECAdapter *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress);
abbca718
LOK
47 return (cec_parser != NULL);
48}
49
5f39c4d8
LOK
50void cec_destroy(void)
51{
52 cec_close();
53 delete cec_parser;
54 cec_parser = NULL;
55}
56
abbca718
LOK
57bool cec_open(const char *strPort, int iTimeout)
58{
59 if (cec_parser)
60 return cec_parser->Open(strPort, iTimeout);
61 return false;
62}
63
5f39c4d8 64void cec_close(void)
f99bc831 65{
f99bc831 66 if (cec_parser)
5f39c4d8 67 cec_parser->Close();
f99bc831
LOK
68}
69
2abe74eb 70int cec_find_adapters(vector<cec_adapter> &deviceList, const char *strDevicePath /* = NULL */)
abbca718
LOK
71{
72 if (cec_parser)
2abe74eb
LOK
73 return cec_parser->FindAdapters(deviceList, strDevicePath);
74 return -1;
abbca718
LOK
75}
76
2abe74eb 77bool cec_ping_adapters(void)
abbca718
LOK
78{
79 if (cec_parser)
2abe74eb 80 return cec_parser->PingAdapter();
abbca718
LOK
81 return false;
82}
83
2abe74eb 84bool cec_start_bootloader(void)
abbca718
LOK
85{
86 if (cec_parser)
2abe74eb 87 return cec_parser->StartBootloader();
abbca718
LOK
88 return false;
89}
90
2abe74eb 91int cec_get_min_version(void)
abbca718
LOK
92{
93 if (cec_parser)
2abe74eb
LOK
94 return cec_parser->GetMinVersion();
95 return -1;
abbca718
LOK
96}
97
2abe74eb 98int cec_get_lib_version(void)
abbca718
LOK
99{
100 if (cec_parser)
2abe74eb
LOK
101 return cec_parser->GetLibVersion();
102 return -1;
abbca718
LOK
103}
104
105bool cec_get_next_log_message(cec_log_message *message)
106{
107 if (cec_parser)
108 return cec_parser->GetNextLogMessage(message);
109 return false;
110}
111
112bool cec_get_next_keypress(cec_keypress *key)
113{
114 if (cec_parser)
115 return cec_parser->GetNextKeypress(key);
116 return false;
117}
118
825ddb96
LOK
119bool cec_get_next_command(cec_command *command)
120{
121 if (cec_parser)
122 return cec_parser->GetNextCommand(command);
123 return false;
124}
125
390b42d6 126bool cec_transmit(const CEC::cec_frame &data, bool bWaitForAck /* = true */)
abbca718
LOK
127{
128 if (cec_parser)
390b42d6 129 return cec_parser->Transmit(data, bWaitForAck);
abbca718
LOK
130 return false;
131}
132
6dfe9213 133bool cec_set_logical_address(cec_logical_address iLogicalAddress)
abbca718
LOK
134{
135 if (cec_parser)
6dfe9213
LOK
136 return cec_parser->SetLogicalAddress(iLogicalAddress);
137 return false;
138}
139
2abe74eb 140bool cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */)
6dfe9213
LOK
141{
142 if (cec_parser)
2abe74eb 143 return cec_parser->PowerOnDevices(address);
abbca718
LOK
144 return false;
145}
146
2abe74eb 147bool cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
abbca718
LOK
148{
149 if (cec_parser)
2abe74eb
LOK
150 return cec_parser->StandbyDevices(address);
151 return false;
abbca718
LOK
152}
153
2abe74eb 154bool cec_set_active_view(void)
abbca718
LOK
155{
156 if (cec_parser)
2abe74eb
LOK
157 return cec_parser->SetActiveView();
158 return false;
abbca718
LOK
159}
160
2abe74eb 161bool cec_set_inactive_view(void)
abbca718
LOK
162{
163 if (cec_parser)
2abe74eb
LOK
164 return cec_parser->SetInactiveView();
165 return false;
abbca718
LOK
166}
167
168//@}