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