fixed return value check of m_communication->Write()
[deb_libcec.git] / src / lib / CECParserC.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
33#include "CECParser.h"
34
35using namespace CEC;
36using namespace std;
37
38/*!
39 * C interface implementation
40 */
41//@{
42ICECDevice *cec_parser;
43
df7339c6 44bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
abbca718 45{
df7339c6 46 cec_parser = (ICECDevice *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress);
abbca718
LOK
47 return (cec_parser != NULL);
48}
49
abbca718
LOK
50bool cec_open(const char *strPort, int iTimeout)
51{
52 if (cec_parser)
53 return cec_parser->Open(strPort, iTimeout);
54 return false;
55}
56
f99bc831
LOK
57bool cec_close(int iTimeout)
58{
59 bool bReturn = false;
60 if (cec_parser)
61 bReturn = cec_parser->Close(iTimeout);
62
63 delete cec_parser;
64 cec_parser = NULL;
65 return bReturn;
66}
67
abbca718
LOK
68bool cec_ping(void)
69{
70 if (cec_parser)
71 return cec_parser->Ping();
72 return false;
73}
74
75bool cec_start_bootloader(void)
76{
77 if (cec_parser)
78 return cec_parser->StartBootloader();
79 return false;
80}
81
82bool cec_power_off_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
83{
84 if (cec_parser)
85 return cec_parser->PowerOffDevices(address);
86 return false;
87}
88
89bool cec_power_on_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
90{
91 if (cec_parser)
92 return cec_parser->PowerOnDevices(address);
93 return false;
94}
95
96bool cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
97{
98 if (cec_parser)
99 return cec_parser->StandbyDevices(address);
100 return false;
101}
102
103bool cec_set_active_view(void)
104{
105 if (cec_parser)
106 return cec_parser->SetActiveView();
107 return false;
108}
109
110bool cec_set_inactive_view(void)
111{
112 if (cec_parser)
113 return cec_parser->SetInactiveView();
114 return false;
115}
116
117bool cec_get_next_log_message(cec_log_message *message)
118{
119 if (cec_parser)
120 return cec_parser->GetNextLogMessage(message);
121 return false;
122}
123
124bool cec_get_next_keypress(cec_keypress *key)
125{
126 if (cec_parser)
127 return cec_parser->GetNextKeypress(key);
128 return false;
129}
130
825ddb96
LOK
131bool cec_get_next_command(cec_command *command)
132{
133 if (cec_parser)
134 return cec_parser->GetNextCommand(command);
135 return false;
136}
137
390b42d6 138bool cec_transmit(const CEC::cec_frame &data, bool bWaitForAck /* = true */)
abbca718
LOK
139{
140 if (cec_parser)
390b42d6 141 return cec_parser->Transmit(data, bWaitForAck);
abbca718
LOK
142 return false;
143}
144
6dfe9213 145bool cec_set_logical_address(cec_logical_address iLogicalAddress)
abbca718
LOK
146{
147 if (cec_parser)
6dfe9213
LOK
148 return cec_parser->SetLogicalAddress(iLogicalAddress);
149 return false;
150}
151
152bool cec_set_ack_mask(uint16_t iMask)
153{
154 if (cec_parser)
155 return cec_parser->SetAckMask(iMask);
abbca718
LOK
156 return false;
157}
158
159int cec_get_min_version(void)
160{
161 if (cec_parser)
162 return cec_parser->GetMinVersion();
163 return -1;
164}
165
166int cec_get_lib_version(void)
167{
168 if (cec_parser)
169 return cec_parser->GetLibVersion();
170 return -1;
171}
172
173int cec_find_devices(vector<cec_device> &deviceList, const char *strDevicePath /* = NULL */)
174{
175 if (cec_parser)
176 return cec_parser->FindDevices(deviceList, strDevicePath);
177 return -1;
178}
179
180//@}