Commit | Line | Data |
---|---|---|
2abe74eb 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. |
2abe74eb 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 | ||
33 | #include "LibCEC.h" | |
34 | ||
7bb4ed43 | 35 | #include "adapter/USBCECAdapterDetection.h" |
08d80226 | 36 | #include "adapter/USBCECAdapterCommunication.h" |
2abe74eb | 37 | #include "CECProcessor.h" |
0d800fe5 | 38 | #include "CECTypeUtils.h" |
004b8382 | 39 | #include "devices/CECAudioSystem.h" |
0f23c85c | 40 | #include "devices/CECBusDevice.h" |
004b8382 LOK |
41 | #include "devices/CECPlaybackDevice.h" |
42 | #include "devices/CECTV.h" | |
ba65909d LOK |
43 | #include "platform/util/timeutils.h" |
44 | #include "platform/util/StdString.h" | |
c9d15485 | 45 | #include "platform/util/util.h" |
2abe74eb | 46 | |
004b8382 LOK |
47 | #include "CECClient.h" |
48 | ||
2abe74eb LOK |
49 | using namespace std; |
50 | using namespace CEC; | |
f00ff009 | 51 | using namespace PLATFORM; |
2abe74eb | 52 | |
c9d15485 | 53 | //TODO replace deprecated constructor in 2.0 |
c30acafa LOK |
54 | CLibCEC::CLibCEC(const char *UNUSED(strDeviceName), cec_device_type_list UNUSED(types), uint16_t UNUSED(iPhysicalAddress) /* = 0 */) : |
55 | m_iStartTime(GetTimeMs()), | |
56 | m_client(NULL) | |
57 | { | |
58 | m_cec = new CCECProcessor(this); | |
59 | } | |
60 | ||
c9d15485 | 61 | //TODO replace deprecated constructor in 2.0 |
c30acafa LOK |
62 | CLibCEC::CLibCEC(libcec_configuration *UNUSED(configuration)) : |
63 | m_iStartTime(GetTimeMs()), | |
64 | m_client(NULL) | |
caca2d81 | 65 | { |
004b8382 | 66 | m_cec = new CCECProcessor(this); |
f8513317 LOK |
67 | } |
68 | ||
2abe74eb LOK |
69 | CLibCEC::~CLibCEC(void) |
70 | { | |
c0152c09 LOK |
71 | // unregister all clients client |
72 | UnregisterClients(); | |
73 | ||
74 | // delete the adapter connection | |
c9d15485 | 75 | DELETE_AND_NULL(m_cec); |
2abe74eb LOK |
76 | } |
77 | ||
b32ffd87 | 78 | bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */) |
2abe74eb | 79 | { |
c0152c09 | 80 | if (!m_cec || !strPort) |
99aeafb9 LOK |
81 | return false; |
82 | ||
c0152c09 | 83 | // open a new connection |
b32ffd87 | 84 | if (!m_cec->Start(strPort, CEC_SERIAL_DEFAULT_BAUDRATE, iTimeoutMs)) |
2abe74eb LOK |
85 | { |
86 | AddLog(CEC_LOG_ERROR, "could not start CEC communications"); | |
87 | return false; | |
88 | } | |
89 | ||
c0152c09 | 90 | // register all clients |
004b8382 LOK |
91 | for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++) |
92 | { | |
93 | if (!m_cec->RegisterClient(*it)) | |
94 | { | |
95 | AddLog(CEC_LOG_ERROR, "failed to register a CEC client"); | |
96 | return false; | |
97 | } | |
98 | } | |
99 | ||
2abe74eb LOK |
100 | return true; |
101 | } | |
102 | ||
103 | void CLibCEC::Close(void) | |
104 | { | |
af205cf4 LOK |
105 | if (!m_cec) |
106 | return; | |
107 | ||
c0152c09 | 108 | // unregister all clients |
af205cf4 | 109 | m_cec->UnregisterClients(); |
c0152c09 LOK |
110 | |
111 | // close the connection | |
af205cf4 | 112 | m_cec->Close(); |
fa4798bd LOK |
113 | } |
114 | ||
25701fa6 | 115 | int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) |
2abe74eb | 116 | { |
6807ee55 LOK |
117 | if (!CUSBCECAdapterDetection::CanAutodetect()) |
118 | { | |
119 | AddLog(CEC_LOG_WARNING, "libCEC has not been compiled with adapter detection code for this target, so the path to the COM port has to be provided to libCEC"); | |
120 | return 0; | |
121 | } | |
122 | ||
7bb4ed43 | 123 | return CUSBCECAdapterDetection::FindAdapters(deviceList, iBufSize, strDevicePath); |
2abe74eb LOK |
124 | } |
125 | ||
2abe74eb LOK |
126 | bool CLibCEC::StartBootloader(void) |
127 | { | |
1113cb7d | 128 | return m_cec ? m_cec->StartBootloader() : false; |
2abe74eb LOK |
129 | } |
130 | ||
c0152c09 | 131 | bool CLibCEC::PingAdapter(void) |
2abe74eb | 132 | { |
c0152c09 | 133 | return m_client ? m_client->PingAdapter() : false; |
2abe74eb LOK |
134 | } |
135 | ||
c0152c09 | 136 | bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) |
a9232a79 | 137 | { |
c0152c09 | 138 | return m_client ? m_client->EnableCallbacks(cbParam, callbacks) : false; |
a9232a79 LOK |
139 | } |
140 | ||
c0152c09 | 141 | bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration) |
2abe74eb | 142 | { |
c0152c09 | 143 | return m_client ? m_client->GetCurrentConfiguration(*configuration) : false; |
2abe74eb LOK |
144 | } |
145 | ||
c0152c09 | 146 | bool CLibCEC::SetConfiguration(const libcec_configuration *configuration) |
28fa6c97 | 147 | { |
c0152c09 | 148 | return m_client ? m_client->SetConfiguration(*configuration) : false; |
28fa6c97 LOK |
149 | } |
150 | ||
004b8382 | 151 | bool CLibCEC::CanPersistConfiguration(void) |
1969b140 | 152 | { |
c0152c09 | 153 | return m_client ? m_client->CanPersistConfiguration() : false; |
1969b140 LOK |
154 | } |
155 | ||
004b8382 | 156 | bool CLibCEC::PersistConfiguration(libcec_configuration *configuration) |
8b7e5ff6 | 157 | { |
c0152c09 | 158 | return m_client ? m_client->PersistConfiguration(*configuration) : false; |
8b7e5ff6 LOK |
159 | } |
160 | ||
004b8382 | 161 | void CLibCEC::RescanActiveDevices(void) |
6a1c0009 | 162 | { |
c0152c09 LOK |
163 | if (m_client) |
164 | m_client->RescanActiveDevices(); | |
44c74256 LOK |
165 | } |
166 | ||
c0152c09 | 167 | bool CLibCEC::IsLibCECActiveSource(void) |
eab72c40 | 168 | { |
c0152c09 | 169 | return m_client ? m_client->IsLibCECActiveSource() : false; |
eab72c40 LOK |
170 | } |
171 | ||
004b8382 | 172 | bool CLibCEC::Transmit(const cec_command &data) |
b4b1b49b | 173 | { |
004b8382 | 174 | return m_client ? m_client->Transmit(data) : false; |
b4b1b49b LOK |
175 | } |
176 | ||
004b8382 | 177 | bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress) |
b4b1b49b | 178 | { |
004b8382 | 179 | return m_client ? m_client->SetLogicalAddress(iLogicalAddress) : false; |
b4b1b49b LOK |
180 | } |
181 | ||
004b8382 | 182 | bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) |
e55f3f70 | 183 | { |
004b8382 | 184 | return m_client ? m_client->SetPhysicalAddress(iPhysicalAddress) : false; |
e55f3f70 | 185 | } |
44c74256 | 186 | |
004b8382 | 187 | bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort /* = CEC_DEFAULT_HDMI_PORT */) |
57f45e6c | 188 | { |
004b8382 | 189 | return m_client ? m_client->SetHDMIPort(iBaseDevice, iPort) : false; |
57f45e6c LOK |
190 | } |
191 | ||
004b8382 | 192 | bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */) |
6d858ba4 | 193 | { |
004b8382 | 194 | return m_client ? m_client->SendPowerOnDevices(address) : false; |
6d858ba4 LOK |
195 | } |
196 | ||
004b8382 | 197 | bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) |
6d858ba4 | 198 | { |
004b8382 | 199 | return m_client ? m_client->SendStandbyDevices(address) : false; |
6d858ba4 LOK |
200 | } |
201 | ||
004b8382 | 202 | bool CLibCEC::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */) |
6d858ba4 | 203 | { |
004b8382 | 204 | return m_client ? m_client->SendSetActiveSource(type) : false; |
6d858ba4 LOK |
205 | } |
206 | ||
004b8382 | 207 | bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */) |
04e637f9 | 208 | { |
004b8382 | 209 | return m_client ? m_client->SendSetDeckControlMode(mode, bSendUpdate) : false; |
04e637f9 LOK |
210 | } |
211 | ||
004b8382 | 212 | bool CLibCEC::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */) |
04e637f9 | 213 | { |
004b8382 | 214 | return m_client ? m_client->SendSetDeckInfo(info, bSendUpdate) : false; |
04e637f9 LOK |
215 | } |
216 | ||
004b8382 | 217 | bool CLibCEC::SetInactiveView(void) |
04e637f9 | 218 | { |
004b8382 | 219 | return m_client ? m_client->SendSetInactiveView() : false; |
04e637f9 LOK |
220 | } |
221 | ||
004b8382 | 222 | bool CLibCEC::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */) |
a33794d8 | 223 | { |
004b8382 | 224 | return m_client ? m_client->SendSetMenuState(state, bSendUpdate) : false; |
a33794d8 LOK |
225 | } |
226 | ||
004b8382 | 227 | bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) |
a33794d8 | 228 | { |
004b8382 | 229 | return m_client ? m_client->SendSetOSDString(iLogicalAddress, duration, strMessage) : false; |
a33794d8 LOK |
230 | } |
231 | ||
c0152c09 LOK |
232 | bool CLibCEC::SwitchMonitoring(bool bEnable) |
233 | { | |
234 | return m_client ? m_client->SwitchMonitoring(bEnable) : false; | |
235 | } | |
236 | ||
004b8382 | 237 | cec_version CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress) |
ed21be2a | 238 | { |
004b8382 | 239 | return m_client ? m_client->GetDeviceCecVersion(iAddress) : CEC_VERSION_UNKNOWN; |
ed21be2a LOK |
240 | } |
241 | ||
004b8382 | 242 | bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) |
2abe74eb | 243 | { |
c0152c09 | 244 | return m_client ? m_client->GetDeviceMenuLanguage(iAddress, *language) : false; |
2abe74eb LOK |
245 | } |
246 | ||
004b8382 | 247 | uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress) |
95ba7a09 | 248 | { |
004b8382 | 249 | return m_client ? m_client->GetDeviceVendorId(iAddress) : (uint64_t)CEC_VENDOR_UNKNOWN; |
02e7043e LOK |
250 | } |
251 | ||
004b8382 | 252 | uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress) |
32403cc3 | 253 | { |
004b8382 | 254 | return m_client ? m_client->GetDevicePhysicalAddress(iAddress) : CEC_INVALID_PHYSICAL_ADDRESS; |
32403cc3 LOK |
255 | } |
256 | ||
004b8382 | 257 | cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress) |
02e7043e | 258 | { |
004b8382 | 259 | return m_client ? m_client->GetDevicePowerStatus(iAddress) : CEC_POWER_STATUS_UNKNOWN; |
95ba7a09 LOK |
260 | } |
261 | ||
c0152c09 LOK |
262 | bool CLibCEC::PollDevice(cec_logical_address iAddress) |
263 | { | |
264 | return m_client ? m_client->PollDevice(iAddress) : false; | |
265 | } | |
266 | ||
267 | cec_logical_addresses CLibCEC::GetActiveDevices(void) | |
268 | { | |
269 | cec_logical_addresses addresses; | |
270 | addresses.Clear(); | |
271 | if (m_client) | |
272 | addresses = m_client->GetActiveDevices(); | |
273 | return addresses; | |
274 | } | |
275 | ||
276 | bool CLibCEC::IsActiveDevice(cec_logical_address iAddress) | |
277 | { | |
278 | return m_client ? m_client->IsActiveDevice(iAddress) : false; | |
279 | } | |
280 | ||
281 | bool CLibCEC::IsActiveDeviceType(cec_device_type type) | |
282 | { | |
283 | return m_client ? m_client->IsActiveDeviceType(type) : false; | |
284 | } | |
285 | ||
004b8382 | 286 | uint8_t CLibCEC::VolumeUp(bool bSendRelease /* = true */) |
2abe74eb | 287 | { |
004b8382 | 288 | return m_client ? m_client->SendVolumeUp(bSendRelease) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; |
2abe74eb LOK |
289 | } |
290 | ||
004b8382 | 291 | uint8_t CLibCEC::VolumeDown(bool bSendRelease /* = true */) |
2abe74eb | 292 | { |
004b8382 | 293 | return m_client ? m_client->SendVolumeDown(bSendRelease) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; |
2abe74eb LOK |
294 | } |
295 | ||
004b8382 | 296 | uint8_t CLibCEC::MuteAudio(bool UNUSED(bSendRelease) /* = true */) |
b1c47f9d | 297 | { |
004b8382 | 298 | return m_client ? m_client->SendMuteAudio() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; |
b1c47f9d LOK |
299 | } |
300 | ||
004b8382 | 301 | bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */) |
2abe74eb | 302 | { |
004b8382 | 303 | return m_client ? m_client->SendKeypress(iDestination, key, bWait) : false; |
2abe74eb LOK |
304 | } |
305 | ||
004b8382 | 306 | bool CLibCEC::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = true */) |
e1804a4e | 307 | { |
004b8382 | 308 | return m_client ? m_client->SendKeyRelease(iDestination, bWait) : false; |
e1804a4e LOK |
309 | } |
310 | ||
004b8382 | 311 | cec_osd_name CLibCEC::GetDeviceOSDName(cec_logical_address iAddress) |
f42d3e0f | 312 | { |
004b8382 | 313 | cec_osd_name retVal; |
20505741 LOK |
314 | retVal.device = CECDEVICE_UNKNOWN; |
315 | memset(retVal.name, 0, 14); | |
316 | ||
004b8382 LOK |
317 | if (m_client) |
318 | retVal = m_client->GetDeviceOSDName(iAddress); | |
319 | return retVal; | |
f42d3e0f LOK |
320 | } |
321 | ||
c0152c09 LOK |
322 | cec_logical_address CLibCEC::GetActiveSource(void) |
323 | { | |
324 | return m_client ? m_client->GetActiveSource() : CECDEVICE_UNKNOWN; | |
325 | } | |
326 | ||
327 | bool CLibCEC::IsActiveSource(cec_logical_address iAddress) | |
328 | { | |
329 | return m_client ? m_client->IsActiveSource(iAddress) : false; | |
330 | } | |
331 | bool CLibCEC::SetStreamPath(cec_logical_address iAddress) | |
332 | { | |
333 | return m_client ? m_client->SetStreamPath(iAddress) : false; | |
334 | } | |
335 | ||
336 | bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress) | |
337 | { | |
338 | return m_client ? m_client->SetStreamPath(iPhysicalAddress) : false; | |
339 | } | |
340 | ||
004b8382 | 341 | cec_logical_addresses CLibCEC::GetLogicalAddresses(void) |
f42d3e0f | 342 | { |
004b8382 | 343 | cec_logical_addresses addresses; |
c30acafa | 344 | addresses.Clear(); |
c0152c09 LOK |
345 | if (m_client) |
346 | m_client->GetLogicalAddresses(); | |
004b8382 | 347 | return addresses; |
f42d3e0f LOK |
348 | } |
349 | ||
004b8382 | 350 | bool CLibCEC::GetNextLogMessage(cec_log_message *message) |
80b72250 | 351 | { |
004b8382 | 352 | return m_client ? m_client->GetNextLogMessage(message) : false; |
80b72250 LOK |
353 | } |
354 | ||
004b8382 | 355 | bool CLibCEC::GetNextKeypress(cec_keypress *key) |
5477a250 | 356 | { |
004b8382 | 357 | return m_client ? m_client->GetNextKeypress(key) : false; |
5477a250 LOK |
358 | } |
359 | ||
004b8382 | 360 | bool CLibCEC::GetNextCommand(cec_command *command) |
5477a250 | 361 | { |
004b8382 | 362 | return m_client ? m_client->GetNextCommand(command) : false; |
5477a250 LOK |
363 | } |
364 | ||
004b8382 | 365 | cec_device_type CLibCEC::GetType(cec_logical_address address) |
f8513317 | 366 | { |
0d800fe5 | 367 | return CCECTypeUtils::GetType(address); |
f8513317 LOK |
368 | } |
369 | ||
004b8382 | 370 | uint16_t CLibCEC::GetMaskForType(cec_logical_address address) |
caca2d81 | 371 | { |
0d800fe5 | 372 | return CCECTypeUtils::GetMaskForType(address); |
caca2d81 LOK |
373 | } |
374 | ||
004b8382 | 375 | uint16_t CLibCEC::GetMaskForType(cec_device_type type) |
a2198e5e | 376 | { |
0d800fe5 | 377 | return CCECTypeUtils::GetMaskForType(type); |
004b8382 | 378 | } |
08d80226 | 379 | |
004b8382 LOK |
380 | bool CLibCEC::IsValidPhysicalAddress(uint16_t iPhysicalAddress) |
381 | { | |
382 | return iPhysicalAddress >= CEC_MIN_PHYSICAL_ADDRESS && | |
383 | iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS; | |
a2198e5e LOK |
384 | } |
385 | ||
004b8382 | 386 | const char *CLibCEC::ToString(const cec_device_type type) |
25701fa6 | 387 | { |
0d800fe5 | 388 | return CCECTypeUtils::ToString(type); |
25701fa6 | 389 | } |
03ae897d LOK |
390 | |
391 | const char *CLibCEC::ToString(const cec_menu_state state) | |
392 | { | |
0d800fe5 | 393 | return CCECTypeUtils::ToString(state); |
03ae897d LOK |
394 | } |
395 | ||
396 | const char *CLibCEC::ToString(const cec_version version) | |
397 | { | |
0d800fe5 | 398 | return CCECTypeUtils::ToString(version); |
03ae897d LOK |
399 | } |
400 | ||
401 | const char *CLibCEC::ToString(const cec_power_status status) | |
402 | { | |
0d800fe5 | 403 | return CCECTypeUtils::ToString(status); |
03ae897d LOK |
404 | } |
405 | ||
406 | const char *CLibCEC::ToString(const cec_logical_address address) | |
407 | { | |
0d800fe5 | 408 | return CCECTypeUtils::ToString(address); |
03ae897d LOK |
409 | } |
410 | ||
411 | const char *CLibCEC::ToString(const cec_deck_control_mode mode) | |
412 | { | |
0d800fe5 | 413 | return CCECTypeUtils::ToString(mode); |
03ae897d LOK |
414 | } |
415 | ||
416 | const char *CLibCEC::ToString(const cec_deck_info status) | |
417 | { | |
0d800fe5 | 418 | return CCECTypeUtils::ToString(status); |
03ae897d LOK |
419 | } |
420 | ||
421 | const char *CLibCEC::ToString(const cec_opcode opcode) | |
422 | { | |
0d800fe5 | 423 | return CCECTypeUtils::ToString(opcode); |
03ae897d LOK |
424 | } |
425 | ||
426 | const char *CLibCEC::ToString(const cec_system_audio_status mode) | |
427 | { | |
0d800fe5 | 428 | return CCECTypeUtils::ToString(mode); |
03ae897d LOK |
429 | } |
430 | ||
0d800fe5 | 431 | const char *CLibCEC::ToString(const cec_audio_status status) |
03ae897d | 432 | { |
0d800fe5 | 433 | return CCECTypeUtils::ToString(status); |
03ae897d LOK |
434 | } |
435 | ||
436 | const char *CLibCEC::ToString(const cec_vendor_id vendor) | |
437 | { | |
0d800fe5 | 438 | return CCECTypeUtils::ToString(vendor); |
03ae897d | 439 | } |
caca2d81 LOK |
440 | |
441 | const char *CLibCEC::ToString(const cec_client_version version) | |
442 | { | |
0d800fe5 | 443 | return CCECTypeUtils::ToString(version); |
caca2d81 | 444 | } |
d40928b5 | 445 | |
3efda01a LOK |
446 | const char *CLibCEC::ToString(const cec_server_version version) |
447 | { | |
0d800fe5 | 448 | return CCECTypeUtils::ToString(version); |
3efda01a LOK |
449 | } |
450 | ||
004b8382 | 451 | void CLibCEC::CheckKeypressTimeout(void) |
a75e3a5a | 452 | { |
004b8382 LOK |
453 | // check all clients |
454 | for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++) | |
455 | (*it)->CheckKeypressTimeout(); | |
a75e3a5a LOK |
456 | } |
457 | ||
004b8382 | 458 | void CLibCEC::AddLog(const cec_log_level level, const char *strFormat, ...) |
d40928b5 | 459 | { |
004b8382 LOK |
460 | CStdString strLog; |
461 | ||
c0152c09 | 462 | // format the message |
004b8382 LOK |
463 | va_list argList; |
464 | va_start(argList, strFormat); | |
465 | strLog.FormatV(strFormat, argList); | |
466 | va_end(argList); | |
467 | ||
468 | cec_log_message message; | |
469 | message.level = level; | |
470 | message.time = GetTimeMs() - m_iStartTime; | |
471 | snprintf(message.message, sizeof(message.message), "%s", strLog.c_str()); | |
472 | ||
473 | // send the message to all clients | |
474 | for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++) | |
475 | (*it)->AddLog(message); | |
224ea877 LOK |
476 | } |
477 | ||
5d19989f LOK |
478 | void CLibCEC::AddCommand(const cec_command &command) |
479 | { | |
480 | // send the command to all clients | |
481 | for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++) | |
482 | (*it)->AddCommand(command); | |
483 | } | |
484 | ||
004b8382 | 485 | void CLibCEC::Alert(const libcec_alert type, const libcec_parameter ¶m) |
30b4aac0 | 486 | { |
004b8382 LOK |
487 | // send the alert to all clients |
488 | for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++) | |
489 | (*it)->Alert(type, param); | |
30b4aac0 LOK |
490 | } |
491 | ||
004b8382 | 492 | bool CLibCEC::SetActiveView(void) |
224ea877 | 493 | { |
004b8382 LOK |
494 | AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__); |
495 | return SetActiveSource(); | |
224ea877 LOK |
496 | } |
497 | ||
004b8382 | 498 | bool CLibCEC::EnablePhysicalAddressDetection(void) |
224ea877 | 499 | { |
004b8382 LOK |
500 | AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__); |
501 | return true; | |
224ea877 | 502 | } |
3efda01a | 503 | |
c0152c09 | 504 | CCECClient *CLibCEC::RegisterClient(libcec_configuration &configuration) |
3efda01a | 505 | { |
004b8382 LOK |
506 | if (!m_cec) |
507 | return NULL; | |
508 | ||
c0152c09 | 509 | // create a new client instance |
004b8382 LOK |
510 | CCECClient *newClient = new CCECClient(m_cec, configuration); |
511 | if (!newClient) | |
512 | return NULL; | |
004b8382 | 513 | m_clients.push_back(newClient); |
c0152c09 LOK |
514 | |
515 | // if the default client isn't set, set it | |
004b8382 LOK |
516 | if (!m_client) |
517 | m_client = newClient; | |
518 | ||
c0152c09 | 519 | // register the new client |
0b8c7eab | 520 | if (m_cec->CECInitialised()) |
004b8382 LOK |
521 | m_cec->RegisterClient(newClient); |
522 | ||
99aeafb9 | 523 | return newClient; |
3efda01a | 524 | } |
c9549d35 | 525 | |
004b8382 | 526 | void CLibCEC::UnregisterClients(void) |
c9549d35 | 527 | { |
c0152c09 LOK |
528 | if (m_cec) |
529 | m_cec->UnregisterClients(); | |
530 | ||
004b8382 | 531 | m_clients.clear(); |
c0152c09 | 532 | |
c9d15485 | 533 | DELETE_AND_NULL(m_client); |
c9549d35 | 534 | } |
9878069e | 535 | |
004b8382 | 536 | void * CECInitialise(libcec_configuration *configuration) |
9878069e | 537 | { |
004b8382 LOK |
538 | if (!configuration) |
539 | return NULL; | |
540 | ||
c0152c09 | 541 | // create a new libCEC instance |
c30acafa | 542 | CLibCEC *lib = new CLibCEC(NULL); |
c0152c09 LOK |
543 | |
544 | // register a new client | |
99aeafb9 | 545 | CCECClient *client(NULL); |
c0152c09 LOK |
546 | if (lib && configuration) |
547 | client = lib->RegisterClient(*configuration); | |
99aeafb9 | 548 | |
c0152c09 | 549 | // update the current configuration |
99aeafb9 | 550 | if (client) |
c0152c09 | 551 | client->GetCurrentConfiguration(*configuration); |
99aeafb9 LOK |
552 | |
553 | // ensure that the correct server version is set | |
554 | configuration->serverVersion = LIBCEC_VERSION_CURRENT; | |
004b8382 LOK |
555 | |
556 | return static_cast< void* > (lib); | |
9878069e | 557 | } |
209b7a5c | 558 | |
38f1fbcc | 559 | void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types) |
209b7a5c | 560 | { |
38f1fbcc | 561 | libcec_configuration configuration; configuration.Clear(); |
004b8382 LOK |
562 | |
563 | // client version < 1.5.0 | |
564 | snprintf(configuration.strDeviceName, 13, "%s", strDeviceName); | |
565 | configuration.deviceTypes = types; | |
aa169fd7 | 566 | configuration.iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS; |
004b8382 LOK |
567 | |
568 | if (configuration.deviceTypes.IsEmpty()) | |
569 | configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); | |
570 | ||
571 | return CECInitialise(&configuration); | |
209b7a5c LOK |
572 | } |
573 | ||
38f1fbcc LOK |
574 | void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /* = CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) |
575 | { | |
576 | libcec_configuration configuration; configuration.Clear(); | |
577 | ||
578 | // client version < 1.5.0 | |
579 | snprintf(configuration.strDeviceName, 13, "%s", strDeviceName); | |
580 | configuration.iPhysicalAddress = iPhysicalAddress; | |
581 | configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); | |
582 | ||
583 | return CECInitialise(&configuration); | |
584 | } | |
585 | ||
004b8382 | 586 | bool CECStartBootloader(void) |
209b7a5c | 587 | { |
004b8382 LOK |
588 | bool bReturn(false); |
589 | cec_adapter deviceList[1]; | |
590 | if (CUSBCECAdapterDetection::FindAdapters(deviceList, 1) > 0) | |
209b7a5c | 591 | { |
004b8382 LOK |
592 | CUSBCECAdapterCommunication comm(NULL, deviceList[0].comm); |
593 | CTimeout timeout(CEC_DEFAULT_CONNECT_TIMEOUT); | |
594 | while (timeout.TimeLeft() > 0 && (bReturn = comm.Open(timeout.TimeLeft() / CEC_CONNECT_TRIES, true)) == false) | |
209b7a5c | 595 | { |
004b8382 LOK |
596 | comm.Close(); |
597 | CEvent::Sleep(500); | |
209b7a5c | 598 | } |
004b8382 LOK |
599 | if (comm.IsOpen()) |
600 | bReturn = comm.StartBootloader(); | |
209b7a5c | 601 | } |
004b8382 LOK |
602 | |
603 | return bReturn; | |
604 | } | |
605 | ||
606 | void CECDestroy(CEC::ICECAdapter *instance) | |
607 | { | |
c9d15485 | 608 | DELETE_AND_NULL(instance); |
209b7a5c | 609 | } |
f80cd208 | 610 | |
b32ffd87 | 611 | bool CLibCEC::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */) |
f80cd208 LOK |
612 | { |
613 | if (m_cec->IsRunning()) | |
614 | return false; | |
004b8382 | 615 | |
f80cd208 | 616 | return m_cec->GetDeviceInformation(strPort, config, iTimeoutMs); |
a75e3a5a | 617 | } |
c30acafa | 618 | |
c0152c09 | 619 | // no longer being used |
c30acafa | 620 | void CLibCEC::AddKey(const cec_keypress &UNUSED(key)) {} |
c30acafa LOK |
621 | void CLibCEC::ConfigurationChanged(const libcec_configuration &UNUSED(config)) {} |
622 | void CLibCEC::SetCurrentButton(cec_user_control_code UNUSED(iButtonCode)) {} | |
623 | CLibCEC *CLibCEC::GetInstance(void) { return NULL; } | |
624 | void CLibCEC::SetInstance(CLibCEC *UNUSED(instance)) {} |