diff --git a/.github/workflows/native_full_build.yml b/.github/workflows/native_full_build.yml new file mode 100644 index 0000000..11ef474 --- /dev/null +++ b/.github/workflows/native_full_build.yml @@ -0,0 +1,24 @@ +name: Build Component in Native Environment + +on: + push: + branches: [ main, 'sprint/**', 'release/**', develop ] + pull_request: + branches: [ main, 'sprint/**', 'release/**', topic/RDK*, develop ] + +jobs: + build-entservices-on-pr: + name: Build entservices-mediaanddrm component in github rdkcentral + runs-on: ubuntu-latest + container: + image: ghcr.io/rdkcentral/docker-rdk-ci:latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: native build + run: | + ./cov_build.sh + env: + GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} diff --git a/cov_build.sh b/cov_build.sh new file mode 100755 index 0000000..2926cab --- /dev/null +++ b/cov_build.sh @@ -0,0 +1,108 @@ +#!/bin/bash +set -x +set -e + +WORKDIR=`pwd` +export ROOT=/home/rdkv-core/Yuvaram/workspace/downloads +export ROOT=/usr +export INSTALL_DIR=${ROOT}/local +mkdir -p $INSTALL_DIR + +apt update +apt install -y libdbus-1-dev + +cd $ROOT +rm -rf iarmbus +git clone https://github.com/rdkcentral/iarmbus.git + +cd $ROOT +rm -rf iarmmgrs +git clone https://github.com/rdkcentral/iarmmgrs.git + +export IARMBUS_PATH=$ROOT/iarmbus +export IARMMGRS_PATH=$ROOT/iarmmgrs + +# Build and deploy stubs for IARMBus +echo "Building IARMBus stubs" +cd $WORKDIR +cd ./stubs +g++ -fPIC -shared -o libIARMBus.so iarm_stubs.cpp -I$WORKDIR/stubs -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$IARMBUS_PATH/core -I$IARMBUS_PATH/core/include -fpermissive +g++ -fPIC -shared -o libWPEFrameworkPowerController.so powerctrl_stubs.cpp -I$WORKDIR/stubs -fpermissive + +#cp $IARMBUS_PATH/core/libIARMCore.h /usr/local/include +#cp $IARMBUS_PATH/core/include/libIBus.h /usr/local/include +#cp $IARMBUS_PATH/core/include/libIARM.h /usr/local/include +#cp $IARMBUS_PATH/core/include/libIBusDaemon.h /usr/local/include +#cp $IARMMGRS_PATH/hal/include/comcastIrKeyCodes.h /usr/local/include +#cp $IARMMGRS_PATH/mfr/include/mfr*.h /usr/local/include +#cp $IARMMGRS_PATH/mfr/common/include/mfrApi.h /usr/local/include + +cp libIARMBus.so /usr/local/lib +cp libWPEFrameworkPowerController.so /usr/local/lib/libWPEFrameworkPowerController.so + +function standaloneBuildClean() +{ + pd=`pwd` + CLEAN_BUILD=1 + dnames="$RDK_SCRIPTS_PATH" + for dName in $dnames + do + cd $dName + if [ -f Makefile ]; then + make distclean + fi + rm -f configure + rm -rf aclocal.m4 autom4te.cache config.log config.status libtool + rm -rf install + find . -iname "Makefile.in" -exec rm -f {} \; + find . -iname "Makefile" | xargs rm -f + ls cfg/* | grep -v "Makefile.am" | xargs rm -f + cd $pd + done + find . -iname "*.o" -exec rm -f {} \; +} + +function standaloneBuildConfigure() +{ + aclocal -I cfg + libtoolize --automake + autoheader + automake --foreign --add-missing + rm -f configure + autoconf + ./configure +} + +echo "##### Building sys_mon_tools module" +cd $WORKDIR + +export GLIBS='-lglib-2.0 -lz' +export ROOT_INC="/usr/lib/x86_64-linux-gnu" +export GLIB_INCLUDE_PATH="/usr/include/glib-2.0" +export GLIB_CONFIG_INCLUDE_PATH="${ROOT_INC}/glib-2.0/include" +export DBUS_INCLUDE_PATH="/usr/include/dbus-1.0" +export DBUS_CONFIG_INCLUDE_PATH="${ROOT_INC}/dbus-1.0/include" +export CFLAGS+="-O2 -Wall -fPIC -I./include -I${GLIB_INCLUDE_PATH} -I${GLIB_CONFIG_INCLUDE_PATH} \ + -I/usr/include \ + -I/usr/local/include \ + -I${WORKDIR}/stubs \ + -I${DBUS_INCLUDE_PATH} \ + -I${DBUS_CONFIG_INCLUDE_PATH} \ + -I/usr/include/libsoup-2.4 \ + -I/usr/include/gssdp-1.0" +export LDFLAGS+="-Wl,-rpath, -L/usr/lib" +export CC="gcc $CFLAGS" +export CXX="g++ $CFLAGS $LDFLAGS" +export USE_IARM_BUS="y" + +standaloneBuildClean +standaloneBuildConfigure + +#make +# +#cp $IARMMGRS_PATH/hal/include/comcastIrKeyCodes.h /usr/local/include +#cp $IARMMGRS_PATH/mfr/include/mfr*.h /usr/local/include +#cp $IARMMGRS_PATH/mfr/common/include/mfrApi.h /usr/local/include + +make VERBOSE=1 AM_CPPFLAGS="-I${WORKDIR}/stubs -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libsoup-3.0 -I/usr/local/include -I${IARMMGRS_PATH}/sysmgr/include -I${IARMBUS_PATH}/core -I${IARMBUS_PATH}/core/include -I${IARMMGRS_PATH}/hal/include -I${IARMMGRS_PATH}/mfr/include -I${IARMMGRS_PATH}/mfr/common/include" \ +AM_LDFLAGS="-L/usr/local/lib -lIARMBus -lWPEFrameworkPowerController" CXXFLAGS="-fpermissive -I${WORKDIR}/stubs" diff --git a/stubs/iarm_stubs.cpp b/stubs/iarm_stubs.cpp new file mode 100644 index 0000000..a3ed949 --- /dev/null +++ b/stubs/iarm_stubs.cpp @@ -0,0 +1,73 @@ +#include "libIBus.h" +#include "libIARMCore.h" +#include +using namespace std; + +IARM_Result_t IARM_Malloc(IARM_MemType_t type, size_t size, void **ptr) +{ + return IARM_RESULT_SUCCESS; +} + +int main() +{ +} + +IARM_Result_t IARM_Free(IARM_MemType_t type, void *alloc) +{ + return IARM_RESULT_SUCCESS; +} + +IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) +{ + return IARM_RESULT_SUCCESS; +} + +IARM_Result_t IARM_Bus_Init(const char* name) +{ + return IARM_RESULT_SUCCESS; +} + +IARM_Result_t IARM_Bus_Connect() +{ + return IARM_RESULT_SUCCESS; +} + +IARM_Result_t IARM_Bus_IsConnected(const char* memberName, int* isRegistered) +{ + return IARM_RESULT_SUCCESS; +} + +IARM_Result_t IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) +{ + return IARM_RESULT_SUCCESS; +} + +IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId) +{ + return IARM_RESULT_SUCCESS; +} + +IARM_Result_t IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) +{ + return IARM_RESULT_SUCCESS; +} +IARM_Result_t IARM_Bus_RegisterCall(const char *methodName, IARM_BusCall_t handler) +{ +return IARM_RESULT_SUCCESS; +} +IARM_Result_t IARM_Bus_Term(void) +{ +return IARM_RESULT_SUCCESS; +} +IARM_Result_t IARM_Bus_Disconnect(void) +{ +return IARM_RESULT_SUCCESS; +} +IARM_Result_t IARM_Bus_RegisterEvent(IARM_EventId_t maxEventId) +{ +return IARM_RESULT_SUCCESS; +} +IARM_Result_t IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen) +{ + return IARM_RESULT_SUCCESS; +} diff --git a/stubs/power_controller.h b/stubs/power_controller.h new file mode 100644 index 0000000..8739760 --- /dev/null +++ b/stubs/power_controller.h @@ -0,0 +1,415 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2025 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ +#ifndef POWERMANAGER_CLIENT_H +#define POWERMANAGER_CLIENT_H + +#include +#include + +#undef EXTERNAL +#if defined(WIN32) || defined(_WINDOWS) || defined (__CYGWIN__) || defined(_WIN64) +#ifdef DEVICEINFO_EXPORTS +#define EXTERNAL __declspec(dllexport) +#else +#define EXTERNAL __declspec(dllimport) +#pragma comment(lib, "deviceinfo.lib") +#endif +#else +#define EXTERNAL __attribute__((visibility("default"))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum PowerController_PowerState { + POWER_STATE_UNKNOWN = 0 /* UNKNOWN */, + POWER_STATE_OFF = 1 /* OFF */, + POWER_STATE_STANDBY = 2 /* STANDBY */, + POWER_STATE_ON = 3 /* ON */, + POWER_STATE_STANDBY_LIGHT_SLEEP = 4 /* LIGHT_SLEEP */, + POWER_STATE_STANDBY_DEEP_SLEEP = 5 /* DEEP_SLEEP */ +} PowerController_PowerState_t; + +typedef enum PowerController_ThermalTemperature { + THERMAL_TEMPERATURE_UNKNOWN = 0 /* UNKNOWN Thermal Temperature */, + THERMAL_TEMPERATURE_NORMAL = 1 /* Normal Thermal Temperature */, + THERMAL_TEMPERATURE_HIGH = 2 /* High Thermal Temperature */, + THERMAL_TEMPERATURE_CRITICAL = 4 /* Critial Thermal Temperature */ +} PowerController_ThermalTemperature_t; + +typedef enum PowerController_WakeupSrcType { + WAKEUP_SRC_UNKNOWN = 0 /* UNKNOWN */, + WAKEUP_SRC_VOICE = 1 /* VOICE */, + WAKEUP_SRC_PRESENCEDETECTED = 2 /* PRESENCEDETECTED */, + WAKEUP_SRC_BLUETOOTH = 3 /* BLUETOOTH */, + WAKEUP_SRC_WIFI = 4 /* WIFI */, + WAKEUP_SRC_IR = 5 /* IR */, + WAKEUP_SRC_POWERKEY = 6 /* POWERKEY */, + WAKEUP_SRC_TIMER = 7 /* TIMER */, + WAKEUP_SRC_CEC = 8 /* CEC */, + WAKEUP_SRC_LAN = 9 /* LAN */, + WAKEUP_SRC_RF4CE = 10 /* RF4CE */ +} PowerController_WakeupSrcType_t; + +typedef enum PowerController_WakeupReason { + WAKEUP_REASON_UNKNOWN = 0 /* UNKNOWN */, + WAKEUP_REASON_IR = 1 /* IR */, + WAKEUP_REASON_BLUETOOTH = 2 /* BLUETOOTH */, + WAKEUP_REASON_RF4CE = 3 /* RF4CE */, + WAKEUP_REASON_GPIO = 4 /* GPIO */, + WAKEUP_REASON_LAN = 5 /* LAN */, + WAKEUP_REASON_WIFI = 6 /* WIFI */, + WAKEUP_REASON_TIMER = 7 /* TIMER */, + WAKEUP_REASON_FRONTPANEL = 8 /* FRONTPANEL */, + WAKEUP_REASON_WATCHDOG = 9 /* WATCHDOG */, + WAKEUP_REASON_SOFTWARERESET = 10 /* SOFTWARERESET */, + WAKEUP_REASON_THERMALRESET = 11 /* THERMALRESET */, + WAKEUP_REASON_WARMRESET = 12 /* WARMRESET */, + WAKEUP_REASON_COLDBOOT = 13 /* COLDBOOT */, + WAKEUP_REASON_STRAUTHFAIL = 14 /* STR_AUTH_FAIL */, + WAKEUP_REASON_CEC = 15 /* CEC */, + WAKEUP_REASON_PRESENCE = 16 /* PRESENCE */, + WAKEUP_REASON_VOICE = 17 /* VOICE */ +} PowerController_WakeupReason_t; + +typedef enum PowerController_SystemMode { + SYSTEM_MODE_UNKNOWN = 0 /* UNKNOWN */, + SYSTEM_MODE_NORMAL = 1 /* NORMAL */, + SYSTEM_MODE_EAS = 2 /* EAS */, + SYSTEM_MODE_WAREHOUSE = 3 /* WAREHOUSE */ +} PowerController_SystemMode_t; + +#define POWER_CONTROLLER_ERROR_NONE 0 +#define POWER_CONTROLLER_ERROR_GENERAL 1 +#define POWER_CONTROLLER_ERROR_UNAVAILABLE 2 +#define POWER_CONTROLLER_ERROR_NOT_EXIST 43 + +/** + * @brief Initializes the Power Controller. + * + * This function creates an instance of the PowerManager plugin client interface and increments the client instance count. + * + * @details + * - If the Power Controller instance does not already exist, it will be created. + * - The instance count is incremented each time this function is called. + * - After Init, & before making any PowerController request client needs to ensure + * - Power Manager plugin is activated and operational via `PowerController_IsOperational`. + * - If not operational, clients can use this Connect API to establish COM-RPC connection with the Power Manager plugin. + * - If there us any failure in Connect all PowerController requests will fail with `POWER_CONTROLLER_ERROR_UNAVAILABLE` (Except for callback register / unregister APIs). + * + * @see PowerController_Term + */ +EXTERNAL void PowerController_Init(); + +/** + * @brief PowerController attempts to connect to the Power Manager plugin. + * + * This function connects to the Power Manager plugin. + * + * @details + * - This function is used to connect to the Power Manager plugin. + * - Before making any PowerController request client needs to ensure + * - Power Manager plugin is activated and operational via `PowerController_IsOperational`. + * - If not operational, clients can use this Connect API to establish COM-RPC connection with the Power Manager plugin. + * - If there us any failure in Connect all PowerController requests will fail with `POWER_CONTROLLER_ERROR_UNAVAILABLE` (Except for callback register / unregister APIs). + * - In case of failure this API should be called again with brief delay. + * + * @return `POWER_CONTROLLER_ERROR_NONE` on success. + * @return `POWER_CONTROLLER_ERROR_UNAVAILABLE` if Thunder RPC server is not running / error establishing RPC communication channel. + * @return `POWER_CONTROLLER_ERROR_NOT_EXIST` if the PowerManager plugin is not activated yet. + */ +EXTERNAL uint32_t PowerController_Connect(); + +/** + * @brief Terminates the Power Controller. + * + * This function decrements client instance count attempts to delete Power Controller instance + * + * @details + * - If the controller reference count is greater than one, this function only decrements the count. + * - When the reference count reaches zero, the controller instance is destroyed, and all associated resources are released (PowerManager plugin client instance). + * - Ensure that this function is called once for every call to `PowerController_Init`. + * + * @see PowerController_Init + */ +EXTERNAL void PowerController_Term(); + +/** + * @brief Checks if the Power Manager plugin is active & operational + * + * This function determines whether the Power Manager interface is operational and ready to handle requests. + * It can be used to verify the availability of the Power Manager client before initiating operations that depend on it. + * + * IMPORTANT - This is the first function that should be called after `PowerController_Init`. + * + * @return `true` if the Power Manager interface is active and operational, otherwise `false`. + * + * @details + * - Use this function to confirm the operational status of the Power Manager plugin. + * - Calling this function is NOT MANDATORY but optional + * - Clients can register for notifications about state changes using `PowerController_RegisterOperationalStateChangeCallback`. + * - If the Power Manager interface is not active, subsequent Power Manager operations will fail with the error `POWER_CONTROLLER_ERROR_UNAVAILABLE`. + * - Therefore in failure cases, clients can use `PowerController_Connect` to establish COM-RPC connection with the Power Manager plugin. + * + * @see PowerController_RegisterOperationalStateChangeCallback + */ +EXTERNAL bool PowerController_IsOperational(); + +/** Gets the Power State.*/ +// @text getPowerState +// @brief Get Power State +// @param powerState: Get current power state +EXTERNAL uint32_t PowerController_GetPowerState(PowerController_PowerState_t* currentState /* @out */, PowerController_PowerState_t* previousState /* @out */); + +/** Sets Power State . */ +// @text setPowerState +// @brief Set Power State +// @param keyCode: NA for most platfroms, to be depricated +// @param powerState: Set power to this state +// @param reason: null terminated string stating reason for for state change +EXTERNAL uint32_t PowerController_SetPowerState(const int keyCode /* @in */, const PowerController_PowerState_t powerstate /* @in */, const char* reason /* @in */); + +/** Gets the current Thermal state.*/ +// @text getThermalState +// @brief Get Current Thermal State (temperature) +// @param currentTemperature: current temperature +EXTERNAL uint32_t PowerController_GetThermalState(float* currentTemperature /* @out */); + +/** Sets the Temperature Thresholds.*/ +// @text setTemperatureThresholds +// @brief Set Temperature Thresholds +// @param high: high threshold +// @param critical : critical threshold +EXTERNAL uint32_t PowerController_SetTemperatureThresholds(float high /* @in */, float critical /* @in */); + +/** Gets the current Temperature Thresholds.*/ +// @text getTemperatureThresholds +// @brief Get Temperature Thresholds +// @param high: high threshold +// @param critical : critical threshold +EXTERNAL uint32_t PowerController_GetTemperatureThresholds(float* high /* @out */, float* critical /* @out */); + +/** Sets the current Temperature Grace interval.*/ +// @property +// @text PowerController_SetOvertempGraceInterval +// @brief Set Temperature Thresholds +// @param graceInterval: interval in secs? +EXTERNAL uint32_t PowerController_SetOvertempGraceInterval(const int graceInterval /* @in */); + +/** Gets the grace interval for over-temperature.*/ +// @property +// @text PowerController_GetOvertempGraceInterval +// @brief Get Temperature Grace interval +// @param graceInterval: interval in secs? +EXTERNAL uint32_t PowerController_GetOvertempGraceInterval(int* graceInterval /* @out */); + +/** Set Deep Sleep Timer for later wakeup */ +// @property +// @text setDeepSleepTimer +// @brief Set Deep sleep timer for timeOut period +// @param timeOut: deep sleep timeout +EXTERNAL uint32_t PowerController_SetDeepSleepTimer(const int timeOut /* @in */); + +/** Get Last Wakeup reason */ +// @property +// @text getLastWakeupReason +// @brief Get Last Wake up reason +// @param wakeupReason: wake up reason +EXTERNAL uint32_t PowerController_GetLastWakeupReason(PowerController_WakeupReason_t* wakeupReason /* @out */); + +/** Get Last Wakeup key code */ +// @property +// @text getLastWakeupKeyCode +// @brief Get the key code that can be used for wakeup +// @param keycode: Key code for wakeup +EXTERNAL uint32_t PowerController_GetLastWakeupKeyCode(int* keycode /* @out */); + +/** Request Reboot with PowerManager */ +// @text reboot +// @brief Reboot device +// @param rebootRequestor: null terminated string identifier for the entity requesting the reboot. +// @param rebootReasonCustom: custom-defined reason for the reboot, provided as a null terminated string. +// @param rebootReasonOther: null terminated string describing any other reasons for the reboot. +EXTERNAL uint32_t PowerController_Reboot(const char* rebootRequestor /* @in */, const char* rebootReasonCustom /* @in */, const char* rebootReasonOther /* @in */); + +/** Set Network Standby Mode */ +// @property +// @text setNetworkStandbyMode +// @brief Set the standby mode for Network +// @param standbyMode: Network standby mode +EXTERNAL uint32_t PowerController_SetNetworkStandbyMode(const bool standbyMode /* @in */); + +/** Get Network Standby Mode */ +// @text getNetworkStandbyMode +// @brief Get the standby mode for Network +// @param standbyMode: Network standby mode +EXTERNAL uint32_t PowerController_GetNetworkStandbyMode(bool* standbyMode /* @out */); + +/** Set Wakeup source configuration */ +// @text setWakeupSrcConfig +// @brief Set the source configuration for device wakeup +// @param powerMode: power mode +// @param wakeSrcType: source type +// @param config: config +EXTERNAL uint32_t PowerController_SetWakeupSrcConfig(const int powerMode /* @in */, const int wakeSrcType /* @in */, int config /* @in */); + +/** Get Wakeup source configuration */ +// @text getWakeupSrcConfig +// @brief Get the source configuration for device wakeup +// @param powerMode: power mode +// @param srcType: source type +// @param config: config +EXTERNAL uint32_t PowerController_GetWakeupSrcConfig(int* powerMode /* @out */, int* srcType /* @out */, int* config /* @out */); + +/** Initiate System mode change */ +// @text PowerController_SetSystemMode +// @brief System mode change +// @param oldMode: current mode +// @param newMode: new mode +EXTERNAL uint32_t PowerController_SetSystemMode(const PowerController_SystemMode_t currentMode /* @in */, const PowerController_SystemMode_t newMode /* @in */); + +/** Get Power State before last reboot */ +// @text PowerController_GetPowerStateBeforeReboot +// @brief Get Power state before last reboot +// @param powerStateBeforeReboot: power state +EXTERNAL uint32_t PowerController_GetPowerStateBeforeReboot(PowerController_PowerState_t* powerStateBeforeReboot /* @out */); + +/** Engage a client in power mode change operation. */ +// @text PowerController_AddPowerModePreChangeClient +// @brief - Register a client to engage in power mode state changes. +// - When `PowerModePreChange` event is received, then added client should call either +// - `PowerModePreChangeComplete` API to inform power manager that this client has completed its pre-change operation. +// - Or `DelayPowerModeChangeBy` API to delay the power mode change. +// - If the client does not call `PowerModePreChangeComplete` API, the power mode change will complete +// after the maximum delay `stateChangeAfter` seconds (as received in `OnPowerModePreChange` event). +// - Clients are required to re-register if the PowerManager plugin restarts. Therefore, it is essential for clients to register +// for operational state changes using `PowerController_RegisterOperationalStateChangeCallback`. +// +// IMPORTANT: ** IT'S A BUG IF CLIENT `Unregister` FROM `IModePreChangeNotification` BEFORE DISENGAGING ITSELF ** +// always make sure to call `RemovePowerModePreChangeClient` before calling `Unregister` from `IModePreChangeNotification`. +// +// @param clientName: Name of the client as null terminated string +// @param clientId: Unique identifier for the client to be used while acknowledging the pre-change operation (`PowerModePreChangeComplete`) +// or to delay the power mode change (`DelayPowerModeChangeBy`) +EXTERNAL uint32_t PowerController_AddPowerModePreChangeClient(const char *clientName /* @in */, uint32_t* clientId /* @out */); + +/** Disengage a client from the power mode change operation. */ +// @text PowerController_RemovePowerModePreChangeClient +// @brief Removes a registered client from participating in power mode pre-change operations. +// NOTE client will still continue to receive pre-change notifications. +// @param clientId: Unique identifier for the client. See `AddPowerModePreChangeClient` +EXTERNAL uint32_t PowerController_RemovePowerModePreChangeClient(const uint32_t clientId /* @in */); + +/** Power prechange activity completed */ +// @text PowerController_PowerModePreChangeComplete +// @brief Pre power mode handling complete for given client and transation id +// @param clientId: Unique identifier for the client, as received in AddPowerModePreChangeClient +// @param transactionId: transaction id as received in OnPowerModePreChange +EXTERNAL uint32_t PowerController_PowerModePreChangeComplete(const uint32_t clientId /* @in */, const int transactionId /* @in */); + +/** Delay Powermode change by given time */ +// @text PowerController_DelayPowerModeChangeBy +// @brief Delay Powermode change by given time. If different clients provide different values of delay, then the maximum of these values is used. +// @param clientId: Unique identifier for the client, as received in AddPowerModePreChangeClient +// @param transactionId: transaction id as received in OnPowerModePreChange +// @param delayPeriod: delay in seconds +EXTERNAL uint32_t PowerController_DelayPowerModeChangeBy(const uint32_t clientId /* @in */, const int transactionId /* @in */, const int delayPeriod /* @in */); + +/* Callback data types for event notifications from power manager plugin */ +// @brief Operational state changed event +// @param isOperational: true if PowerManager plugin is activated, false otherwise +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_OperationalStateChangeCb)(bool isOperational, void* userdata); + +// @brief Power mode changed +// @param currentState: Current Power State +// @param newState: New Power State +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_PowerModeChangedCb)(const PowerController_PowerState_t currentState, const PowerController_PowerState_t newState, void* userdata); + +// @brief Power mode Pre-change event +// @param currentState: Current Power State +// @param newState: Changing power state to this New Power State +// @param transactionId: transactionId to be used when invoking prePowerChangeComplete() / delayPowerModeChangeBy API +// @param stateChangeAfter: seconds after which the actual power mode will be applied. +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_PowerModePreChangeCb)(const PowerController_PowerState_t currentState, const PowerController_PowerState_t newState, const int transactionId, const int stateChangeAfter, void* userdata); + +// @brief Deep sleep timeout event +// @param wakeupTimeout: Deep sleep wakeup timeout in seconds +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_DeepSleepTimeoutCb)(const int wakeupTimeout, void* userdata); + +// @brief Network Standby Mode changed event - only on XIone +// @param enabled: network standby enabled or disabled +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_NetworkStandbyModeChangedCb)(const bool enabled, void* userdata); + +// @brief Thermal Mode changed event +// @param currentThermalLevel: current thermal level +// @param newThermalLevel: new thermal level +// @param currentTemperature: current temperature +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_ThermalModeChangedCb)(const PowerController_ThermalTemperature_t currentThermalLevel, const PowerController_ThermalTemperature_t newThermalLevel, const float currentTemperature, void* userdata); + +// @brief Reboot begin event +// @param rebootReasonCustom: Reboot reason custom +// @param rebootReasonOther: Reboot reason other +// @param rebootRequestor: Reboot requested by +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_RebootBeginCb)(const char* rebootReasonCustom, const char* rebootReasonOther, const char* rebootRequestor, void* userdata); + +/* Type defines for callbacks / notifications */ +/* userdata in all callbacks are opaque, clients can use it to have context to callbacks */ + +/** Register for PowerManager plugin operational state change event callback, for initial state use `PowerController_IsOperational` call */ +EXTERNAL uint32_t PowerController_RegisterOperationalStateChangeCallback(PowerController_OperationalStateChangeCb callback, void* userdata); +/** UnRegister (previously registered) PowerManager plugin operational state change event callback */ +EXTERNAL uint32_t PowerController_UnRegisterOperationalStateChangeCallback(PowerController_OperationalStateChangeCb callback); +/** Register for PowerMode changed callback */ +EXTERNAL uint32_t PowerController_RegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback, void* userdata); +/** UnRegister (previously registered) PowerMode changed callback */ +EXTERNAL uint32_t PowerController_UnRegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback); +/** Register for PowerMode pre-change callback */ +EXTERNAL uint32_t PowerController_RegisterPowerModePreChangeCallback(PowerController_PowerModePreChangeCb callback, void* userdata); +/** UnRegister (previously registered) PowerMode pre-change callback */ +EXTERNAL uint32_t PowerController_UnRegisterPowerModePreChangeCallback(PowerController_PowerModePreChangeCb callback); +/** Register for PowerMode pre-change callback */ +EXTERNAL uint32_t PowerController_RegisterDeepSleepTimeoutCallback(PowerController_DeepSleepTimeoutCb callback, void* userdata); +/** UnRegister (previously registered) DeepSleep Timeout callback */ +EXTERNAL uint32_t PowerController_UnRegisterDeepSleepTimeoutCallback(PowerController_DeepSleepTimeoutCb callback); +/** Register for Network Standby Mode changed event - only on XIone */ +EXTERNAL uint32_t PowerController_RegisterNetworkStandbyModeChangedCallback(PowerController_NetworkStandbyModeChangedCb callback, void* userdata); +/** UnRegister (previously registered) Network Standby Mode changed callback */ +EXTERNAL uint32_t PowerController_UnRegisterNetworkStandbyModeChangedCallback(PowerController_NetworkStandbyModeChangedCb callback); +/** Register for Thermal Mode changed event callback */ +EXTERNAL uint32_t PowerController_RegisterThermalModeChangedCallback(PowerController_ThermalModeChangedCb callback, void* userdata); +/** UnRegister (previously registered) Thermal Mode changed event callback */ +EXTERNAL uint32_t PowerController_UnRegisterThermalModeChangedCallback(PowerController_ThermalModeChangedCb callback); +/** Register for reboot start event callback */ +EXTERNAL uint32_t PowerController_RegisterRebootBeginCallback(PowerController_RebootBeginCb callback, void* userdata); +/** UnRegister (previously registered) reboot start event callback */ +EXTERNAL uint32_t PowerController_UnRegisterRebootBeginCallback(PowerController_RebootBeginCb callback); + +#ifdef __cplusplus +}; // extern "C" +#endif + +#endif // POWERMANAGER_CLIENT_H diff --git a/stubs/powerctrl_stubs.cpp b/stubs/powerctrl_stubs.cpp new file mode 100644 index 0000000..df538e8 --- /dev/null +++ b/stubs/powerctrl_stubs.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2025 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "power_controller.h" + +void PowerController_Init() +{ + +} + +void PowerController_Term() +{ + +} + +bool PowerController_IsOperational() +{ + return true; +} + +uint32_t PowerController_Connect() +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_GetPowerState(PowerController_PowerState_t* currentState, PowerController_PowerState_t* previousState) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_SetPowerState(const int keyCode, const PowerController_PowerState_t powerstate, const char* reason) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_PowerModePreChangeComplete(const uint32_t clientId, const int transactionId) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_RegisterPowerModePreChangeCallback(PowerController_PowerModePreChangeCb callback, void* userdata) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_UnRegisterPowerModePreChangeCallback(PowerController_PowerModePreChangeCb callback) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_AddPowerModePreChangeClient(const char* clientName, uint32_t* clientId) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_RemovePowerModePreChangeClient(const uint32_t clientId) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_DelayPowerModeChangeBy(const uint32_t clientId, const int transactionId, const int delayPeriod) +{ + return POWER_CONTROLLER_ERROR_NONE; +} diff --git a/stubs/safec_lib.h b/stubs/safec_lib.h new file mode 100644 index 0000000..49924ae --- /dev/null +++ b/stubs/safec_lib.h @@ -0,0 +1,165 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. +*/ + +#define SAFEC_DUMMY_API 1 +#ifndef SAFEC_DUMMY_API +#include "safe_str_lib.h" +#include "safe_mem_lib.h" + +/* Macro is defined for non clobbering of the safec secure string API strcpy_s & memcpy_s function*/ +/* strcpy_s overwrites the old value and nulls the dest when encounters an error*/ +#ifndef STRCPY_S_NOCLOBBER + #define STRCPY_S_NOCLOBBER(dst,dmax,src) ((src != NULL) ? (strlen(src) < dmax ? strcpy_s(dst,dmax,src) : ESNOSPC):ESNULLP) +#endif +#define MEMCPY_S_NOCLOBBER(dst,dmax,src,len) ((src != NULL) ? (len <= dmax ? memcpy_s(dst,dmax,src,len) : ESNOSPC):ESNULLP) +#endif + +#define STRCPY_S(dest,size,source) \ + { \ + errno_t rc=-1; \ + rc=strcpy_s(dest, size, source); \ + if(rc!=EOK) \ + { \ + RDK_SAFECLIB_ERR(rc); \ + }\ +} +#define MEMCPY_S(dest,dsize,source,ssize) \ + { \ + errno_t safec_rc=-1; \ + safec_rc=memcpy_s(dest, dsize, source, ssize); \ + if(safec_rc!=EOK) \ + { \ + RDK_SAFECLIB_ERR(safec_rc); \ + }\ +} + +/* + * SAFECLIB Error Handling Logging APIs + */ +#define RDK_SAFECLIB_ERR(rc) printf("safeclib error at rc - %d %s %s:%d", rc, __FILE__, __FUNCTION__, __LINE__) + +#define ERR_CHK(rc) \ + if(rc !=EOK) { \ + RDK_SAFECLIB_ERR(rc); \ + } + +#ifdef SAFEC_DUMMY_API +#include +#include +#include +typedef int errno_t; +#define EOK 0 +#define ESNULLP 400 /* null ptr */ +#define ESLEMAX 403 /* length exceeds RSIZE_MAX */ +#define ESNOSPC 406 /* not enough space for s2 */ + +#define strcpy_s(dst,max,src) (src != NULL)?((max > strlen(src))?EOK:ESLEMAX):ESNULLP; \ + if((src != NULL) && (max > strlen(src))) strcpy(dst,src); + +#define strncpy_s(dst,max,src,len) (src != NULL)?((len <= max)?EOK:ESLEMAX):ESNULLP; \ + if((src != NULL) && (len <= max)) strncpy(dst,src,len); + +#define memset_s(dst,max_1,c,max) EOK; \ + memset(dst,c,max); + +#define strcat_s(dst,max,src) (src != NULL)?((max > strlen(src))?EOK:ESLEMAX):ESNULLP; \ + if((src != NULL) && (max > strlen(src))) strcat(dst,src); + +#define strncat_s(dst,max,src,len) (src != NULL)?((len <= max)?EOK:ESLEMAX):ESNULLP; \ + if((src != NULL) && (len <= max)) strncat(dst,src,len); + +#define memcpy_s(dst,max,src,len) EOK; \ + memcpy(dst,src,len); + +#ifndef STRCPY_S_NOCLOBBER + #define STRCPY_S_NOCLOBBER(dst,max,src) (src != NULL)?((max > strlen(src))?EOK:ESLEMAX):ESNULLP; \ + if((src != NULL) && (strlen(src) < max)) strcpy(dst, src); +#endif + +#define MEMCPY_S_NOCLOBBER(dst,max,src,len) (src != NULL) ? ((len <= max)?EOK:ESLEMAX):ESNULLP; \ + if((src != NULL) && (len <= max)) memcpy(dst, src, len); + +#define strtok_s(dest, dmax, delim, ptr) strtok_r(dest, delim, ptr) + +#define sprintf_s( dst, max, fmt, ... ) (parseFormat(dst, max, fmt, ##__VA_ARGS__) == 0) ? -ESNULLP : sprintf( dst, fmt, ##__VA_ARGS__) + +#define STRCPY_S(dest,size,source) \ + { \ + errno_t rc=-1; \ + rc=strcpy_s(dest, size, source); \ + if(rc!=EOK) \ + { \ + RDK_SAFECLIB_ERR(rc); \ + }\ +} +#define MEMCPY_S(dest,dsize,source,ssize) \ + { \ + errno_t safec_rc=-1; \ + safec_rc=memcpy_s(dest, dsize, source, ssize); \ + if(safec_rc!=EOK) \ + { \ + RDK_SAFECLIB_ERR(safec_rc); \ + }\ +} + +static inline int parseFormat(const char *dst, int max, const char *fmt, ...) +{ + va_list argp; + int len = 0; + + if((fmt == NULL) || (dst == NULL) || (max == 0)) + { + return 0; + } + + va_start(argp, fmt); + + len = vsnprintf((char *)dst, (size_t)max, fmt, argp); + + va_end(argp); + + return (max > len) ? 1 : 0; +} + +static inline int strcmp_s(const char *dst, int dmax, const char *src, int *r) { + if((src == NULL) || (dst == NULL) || (dmax == 0)) + return ESNULLP; + + *r = strcmp(dst, src); + return EOK; +} + +static inline int strcasecmp_s(const char *dst, int dmax, const char *src, int *r) { + if((src == NULL) || (dst == NULL) || (dmax == 0)) + return ESNULLP; + + *r = strcasecmp(dst, src); + return EOK; +} + +static inline int memcmp_s(const void *dst, int dmax, const void *src, int len, int *r) { + if((src == NULL) || (dst == NULL) || (dmax == 0)) + return ESNULLP; + if(len > dmax) + return ESNOSPC; + + *r = memcmp(dst, src,len); + return EOK; +} +#endif