35 #include "illegalArgumentException.hpp"
36 #include "exception.hpp"
39 #include "safec_lib.h"
41 #define DEV_NAME "HDMI"
42 #define BASE_NAME "Device.Services.STBService.1.Components.HDMI"
43 #define UPDATE_FORMAT_STRING "%s.%d.%s"
46 #define STATUS_STRING "Status"
47 #define ENABLE_STRING "Enable"
48 #define RES_MODE_STRING "ResolutionMode"
49 #define RES_VAL_STRING "ResolutionValue"
50 #define NAME_STRING "Name"
51 #define ENABLED_STRING "Enabled"
52 #define DISABLED_STRING "Disabled"
76 char hostIf_STBServiceHDMI::dsHDMIResolutionMode[10] = HDMI_RESOLUTION_MODE_MANUAL;
77 GHashTable* hostIf_STBServiceHDMI::ifHash = NULL;
78 GMutex* hostIf_STBServiceHDMI::m_mutex = NULL;
100 ifHash = g_hash_table_new(NULL,NULL);
108 std::string videoPortName = strVideoPort.substr(0, strVideoPort.size()-1);
110 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
114 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught device::IllegalArgumentException, not able create STB service %s Interface instance %d..\n", DEV_NAME, dev_id);
118 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create STB service %s Interface instance %d..\n", DEV_NAME, dev_id);
122 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"Caught dsError_t %d, not able create STB service %s Interface instance %d..\n", e, DEV_NAME, dev_id);
126 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught device::Exception %d \"%s\", not able create STB service %s Interface instance %d..\n", e.
getCode(), e.
getMessage().c_str(), DEV_NAME, dev_id);
132 GList* hostIf_STBServiceHDMI::getAllInstances()
135 return g_hash_table_get_keys(ifHash);
143 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
148 void hostIf_STBServiceHDMI::closeAllInstances()
152 GList* tmp_list = g_hash_table_get_values (ifHash);
157 tmp_list = tmp_list->next;
163 void hostIf_STBServiceHDMI::getLock()
167 m_mutex = g_mutex_new();
169 g_mutex_lock(m_mutex);
172 void hostIf_STBServiceHDMI::releaseLock()
174 g_mutex_unlock(m_mutex);
188 backupEnable =
false;
189 rc=strcpy_s(backupStatus,
sizeof(backupStatus),
" ");
194 rc=strcpy_s(backupResolutionValue,
sizeof(backupResolutionValue),
" ");
199 rc=strcpy_s(backupName,
sizeof(backupName),
" ");
205 bCalledEnable =
false;
206 bCalledStatus =
false;
207 bCalledResolutionValue =
false;
213 hostIf_STBServiceHDMI::~hostIf_STBServiceHDMI() {
215 delete displayDevice;
232 int ret = NOT_HANDLED;
233 if(strcasecmp(paramName, RES_MODE_STRING) == 0)
235 ret = setHDMIResolutionMode(stMsgData->
paramValue);
237 else if(strcasecmp(paramName, RES_VAL_STRING) == 0)
239 if(0 == strcasecmp(getHDMIResolutionMode(), HDMI_RESOLUTION_MODE_MANUAL))
241 ret = setResolution(stMsgData);
245 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Setting the ResolutionValue has no effect because the ResolutionMode is \"Auto\".\n");
249 else if(strcasecmp(paramName, ENABLE_STRING) == 0)
251 ret = setEnableVideoPort(stMsgData);
272 int ret = NOT_HANDLED;
273 if(strcasecmp(paramName, ENABLE_STRING) == 0)
275 ret = getEnable(stMsgData);
277 else if(strcasecmp(paramName, STATUS_STRING) == 0)
279 ret = getStatus(stMsgData);
281 else if(strcasecmp(paramName, NAME_STRING) == 0)
283 ret = getName(stMsgData);
285 else if(strcasecmp(paramName, RES_MODE_STRING) == 0)
293 else if(strcasecmp(paramName, RES_VAL_STRING) == 0)
295 ret = getResolutionValue(stMsgData);
297 else if(strncasecmp(paramName, DISPLAYDEVICE_OBJECT_NAME, strlen(DISPLAYDEVICE_OBJECT_NAME)) == 0)
299 ret = displayDevice->
handleGetMsg(paramName+strlen(DISPLAYDEVICE_OBJECT_NAME), stMsgData);
313 displayDevice->
doUpdates(BASE_NAME, mUpdateCallback);
316 char tmp_buff[PARAM_LEN];
318 memset(&msgData,0,
sizeof(msgData));
319 memset(tmp_buff,0,PARAM_LEN);
322 getResolutionValue(&msgData,&bChanged);
325 snprintf(tmp_buff, PARAM_LEN, UPDATE_FORMAT_STRING, BASE_NAME, dev_id, RES_VAL_STRING);
331 memset(&msgData,0,
sizeof(msgData));
332 memset(tmp_buff,0,PARAM_LEN);
335 getEnable(&msgData,&bChanged);
338 snprintf(tmp_buff, PARAM_LEN, UPDATE_FORMAT_STRING, BASE_NAME, dev_id, ENABLE_STRING);
344 memset(&msgData,0,
sizeof(msgData));
345 memset(tmp_buff,0,PARAM_LEN);
348 getStatus(&msgData,&bChanged);
351 snprintf(tmp_buff, PARAM_LEN, UPDATE_FORMAT_STRING, BASE_NAME, dev_id, STATUS_STRING);
357 memset(&msgData,0,
sizeof(msgData));
358 memset(tmp_buff,0,PARAM_LEN);
361 getName(&msgData,&bChanged);
364 snprintf(tmp_buff, PARAM_LEN, UPDATE_FORMAT_STRING, BASE_NAME, dev_id, NAME_STRING);
384 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] (): Value: %s \n",__FUNCTION__, stMsgData->
paramValue);
386 char inResolution[MAX_RESOLUTION_LENGTH] = {
'\0'};
387 char *bufPtr = NULL, *hzPtr = NULL, *interlacedPtr = NULL;
388 char *pixelName = NULL, *frameRateName = NULL;
389 bool isInterlaced =
true;
391 strncpy(inResolution, stMsgData->
paramValue,
sizeof(inResolution)-1);
392 inResolution[
sizeof(inResolution)-1] =
'\0';
393 hzPtr = strcasestr(inResolution, (
char*)
"Hz");
397 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s] (): Missing Hz value in Resolution\n",__FUNCTION__);
402 strncpy(hzPtr,
"Hz", 3);
405 interlacedPtr = strcasestr(inResolution, (
char*)
"p");
408 isInterlaced =
false;
409 *interlacedPtr =
'p';
413 interlacedPtr = strcasestr(inResolution, (
char*)
"i");
417 *interlacedPtr =
'i';
421 bufPtr = inResolution;
427 pixelName = strsep (&bufPtr,
"i");
431 pixelName = strsep (&bufPtr,
"p");
437 pixelName = strsep (&bufPtr,
"/");
440 frameRateName = strsep (&bufPtr,
"Hz");
442 if (!pixelName || !frameRateName)
444 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s] Null Pointers caught \n",__FUNCTION__);
448 static int pixelResolArrSize =
sizeof( dsVideoPixelResolutionMapper ) /
sizeof(
EnumStringMapper );
449 int pixelId = getEnumFromString(dsVideoPixelResolutionMapper, pixelResolArrSize, pixelName);
452 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s] Error in PixelResolution value: %s\n",__FUNCTION__, pixelName);
456 static int frameRateArrSize =
sizeof( dsVideoFrameRateMapper ) /
sizeof(
EnumStringMapper );
457 int frameRateId = getEnumFromString(dsVideoFrameRateMapper, frameRateArrSize, frameRateName);
460 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s] Error in FrameRate value: %s\n",__FUNCTION__, frameRateName);
464 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] pixelId = %d frameRateId = %d interlaced = %s\n", __FUNCTION__, pixelId, frameRateId, isInterlaced?
"true":
"false");
465 size_t numResolutions =
dsUTL_DIM(kResolutions);
466 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] (): numResolutions = %d\n",__FUNCTION__, numResolutions);
467 for (
size_t i = 0; i < numResolutions; i++) {
471 (resolution->
frameRate == frameRateId) &&
472 (interlacedPtr?(resolution->
interlaced == isInterlaced):
true) )
479 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s] (): Out of range values entered\n",__FUNCTION__);
481 catch (
const std::exception e) {
482 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s] Exception\r\n",__FUNCTION__);
499 int hostIf_STBServiceHDMI::getResolutionValue(
HOSTIF_MsgData_t *stMsgData,
bool *pChanged)
504 snprintf(stMsgData->
paramValue, PARAM_LEN,
"%s%s/%sHz",
509 if(bCalledResolutionValue && pChanged && strcmp(backupResolutionValue, stMsgData->
paramValue))
513 bCalledResolutionValue =
true;
514 strncpy(backupResolutionValue, stMsgData->
paramValue, _BUF_LEN_16-1);
515 backupResolutionValue[_BUF_LEN_16-1] =
'\0';
517 stMsgData->
paramtype = hostIf_StringType;
519 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] getHDMIResolution(): Value: %s\n",__FUNCTION__, stMsgData->
paramValue);
521 catch (
const std::exception e) {
522 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s] Exception\r\n",__FUNCTION__);
539 int hostIf_STBServiceHDMI::setEnableVideoPort(
const HOSTIF_MsgData_t *stMsgData)
542 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] In setEnableVideoPort(): Value: %s \n",__FUNCTION__, stMsgData->
paramValue);
551 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s] HDMI Display is NOT connected\r\n",__FUNCTION__);
555 catch (
const std::exception e) {
556 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s] Exception\r\n",__FUNCTION__);
576 int hostIf_STBServiceHDMI::getEnable(
HOSTIF_MsgData_t *stMsgData,
bool *pChanged)
581 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] In getHDMIEnable(): vPort.isEnabled(): %d \n",__FUNCTION__, vPort.
isEnabled());
587 stMsgData->
paramtype = hostIf_BooleanType;
592 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s] HDMI Display is NOT connected\r\n",__FUNCTION__);
594 if(bCalledEnable && pChanged && (backupEnable != get_boolean(stMsgData->
paramValue)))
598 bCalledEnable =
true;
599 backupEnable = get_boolean(stMsgData->
paramValue);
601 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] In getHDMIEnable(): Value: %s \n",__FUNCTION__, stMsgData->
paramValue);
603 catch (
const std::exception e) {
604 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"[%s] Exception\r\n",__FUNCTION__);
622 int hostIf_STBServiceHDMI::getStatus(
HOSTIF_MsgData_t *stMsgData,
bool *pChanged)
624 int ret = getEnable(stMsgData);
629 strncpy(stMsgData->
paramValue, ENABLED_STRING, PARAM_LEN);
633 strncpy(stMsgData->
paramValue, DISABLED_STRING, PARAM_LEN);
638 if(bCalledStatus && pChanged && strcmp(backupStatus, stMsgData->
paramValue))
642 bCalledStatus =
true;
643 strncpy(backupStatus, stMsgData->
paramValue, _BUF_LEN_16-1);
644 backupStatus[_BUF_LEN_16-1] =
'\0';
661 int hostIf_STBServiceHDMI::getName(
HOSTIF_MsgData_t *stMsgData,
bool *pChanged)
664 if(bCalledName && pChanged && strcmp(backupName, stMsgData->
paramValue))
669 strncpy(backupName, stMsgData->
paramValue, _BUF_LEN_256-1);
670 backupName[_BUF_LEN_256-1] =
'\0';
671 stMsgData->
paramtype = hostIf_StringType;
685 int hostIf_STBServiceHDMI::setHDMIResolutionMode(
const char* value)
687 if((0 != strcasecmp(value, HDMI_RESOLUTION_MODE_AUTO)) &&
688 (0 != strcasecmp(value, HDMI_RESOLUTION_MODE_MANUAL)))
690 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s]Failed to set HDMI ResolutionMode [%s]. Expected input values: [Auto|Manual] \n", __FUNCTION__, value);
694 strncpy(dsHDMIResolutionMode,value,
sizeof(dsHDMIResolutionMode));
695 dsHDMIResolutionMode[
sizeof(dsHDMIResolutionMode)-1] =
'\0';
696 if(0 == strcasecmp(value, HDMI_RESOLUTION_MODE_AUTO))
699 strncpy(msgData.
paramValue,HDMI_RESOLUTION_VALUE_DEFAULT, PARAM_LEN);
702 setResolution(&msgData);
707 const char* hostIf_STBServiceHDMI::getHDMIResolutionMode()
709 return dsHDMIResolutionMode;