Skip to content

Commit

Permalink
RDK-51273: Support LocalStorage and Uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Sep 2, 2024
1 parent 37d0037 commit 63ad130
Show file tree
Hide file tree
Showing 23 changed files with 1,968 additions and 303 deletions.
3 changes: 3 additions & 0 deletions Analytics/Analytics.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ if boolean("@PLUGIN_ANALYTICS_SIFT_BACKEND_ENABLED@"):
sift.add("minretryperiod", "@PLUGIN_ANALYTICS_SIFT_MIN_RETRY_PERIOD@")
sift.add("maxretryperiod", "@PLUGIN_ANALYTICS_SIFT_MAX_RETRY_PERIOD@")
sift.add("exponentialperiodicfactor", "@PLUGIN_ANALYTICS_SIFT_EXPONENTIAL_PERIODIC_FACTOR@")
sift.add("storepath", "@PLUGIN_ANALYTICS_SIFT_STORE_PATH@")
sift.add("eventslimit", "@PLUGIN_ANALYTICS_SIFT_STORE_EVENTS_LIMIT@")
sift.add("url", "@PLUGIN_ANALYTICS_SIFT_URL@")
configuration.add("sift", sift)
1 change: 1 addition & 0 deletions Analytics/Analytics.config
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if(PLUGIN_ANALYTICS_SIFT_BACKEND_ENABLED)
kv(minretryperiod, ${PLUGIN_ANALYTICS_SIFT_MIN_RETRY_PERIOD})
kv(maxretryperiod, ${PLUGIN_ANALYTICS_SIFT_MAX_RETRY_PERIOD})
kv(exponentialperiodicfactor, ${PLUGIN_ANALYTICS_SIFT_EXPONENTIAL_PERIODIC_FACTOR})
kv(storepath, ${PLUGIN_ANALYTICS_SIFT_STORE_PATH})
end()
ans(siftobject)
map_append(${configuration} sift ${siftobject})
Expand Down
5 changes: 5 additions & 0 deletions Analytics/Analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ namespace WPEFramework {
END_INTERFACE_MAP

static const string ANALYTICS_METHOD_SEND_EVENT;
static const string ANALYTICS_METHOD_SET_SESSION_ID;
static const string ANALYTICS_METHOD_SET_TIME_READY;

private:
void Deactivated(RPC::IRemoteConnection* connection);
// JSONRPC methods
void RegisterAll();
void UnregisterAll();

uint32_t SendEventWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t SetSessionIdWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t SetTimeReadyWrapper(const JsonObject& parameters, JsonObject& response);

private:
PluginHost::IShell* mService;
Expand Down
41 changes: 41 additions & 0 deletions Analytics/AnalyticsJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "UtilsJsonRpc.h"

const string WPEFramework::Plugin::Analytics::ANALYTICS_METHOD_SEND_EVENT = "sendEvent";
// TODO: To be removed once the Analytics is capable of handling it internally
const string WPEFramework::Plugin::Analytics::ANALYTICS_METHOD_SET_SESSION_ID = "setSessionId";
const string WPEFramework::Plugin::Analytics::ANALYTICS_METHOD_SET_TIME_READY = "setTimeReady";

namespace WPEFramework {

Expand All @@ -31,11 +34,15 @@ namespace Plugin {
void Analytics::RegisterAll()
{
Register(_T(ANALYTICS_METHOD_SEND_EVENT), &Analytics::SendEventWrapper, this);
Register(_T(ANALYTICS_METHOD_SET_SESSION_ID), &Analytics::SetSessionIdWrapper, this);
Register(_T(ANALYTICS_METHOD_SET_TIME_READY), &Analytics::SetTimeReadyWrapper, this);
}

void Analytics::UnregisterAll()
{
Unregister(_T(ANALYTICS_METHOD_SEND_EVENT));
Unregister(_T(ANALYTICS_METHOD_SET_SESSION_ID));
Unregister(_T(ANALYTICS_METHOD_SET_TIME_READY));
}

// API implementation
Expand Down Expand Up @@ -83,6 +90,40 @@ namespace Plugin {
returnResponse(result);
}

// Method: setSessionId - Set the session ID
// Return codes:
// - ERROR_NONE: Success
// - ERROR_GENERAL: Failed to set the session ID
uint32_t Analytics::SetSessionIdWrapper(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();

uint32_t result = Core::ERROR_NONE;

returnIfStringParamNotFound(parameters, "sessionId");

string sessionId = parameters["sessionId"].String();

result = mAnalytics->SetSessionId(sessionId);

returnResponse(result);
}

// Method: setTimeReady - Set the time ready
// Return codes:
// - ERROR_NONE: Success
// - ERROR_GENERAL: Failed to set the time ready
uint32_t Analytics::SetTimeReadyWrapper(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();

uint32_t result = Core::ERROR_NONE;

result = mAnalytics->SetTimeReady();

returnResponse(result);
}

}

}
5 changes: 4 additions & 1 deletion Analytics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ set(PLUGIN_ANALYTICS_SIFT_MAX_RETRIES 10 CACHE STRING "Sift max retries posting
set(PLUGIN_ANALYTICS_SIFT_MIN_RETRY_PERIOD 1 CACHE STRING "Sift min retry period seconds")
set(PLUGIN_ANALYTICS_SIFT_MAX_RETRY_PERIOD 30 CACHE STRING "Sift max retry period seconds")
set(PLUGIN_ANALYTICS_SIFT_EXPONENTIAL_PERIODIC_FACTOR 2 CACHE STRING "Sift exponential periodic factor")

set(PLUGIN_ANALYTICS_SIFT_STORE_PATH "/opt/persistent/sky/AnalyticsSiftStore" CACHE STRING "Sift store path")
set(PLUGIN_ANALYTICS_SIFT_STORE_EVENTS_LIMIT 1000 CACHE STRING "Sift store events limit")
set(PLUGIN_ANALYTICS_SIFT_URL "https://sift.rdkcloud.com/v1/events" CACHE STRING "Sift URL")

message("Setup ${MODULE_NAME} v${MODULE_VERSION}")

Expand All @@ -63,6 +65,7 @@ add_library(${MODULE_NAME} SHARED
target_include_directories(${MODULE_NAME} PRIVATE Implementation)
target_include_directories(${MODULE_NAME} PRIVATE ../helpers)

add_subdirectory(Implementation/LocalStore)
add_subdirectory(Implementation/Backend)

set_target_properties(${MODULE_NAME} PROPERTIES
Expand Down
43 changes: 31 additions & 12 deletions Analytics/Implementation/AnalyticsImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ namespace Plugin {
return Core::ERROR_NONE;
}

uint32_t AnalyticsImplementation::SetSessionId(const string& id)
{
uint32_t ret = Core::ERROR_GENERAL;
// set session id in sift backend
if (mBackends.find(IAnalyticsBackend::SIFT) != mBackends.end())
{
ret = mBackends.at(IAnalyticsBackend::SIFT).SetSessionId(id);
}

return ret;
}

uint32_t AnalyticsImplementation::SetTimeReady()
{
// set time ready action
std::unique_lock<std::mutex> lock(mQueueMutex);
mActionQueue.push({ACTION_TYPE_SET_TIME_READY, nullptr});
lock.unlock();
mQueueCondition.notify_one();
return Core::ERROR_NONE;
}

uint32_t AnalyticsImplementation::Configure(PluginHost::IShell* shell)
{
LOGINFO("Configuring Analytics");
Expand Down Expand Up @@ -137,7 +159,7 @@ namespace Plugin {

if (mActionQueue.empty() && !mSysTimeValid)
{
action = {ACTION_POPULATE_DEVICE_INFO, nullptr};
action = {ACTION_POPULATE_TIME_INFO, nullptr};
}
else
{
Expand All @@ -148,9 +170,9 @@ namespace Plugin {
lock.unlock();

switch (action.type) {
case ACTION_POPULATE_DEVICE_INFO:
case ACTION_POPULATE_TIME_INFO:

mSysTimeValid = IsSysTimeValid();
//mSysTimeValid = IsSysTimeValid();

if ( mSysTimeValid )
{
Expand All @@ -161,7 +183,7 @@ namespace Plugin {
mEventQueue.pop();
}
}
break;
break;
case ACTION_TYPE_SEND_EVENT:

if (mSysTimeValid)
Expand Down Expand Up @@ -191,6 +213,10 @@ namespace Plugin {
break;
case ACTION_TYPE_SHUTDOWN:
return;
case ACTION_TYPE_SET_TIME_READY:
{
mSysTimeValid = true;
}break;
default:
break;
}
Expand All @@ -202,14 +228,7 @@ namespace Plugin {
bool AnalyticsImplementation::IsSysTimeValid()
{
bool ret = false;
//TODO: Check here if time is OK
// for now check if /tmp/as_timezone_ready exists
std::ifstream timezoneFile("/tmp/as_timezone_ready");
if (timezoneFile.is_open())
{
timezoneFile.close();
ret = true;
}
//TODO: Add system time validation

return ret;
}
Expand Down
11 changes: 8 additions & 3 deletions Analytics/Implementation/AnalyticsImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ namespace Plugin {
enum ActionType
{
ACTION_TYPE_UNDEF,
ACTION_POPULATE_DEVICE_INFO,
ACTION_POPULATE_TIME_INFO,
ACTION_TYPE_SEND_EVENT,
ACTION_TYPE_SHUTDOWN
ACTION_TYPE_SHUTDOWN,
ACTION_TYPE_SET_TIME_READY
};

struct Event
Expand All @@ -70,6 +71,7 @@ namespace Plugin {
{
ActionType type;
std::shared_ptr<Event> payload;
std::string id;
};


Expand All @@ -82,6 +84,9 @@ namespace Plugin {
const uint64_t& epochTimestamp,
const uint64_t& uptimeTimestamp,
const string& eventPayload) override;
uint32_t SetSessionId(const string& id) override;
uint32_t SetTimeReady() override;


// IConfiguration interface
uint32_t Configure(PluginHost::IShell* shell);
Expand All @@ -99,7 +104,7 @@ namespace Plugin {
std::thread mThread;
std::queue<Action> mActionQueue;
std::queue<Event> mEventQueue;
IAnalyticsBackends mBackends;
const IAnalyticsBackends mBackends;
bool mSysTimeValid;
PluginHost::IShell* mShell;
};
Expand Down
1 change: 1 addition & 0 deletions Analytics/Implementation/Backend/AnalyticsBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace Plugin {

virtual uint32_t Configure(PluginHost::IShell* shell) = 0;
virtual uint32_t SendEvent(const Event& event) = 0;
virtual uint32_t SetSessionId(const std::string& sessionId) = 0;
};

typedef std::map<std::string, IAnalyticsBackend&> IAnalyticsBackends;
Expand Down
6 changes: 4 additions & 2 deletions Analytics/Implementation/Backend/Sift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set(TARGET_LIB ${NAMESPACE}${PLUGIN_NAME}SiftBackend)

add_library(${TARGET_LIB} STATIC)

target_sources(${TARGET_LIB} PRIVATE SiftBackend.cpp SiftConfig.cpp)
target_sources(${TARGET_LIB} PRIVATE SiftBackend.cpp SiftConfig.cpp SiftStore.cpp SiftUploader.cpp)

find_package(CURL)
if (CURL_FOUND)
Expand All @@ -28,8 +28,10 @@ else (CURL_FOUND)
message ("Curl/libcurl required.")
endif (CURL_FOUND)


target_include_directories(${TARGET_LIB} PUBLIC "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(${TARGET_LIB} PRIVATE ../../../../helpers)
target_include_directories(${TARGET_LIB} PRIVATE ../../LocalStore)
set_property(TARGET ${TARGET_LIB} PROPERTY POSITION_INDEPENDENT_CODE ON)
set_target_properties(${TARGET_LIB} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
target_link_libraries(${TARGET_LIB} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins)
target_link_libraries(${TARGET_LIB} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${NAMESPACE}${PLUGIN_NAME}LocalStore)
Loading

0 comments on commit 63ad130

Please sign in to comment.