Skip to content

Commit a0fa4dc

Browse files
committed
base interface template change
1 parent 55ceafa commit a0fa4dc

File tree

4 files changed

+85
-7
lines changed

4 files changed

+85
-7
lines changed

HdmiCecSink/HdmiCecSink.cpp

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ namespace WPEFramework
756756
#ifdef IO_HCEC_ENABLE_IARM
757757
InitializeIARM();
758758
#else
759-
device::Host::getInstance().Register(this, "WPE[HdmiCecSink]");
759+
device::Host::getInstance().Register(baseInterface<device::Host::IHdmiInEvents>(), "WPE[HdmiCecSink]");
760760
#endif /* IO_HCEC_ENABLE_IARM */
761761
m_sendKeyEventThreadExit = false;
762762
m_sendKeyEventThread = std::thread(threadSendKeyEvent);
@@ -783,6 +783,7 @@ namespace WPEFramework
783783
}
784784
}
785785

786+
#ifdef IO_HCEC_ENABLE_IARM
786787
err = IARM_Bus_Call(IARM_BUS_DSMGR_NAME,
787788
IARM_BUS_DSMGR_API_dsHdmiInGetNumberOfInputs,
788789
(void *)&hdmiInput,
@@ -796,7 +797,9 @@ namespace WPEFramework
796797
LOGINFO("Not able to get Numebr of inputs so defaulting to 3 \n");
797798
m_numofHdmiInput = 3;
798799
}
799-
800+
#else
801+
m_numofHdmiInput = device::HdmiInput::getInstance().getNumberOfInputs();
802+
#endif /* IO_HCEC_ENABLE_IARM */
800803
LOGINFO("initalize inputs \n");
801804

802805
for (int i = 0; i < m_numofHdmiInput; i++){
@@ -886,7 +889,7 @@ namespace WPEFramework
886889
#ifdef IO_HCEC_ENABLE_IARM
887890
DeinitializeIARM();
888891
#else
889-
device::Host::getInstance().UnRegister(this);
892+
device::Host::getInstance().UnRegister(baseInterface<device::Host::IHdmiInEvents>());
890893
#endif /* IO_HCEC_ENABLE_IARM */
891894

892895
LOGWARN(" HdmiCecSink Deinitialize() Done");
@@ -2081,6 +2084,8 @@ namespace WPEFramework
20812084
int err;
20822085
bool isAnyPortConnected = false;
20832086

2087+
#ifdef IO_HCEC_ENABLE_IARM
2088+
20842089
dsHdmiInGetStatusParam_t params;
20852090
err = IARM_Bus_Call(IARM_BUS_DSMGR_NAME,
20862091
IARM_BUS_DSMGR_API_dsHdmiInGetStatus,
@@ -2101,7 +2106,21 @@ namespace WPEFramework
21012106
hdmiInputs[i].update(params.status.isPortConnected[i]);
21022107
}
21032108
}
2109+
#else
2110+
2111+
for( int i = 0; i < m_numofHdmiInput; i++ )
2112+
{
2113+
//LOGINFO("update Port Status [%d] \n", i);
2114+
hdmiInputs[i].update(device::HdmiInput::getInstance().isPortConnected(i));
2115+
2116+
//LOGINFO("Is HDMI In Port [%d] connected [%d] \n",i, params.status.isPortConnected[i]);
2117+
if ( hdmiInputs[i].m_isConnected )
2118+
{
2119+
isAnyPortConnected = true;
2120+
}
2121+
}
21042122

2123+
#endif /* IO_HCEC_ENABLE_IARM */
21052124
if ( isAnyPortConnected ) {
21062125
m_isHdmiInConnected = true;
21072126
} else {
@@ -3562,6 +3581,7 @@ namespace WPEFramework
35623581

35633582
}
35643583

3584+
#ifdef IO_HCEC_ENABLE_IARM
35653585
void HdmiCecSink::getHdmiArcPortID()
35663586
{
35673587
int err;
@@ -3586,6 +3606,50 @@ namespace WPEFramework
35863606
}
35873607
} while(retryCount++ <= 6);
35883608
}
3609+
#else
3610+
3611+
#ifdef TBD_IN_DS_CLIENT
3612+
void HdmiInput::getHDMIARCPortId(int *portId)
3613+
{
3614+
if(NULL != portId)
3615+
{
3616+
dsError_t error = dsERR_GENERAL;
3617+
error = dsGetHDMIARCPortId(portId);
3618+
if(dsERR_NONE != error)
3619+
{
3620+
*portId = -1;
3621+
}
3622+
}
3623+
}
3624+
#endif /* TBD_IN_DS_CLIENT */
3625+
3626+
void HdmiCecSink::getHdmiArcPortID()
3627+
{
3628+
int portId;
3629+
unsigned int retryCount = 1;
3630+
do {
3631+
usleep(50000); // Sleep for 50ms before retrying
3632+
portId = -1;
3633+
#ifdef TBD_IN_DS_CLIENT
3634+
device::HdmiInput::getInstance().getHDMIARCPortId(&portId);
3635+
#else
3636+
portId = 0; // just for compilation & testing
3637+
#endif /* TBD_IN_DS_CLIENT */
3638+
if (-1 != portId)
3639+
{
3640+
LOGINFO("HDMI ARC port ID HdmiArcPortID[%d] on retry count[%d]", portId, retryCount);
3641+
HdmiArcPortID = portId;
3642+
break;
3643+
}
3644+
else
3645+
{
3646+
LOGWARN("getHDMIARCPortId failed for retry count[%d]", retryCount);
3647+
}
3648+
} while(retryCount++ <= 6);
3649+
}
3650+
3651+
#endif /* IO_HCEC_ENABLE_IARM */
3652+
35893653

35903654
void HdmiCecSink::getCecVersion()
35913655
{

HdmiCecSink/HdmiCecSink.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ namespace WPEFramework {
484484
// As the registration/unregistration of notifications is realized by the class PluginHost::JSONRPC,
485485
// this class exposes a public method called, Notify(), using this methods, all subscribed clients
486486
// will receive a JSONRPC message as a notification, in case this method is called.
487-
class HdmiCecSink : public PluginHost::IPlugin, public PluginHost::JSONRPC, device::Host::IHdmiInEvents {
487+
class HdmiCecSink : public PluginHost::IPlugin, public PluginHost::JSONRPC, public device::Host::IHdmiInEvents {
488488

489489
enum {
490490
POLL_THREAD_STATE_NONE,
@@ -589,6 +589,13 @@ namespace WPEFramework {
589589
END_INTERFACE_MAP
590590

591591
private:
592+
template <typename T>
593+
T* baseInterface()
594+
{
595+
static_assert(std::is_base_of<T, HdmiCecSink>(), "base type mismatch");
596+
return static_cast<T*>(this);
597+
}
598+
592599
class PowerManagerNotification : public Exchange::IPowerManager::IModeChangedNotification {
593600
private:
594601
PowerManagerNotification(const PowerManagerNotification&) = delete;

HdmiCecSource/HdmiCecSourceImplementation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ namespace WPEFramework
393393
#ifdef IO_HCEC_ENABLE_IARM
394394
DeinitializeIARM();
395395
#else
396-
device::Host::getInstance().UnRegister(this);
396+
device::Host::getInstance().UnRegister(baseInterface<device::Host::IDisplayDeviceEvents>());
397397
#endif /* IO_HCEC_ENABLE_IARM */
398398

399399
}
@@ -427,7 +427,7 @@ namespace WPEFramework
427427
device::Manager::Initialize();
428428

429429
#ifndef IO_HCEC_ENABLE_IARM
430-
device::Host::getInstance().Register(this, "WPE[HdmiCecSource]");
430+
device::Host::getInstance().Register(baseInterface<device::Host::IDisplayDeviceEvents>(), "WPE[HdmiCecSource]");
431431
#endif /* IO_HCEC_ENABLE_IARM */
432432

433433
std::string strVideoPort = device::Host::getInstance().getDefaultVideoPortName();

HdmiCecSource/HdmiCecSourceImplementation.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ namespace WPEFramework {
172172
// As the registration/unregistration of notifications is realized by the class PluginHost::JSONRPC,
173173
// this class exposes a public method called, Notify(), using this methods, all subscribed clients
174174
// will receive a JSONRPC message as a notification, in case this method is called.
175-
class HdmiCecSourceImplementation : public Exchange::IHdmiCecSource, device::Host::IDisplayDeviceEvents {
175+
class HdmiCecSourceImplementation : public Exchange::IHdmiCecSource, public device::Host::IDisplayDeviceEvents {
176176
enum {
177177
VOLUME_UP = 0x41,
178178
VOLUME_DOWN = 0x42,
@@ -229,6 +229,13 @@ namespace WPEFramework {
229229

230230

231231
private:
232+
template <typename T>
233+
T* baseInterface()
234+
{
235+
static_assert(std::is_base_of<T, HdmiCecSourceImplementation>(), "base type mismatch");
236+
return static_cast<T*>(this);
237+
}
238+
232239
class PowerManagerNotification : public Exchange::IPowerManager::IModeChangedNotification {
233240
private:
234241
PowerManagerNotification(const PowerManagerNotification&) = delete;

0 commit comments

Comments
 (0)