37 #include <semaphore.h>
44 #include "libIBusDaemon.h"
46 #include "comcastIrKeyCodes.h"
52 #include "ledmgr_types.hpp"
68 #define HANDLE(event) case event:\
69 std::cout<<"Detected event "<<#event<<std::endl;\
74 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CHANNELMAP);
75 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DISCONNECTMGR);
76 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_TUNEREADY);
77 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_EXIT_OK);
78 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CMAC);
79 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_MOTO_ENTITLEMENT);
80 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_MOTO_HRV_RX);
81 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CARD_CISCO_STATUS);
82 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_VIDEO_PRESENTING);
83 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_HDMI_OUT);
84 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_HDCP_ENABLED);
85 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_HDMI_EDID_READ);
86 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_DWNLD);
87 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_TIME_SOURCE);
88 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE);
89 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CA_SYSTEM);
90 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_ESTB_IP);
91 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_ECM_IP);
92 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_LAN_IP);
93 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_MOCA);
94 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DOCSIS);
95 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DSG_BROADCAST_CHANNEL);
96 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL);
97 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD);
98 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_DWNLD);
99 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CVR_SUBSYSTEM);
100 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DOWNLOAD);
101 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_VOD_AD);
102 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DAC_INIT_TIMESTAMP);
103 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_SERIAL_NO);
104 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_ECM_MAC);
105 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DAC_ID);
106 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_PLANT_ID);
107 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_STB_SERIAL_NO);
108 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_BOOTUP);
109 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_GATEWAY_CONNECTION);
110 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_DST_OFFSET);
111 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_RF_CONNECTED);
112 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_PARTNERID_CHANGE);
113 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_IP_MODE);
114 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_LP_CONNECTION_RESET);
115 HANDLE(IARM_BUS_SYSMGR_SYSSTATE_RWS_CONNECTION_RESET);
127 using namespace device;
128 static bool isVeryBright =
true;
129 if(
true == isVeryBright)
132 isVeryBright =
false;
133 INFO(
"Dimming the light\n");
139 INFO(
"Setting full brightness\n");
150 void keyEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
152 if( IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP != ledMgr::getInstance().getPowerState() )
155 ledMgr::getInstance().
handleKeyPress(irEventData->data.irkey.keyCode, irEventData->data.irkey.keyType);
158 INFO(
"power state is deepsleep, handleKeyPress not invoked");
177 ledMgr::getInstance().
setPowerState(eventData->data.state.newState);
178 INFO(
"Detected power status change to 0x%x\n", eventData->data.state.newState);
182 if(0 <= eventData->data.reset_sequence_progress)
184 INFO(
"Reset sequence %d.\n", eventData->data.reset_sequence_progress);
185 ledMgr::getInstance().handleDeviceReset(eventData->data.reset_sequence_progress);
189 INFO(
"Exit reset sequence.\n");
190 ledMgr::getInstance().handleDeviceResetAbort();
206 IARM_Bus_CommonAPI_SysModeChange_Param_t *param = (IARM_Bus_CommonAPI_SysModeChange_Param_t *)arg;
208 return IARM_RESULT_SUCCESS;
218 void sysEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
221 IARM_Bus_SYSMgr_SystemState_t stateId = sysEventData->data.systemStates.stateId;
226 case IARM_BUS_SYSMGR_SYSSTATE_CHANNELMAP:
228 case IARM_BUS_SYSMGR_SYSSTATE_DISCONNECTMGR:
230 case IARM_BUS_SYSMGR_SYSSTATE_TUNEREADY:
232 case IARM_BUS_SYSMGR_SYSSTATE_EXIT_OK:
234 case IARM_BUS_SYSMGR_SYSSTATE_CMAC:
236 case IARM_BUS_SYSMGR_SYSSTATE_MOTO_ENTITLEMENT:
238 case IARM_BUS_SYSMGR_SYSSTATE_MOTO_HRV_RX:
240 case IARM_BUS_SYSMGR_SYSSTATE_CARD_CISCO_STATUS:
242 case IARM_BUS_SYSMGR_SYSSTATE_VIDEO_PRESENTING:
244 case IARM_BUS_SYSMGR_SYSSTATE_HDMI_OUT:
246 case IARM_BUS_SYSMGR_SYSSTATE_HDCP_ENABLED:
248 case IARM_BUS_SYSMGR_SYSSTATE_HDMI_EDID_READ:
250 case IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_DWNLD:
251 ledMgr::getInstance().handleCDLEvents(sysEventData->data.systemStates.state);
253 case IARM_BUS_SYSMGR_SYSSTATE_TIME_SOURCE:
255 case IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE:
257 case IARM_BUS_SYSMGR_SYSSTATE_CA_SYSTEM:
259 case IARM_BUS_SYSMGR_SYSSTATE_ESTB_IP:
261 case IARM_BUS_SYSMGR_SYSSTATE_ECM_IP:
263 case IARM_BUS_SYSMGR_SYSSTATE_LAN_IP:
265 case IARM_BUS_SYSMGR_SYSSTATE_MOCA:
267 case IARM_BUS_SYSMGR_SYSSTATE_DOCSIS:
269 case IARM_BUS_SYSMGR_SYSSTATE_DSG_BROADCAST_CHANNEL:
271 case IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL:
273 case IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD:
275 case IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_DWNLD:
277 case IARM_BUS_SYSMGR_SYSSTATE_CVR_SUBSYSTEM:
279 case IARM_BUS_SYSMGR_SYSSTATE_DOWNLOAD:
281 case IARM_BUS_SYSMGR_SYSSTATE_VOD_AD:
283 case IARM_BUS_SYSMGR_SYSSTATE_DAC_INIT_TIMESTAMP:
285 case IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_SERIAL_NO:
287 case IARM_BUS_SYSMGR_SYSSTATE_ECM_MAC:
289 case IARM_BUS_SYSMGR_SYSSTATE_DAC_ID:
291 case IARM_BUS_SYSMGR_SYSSTATE_PLANT_ID:
293 case IARM_BUS_SYSMGR_SYSSTATE_STB_SERIAL_NO:
295 case IARM_BUS_SYSMGR_SYSSTATE_BOOTUP:
297 case IARM_BUS_SYSMGR_SYSSTATE_GATEWAY_CONNECTION:
300 case IARM_BUS_SYSMGR_SYSSTATE_DST_OFFSET:
302 case IARM_BUS_SYSMGR_SYSSTATE_RF_CONNECTED:
304 case IARM_BUS_SYSMGR_SYSSTATE_PARTNERID_CHANGE:
306 case IARM_BUS_SYSMGR_SYSSTATE_IP_MODE:
308 case IARM_BUS_SYSMGR_SYSSTATE_LP_CONNECTION_RESET:
310 case IARM_BUS_SYSMGR_SYSSTATE_RWS_CONNECTION_RESET:
343 ledMgr::getInstance().
setPowerState(power_query_arg.curState);
350 INFO(
"Successfully initialized event handlers\n");
363 ERROR(
"Error initializing event handlers\n");
376 INFO(
"Successfully terminated all event handlers\n");
386 INFO(
"1. Enable power\n");
387 INFO(
"2. Disable power\n");
388 INFO(
"3. Cycle power through colours\n");
389 INFO(
"4. 4 slow blinks\n");
390 INFO(
"5. 4 fast blinks\n");
391 INFO(
"6. Simulate reset.\n");
392 INFO(
"7. Simulate reset abort\n");
402 int singleExecution = 0;
408 INFO(
"Enter command:\n");
409 if(!(std::cin >> choice))
413 cin.ignore(10000,
'\n');
419 choice = *((
int *)ptr);
420 cout <<
"Choice is : "<<choice<<endl;
433 ERROR(
"Unimplemented.\n");
444 for(
int i = 1; i < 6; i++)
446 eventData.data.reset_sequence_progress = i;
455 for(
int i = 1; i < 3; i++)
457 eventData.data.reset_sequence_progress = i;
461 eventData.data.reset_sequence_progress = -1;
467 ERROR(
"Unknown option.\n");
477 static bool drop_root()
479 bool ret =
false,retval =
false;
480 cap_user appcaps = {{0, 0, 0,
'\0', 0, 0, 0,
'\0'}};
481 ret = isBlocklisted();
484 INFO(
"NonRoot feature is disabled\n");
488 INFO(
"NonRoot feature is enabled\n");
490 appcaps.user_name = NULL;
491 if(init_capability() != NULL) {
492 if(drop_root_caps(&appcaps) != -1) {
493 if(update_process_caps(&appcaps) != -1) {
494 read_capability(&appcaps);
503 int main(
int argc,
char *argv[])
506 INFO(
"ledmgr is running\n");
509 ERROR(
"drop_root function failed!\n");
511 if(0 != sem_init(&g_app_done_sem, 0, 0))
513 ERROR(
"Could not initialize semaphore!\n");
516 GMainLoop * main_loop = g_main_loop_new(NULL,
false);
523 ERROR(
"Error initializing event handlers!\n");
526 INFO(
"Successfully initialized event handlers\n");
536 ERROR(
"Could not launch command line interface.\n");
542 int stcmp_result = strcmp(argv[1],
"--CLI");
543 if (0 == stcmp_result)
546 int arg = strtol(argv[2],NULL,10);
550 ERROR(
"Could not launch command line interface.\n");
556 g_main_loop_run(main_loop);
557 g_main_loop_unref(main_loop);
558 sem_wait(&g_app_done_sem);