RDK Documentation (Open Sourced RDK Components)
pwrMgr.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 
22 /**
23 * @defgroup iarmmgrs
24 * @{
25 * @defgroup power
26 * @{
27 **/
28 
29 
30 #include <stdio.h>
31 #include <fcntl.h>
32 #include <errno.h>
33 #include <stdint.h>
34 #include <unistd.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <stdbool.h>
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 #ifdef __cplusplus
43 }
44 #endif
45 
46 #ifdef OFFLINE_MAINT_REBOOT
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <sys/types.h>
51 #include <ifaddrs.h>
52 #include <sys/ioctl.h>
53 #include <net/if.h>
54 #endif
55 
56 #include <sys/stat.h>
57 #include "iarmUtil.h"
58 #include "irMgr.h"
59 #include "sysMgr.h"
60 #include "dsMgr.h"
61 #include "comcastIrKeyCodes.h"
62 #include "libIBus.h"
63 #include "plat_power.h"
64 #include "pwrMgrInternal.h"
65 #include <pthread.h>
66 #include "libIBusDaemon.h"
67 #include "manager.hpp"
68 #include "host.hpp"
69 #include "list.hpp"
70 #include "sleepMode.hpp"
71 #include "pwrlogger.h"
72 #include "frontPanelIndicator.hpp"
73 #include "resetModes.h"
74 #include "rfcapi.h"
75 #include "iarmcec.h"
76 #include "deepSleepMgr.h"
77 #include "productTraits.h"
78 #include "exception.hpp"
79 
80 /* For glib APIs*/
81 #include <glib.h>
82 
83 #ifndef NO_RF4CE
84 static void _speechEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
85 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
86 #include "ctrlm_ipc.h"
87 #include "ctrlm_ipc_rcu.h"
88 static void _ctrlmMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
89 #else
90 #ifdef USE_UNIFIED_RF4CE_MGR_API_4
91 #include "vrexMgrApi.h"
92 #else
93 #include "vrexMgr.h"
94 #endif /* USE_UNIFIED_RF4CE_MGR_API_4 */
95 #ifdef RF4CE_GENMSO_API
96 #include "rf4ceMgr.h"
97 static void _rfMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
98 #elif defined(RF4CE_API)
99 #include "rf4ceMgr.h"
100 static void _rf4ceMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
101 #elif defined(RF4CE_GPMSO_API)
102 #include "rf4ceMgr.h"
103 static void _gpMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
104 #else
105 #warning "No RF4CE API defined"
106 #endif
107 #endif /* USE_UNIFIED_CONTROL_MGR_API_1 */
108 #endif /* NO_RF4CE */
109 
110 #define PADDING_SIZE 32
111 #define _UIMGR_SETTINGS_MAGIC 0xFEBEEFAC
112 /*LED settings*/
113 typedef struct _PWRMgr_LED_Settings_t{
114  unsigned int brightness;
115  unsigned int color;
117 
118 typedef struct _PWRMgr_Settings_t{
119  uint32_t magic;
120  uint32_t version;
121  uint32_t length;
122  volatile IARM_Bus_PWRMgr_PowerState_t powerState;
123  PWRMgr_LED_Settings_t ledSettings;
124  #ifdef ENABLE_DEEP_SLEEP
125  uint32_t deep_sleep_timeout;
126  #endif
127  #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
128  bool nwStandbyMode;
129  #endif
130  char padding[PADDING_SIZE];
132 
133 typedef enum _UIDev_PowerState_t {
134  UIDEV_POWERSTATE_OFF,
135  UIDEV_POWERSTATE_STANDBY,
136  UIDEV_POWERSTATE_ON,
137  UIDEV_POWERSTATE_UNKNOWN
138 } UIDev_PowerState_t;
139 
140 typedef struct _UIMgr_Settings_t{
141  uint32_t magic;
142  uint32_t version;
143  uint32_t length;
144  UIDev_PowerState_t powerState;
145  char padding[PADDING_SIZE];
147 
148 static PWRMgr_Settings_t m_settings = {0};
149 static const char *m_settingsFile = NULL;
150 static bool isCecLocalLogicEnabled = false;
151 
152 #define MAX_NUM_VIDEO_PORTS 5
153 typedef struct{
155  bool isEnabled;
157 static PWRMgr_Standby_Video_State_t g_standby_video_port_setting[MAX_NUM_VIDEO_PORTS];
158 static pwrMgrProductTraits::ux_controller * ux = nullptr;
159 
160 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
161 #ifndef POWER_KEY_SENSITIVITY
162 #define POWER_KEY_SENSITIVITY 500
163 #endif
164 static struct timeval powerKeyIntervals[] = {
165  /*
166  * [0] is timestamp of DOWN
167  * [1] is timestamp of UP
168  */
169  {0, 0}, {0, 0}
170 };
171 #define PWRMGR_SET_POWER_KEYDOWN_TM() do\
172 {\
173  if (POWER_KEY_SENSITIVITY) {\
174  struct timeval __tv;\
175  gettimeofday(&__tv, NULL);\
176  printf("[POWERKEY-DOWN][%ld\[%d]\r\n", __tv.tv_sec, __tv.tv_usec);\
177  fflush(stdout);\
178  powerKeyIntervals[0] = (__tv);\
179  powerKeyIntervals[1].tv_sec = 0;\
180  powerKeyIntervals[1].tv_usec = 0;\
181  }\
182 } while(0)
183 
184 #define PWRMGR_SET_POWER_KEYUP_TM() do\
185 {\
186  if (POWER_KEY_SENSITIVITY && powerKeyIntervals[0].tv_sec != 0) {\
187  struct timeval __tv;\
188  gettimeofday(&__tv, NULL);\
189  printf("[POWERKEY-UP ][%ld\[%d]\r\n", __tv.tv_sec, __tv.tv_usec);\
190  fflush(stdout);\
191  powerKeyIntervals[1] = (__tv);\
192  }\
193  else {\
194  }\
195 } while(0)\
196 
197 #define TIMEVAL_DIFF(t2,t1) ((int)(((((int)(t2.tv_sec - t1.tv_sec)) - 1) * 1000) + (((1000*1000 + t2.tv_usec) - t1.tv_usec)/1000)))
198 #define PWRMGR_GET_POWER_KEY_INTERVAL() \
199  (((powerKeyIntervals[1].tv_sec) && (powerKeyIntervals[1].tv_sec >= powerKeyIntervals[0].tv_sec)) ?\
200  (TIMEVAL_DIFF(powerKeyIntervals[1], powerKeyIntervals[0])) :\
201  (POWER_KEY_SENSITIVITY))
202 
203 static volatile IARM_Bus_PWRMgr_PowerState_t transitionState;
204 static volatile IARM_Bus_PWRMgr_PowerState_t targetState;
205 
206 static pthread_cond_t powerStateCond = PTHREAD_COND_INITIALIZER;
207 static pthread_mutex_t powerStateMutex = PTHREAD_MUTEX_INITIALIZER;
208 static pthread_t asyncPowerThreadId = NULL;
209 
210 static void _SetPowerStateAsync(IARM_Bus_PWRMgr_PowerState_t curState, IARM_Bus_PWRMgr_PowerState_t newState);
211 #endif
212 static pthread_mutex_t wareHouseOpsMutex = PTHREAD_MUTEX_INITIALIZER;
213 static pthread_t asyncPowerWarehouseOpsThreadId = NULL;
214 
215 
216 static void _sleepModeChangeHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
217 static void _controlEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
218 static void _irEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
219 static void _systemStateChangeHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
220 static IARM_Result_t _SetPowerState(void *arg);
221 static IARM_Result_t _GetPowerState(void *arg);
222 static IARM_Result_t _WareHouseReset(void *arg);
223 static IARM_Result_t _WareHouseClear(void *arg);
224 static IARM_Result_t _ColdFactoryReset(void *);
225 static IARM_Result_t _FactoryReset(void *);
226 static IARM_Result_t _UserFactoryReset(void *);
227 static IARM_Result_t _GetPowerStateBeforeReboot(void *arg);
228 static IARM_Result_t _HandleReboot(void *arg);
229 #ifdef ENABLE_SET_WAKEUP_SRC_CONFIG
230 static IARM_Result_t _SetWakeupSrcConfig(void *arg);
231 #endif //ENABLE_SET_WAKEUP_SRC_CONFIG
232 static IARM_Result_t _handleDeepsleepTimeoutWakeup(void *arg);
233 static void handleDeepsleepTimeoutWakeup (void * arg);
234 static void* deepsleepTimeoutWakeupThread (void * arg);
235 
236 static int _InitSettings(const char *settingsFile);
237 static int _WriteSettings(const char *settingsFile);
238 static void _DumpSettings(const PWRMgr_Settings_t *pSettings);
239 
240 static int _SetLEDStatus(IARM_Bus_PWRMgr_PowerState_t state);
241 
242 int _SetAVPortsPowerState(IARM_Bus_PWRMgr_PowerState_t powerState);
243 static IARM_Bus_PWRMgr_PowerState_t _ConvertUIDevToIARMBusPowerState(UIDev_PowerState_t powerState);
244 static IARM_Result_t _SetStandbyVideoState(void *arg);
245 static IARM_Result_t _GetStandbyVideoState(void *arg);
246 static int ecm_connectivity_lost = 0;
248 time_t xre_timer; // Hack to fix DELIA-11393
249 static bool deepSleepWakeup = false;
250 extern void IARM_Bus_PWRMGR_RegisterSleepTimerAPIs(void *);
251 
252 /*EAS handling */
253 static IARM_Result_t _SysModeChange(void *arg);
254 static IARM_Bus_Daemon_SysMode_t isEASInProgress = IARM_BUS_SYS_MODE_NORMAL;
255 
256 /*pwrMgr Glib variables */
257 GMainLoop *pwrMgr_Gloop = NULL;
258 static gboolean heartbeatMsg(gpointer data);
259 std::string powerStateBeforeReboot_gc;
260 static IARM_Bus_PWRMgr_PowerState_t g_last_known_power_state = IARM_BUS_PWRMGR_POWERSTATE_ON;
261 #ifdef ENABLE_DEEP_SLEEP
262 
263  /* PwrMgr Static Functions for Deep SLeep feature */
264 
265  /* IARM RPC Handler to Set Deep Sleep Wakeup Timer */
266  static IARM_Result_t _SetDeepSleepTimeOut(void *arg);
267 
268  /* Gloop Wakeup Timer Handler */
269  static gboolean deep_sleep_wakeup_fn(gpointer data);
270 
271  /* Calculate Wakeup Time */
272  static uint32_t getWakeupTime();
273 
274  /* Gloop Handler to invoke deep sleep , if the box boots in deep sleep and timer expires.*/
275  static gboolean invoke_deep_sleep_on_bootup_timeout(gpointer data);
276 
277  /* Variables for Deep Sleep */
278  static uint32_t deep_sleep_wakeup_timeout_sec = 28800; //8*60*60 - 8 hours
279  static uint8_t IsWakeupTimerSet = 0;
280  static guint wakeup_event_src = 0;
281  static guint dsleep_bootup_event_src = 0;
282  static time_t timeAtDeepSleep = 0;
283 #endif
284 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
285  static bool nwStandbyMode_gs = false;
286 #endif
287 
288 #ifdef OFFLINE_MAINT_REBOOT
289 gint64 standby_time = 0;
290 static bool rfcUpdated = false;
291 static int standby_reboot_threshold = 86400*3;
292 static int force_reboot_threshold = 172800*3;
293 
294 #define MAX_RFC_LEN 15
295 
296 #define UPTIME_ABOVE_STANDBY_REBOOT(time) (time >= standby_reboot_threshold)
297 #define UPTIME_ABOVE_FORCE_REBOOT(time) (time >= force_reboot_threshold)
298 #define REBOOT_GRACE_INTERVAL(u, s) ((u - s) >= 900)
299 
300 #define STANDBY_REBOOT_ENABLE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StandbyReboot.Enable"
301 #define STANDBY_REBOOT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StandbyReboot.StandbyAutoReboot"
302 #define FORCE_REBOOT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StandbyReboot.ForceAutoReboot"
303 #endif
304 
305 static IARM_Result_t _SetNetworkStandbyMode(void *arg);
306 static IARM_Result_t _GetNetworkStandbyMode(void *arg);
307 
308 static void setPowerStateBeforeReboot (IARM_Bus_PWRMgr_PowerState_t powerState) {
309  switch (powerState) {
310  case IARM_BUS_PWRMGR_POWERSTATE_OFF:
311  powerStateBeforeReboot_gc = std::string ("OFF");
312  break;
313  case IARM_BUS_PWRMGR_POWERSTATE_STANDBY:
314  powerStateBeforeReboot_gc = std::string ("STANDBY");
315  break;
316  case IARM_BUS_PWRMGR_POWERSTATE_ON:
317  powerStateBeforeReboot_gc = std::string ("ON");
318  break;
319  case IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP:
320  powerStateBeforeReboot_gc = std::string ("LIGHT_SLEEP");
321  break;
322  case IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP:
323  powerStateBeforeReboot_gc = std::string ("DEEP_SLEEP");
324  break;
325  default :
326  powerStateBeforeReboot_gc = std::string ("UNKNOWN");
327  break;
328  }
329  printf ("[%s]:[%d] powerStateBeforeReboot: %s \n", __FUNCTION__, __LINE__, powerStateBeforeReboot_gc.c_str());
330 }
331 
332 static bool get_video_port_standby_setting(const char * port)
333 {
334  if(NULL == port)
335  {
336  __TIMESTAMP();LOG("Error! Port name is NULL!\n");
337  return false;
338  }
339  for(int i = 0; i < MAX_NUM_VIDEO_PORTS; i++)
340  {
341  if(0 == strncasecmp(port, g_standby_video_port_setting[i].port, PWRMGR_MAX_VIDEO_PORT_NAME_LENGTH))
342  {
343  return g_standby_video_port_setting[i].isEnabled;
344  }
345  }
346  return false; //Default setting: video port is disabled in standby mode
347 }
348 
349 IARM_Result_t PWRMgr_Start(int argc, char *argv[])
350 {
351  char *settingsFile = NULL;
352  time(&xre_timer); // Hack to fix DELIA-11393
353 
354  if (argc == 2) settingsFile = argv[1];
355 
356  setvbuf(stdout, NULL, _IOLBF, 0);
357  LOG("Entering [%s] - [%s] - disabling io redirect buf\r\n", __FUNCTION__,IARM_BUS_PWRMGR_NAME);
358 
359 #ifdef POWERMGR_PRODUCT_PROFILE_ID
360  if(true == pwrMgrProductTraits::ux_controller::initialize_ux_controller(POWERMGR_PRODUCT_PROFILE_ID))
361  {
362  ux = pwrMgrProductTraits::ux_controller::get_instance();
363  }
364 #endif
365  if(nullptr == ux)
366  {
367  LOG("pwrmgr product traits not supported.\n");
368  }
369 
370  PLAT_INIT();
371 
374 
375  /* LOG("Initing PwrMgr Settings START\r\n");*/
376  try {
378  }
379  catch (...){
380  LOG("Exception Caught during [device::Manager::Initialize]\r\n");
381  }
382 
383  _InitSettings(settingsFile);
384 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
385  transitionState = m_settings.powerState;
386  targetState = m_settings.powerState;
387 #endif
393  IARM_Bus_RegisterCall(IARM_BUS_PWRMGR_API_WareHouseClear, _WareHouseClear);
394 
398  IARM_Bus_RegisterCall(IARM_BUS_PWRMGR_API_SetStandbyVideoState, _SetStandbyVideoState);
399  IARM_Bus_RegisterCall(IARM_BUS_PWRMGR_API_GetStandbyVideoState, _GetStandbyVideoState);
400  #ifdef ENABLE_DEEP_SLEEP
403  #endif
404  IARM_Bus_RegisterCall(IARM_BUS_PWRMGR_API_SetNetworkStandbyMode, _SetNetworkStandbyMode);
405  IARM_Bus_RegisterCall(IARM_BUS_PWRMGR_API_GetNetworkStandbyMode, _GetNetworkStandbyMode);
406 
408  IARM_Bus_RegisterEventHandler(IARM_BUS_IRMGR_NAME, IARM_BUS_IRMGR_EVENT_CONTROL, _controlEventHandler);
409 
410  IARM_Bus_RegisterEventHandler(IARM_BUS_SYSMGR_NAME, IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE, _systemStateChangeHandler);
411  IARM_Bus_RegisterEventHandler(IARM_BUS_DSMGR_NAME,IARM_BUS_DSMGR_EVENT_SLEEP_MODE_CHANGED,_sleepModeChangeHandler);
412 
413 #ifndef NO_RF4CE
414 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
415  IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_SESSION_BEGIN, _speechEventHandler);
416  IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_SESSION_ABORT, _speechEventHandler);
417  IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_SESSION_SHORT, _speechEventHandler);
418  IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_KEY_GHOST, _ctrlmMessageHandler);
419 #else
420 #ifdef USE_UNIFIED_RF4CE_MGR_API_4
421  IARM_Bus_RegisterEventHandler(VREX_MGR_IARM_BUS_NAME, VREX_MGR_IARM_EVENT_VOICE_BEGIN, _speechEventHandler);
422  IARM_Bus_RegisterEventHandler(VREX_MGR_IARM_BUS_NAME, VREX_MGR_IARM_EVENT_VOICE_SESSION_ABORT, _speechEventHandler);
423  IARM_Bus_RegisterEventHandler(VREX_MGR_IARM_BUS_NAME, VREX_MGR_IARM_EVENT_VOICE_SESSION_SHORT, _speechEventHandler);
424 #else
425  IARM_Bus_RegisterEventHandler(IARM_BUS_VREXMGR_NAME, IARM_BUS_VREXMGR_EVENT_SPEECH, _speechEventHandler);
426 #endif /* USE_UNIFIED_RF4CE_MGR_API_4 */
427 #ifdef RF4CE_GENMSO_API
428  IARM_Bus_RegisterEventHandler(IARM_BUS_RFMGR_NAME,IARM_BUS_RFMGR_EVENT_MSG_IND,_rfMessageHandler);
429 #elif defined(RF4CE_API)
430  IARM_Bus_RegisterEventHandler(IARM_BUS_RF4CEMGR_NAME,IARM_BUS_RF4CEMGR_EVENT_MSG_IND,_rf4ceMessageHandler);
431 #elif defined(RF4CE_GPMSO_API)
432  IARM_Bus_RegisterEventHandler(IARM_BUS_GPMGR_NAME,IARM_BUS_GPMGR_EVENT_MSG_IND,_gpMessageHandler);
433 #else
434 #warning "No RF4CE API defined"
435 #endif
436 #endif /* NO_RF4CE */
437 #endif /* USE_UNIFIED_CONTROL_MGR_API_1 */
438 
439  initReset();
440 
441  /*Register EAS handler so that we can ensure audio settings for EAS */
442  IARM_Bus_RegisterCall(IARM_BUS_COMMON_API_SysModeChange,_SysModeChange);
444 
445 #ifdef ENABLE_SET_WAKEUP_SRC_CONFIG
446  IARM_Bus_RegisterCall(IARM_BUS_PWRMGR_API_SetWakeupSrcConfig, _SetWakeupSrcConfig);
447 #endif //ENABLE_SET_WAKEUP_SRC_CONFIG
448 
449 #ifdef ENABLE_THERMAL_PROTECTION
450  initializeThermalProtection();
451 #endif //ENABLE_THERMAL_PROTECTION
452 
453  /* Create Main loop for Power Manager */
454  pwrMgr_Gloop = g_main_loop_new ( NULL , FALSE );
455  if(pwrMgr_Gloop != NULL){
456  g_timeout_add_seconds (300 , heartbeatMsg , pwrMgr_Gloop);
457  }
458  else {
459  LOG("Fails to Create a main Loop for [%s] \r\n",IARM_BUS_PWRMGR_NAME);
460  }
461 
462  IARM_Bus_PWRMGR_RegisterSleepTimerAPIs(pwrMgr_Gloop);
463  RFC_ParamData_t rfcParam;
464  WDMP_STATUS status = getRFCParameter("TestComponent", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.CECLocalLogic.Enable", &rfcParam);
465  if(strncmp(rfcParam.value, "true",4) == 0)
466  {
467  isCecLocalLogicEnabled= true;
468  LOG("pwrMgr:RFC CEC Local Logic feature enabled \r\n");
469  }
470  char *rdk_deep_sleep_wakeup = getenv("RDK_DEEPSLEEP_WAKEUP_ON_POWER_BUTTON");
471  deepSleepWakeup = (rdk_deep_sleep_wakeup && atoi(rdk_deep_sleep_wakeup));
472 
473  try
474  {
475  m_sleepMode = static_cast<dsSleepMode_t>(device::Host::getInstance().getPreferredSleepMode().getId());
476  printf ("initial value m_sleepMode:%d \n", m_sleepMode);
477  }
478  catch(...)
479  {
480  LOG("PwrMgr: Exception coughht while processing getPreferredSleepMode\r\n");
481  }
482  return IARM_RESULT_SUCCESS;
483 }
484 
485 IARM_Result_t PWRMgr_Loop()
486 {
487 
488  /* Power Mgr loop */
489  if(pwrMgr_Gloop)
490  {
491  g_main_loop_run (pwrMgr_Gloop);
492  g_main_loop_unref(pwrMgr_Gloop);
493  }
494  return IARM_RESULT_SUCCESS;
495 }
496 
497 #ifdef OFFLINE_MAINT_REBOOT
498 bool isStandbyRebootEnabled()
499 {
500  RFC_ParamData_t rfcParam;
501  char* key = STANDBY_REBOOT_ENABLE;
502  if (WDMP_SUCCESS == getRFCParameter("PwrMgr", key, &rfcParam))
503  {
504  return (strncasecmp(rfcParam.value, "true", 4) == 0);
505  }
506 
507  return false;
508 }
509 
510 int getStandbyRebootValue(char* key)
511 {
512  RFC_ParamData_t param;
513  char rfcVal[MAX_RFC_LEN+1] = {0};
514  int len = 0;
515 
516  if (WDMP_SUCCESS == getRFCParameter("PwrMgr", key, &param))
517  {
518  len = strlen(param.value);
519  if (len > MAX_RFC_LEN)
520  {
521  len = MAX_RFC_LEN;
522  }
523 
524  if ( (param.value[0] == '"') && (param.value[len] == '"'))
525  {
526  strncpy (rfcVal, &param.value[1], len - 1);
527  rfcVal[len] = '\0';
528  }
529  else
530  {
531  strncpy (rfcVal, param.value, MAX_RFC_LEN-1);
532  rfcVal[len] = '\0';
533  }
534  return atoi(rfcVal);
535  }
536 
537  return -1;
538 }
539 
540 bool isOfflineMode()
541 {
542 #if 0
543  struct stat buf;
544  return ((stat("/tmp/addressaquired_ipv4", &buf) != 0)
545  && (stat("/tmp/addressaquired_ipv6", &buf) != 0));
546 #endif
547 
548  struct ifaddrs *ifAddr, *ifAddrIt;
549  bool offline = true;
550 
551  getifaddrs(&ifAddr);
552  for (ifAddrIt = ifAddr; ifAddrIt != NULL; ifAddrIt = ifAddrIt->ifa_next)
553  {
554  if (NULL != ifAddrIt->ifa_addr
555  && (!strcmp(ifAddrIt->ifa_name, "eth0:0") || !strcmp(ifAddrIt->ifa_name, "wlan0:0")))
556  {
557  LOG("ifa_name=%s sa_family=%s ifa_flags=0x%X\n",
558  ifAddrIt->ifa_name,
559  ifAddrIt->ifa_addr->sa_family == AF_INET? "AF_INET" : ifAddrIt->ifa_addr->sa_family == AF_INET6? "AF_INET6" : "None",
560  (ifAddrIt->ifa_flags & IFF_RUNNING) );
561  }
562 
563  if (NULL != ifAddrIt->ifa_addr
564  && (ifAddrIt->ifa_addr->sa_family == AF_INET || ifAddrIt->ifa_addr->sa_family == AF_INET6)
565  && (!strcmp(ifAddrIt->ifa_name, "eth0:0") || !strcmp(ifAddrIt->ifa_name, "wlan0:0"))
566  && (ifAddrIt->ifa_flags & IFF_RUNNING))
567  {
568  offline = false;
569  }
570  }
571  freeifaddrs(ifAddr);
572 
573  return offline;
574 }
575 
576 bool isInStandby()
577 {
578  PWRMgr_Settings_t *pSettings = &m_settings;
579  IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState;
580  LOG("%s PowerState = %d\n", __func__, curState);
581  return (curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY
582  || curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP);
583 }
584 
585 #endif
586 
587 
588 static gboolean heartbeatMsg(gpointer data)
589 {
590  time_t curr = 0;
591  time(&curr);
592  LOG("I-ARM POWER Mgr: HeartBeat at %s\r\n", ctime(&curr));
593 
594 #ifdef OFFLINE_MAINT_REBOOT
595  if (!rfcUpdated)
596  {
597  LOG("StandbyReboot.Enable = %s\n", isStandbyRebootEnabled() ? "true" : "false");
598 
599  standby_reboot_threshold = getStandbyRebootValue(STANDBY_REBOOT);
600  if (standby_reboot_threshold == -1)
601  {
602  standby_reboot_threshold = 86400*3;
603  }
604  LOG("StandbyReboot.StandbyAutoReboot = %d\n", standby_reboot_threshold);
605 
606  force_reboot_threshold = getStandbyRebootValue(FORCE_REBOOT);
607  if (force_reboot_threshold == -1)
608  {
609  force_reboot_threshold = 172800*3;
610  }
611  LOG("StandbyReboot.ForceAutoReboot = %d\n", force_reboot_threshold);
612  rfcUpdated = true;
613  }
614 
615  if (isStandbyRebootEnabled())
616  {
617  gint64 uptime = g_get_monotonic_time()/G_USEC_PER_SEC;
618  if (UPTIME_ABOVE_STANDBY_REBOOT(uptime))
619  {
620  if (REBOOT_GRACE_INTERVAL(uptime, standby_time) && isInStandby())
621  {
622  LOG("Going to reboot after %lld\n", uptime);
623  sleep(10);
624  system("sh /rebootNow.sh -s PwrMgr -r 'Standby Maintenance reboot' -o 'Standby Maintenance reboot'");
625  }
626 
627  if (UPTIME_ABOVE_FORCE_REBOOT(uptime))
628  {
629  LOG("Going to reboot after %lld\n", uptime);
630  sleep(10);
631  system("sh /rebootNow.sh -s PwrMgr -r 'Forced Maintenance reboot' -o 'Forced Maintenance reboot'");
632  }
633  }
634  }
635 #endif
636 
637  return TRUE;
638 }
639 
640 
641 IARM_Result_t PWRMgr_Stop(void)
642 {
643 
644  if(pwrMgr_Gloop)
645  {
646  g_main_loop_quit(pwrMgr_Gloop);
647  }
648 
649  try {
651  }
652  catch (...){
653  LOG("Exception Caught during [device::Manager::Initialize]\r\n");
654  }
655 
657 #ifndef NO_RF4CE
658  #ifdef USE_UNIFIED_CONTROL_MGR_API_1
659  IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_SESSION_BEGIN, _speechEventHandler);
660  IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_SESSION_ABORT, _speechEventHandler);
661  IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_SESSION_SHORT, _speechEventHandler);
662  IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_KEY_GHOST, _ctrlmMessageHandler);
663  #else
664  #ifdef USE_UNIFIED_RF4CE_MGR_API_4
665  IARM_Bus_RemoveEventHandler(VREX_MGR_IARM_BUS_NAME, VREX_MGR_IARM_EVENT_VOICE_BEGIN, _speechEventHandler);
666  IARM_Bus_RemoveEventHandler(VREX_MGR_IARM_BUS_NAME, VREX_MGR_IARM_EVENT_VOICE_SESSION_ABORT, _speechEventHandler);
667  IARM_Bus_RemoveEventHandler(VREX_MGR_IARM_BUS_NAME, VREX_MGR_IARM_EVENT_VOICE_SESSION_SHORT, _speechEventHandler);
668  #else
669  IARM_Bus_RemoveEventHandler(IARM_BUS_VREXMGR_NAME, IARM_BUS_VREXMGR_EVENT_SPEECH, _speechEventHandler);
670  #endif /* USE_UNIFIED_RF4CE_MGR_API_4 */
671  #ifdef RF4CE_GENMSO_API
672  IARM_Bus_RemoveEventHandler(IARM_BUS_RFMGR_NAME, IARM_BUS_RFMGR_EVENT_MSG_IND, _rfMessageHandler);
673  #elif defined(RF4CE_API)
674  IARM_Bus_RemoveEventHandler(IARM_BUS_RF4CEMGR_NAME, IARM_BUS_RF4CEMGR_EVENT_MSG_IND, _rf4ceMessageHandler);
675  #elif defined(RF4CE_GPMSO_API)
676  IARM_Bus_RemoveEventHandler(IARM_BUS_GPMGR_NAME, IARM_BUS_GPMGR_EVENT_MSG_IND, _gpMessageHandler);
677  #else
678  #warning "No RF4CE API defined"
679  #endif
680  #endif /* USE_UNIFIED_CONTROL_MGR_API_1 */
681 #endif /* NO_RF4CE */
682 
684  IARM_Bus_Term();
685  PLAT_TERM();
686  return IARM_RESULT_SUCCESS;
687 }
688 
689 void _sleepModeChangeHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
690 {
691  if (strcmp(owner,IARM_BUS_DSMGR_NAME) == 0)
692  {
693  switch (eventId) {
695  {
697  m_sleepMode = eventData->data.sleepModeInfo.sleepMode;
698  printf("%s m_sleepMode :%d \n",__FUNCTION__,m_sleepMode);
699  }
700  break;
701 
702  default:
703  break;
704  }
705  }
706 }
707 
708 static void _systemStateChangeHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
709 {
711  int state;
712  int error;
713  FILE *fp;
714  unsigned long secs = 0;
715  IARM_Bus_SYSMgr_SystemState_t stateId = sysEventData->data.systemStates.stateId;
716  state = sysEventData->data.systemStates.state;
717  error = sysEventData->data.systemStates.error;
718 
719  if (strcmp(owner, IARM_BUS_SYSMGR_NAME) == 0)
720  {
721  switch(stateId)
722  {
723  case IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL:
724  case IARM_BUS_SYSMGR_SYSSTATE_ECM_IP:
725  if(1 == error)
726  {
727  fp = fopen("/proc/uptime", "r");
728  if (NULL != fp)
729  {
730  setvbuf(fp, (char *) NULL, _IONBF, 0);
731  fseek(fp, 0, SEEK_SET);
732  if(0 > fscanf(fp, "%ld", &secs))
733  {
734  LOG("Error: fscanf on uptime failed \r\n");
735  /*Proc is not accessible(may never happen) taken as ecm connection lost */
736  ecm_connectivity_lost = 1;
737  }
738  fclose(fp);
739  }
740  else
741  {
742  LOG("Error: fopen on uptime failed \r\n");
743  /*Proc is not up(may never happen) taken as ecm connection lost */
744  ecm_connectivity_lost = 1;
745  }
746  /* Refer DELIA-6512 */
747  if(secs > 300)
748  {
749  if(0 == ecm_connectivity_lost)
750  {
751  if (stateId == IARM_BUS_SYSMGR_SYSSTATE_ECM_IP)
752  {
753  LOG("[PwrMgr] ECM connectivity Lost on ECM_IP Event..\r\n");
754  ecm_connectivity_lost = 1;
755  }
756  else if ((stateId == IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL) && (0 == state))
757  {
758  LOG("[PwrMgr] ECM connectivity Lost on DSG_CA_TUNNEL Event ..\r\n");
759  ecm_connectivity_lost = 1;
760  }
761  }
762  }
763  }
764  else if(0 == error)
765  {
766  /* Refer DELIA-6512 */
767  if(1 == ecm_connectivity_lost)
768  {
769  if (stateId == IARM_BUS_SYSMGR_SYSSTATE_ECM_IP)
770  {
771  LOG("[PwrMgr] ECM connectivity recovered on ECM_IP Event..\r\n");
772  ecm_connectivity_lost = 0;
773  }
774  else if ((stateId == IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL) && (2 == state))
775  {
776  LOG("[PwrMgr] ECM connectivity recovered on DSG_CA_TUNNEL Event..\r\n");
777  ecm_connectivity_lost = 0;
778  }
779  }
780  }
781  break;
782 
783  default:
784  break;
785  }
786  }
787 }
788 
789 static void _irEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
790 {
792 
793  int keyCode = irEventData->data.irkey.keyCode;
794  int keyType = irEventData->data.irkey.keyType;
795  int isFP = irEventData->data.irkey.isFP;
796 
797  int resetState = 0;
798 
799  {
800 
801  if((keyType != KET_KEYUP) && (keyType != KET_KEYDOWN) && (keyType != KET_KEYREPEAT))
802  {
803  LOG("Unexpected Key type recieved %X\r\n",keyType);
804  return;
805  }
806 
807  /*LOG("Power Manager Get IR Key (%x, %x) From IR Manager\r\n", keyCode, keyType);*/
808 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
809  if( (keyType == KET_KEYDOWN) && (keyCode == KED_FP_POWER))
810  {
811  PWRMGR_SET_POWER_KEYDOWN_TM();
812  }
813 #endif
814 
815  if( (keyType == KET_KEYUP) && (keyCode == KED_FP_POWER) && isFP && ecm_connectivity_lost )
816  {
817  /*DELIA-1801:Requirement is to bring up the box in "ON" state always when there is a ecm connectivity loss*/
818  LOG("[PwrMgr] Rebooting the box due to ECM connectivity Loss ..\r\n");
819  m_settings.powerState = IARM_BUS_PWRMGR_POWERSTATE_ON;
820  _WriteSettings(m_settingsFile);
821  PwrMgr_Reset(IARM_BUS_PWRMGR_POWERSTATE_ON, false);
822  return;
823  }
824 
825  {
826  PWRMgr_Settings_t *pSettings = &m_settings;
827  /* Intercept PowerKey */
828  IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState;
829  IARM_Bus_PWRMgr_PowerState_t newState = ((curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? IARM_BUS_PWRMGR_POWERSTATE_STANDBY : IARM_BUS_PWRMGR_POWERSTATE_ON);
830 #ifdef ENABLE_LLAMA_PLATCO
831  /*To avoid state transition from DEEPSLEEP to ON, that could affect state change of RDKTV platforms LLAMA-3152*/
832  if(curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP && keyCode != KED_DEEPSLEEP_WAKEUP)
833  {
834  LOG(" Ignoring the IR Events in Deepsleep Mode ..\r\n");
835  return;
836  }
837 #endif
838 
839 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
840  //LOG("Power Manager Settings State vs new State(%x, %x) transition state %x \r\n", curState, newState, transitionState);
841 #endif
842 
843  if (( (keyType == KET_KEYUP) && (keyCode == KED_DISCRETE_POWER_ON) && (newState == IARM_BUS_PWRMGR_POWERSTATE_ON) ) ||
844  ((keyType == KET_KEYUP) && (keyCode == KED_DISCRETE_POWER_STANDBY) && (newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY)))
845  {
847  LOG("Setting Discrete Powerstate cur=%d,new=%d\r\n", curState, newState);
848  param.newState = newState;
849  param.keyCode = keyCode;
850  _SetPowerState((void *)&param);
851  return;
852  }
853 
854  }
855 
856 
857  if (keyCode == KED_UNDEFINEDKEY)
858  return;
859  else
860  {
861  static int skipWakupKey = 0;
862  int isWakeupKey = 1;
863  int isPassthruKey= 0;
864  static const int passthruKeys[] = {
865  KED_FP_POWER,
866  KED_RF_POWER,
867  KED_POWER,
868  KED_VOLUMEDOWN,
869  KED_VOLUMEUP,
870  KED_MUTE
871  };
872 
873  static const int skipWakeupKeys[] = {
874  KED_MUTE,
875  KED_VOLUMEDOWN,
876  KED_VOLUMEUP,
877  KED_DISCRETE_POWER_ON,
878  KED_DISCRETE_POWER_STANDBY,
879  KED_XR2V3,
880  KED_XR5V2,
881  KED_XR11V2,
882  KED_XR13,
883  KED_XR11_NOTIFY,
884  KED_XR15V1_NOTIFY,
885  KED_INPUTKEY,
886  KED_UNDEFINEDKEY,
887  };
888 
889  static const char *keytypeString[3] = {"Pressed", "Released", "Repeat"};
890 
891  #ifdef _ENABLE_WAKEUP_KEY
892  {
893  int i = 0;
894  for (i = 0; i < sizeof(passthruKeys) / sizeof(passthruKeys[0]); i++) {
895  if (keyCode == passthruKeys[i]) {
896  isPassthruKey = 1;
897  break;
898  }
899  }
900 
901  for (i = 0; i < sizeof(skipWakeupKeys) / sizeof(skipWakeupKeys[0]); i++) {
902  if (keyCode == skipWakeupKeys[i]) {
903  isWakeupKey = 0;
904  break;
905  }
906  }
907  }
908  #else
909  {
910  isPassthruKey = 1;
911  isWakeupKey = 0;
912  }
913  #endif
914 
915  if(isWakeupKey) {
916  __TIMESTAMP();LOG("%s Power %s\n",((isFP == 1) ? "FrontPanel":"RF/IR"),keytypeString[((keyType>>8)-0x80)]);
917  }
918 
919  #ifdef _DISABLE_KEY_POWEROFF
920  const int disableFPResetLogic = 1;
921  #else
922  const int disableFPResetLogic = 0;
923  #endif
924 
925  if (disableFPResetLogic && keyCode == KED_FP_POWER && isFP) {
926  printf("Disable FP Reset Logic\r\n");
927  }else {
928  /* check if key is Control key and skip Reset sequence step if so */
929  static const int skipControlKeys[] = {
930  KED_XR2V3,
931  KED_XR5V2,
932  KED_XR11V2,
933  KED_XR13
934  };
935  bool is_control_key = false;
936  for (int i = 0; i < sizeof(skipControlKeys) / sizeof(skipControlKeys[0]); ++i) {
937  if (keyCode == skipControlKeys[i]) {
938  is_control_key = true;
939  break;
940  }
941  }
942  if (!is_control_key) {
943  resetState = checkResetSequence(keyType,keyCode);
944  }
945  else {
946  __TIMESTAMP();LOG("Control Key (%02x, %02x), do not check Reset sequence", keyCode, keyType);
947  }
948  }
949 
950  //LOG("After resetcheck Power Manager keyCode and isWakeupKey(%x, %x, %x) \r\n", keyCode, keyType, isWakeupKey);
951  /* Only wakup key or power key can change power state */
952  if ((keyCode == KED_FP_POWER) || (keyCode == KED_RF_POWER) || isWakeupKey)
953  {
954  PWRMgr_Settings_t *pSettings = &m_settings;
955  /* Intercept PowerKey */
956  IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState;
957 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
958  if (POWER_KEY_SENSITIVITY) {
959  curState = transitionState;
960  }
961 #endif
962  IARM_Bus_PWRMgr_PowerState_t newState;
963  if(m_sleepMode == dsHOST_SLEEP_MODE_DEEP)
964  {
965  newState = ((curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP: IARM_BUS_PWRMGR_POWERSTATE_ON);
966  }
967  else
968  {
969  newState = ((curState == IARM_BUS_PWRMGR_POWERSTATE_ON) ? IARM_BUS_PWRMGR_POWERSTATE_STANDBY : IARM_BUS_PWRMGR_POWERSTATE_ON);
970  }
971  if((keyCode == KED_DEEPSLEEP_WAKEUP) && (keyType == KET_KEYUP) && (curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP))
972  {
973  #ifdef PLATCO_BOOTTO_STANDBY
974  newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
975  LOG("KED_DEEPSLEEP_WAKEUP in DEEP_SLEEP so change the state to STANDBY cur=%d,new=%d\r\n", curState, newState);
976  #else
977  newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
978  LOG("KED_DEEPSLEEP_WAKEUP in DEEP_SLEEP so change the state to ON cur=%d,new=%d\r\n", curState, newState);
979  #endif
980  }
981 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
982  //LOG("After adjustment Power Manager Settings State vs new State(%x, %x) transition state %x \r\n", curState, newState, transitionState);
983 #endif
984 
985  {
986  /* On KEY_KEYDOWN, Check if to skip the wakeup key :
987  * Skip the first key (DOWN/REPEAT/UP) if in standby mode
988  * Passthru the key if (DOWN/REPEAT/UP) in ON mode
989  */
990  if (isWakeupKey && keyType == KET_KEYDOWN) {
991  if (curState != IARM_BUS_PWRMGR_POWERSTATE_ON) {
992  skipWakupKey = 0;
993  }
994  else {
995  skipWakupKey = 0;
996  }
997  }
998  }
999 
1000  #ifdef _DISABLE_KEY_POWEROFF
1001  const int disableKeyPowerOff = 1;
1002  #else
1003  const int disableKeyPowerOff = 0;
1004  #endif
1005 
1006  #ifdef _ENABLE_WAKEUP_KEY
1007  /* For IR POWER, always switch to ON state, for FP POWER, always toggle the power */
1008  if (((keyCode == KED_RF_POWER || isWakeupKey) && curState != IARM_BUS_PWRMGR_POWERSTATE_ON && (keyCode == KED_SELECT ? difftime(time(NULL), xre_timer) >= 3.0:1)) || (keyCode == KED_FP_POWER))
1009  #else
1010  /* For IR POWER, always toggle the power, for FP POWER, always toggle the power */
1011  if ((keyCode == KED_RF_POWER) || (isWakeupKey && curState != IARM_BUS_PWRMGR_POWERSTATE_ON && (keyCode == KED_SELECT ? difftime(time(NULL), xre_timer) >= 3.0:1)) || (keyCode == KED_FP_POWER))
1012  #endif
1013  {
1014 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
1015  LOG("before handling Power Manager Settings State vs new State(%x, %x) transition state %x \r\n", curState, newState, transitionState);
1016 #endif
1017  /* Notify application of Power Changes */
1018  if (keyType == KET_KEYUP && curState != newState && (resetState == 0)) {
1019  LOG("Setting Powerstate cur=%d,new=%d\r\n", curState, newState);
1021  param.newState = newState;
1022  param.keyCode = keyCode;
1023  int doNothandlePowerKey = ((disableKeyPowerOff) && (curState == IARM_BUS_PWRMGR_POWERSTATE_ON) && (newState != IARM_BUS_PWRMGR_POWERSTATE_ON));
1024  if ((deepSleepWakeup) && (curState != IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)){
1025  doNothandlePowerKey = 1;
1026  LOG("RDK_DEEPSLEEP_WAKEUP_ON_POWER_BUTTON is set, power-ON only from DEEPSLEEP\r\n");
1027  }
1028 
1029 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
1030  if (doNothandlePowerKey) {
1031  printf("Ignore Power Key when in ON state \r\n");
1032  }
1033  else
1034  {
1035  PWRMGR_SET_POWER_KEYUP_TM();
1036  if (PWRMGR_GET_POWER_KEY_INTERVAL() >= POWER_KEY_SENSITIVITY) {
1037  LOG("Taking PowerKey for Sensitivity %d, cur=%d,new=%d\r\n", PWRMGR_GET_POWER_KEY_INTERVAL(), curState, newState);
1038  _SetPowerStateAsync(curState, newState);
1039  }
1040  else {
1041  LOG("Ignoring PowerKey for Sensitivity %d, cur=%d,new=%d\r\n", PWRMGR_GET_POWER_KEY_INTERVAL(), curState, newState);
1042  }
1043  }
1044 #else
1045  if (!doNothandlePowerKey) {
1046  _SetPowerState((void *)&param);
1047  }
1048 #endif
1049  if (!doNothandlePowerKey) {
1050  setResetPowerState(newState);
1051  }
1052  }
1053  else {
1054  LOG("NOT NOT NOT Setting Powerstate cur=%d,new=%d on keyType %x\r\n", curState, newState, keyType);
1055  }
1056  }
1057  else
1058  {
1059  /* Do nothing */
1060  }
1061  }
1062  }
1063  }
1064 
1065 }
1066 
1067 static IARM_Result_t _SetPowerState(void *arg)
1068 {
1069  IARM_Result_t retCode = IARM_RESULT_SUCCESS;
1071  PWRMgr_Settings_t *pSettings = &m_settings;
1072  IARM_Bus_CommonAPI_PowerPreChange_Param_t powerPreChangeParam;
1073  IARM_Bus_PWRMgr_PowerState_t newState = param->newState;
1074  IARM_Bus_PWRMgr_PowerState_t curState = pSettings->powerState; /* Notify application of Power Changes */
1075  static const char *powerstateString[5] = {"OFF","STANDBY","ON", "LIGHTSLEEP", "DEEPSLEEP"};
1076 
1077  if(curState != newState) {
1078 
1079 #ifdef ENABLE_DEEP_SLEEP
1080  /* * When Changing from Deep sleep wakeup
1081  * Notify Deep sleep manager first followed by
1082  * Power pre change call.
1083  */
1084  //Changing power state ,Remove event source
1085  if(dsleep_bootup_event_src)
1086  {
1087  g_source_remove(dsleep_bootup_event_src);
1088  dsleep_bootup_event_src = 0;
1089  __TIMESTAMP();LOG("Removed Deep sleep boot up event Time source %d \r\n",dsleep_bootup_event_src);
1090  }
1091 
1092  if( (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP == curState)
1093  && (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP != newState))
1094  {
1095  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
1096  int dsStatus= 0;
1098  (char *)"GetDeepSleepStatus",
1099  (void *)&dsStatus,
1100  sizeof(dsStatus));
1101  if((DeepSleepStatus_InProgress == dsStatus) || (IARM_RESULT_SUCCESS != rpcRet))
1102  {
1103  LOG("%s deepsleep in progress ignoreing the request dsStatus %d rpcRet :%d\r\n",__FUNCTION__,dsStatus,rpcRet);
1104  return retCode;
1105  }
1106  IARM_Bus_CommonAPI_PowerPreChange_Param_t deepSleepWakeupParam;
1107 
1108  __TIMESTAMP();LOG("Waking up from Deep Sleep.. \r\n");
1109  deepSleepWakeupParam.curState = curState;
1110  deepSleepWakeupParam.newState = newState;
1111 
1112  /* Notify Deep sleep manager on Power Mode change */
1113  IARM_BusDaemon_DeepSleepWakeup(deepSleepWakeupParam);
1114  }
1115 #endif
1116 
1117  __TIMESTAMP();LOG("Power Mode Change from %s to %s start\n",powerstateString[curState],powerstateString[newState]);
1118 
1119  powerPreChangeParam.newState = param->newState;
1120  powerPreChangeParam.curState = pSettings->powerState;
1121 
1122  IARM_BusDaemon_PowerPrechange(powerPreChangeParam);
1123  __TIMESTAMP();LOG("Power Mode Change from %s to %s end\n",powerstateString[curState],powerstateString[newState]);
1124 
1125  if (nullptr != ux) //If ux_controller is supported, it will set up AV ports and LEDs in the below call.
1126  ux->applyPowerStateChangeConfig(newState, curState);
1127  else { // Since ux_controller is not supported, we needs to set up AV ports and LED here.
1128  _SetAVPortsPowerState(newState);
1129  _SetLEDStatus(newState);
1130  }
1131 #ifdef OFFLINE_MAINT_REBOOT
1132  if(newState != IARM_BUS_PWRMGR_POWERSTATE_ON){
1133 
1134  standby_time = g_get_monotonic_time()/G_USEC_PER_SEC;
1135  LOG("Power state changed at %lld\n", standby_time);
1136  }
1137 #endif
1138 
1139  pSettings->powerState = newState;
1140  _WriteSettings(m_settingsFile);
1141 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
1142  if(transitionState != newState)
1143  {
1144  transitionState = newState;
1145  }
1146  if(targetState != newState)
1147  {
1148  targetState = newState;
1149  }
1150 #endif
1151 #ifndef ENABLE_LLAMA_PLATCO
1152  if (newState != IARM_BUS_PWRMGR_POWERSTATE_ON) {
1153  time(&xre_timer); // Hack to fix DELIA-11393
1154  LOG("Invoking clean up script\r\n");
1155  if(param->keyCode != KED_FP_POWER)
1156  {
1157  system("/lib/rdk/standbyCleanup.sh");
1158  }
1159  else
1160  {
1161  __TIMESTAMP();LOG("Standby operation due to KED_FP_POWER key press, Invoking script with forceShutdown \r\n");
1162  system("/lib/rdk/standbyCleanup.sh --forceShutdown");
1163  }
1164  }
1165 #endif
1166  /* Independent of Deep sleep */
1167  PLAT_API_SetPowerState(newState);
1168 
1169  /* * Power Change Event
1170  * Used by Deep sleep and HDMI CEC.
1171  */
1172  LOG("[PwrMgr] Post Power Mode Change Event \r\n");
1173  {
1174  IARM_Bus_PWRMgr_EventData_t _eventData;
1175  _eventData.data.state.curState = curState;
1176  _eventData.data.state.newState = newState;
1177 
1178 #ifdef ENABLE_DEEP_SLEEP
1179  if(IsWakeupTimerSet)
1180  {
1181  /* Use the wakeup timer set by XRE */
1182  _eventData.data.state.deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1183  }
1184  else
1185  {
1186  /* Set the wakeup time till 2AM */
1187  deep_sleep_wakeup_timeout_sec = getWakeupTime();
1188  _eventData.data.state.deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1189  }
1190 
1191 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1192  _eventData.data.state.nwStandbyMode = nwStandbyMode_gs;
1193 #endif
1194 
1195 
1196  /* Start a Deep sleep Wakeup Time source
1197  * Reboot the box after elapse of user configured / Calculated Timeout.
1198  */
1199  if(IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP == newState)
1200  {
1201 
1202  /*
1203  - In Deep Sleep, the timer resets and the does not reboot after wakeup time out
1204  - As Gloop calls the handler only after Soc wakeup from dep sleep and after expiry of deep_sleep_wakeup_timeout_sec
1205  - So if Wakeup timeout is 10 minutes , box reboots after 20 minutes,
1206  - To handle this, the handler is called every 30 sec and check for expiry of deep sleep wakeup timeout.
1207  */
1208  time(&timeAtDeepSleep);
1209 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1210  #ifndef USE_WAKEUP_TIMER_EVT
1211  wakeup_event_src = g_timeout_add_seconds ((guint)1, deep_sleep_wakeup_fn, pwrMgr_Gloop);
1212  #else
1213  __TIMESTAMP();LOG("deep_sleep_wakeup_fn is not running\r\n");
1214  #endif
1215  __TIMESTAMP();LOG("Networkstandbymode for Source %d is: %s \r\n",wakeup_event_src, (nwStandbyMode_gs?("Enabled"):("Disabled")));
1216 #else
1217  wakeup_event_src = g_timeout_add_seconds ((guint)30, deep_sleep_wakeup_fn, pwrMgr_Gloop);
1218 #endif
1219  __TIMESTAMP();LOG("Added Deep Sleep Wakeup Time Source %d for %d Sec \r\n",wakeup_event_src,deep_sleep_wakeup_timeout_sec);
1220 
1221  }
1222  else if(wakeup_event_src)
1223  {
1224  //We got some key event, Remove event source
1225  __TIMESTAMP();LOG("Removed Deep sleep Wakeup Time source %d for %d Sec.. \r\n",wakeup_event_src,deep_sleep_wakeup_timeout_sec);
1226  g_source_remove(wakeup_event_src);
1227  wakeup_event_src = 0;
1228  timeAtDeepSleep = 0;
1229  }
1230 #endif
1232  IARM_BUS_PWRMGR_EVENT_MODECHANGED, (void *)&_eventData, sizeof(_eventData));
1233  if(IARM_BUS_PWRMGR_POWERSTATE_ON == newState)
1234  {
1235  __TIMESTAMP();LOG("IARMCEC_SendCECImageViewOn and IARMCEC_SendCECActiveSource. \r\n");
1236  IARMCEC_SendCECImageViewOn(isCecLocalLogicEnabled);
1237  IARMCEC_SendCECActiveSource(isCecLocalLogicEnabled,KET_KEYDOWN,KED_MENU);
1238  }
1239  }
1240 
1241  }
1242  else
1243  {
1244  LOG("Warning:PowerState is same as requested\r\n");
1245  }
1246  return retCode;
1247 }
1248 
1249 
1250 static IARM_Result_t _GetPowerState(void *arg)
1251 {
1252  PWRMgr_Settings_t *pSettings = &m_settings;
1254  param->curState = pSettings->powerState;
1255  //LOG("_GetPowerState return %d\r\n", pSettings->powerState);
1256  return IARM_RESULT_SUCCESS;
1257 }
1258 
1259 static IARM_Result_t _GetPowerStateBeforeReboot(void *arg)
1260 {
1262  memset (param->powerStateBeforeReboot, '\0', MAX_PWR_STATE_BEF_REBOOR_STR_LEN);
1263  strncpy (param->powerStateBeforeReboot, powerStateBeforeReboot_gc.c_str(), strlen(powerStateBeforeReboot_gc.c_str()));
1264  return IARM_RESULT_SUCCESS;
1265 }
1266 
1267 
1268 static IARM_Result_t _HandleReboot(void *arg)
1269 {
1271  param->reboot_reason_custom[sizeof(param->reboot_reason_custom) - 1] = '\0'; //Just to be on the safe side.
1272  param->reboot_reason_custom[sizeof(param->reboot_reason_other) - 1] = '\0';
1273  param->requestor[sizeof(param->requestor) - 1] = '\0';
1274 
1275  if(nullptr != ux)
1276  {
1277  if(0 == strncmp(PWRMGR_REBOOT_REASON_MAINTENANCE, param->reboot_reason_custom, sizeof(param->reboot_reason_custom)))
1278  ux->applyPreMaintenanceRebootConfig(m_settings.powerState);
1279  else
1280  ux->applyPreRebootConfig(m_settings.powerState);
1281  }
1282  performReboot(param->requestor, param->reboot_reason_custom, param->reboot_reason_other);
1283  return IARM_RESULT_SUCCESS;
1284 }
1285 
1286 #ifdef ENABLE_SET_WAKEUP_SRC_CONFIG
1287 static IARM_Result_t _SetWakeupSrcConfig(void *arg)
1288 {
1289  IARM_Result_t retCode = IARM_RESULT_IPCCORE_FAIL;
1290  int result = 1;
1291 
1292  if(NULL != arg)
1293  {
1294  IARM_Bus_PWRMgr_SetWakeupSrcConfig_Param_t *param = (IARM_Bus_PWRMgr_SetWakeupSrcConfig_Param_t *)arg;
1295  LOG("[PwrMgr] Setting WakeupSrcConfiguration for src type %d to %d\n", param->srcType,param->config);
1296  result = PLAT_API_SetWakeupSrc(param->srcType, param->config);
1297  retCode = result?IARM_RESULT_IPCCORE_FAIL:IARM_RESULT_SUCCESS;
1298  }
1299  else
1300  {
1301  retCode = IARM_RESULT_INVALID_PARAM;
1302  }
1303  return retCode;
1304 }
1305 #endif //ENABLE_SET_WAKEUP_SRC_CONFIG
1306 
1307 static void* _AsyncPowerWareHouseOperation(void *pWareHouseOpnArg)
1308 {
1309  IARM_Bus_PWRMgr_WareHouseOps_t* pWareHouseOpn = (IARM_Bus_PWRMgr_WareHouseOps_t*) pWareHouseOpnArg;
1310 
1311  pthread_mutex_lock(&wareHouseOpsMutex);
1312  if (NULL == pWareHouseOpn) {
1313  LOG("_AsyncPowerWareHouseOperation pWareHouseOpnArg is NULL\r\n");
1314  pthread_mutex_unlock(&wareHouseOpsMutex);
1315  asyncPowerWarehouseOpsThreadId = NULL;
1316  pthread_exit(NULL);
1317  }
1318 
1319  IARM_BUS_PWRMgr_WareHouseOpn_EventData_t wareHouseOpnEventData;
1320  wareHouseOpnEventData.wareHouseOpn = (*pWareHouseOpn);
1321  wareHouseOpnEventData.status = IARM_BUS_PWRMGR_WAREHOUSE_INPROGRESS;
1322  LOG("_AsyncPowerWareHouseOperation pWareHouseOpnArg is %d pWareHouseOpn is %d\r\n", *((int*)pWareHouseOpnArg), *pWareHouseOpn);
1323 
1324  if (IARM_BUS_PWRMGR_WAREHOUSE_RESET == (*pWareHouseOpn)) {
1325  processWHResetNoReboot();
1326  wareHouseOpnEventData.status = IARM_BUS_PWRMGR_WAREHOUSE_COMPLETED;
1327  }
1328  else if (IARM_BUS_PWRMGR_WAREHOUSE_CLEAR == (*pWareHouseOpn)) {
1329  processWHClearNoReboot();
1330  wareHouseOpnEventData.status = IARM_BUS_PWRMGR_WAREHOUSE_COMPLETED;
1331  }
1332  else {
1333  /* goto sleep */
1334  LOG("_AsyncPowerWareHouseOperation unexpected pWareHouseOpnArg %d\r\n", (*pWareHouseOpn));
1335  wareHouseOpnEventData.status = IARM_BUS_PWRMGR_WAREHOUSE_FAILED;
1336  }
1337 
1338  LOG("_AsyncPowerWareHouseOperation broadcasted IARM_BUS_PWRMGR_EVENT_WAREHOUSEOPS_STATUSCHANGED event\r\n");
1339  IARM_Bus_BroadcastEvent(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_EVENT_WAREHOUSEOPS_STATUSCHANGED, (void *)&wareHouseOpnEventData, sizeof(wareHouseOpnEventData));
1340 
1341  free (pWareHouseOpn); pWareHouseOpn=NULL;
1342  pthread_mutex_unlock(&wareHouseOpsMutex);
1343  asyncPowerWarehouseOpsThreadId = NULL;
1344  pthread_exit(NULL);
1345 }
1346 
1347 static int _SetPowerWareHouseOperation(IARM_Bus_PWRMgr_WareHouseOps_t eWareHouseOpn)
1348 {
1349 
1350  IARM_Result_t retCode = IARM_RESULT_SUCCESS;
1351 
1352  if (asyncPowerWarehouseOpsThreadId == NULL)
1353  {
1355  *pWareHouseOpn = eWareHouseOpn;
1356  LOG("_SetPowerWareHouseOperation eWareHouseOpn is %d pWareHouseOpn is %d\r\n", eWareHouseOpn, *pWareHouseOpn);
1357  int err = pthread_create(&asyncPowerWarehouseOpsThreadId, NULL, _AsyncPowerWareHouseOperation, (void*)pWareHouseOpn);
1358  if(err != 0){
1359  LOG("_AsyncPowerWareHouseOperation thread create failed \r\n");
1360  }else {
1361  err = pthread_detach(asyncPowerWarehouseOpsThreadId);
1362  if(err != 0){
1363  LOG("_AsyncPowerWareHouseOperation thread detach failed \r\n");
1364  }
1365  else
1366  LOG("_AsyncPowerWareHouseOperation thread detach success \r\n");
1367  }
1368  }
1369  else {
1370  retCode = IARM_RESULT_INVALID_STATE;
1371  LOG("_SetPowerWareHouseOperation already in progress %d. Pls call it once existing reset finished.\r\n", retCode);
1372  }
1373  return retCode;
1374 }
1375 
1376 static IARM_Result_t _WareHouseReset(void *arg)
1377 {
1379  int ret = param->suppressReboot ? _SetPowerWareHouseOperation (IARM_BUS_PWRMGR_WAREHOUSE_RESET) : processWHReset();
1380  LOG("_WareHouseReset returned : %d\r\n", ret);
1381  fflush(stdout);
1382  if (ret == 0)
1383  return IARM_RESULT_SUCCESS;
1384  else
1385  return IARM_RESULT_IPCCORE_FAIL;
1386 }
1387 
1388 static IARM_Result_t _WareHouseClear(void *arg)
1389 {
1391  int ret = param->suppressReboot ? _SetPowerWareHouseOperation (IARM_BUS_PWRMGR_WAREHOUSE_CLEAR) : processWHClear();
1392  LOG("_WareHouseClear returned : %d\r\n", ret);
1393  fflush(stdout);
1394  if (ret == 0)
1395  return IARM_RESULT_SUCCESS;
1396  else
1397  return IARM_RESULT_IPCCORE_FAIL;
1398 }
1399 
1400 static IARM_Result_t _ColdFactoryReset(void *)
1401 {
1402  int ret = processColdFactoryReset();
1403  LOG("_ColdFactoryReset returned : %d\r\n", ret);
1404  fflush(stdout);
1405  if (ret == 0)
1406  return IARM_RESULT_SUCCESS;
1407  else
1408  return IARM_RESULT_IPCCORE_FAIL;
1409 }
1410 
1411 static IARM_Result_t _FactoryReset(void *)
1412 {
1413  int ret = processFactoryReset();
1414  LOG("_FactoryReset returned : %d\r\n", ret);
1415  fflush(stdout);
1416  if (ret == 0)
1417  return IARM_RESULT_SUCCESS;
1418  else
1419  return IARM_RESULT_IPCCORE_FAIL;
1420 }
1421 
1422 static IARM_Result_t _UserFactoryReset(void *)
1423 {
1424  int ret = processUserFactoryReset();
1425  LOG("_UserFactoryReset returned : %d\r\n", ret);
1426  fflush(stdout);
1427  if (ret == 0)
1428  return IARM_RESULT_SUCCESS;
1429  else
1430  return IARM_RESULT_IPCCORE_FAIL;
1431 }
1432 
1433 static IARM_Result_t _SetStandbyVideoState(void *arg)
1434 {
1436  if(NULL == param->port)
1437  {
1438  param->result = -1;
1439  __TIMESTAMP();LOG("[PwrMgr] empty port name. Cannot proceed.\n");
1440  return IARM_RESULT_SUCCESS;
1441  }
1442  else
1443  param->result = 0;
1444 
1445  int i = 0;
1446  for(i = 0; i < MAX_NUM_VIDEO_PORTS; i++)
1447  {
1448  if(0 == strncasecmp(param->port, g_standby_video_port_setting[i].port, PWRMGR_MAX_VIDEO_PORT_NAME_LENGTH))
1449  {
1450  /*Found a match. Update it*/
1451  g_standby_video_port_setting[i].isEnabled = ((0 == param->isEnabled) ? false : true);
1452  break;
1453  }
1454  }
1455  if(MAX_NUM_VIDEO_PORTS == i)
1456  {
1457  /*No matching entries are present. Add one.*/
1458  for(i = 0; i < MAX_NUM_VIDEO_PORTS; i++)
1459  {
1460  if('\0' == g_standby_video_port_setting[i].port[0])
1461  {
1462  strncpy(g_standby_video_port_setting[i].port, param->port, (PWRMGR_MAX_VIDEO_PORT_NAME_LENGTH - 1));
1463  g_standby_video_port_setting[i].isEnabled = ((0 == param->isEnabled) ? false : true);
1464  break;
1465  }
1466  }
1467  }
1468  if(MAX_NUM_VIDEO_PORTS == i)
1469  {
1470  __TIMESTAMP();LOG("Error! Out of room to write new video port setting for standby mode.\n");
1471  }
1472 
1473  try
1474  {
1476  if((IARM_BUS_PWRMGR_POWERSTATE_ON != m_settings.powerState) && (IARM_BUS_PWRMGR_POWERSTATE_OFF != m_settings.powerState))
1477  {
1478  /*We're currently in one of the standby states. This new setting needs to be applied right away.*/
1479  __TIMESTAMP();LOG("[PwrMgr] Setting standby %s port status to %s.\n", param->port, ((1 == param->isEnabled)? "enabled" : "disabled"));
1480  if(1 == param->isEnabled)
1481  vPort.enable();
1482  else
1483  vPort.disable();
1484  }
1485  else
1486  {
1487  __TIMESTAMP();LOG("[PwrMgr] video port %s will be %s when going into standby mode.\n", param->port, ((1 == param->isEnabled)? "enabled" : "disabled"));
1488  }
1489  }
1490  catch (...)
1491  {
1492  __TIMESTAMP();LOG("Exception Caught during [PWRMgr - _SetStandbyVideoState]. Possible bad video port.\n");
1493  param->result = -1;
1494  }
1495  return IARM_RESULT_SUCCESS;
1496 }
1497 
1498 static IARM_Result_t _GetStandbyVideoState(void *arg)
1499 {
1501  if(NULL == param->port)
1502  {
1503  __TIMESTAMP();LOG("Bad port name. Cannot get state.\n");
1504  return IARM_RESULT_SUCCESS;
1505  }
1506 
1507  try
1508  {
1510 
1511  }
1512  catch (...)
1513  {
1514  __TIMESTAMP();LOG("Exception Caught during [PWRMgr - _GetStandbyVideoState]. Possible bad video port.\n");
1515  param->result = -1;
1516  return IARM_RESULT_SUCCESS;
1517  }
1518  param->isEnabled = ((true == get_video_port_standby_setting(param->port))? 1 : 0);
1519  param->result = 0;
1520  return IARM_RESULT_SUCCESS;
1521 }
1522 
1523 static int _InitSettings(const char *settingsFile)
1524 {
1525  if (settingsFile == NULL) settingsFile = "/opt/uimgr_settings.bin";
1526 
1527  m_settingsFile = settingsFile;
1528  LOG("Initializing settings at file %s\r\n", settingsFile);
1529 
1530  int ret = open(settingsFile, O_CREAT|O_RDWR, S_IRWXU|S_IRUSR);
1531  int fd = ret;
1532  struct stat buf;
1533 
1534  if (fd >= 0) {
1535 
1536  PWRMgr_Settings_t *pSettings = &m_settings;
1537  int read_size = sizeof(uint32_t) * 3;
1538  lseek(fd, 0, SEEK_SET);
1539  ret = read(fd, pSettings,read_size);
1540  if((ret == read_size))
1541  {
1542  switch(pSettings->version)
1543  {
1544  case 0:
1545  {
1546  UIMgr_Settings_t uiMgrSettings;
1547  lseek(fd, 0, SEEK_SET);
1548  pSettings->length = sizeof(UIMgr_Settings_t) - PADDING_SIZE;
1549  read_size = pSettings->length;
1550  ret = read(fd, &uiMgrSettings,read_size);
1551  if(ret == read_size)
1552  {
1553 
1554  pSettings->magic = _UIMGR_SETTINGS_MAGIC;
1555  pSettings->version = 1;
1556  pSettings->length = sizeof(PWRMgr_Settings_t) - PADDING_SIZE;
1557  pSettings->powerState =
1558  _ConvertUIDevToIARMBusPowerState(uiMgrSettings.powerState);
1559  g_last_known_power_state = pSettings->powerState;
1560  #ifdef ENABLE_DEEP_SLEEP
1561  pSettings->deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1562  #endif
1563  #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1564  pSettings->nwStandbyMode = nwStandbyMode_gs;
1565  #endif
1566  lseek(fd, 0, SEEK_SET);
1567  write(fd, pSettings, pSettings->length);
1568 
1569  }
1570  else
1571  {
1572  ret = 0; //error case, not able to read full length
1573  }
1574  }
1575 
1576  break;
1577  case 1:
1578  {
1579  if((pSettings->length == (sizeof(PWRMgr_Settings_t) - PADDING_SIZE )))
1580  {
1581  LOG("[PwrMgr] Length of Persistence matches with Current Data Size \r\n");
1582  lseek(fd, 0, SEEK_SET);
1583  read_size = pSettings->length;
1584  ret = read(fd, pSettings,read_size);
1585  if(ret != read_size)
1586  {
1587  ret = 0; //error case, not able to read full length
1588  LOG("[PwrMgr] error case, not able to read full length \r\n");
1589  }
1590  else
1591  {
1592  g_last_known_power_state = pSettings->powerState;
1593  #ifdef ENABLE_DEEP_SLEEP
1594  deep_sleep_wakeup_timeout_sec = pSettings->deep_sleep_timeout;
1595  __TIMESTAMP();LOG("Persisted deep_sleep_delay = %d Secs \r\n",deep_sleep_wakeup_timeout_sec);
1596  #endif
1597  #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1598  nwStandbyMode_gs = pSettings->nwStandbyMode;
1599  __TIMESTAMP();LOG("Persisted network standby mode is: %s \r\n", nwStandbyMode_gs?("Enabled"):("Disabled"));
1600  #endif
1601  #ifdef PLATCO_BOOTTO_STANDBY
1602  if(stat("/tmp/pwrmgr_restarted",&buf) != 0)
1603  {
1604  pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1605  __TIMESTAMP();LOG("Setting default powerstate to standby\n\r");
1606  }
1607  #endif
1608  }
1609  }
1610  else if (((pSettings->length < (sizeof(PWRMgr_Settings_t) - PADDING_SIZE ))))
1611  {
1612  /* New Code reading the old version persistent file information */
1613  LOG("[PwrMgr] Length of Persistence is less than Current Data Size \r\n");
1614  lseek(fd, 0, SEEK_SET);
1615  read_size = pSettings->length;
1616  ret = read(fd, pSettings,read_size);
1617  if(ret != read_size)
1618  {
1619  LOG("[PwrMgr] Read Failed for Data Length %d \r\n",ret);
1620  ret = 0; //error case, not able to read full length
1621  }
1622  else
1623  {
1624  /*TBD - The struct should be initialized first so that we dont need to add
1625  manually the new fields.
1626  */
1627  g_last_known_power_state = pSettings->powerState;
1628  lseek(fd, 0, SEEK_SET);
1629  #ifdef ENABLE_DEEP_SLEEP
1630  pSettings->deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1631  #endif
1632  #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1633  pSettings->nwStandbyMode = nwStandbyMode_gs;
1634  #endif
1635  #ifdef PLATCO_BOOTTO_STANDBY
1636  if(stat("/tmp/pwrmgr_restarted",&buf) != 0) {
1637  pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1638  }
1639  #endif
1640  pSettings->length = (sizeof(PWRMgr_Settings_t) - PADDING_SIZE );
1641  LOG("[PwrMgr] Write PwrMgr Settings File With Current Data Length %d \r\n",pSettings->length);
1642  ret = write(fd, pSettings, pSettings->length);
1643  if(ret != pSettings->length)
1644  {
1645  LOG("[PwrMgr] Write Failed For New Data Length %d \r\n",ret);
1646  ret = 0; //error case, not able to read full length
1647  }
1648  }
1649  }
1650  else if (((pSettings->length > (sizeof(PWRMgr_Settings_t) - PADDING_SIZE ))))
1651  {
1652  /* Old Code reading the migrated new version persistent file information */
1653  LOG("[PwrMgr] Length of Persistence is more than Current Data Size. \r\n");
1654 
1655  lseek(fd, 0, SEEK_SET);
1656  read_size = (sizeof(PWRMgr_Settings_t) - PADDING_SIZE );
1657  ret = read(fd,pSettings,read_size);
1658  if(ret != read_size)
1659  {
1660  LOG("[PwrMgr] Read Failed for Data Length %d \r\n",ret);
1661  ret = 0; //error case, not able to read full length
1662  }
1663  else
1664  {
1665  /*Update the length and truncate the file */
1666  g_last_known_power_state = pSettings->powerState;
1667  lseek(fd, 0, SEEK_SET);
1668  pSettings->length = (sizeof(PWRMgr_Settings_t) - PADDING_SIZE );
1669  LOG("[PwrMgr] Write and Truncate PwrMgr Settings File With Current Data Length %d ........\r\n",pSettings->length);
1670  ret = write(fd, pSettings, pSettings->length);
1671  if(ret != pSettings->length)
1672  {
1673  LOG("[PwrMgr] Write Failed For New Data Length %d \r\n",ret);
1674  ret = 0; //error case, not able to read full length
1675  }
1676  else
1677  {
1678  /* Truncate the File information */
1679  int fret = 0;
1680  lseek(fd, 0, SEEK_SET);
1681  fret = ftruncate(fd,pSettings->length);
1682  if(fret != 0)
1683  {
1684  LOG("[PwrMgr] Truncate Failed For New Data Length %d \r\n",fret);
1685  ret = 0; //error case, not able to read full length
1686  }
1687  }
1688 
1689  }
1690 
1691  }
1692  else
1693  {
1694  ret = 0; //Version 1 but not with current size and data...
1695  }
1696  }
1697  break;
1698  default:
1699  ret = 0; //Consider it as an invalid file.
1700  }
1701  }
1702  else
1703  {
1704  /**/
1705  #ifdef PLATCO_BOOTTO_STANDBY
1706  if(stat("/tmp/pwrmgr_restarted",&buf) != 0) {
1707  powerStateBeforeReboot_gc = std::string("UNKNOWN");
1708  printf ("[%s]:[%d] powerStateBeforeReboot: %s\n", __FUNCTION__, __LINE__, powerStateBeforeReboot_gc.c_str());
1709  }
1710  #endif
1711  ret = 0;
1712  }
1713  if (ret == 0) {
1714 
1715  lseek(fd, 0, SEEK_SET);
1716  LOG("Initial Creation of UIMGR Settings\r\n");
1717  pSettings->magic = _UIMGR_SETTINGS_MAGIC;
1718  pSettings->version = 1;
1719  pSettings->length = sizeof(*pSettings) - PADDING_SIZE;
1720  pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_ON;
1721  #ifdef ENABLE_DEEP_SLEEP
1722  pSettings->deep_sleep_timeout = deep_sleep_wakeup_timeout_sec;
1723  #endif
1724  #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
1725  pSettings->nwStandbyMode = nwStandbyMode_gs;
1726  #endif
1727  #ifdef PLATCO_BOOTTO_STANDBY
1728  if(stat("/tmp/pwrmgr_restarted",&buf) != 0)
1729  pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1730  #endif
1731  ret = write(fd, pSettings, pSettings->length);
1732  if (ret < 0) {
1733  }
1734  }
1735 
1736  #ifdef ENABLE_DEEP_SLEEP
1737  /* If Persistent power mode is Deep Sleep
1738  start a thread to put box to deep sleep after specified time.
1739  */
1740  if(pSettings->powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)
1741  {
1742  __TIMESTAMP();LOG("Box Reboots with Deep Sleep mode.. Start a Event Time SOurce .. \r\n");
1743  guint dsleep_bootup_timeout = 3600; //In sec
1744  dsleep_bootup_event_src = g_timeout_add_seconds (dsleep_bootup_timeout,invoke_deep_sleep_on_bootup_timeout,pwrMgr_Gloop);
1745  __TIMESTAMP();LOG("Added Time source %d to put the box to deep sleep after %d Sec.. \r\n",dsleep_bootup_event_src,dsleep_bootup_timeout);
1746  }
1747  #endif
1748 
1749  setPowerStateBeforeReboot (g_last_known_power_state);
1750  __TIMESTAMP();LOG("Setting PowerStateBeforeReboot %d \r\n", g_last_known_power_state);
1751 
1752  /* Sync with platform if it is supported */
1753  {
1754  if(nullptr != ux)
1755  ux->applyPostRebootConfig(pSettings->powerState, g_last_known_power_state); // This will set up ports, lights and bootloader pattern internally.
1756 
1757  IARM_Bus_PWRMgr_PowerState_t state;
1758  ret = PLAT_API_GetPowerState(&state);
1759  if (ret == 0) {
1760  if (pSettings->powerState == state) {
1761  LOG("PowerState is already sync'd with hardware to %d\r\n", state);
1762  }
1763  else {
1764  int loopCount = 0;
1765  LOG("PowerState sync hardware state %d with UIMGR to %d\r\n", state, pSettings->powerState);
1766  do {
1767  loopCount++;
1768  if(nullptr == ux) // Since ux_controller is not supported, ports need to be set up explicitly.
1769  _SetAVPortsPowerState(pSettings->powerState);
1770  ret = PLAT_API_SetPowerState(pSettings->powerState);
1771  sleep(1);
1772  PLAT_API_GetPowerState(&state);
1773  } while(state != pSettings->powerState && loopCount < 10);
1774 
1775  if (state != pSettings->powerState) {
1776  LOG("CRITICAL ERROR: PowerState sync failed \r\n");
1777  pSettings->powerState = state;
1778  }
1779  }
1780  if(nullptr == ux) // Since ux_controller is not supported, ports need to be set up explicitly.
1781  {
1782  _SetAVPortsPowerState(pSettings->powerState);
1783  _SetLEDStatus(pSettings->powerState);
1784  }
1785 
1786  if (fd >= 0) {
1787  lseek(fd, 0, SEEK_SET);
1788  ret = write(fd, pSettings, pSettings->length);
1789  if (ret < 0) {
1790  }
1791  }
1792  }
1793  else {
1794  /* Use settings stored in uimgr file */
1795  }
1796  }
1797 
1798  #ifdef PLATCO_BOOTTO_STANDBY
1799  if(stat("/tmp/pwrmgr_restarted",&buf) != 0) {
1800  IARM_Bus_PWRMgr_EventData_t _eventData;
1801  _eventData.data.state.curState = IARM_BUS_PWRMGR_POWERSTATE_OFF;
1802  _eventData.data.state.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
1803  LOG("%s: Init setting powermode change from OFF to STANDBY \r\n", __FUNCTION__);
1804  IARM_Bus_BroadcastEvent( IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_EVENT_MODECHANGED, (void *)&_eventData, sizeof(_eventData));
1805  }
1806  #endif
1807 
1808  if (ret > 0 && ret < (int)sizeof(*pSettings)) {
1809  _DumpSettings(pSettings);
1810  /* @TODO: assert pSettings->length == FileLength */
1811  }
1812 
1813  if (ret > (int)sizeof(*pSettings)) {
1814  LOG("Error: Should not have read that much ! \r\n");
1815  /* @TODO: Error Handling */
1816  /* Init Settings to default, truncate settings to 0 */
1817  }
1818 
1819  fsync(fd);
1820  close(fd);
1821  }
1822 
1823  if (ret < 0) {
1824  LOG("Error: Failed to operate on uimgr_settings.bin, reason=[%s]\r\n", strerror(errno));
1825  }
1826 
1827  return ret;
1828 }
1829 
1830 
1831 static int _WriteSettings(const char *settingsFile)
1832 {
1833  PWRMgr_Settings_t *pSettings = &m_settings;
1834  int fd = open(settingsFile, O_WRONLY);
1835  int ret = fd;
1836 
1837  if (fd >= 0) {
1838  lseek(fd, 0, SEEK_SET);
1839  PWRMgr_Settings_t *pSettings = &m_settings;
1840  ret = write(fd, pSettings, pSettings->length);
1841  fsync(fd);
1842  close(fd);
1843  }
1844 
1845  if (ret < 0) {
1846  LOG("Error: Failed to write on [%s], reason=[%s]\r\n", settingsFile, strerror(errno));
1847  }
1848  else {
1849  LOG("Settings updated successfully\r\n");
1850  _DumpSettings(pSettings);
1851  }
1852 
1853  return ret;
1854 }
1855 
1856 static void _DumpSettings(const PWRMgr_Settings_t *pSettings)
1857 {
1858  LOG("PWRMGR-Settings-Mag: %X\r\n", pSettings->magic);
1859  LOG("PWRMGR-Settings-Ver: %d\r\n", pSettings->version);
1860  LOG("PWRMGR-Settings-Len: %d\r\n", pSettings->length );
1861  LOG("PWRMGR-Settings-PWR: %d\r\n", pSettings->powerState);
1862  LOG("PWRMGR-Settings-Brightness: %d\r\n", pSettings->ledSettings.brightness);
1863  #ifdef ENABLE_DEEP_SLEEP
1864  LOG("PWRMGR-Settings-Deep Sleep Timeout: %d\r\n", pSettings->deep_sleep_timeout);
1865  #endif
1866 }
1867 
1868 static int _SetLEDStatus(IARM_Bus_PWRMgr_PowerState_t powerState)
1869 {
1870  try {
1871 
1872  if( powerState != IARM_BUS_PWRMGR_POWERSTATE_ON )
1873  {
1874 #ifdef FP_POWER_LED_ON_IN_LOW_POWER_MODE //For devices like TVs that are expected to have lights on when in one of the standby modes.
1876  LOG("[PWRMgr-_SetLEDStatus] Settings the Power LED State to ON\r\n");
1877 #else
1879  LOG("[PWRMgr-_SetLEDStatus] Settings the Power LED State to OFF \r\n");
1880 #endif
1881  }
1882  else
1883  {
1885  LOG("[PWRMgr-_SetLEDStatus] Settings the Power LED State to ON \r\n");
1886  }
1887  }
1888  catch (...) {
1889  LOG("Exception Caught during [PWRMgr - _SetLEDStatus]\r\n");
1890  return 0;
1891  }
1892  return 0;
1893 }
1894 
1895 static IARM_Bus_PWRMgr_PowerState_t _ConvertUIDevToIARMBusPowerState(UIDev_PowerState_t powerState)
1896 {
1897  IARM_Bus_PWRMgr_PowerState_t ret = IARM_BUS_PWRMGR_POWERSTATE_ON;
1898  switch(powerState)
1899  {
1900  case UIDEV_POWERSTATE_OFF:
1901  ret = IARM_BUS_PWRMGR_POWERSTATE_OFF;
1902  break;
1903  case UIDEV_POWERSTATE_STANDBY:
1904  ret = IARM_BUS_PWRMGR_POWERSTATE_ON;
1905  break;
1906  }
1907  return ret;
1908 }
1909 
1910 int _SetAVPortsPowerState(IARM_Bus_PWRMgr_PowerState_t powerState)
1911 {
1912 
1913  try {
1914  if( powerState != IARM_BUS_PWRMGR_POWERSTATE_ON ){
1915  if(IARM_BUS_PWRMGR_POWERSTATE_OFF != powerState)
1916  {
1917  //We're in one of the standby modes. Certain ports may have to be left on.
1919  for (size_t i = 0; i < videoPorts.size(); i++)
1920  {
1921  bool doEnable = get_video_port_standby_setting(videoPorts.at(i).getName().c_str());
1922  LOG("Video port %s will be %s in standby mode.\n", videoPorts.at(i).getName().c_str(), (doEnable? "enabled" : "disabled"));
1923  if(false == doEnable)
1924  videoPorts.at(i).disable();
1925  }
1926  }
1927  else
1928  {
1929  //Disable all ports when going into POWERSTATE_OFF
1931  for (size_t i = 0; i < videoPorts.size(); i++)
1932  {
1933  videoPorts.at(i).disable();
1934  }
1935  }
1936 
1938 
1939  for (size_t i = 0; i < audioPorts.size(); i++)
1940  {
1941  audioPorts.at(i).disable();
1942  }
1943  /*LOG("Disabling the AV Ports [_SetAVPortsPowerState]\r\n");*/
1944  }
1945  else
1946  {
1947 
1949  for (size_t i = 0; i < videoPorts.size(); i++)
1950  {
1951  videoPorts.at(i).enable();
1952  }
1954  for (size_t i = 0; i < audioPorts.size(); i++)
1955  {
1956  device::AudioOutputPort &vPort = audioPorts.at(i);
1957  bool isPortPersistenceValEnabled = true;
1958  try {
1959  isPortPersistenceValEnabled = vPort.getEnablePersist();
1960  }
1961  catch(const device::Exception& err)
1962  {
1963  LOG("Audio Port Getting enable persist value failed. Proceeding with true\n");
1964  }
1965  if(isPortPersistenceValEnabled)
1966  {
1967  /*Instead of enabling all the audio ports on power transition */
1968  /*Get the values from persistent storage & update */
1969  audioPorts.at(i).enable();
1970  }
1971  }
1972 
1973  for (size_t i = 0; i < videoPorts.size(); i++)
1974  {
1975  device::VideoOutputPort &vPort = videoPorts.at(i);
1976  if (vPort.isDisplayConnected())
1977  {
1978  device::AudioOutputPort &aPort = videoPorts.at(i).getAudioOutputPort();
1979  LOG("Setting Audio Mode-(STBY- ACTIVE) Port name: %s by persistence to [%s]\r\n",aPort.getName().c_str(),aPort.getStereoMode(true).getName().c_str());
1980  try {
1981  if(isEASInProgress == IARM_BUS_SYS_MODE_EAS)
1982  {
1983  /* Force Stereo in EAS mode. */
1984  LOG("Force Stereo in EAS mode \r\n");
1986  }
1987  else
1988  {
1989  aPort.setStereoMode(aPort.getStereoMode(true).getName(),false);
1990  }
1991  }
1992  catch(...)
1993  {
1994  }
1995  }
1996  }
1997 
1998  /*LOG("Enabling the AV Ports [_SetAVPortsPowerState]\r\n");*/
1999  }
2000 
2001  }
2002  catch (...) {
2003  LOG("Exception Caught during [_SetAVPortsPowerState]\r\n");
2004  return 0;
2005  }
2006  return 0;
2007 }
2008 
2009 
2010 
2011 /**
2012  * @fn static IARM_Result_t _SysModeChange(void *arg){
2013  * @brief This function is a event handler which returns current system
2014  * mode using IARM. It returns mode as "NORMAL", "WAREHOUSE","EAS" or "UNKNOWN".
2015  *
2016  * @param[in] void pointer to void, containing IARM_Bus_CommonAPI_SysModeChange_Param_t data.
2017  *
2018  * @return variable of IARM_Result_t type.
2019  * @retval IARM_RESULT_SUCCESS On function completion.
2020  */
2021 static IARM_Result_t _SysModeChange(void *arg)
2022 {
2023  IARM_Bus_CommonAPI_SysModeChange_Param_t *param = (IARM_Bus_CommonAPI_SysModeChange_Param_t *)arg;
2024 
2025  __TIMESTAMP();printf("[PwrMgr] Recvd Sysmode Change::New mode --> %d,Old mode --> %d",param->newMode,param->oldMode);
2026 
2027  if (param->newMode == IARM_BUS_SYS_MODE_EAS) {
2028  isEASInProgress = IARM_BUS_SYS_MODE_EAS;
2029  }
2030  else if (param->newMode == IARM_BUS_SYS_MODE_NORMAL) {
2031  isEASInProgress = IARM_BUS_SYS_MODE_NORMAL;
2032  }
2033  return IARM_RESULT_SUCCESS;
2034 }
2035 
2036 #ifdef _ENABLE_FP_KEY_SENSITIVITY_IMPROVEMENT
2037 static void *_AsyncPowerTransition(void *)
2038 {
2039  PWRMgr_Settings_t *pSettings = &m_settings;
2040 
2041  while(1) {
2042  pthread_mutex_lock(&powerStateMutex);
2043  if (pSettings->powerState != targetState) {
2044 
2046  param.newState = targetState;
2047  _SetPowerState(&param);
2048  }
2049  else {
2050  /* goto sleep */
2051  pthread_cond_wait(&powerStateCond, &powerStateMutex);
2052  }
2053  pthread_mutex_unlock(&powerStateMutex);
2054  }
2055  pthread_exit(NULL);
2056 }
2057 
2058 static void _SetPowerStateAsync(IARM_Bus_PWRMgr_PowerState_t curState, IARM_Bus_PWRMgr_PowerState_t newState)
2059 {
2060  PWRMgr_Settings_t *pSettings = &m_settings;
2061 
2062  IARM_Result_t retCode = IARM_RESULT_SUCCESS;
2063 
2064  if (asyncPowerThreadId == NULL)
2065  {
2066  int err = pthread_create(&asyncPowerThreadId, NULL, _AsyncPowerTransition, NULL);
2067  if(err != 0){
2068  LOG("_AsyncPowerTransition thread create failed \r\n");
2069  }else {
2070  err = pthread_detach(asyncPowerThreadId);
2071  if(err != 0){
2072  LOG("_AsyncPowerTransition thread detach failed \r\n");
2073  }
2074  }
2075 
2076  }
2077 
2078  /* Awake the thread to check status */
2079  if (curState != newState) {
2080 
2081  LOG("PowerState Fast transitioning from %d to %d, while still in [%d]\r\n", curState, newState, pSettings->powerState);
2082 
2083  _SetLEDStatus(newState);
2084  transitionState = newState;
2085  pthread_mutex_lock(&powerStateMutex);
2086  if (targetState != newState) {
2087  targetState = newState;
2088  pthread_cond_signal(&powerStateCond);
2089  }
2090  pthread_mutex_unlock(&powerStateMutex);
2091  }
2092  else {
2093  LOG("Warning:PowerState is same as requested\r\n");
2094  }
2095 
2096  return;
2097 }
2098 #endif
2099 
2100 #ifndef NO_RF4CE
2101 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
2102 static void _ctrlmMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
2103 {
2104  if (eventId == CTRLM_RCU_IARM_EVENT_KEY_GHOST)
2105  {
2106  ctrlm_rcu_iarm_event_key_ghost_t* ghostEvent = (ctrlm_rcu_iarm_event_key_ghost_t*)data;
2107  if (ghostEvent != NULL)
2108  {
2109  if (ghostEvent->api_revision != CTRLM_RCU_IARM_BUS_API_REVISION)
2110  {
2111  LOG("CTRLM ghost key event: ERROR - Wrong CTRLM API revision - expected %d, event is %d!!",
2112  CTRLM_RCU_IARM_BUS_API_REVISION, ghostEvent->api_revision);
2113  return;
2114  }
2115  LOG("CTRLM ghost code event: network_id: %d, network_type: %d, controller_id: %d, ghost_code: %d.\n",
2116  ghostEvent->network_id, ghostEvent->network_type, ghostEvent->controller_id, ghostEvent->ghost_code);
2117  // Decide whether or not to set the power state - either POWER ghost code sets the state to ON.
2118  if ((ghostEvent->ghost_code == CTRLM_RCU_GHOST_CODE_POWER_OFF) ||
2119  (ghostEvent->ghost_code == CTRLM_RCU_GHOST_CODE_POWER_ON))
2120  {
2122  param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2123  LOG("CTRLM Setting Powerstate to ON.\n");
2124  _SetPowerState((void *)&param);
2125  }
2126  }
2127  else
2128  {
2129  LOG("CTRLM ghost code event: ERROR: NULL event data!!\n");
2130  }
2131  }
2132  else
2133  {
2134  LOG("CTRLM event handler: ERROR: bad event type %d!!\n", eventId);
2135  }
2136 }
2137 #else
2138 #ifdef RF4CE_GENMSO_API
2139 static void _rfMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
2140 {
2141 
2142  MSOBusAPI_Packet_t* busMsg;
2143  int statusCode;
2145 
2146  busMsg = (MSOBusAPI_Packet_t*)data;
2147 
2148  if(len != (busMsg->length + sizeof(MSOBusAPI_Packet_t) - sizeof(MSOBusAPI_Msg_t))) //Message size + header of packet
2149  {
2150  LOG("BusTestApplication: %i MsgIndication with wrong length rec:%d exp:%d\n",eventId,
2151  len, (busMsg->length + sizeof(MSOBusAPI_Packet_t) - sizeof(MSOBusAPI_Msg_t)));
2152  return;
2153  }
2154  //LOG("BusTestApplication: Message received: id:%d\n", busMsg->msgId);
2155  switch(busMsg->msgId)
2156  {
2157  case MSOBusAPI_MsgId_GhostCommand:
2158  {
2159  LOG("BusTestApplication: command code : id:%d\n", busMsg->msg.UserCommand.commandCode);
2160  if (busMsg->msg.UserCommand.commandCode == 1 || busMsg->msg.UserCommand.commandCode == 2)
2161  {
2162  param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2163  //LOG("Setting Powerstate to new=%d\r\n", param.newState);
2164  _SetPowerState((void *)&param);
2165  }
2166  break;
2167  }
2168  default:
2169  {
2170  //LOG("BusTestApplication: Message received: id:%d\n", busMsg->msgId);
2171  break;
2172  }
2173  }
2174  }
2175 
2176 #elif defined(RF4CE_API)
2177 static void _rf4ceMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
2178 {
2179 
2180  rf4ce_Packet_t* busMsg;
2181  int statusCode;
2183 
2184  busMsg = (rf4ce_Packet_t*)data;
2185 
2186  __TIMESTAMP();LOG("pwrMgr: RF4CE Msg indication event handler, msgId: 0x%X\n", (unsigned)busMsg->msgId);
2187  if (busMsg->msgId == rf4ce_MsgId_GhostCommand) {
2188  __TIMESTAMP();LOG("pwrMgr: RF4CE Ghost Command, msgId: 0x%X\n", (unsigned)busMsg->msg.UserCommand.commandCode);
2189  }
2190 
2191  if(len != (busMsg->length + sizeof(rf4ce_Packet_t) - sizeof(rf4ce_Msg_t))) //Message size + header of packet
2192  {
2193  LOG("BusTestApplication: %i MsgIndication with wrong length rec:%d exp:%d\n",eventId,
2194  len, (busMsg->length + sizeof(rf4ce_Packet_t) - sizeof(rf4ce_Msg_t)));
2195  return;
2196  }
2197  //LOG("BusTestApplication: Message received: id:%d\n", busMsg->msgId);
2198  switch(busMsg->msgId)
2199  {
2200  case rf4ce_MsgId_GhostCommand:
2201  {
2202  LOG("BusTestApplication: command code : id:%d\n", busMsg->msg.UserCommand.commandCode);
2203  if (busMsg->msg.UserCommand.commandCode == 1 || busMsg->msg.UserCommand.commandCode == 2)
2204  {
2205  param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2206  //LOG("Setting Powerstate to new=%d\r\n", param.newState);
2207  _SetPowerState((void *)&param);
2208  }
2209  break;
2210  }
2211  default:
2212  {
2213  //LOG("BusTestApplication: Message received: id:%d\n", busMsg->msgId);
2214  break;
2215  }
2216  }
2217 }
2218 #elif defined(RF4CE_GPMSO_API)
2219 static void _gpMessageHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
2220 {
2221 
2222  gpMSOBusAPI_Packet_t* busMsg;
2223  int statusCode;
2225 
2226  busMsg = (gpMSOBusAPI_Packet_t*)data;
2227 
2228  if(len != (busMsg->length + sizeof(gpMSOBusAPI_Packet_t) - sizeof(gpMSOBusAPI_Msg_t))) //Message size + header of packet
2229  {
2230  LOG("BusTestApplication: %i MsgIndication with wrong length rec:%d exp:%d\n",eventId,
2231  len, (busMsg->length + sizeof(gpMSOBusAPI_Packet_t) - sizeof(gpMSOBusAPI_Msg_t)));
2232  return;
2233  }
2234  //LOG("BusTestApplication: Message received: id:%d\n", busMsg->msgId);
2235  switch(busMsg->msgId)
2236  {
2237  case gpMSOBusAPI_MsgId_GhostCommand:
2238  {
2239  LOG("BusTestApplication: command code : id:%d\n", busMsg->msg.UserCommand.commandCode);
2240  if (busMsg->msg.UserCommand.commandCode == 1 || busMsg->msg.UserCommand.commandCode == 2)
2241  {
2242  param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON;
2243  //LOG("Setting Powerstate to new=%d\r\n", param.newState);
2244  _SetPowerState((void *)&param);
2245  }
2246  break;
2247  }
2248  default:
2249  {
2250  //LOG("BusTestApplication: Message received: id:%d\n", busMsg->msgId);
2251  break;
2252  }
2253  }
2254  }
2255 #else
2256 #warning "No RF4CE API defined"
2257 #endif
2258 #endif /* USE_UNIFIED_CONTROL_MGR_API_1 */
2259 #endif /* NO_RF4CE */
2260 
2261 static void _controlEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
2262 {
2265  int powerUp = 0;
2266 
2267  __TIMESTAMP();LOG("pwrMgr: Control event handler, key: 0x%X, src: 0x%X\n",
2268  (unsigned)irEventData->data.irkey.keyCode, (unsigned)irEventData->data.irkey.keySrc);
2269 
2270  _GetPowerState((void *)&powerState);
2271  if (powerState.curState != IARM_BUS_PWRMGR_POWERSTATE_ON) {
2272  int keySrc = irEventData->data.irkey.keySrc;
2273  switch(irEventData->data.irkey.keyCode) {
2274  case KED_VOLUMEUP:
2275  case KED_VOLUMEDOWN:
2276  case KED_MUTE:
2277  case KED_INPUTKEY:
2278  case KED_TVPOWER:
2279  if ((keySrc == IARM_BUS_IRMGR_KEYSRC_RF) ||
2280  (keySrc == IARM_BUS_IRMGR_KEYSRC_IR)) {
2281  powerUp = 1;
2282  }
2283  break;
2284 
2285  case KED_PUSH_TO_TALK:
2286  case KED_VOLUME_OPTIMIZE:
2287  if (keySrc == IARM_BUS_IRMGR_KEYSRC_IR) {
2288  powerUp = 1;
2289  }
2290  break;
2291  }
2292  if (powerUp) {
2293  irEventData->data.irkey.keyCode = KED_POWER;
2294  irEventData->data.irkey.keyType = KET_KEYUP;
2295  _irEventHandler(owner,eventId,(void*)irEventData,len);
2296  }
2297  }
2298 }
2299 
2300 #ifndef NO_RF4CE
2301 static void _speechEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
2302 {
2304  _GetPowerState((void *)&powerState);
2305  __TIMESTAMP();LOG("pwrMgr: Voice event handler, eventId: %d.\n", (int)eventId);
2306 #ifdef USE_UNIFIED_CONTROL_MGR_API_1
2307  if(powerState.curState != IARM_BUS_PWRMGR_POWERSTATE_ON &&
2308  (eventId == CTRLM_VOICE_IARM_EVENT_SESSION_BEGIN ||
2309  eventId == CTRLM_VOICE_IARM_EVENT_SESSION_ABORT ||
2310  eventId == CTRLM_VOICE_IARM_EVENT_SESSION_SHORT) )
2311 #else
2312 #ifdef USE_UNIFIED_RF4CE_MGR_API_4
2313  if(powerState.curState != IARM_BUS_PWRMGR_POWERSTATE_ON &&
2314  (eventId == VREX_MGR_IARM_EVENT_VOICE_BEGIN ||
2315  eventId == VREX_MGR_IARM_EVENT_VOICE_SESSION_ABORT ||
2316  eventId == VREX_MGR_IARM_EVENT_VOICE_SESSION_SHORT) )
2317 #else
2318  _SPEECH_EVENT *sEvent;
2320  sEvent = (_SPEECH_EVENT *)&vrexEventData->data.speechEvent;
2321  if(eventId == IARM_BUS_VREXMGR_EVENT_SPEECH && sEvent->type == IARM_BUS_VREXMGR_SPEECH_BEGIN && powerState.curState != IARM_BUS_PWRMGR_POWERSTATE_ON)
2322 #endif /* USE_UNIFIED_RF4CE_MGR_API_4 */
2323 #endif /* USE_UNIFIED_CONTROL_MGR_API_1 */
2324  {
2325  IARM_Bus_IRMgr_EventData_t irEventData;
2326  irEventData.data.irkey.keyCode = KED_POWER;
2327  irEventData.data.irkey.keyType = KET_KEYUP;
2328  _irEventHandler(owner,eventId,(void*)&irEventData,len);
2329  }
2330 }
2331 #endif /* NO_RF4CE */
2332 
2333 #ifdef ENABLE_DEEP_SLEEP
2334 static IARM_Result_t _SetDeepSleepTimeOut(void *arg)
2335 {
2337 
2338  if(param != NULL)
2339  {
2340  __TIMESTAMP();LOG("Deep sleep timeout set to : %d\r\n", param->timeout);
2341  deep_sleep_wakeup_timeout_sec = param->timeout;
2342  m_settings.deep_sleep_timeout = param->timeout;
2343  IsWakeupTimerSet = 1;
2344  _WriteSettings(m_settingsFile);
2345  return IARM_RESULT_SUCCESS;
2346  }
2347  return IARM_RESULT_IPCCORE_FAIL;
2348 }
2349 static void handleDeepsleepTimeoutWakeup (void * arg)
2350 {
2351  __TIMESTAMP();LOG("Entering %s \r\n", __FUNCTION__);
2353  param.timeout = deep_sleep_wakeup_timeout_sec;
2355  IARM_BUS_PWRMGR_EVENT_DEEPSLEEP_TIMEOUT, (void *)&param, sizeof(param));
2356 #if !defined (_DISABLE_SCHD_REBOOT_AT_DEEPSLEEP)
2357  __TIMESTAMP();LOG("Reboot the box due to Deep Sleep Timer Expiry : %d \r\n", param.timeout);
2358 #else
2359  /*Scheduled maintanace reboot is disabled for XiOne/Llama/Platco. Instead state will change to LIGHT_SLEEP*/
2361  PWRMgr_Settings_t *pSettings = &m_settings;
2362  __TIMESTAMP();LOG("deep_sleep_wakeup_fn: Set Device to light sleep on Deep Sleep timer expiry..\r\n");
2363  pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP;
2364  paramSetPwr.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP;
2365  _SetPowerState((void *)&paramSetPwr);
2366 #endif /*End of _DISABLE_SCHD_REBOOT_AT_DEEPSLEEP*/
2367 }
2368 
2369 static void* deepsleepTimeoutWakeupThread (void * arg)
2370 {
2371  __TIMESTAMP();LOG("Entering %s \r\n", __FUNCTION__);
2372  handleDeepsleepTimeoutWakeup(arg);
2373  pthread_exit(NULL);
2374 }
2375 
2376 static IARM_Result_t _handleDeepsleepTimeoutWakeup (void *arg)
2377 {
2378  IARM_Result_t retCode = IARM_RESULT_SUCCESS;
2379  //Deepsleep wakeup will take time and a low freq event, hence using detach thread approch here.
2380  pthread_t asyncDeepsleepTimeoutThreadId = 0;
2381  int err = pthread_create(&asyncDeepsleepTimeoutThreadId, NULL, deepsleepTimeoutWakeupThread, NULL);
2382  if(err != 0){
2383  __TIMESTAMP();LOG("handleDeepsleepTimeoutWakeup thread create failed \r\n");
2384  }else {
2385  err = pthread_detach(asyncDeepsleepTimeoutThreadId);
2386  if(err != 0){
2387  __TIMESTAMP();LOG("handleDeepsleepTimeoutWakeup thread detach failed \r\n");
2388  }
2389  }
2390  return retCode;
2391 }
2392 
2393 /* Wakeup the box after wakeup timeout for maintenance activities
2394  Reboot the box and entered to light sleep.
2395 */
2396 static gboolean deep_sleep_wakeup_fn(gpointer data)
2397 {
2398  uint32_t timeout = (uint32_t) difftime(time(NULL),timeAtDeepSleep);
2399 
2400  __TIMESTAMP();LOG("Sec Elapsed Since Deep Sleep : %d \r\n",timeout);
2401 
2402  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
2403  int dsStatus= 0;
2405  (char *)"GetDeepSleepStatus",
2406  (void *)&dsStatus,
2407  sizeof(dsStatus));
2408 
2409  if((DeepSleepStatus_InProgress != dsStatus) && (timeout >= deep_sleep_wakeup_timeout_sec))
2410  {
2411  //Calling synchronously here
2412  handleDeepsleepTimeoutWakeup (NULL);
2413  return FALSE;
2414  }
2415 return TRUE;
2416 }
2417 
2418 
2419 /* Put the box to Deep Sleep after timeout (configured for now + 1 hour)
2420  if box had restarted in deep sleep mode
2421 */
2422 static gboolean invoke_deep_sleep_on_bootup_timeout(gpointer data)
2423 {
2425  PWRMgr_Settings_t *pSettings = &m_settings;
2426 
2427  __TIMESTAMP();LOG("deep_sleep_thread : Set Device to Deep Sleep on Bootip Timer Expiry.. \r\n");
2428 
2429  /* Change the current state to standby and new state to Deep Sleep */
2430  pSettings->powerState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY;
2431  param.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP;
2432  _SetPowerState((void *)&param);
2433  return FALSE;
2434 }
2435 
2436 
2437 /* Get TZ diff
2438  Added For wakeup Time calculation based on TZ
2439 */
2440 // enum with Time Zone hours
2441 typedef enum _tzValue {
2442  tzHST11=11,
2443  tzHST11HDT=10,
2444  tzAKST=9,
2445  tzAKST09AKDT=8,
2446  tzPST08=8,
2447  tzPST08PDT=8,
2448  tzMST07=7,
2449  tzMST07MDT=6,
2450  tzCST06=6,
2451  tzCST06CDT=5,
2452  tzEST05=5,
2453  tzEST05EDT=4
2454 }tzValue;
2455 // Map to associate the Time Zone strings with TZ hours
2456 #include <map>
2457 static std::map<std::string, tzValue> _maptzValues;
2458 static void InitializeTimeZone();
2459 static uint32_t getTZDiffInSec()
2460 {
2461  uint32_t _TZDiffTime = 6*3600;
2462  IARM_Result_t iResult = IARM_RESULT_SUCCESS;
2463  tzValue value=tzCST06;
2464 
2465  /* Initialize the Time Zone */
2466  InitializeTimeZone();
2467 
2468  /* Get the Time Zone Pay Load from SysMgr */
2470  iResult = IARM_Bus_Call(IARM_BUS_SYSMGR_NAME,IARM_BUS_SYSMGR_API_GetSystemStates,(void *)&param,sizeof(param));
2471  if(iResult == IARM_RESULT_SUCCESS)
2472  {
2473  if (param.time_zone_available.error)
2474  {
2475  __TIMESTAMP();LOG("Failed to get the Time Zone Information from SysMgr \r\n");
2476  }
2477  else if (param.time_zone_available.state == 2)
2478  {
2479  if (strlen(param.time_zone_available.payload) > 1)
2480  {
2481  __TIMESTAMP();LOG("TZ Payload - %s",param.time_zone_available.payload);
2482  value = _maptzValues[param.time_zone_available.payload];
2483  _TZDiffTime = value * 3600;
2484 
2485  __TIMESTAMP();LOG("TZ value = %d\r\n",value);
2486  __TIMESTAMP();LOG("Time Zone in Sec = %d \r\n",_TZDiffTime);
2487  }
2488  }
2489  }
2490  return _TZDiffTime;
2491 }
2492 
2493 /* Get TZ diff
2494  Have Record of All US TZ as of now.
2495 */
2496 static void InitializeTimeZone()
2497 {
2498  _maptzValues["HST11"] = tzHST11;
2499  _maptzValues["HST11HDT,M3.2.0,M11.1.0"] = tzHST11HDT;
2500  _maptzValues["AKST"] = tzAKST;
2501  _maptzValues["AKST09AKDT,M3.2.0,M11.1.0"] = tzAKST09AKDT;
2502  _maptzValues["PST08"] = tzPST08;
2503  _maptzValues["PST08PDT,M3.2.0,M11.1.0"] = tzPST08PDT;
2504  _maptzValues["MST07"] = tzMST07;
2505  _maptzValues["MST07MDT,M3.2.0,M11.1.0"] = tzMST07MDT;
2506  _maptzValues["CST06"] = tzCST06;
2507  _maptzValues["CST06CDT,M3.2.0,M11.1.0"] = tzCST06CDT;
2508  _maptzValues["EST05"] = tzEST05;
2509  _maptzValues["EST05EDT,M3.2.0,M11.1.0"] = tzEST05EDT;
2510  //printf("_maptzValues contains %ld items \r\n",_maptzValues.size());
2511 }
2512 
2513 /* Get Wakeup timeout.
2514  Wakeup the box to do Maintenance related activities.
2515 */
2516 
2517 static uint32_t getWakeupTime()
2518 {
2519  time_t now,wakeup;
2520  struct tm wakeupTime;
2521  uint32_t wakeupTimeInSec = 0,getTZDiffTime = 0;
2522  uint32_t wakeupTimeInMin = 5;
2523  FILE *fpWT = NULL;
2524 
2525  /* Read the wakeup Time in Seconds from /tmp override
2526  else calculate the Wakeup time til 2AM */
2527  fpWT = fopen("/tmp/deepSleepWakeupTimer","r");
2528  if (NULL != fpWT)
2529  {
2530  if(0 > fscanf(fpWT,"%d",&wakeupTimeInMin))
2531  {
2532  __TIMESTAMP();LOG("Error: fscanf on wakeupTimeInSec failed");
2533  }
2534  else
2535  {
2536  wakeupTimeInSec = wakeupTimeInMin * 60 ;
2537  fclose (fpWT);
2538  __TIMESTAMP();LOG(" /tmp/ override Deep Sleep Wakeup Time is %d \r\n",wakeupTimeInSec);
2539  return wakeupTimeInSec;
2540  }
2541  fclose (fpWT);
2542  }
2543 
2544  /* curr time */
2545  time (&now);
2546 
2547  /* wakeup time */
2548  time (&wakeup);
2549  wakeupTime = *localtime (&wakeup);
2550 
2551  if (wakeupTime.tm_hour >=0 && wakeupTime.tm_hour < 2)
2552  {
2553  /*Calculate the wakeup time till 2 AM..*/
2554  wakeupTime.tm_hour = 2;
2555  wakeupTime.tm_min = 0;
2556  wakeupTime.tm_sec = 0;
2557  wakeupTimeInSec = difftime(mktime(&wakeupTime),now);
2558 
2559  }
2560  else
2561  {
2562  /*Calculate the wakeup time till midnight + 2 hours for 2 AM..*/
2563  wakeupTime.tm_hour = 23;
2564  wakeupTime.tm_min = 59;
2565  wakeupTime.tm_sec = 60;
2566  wakeupTimeInSec = difftime(mktime(&wakeupTime),now);
2567  wakeupTimeInSec = wakeupTimeInSec + 7200; // 7200sec for 2 hours
2568  }
2569 
2570  /* Add randomness to calculated value i.e between 2AM - 3AM
2571  for 1 hour window
2572  */
2573  srand(time(NULL));
2574  uint32_t randTimeInSec = (uint32_t)rand()%(3600) + 0; // for 1 hour window
2575  wakeupTimeInSec = wakeupTimeInSec + randTimeInSec;
2576  //printf ("randTimeInSec is : %d sec \r\n", randTimeInSec);
2577 
2578  __TIMESTAMP();LOG("Calculated Deep Sleep Wakeup Time Before TZ setting is %d Sec \r\n", wakeupTimeInSec);
2579  getTZDiffTime = getTZDiffInSec();
2580  wakeupTimeInSec = wakeupTimeInSec + getTZDiffTime;
2581  __TIMESTAMP();LOG("Calculated Deep Sleep Wakeup Time After TZ setting is %d Sec \r\n", wakeupTimeInSec);
2582 
2583  return wakeupTimeInSec;
2584 }
2585 
2586 #endif
2587 static IARM_Result_t _SetNetworkStandbyMode(void *arg)
2588 {
2590  uint32_t uiTimeout = 3; /*Timeout in seconds*/
2591  if(param != NULL)
2592  {
2593 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
2594  LOG("Setting network standbyMode: %s \r\n", param->bStandbyMode?("Enabled"):("Disabled"));
2595  nwStandbyMode_gs = param->bStandbyMode;
2596  m_settings.nwStandbyMode = param->bStandbyMode;
2597  _WriteSettings(m_settingsFile);
2598 
2599  IARM_Bus_PWRMgr_EventData_t _eventData;
2600  _eventData.data.bNetworkStandbyMode = m_settings.nwStandbyMode;
2601 
2603 
2604 #else
2605  LOG ("\nError _SetNetworkStandbyMode not implemented. standbyMode: %s", param->bStandbyMode?("Enabled"):("Disabled"));
2606 #endif
2607  return IARM_RESULT_SUCCESS;
2608  }
2609  return IARM_RESULT_IPCCORE_FAIL;
2610 }
2611 
2612 static IARM_Result_t _GetNetworkStandbyMode(void *arg)
2613 {
2615 
2616  if(param != NULL)
2617  {
2618 #ifdef ENABLE_LLAMA_PLATCO_SKY_XIONE
2619  param->bStandbyMode = m_settings.nwStandbyMode;
2620  LOG("Network standbyMode is: %s \r\n", param->bStandbyMode?("Enabled"):("Disabled"));
2621 #else
2622  LOG ("\nError _GetNetworkStandbyMode not implemented.");
2623 #endif
2624  return IARM_RESULT_SUCCESS;
2625  }
2626  return IARM_RESULT_IPCCORE_FAIL;
2627 }
2628 
2629 
2630 /** @} */
2631 /** @} */
IARM_BUS_PWRMGR_API_SetPowerState
#define IARM_BUS_PWRMGR_API_SetPowerState
Definition: pwrMgr.h:158
IARM_BUS_PWRMGR_NAME
#define IARM_BUS_PWRMGR_NAME
Definition: pwrMgr.h:54
_IARM_Bus_PWRMgr_SetPowerState_Param_t
Structure which holds the new powerstate to be set to the device.
Definition: pwrMgr.h:163
device::AudioOutputPort::enable
void enable()
This API is used to enable the Audio output port.
Definition: audioOutputPort.cpp:304
_IARM_Bus_PWRMgr_RebootParam_t
Structure to pass reboot reason argument with the reboot call.
Definition: pwrMgr.h:302
pwrMgrProductTraits::ux_controller
Definition: productTraits.h:72
PLAT_API_GetPowerState
int PLAT_API_GetPowerState(IARM_Bus_PWRMgr_PowerState_t *curState)
This function is used to get the CPE Power State.
PLAT_INIT
int PLAT_INIT(void)
Initialize the underlying Power Management module.
device::VideoOutputPort::getName
const std::string & getName() const
This API gets the name of the VideoOutputPort. The VideoOutputPort names can be HDMI,...
Definition: videoOutputPort.hpp:225
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
IARM_BUS_IRMGR_EVENT_IRKEY
@ IARM_BUS_IRMGR_EVENT_IRKEY
Definition: irMgr.h:220
_IARM_Bus_PWRMgr_StandbyVideoState_Param_t
Definition: pwrMgr.h:273
sysMgr.h
IARM-Bus Sys Manager Public API.
IARM_BUS_PWRMGR_API_Reboot
#define IARM_BUS_PWRMGR_API_Reboot
Definition: pwrMgr.h:307
dsHOST_SLEEP_MODE_DEEP
@ dsHOST_SLEEP_MODE_DEEP
Definition: dsTypes.h:922
IARM_BUS_IRMGR_KEYSRC_RF
@ IARM_BUS_IRMGR_KEYSRC_RF
Definition: irMgr.h:230
IARM_BUS_SYSMGR_NAME
#define IARM_BUS_SYSMGR_NAME
Definition: sysMgr.h:110
IARM_BUS_PWRMGR_API_UserFactoryReset
#define IARM_BUS_PWRMGR_API_UserFactoryReset
Definition: pwrMgr.h:191
pwrMgrInternal.h
_IARM_Bus_PWRMgr_GetPowerState_Param_t
Structure which holds the current power state of the CPE.
Definition: pwrMgr.h:173
dsSleepMode_t
enum _dsSleepMode_t dsSleepMode_t
device::Host::getVideoOutputPorts
List< VideoOutputPort > getVideoOutputPorts()
This API is used to get the list of the video output ports supported on the device....
Definition: host.cpp:285
device::AudioStereoMode::kStereo
static const int kStereo
Indicates audio mode of type stereo.
Definition: audioStereoMode.hpp:56
device::VideoOutputPort::isDisplayConnected
bool isDisplayConnected() const
This API is used to Check if the port is currently connected to any display device.
Definition: videoOutputPort.cpp:381
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
device::VideoOutputPort
Class extending enumerable to implement the videoooutputport interface.
Definition: videoOutputPort.hpp:59
_SysModeChange
static IARM_Result_t _SysModeChange(void *arg)
This function is a event handler which returns current system mode using IARM. It returns mode as "NO...
Definition: pwrMgr.c:2021
device::AudioOutputPort::getStereoMode
const AudioStereoMode & getStereoMode(bool usePersist=false)
This API is used to get the current stereo mode of the output port.
Definition: audioOutputPort.cpp:273
manager.hpp
It contains class referenced by manager.cpp file.
_PWRMgr_EventData_t
Structure which holds the event data.
Definition: pwrMgr.h:117
_IARM_Bus_PWRMgr_NetworkStandbyMode_Param_t
Definition: pwrMgr.h:283
IARM_BUS_PWRMGR_API_WareHouseReset
#define IARM_BUS_PWRMGR_API_WareHouseReset
Definition: pwrMgr.h:178
_IARM_Bus_PWRMgr_GetPowerStateBeforeReboot_Param_t::powerStateBeforeReboot
char powerStateBeforeReboot[(32)]
Definition: pwrMgr.h:293
IARM_BUS_PWRMGR_API_GetPowerState
#define IARM_BUS_PWRMGR_API_GetPowerState
Definition: pwrMgr.h:168
IARM_BUS_VREXMGR_NAME
#define IARM_BUS_VREXMGR_NAME
Definition: vrexMgr.h:99
_IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t::timeout
unsigned int timeout
Definition: pwrMgr.h:199
PLAT_API_SetPowerState
int PLAT_API_SetPowerState(IARM_Bus_PWRMgr_PowerState_t newState)
This API sets the CPE Power State.
device::AudioOutputPort::getName
const std::string & getName() const
This API gets the name of the AudioOutputPort. The AudioOutputPort names can be IDLR,...
Definition: audioOutputPort.hpp:105
device::Host::getAudioOutputPorts
List< AudioOutputPort > getAudioOutputPorts()
This API is used to get the list of the audio output ports supported on the device....
Definition: host.cpp:309
frontPanelIndicator.hpp
Structures and classes for front panel indicator are defined here.
IARM_Bus_RegisterEvent
IARM_Result_t IARM_Bus_RegisterEvent(IARM_EventId_t maxEventId)
This API is used to register all the events that are published by the application.
IARM_BUS_PWRMGR_EVENT_WAREHOUSEOPS_STATUSCHANGED
@ IARM_BUS_PWRMGR_EVENT_WAREHOUSEOPS_STATUSCHANGED
Definition: pwrMgr.h:65
IARM_Bus_RegisterEventHandler
IARM_Result_t IARM_Bus_RegisterEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
This API register to listen to event and provide the callback function for event notification....
Definition: iarmMgrMocks.cpp:43
vrexMgr.h
IARM-Bus VREX Manager Public API.
IARM_BUS_PWRMGR_API_handleDeepsleepTimeoutWakeup
#define IARM_BUS_PWRMGR_API_handleDeepsleepTimeoutWakeup
Definition: pwrMgr.h:323
_IARM_Bus_PWRMgr_GetPowerState_Param_t::curState
IARM_Bus_PWRMgr_PowerState_t curState
Definition: pwrMgr.h:174
_IARM_Bus_SYSMgr_GetSystemStates_Param_t
Definition: sysMgr.h:299
IARM_Bus_RegisterCall
IARM_Result_t IARM_Bus_RegisterCall(const char *methodName, IARM_BusCall_t handler)
This API is used to register an RPC method that can be invoked by other applications.
device::List::size
size_t size()
This function gets the size of the container.
Definition: list.hpp:118
IARM_Bus_RemoveEventHandler
IARM_Result_t IARM_Bus_RemoveEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
Remove specific handler registered for the given event.
Definition: iarmMgrMocks.cpp:50
device::AudioOutputPort
Class extending Enumerable to implement the audiooutputport interface.
Definition: audioOutputPort.hpp:60
_IARM_Bus_PWRMgr_NetworkStandbyMode_Param_t::bStandbyMode
bool bStandbyMode
Definition: pwrMgr.h:284
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
IARMCEC_SendCECActiveSource
bool IARMCEC_SendCECActiveSource(bool bCecLocalLogic, int keyType, int keyCode)
Utility function to send ActiveSource CEC event to TV.
Definition: iarmcec.c:29
IARM_BUS_DSMGR_EVENT_SLEEP_MODE_CHANGED
@ IARM_BUS_DSMGR_EVENT_SLEEP_MODE_CHANGED
Definition: dsMgr.h:74
_IARM_BUS_SYSMgr_EventData_t
Definition: sysMgr.h:229
device::Manager::Initialize
static void Initialize()
This API is used to initialize the Device Setting module. Each API should be called by any client of ...
Definition: manager.cpp:97
_IARM_BUS_PWRMgr_WareHouseOpn_EventData_t::wareHouseOpn
IARM_Bus_PWRMgr_WareHouseOps_t wareHouseOpn
Definition: pwrMgr.h:151
_SPEECH_EVENT
Definition: vrexMgr.h:150
IARM_Bus_BroadcastEvent
IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
This API is used to publish an Asynchronous event to all IARM client registered for this perticular e...
IARM_BUS_PWRMGR_API_SetDeepSleepTimeOut
#define IARM_BUS_PWRMGR_API_SetDeepSleepTimeOut
Definition: pwrMgr.h:193
device::Host::getPreferredSleepMode
SleepMode getPreferredSleepMode()
This API is used to gets the Preferred sleep Mode and implements the low power mode for RDK platform....
Definition: host.cpp:422
libIBus.h
RDK IARM-Bus API Declarations.
IARM_BUS_IRMGR_NAME
#define IARM_BUS_IRMGR_NAME
Definition: irMgr.h:216
_UIMgr_Settings_t
Definition: pwrMgr.c:140
IARM_Bus_PWRMgr_WareHouseOps_t
enum _IARM_Bus_PWRMgr_WareHouseOps_t IARM_Bus_PWRMgr_WareHouseOps_t
Enumerator which represents the possible warehouse ops.
_IARM_Bus_PWRMgr_WareHouseReset_Param_t::suppressReboot
bool suppressReboot
Definition: pwrMgr.h:184
_PWRMgr_LED_Settings_t
Definition: pwrMgr.c:113
IARM_BUS_PWRMGR_EVENT_MODECHANGED
@ IARM_BUS_PWRMGR_EVENT_MODECHANGED
Definition: pwrMgr.h:60
IARMCEC_SendCECImageViewOn
bool IARMCEC_SendCECImageViewOn(bool bCecLocalLogic)
Utility function to send ImageViewOn CEC event to TV.
Definition: iarmcec.c:91
_PWRMgr_Settings_t
Definition: pwrMgr.c:118
IARM_BUS_PWRMGR_EVENT_MAX
@ IARM_BUS_PWRMGR_EVENT_MAX
Definition: pwrMgr.h:67
PLAT_TERM
void PLAT_TERM(void)
This API terminates the power management module.
PWRMGR_MAX_VIDEO_PORT_NAME_LENGTH
#define PWRMGR_MAX_VIDEO_PORT_NAME_LENGTH
Structure which holds the setting for whether video port is enabled in standby.
Definition: pwrMgr.h:272
device::DSConstant::getName
virtual const std::string & getName() const
This function is used to the get the data member name.
Definition: dsConstant.hpp:141
IARM_BUS_IRMGR_KEYSRC_IR
@ IARM_BUS_IRMGR_KEYSRC_IR
Definition: irMgr.h:229
_IARM_Bus_PWRMgr_GetPowerStateBeforeReboot_Param_t
Structure which holds the power state before reboot of the CPE.
Definition: pwrMgr.h:292
PWRMgr_Standby_Video_State_t
Definition: pwrMgr.c:153
device::Exception
This class handles exceptions occurring in DS module.
Definition: exception.hpp:52
device::VideoOutputPort::getAudioOutputPort
AudioOutputPort & getAudioOutputPort()
This API is used to get the audio output port connected to the video output port. This connection is ...
Definition: videoOutputPort.cpp:280
device::FrontPanelIndicator::getInstance
static FrontPanelIndicator & getInstance(int id)
This function gets the FrontPanelIndicator instance corresponding to the id parameter,...
Definition: frontPanelIndicator.cpp:208
keyType
Definition: reset.c:85
device::Manager::DeInitialize
static void DeInitialize()
This API is used to deinitialize the device settings module. DeInitialize() must be called to release...
Definition: manager.cpp:138
device::Host::getVideoOutputPort
VideoOutputPort & getVideoOutputPort(const std::string &name)
This API is used to get the reference to the video output port by its name. The name of the port must...
Definition: host.cpp:350
IARM_BUS_PWRMGR_API_GetPowerStateBeforeReboot
#define IARM_BUS_PWRMGR_API_GetPowerStateBeforeReboot
Definition: pwrMgr.h:288
irMgr.h
IARM-Bus IR Manager API.
device::Host::getInstance
static Host & getInstance(void)
This API is used to get a reference to the single instance of the Host object.
Definition: host.cpp:88
device::VideoOutputPort::enable
void enable()
This API is used to enable the video output port.
Definition: videoOutputPort.cpp:552
_IARM_BUS_PWRMgr_WareHouseOpn_EventData_t::status
IARM_Bus_PWRMgr_WareHouseOpsStatus_t status
Definition: pwrMgr.h:152
IARM_BUS_DEEPSLEEPMGR_NAME
#define IARM_BUS_DEEPSLEEPMGR_NAME
Definition: deepSleepMgr.h:61
_IRMgr_EventData_t
Definition: irMgr.h:235
dsHOST_SLEEP_MODE_LIGHT
@ dsHOST_SLEEP_MODE_LIGHT
Definition: dsTypes.h:921
device::List< device::VideoOutputPort >
DeepSleepStatus_InProgress
@ DeepSleepStatus_InProgress
Definition: deepSleepMgr.h:66
IARM_BUS_PWRMGR_EVENT_DEEPSLEEP_TIMEOUT
@ IARM_BUS_PWRMGR_EVENT_DEEPSLEEP_TIMEOUT
Definition: pwrMgr.h:61
IARM_BUS_PWRMGR_API_ColdFactoryReset
#define IARM_BUS_PWRMGR_API_ColdFactoryReset
Definition: pwrMgr.h:189
IARM_Bus_Connect
IARM_Result_t IARM_Bus_Connect(void)
This API is used to connect application to the IARM bus daemon. After connected, the application can ...
Definition: iarmMgrMocks.cpp:33
_IARM_BUS_PWRMgr_DeepSleepTimeout_EventData_t
Structure which holds the Deep sleep timeout value.
Definition: pwrMgr.h:143
_IARM_BUS_VREXMgr_EventData_t
Definition: vrexMgr.h:179
_IARM_Bus_PWRMgr_SetPowerState_Param_t::newState
IARM_Bus_PWRMgr_PowerState_t newState
Definition: pwrMgr.h:164
device::AudioOutputPort::setStereoMode
void setStereoMode(const int mode, const bool toPersist=true)
This API is used to set the stereo mode to be used in a given audio port.If toPersist is true,...
Definition: audioOutputPort.cpp:1412
_IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t
Structure which holds the timeout value to set for Deep sleep.
Definition: pwrMgr.h:198
_IARM_BUS_PWRMgr_WareHouseOpn_EventData_t
Structure which holds warehouse opn status value.
Definition: pwrMgr.h:150
_IARM_Bus_PWRMgr_WareHouseReset_Param_t
Structure which holds the ware house reset time.
Definition: pwrMgr.h:183
_IARM_Bus_PWRMgr_SetPowerState_Param_t::keyCode
int keyCode
Definition: pwrMgr.h:165
_IARM_BUS_PWRMgr_DeepSleepTimeout_EventData_t::timeout
unsigned int timeout
Definition: pwrMgr.h:144
IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED
@ IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED
Definition: pwrMgr.h:66
IARM_Bus_Init
IARM_Result_t IARM_Bus_Init(const char *name)
This API is used to initialize the IARM-Bus library.
Definition: iarmMgrMocks.cpp:38
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
device::FrontPanelIndicator::setState
void setState(const bool &enable)
This API is used to enable or disable the front panel indicator.
Definition: frontPanelIndicator.cpp:350
device::DSConstant::getId
virtual int getId() const
This function is used to get the id.
Definition: dsConstant.hpp:130
IARM_BUS_PWRMGR_API_FactoryReset
#define IARM_BUS_PWRMGR_API_FactoryReset
Definition: pwrMgr.h:190
device::VideoOutputPort::disable
void disable()
This API is used to disable the Audio output port.
Definition: videoOutputPort.cpp:567
_DSMgr_EventData_t
Definition: dsMgr.h:81
sleepMode.hpp
This file defines SleepMode class for device settings.
IARM_BUS_SYSMGR_API_GetSystemStates
#define IARM_BUS_SYSMGR_API_GetSystemStates
Definition: sysMgr.h:284