Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 35 additions & 42 deletions FrontPanel/FrontPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "frontPanelTextDisplay.hpp"

#include "libIBus.h"
#include "rdk/iarmmgrs-hal/pwrMgr.h"

#include "UtilsJsonRpc.h"
#include "UtilsIarm.h"
Expand Down Expand Up @@ -66,9 +67,6 @@
#define API_VERSION_NUMBER_MINOR 0
#define API_VERSION_NUMBER_PATCH 6

using PowerState = WPEFramework::Exchange::IPowerManager::PowerState;


namespace
{

Expand Down Expand Up @@ -179,8 +177,6 @@ namespace WPEFramework
: PluginHost::JSONRPC()
, m_updateTimer(this)
, m_runUpdateTimer(false)
, _pwrMgrNotification(*this)
, _registeredEventHandlers(false)
{
FrontPanel::_instance = this;
m_runUpdateTimer = false;
Expand All @@ -204,20 +200,12 @@ namespace WPEFramework

FrontPanel::~FrontPanel()
{
if (_powerManagerPlugin) {
_powerManagerPlugin->Unregister(_pwrMgrNotification.baseInterface<Exchange::IPowerManager::IModeChangedNotification>());
_powerManagerPlugin.Reset();
}

_registeredEventHandlers = false;
}

const string FrontPanel::Initialize(PluginHost::IShell *service)
const string FrontPanel::Initialize(PluginHost::IShell * /* service */)
{
InitializePowerManager(service);
FrontPanel::_instance = this;
CFrontPanel::instance(service);
CFrontPanel::instance()->start();
InitializeIARM();
CFrontPanel::instance()->start();
CFrontPanel::instance()->addEventObserver(this);
loadPreferences();

Expand All @@ -233,41 +221,46 @@ namespace WPEFramework
m_runUpdateTimer = false;
}
patternUpdateTimer.Revoke(m_updateTimer);
}

void FrontPanel::InitializePowerManager(PluginHost::IShell *service)
{
_powerManagerPlugin = PowerManagerInterfaceBuilder(_T("org.rdk.PowerManager"))
.withIShell(service)
.withRetryIntervalMS(200)
.withRetryCount(25)
.createInterface();
registerEventHandlers();
DeinitializeIARM();
}
void FrontPanel::powerModeChange(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
{
if (strcmp(owner, IARM_BUS_PWRMGR_NAME) == 0) {
if (eventId == IARM_BUS_PWRMGR_EVENT_MODECHANGED ) {
IARM_Bus_PWRMgr_EventData_t *param = (IARM_Bus_PWRMgr_EventData_t *)data;
LOGINFO("Event IARM_BUS_PWRMGR_EVENT_MODECHANGED: State Changed %d -- > %d\r",
param->data.state.curState, param->data.state.newState);
if(param->data.state.newState == IARM_BUS_PWRMGR_POWERSTATE_ON)
{
LOGINFO("setPowerStatus true");
CFrontPanel::instance()->setPowerStatus(true);
}
else
{
LOGINFO("setPowerStatus false");
CFrontPanel::instance()->setPowerStatus(false);
}
}
}
}

void FrontPanel::onPowerModeChanged(const PowerState currentState, const PowerState newState)
void FrontPanel::InitializeIARM()
{
if(newState == WPEFramework::Exchange::IPowerManager::POWER_STATE_ON)
{
LOGINFO("setPowerStatus true");
CFrontPanel::instance()->setPowerStatus(true);
}
else
if (Utils::IARM::init())
{
LOGINFO("setPowerStatus false");
CFrontPanel::instance()->setPowerStatus(false);
IARM_Result_t res;
IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_PWRMGR_NAME,IARM_BUS_PWRMGR_EVENT_MODECHANGED, powerModeChange) );
}
return;
}

void FrontPanel::registerEventHandlers()
void FrontPanel::DeinitializeIARM()
{
ASSERT (_powerManagerPlugin);

if(!_registeredEventHandlers && _powerManagerPlugin) {
_registeredEventHandlers = true;
_powerManagerPlugin->Register(_pwrMgrNotification.baseInterface<Exchange::IPowerManager::IModeChangedNotification>());
}
if (Utils::IARM::isConnected())
{
IARM_Result_t res;
IARM_CHECK( IARM_Bus_RemoveEventHandler(IARM_BUS_PWRMGR_NAME,IARM_BUS_PWRMGR_EVENT_MODECHANGED, powerModeChange) );
}
}

void setResponseArray(JsonObject& response, const char* key, const std::vector<std::string>& items)
Expand Down
48 changes: 4 additions & 44 deletions FrontPanel/FrontPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
#include "Module.h"
#include "libIARM.h"
#include "frontpanel.h"
#include <interfaces/IPowerManager.h>
#include "PowerManagerInterface.h"

using namespace WPEFramework;
using PowerState = WPEFramework::Exchange::IPowerManager::PowerState;
using ThermalTemperature = WPEFramework::Exchange::IPowerManager::ThermalTemperature;

#define DATA_LED "data_led"
#define RECORD_LED "record_led"
Expand Down Expand Up @@ -85,38 +79,6 @@ namespace WPEFramework {
// will receive a JSONRPC message as a notification, in case this method is called.
class FrontPanel : public PluginHost::IPlugin, public PluginHost::JSONRPC {
private:
class PowerManagerNotification : public Exchange::IPowerManager::IModeChangedNotification {
private:
PowerManagerNotification(const PowerManagerNotification&) = delete;
PowerManagerNotification& operator=(const PowerManagerNotification&) = delete;

public:
explicit PowerManagerNotification(FrontPanel& parent)
: _parent(parent)
{
}
~PowerManagerNotification() override = default;

public:
void OnPowerModeChanged(const PowerState currentState, const PowerState newState) override
{
_parent.onPowerModeChanged(currentState, newState);
}

template <typename T>
T* baseInterface()
{
static_assert(std::is_base_of<T, PowerManagerNotification>(), "base type mismatch");
return static_cast<T*>(this);
}

BEGIN_INTERFACE_MAP(PowerManagerNotification)
INTERFACE_ENTRY(Exchange::IPowerManager::IModeChangedNotification)
END_INTERFACE_MAP

private:
FrontPanel& _parent;
};

// We do not allow this plugin to be copied !!
FrontPanel(const FrontPanel&) = delete;
Expand All @@ -139,7 +101,6 @@ namespace WPEFramework {
void setClockTestPattern(bool show);

void loadPreferences();
void InitializePowerManager(PluginHost::IShell *service);

//Begin methods
uint32_t setBrightnessWrapper(const JsonObject& parameters, JsonObject& response);
Expand All @@ -164,14 +125,16 @@ namespace WPEFramework {
virtual const string Initialize(PluginHost::IShell* shell) override;
virtual void Deinitialize(PluginHost::IShell* service) override;
virtual string Information() const override { return {}; }
void onPowerModeChanged(const PowerState currentState, const PowerState newState);
void updateLedTextPattern();
void registerEventHandlers();

BEGIN_INTERFACE_MAP(FrontPanel)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IDispatcher)
END_INTERFACE_MAP
private:
void InitializeIARM();
void DeinitializeIARM();
static void powerModeChange(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
public:
static FrontPanel* _instance;
private:
Expand All @@ -181,9 +144,6 @@ namespace WPEFramework {
TestPatternInfo m_updateTimer;
bool m_runUpdateTimer;
std::mutex m_updateTimerMutex;
PowerManagerInterfaceRef _powerManagerPlugin;
Core::Sink<PowerManagerNotification> _pwrMgrNotification;
bool _registeredEventHandlers;

};
} // namespace Plugin
Expand Down
36 changes: 9 additions & 27 deletions helpers/frontpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@

#if defined(HAS_API_POWERSTATE)
#include "libIBus.h"
#include <interfaces/IPowerManager.h>

using namespace WPEFramework;
using PowerState = WPEFramework::Exchange::IPowerManager::PowerState;
#include "pwrMgr.h"
#endif

#include "UtilsJsonRpc.h"
#include "UtilsLogging.h"
#include "UtilssyncPersistFile.h"
#include "PowerManagerInterface.h"
#include "UtilsSearchRDKProfile.h"

#define FP_SETTINGS_FILE_JSON "/opt/fp_service_preferences.json"
Expand Down Expand Up @@ -85,7 +81,6 @@ namespace WPEFramework
static int m_currentBlinkListIndex = 0;
static std::vector<std::string> m_lights;
static device::List <device::FrontPanelIndicator> fpIndicators;
static PowerManagerInterfaceRef _powerManagerPlugin;

static Core::TimerType<BlinkInfo> blinkTimer(64 * 1024, "BlinkTimer");

Expand Down Expand Up @@ -128,18 +123,10 @@ namespace WPEFramework
{
}

CFrontPanel* CFrontPanel::instance(PluginHost::IShell *service)
CFrontPanel* CFrontPanel::instance()
{
if (!initDone)
{
if (nullptr != service)
{
_powerManagerPlugin = PowerManagerInterfaceBuilder(_T("org.rdk.PowerManager"))
.withIShell(service)
.withRetryIntervalMS(200)
.withRetryCount(25)
.createInterface();
}
if (!s_instance)
s_instance = new CFrontPanel;
#ifdef USE_DS
Expand All @@ -161,18 +148,13 @@ namespace WPEFramework

#if defined(HAS_API_POWERSTATE)
{
Core::hresult res = Core::ERROR_GENERAL;
PowerState pwrStateCur = WPEFramework::Exchange::IPowerManager::POWER_STATE_UNKNOWN;
PowerState pwrStatePrev = WPEFramework::Exchange::IPowerManager::POWER_STATE_UNKNOWN;
ASSERT (_powerManagerPlugin);
if (_powerManagerPlugin) {
res = _powerManagerPlugin->GetPowerState(pwrStateCur, pwrStatePrev);
if (Core::ERROR_NONE == res)
{
if (pwrStateCur == WPEFramework::Exchange::IPowerManager::POWER_STATE_ON)
powerStatus = true;
}
LOGINFO("pwrStateCur[%d] pwrStatePrev[%d] powerStatus[%d]", pwrStateCur, pwrStatePrev, powerStatus);
IARM_Bus_PWRMgr_GetPowerState_Param_t param;
IARM_Result_t res = IARM_Bus_Call(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_API_GetPowerState,
(void*)&param, sizeof(param));

if (res == IARM_RESULT_SUCCESS) {
if (param.curState == IARM_BUS_PWRMGR_POWERSTATE_ON)
powerStatus = true;
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion helpers/frontpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace WPEFramework
class CFrontPanel
{
public:
static CFrontPanel* instance(PluginHost::IShell *service = nullptr);
static CFrontPanel* instance();
bool start();
bool stop();
std::string getLastError();
Expand Down
Loading