Skip to content

Commit

Permalink
Merge pull request rdkcentral#5689 from ssitar583/sprint/24Q3
Browse files Browse the repository at this point in the history
DELIA-65834 : Skipped new mode request
  • Loading branch information
anand-ky authored Sep 11, 2024
2 parents 9e66835 + 99f5b13 commit 74bcf19
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
33 changes: 19 additions & 14 deletions SystemServices/SystemServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,29 +1392,31 @@ namespace WPEFramework {
JsonObject& response)
{
bool changeMode = true;
bool isTimerContext = false;
getBoolParameter("timercontext", isTimerContext);
JsonObject param;
std::string oldMode = m_currentMode;
bool result = true;
if(m_remainingDuration>0)
if((!isTimerContext) && isTimerActive())
{
populateResponseWithError(SysSrv_ModeChangeInProgress, response);
LOGERR("Mode change is already in progress.current mode is %s and it will be in progress for next %d seconds. Please try again later.\n",m_currentMode.c_str(),m_remainingDuration);
int actualDurationLeft = m_remainingDuration ? m_remainingDuration : 1;
LOGERR("Mode change is already in progress.current mode is %s and it will be in progress for next %d seconds. Please try again later.\n",m_currentMode.c_str(),actualDurationLeft);
returnResponse(false);
}
if (parameters.HasLabel("modeInfo")) {
param.FromString(parameters["modeInfo"].String());
if (param.HasLabel("duration") && param.HasLabel("mode")) {
int duration = param["duration"].Number();
std::string newMode = param["mode"].String();
if(duration>86400)
if(duration>86400)
{
LOGWARN("Duration is more than 24 hours. Setting duration to 24 hours,which is maximum allowed duration to set\n");
duration = 86400;
}
LOGWARN("request to switch to mode '%s' from mode '%s' \
with duration %d\n", newMode.c_str(),
oldMode.c_str(), duration);

if (MODE_NORMAL != newMode && MODE_WAREHOUSE != newMode &&
MODE_EAS != newMode) {
LOGERR("value of new mode is incorrect, therefore \
Expand All @@ -1431,16 +1433,13 @@ namespace WPEFramework {
m_currentMode = MODE_NORMAL;
stopModeTimer();
}

if (changeMode) {
IARM_Bus_CommonAPI_SysModeChange_Param_t modeParam;
stringToIarmMode(oldMode, modeParam.oldMode);
stringToIarmMode(m_currentMode, modeParam.newMode);

if (IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_DAEMON_NAME,
"DaemonSysModeChange", &modeParam, sizeof(modeParam))) {
LOGWARN("switched to mode '%s'\n", m_currentMode.c_str());

if (MODE_NORMAL != m_currentMode && duration < 0) {
LOGWARN("duration is negative, therefore \
mode timer stopped and Receiver will keep \
Expand All @@ -1462,6 +1461,7 @@ namespace WPEFramework {
command = "rm -f ";
}
command += WAREHOUSE_MODE_FILE;

/* TODO: replace with system alternate. */
int sysStat = system(command.c_str());
LOGINFO("system returned %d\n", sysStat);
Expand Down Expand Up @@ -1491,15 +1491,22 @@ namespace WPEFramework {
m_temp_settings.setValue("mode_duration", m_remainingDuration);
}

void SystemServices::stopModeTimer()
void SystemServices::stopModeTimer(bool isDetachRequired)
{
m_remainingDuration = 0;
m_operatingModeTimer.stop();

if(isDetachRequired)
{
m_operatingModeTimer.detach();
}
//set values in temp file so they can be restored in receiver restarts / crashes
// TODO: query & confirm time duration range.
m_temp_settings.setValue("mode_duration", m_remainingDuration);
}
bool SystemServices::isTimerActive()
{
return m_operatingModeTimer.isActive();
}

/**
* @brief This function is used to update duration.
Expand All @@ -1508,22 +1515,20 @@ namespace WPEFramework {
{
if (m_remainingDuration > 0) {
m_remainingDuration--;
m_temp_settings.setValue("mode_duration", m_remainingDuration);
} else {
m_operatingModeTimer.stop();
m_operatingModeTimer.detach();
stopModeTimer(true);
JsonObject parameters, param, response;
param["mode"] = "NORMAL";
param["duration"] = 0;
param["timercontext"] = true;
parameters["modeInfo"] = param;
if (_instance) {
_instance->setMode(parameters,response);
} else {
LOGERR("_instance is NULL.\n");
}
}

//set values in temp file so they can be restored in receiver restarts / crashes
m_temp_settings.setValue("mode_duration", m_remainingDuration);
}

/***
Expand Down
3 changes: 2 additions & 1 deletion SystemServices/SystemServices.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ namespace WPEFramework {
std::string m_strRegion;

static void startModeTimer(int duration);
static void stopModeTimer();
static void stopModeTimer(bool isDetachRequired = false);
static bool isTimerActive();
static void updateDuration();
std::string m_strStandardTerritoryList;
#ifdef ENABLE_DEVICE_MANUFACTURER_INFO
Expand Down
29 changes: 18 additions & 11 deletions SystemServices/cTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
cTimer::cTimer()
{
clear = false;
active = false;
interval = 0;
}

Expand All @@ -42,15 +43,17 @@ cTimer::~cTimer()
Running this timer function as thread function
*/
void cTimer::timerFunction() {
this->active = true;
while (true) {
if (this->clear) {
if (this->clear) {
this->active = false;
return;
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
if (this->clear) {
if (this->clear) {
this->active = false;
return;
}

}
this->callBack_function();
}
}
Expand All @@ -74,19 +77,24 @@ bool cTimer::start()
*/
void cTimer::stop()
{
this->clear = true;
this->clear = true;
}

bool cTimer::isActive()
{
return this->active;
}

void cTimer::detach()
{
timerThread.detach();
timerThread.detach();
}

void cTimer::join()
{
if (timerThread.joinable()) {
timerThread.join();
}
if (timerThread.joinable()) {
timerThread.join();
}
}

/***
Expand All @@ -100,4 +108,3 @@ void cTimer::setInterval(void (*function)(), int val)
this->callBack_function = function;
this->interval = val;
}

2 changes: 2 additions & 0 deletions SystemServices/cTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using namespace std;
class cTimer{
private:
bool clear;
bool active;
int interval;
void (*callBack_function)() = NULL;
std::thread timerThread;
Expand Down Expand Up @@ -57,6 +58,7 @@ class cTimer{
void stop();
void detach();
void join();
bool isActive();

/***
* @brief : Set interval in which the given function should be invoked.
Expand Down

0 comments on commit 74bcf19

Please sign in to comment.