27bf5bb640714938fd798f2912e8063569267534
[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)
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);
154
155 return true;
156 }
157
158 return false;
159 }
160
161 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
162 {
163 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
164 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
165 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
166 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
167 }
168
169 bool CCECProcessor::FindLogicalAddressTuner(void)
170 {
171 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
172 return TryLogicalAddress(CECDEVICE_TUNER1) ||
173 TryLogicalAddress(CECDEVICE_TUNER2) ||
174 TryLogicalAddress(CECDEVICE_TUNER3) ||
175 TryLogicalAddress(CECDEVICE_TUNER4);
176 }
177
178 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
179 {
180 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
181 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
182 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
183 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
184 }
185
186 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
187 {
188 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
189 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
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();
208 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
209 bReturn &= FindLogicalAddressTuner();
210 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
211 bReturn &= FindLogicalAddressPlaybackDevice();
212 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
213 bReturn &= FindLogicalAddressAudioSystem();
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 {
273 if (!m_logicalAddresses[iDevicePtr])
274 m_busDevices[iDevicePtr]->PollVendorId();
275 }
276
277 Sleep(5);
278 }
279
280 return NULL;
281 }
282
283 bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
284 {
285 bool bReturn(false);
286
287 if (!IsRunning())
288 return bReturn;
289
290 cec_logical_address addr = m_logicalAddresses.primary;
291
292 if (type != CEC_DEVICE_TYPE_RESERVED)
293 {
294 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
295 {
296 if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
297 {
298 addr = (cec_logical_address) iPtr;
299 break;
300 }
301 }
302 }
303
304 return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress()) &&
305 m_busDevices[addr]->TransmitActiveSource();
306 }
307
308 bool CCECProcessor::SetActiveSource(cec_logical_address iAddress)
309 {
310 return SetStreamPath(m_busDevices[iAddress]->GetPhysicalAddress());
311 }
312
313 bool CCECProcessor::SetActiveView(void)
314 {
315 return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]);
316 }
317
318 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
319 {
320 bool bReturn(false);
321
322 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
323 if (device)
324 {
325 ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
326 if (bSendUpdate)
327 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
328 bReturn = true;
329 }
330
331 return bReturn;
332 }
333
334 bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
335 {
336 bool bReturn(false);
337
338 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
339 if (device)
340 {
341 ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
342 if (bSendUpdate)
343 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
344 bReturn = true;
345 }
346
347 return bReturn;
348 }
349
350 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
351 {
352 bool bReturn(false);
353
354 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
355 if (device)
356 {
357 device->SetActiveDevice();
358 bReturn = true;
359 }
360
361 return bReturn;
362 }
363
364 bool CCECProcessor::SetInactiveView(void)
365 {
366 if (!IsRunning())
367 return false;
368
369 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
370 return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveView();
371 return false;
372 }
373
374 void CCECProcessor::LogOutput(const cec_command &data)
375 {
376 CStdString strTx;
377 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
378 if (data.opcode_set)
379 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
380
381 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
382 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
383 m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
384 }
385
386 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
387 {
388 if (m_logicalAddresses.primary != iLogicalAddress)
389 {
390 CStdString strLog;
391 strLog.Format("<< setting primary logical address to %1x", iLogicalAddress);
392 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
393 m_logicalAddresses.primary = iLogicalAddress;
394 m_logicalAddresses.Set(iLogicalAddress);
395 return SetAckMask(m_logicalAddresses.AckMask());
396 }
397
398 return true;
399 }
400
401 bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
402 {
403 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
404 {
405 if (m_logicalAddresses[iPtr])
406 m_busDevices[iPtr]->SetMenuState(state);
407 }
408
409 if (bSendUpdate)
410 m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
411
412 return true;
413 }
414
415 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
416 {
417 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
418 {
419 m_busDevices[m_logicalAddresses.primary]->SetPhysicalAddress(iPhysicalAddress);
420 return SetActiveView();
421 }
422 return false;
423 }
424
425 bool CCECProcessor::SwitchMonitoring(bool bEnable)
426 {
427 CStdString strLog;
428 strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
429 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
430
431 m_bMonitor = bEnable;
432 if (bEnable)
433 return SetAckMask(0);
434 else
435 return SetAckMask(m_logicalAddresses.AckMask());
436 }
437
438 bool CCECProcessor::PollDevice(cec_logical_address iAddress)
439 {
440 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
441 return m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress);
442 return false;
443 }
444
445 CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
446 {
447 if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress() == iPhysicalAddress)
448 return m_busDevices[m_logicalAddresses.primary];
449
450 CCECBusDevice *device = NULL;
451 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
452 {
453 if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
454 {
455 device = m_busDevices[iPtr];
456 break;
457 }
458 }
459
460 return device;
461 }
462
463 CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
464 {
465 CCECBusDevice *device = NULL;
466
467 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
468 {
469 if (m_busDevices[iPtr]->m_type == type)
470 {
471 device = m_busDevices[iPtr];
472 break;
473 }
474 }
475
476 return device;
477 }
478
479 cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
480 {
481 return m_busDevices[iAddress]->GetCecVersion();
482 }
483
484 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
485 {
486 if (m_busDevices[iAddress])
487 {
488 *language = m_busDevices[iAddress]->GetMenuLanguage();
489 return (strcmp(language->language, "???") != 0);
490 }
491 return false;
492 }
493
494 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
495 {
496 if (m_busDevices[iAddress])
497 return m_busDevices[iAddress]->GetVendorId();
498 return false;
499 }
500
501 cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
502 {
503 if (m_busDevices[iAddress])
504 return m_busDevices[iAddress]->GetPowerStatus();
505 return CEC_POWER_STATUS_UNKNOWN;
506 }
507
508 bool CCECProcessor::Transmit(const cec_command &data)
509 {
510 bool bReturn(false);
511 LogOutput(data);
512
513 CCECAdapterMessage *output = new CCECAdapterMessage(data);
514 bReturn = Transmit(output);
515 delete output;
516
517 return bReturn;
518 }
519
520 bool CCECProcessor::Transmit(CCECAdapterMessage *output)
521 {
522 bool bReturn(false);
523 CLockObject lock(&m_mutex);
524 {
525 CLockObject msgLock(&output->mutex);
526 if (!m_communication || !m_communication->Write(output))
527 return bReturn;
528 else
529 {
530 output->condition.Wait(&output->mutex);
531 if (output->state != ADAPTER_MESSAGE_STATE_SENT)
532 {
533 m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
534 return bReturn;
535 }
536 }
537
538 if (output->transmit_timeout > 0)
539 {
540 if ((bReturn = WaitForTransmitSucceeded(output->size(), output->transmit_timeout)) == false)
541 m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
542 }
543 else
544 bReturn = true;
545 }
546
547 return bReturn;
548 }
549
550 void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
551 {
552 m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
553
554 cec_command command;
555 // TODO
556 cec_command::Format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
557 command.parameters.PushBack((uint8_t)opcode);
558 command.parameters.PushBack((uint8_t)reason);
559
560 Transmit(command);
561 }
562
563 bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout /* = 1000 */)
564 {
565 bool bError(false);
566 bool bTransmitSucceeded(false);
567 uint8_t iPacketsLeft(iLength / 4);
568
569 int64_t iNow = GetTimeMs();
570 int64_t iTargetTime = iNow + (uint64_t) iTimeout;
571
572 while (!bTransmitSucceeded && !bError && (iTimeout == 0 || iNow < iTargetTime))
573 {
574 CCECAdapterMessage msg;
575
576 if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
577 {
578 iNow = GetTimeMs();
579 continue;
580 }
581
582 if ((bError = msg.is_error()) == false)
583 {
584 m_controller->AddLog(bError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
585
586 switch(msg.message())
587 {
588 case MSGCODE_COMMAND_ACCEPTED:
589 if (iPacketsLeft > 0)
590 iPacketsLeft--;
591 break;
592 case MSGCODE_TRANSMIT_SUCCEEDED:
593 bTransmitSucceeded = (iPacketsLeft == 0);
594 bError = !bTransmitSucceeded;
595 break;
596 default:
597 if (ParseMessage(msg))
598 m_commandBuffer.Push(m_currentframe);
599 }
600
601 iNow = GetTimeMs();
602 }
603 }
604
605 return bTransmitSucceeded && !bError;
606 }
607
608 bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
609 {
610 bool bEom = false;
611
612 if (msg.empty())
613 return bEom;
614
615 switch(msg.message())
616 {
617 case MSGCODE_FRAME_START:
618 {
619 m_currentframe.Clear();
620 if (msg.size() >= 2)
621 {
622 m_currentframe.initiator = msg.initiator();
623 m_currentframe.destination = msg.destination();
624 m_currentframe.ack = msg.ack();
625 m_currentframe.eom = msg.eom();
626 }
627 }
628 break;
629 case MSGCODE_FRAME_DATA:
630 {
631 if (msg.size() >= 2)
632 {
633 m_currentframe.PushBack(msg[1]);
634 m_currentframe.eom = msg.eom();
635 }
636 bEom = msg.eom();
637 }
638 break;
639 default:
640 break;
641 }
642
643 return bEom;
644 }
645
646 void CCECProcessor::ParseCommand(cec_command &command)
647 {
648 CStdString dataStr;
649 dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode);
650 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
651 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
652 m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
653
654 if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST)
655 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
656 }
657
658 cec_logical_addresses CCECProcessor::GetActiveDevices(void)
659 {
660 cec_logical_addresses addresses;
661 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
662 {
663 if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
664 addresses.Set((cec_logical_address) iPtr);
665 }
666 return addresses;
667 }
668
669 bool CCECProcessor::IsActiveDevice(cec_logical_address address)
670 {
671 return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
672 }
673
674 bool CCECProcessor::IsActiveDeviceType(cec_device_type type)
675 {
676 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
677 {
678 if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
679 return true;
680 }
681
682 return false;
683 }
684
685 uint16_t CCECProcessor::GetPhysicalAddress(void) const
686 {
687 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
688 return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress();
689 return false;
690 }
691
692 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
693 {
694 m_controller->SetCurrentButton(iButtonCode);
695 }
696
697 void CCECProcessor::AddCommand(const cec_command &command)
698 {
699 m_controller->AddCommand(command);
700 }
701
702 void CCECProcessor::AddKey(cec_keypress &key)
703 {
704 m_controller->AddKey(key);
705 }
706
707 void CCECProcessor::AddKey(void)
708 {
709 m_controller->AddKey();
710 }
711
712 void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage)
713 {
714 m_controller->AddLog(level, strMessage);
715 }
716
717 bool CCECProcessor::SetAckMask(uint16_t iMask)
718 {
719 bool bReturn(false);
720 CStdString strLog;
721 strLog.Format("setting ackmask to %2x", iMask);
722 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
723
724 CCECAdapterMessage *output = new CCECAdapterMessage;
725
726 output->push_back(MSGSTART);
727 output->push_escaped(MSGCODE_SET_ACK_MASK);
728 output->push_escaped(iMask >> 8);
729 output->push_escaped((uint8_t)iMask);
730 output->push_back(MSGEND);
731
732 if ((bReturn = Transmit(output)) == false)
733 m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
734
735 delete output;
736
737 return bReturn;
738 }