diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 77d1d6b..0000000 --- a/.gitignore +++ /dev/null @@ -1,58 +0,0 @@ -# http://www.gnu.org/software/automake - -Makefile.in -/ar-lib -/mdate-sh -/py-compile -/test-driver -/ylwrap -.deps/ -.dirstamp - -# http://www.gnu.org/software/autoconf - -autom4te.cache -/autoscan.log -/autoscan-*.log -/aclocal.m4 -/compile -/config.cache -/config.guess -/config.h.in -/config.log -/config.status -/config.sub -/configure -/configure.scan -/depcomp -/install-sh -/missing -/stamp-h1 - -# https://www.gnu.org/software/libtool/ - -/ltmain.sh - -# http://www.gnu.org/software/texinfo - -/texinfo.tex - -# http://www.gnu.org/software/m4/ - -m4/libtool.m4 -m4/ltoptions.m4 -m4/ltsugar.m4 -m4/ltversion.m4 -m4/lt~obsolete.m4 - -# Generated Makefile -# (meta build system like autotools, -# can automatically generate from config.status script -# (which is called by configure script)) -# Makefile - -cfg - -# clangd -compile_commands.json -.cache diff --git a/Makefile.am b/Makefile.am index bd0c328..50203e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,6 @@ AM_CFLAGS = \ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs/rdmmgr \ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs/receiver \ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs/sysmgr \ - -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/WPEFramework/powercontroller \ -L$(PKG_CONFIG_SYSROOT_DIR)/usr/lib/ @@ -42,10 +41,10 @@ mfr_util_SOURCES = mfr-utils/sys_mfr_utils.c mfr_util_LDADD = -lIARMBus QueryPowerState_SOURCES=iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c -QueryPowerState_LDADD = $(DIRECT_LIBS) $(FUSION_LIBS) $(GLIB_LIBS) $(DBUS_LIBS) -lWPEFrameworkPowerController +QueryPowerState_LDADD = $(DIRECT_LIBS) $(FUSION_LIBS) $(GLIB_LIBS) -lIARMBus $(DBUS_LIBS) SetPowerState_SOURCES=iarm_set_powerstate/IARM_BUS_SetPowerStatus.c -SetPowerState_LDADD = -ldbus-1 -lstdc++ -lpthread -lWPEFrameworkPowerController +SetPowerState_LDADD = -ldbus-1 -lstdc++ -lIARMBus -lpthread keySimulator_SOURCES=key_simulator/IARM_BUS_UIEventSimulator.c key_simulator/uinput.c keySimulator_LDADD = $(GLIB_LIBS) -lIARMBus $(DBUS_LIBS) diff --git a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c index 0550d61..17b3440 100644 --- a/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c +++ b/iarm_query_powerstate/IARM_Bus_CheckPowerStatus.c @@ -15,133 +15,134 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ +*/ +#include #include +#include #include -#include -#include -#include #include - -// This include is still required for data types to read cached power status residing in /opt/uimgr_settings.bin -// TODO: after IARM PwrMgr logic is moved to PowerManager plugin refactor this code and remove this header file too. +#include +#include +#include "libIBus.h" #include "pwrMgr.h" -#include "power_controller.h" #define PADDING_SIZE 32 /*LED settings*/ -typedef struct _PWRMgr_LED_Settings_t { +typedef struct _PWRMgr_LED_Settings_t{ unsigned int brightness; unsigned int color; -} PWRMgr_LED_Settings_t; +}PWRMgr_LED_Settings_t; typedef struct _PWRMgr_Settings_t { uint32_t magic; uint32_t version; uint32_t length; IARM_Bus_PWRMgr_PowerState_t powerState; - PWRMgr_LED_Settings_t ledSettings; - uint32_t deep_sleep_timeout; + PWRMgr_LED_Settings_t ledSettings; + uint32_t deep_sleep_timeout; char padding[PADDING_SIZE]; } PWRMgr_Settings_t; -void usage() +void usage () { - printf("\nUsage: 'QueryPowerState [CMD]'\n"); - printf("\tCMDs are,\n"); - printf("\t\t -h -> Help\n"); - printf("\t\t -c -> Box state from PowerManager plugin\n"); - printf("\t\t No CMD will read the iARM state from '/opt'\n"); - - printf("\n\tOutput will be,\n"); - printf("\t\t\t ON -> Box is in Active Mode\n"); - printf("\t\t\t STANDBY -> Box is in Standby Mode\n"); - printf("\t\t\t LIGHTSLEEP -> Box is in Light Sleep Standby Mode\n"); - printf("\t\t\t DEEPSLEEP -> Box is in Deep Sleep Standby Mode\n"); - printf("\t\t\t OFF -> Box id OFF\n"); + printf ("\nUsage: 'QueryPowerState [CMD]'\n"); + printf ("\tCMDs are,\n"); + printf ("\t\t -h -> Help\n"); + printf ("\t\t -c -> Box state from iARM Cache\n"); + printf ("\t\t No CMD will read the iARM state from '/opt'\n"); + + printf ("\n\tOutput will be,\n"); + printf ("\t\t\t ON -> Box is in Active Mode\n"); + printf ("\t\t\t STANDBY -> Box is in Standby Mode\n"); + printf ("\t\t\t LIGHTSLEEP -> Box is in Light Sleep Standby Mode\n"); + printf ("\t\t\t DEEPSLEEP -> Box is in Deep Sleep Standby Mode\n"); + printf ("\t\t\t OFF -> Box id OFF\n"); } /** * Test application to check whether the box is in standby or not. * This has been developed to resolve, XONE-4598 */ -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { + PWRMgr_Settings_t pwrSettings; int ret = 0; - - if (argc > 1) { - if (argv[1][1] == 'c') { - uint32_t res = 0; - PowerController_PowerState_t curState = POWER_STATE_UNKNOWN, previousState = POWER_STATE_UNKNOWN; - - PowerController_Init(); - + const char *settingsFile = "/opt/uimgr_settings.bin"; + + memset(&pwrSettings,0,sizeof(PWRMgr_Settings_t)); + + if (argc > 1) + { + if (argv[1][1] == 'c') + { + IARM_Bus_PWRMgr_GetPowerState_Param_t param; + + IARM_Bus_Init("iARMQueryPower_1tool"); + IARM_Bus_Connect(); + /** Query current Power state */ - res = PowerController_GetPowerState(&curState, &previousState); - - if (POWER_CONTROLLER_ERROR_NONE == res) { - - if (POWER_STATE_OFF == curState) { - printf("OFF\n"); - } else if (POWER_STATE_STANDBY == curState) { - printf("STANDBY\n"); - } else if (POWER_STATE_ON == curState) { - printf("ON\n"); - } else if (POWER_STATE_STANDBY_LIGHT_SLEEP == curState) { - printf("LIGHTSLEEP\n"); - } else if (POWER_STATE_STANDBY_DEEP_SLEEP == curState) { - printf("DEEPSLEEP\n"); - } else { - printf("Unknown\n"); - } - } else if (POWER_CONTROLLER_ERROR_UNAVAILABLE == res) { - printf("Error :: PowerManager plugin unavailable\n"); - } else { - printf("Error :: Unknown\n"); + if (IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_PWRMGR_NAME, + IARM_BUS_PWRMGR_API_GetPowerState, + (void *)¶m, + sizeof(param))) + { + + if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_OFF) + printf ("OFF"); + else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY) + printf ("STANDBY"); + else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_ON) + printf ("ON"); + else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP) + printf ("LIGHTSLEEP"); + else if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP) + printf ("DEEPSLEEP"); + else + printf ("Unknown"); } - - /* Dispose closes RPC conn, do not make any power manager calls after this */ - PowerController_Term(); - - } else if (argv[1][1] == 'h') { + else + printf ("Unknown"); + + IARM_Bus_Disconnect(); + IARM_Bus_Term(); + } + else if (argv[1][1] == 'h') + { usage(); } - } else { - PWRMgr_Settings_t pwrSettings; - const char* settingsFile = "/opt/uimgr_settings.bin"; - + } + else + { int fd = open(settingsFile, O_RDONLY); - memset(&pwrSettings, 0, sizeof(PWRMgr_Settings_t)); - if (fd > 0) { lseek(fd, 0, SEEK_SET); - ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE)); + + ret = read(fd, &pwrSettings, (sizeof(PWRMgr_Settings_t) - PADDING_SIZE) ); - close(fd); + close (fd); } - if (ret > 0) { - if (IARM_BUS_PWRMGR_POWERSTATE_OFF == pwrSettings.powerState) { - printf("OFF"); - } else if (IARM_BUS_PWRMGR_POWERSTATE_STANDBY == pwrSettings.powerState) { - printf("STANDBY"); - } else if (IARM_BUS_PWRMGR_POWERSTATE_ON == pwrSettings.powerState) { - printf("ON"); - } else if (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP == pwrSettings.powerState) { - printf("LIGHTSLEEP"); - } else if (IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP == pwrSettings.powerState) { - printf("DEEPSLEEP"); - } else { - printf("Unknown Power state"); - } - } else { - printf("Error in reading PWRMgr settings File"); + if (ret > 0) + { + if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_OFF) + printf ("OFF"); + else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY) + printf ("STANDBY"); + else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_ON) + printf ("ON"); + else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP) + printf ("LIGHTSLEEP"); + else if (pwrSettings.powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP) + printf ("DEEPSLEEP"); + else + printf ("Unknown Power state"); } - - printf("\n"); + else + printf ("Error in reading PWRMgr settings File"); } + printf ("\n"); return 0; } diff --git a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c index 527dc48..6232e8d 100644 --- a/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c +++ b/iarm_set_powerstate/IARM_BUS_SetPowerStatus.c @@ -15,261 +15,98 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ -#include -#include +*/ #include -#include #include -#include -#include -#include - -#include "power_controller.h" - -#define ARRAY_SIZE 10 +#include "libIBus.h" +#include "pwrMgr.h" -const char* pPowerON = "ON"; -const char* pPowerOFF = "OFF"; -const char* pPowerStandby = "STANDBY"; -const char* pPowerLigtSleep = "LIGHTSLEEP"; -const char* pPowerDeepSleep = "DEEPSLEEP"; -const char* pNOP = "NOP"; +const char *pPowerON = "ON"; +const char *pPowerOFF = "OFF"; +const char *pPowerStandby = "STANDBY"; +const char *pPowerLigtSleep = "LIGHTSLEEP"; +const char *pPowerDeepSleep = "DEEPSLEEP"; -static void usage() -{ - printf("\nUsage: 'SetPowerState [OPTIONS] [ON | STANDBY | LIGHTSLEEP | DEEPSLEEP | OFF | NOP] with PowerManager plugin\n"); - printf("\t\t ON -> Set to Active Mode\n"); - printf("\t\t STANDBY -> Set to Standby Mode\n"); - printf("\t\t LIGHTSLEEP -> Set to LIGHT Sleep Standby mode\n"); - printf("\t\t DEEPSLEEP -> Set to DEEP Sleep Standby mode\n"); - printf("\t\t OFF -> Set to OFF\n"); - printf("\t\t NOP -> No operation, to support test scenarios with parallel `SetPowerState` run\n\n"); - printf("\tOptions:\n"); - printf("\t --client Specify client name (e.g., C1, C2).\n"); - printf("\t --ack Delay to acknowledge power change in seconds (-1: no ack, 0: quick ack, >0: delayed ack; default: -1).\n"); - printf("\t --delay Delay for power change in seconds, as CSV (default: no delay).\n"); - printf("\t Each delay corresponds to `DelayPowerModeChangeBy` call\n"); - printf("\t --await Wait at least this many seconds before exiting (default 0).\n"); -} -static void parseCSV(const char* arg, int* values, int* size) +void usage () { - char* token; - char buffer[256]; - int index = 0; - - strncpy(buffer, arg, sizeof(buffer) - 1); - buffer[sizeof(buffer) - 1] = '\0'; - - token = strtok(buffer, ","); - while (token != NULL && index < ARRAY_SIZE) { - values[index++] = atoi(token); - token = strtok(NULL, ","); - } - - *size = index; -} - -typedef struct { - char clientName[256]; - int ack; - int delay[ARRAY_SIZE]; - int delaySize; - uint32_t clientId; - volatile int transactionId; - pthread_t asyncThread; -} Controller; - -static void* asyncThreadMain(void* arg) -{ - Controller* controller = (Controller*)arg; - usleep((controller->ack - 0.05) * 1000000); // Ack delay minus 50ms - PowerController_PowerModePreChangeComplete(controller->clientId, controller->transactionId); - return NULL; -} - -static void onPowerModePreChangeEvent(const PowerController_PowerState_t currentState, - const PowerController_PowerState_t newState, - const int transactionId, const int stateChangeAfter, void* userdata) -{ - Controller* controller = (Controller*)userdata; - - printf("onPowerModePreChangeEvent currentState: %d, newState: %d, clientId: %d, transactionId: %d, stateChangeAfter: %d\n", - currentState, newState, controller->clientId, transactionId, stateChangeAfter); - - controller->transactionId = transactionId; - - if (controller->ack == 0) { - PowerController_PowerModePreChangeComplete(controller->clientId, transactionId); - } else if (controller->ack > 0) { - pthread_create(&(controller->asyncThread), NULL, asyncThreadMain, controller); - } -} - -static void initController(Controller* controller) -{ - PowerController_Init(); - - while (!PowerController_IsOperational()) { - uint32_t status = PowerController_Connect(); - - if (POWER_CONTROLLER_ERROR_NONE == status) { - printf("\nSuccess :: Connect\n"); - break; - } else if (POWER_CONTROLLER_ERROR_UNAVAILABLE == status) { - printf("\nFailed :: Connect :: Thunder is UNAVAILABLE\n"); - } else if (POWER_CONTROLLER_ERROR_NOT_EXIST == status) { - printf("\nFailed :: Connect :: PowerManager is UNAVAILABLE\n"); - } else { - // Do nothing - } - usleep(100 * 1000); // 100ms - } - - PowerController_RegisterPowerModePreChangeCallback(onPowerModePreChangeEvent, controller); - - if (strlen(controller->clientName) > 0) { - PowerController_AddPowerModePreChangeClient(controller->clientName, &(controller->clientId)); - } -} - -static void terminateController(Controller* controller) -{ - if (controller->asyncThread) { - pthread_join(controller->asyncThread, NULL); - } - - if (strlen(controller->clientName) > 0) { - PowerController_RemovePowerModePreChangeClient(controller->clientId); - } - - PowerController_UnRegisterPowerModePreChangeCallback(onPowerModePreChangeEvent); - - // TODO: without this delay there is a hang Communicator ThreadPool destroy. - // This is captured as part of jira `RDK-56273` & will be taken up in future sprints. - sleep(1); - PowerController_Term(); - printf("PowerController_Term after 1s delay\n"); -} - -static void runDelay(Controller* controller) -{ - int retry = 5; - - // Wait for PowerManager to respond - // `transactionId` will be updated on receiving onPowerModePreChangeEvent - while (controller->transactionId == 0 && retry-- > 0) { - usleep(100 * 1000); // 100ms - } - - if (controller->transactionId > 0) { - for (int i = 0; i < controller->delaySize; i++) { - if (controller->delay[i] > 0) { - PowerController_DelayPowerModeChangeBy(controller->clientId, controller->transactionId, controller->delay[i]); - usleep((controller->delay[i] - 0.05) * 1000000); // Delay minus 50ms - } - } - } + printf ("\nUsage: 'iARM_SetPowerStatus [ON | STANDBY | LIGHTSLEEP | DEEPSLEEP | OFF ]'\n"); + printf ("\t\t ON -> Set to Active Mode\n"); + printf ("\t\t STANDBY -> Set to Standby Mode\n"); + printf ("\t\t LIGHTSLEEP -> Set to LIGHT Sleep Standby mode\n"); + printf ("\t\t DEEPSLEEP -> Set to DEEP Sleep Standby mode\n"); + printf ("\t\t OFF -> Set to OFF\n"); } +void setPowerMode(); /** * Test application to check whether the box is in standby or not. * This has been developed to resolve, XONE-4598 */ -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - PowerController_PowerState_t powerstate = POWER_STATE_ON; - struct option longOptions[] = { - { "client", required_argument, NULL, 'c' }, - { "ack", required_argument, NULL, 'a' }, - { "delay", required_argument, NULL, 'd' }, - { "await", required_argument, NULL, 'w' }, - { NULL, 0, NULL, 0 } - }; - - Controller controller = { .clientName = "", .ack = -1, .delaySize = 0, .clientId = 0, .transactionId = 0 }; + IARM_Bus_PWRMgr_SetPowerState_Param_t param; - int await = 0; - char argstate[256] = ""; - - int opt; - int optionIndex = 0; - while ((opt = getopt_long(argc, argv, "c:a:d:w:", longOptions, &optionIndex)) != -1) { - switch (opt) { - case 'c': - strncpy(controller.clientName, optarg, sizeof(controller.clientName) - 1); - break; - case 'a': - controller.ack = atoi(optarg); - break; - case 'd': - parseCSV(optarg, controller.delay, &controller.delaySize); - break; - case 'w': - await = atoi(optarg); - break; - default: - usage(); - return EXIT_FAILURE; - } - } + param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON; - if (optind < argc) { - strncpy(argstate, argv[optind], sizeof(argstate) - 1); - } else { - fprintf(stderr, "Error: POWER_STATE is mandatory.\n"); + if (argc < 2) + { usage(); - return EXIT_FAILURE; } - - if (strncasecmp(pPowerON, argstate, strlen(pPowerON)) == 0) { - powerstate = POWER_STATE_ON; - printf("ON Request...\n"); - } else if (strncasecmp(pPowerStandby, argstate, strlen(pPowerStandby)) == 0) { - powerstate = POWER_STATE_STANDBY; - printf("STANDBY Request...\n"); - } else if (strncasecmp(pPowerLigtSleep, argstate, strlen(pPowerLigtSleep)) == 0) { - powerstate = POWER_STATE_STANDBY_LIGHT_SLEEP; - printf("Light Sleep Request...\n"); - } else if (strncasecmp(pPowerDeepSleep, argstate, strlen(pPowerDeepSleep)) == 0) { - powerstate = POWER_STATE_STANDBY_DEEP_SLEEP; - printf("Deep Sleep Request...\n"); - } else if (strncasecmp(pPowerOFF, argstate, strlen(pPowerOFF)) == 0) { - powerstate = POWER_STATE_OFF; - printf("OFF Request...\n"); - } else if (strcmp(argstate, pNOP) == 0) { - powerstate = POWER_STATE_UNKNOWN; - printf("NOP Request...\n"); - } else { + else if (strncasecmp(pPowerON, argv[1], strlen (pPowerON)) == 0) + { + printf ("ON Request...\n"); + param.newState = IARM_BUS_PWRMGR_POWERSTATE_ON; + } + else if (strncasecmp(pPowerStandby, argv[1], strlen (pPowerStandby)) == 0) + { + param.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY; + printf ("STANDBY Request...\n"); + } + else if (strncasecmp(pPowerLigtSleep, argv[1], strlen (pPowerLigtSleep)) == 0) + { + param.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP; + printf ("Light Sleep Request...\n"); + } + else if (strncasecmp(pPowerDeepSleep, argv[1], strlen (pPowerDeepSleep)) == 0) + { + param.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP; + printf ("Deep Sleep Request...\n"); + } + else if (strncasecmp(pPowerOFF, argv[1], strlen (pPowerOFF)) == 0) + { + param.newState = IARM_BUS_PWRMGR_POWERSTATE_OFF; + printf ("OFF Request...\n"); + } + else + { usage(); - return EXIT_FAILURE; } - - initController(&controller); - - // Wait for parallel `SetPowerState` run - usleep(100 * 1000); - - if (POWER_STATE_UNKNOWN != powerstate) { - int keyCode = 0; - uint32_t res = PowerController_SetPowerState(keyCode, powerstate, "sys_mon_tool[SetPowerState]"); - if (POWER_CONTROLLER_ERROR_NONE == res) { - printf("SetPowerState :: Success \n"); - } else if (POWER_CONTROLLER_ERROR_UNAVAILABLE == res) { - printf("SetPowerState :: Failed :: PowerManager plugin unavailable\n"); - } else { - printf("SetPowerState :: Failed \n"); + + + if ((param.newState == IARM_BUS_PWRMGR_POWERSTATE_ON) || + (param.newState == IARM_BUS_PWRMGR_POWERSTATE_OFF) || + (param.newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY) || + (param.newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP) || + (param.newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)) + { + IARM_Bus_Init("iARMSetPower_tool"); + IARM_Bus_Connect(); + + /** Query current Power state */ + if (IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_PWRMGR_NAME, + IARM_BUS_PWRMGR_API_SetPowerState, + (void *)¶m, + sizeof(param))) + { + printf ("SetPowerState :: Success \n"); } + else + { + printf ("SetPowerState :: Failed \n"); + } + IARM_Bus_Disconnect(); + IARM_Bus_Term(); } - - runDelay(&controller); - - if (await > 0) { - sleep(await); - } - - terminateController(&controller); - return 0; }