Skip to content

Commit bc803aa

Browse files
committed
added exception handling
1 parent f2c5780 commit bc803aa

File tree

1 file changed

+71
-62
lines changed

1 file changed

+71
-62
lines changed

HdmiCecSink/HdmiCecSink.cpp

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "host.hpp"
2626
#include "UtilsgetRFCConfig.h"
2727

28-
#include "dsRpc.h"
2928
#include "dsDisplay.h"
3029
#include "videoOutputPort.hpp"
3130
#include "manager.hpp"
@@ -792,7 +791,17 @@ namespace WPEFramework
792791
}
793792
}
794793

795-
m_numofHdmiInput = device::HdmiInput::getInstance().getNumberOfInputs();
794+
try
795+
{
796+
m_numofHdmiInput = device::HdmiInput::getInstance().getNumberOfInputs();
797+
LOGINFO("HdmiCecSink plugin m_numofHdmiInput %d", m_numofHdmiInput);
798+
}
799+
catch(const device::Exception& err)
800+
{
801+
LOGINFO("HdmiCecSink plugin device::HdmiInput::getInstance().getNumberOfInputs failed");
802+
m_numofHdmiInput = 3;
803+
LOG_DEVICE_EXCEPTION0();
804+
}
796805

797806
LOGINFO("initalize inputs \n");
798807

@@ -826,76 +835,76 @@ namespace WPEFramework
826835

827836
void HdmiCecSink::Deinitialize(PluginHost::IShell* /* service */)
828837
{
829-
if(_powerManagerPlugin)
830-
{
831-
_powerManagerPlugin->Unregister(_pwrMgrNotification.baseInterface<Exchange::IPowerManager::IModeChangedNotification>());
832-
_powerManagerPlugin.Reset();
833-
}
834-
_registeredEventHandlers = false;
838+
if(_powerManagerPlugin)
839+
{
840+
_powerManagerPlugin->Unregister(_pwrMgrNotification.baseInterface<Exchange::IPowerManager::IModeChangedNotification>());
841+
_powerManagerPlugin.Reset();
842+
}
843+
_registeredEventHandlers = false;
835844

836-
profileType = searchRdkProfile();
845+
profileType = searchRdkProfile();
837846

838-
if (profileType == STB || profileType == NOT_FOUND)
839-
{
840-
LOGINFO("Invalid profile type for TV \n");
841-
return ;
842-
}
847+
if (profileType == STB || profileType == NOT_FOUND)
848+
{
849+
LOGINFO("Invalid profile type for TV \n");
850+
return ;
851+
}
843852

844-
CECDisable();
845-
m_currentArcRoutingState = ARC_STATE_ARC_EXIT;
853+
CECDisable();
854+
m_currentArcRoutingState = ARC_STATE_ARC_EXIT;
846855

847-
m_semSignaltoArcRoutingThread.release();
856+
m_semSignaltoArcRoutingThread.release();
848857

849-
try
850-
{
851-
if (m_arcRoutingThread.joinable())
852-
m_arcRoutingThread.join();
853-
}
854-
catch(const std::system_error& e)
855-
{
856-
LOGERR("system_error exception in thread join %s", e.what());
857-
}
858-
catch(const std::exception& e)
859-
{
860-
LOGERR("exception in thread join %s", e.what());
861-
}
858+
try
859+
{
860+
if (m_arcRoutingThread.joinable())
861+
m_arcRoutingThread.join();
862+
}
863+
catch(const std::system_error& e)
864+
{
865+
LOGERR("system_error exception in thread join %s", e.what());
866+
}
867+
catch(const std::exception& e)
868+
{
869+
LOGERR("exception in thread join %s", e.what());
870+
}
862871

863-
{
864-
m_sendKeyEventThreadExit = true;
865-
std::unique_lock<std::mutex> lk(m_sendKeyEventMutex);
866-
m_sendKeyEventThreadRun = true;
867-
m_sendKeyCV.notify_one();
868-
}
872+
{
873+
m_sendKeyEventThreadExit = true;
874+
std::unique_lock<std::mutex> lk(m_sendKeyEventMutex);
875+
m_sendKeyEventThreadRun = true;
876+
m_sendKeyCV.notify_one();
877+
}
869878

870-
try
871-
{
872-
if (m_sendKeyEventThread.joinable())
873-
m_sendKeyEventThread.join();
874-
}
875-
catch(const std::system_error& e)
876-
{
877-
LOGERR("system_error exception in thread join %s", e.what());
878-
}
879-
catch(const std::exception& e)
880-
{
881-
LOGERR("exception in thread join %s", e.what());
882-
}
879+
try
880+
{
881+
if (m_sendKeyEventThread.joinable())
882+
m_sendKeyEventThread.join();
883+
}
884+
catch(const std::system_error& e)
885+
{
886+
LOGERR("system_error exception in thread join %s", e.what());
887+
}
888+
catch(const std::exception& e)
889+
{
890+
LOGERR("exception in thread join %s", e.what());
891+
}
883892

884-
HdmiCecSink::_instance = nullptr;
885-
device::Host::getInstance().UnRegister(baseInterface<device::Host::IHdmiInEvents>());
893+
HdmiCecSink::_instance = nullptr;
894+
device::Host::getInstance().UnRegister(baseInterface<device::Host::IHdmiInEvents>());
886895

887-
try
888-
{
889-
device::Manager::DeInitialize();
890-
LOGINFO("HdmiCecSink plugin device::Manager::DeInitialize success");
891-
}
892-
catch(const device::Exception& err)
893-
{
894-
LOGINFO("HdmiCecSink plugin device::Manager::DeInitialize failed");
895-
LOG_DEVICE_EXCEPTION0();
896-
}
896+
try
897+
{
898+
device::Manager::DeInitialize();
899+
LOGINFO("HdmiCecSink plugin device::Manager::DeInitialize success");
900+
}
901+
catch(const device::Exception& err)
902+
{
903+
LOGINFO("HdmiCecSink plugin device::Manager::DeInitialize failed");
904+
LOG_DEVICE_EXCEPTION0();
905+
}
897906

898-
LOGWARN(" HdmiCecSink Deinitialize() Done");
907+
LOGWARN(" HdmiCecSink Deinitialize() Done");
899908
}
900909

901910
void HdmiCecSink::InitializePowerManager(PluginHost::IShell *service)

0 commit comments

Comments
 (0)