cec: moved part of the TryLogicalAddress() logic to CCECBusDevice
[deb_libcec.git] / src / lib / CECProcessor.cpp
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 "CECProcessor.h"
34
35 #include "AdapterCommunication.h"
36 #include "devices/CECBusDevice.h"
37 #include "devices/CECAudioSystem.h"
38 #include "devices/CECPlaybackDevice.h"
39 #include "devices/CECRecordingDevice.h"
40 #include "devices/CECTuner.h"
41 #include "devices/CECTV.h"
42 #include "implementations/CECCommandHandler.h"
43 #include "LibCEC.h"
44 #include "util/StdString.h"
45 #include "platform/timeutils.h"
46
47 using namespace CEC;
48 using namespace std;
49
50 CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
51 m_bStarted(false),
52 m_strDeviceName(strDeviceName),
53 m_communication(serComm),
54 m_controller(controller),
55 m_bMonitor(false)
56 {
57 m_logicalAddresses.Clear();
58 m_logicalAddresses.Set(iLogicalAddress);
59 m_types.clear();
60 for (int iPtr = 0; iPtr <= 16; iPtr++)
61 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
62 }
63
64 CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, const cec_device_type_list &types) :
65 m_bStarted(false),
66 m_strDeviceName(strDeviceName),
67 m_types(types),
68 m_communication(serComm),
69 m_controller(controller),
70 m_bMonitor(false)
71 {
72 m_logicalAddresses.Clear();
73 for (int iPtr = 0; iPtr < 16; iPtr++)
74 {
75 switch(iPtr)
76 {
77 case CECDEVICE_AUDIOSYSTEM:
78 m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF);
79 break;
80 case CECDEVICE_PLAYBACKDEVICE1:
81 case CECDEVICE_PLAYBACKDEVICE2:
82 case CECDEVICE_PLAYBACKDEVICE3:
83 m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF);
84 break;
85 case CECDEVICE_RECORDINGDEVICE1:
86 case CECDEVICE_RECORDINGDEVICE2:
87 case CECDEVICE_RECORDINGDEVICE3:
88 m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF);
89 break;
90 case CECDEVICE_TUNER1:
91 case CECDEVICE_TUNER2:
92 case CECDEVICE_TUNER3:
93 case CECDEVICE_TUNER4:
94 m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF);
95 break;
96 case CECDEVICE_TV:
97 m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
98 break;
99 default:
100 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF);
101 break;
102 }
103 }
104 }
105
106 CCECProcessor::~CCECProcessor(void)
107 {
108 m_startCondition.Broadcast();
109 StopThread();
110 m_communication = NULL;
111 m_controller = NULL;
112 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
113 delete m_busDevices[iPtr];
114 }
115
116 bool CCECProcessor::Start(void)
117 {
118 CLockObject lock(&m_mutex);
119 if (!m_communication || !m_communication->IsOpen())
120 {
121 m_controller->AddLog(CEC_LOG_ERROR, "connection is closed");
122 return false;
123 }
124
125 if (CreateThread())
126 {
127 if (!m_startCondition.Wait(&m_mutex) || !m_bStarted)
128 {
129 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
130 return false;
131 }
132 return true;
133 }
134 else
135 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
136
137 return false;
138 }
139
140 bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int iIndex)
141 {
142 if (m_busDevices[address]->TryLogicalAddress())
143 {
144 /* only set our OSD name and active source for the primary device */
145 if (m_logicalAddresses.IsEmpty())
146 {
147 m_busDevices[address]->m_strDeviceName = m_strDeviceName;
148 m_busDevices[address]->m_bActiveSource = true;
149 }
150 m_logicalAddresses.Set(address);
151
152 // TODO
153 m_busDevices[address]->SetPhysicalAddress((uint16_t)CEC_DEFAULT_PHYSICAL_ADDRESS + ((uint16_t)iIndex * 0x100));
154
155 return true;
156 }
157
158 return false;
159 }
160
161 bool CCECProcessor::FindLogicalAddressRecordingDevice(unsigned int iIndex)
162 {
163 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
164 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1, iIndex) ||
165 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2, iIndex) ||
166 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3, iIndex);
167 }
168
169 bool CCECProcessor::FindLogicalAddressTuner(unsigned int iIndex)
170 {
171 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
172 return TryLogicalAddress(CECDEVICE_TUNER1, iIndex) ||
173 TryLogicalAddress(CECDEVICE_TUNER2, iIndex) ||
174 TryLogicalAddress(CECDEVICE_TUNER3, iIndex) ||
175 TryLogicalAddress(CECDEVICE_TUNER4, iIndex);
176 }
177
178 bool CCECProcessor::FindLogicalAddressPlaybackDevice(unsigned int iIndex)
179 {
180 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
181 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1, iIndex) ||
182 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2, iIndex) ||
183 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3, iIndex);
184 }
185
186 bool CCECProcessor::FindLogicalAddressAudioSystem(unsigned int iIndex)
187 {
188 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
189 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM, iIndex);
190 }
191
192 bool CCECProcessor::FindLogicalAddresses(void)
193 {
194 bool bReturn(true);
195 m_logicalAddresses.Clear();
196 CStdString strLog;
197
198 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
199 {
200 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
201 continue;
202
203 strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]);
204 AddLog(CEC_LOG_DEBUG, strLog);
205
206 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
207 bReturn &= FindLogicalAddressRecordingDevice(iPtr);
208 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
209 bReturn &= FindLogicalAddressTuner(iPtr);
210 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
211 bReturn &= FindLogicalAddressPlaybackDevice(iPtr);
212 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
213 bReturn &= FindLogicalAddressAudioSystem(iPtr);
214 }
215
216 return bReturn;
217 }
218
219 void *CCECProcessor::Process(void)
220 {
221 bool bParseFrame(false);
222 cec_command command;
223 CCECAdapterMessage msg;
224
225 {
226 if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses())
227 {
228 CLockObject lock(&m_mutex);
229 m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addressed");
230 m_startCondition.Signal();
231 return NULL;
232 }
233
234 SetAckMask(m_logicalAddresses.AckMask());
235
236 {
237 CLockObject lock(&m_mutex);
238 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
239 m_bStarted = true;
240 m_startCondition.Signal();
241 }
242 }
243
244 while (!IsStopped())
245 {
246 command.Clear();
247 msg.clear();
248
249 {
250 CLockObject lock(&m_mutex);
251 if (m_commandBuffer.Pop(command))
252 {
253 bParseFrame = true;
254 }
255 else if (m_communication->IsOpen() && m_communication->Read(msg, 50))
256 {
257 m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
258 if ((bParseFrame = (ParseMessage(msg) && !IsStopped())) == true)
259 command = m_currentframe;
260 }
261 }
262
263 if (bParseFrame)
264 ParseCommand(command);
265 bParseFrame = false;
266
267 Sleep(5);
268
269 m_controller->CheckKeypressTimeout();
270
271 for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++)
272 m_busDevices[iDevicePtr]->PollVendorId();
273
274 Sleep(5);
275 }
276
277 return NULL;
278 }
279
280 bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
281 {
282 bool bReturn(false);
283
284 if (!IsRunning())
285 return bReturn;
286
287 cec_logical_address addr = m_logicalAddresses.primary;
288
289 if (type != CEC_DEVICE_TYPE_RESERVED)
290 {
291 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
292 {
293 if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
294 {
295 addr = (cec_logical_address) iPtr;
296 break;
297 }
298 }
299 }
300
301 return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress()) &&
302 m_busDevices[addr]->TransmitActiveSource();
303 }
304
305 bool CCECProcessor::SetActiveView(void)
306 {
307 return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]);
308 }
309
310 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
311 {
312 bool bReturn(false);
313
314 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
315 if (device)
316 {
317 ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
318 if (bSendUpdate)
319 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
320 bReturn = true;
321 }
322
323 return bReturn;
324 }
325
326 bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
327 {
328 bool bReturn(false);
329
330 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
331 if (device)
332 {
333 ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
334 if (bSendUpdate)
335 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
336 bReturn = true;
337 }
338
339 return bReturn;
340 }
341
342 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
343 {
344 bool bReturn(false);
345
346 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
347 if (device)
348 {
349 device->SetActiveDevice();
350 bReturn = true;
351 }
352
353 return bReturn;
354 }
355
356 bool CCECProcessor::SetInactiveView(void)
357 {
358 if (!IsRunning())
359 return false;
360
361 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
362 return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveView();
363 return false;
364 }
365
366 void CCECProcessor::LogOutput(const cec_command &data)
367 {
368 CStdString strTx;
369 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
370 if (data.opcode_set)
371 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
372
373 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
374 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
375 m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
376 }
377
378 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
379 {
380 if (m_logicalAddresses.primary != iLogicalAddress)
381 {
382 CStdString strLog;
383 strLog.Format("<< setting primary logical address to %1x", iLogicalAddress);
384 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
385 m_logicalAddresses.primary = iLogicalAddress;
386 m_logicalAddresses.Set(iLogicalAddress);
387 return SetAckMask(m_logicalAddresses.AckMask());
388 }
389
390 return true;
391 }
392
393 bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
394 {
395 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
396 {
397 if (m_logicalAddresses[iPtr])
398 m_busDevices[iPtr]->SetMenuState(state);
399 }
400
401 if (bSendUpdate)
402 m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
403
404 return true;
405 }
406
407 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
408 {
409 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
410 {
411 m_busDevices[m_logicalAddresses.primary]->SetPhysicalAddress(iPhysicalAddress);
412 return SetActiveView();
413 }
414 return false;
415 }
416
417 bool CCECProcessor::SwitchMonitoring(bool bEnable)
418 {
419 CStdString strLog;
420 strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
421 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
422
423 m_bMonitor = bEnable;
424 if (bEnable)
425 return SetAckMask(0);
426 else
427 return SetAckMask(m_logicalAddresses.AckMask());
428 }
429
430 bool CCECProcessor::PollDevice(cec_logical_address iAddress)
431 {
432 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
433 return m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress);
434 return false;
435 }
436
437 CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
438 {
439 CCECBusDevice *device = NULL;
440
441 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
442 {
443 if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
444 {
445 device = m_busDevices[iPtr];
446 break;
447 }
448 }
449
450 return device;
451 }
452
453 CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
454 {
455 CCECBusDevice *device = NULL;
456
457 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
458 {
459 if (m_busDevices[iPtr]->m_type == type)
460 {
461 device = m_busDevices[iPtr];
462 break;
463 }
464 }
465
466 return device;
467 }
468
469 cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
470 {
471 return m_busDevices[iAddress]->GetCecVersion();
472 }
473
474 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
475 {
476 if (m_busDevices[iAddress])
477 {
478 *language = m_busDevices[iAddress]->GetMenuLanguage();
479 return (strcmp(language->language, "???") != 0);
480 }
481 return false;
482 }
483
484 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
485 {
486 if (m_busDevices[iAddress])
487 return m_busDevices[iAddress]->GetVendorId();
488 return false;
489 }
490
491 cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
492 {
493 if (m_busDevices[iAddress])
494 return m_busDevices[iAddress]->GetPowerStatus();
495 return CEC_POWER_STATUS_UNKNOWN;
496 }
497
498 bool CCECProcessor::Transmit(const cec_command &data)
499 {
500 bool bReturn(false);
501 LogOutput(data);
502
503 CCECAdapterMessage *output = new CCECAdapterMessage(data);
504 bReturn = Transmit(output);
505 delete output;
506
507 return bReturn;
508 }
509
510 bool CCECProcessor::Transmit(CCECAdapterMessage *output)
511 {
512 bool bReturn(false);
513 CLockObject lock(&m_mutex);
514 {
515 CLockObject msgLock(&output->mutex);
516 if (!m_communication || !m_communication->Write(output))
517 return bReturn;
518 else
519 {
520 output->condition.Wait(&output->mutex);
521 if (output->state != ADAPTER_MESSAGE_STATE_SENT)
522 {
523 m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
524 return bReturn;
525 }
526 }
527
528 if (output->transmit_timeout > 0)
529 {
530 if ((bReturn = WaitForTransmitSucceeded(output->size(), output->transmit_timeout)) == false)
531 m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
532 }
533 else
534 bReturn = true;
535 }
536
537 return bReturn;
538 }
539
540 void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
541 {
542 m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
543
544 cec_command command;
545 // TODO
546 cec_command::Format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
547 command.parameters.PushBack((uint8_t)opcode);
548 command.parameters.PushBack((uint8_t)reason);
549
550 Transmit(command);
551 }
552
553 bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout /* = 1000 */)
554 {
555 bool bError(false);
556 bool bTransmitSucceeded(false);
557 uint8_t iPacketsLeft(iLength / 4);
558
559 int64_t iNow = GetTimeMs();
560 int64_t iTargetTime = iNow + (uint64_t) iTimeout;
561
562 while (!bTransmitSucceeded && !bError && (iTimeout == 0 || iNow < iTargetTime))
563 {
564 CCECAdapterMessage msg;
565
566 if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
567 {
568 iNow = GetTimeMs();
569 continue;
570 }
571
572 if ((bError = msg.is_error()) == false)
573 {
574 m_controller->AddLog(bError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
575
576 switch(msg.message())
577 {
578 case MSGCODE_COMMAND_ACCEPTED:
579 if (iPacketsLeft > 0)
580 iPacketsLeft--;
581 break;
582 case MSGCODE_TRANSMIT_SUCCEEDED:
583 bTransmitSucceeded = (iPacketsLeft == 0);
584 bError = !bTransmitSucceeded;
585 break;
586 default:
587 if (ParseMessage(msg))
588 m_commandBuffer.Push(m_currentframe);
589 }
590
591 iNow = GetTimeMs();
592 }
593 }
594
595 return bTransmitSucceeded && !bError;
596 }
597
598 bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
599 {
600 bool bEom = false;
601
602 if (msg.empty())
603 return bEom;
604
605 switch(msg.message())
606 {
607 case MSGCODE_FRAME_START:
608 {
609 m_currentframe.Clear();
610 if (msg.size() >= 2)
611 {
612 m_currentframe.initiator = msg.initiator();
613 m_currentframe.destination = msg.destination();
614 m_currentframe.ack = msg.ack();
615 m_currentframe.eom = msg.eom();
616 }
617 }
618 break;
619 case MSGCODE_FRAME_DATA:
620 {
621 if (msg.size() >= 2)
622 {
623 m_currentframe.PushBack(msg[1]);
624 m_currentframe.eom = msg.eom();
625 }
626 bEom = msg.eom();
627 }
628 break;
629 default:
630 break;
631 }
632
633 return bEom;
634 }
635
636 void CCECProcessor::ParseCommand(cec_command &command)
637 {
638 CStdString dataStr;
639 dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode);
640 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
641 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
642 m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
643
644 if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST)
645 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
646 }
647
648 uint16_t CCECProcessor::GetPhysicalAddress(void) const
649 {
650 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
651 return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress();
652 return false;
653 }
654
655 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
656 {
657 m_controller->SetCurrentButton(iButtonCode);
658 }
659
660 void CCECProcessor::AddCommand(const cec_command &command)
661 {
662 m_controller->AddCommand(command);
663 }
664
665 void CCECProcessor::AddKey(cec_keypress &key)
666 {
667 m_controller->AddKey(key);
668 }
669
670 void CCECProcessor::AddKey(void)
671 {
672 m_controller->AddKey();
673 }
674
675 void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage)
676 {
677 m_controller->AddLog(level, strMessage);
678 }
679
680 bool CCECProcessor::SetAckMask(uint16_t iMask)
681 {
682 bool bReturn(false);
683 CStdString strLog;
684 strLog.Format("setting ackmask to %2x", iMask);
685 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
686
687 CCECAdapterMessage *output = new CCECAdapterMessage;
688
689 output->push_back(MSGSTART);
690 output->push_escaped(MSGCODE_SET_ACK_MASK);
691 output->push_escaped(iMask >> 8);
692 output->push_escaped((uint8_t)iMask);
693 output->push_back(MSGEND);
694
695 if ((bReturn = Transmit(output)) == false)
696 m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
697
698 delete output;
699
700 return bReturn;
701 }