RDK Documentation (Open Sourced RDK Components)
pwrstate_notifier.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 #include <stdio.h>
21 #include <stdint.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <glib.h>
25 #include <pthread.h>
26 #include <unistd.h>
27 #include <signal.h>
28 
29 #include "libIBus.h"
30 #include "sysMgr.h"
31 #include "libIBusDaemon.h"
32 #include "irMgr.h"
33 #include "comcastIrKeyCodes.h"
34 #include "pwrMgr.h"
35 #include "pwrlogger.h"
36 
37 #define IARM_POWER_EVENT "pwrEvent"
38 
39 /** @brief This API handles power mode change events received from power manager.
40  *
41  * @param[in] owner owner of the event
42  * @param[in] eventId power manager event ID
43  * @param[in] data event data
44  * @param[in] len event size
45  */
46 void powerEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
47 {
48  if (data == NULL)
49  {
50  return;
51  }
52  /*
53  switch(eventId)
54  {
55  case IARM_BUS_PWRMGR_EVENT_MODECHANGED:
56  {
57  IARM_Bus_PWRMgr_EventData_t *param = (IARM_Bus_PWRMgr_EventData_t *)data;
58  printf("Event IARM_BUS_PWRMGR_EVENT_MODECHANGED: State Changed %d -- > %d\n",
59  param->data.state.curState, param->data.state.newState);
60  switch(param->data.state.newState)
61  {
62  case IARM_BUS_PWRMGR_POWERSTATE_ON:
63  {
64  FILE *fd = NULL;
65  char buffer[80] = {0};
66  const char* filename = "/tmp/.fwdnld.pid" ;
67  fd = fopen(filename, "r");
68  if (fd == NULL)
69  {
70  printf("Error in opening script file \n");
71  return;
72  }
73  fgets(buffer,80,fd);
74  int pid=atoi(buffer);
75  kill(pid, SIGTERM);
76  fclose(fd);
77  }
78  break;
79 
80  default:
81  break;
82  }
83  }
84  break;
85 
86  default:
87  break;
88  }*/
89  return;
90 }
91 
92 
93 /**
94  * @brief To Register required IARM event handlers with appropriate callback function to handle the event.
95  */
96 int init_event_handler()
97 {
98  IARM_Bus_Init(IARM_POWER_EVENT);
99  printf("SUCCESS: IARM_Bus_Init done!\n");
100 
102  printf("SUCCESS: IARM_Bus_Connect done!\n");
103 
104 
106  {
108  return -1;
109  }
110 
111  return 0;
112 }
113 
114 /**
115  * @brief This API UnRegister IARM event handlers in order to release bus-facing resources.
116  */
117 int term_event_handler()
118 {
120  printf("Successfully terminated all event handlers\n");
121  return 0;
122 }
123 
124 int main(int argc, char *argv[])
125 {
126  GMainLoop * main_loop = g_main_loop_new(NULL, false);
127 
128  if(0 != init_event_handler())
129  {
130  printf("Error: Initializing IARM event handler failed!\n");
131  return -1;
132  }
133 
134  printf("SUCCESS: Initialized IARM event handler!\n");
135 
136  /*Enter event loop */
137  g_main_loop_run(main_loop);
138  g_main_loop_unref(main_loop);
139 
140  term_event_handler();
141 
142  printf("Power Mode Change Client Exiting\n");
143 
144  return 0;
145 }
146 
IARM_BUS_PWRMGR_NAME
#define IARM_BUS_PWRMGR_NAME
Definition: pwrMgr.h:54
sysMgr.h
IARM-Bus Sys Manager Public API.
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
libIBus.h
RDK IARM-Bus API Declarations.
IARM_BUS_PWRMGR_EVENT_MODECHANGED
@ IARM_BUS_PWRMGR_EVENT_MODECHANGED
Definition: pwrMgr.h:60
pwrMgr.h
IARM-Bus Power Manager Public API.
irMgr.h
IARM-Bus IR Manager API.
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
powerEventHandler
void powerEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
This API handles power mode change events received from power manager.
Definition: ledmgrmain.cpp:171
IARM_Bus_UnRegisterEventHandler
IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char *ownerName, IARM_EventId_t eventId)
This API is used to Remove ALL handlers registered for the given event. This API remove the all the e...
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