42 #include "libIBusDaemon.h"
48 #include "exception.hpp"
50 #include "ccec/Util.hpp"
52 #include "ccec/Host.hpp"
53 #include "ccec/host/RDK.hpp"
55 #include "safec_lib.h"
56 #define MAX_LENGTH_OF_OSD_NAME 15
66 static int powerState;
69 static pthread_mutex_t devStatMutex = PTHREAD_MUTEX_INITIALIZER;
76 static char osdName[14+1] =
"SettopBox";
80 static IARM_Result_t _SetDevMgrStatus(
void *arg);
81 static IARM_Result_t _SetOSDName(
void *arg);
82 static IARM_Result_t _GetOSDName(
void *arg);
83 static IARM_Result_t _GetDevStatus(
void *arg);
86 static void _hdmiEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
87 static void _powerEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
110 CCEC_LOG( LOG_WARN,
"RDKHost::CECHost_Init Initialising DeviceStatus Cache \n");
111 pthread_mutex_lock(&devStatMutex);
112 for(
int i=0;i<14;i++)
114 _deviceStatus[i].logicalAddress = i;
115 _deviceStatus[i].powerState = 1;
116 _deviceStatus[i].isConnected = 0;
117 strncpy(_deviceStatus[i].osdName,
"",MAX_LENGTH_OF_OSD_NAME);
119 pthread_mutex_unlock(&devStatMutex);
125 return CECHost_ERR_NONE;
141 return CECHost_ERR_NONE;
156 return CECHost_ERR_NONE;
174 CCEC_LOG( LOG_DEBUG,
"CECHost_GetHdmiOuputPhysicalAddress entering\r\n");
179 CCEC_LOG( LOG_WARN,
"Geting connected PHY %d %d %d %d\r\n", *byte0, *byte1, *byte2, *byte3);
182 return CECHost_ERR_STATE;
186 CCEC_LOG( LOG_EXP,
"exception thrown %s\r\n", e.
what());
187 return CECHost_ERR_HOST;
190 return CECHost_ERR_NONE;
205 CCEC_LOG( LOG_DEBUG,
"CECHost_IsHdmiOutputConnected entering\r\n");
217 return CECHost_ERR_HOST;
220 return CECHost_ERR_NONE;
235 param.
curState = IARM_BUS_PWRMGR_POWERSTATE_ON;
237 int isPowerOn = ((ret == IARM_RESULT_SUCCESS) && (param.curState == IARM_BUS_PWRMGR_POWERSTATE_ON));
238 *state = isPowerOn ? CECHost_POWERSTATE_ON : CECHost_POWERSTATE_STANDBY;
240 CCEC_LOG( LOG_WARN,
"CECHost_GetPowerState has state %d\r\n", *state);
241 return ret == IARM_RESULT_SUCCESS ? CECHost_ERR_NONE : CECHost_ERR_HOST;
257 memset(&eventData,0,
sizeof(eventData));
258 IARM_Result_t ret = IARM_RESULT_SUCCESS;
259 pthread_mutex_lock(&devStatMutex);
260 if (devices->statusType == CECHost_POWER_STATUS)
262 if( _deviceStatus[logicalAddress].powerState != devices->data.powerState)
264 _deviceStatus[logicalAddress].powerState = devices->data.powerState;
265 eventData.logicalAddress = logicalAddress;
266 eventData.changedStatus = IARM_BUS_CECHost_POWER_STATUS;
267 eventData.data.powerState = devices->data.powerState;
268 CCEC_LOG( LOG_WARN,
"RDKHost BroadcastingChangedPowerStatus on Iarm Bus \n");
269 ret =
IARM_Bus_BroadcastEvent(IARM_BUS_CECHOST_NAME,(IARM_EventId_t)IARM_BUS_CECHost_EVENT_DEVICESTATUSCHANGE,(
void *)&eventData,
sizeof(eventData));
272 else if (devices->statusType == CECHost_OSD_NAME)
274 if( 0 != strncmp(_deviceStatus[logicalAddress].osdName,(
const char *)devices->data.osdName,MAX_LENGTH_OF_OSD_NAME))
276 memset(_deviceStatus[logicalAddress].osdName,
'\0',MAX_LENGTH_OF_OSD_NAME);
277 strncpy(_deviceStatus[logicalAddress].osdName,(
const char *)devices->data.osdName,MAX_LENGTH_OF_OSD_NAME-1);
278 eventData.logicalAddress = logicalAddress;
279 eventData.changedStatus = IARM_BUS_CECHost_OSD_NAME;
280 memset(eventData.data.osdName,
'\0',MAX_LENGTH_OF_OSD_NAME);
281 strncpy(eventData.data.osdName,(
const char *)devices->data.osdName,MAX_LENGTH_OF_OSD_NAME-1);
282 CCEC_LOG( LOG_DEBUG,
"RDKHost BroadcastingChangedOsdNameStatus on Iarm Bus \n");
283 ret =
IARM_Bus_BroadcastEvent(IARM_BUS_CECHOST_NAME,(IARM_EventId_t)IARM_BUS_CECHost_EVENT_DEVICESTATUSCHANGE,(
void *)&eventData,
sizeof(eventData));
286 else if (devices->statusType == CECHost_CONNECTED_STATUS)
288 if( _deviceStatus[logicalAddress].isConnected != devices->data.isConnected)
290 _deviceStatus[logicalAddress].isConnected = devices->data.isConnected;
291 if( !devices->data.isConnected)
293 _deviceStatus[logicalAddress].powerState = 1;
294 strncpy(_deviceStatus[logicalAddress].osdName,
"",MAX_LENGTH_OF_OSD_NAME);
296 eventData.logicalAddress = logicalAddress;
297 eventData.changedStatus = IARM_BUS_CECHost_CONNECT_STATUS;
298 eventData.data.isConnected = devices->data.isConnected;
299 CCEC_LOG( LOG_DEBUG,
"RDKHost BroadcastingChanged ConnectStatus on Iarm Bus for %d \n",logicalAddress);
300 ret =
IARM_Bus_BroadcastEvent(IARM_BUS_CECHOST_NAME,(IARM_EventId_t)IARM_BUS_CECHost_EVENT_DEVICESTATUSCHANGE,(
void *)&eventData,
sizeof(eventData));
307 pthread_mutex_unlock(&devStatMutex);
308 return ret == IARM_RESULT_SUCCESS ? CECHost_ERR_NONE : CECHost_ERR_HOST;
322 param.
newState = ((state == CECHost_POWERSTATE_ON) ? IARM_BUS_PWRMGR_POWERSTATE_ON :IARM_BUS_PWRMGR_POWERSTATE_STANDBY);
324 return ret == IARM_RESULT_SUCCESS ? CECHost_ERR_NONE : CECHost_ERR_HOST;
339 size_t buf_size= *len;
340 if (!buf || !len || *len == 0) {
341 return CECHost_ERR_INVALID;
344 size_t nameLen = strlen(osdName);
345 if (*len > nameLen) *len = nameLen;
346 MEMCPY_S((
char *)buf,buf_size+1, (
char *)osdName, *len);
347 return CECHost_ERR_NONE;
366 *active = (powerState == CECHost_POWERSTATE_ON);
367 return CECHost_ERR_NONE;
373 IARM_Bus_CommonAPI_PowerPreChange_Param_t *param = (IARM_Bus_CommonAPI_PowerPreChange_Param_t *)arg;
376 int curState = (param->curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? CECHost_POWERSTATE_ON : CECHost_POWERSTATE_STANDBY;
377 int newState = (param->newState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? CECHost_POWERSTATE_ON : CECHost_POWERSTATE_STANDBY;
378 CCEC_LOG( LOG_DEBUG,
"RDKHost::_PowerPreChange() Old State %d, New State: %d", curState , newState);
380 return IARM_RESULT_SUCCESS;
383 static IARM_Result_t _SetDevMgrStatus(
void *arg)
385 bool opStatus =
false;
386 IARM_Result_t ret = IARM_RESULT_SUCCESS;
389 CCEC_LOG( LOG_DEBUG,
"RDKHost::_SetDevMgrStatus() Dev Manager status set by client to : %s \n", (param->status)?
"true":
"false");
391 if(hostCb.devMgrStatusCb){
392 hostCb.devMgrStatusCb(param->status, &opStatus);
395 opParam.status = opStatus;
397 ret =
IARM_Bus_BroadcastEvent( IARM_BUS_CECHOST_NAME, (IARM_EventId_t)IARM_BUS_CECHost_EVENT_DEVMANAGERSTATUS, (
void *)&opParam,
sizeof(opParam));
398 CCEC_LOG( LOG_DEBUG,
"RDKHost::_SetDevMgrStatus() IARM Broadcast status : %s \n", (ret == IARM_RESULT_SUCCESS) ?
"Success" :
"Failure");
400 return IARM_RESULT_SUCCESS;
403 static IARM_Result_t _SetOSDName(
void *arg)
406 CCEC_LOG( LOG_DEBUG,
"RDKHost::_SetOSDName() : %s::%s", param->
name, osdName);
408 if (strncmp(osdName, (
char *)param->
name,
sizeof(param->
name)) != 0) {
411 strncpy((
char *)osdName, (
const char *) param->
name,
sizeof(osdName) - 1);
413 hostCb.osdCb((uint8_t *)osdName, strlen(osdName));
416 return IARM_RESULT_SUCCESS;
419 static IARM_Result_t _GetDevStatus(
void *arg)
421 pthread_mutex_lock(&devStatMutex);
427 MEMCPY_S(param->devices,
sizeof(param->devices),_deviceStatus,
sizeof(_deviceStatus));
428 CCEC_LOG( LOG_DEBUG,
"RDKHOST::_GetDevStatus() success \n");
429 pthread_mutex_unlock(&devStatMutex);
430 return IARM_RESULT_SUCCESS;
433 pthread_mutex_unlock(&devStatMutex);
434 return IARM_RESULT_INVALID_PARAM;
437 static IARM_Result_t _GetOSDName(
void *arg)
442 if(NULL != param->
name)
444 MEMCPY_S(param->
name,
sizeof(param->
name), osdName,
sizeof(osdName));
445 CCEC_LOG( LOG_DEBUG,
"RDKHost::_GetOSDName() : %s::%s\n",param->
name,osdName);
446 return IARM_RESULT_SUCCESS;
449 return IARM_RESULT_INVALID_PARAM;
452 static void _hdmiEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
457 int hdmi_hotplug_event = eventData->data.hdmi_hpd.event;
458 CCEC_LOG( LOG_DEBUG,
"RDKHost::_hdmiEventHandler: IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG event data:%d \r\n", hdmi_hotplug_event);
459 if (hostCb.hotplugCb)
462 CECHost_HDMI_CONNECTED : CECHost_HDMI_DISCONNECTED));
466 CCEC_LOG( LOG_DEBUG,
"RDKHost::_hdmiEventHandler: Clearing device status on receiving disconnect event\r\n");
467 pthread_mutex_lock(&devStatMutex);
468 for(
int i=0;i<14;i++)
470 _deviceStatus[i].logicalAddress = i;
471 _deviceStatus[i].powerState = 1;
472 _deviceStatus[i].isConnected = 0;
473 strncpy(_deviceStatus[i].osdName,
"",MAX_LENGTH_OF_OSD_NAME);
475 pthread_mutex_unlock(&devStatMutex);
483 static void _powerEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
490 int curState = (eventData->data.state.curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? CECHost_POWERSTATE_ON : CECHost_POWERSTATE_STANDBY;
491 int newState = (eventData->data.state.newState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? CECHost_POWERSTATE_ON : CECHost_POWERSTATE_STANDBY;
493 CCEC_LOG( LOG_DEBUG,
"RDKHost::_powerEventHandler() Old State %d, New State: %d", curState , newState);
494 if (hostCb.pwrStateCb) hostCb.pwrStateCb(curState, newState);
495 powerState = newState;