Skip to content

Commit

Permalink
RDKDEV-1014:OMWAPPI-1545-XDialServer-patches-2401_sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
margret-jaison-infosys committed Apr 3, 2024
1 parent 4afd94c commit 3b54fbb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions server/plat/rtcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void rtAppStatusCache :: setAppCacheId(const char *app_name,std::string id)

rtError rtAppStatusCache::UpdateAppStatusCache(rtValue app_status)
{
const auto now = std::chrono::steady_clock::now();
printf("RTCACHE : %s\n",__FUNCTION__);

rtError err;
Expand All @@ -77,6 +78,10 @@ rtError rtAppStatusCache::UpdateAppStatusCache(rtValue app_status)

err = ObjectCache->insert(id,temp);
notifyStateChanged(App_name);
if (err == RT_OK) {
err = ObjectCache->markUnevictable(id, true);
last_updated[id] = now;
}
return err;
}

Expand Down Expand Up @@ -131,3 +136,15 @@ bool rtAppStatusCache::doIdExist(std::string id)
printf("True\n");
return true;
}

std::chrono::milliseconds rtAppStatusCache::getUpdateAge(const char *app_name)
{
const auto now = std::chrono::steady_clock::now();
std::string id = getAppCacheId(app_name);
auto it = last_updated.find(id);
if (it != last_updated.end()) {
return std::chrono::duration_cast<std::chrono::milliseconds>(now - it->second);
} else {
return std::chrono::milliseconds::max();
}
}
3 changes: 3 additions & 0 deletions server/plat/rtcache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class rtAppStatusCache : public rtObject
StateChangedCallbackHandle registerStateChangedCallback(StateChangedCallback callback);
void unregisterStateChangedCallback(StateChangedCallbackHandle callbackId);

std::chrono::milliseconds getUpdateAge(const char *app_name);

private:

void notifyStateChanged(std::string& id);
Expand All @@ -63,6 +65,7 @@ class rtAppStatusCache : public rtObject
StateChangedCallbackHandle next_handle = 0;
std::map<StateChangedCallbackHandle, StateChangedCallback> state_changed_listeners;
std::mutex state_changed_listeners_mutex;
std::map<std::string, std::chrono::steady_clock::time_point> last_updated;
};

#endif
12 changes: 10 additions & 2 deletions server/plat/rtdial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,17 +706,25 @@ int gdial_os_application_state(const char *app_name, int instance_id, GDialAppSt
}

static bool await_application_state_update(const char *app_name) {
using namespace std::chrono;
static int xdial_wait_for_rtremote_state_response_ms = -1;
if (xdial_wait_for_rtremote_state_response_ms == -1) {
const char* waitstr = getenv("XDIAL_WAIT_FOR_RTREMOTE_STATE_RESPONSE_MS");
xdial_wait_for_rtremote_state_response_ms = waitstr ? atoi(waitstr) : 0;
}
static auto xdial_max_state_value_age = milliseconds::max();
if (xdial_max_state_value_age == milliseconds::max()) {
const char* str = getenv("XDIAL_MAX_STATE_VALUE_AGE_MS");
xdial_max_state_value_age = milliseconds(str ? atoi(str) : 0);
}
// do not poll for the state update if currently held value is younger than XDIAL_MAX_STATE_VALUE_AGE_MS
if (xdial_max_state_value_age > milliseconds(0) && AppCache->getUpdateAge(app_name) < xdial_max_state_value_age) {
return false;
}
std::atomic_bool updated {false};
if (xdial_wait_for_rtremote_state_response_ms > 0) {
// the cached status could be wrong; rtremote state update request has already been launched
// so lets give it some time & report the updated value, if possible
using namespace std::chrono;

auto handlerid = AppCache->registerStateChangedCallback([&](const std::string& application){
if (application == app_name) {
updated = true;
Expand Down

0 comments on commit 3b54fbb

Please sign in to comment.