24 #include "pwrlogger.h"
27 #ifdef SLEEPTIMER_USE_CECSTANDBY
28 #include "CecIARMBusMgr.h"
30 #include "safec_lib.h"
32 static GMainLoop *mainloop = NULL;
33 static guint timerSource = 0;
34 static time_t timerEnd = 0;
35 static pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
36 #define LOCK() pthread_mutex_lock(&_lock)
37 #define UNLOCK() pthread_mutex_unlock(&_lock)
39 #ifdef SLEEPTIMER_USE_CECSTANDBY
40 static void SendCECStandby(
void)
44 unsigned char buf[] = {0x30, 0x36};
45 memset(&dataToSend, 0,
sizeof(dataToSend));
46 dataToSend.length =
sizeof(buf);
47 rc = memcpy_s(dataToSend.data,
sizeof(dataToSend.data), buf, dataToSend.length);
52 LOG(
"SleepTimer send CEC Standby\r\n");
57 static gboolean _onSleepTimerFire(
void *)
60 LOG(
"SleepTimer %d start at %ld, fired at %ld, set standby\r\n", timerSource, timerEnd, time(NULL));
64 #ifdef SLEEPTIMER_USE_CECSTANDBY
67 LOG(
"No STANDBY action implemented\r\n");
72 static IARM_Result_t _SetSleepTimer(
void *arg)
79 if (param->
start == 1) {
81 timerEnd += (time_t)param->
time;
82 LOG(
"SleepTimer (re)set :%.3f, curr source=%d, to fire at %ld\r\n", param->
time, timerSource, timerEnd);
84 g_source_remove(timerSource);
87 timerSource = g_timeout_add_seconds((guint)(param->
time), _onSleepTimerFire, NULL);
89 else if (param->
start == 0) {
90 LOG(
"SleepTimer %d cancelled\r\n", timerSource);
92 g_source_remove(timerSource);
98 return IARM_RESULT_SUCCESS;
100 return IARM_RESULT_IPCCORE_FAIL;
103 static IARM_Result_t _GetSleepTimer(
void *arg)
110 time_t now = time(NULL);
111 param->
time = (double)((now < timerEnd) ? (timerEnd - now) :0);
115 LOG(
"SleepTimer %d has %.3lf remaining\r\n", param->
start, param->
time);
116 return IARM_RESULT_SUCCESS;
119 void IARM_Bus_PWRMGR_RegisterSleepTimerAPIs(
void *context)
121 LOG(
"SleepTimer PwrMgr register APIs\r\n");
122 mainloop = (GMainLoop*)context;