2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "CECProcessor.h"
35 #include "adapter/AdapterMessage.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"
47 using namespace PLATFORM
;
49 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const char *strDeviceName
, cec_logical_address iLogicalAddress
/* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
51 m_bInitialised(false),
52 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
53 m_iBaseDevice((cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
),
54 m_lastInitiator(CECDEVICE_UNKNOWN
),
55 m_strDeviceName(strDeviceName
),
56 m_controller(controller
),
58 m_iStandardLineTimeout(3),
59 m_iRetryLineTimeout(3),
60 m_iLastTransmission(0)
62 m_communication
= new CAdapterCommunication(this);
63 m_logicalAddresses
.Clear();
64 m_logicalAddresses
.Set(iLogicalAddress
);
66 for (int iPtr
= 0; iPtr
<= 16; iPtr
++)
67 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, iPtr
== iLogicalAddress
? iPhysicalAddress
: 0);
70 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const char *strDeviceName
, const cec_device_type_list
&types
) :
72 m_bInitialised(false),
73 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
74 m_iBaseDevice((cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
),
75 m_strDeviceName(strDeviceName
),
77 m_controller(controller
),
79 m_iStandardLineTimeout(3),
80 m_iRetryLineTimeout(3),
81 m_iLastTransmission(0)
83 m_communication
= new CAdapterCommunication(this);
84 m_logicalAddresses
.Clear();
85 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
89 case CECDEVICE_AUDIOSYSTEM
:
90 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
92 case CECDEVICE_PLAYBACKDEVICE1
:
93 case CECDEVICE_PLAYBACKDEVICE2
:
94 case CECDEVICE_PLAYBACKDEVICE3
:
95 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
97 case CECDEVICE_RECORDINGDEVICE1
:
98 case CECDEVICE_RECORDINGDEVICE2
:
99 case CECDEVICE_RECORDINGDEVICE3
:
100 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
102 case CECDEVICE_TUNER1
:
103 case CECDEVICE_TUNER2
:
104 case CECDEVICE_TUNER3
:
105 case CECDEVICE_TUNER4
:
106 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
109 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
112 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
118 CCECProcessor::~CCECProcessor(void)
121 m_startCondition
.Broadcast();
124 delete m_communication
;
125 m_communication
= NULL
;
127 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
128 delete m_busDevices
[iPtr
];
131 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
)
134 CLockObject
lock(m_mutex
);
135 if (!m_communication
)
137 m_controller
->AddLog(CEC_LOG_ERROR
, "no connection handler found");
141 /* check for an already opened connection */
142 if (m_communication
->IsOpen())
144 m_controller
->AddLog(CEC_LOG_ERROR
, "connection already opened");
148 /* open a new connection */
149 if ((bReturn
= m_communication
->Open(strPort
, iBaudRate
, iTimeoutMs
)) == false)
150 m_controller
->AddLog(CEC_LOG_ERROR
, "could not open a connection");
155 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
157 CLockObject
lock(m_mutex
);
158 m_bInitialised
= bSetTo
;
161 bool CCECProcessor::Initialise(void)
165 CLockObject
lock(m_mutex
);
166 if (!m_logicalAddresses
.IsEmpty())
167 m_logicalAddresses
.Clear();
169 if (!FindLogicalAddresses())
171 m_controller
->AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
175 /* only set our OSD name for the primary device */
176 m_busDevices
[m_logicalAddresses
.primary
]->m_strDeviceName
= m_strDeviceName
;
179 /* get the vendor id from the TV, so we are using the correct handler */
180 m_busDevices
[CECDEVICE_TV
]->RequestVendorId();
183 if ((bReturn
= SetHDMIPort(m_iBaseDevice
, m_iHDMIPort
, true)) == false)
186 strLog
.Format("unable to set HDMI port %d on %s (%x)", m_iHDMIPort
, ToString(m_iBaseDevice
), (uint8_t)m_iBaseDevice
);
187 m_controller
->AddLog(CEC_LOG_ERROR
, strLog
);
190 SetInitialised(bReturn
);
195 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
200 CLockObject
lock(m_mutex
);
201 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
204 /* create the processor thread */
205 if (!CreateThread() || !m_startCondition
.Wait(m_mutex
) || !m_bStarted
)
207 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
212 if ((bReturn
= Initialise()) == false)
214 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
219 m_controller
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
225 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
227 if (m_busDevices
[address
]->TryLogicalAddress())
229 m_logicalAddresses
.Set(address
);
236 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
238 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
239 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
240 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
241 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
244 bool CCECProcessor::FindLogicalAddressTuner(void)
246 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
247 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
248 TryLogicalAddress(CECDEVICE_TUNER2
) ||
249 TryLogicalAddress(CECDEVICE_TUNER3
) ||
250 TryLogicalAddress(CECDEVICE_TUNER4
);
253 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
255 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
256 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
257 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
258 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
261 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
263 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
264 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
267 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
269 bool bChanged(false);
272 strLog
.Format("changing device type '%s' into '%s'", ToString(from
), ToString(to
));
273 AddLog(CEC_LOG_NOTICE
, strLog
);
275 CLockObject
lock(m_mutex
);
276 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
277 m_logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
279 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
281 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
284 if (m_types
.types
[iPtr
] == from
)
287 m_types
.types
[iPtr
] = to
;
289 else if (m_types
.types
[iPtr
] == to
&& bChanged
)
291 m_types
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
297 FindLogicalAddresses();
299 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
300 if (previousDevice
&& newDevice
)
302 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
303 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_UNKNOWN
);
305 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
306 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
308 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
309 cec_menu_language lang
;
310 lang
.device
= previousDevice
->GetLogicalAddress();
311 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
312 lang
.language
[iPtr
] = '?';
313 lang
.language
[3] = 0;
314 previousDevice
->SetMenuLanguage(lang
);
316 newDevice
->SetMenuState(previousDevice
->GetMenuState());
317 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
319 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
320 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
322 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
323 previousDevice
->SetPhysicalAddress(0xFFFF);
325 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
326 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
328 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
329 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
331 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
332 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
334 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
335 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
337 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
338 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
346 bool CCECProcessor::FindLogicalAddresses(void)
349 m_logicalAddresses
.Clear();
352 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
354 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
357 strLog
.Format("%s - device %d: type %d", __FUNCTION__
, iPtr
, m_types
.types
[iPtr
]);
358 AddLog(CEC_LOG_DEBUG
, strLog
);
360 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
361 bReturn
&= FindLogicalAddressRecordingDevice();
362 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
363 bReturn
&= FindLogicalAddressTuner();
364 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
365 bReturn
&= FindLogicalAddressPlaybackDevice();
366 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
367 bReturn
&= FindLogicalAddressAudioSystem();
371 SetAckMask(m_logicalAddresses
.AckMask());
376 void CCECProcessor::ReplaceHandlers(void)
378 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
379 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
382 void *CCECProcessor::Process(void)
384 bool bParseFrame(false);
386 CCECAdapterMessage msg
;
389 CLockObject
lock(m_mutex
);
391 m_controller
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
392 m_startCondition
.Signal();
402 CLockObject
lock(m_mutex
);
403 if (m_commandBuffer
.Pop(command
))
407 else if (m_communication
->IsOpen() && m_communication
->Read(msg
, 50))
409 if ((bParseFrame
= (ParseMessage(msg
) && !IsStopped())) == true)
410 command
= m_currentframe
;
415 ParseCommand(command
);
420 m_controller
->CheckKeypressTimeout();
424 m_communication
->Close();
429 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
436 cec_logical_address addr
= m_logicalAddresses
.primary
;
438 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
440 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
442 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
444 addr
= (cec_logical_address
) iPtr
;
450 m_busDevices
[addr
]->SetActiveSource();
451 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
453 bReturn
= m_busDevices
[addr
]->TransmitActiveSource();
455 if (bReturn
&& (m_busDevices
[addr
]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
||
456 m_busDevices
[addr
]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
457 m_busDevices
[addr
]->GetHandler()->SendDeckStatusUpdateOnActiveSource())
459 bReturn
= ((CCECPlaybackDevice
*)m_busDevices
[addr
])->TransmitDeckStatus(CECDEVICE_TV
);
466 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
470 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
473 device
->SetActiveSource();
480 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
482 CLockObject
lock(m_mutex
);
483 m_iStandardLineTimeout
= iTimeout
;
486 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
488 CLockObject
lock(m_mutex
);
489 m_iRetryLineTimeout
= iTimeout
;
492 bool CCECProcessor::SetActiveView(void)
494 return SetActiveSource(m_types
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_types
[0]);
497 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
501 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
504 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
506 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
513 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
517 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
520 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
522 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
529 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
532 CLockObject
lock(m_mutex
);
534 m_iBaseDevice
= iBaseDevice
;
536 if (!m_bStarted
&& !bForce
)
540 strLog
.Format("setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
541 AddLog(CEC_LOG_DEBUG
, strLog
);
543 uint16_t iPhysicalAddress(0);
544 if (iBaseDevice
> CECDEVICE_TV
)
547 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
551 if (iPhysicalAddress
< 0xffff)
553 if (iPhysicalAddress
== 0)
554 iPhysicalAddress
+= 0x1000 * iPort
;
555 else if (iPhysicalAddress
% 0x1000 == 0)
556 iPhysicalAddress
+= 0x100 * iPort
;
557 else if (iPhysicalAddress
% 0x100 == 0)
558 iPhysicalAddress
+= 0x10 * iPort
;
559 else if (iPhysicalAddress
% 0x10 == 0)
560 iPhysicalAddress
+= iPort
;
566 m_controller
->AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
570 SetPhysicalAddress(iPhysicalAddress
);
576 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
578 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
580 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
586 bool CCECProcessor::TransmitInactiveSource(void)
591 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
592 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveSource();
596 void CCECProcessor::LogOutput(const cec_command
&data
)
599 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
601 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
603 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
604 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
605 m_controller
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
608 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
610 CLockObject
lock(m_mutex
);
611 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
614 strLog
.Format("<< setting primary logical address to %1x", iLogicalAddress
);
615 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
616 m_logicalAddresses
.primary
= iLogicalAddress
;
617 m_logicalAddresses
.Set(iLogicalAddress
);
618 return SetAckMask(m_logicalAddresses
.AckMask());
624 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
626 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
628 if (m_logicalAddresses
[iPtr
])
629 m_busDevices
[iPtr
]->SetMenuState(state
);
633 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
638 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
640 bool bSendActiveView(false);
642 cec_logical_addresses sendUpdatesTo
;
645 CLockObject
lock(m_mutex
);
646 if (!m_logicalAddresses
.IsEmpty())
648 bool bWasActiveSource(false);
649 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
650 if (m_logicalAddresses
[iPtr
])
652 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
653 m_busDevices
[iPtr
]->SetInactiveSource();
654 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
656 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
659 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
664 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
665 if (sendUpdatesTo
[iPtr
])
666 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
674 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
677 strLog
.Format("== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
678 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
681 CLockObject
lock(m_mutex
);
682 m_bMonitor
= bEnable
;
686 return SetAckMask(0);
688 return SetAckMask(m_logicalAddresses
.AckMask());
691 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
693 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
695 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
696 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
697 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
702 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
705 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
706 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
711 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
714 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
715 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
720 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
723 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
724 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
729 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
731 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
732 return m_busDevices
[m_logicalAddresses
.primary
];
734 CCECBusDevice
*device
= NULL
;
735 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
737 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
739 device
= m_busDevices
[iPtr
];
747 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
749 CCECBusDevice
*device
= NULL
;
751 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
753 if (m_busDevices
[iPtr
]->m_type
== type
&& m_logicalAddresses
[iPtr
])
755 device
= m_busDevices
[iPtr
];
763 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
765 CCECBusDevice
*device(NULL
);
766 cec_logical_address primary
= m_logicalAddresses
.primary
;
767 if (primary
!= CECDEVICE_UNKNOWN
)
768 device
= m_busDevices
[primary
];
772 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
774 return m_busDevices
[iAddress
]->GetCecVersion();
777 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
779 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
782 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
783 retVal
.device
= iAddress
;
788 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
790 if (m_busDevices
[iAddress
])
792 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
793 return (strcmp(language
->language
, "???") != 0);
798 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
800 if (m_busDevices
[iAddress
])
801 return m_busDevices
[iAddress
]->GetVendorId();
805 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
807 if (m_busDevices
[iAddress
])
808 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
812 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
814 if (m_busDevices
[iAddress
])
815 return m_busDevices
[iAddress
]->GetPowerStatus();
816 return CEC_POWER_STATUS_UNKNOWN
;
819 cec_logical_address
CCECProcessor::GetActiveSource(void)
821 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
823 if (m_busDevices
[iPtr
]->IsActiveSource())
824 return (cec_logical_address
)iPtr
;
827 return CECDEVICE_UNKNOWN
;
830 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
832 return m_busDevices
[iAddress
]->IsActiveSource();
835 bool CCECProcessor::Transmit(const cec_command
&data
)
840 CCECAdapterMessage
*output
= new CCECAdapterMessage(data
);
842 /* set the number of retries */
843 if (data
.opcode
== CEC_OPCODE_NONE
)
844 output
->maxTries
= 1;
845 else if (data
.initiator
!= CECDEVICE_BROADCAST
)
846 output
->maxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
848 bReturn
= Transmit(output
);
850 /* set to "not present" on failed ack */
851 if (output
->IsError() && output
->reply
== MSGCODE_TRANSMIT_FAILED_ACK
&&
852 output
->Destination() != CECDEVICE_BROADCAST
)
853 m_busDevices
[output
->Destination()]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
859 bool CCECProcessor::Transmit(CCECAdapterMessage
*output
)
862 CLockObject
lock(m_mutex
);
864 m_iLastTransmission
= GetTimeMs();
865 m_communication
->SetLineTimeout(m_iStandardLineTimeout
);
870 if (output
->tries
> 0)
871 m_communication
->SetLineTimeout(m_iRetryLineTimeout
);
873 CLockObject
msgLock(output
->mutex
);
874 if (!m_communication
|| !m_communication
->Write(output
))
878 output
->condition
.Wait(output
->mutex
);
879 if (output
->state
!= ADAPTER_MESSAGE_STATE_SENT
)
881 m_controller
->AddLog(CEC_LOG_ERROR
, "command was not sent");
886 if (output
->transmit_timeout
> 0)
888 if ((bReturn
= m_communication
->WaitForTransmitSucceeded(output
)) == false)
889 m_controller
->AddLog(CEC_LOG_DEBUG
, "did not receive ack");
893 }while (output
->transmit_timeout
> 0 && output
->NeedsRetry() && ++output
->tries
< output
->maxTries
);
896 m_communication
->SetLineTimeout(m_iStandardLineTimeout
);
901 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
903 m_controller
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
907 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
908 command
.parameters
.PushBack((uint8_t)opcode
);
909 command
.parameters
.PushBack((uint8_t)reason
);
914 bool CCECProcessor::ParseMessage(const CCECAdapterMessage
&msg
)
917 bool bIsError(msg
.IsError());
922 switch(msg
.Message())
924 case MSGCODE_FRAME_START
:
926 m_currentframe
.Clear();
929 m_currentframe
.initiator
= msg
.Initiator();
930 m_currentframe
.destination
= msg
.Destination();
931 m_currentframe
.ack
= msg
.IsACK();
932 m_currentframe
.eom
= msg
.IsEOM();
934 if (m_currentframe
.ack
== 0x1)
936 m_lastInitiator
= m_currentframe
.initiator
;
937 m_busDevices
[m_lastInitiator
]->GetHandler()->HandlePoll(m_currentframe
.initiator
, m_currentframe
.destination
);
941 case MSGCODE_RECEIVE_FAILED
:
943 if (m_lastInitiator
!= CECDEVICE_UNKNOWN
)
944 bIsError
= m_busDevices
[m_lastInitiator
]->GetHandler()->HandleReceiveFailed();
947 case MSGCODE_FRAME_DATA
:
951 m_currentframe
.PushBack(msg
[1]);
952 m_currentframe
.eom
= msg
.IsEOM();
961 m_controller
->AddLog(bIsError
? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
965 void CCECProcessor::ParseCommand(cec_command
&command
)
968 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
969 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
970 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
971 m_controller
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
973 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
974 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
977 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
979 cec_logical_addresses addresses
;
981 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
983 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
984 addresses
.Set((cec_logical_address
) iPtr
);
989 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
991 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
994 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
996 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
998 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
1005 uint16_t CCECProcessor::GetPhysicalAddress(void) const
1007 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
1008 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
1012 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode
)
1014 m_controller
->SetCurrentButton(iButtonCode
);
1017 void CCECProcessor::AddCommand(const cec_command
&command
)
1019 m_controller
->AddCommand(command
);
1022 void CCECProcessor::AddKey(cec_keypress
&key
)
1024 m_controller
->AddKey(key
);
1027 void CCECProcessor::AddKey(void)
1029 m_controller
->AddKey();
1032 void CCECProcessor::AddLog(cec_log_level level
, const CStdString
&strMessage
)
1034 m_controller
->AddLog(level
, strMessage
);
1037 bool CCECProcessor::SetAckMask(uint16_t iMask
)
1039 bool bReturn(false);
1041 strLog
.Format("setting ackmask to %2x", iMask
);
1042 m_controller
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
1044 CCECAdapterMessage
*output
= new CCECAdapterMessage
;
1046 output
->PushBack(MSGSTART
);
1047 output
->PushEscaped(MSGCODE_SET_ACK_MASK
);
1048 output
->PushEscaped(iMask
>> 8);
1049 output
->PushEscaped((uint8_t)iMask
);
1050 output
->PushBack(MSGEND
);
1052 if ((bReturn
= Transmit(output
)) == false)
1053 m_controller
->AddLog(CEC_LOG_ERROR
, "could not set the ackmask");
1060 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
1062 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
1065 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
1067 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
1070 const char *CCECProcessor::ToString(const cec_device_type type
)
1074 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1075 return "audio system";
1076 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1077 return "playback device";
1078 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1079 return "recording device";
1080 case CEC_DEVICE_TYPE_RESERVED
:
1082 case CEC_DEVICE_TYPE_TUNER
:
1084 case CEC_DEVICE_TYPE_TV
:
1091 const char *CCECProcessor::ToString(const cec_menu_state state
)
1095 case CEC_MENU_STATE_ACTIVATED
:
1097 case CEC_MENU_STATE_DEACTIVATED
:
1098 return "deactivated";
1104 const char *CCECProcessor::ToString(const cec_version version
)
1108 case CEC_VERSION_1_2
:
1110 case CEC_VERSION_1_2A
:
1112 case CEC_VERSION_1_3
:
1114 case CEC_VERSION_1_3A
:
1116 case CEC_VERSION_1_4
:
1123 const char *CCECProcessor::ToString(const cec_power_status status
)
1127 case CEC_POWER_STATUS_ON
:
1129 case CEC_POWER_STATUS_STANDBY
:
1131 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1132 return "in transition from on to standby";
1133 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1134 return "in transition from standby to on";
1140 const char *CCECProcessor::ToString(const cec_logical_address address
)
1144 case CECDEVICE_AUDIOSYSTEM
:
1146 case CECDEVICE_BROADCAST
:
1148 case CECDEVICE_FREEUSE
:
1150 case CECDEVICE_PLAYBACKDEVICE1
:
1151 return "Playback 1";
1152 case CECDEVICE_PLAYBACKDEVICE2
:
1153 return "Playback 2";
1154 case CECDEVICE_PLAYBACKDEVICE3
:
1155 return "Playback 3";
1156 case CECDEVICE_RECORDINGDEVICE1
:
1157 return "Recorder 1";
1158 case CECDEVICE_RECORDINGDEVICE2
:
1159 return "Recorder 2";
1160 case CECDEVICE_RECORDINGDEVICE3
:
1161 return "Recorder 3";
1162 case CECDEVICE_RESERVED1
:
1163 return "Reserved 1";
1164 case CECDEVICE_RESERVED2
:
1165 return "Reserved 2";
1166 case CECDEVICE_TUNER1
:
1168 case CECDEVICE_TUNER2
:
1170 case CECDEVICE_TUNER3
:
1172 case CECDEVICE_TUNER4
:
1181 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1185 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1186 return "skip forward wind";
1187 case CEC_DECK_CONTROL_MODE_EJECT
:
1189 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1190 return "reverse rewind";
1191 case CEC_DECK_CONTROL_MODE_STOP
:
1198 const char *CCECProcessor::ToString(const cec_deck_info status
)
1202 case CEC_DECK_INFO_PLAY
:
1204 case CEC_DECK_INFO_RECORD
:
1206 case CEC_DECK_INFO_PLAY_REVERSE
:
1207 return "play reverse";
1208 case CEC_DECK_INFO_STILL
:
1210 case CEC_DECK_INFO_SLOW
:
1212 case CEC_DECK_INFO_SLOW_REVERSE
:
1213 return "slow reverse";
1214 case CEC_DECK_INFO_FAST_FORWARD
:
1215 return "fast forward";
1216 case CEC_DECK_INFO_FAST_REVERSE
:
1217 return "fast reverse";
1218 case CEC_DECK_INFO_NO_MEDIA
:
1220 case CEC_DECK_INFO_STOP
:
1222 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1223 return "info skip forward wind";
1224 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1225 return "info skip reverse rewind";
1226 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1227 return "info index search forward";
1228 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1229 return "info index search reverse";
1230 case CEC_DECK_INFO_OTHER_STATUS
:
1237 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1241 case CEC_OPCODE_ACTIVE_SOURCE
:
1242 return "active source";
1243 case CEC_OPCODE_IMAGE_VIEW_ON
:
1244 return "image view on";
1245 case CEC_OPCODE_TEXT_VIEW_ON
:
1246 return "text view on";
1247 case CEC_OPCODE_INACTIVE_SOURCE
:
1248 return "inactive source";
1249 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1250 return "request active source";
1251 case CEC_OPCODE_ROUTING_CHANGE
:
1252 return "routing change";
1253 case CEC_OPCODE_ROUTING_INFORMATION
:
1254 return "routing information";
1255 case CEC_OPCODE_SET_STREAM_PATH
:
1256 return "set stream path";
1257 case CEC_OPCODE_STANDBY
:
1259 case CEC_OPCODE_RECORD_OFF
:
1260 return "record off";
1261 case CEC_OPCODE_RECORD_ON
:
1263 case CEC_OPCODE_RECORD_STATUS
:
1264 return "record status";
1265 case CEC_OPCODE_RECORD_TV_SCREEN
:
1266 return "record tv screen";
1267 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1268 return "clear analogue timer";
1269 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1270 return "clear digital timer";
1271 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1272 return "clear external timer";
1273 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1274 return "set analogue timer";
1275 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1276 return "set digital timer";
1277 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1278 return "set external timer";
1279 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1280 return "set timer program title";
1281 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1282 return "timer cleared status";
1283 case CEC_OPCODE_TIMER_STATUS
:
1284 return "timer status";
1285 case CEC_OPCODE_CEC_VERSION
:
1286 return "cec version";
1287 case CEC_OPCODE_GET_CEC_VERSION
:
1288 return "get cec version";
1289 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1290 return "give physical address";
1291 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1292 return "get menu language";
1293 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1294 return "report physical address";
1295 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1296 return "set menu language";
1297 case CEC_OPCODE_DECK_CONTROL
:
1298 return "deck control";
1299 case CEC_OPCODE_DECK_STATUS
:
1300 return "deck status";
1301 case CEC_OPCODE_GIVE_DECK_STATUS
:
1302 return "give deck status";
1303 case CEC_OPCODE_PLAY
:
1305 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1306 return "give tuner status";
1307 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1308 return "select analogue service";
1309 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1310 return "set digital service";
1311 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1312 return "tuner device status";
1313 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1314 return "tuner step decrement";
1315 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1316 return "tuner step increment";
1317 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1318 return "device vendor id";
1319 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1320 return "give device vendor id";
1321 case CEC_OPCODE_VENDOR_COMMAND
:
1322 return "vendor command";
1323 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1324 return "vendor command with id";
1325 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1326 return "vendor remote button down";
1327 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1328 return "vendor remote button up";
1329 case CEC_OPCODE_SET_OSD_STRING
:
1330 return "set osd string";
1331 case CEC_OPCODE_GIVE_OSD_NAME
:
1332 return "give osd name";
1333 case CEC_OPCODE_SET_OSD_NAME
:
1334 return "set osd name";
1335 case CEC_OPCODE_MENU_REQUEST
:
1336 return "menu request";
1337 case CEC_OPCODE_MENU_STATUS
:
1338 return "menu status";
1339 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1340 return "user control pressed";
1341 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1342 return "user control release";
1343 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1344 return "give device power status";
1345 case CEC_OPCODE_REPORT_POWER_STATUS
:
1346 return "report power status";
1347 case CEC_OPCODE_FEATURE_ABORT
:
1348 return "feature abort";
1349 case CEC_OPCODE_ABORT
:
1351 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1352 return "give audio status";
1353 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1354 return "give audio mode status";
1355 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1356 return "report audio status";
1357 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1358 return "set system audio mode";
1359 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1360 return "system audio mode request";
1361 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1362 return "system audio mode status";
1363 case CEC_OPCODE_SET_AUDIO_RATE
:
1364 return "set audio rate";
1370 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1374 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1376 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1383 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1385 // TODO this is a mask
1389 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1393 case CEC_VENDOR_SAMSUNG
:
1397 case CEC_VENDOR_PANASONIC
:
1399 case CEC_VENDOR_PIONEER
:
1401 case CEC_VENDOR_ONKYO
:
1403 case CEC_VENDOR_YAMAHA
:
1405 case CEC_VENDOR_PHILIPS
:
1407 case CEC_VENDOR_SONY
:
1414 void *CCECBusScan::Process(void)
1416 CCECBusDevice
*device(NULL
);
1417 uint8_t iCounter(0);
1419 while (!IsStopped())
1421 if (++iCounter
< 10)
1426 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1428 device
= m_processor
->m_busDevices
[iPtr
];
1430 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1434 device
->GetVendorId();
1438 device
->GetPowerStatus(true);
1446 void CCECBusScan::WaitUntilIdle(void)
1451 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1452 while (iWaitTime
> 0)
1455 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1459 bool CCECProcessor::StartBootloader(void)
1461 return m_communication
->StartBootloader();
1464 bool CCECProcessor::PingAdapter(void)
1466 return m_communication
->PingAdapter();
1469 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1471 m_busDevices
[initiator
]->GetHandler()->HandlePoll(initiator
, destination
);
1472 m_lastInitiator
= initiator
;
1475 bool CCECProcessor::HandleReceiveFailed(void)
1477 return m_lastInitiator
!= CECDEVICE_UNKNOWN
&&
1478 !m_busDevices
[m_lastInitiator
]->GetHandler()->HandleReceiveFailed();