Skip to content

Commit

Permalink
RDK-53686 Analytics JsonRpc uses autogenerated types
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Oct 28, 2024
1 parent 1129d7a commit fb4e6b3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 66 deletions.
3 changes: 2 additions & 1 deletion Analytics/Analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Module.h"

#include <interfaces/IAnalytics.h>
#include <interfaces/json/JsonData_Analytics.h>

namespace WPEFramework {

Expand Down Expand Up @@ -75,7 +76,7 @@ namespace WPEFramework {
void RegisterAll();
void UnregisterAll();

uint32_t SendEventWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t sendEventWrapper(const JsonData::Analytics::SendEventParamsInfo& parameters, JsonObject& response);

private:
PluginHost::IShell* mService;
Expand Down
39 changes: 14 additions & 25 deletions Analytics/AnalyticsJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ const string WPEFramework::Plugin::Analytics::ANALYTICS_METHOD_SEND_EVENT = "sen
namespace WPEFramework {

namespace Plugin {

using namespace JsonData::Analytics;

// Registration
//

void Analytics::RegisterAll()
{
Register(_T(ANALYTICS_METHOD_SEND_EVENT), &Analytics::SendEventWrapper, this);
Register<SendEventParamsInfo, JsonObject>(_T(ANALYTICS_METHOD_SEND_EVENT), &Analytics::sendEventWrapper, this);
}

void Analytics::UnregisterAll()
Expand All @@ -45,41 +48,27 @@ namespace Plugin {
// Return codes:
// - ERROR_NONE: Success
// - ERROR_GENERAL: Failed to send the event
uint32_t Analytics::SendEventWrapper(const JsonObject& parameters, JsonObject& response)
uint32_t Analytics::sendEventWrapper(const SendEventParamsInfo& parameters, JsonObject& response)
{
LOGINFOMETHOD();

uint32_t result = Core::ERROR_NONE;

returnIfStringParamNotFound(parameters, "eventName");
returnIfStringParamNotFound(parameters, "eventSource");
returnIfStringParamNotFound(parameters, "eventSourceVersion");
returnIfParamNotFound(parameters, "cetList");
returnIfParamNotFound(parameters, "eventPayload");

string eventName = parameters["eventName"].String();
string eventVersion = (parameters.HasLabel("eventVersion") ? parameters["eventVersion"].String() : "");
string eventSource = parameters["eventSource"].String();
string eventSourceVersion = parameters["eventSourceVersion"].String();
JsonArray cetListJson = parameters["cetList"].Array();
std::list<string> cetList;
for (int i=0; i<cetListJson.Length(); i++) {
cetList.emplace_back(cetListJson[i].String());
for (int i=0; i<parameters.CetList.Length(); i++) {
cetList.emplace_back(parameters.CetList[i]);
}
RPC::IStringIterator *cetListIterator = Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(cetList);
uint64_t epochTimestamp = (parameters.HasLabel("epochTimestamp"))? parameters["epochTimestamp"].Number() : 0;
uint64_t uptimeTimestamp = (parameters.HasLabel("uptimeTimestamp"))? parameters["uptimeTimestamp"].Number() : 0;
string eventPayload = parameters["eventPayload"].String();

if (mAnalytics != nullptr) {
result = mAnalytics->SendEvent(eventName,
eventVersion,
eventSource,
eventSourceVersion,
result = mAnalytics->SendEvent(parameters.EventName,
parameters.EventVersion,
parameters.EventSource,
parameters.EventSourceVersion,
cetListIterator,
epochTimestamp,
uptimeTimestamp,
eventPayload);
parameters.EpochTimestamp,
parameters.UptimeTimestamp,
parameters.EventPayload);
}

cetListIterator->Release();
Expand Down
27 changes: 27 additions & 0 deletions Analytics/Implementation/AnalyticsImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,33 @@ namespace Plugin {
LOGINFO("Uptime Timestamp: %" PRIu64, uptimeTimestamp);
LOGINFO("Event Payload: %s", eventPayload.c_str());

bool valid = true;
if (eventName.empty())
{
LOGERR("eventName is empty");
valid = false;
}
if (eventSource.empty())
{
LOGERR("eventSource is empty");
valid = false;
}
if (eventSourceVersion.empty())
{
LOGERR("eventSourceVersion is empty");
valid = false;
}
if (eventPayload.empty())
{
LOGERR("eventPayload is empty");
valid = false;
}

if (valid == false)
{
return Core::ERROR_GENERAL;
}

// Fill the uptime if no time provided
if (event->epochTimestamp == 0 && event->uptimeTimestamp == 0)
{
Expand Down
3 changes: 0 additions & 3 deletions Tests/L1Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ include_directories(../../LocationSync
../../Miracast/MiracastService/P2P
../../Miracast/MiracastPlayer
../../Miracast/MiracastPlayer/RTSP
../../Analytics
)
link_directories(../../LocationSync
../../SecurityAgent
Expand Down Expand Up @@ -142,7 +141,6 @@ link_directories(../../LocationSync
../../TextToSpeech
../../SystemAudioPlayer
../../Miracast
../../Analytics
)

target_link_libraries(${PROJECT_NAME}
Expand Down Expand Up @@ -187,7 +185,6 @@ target_link_libraries(${PROJECT_NAME}
${NAMESPACE}SystemAudioPlayer
${NAMESPACE}MiracastService
${NAMESPACE}MiracastPlayer
${NAMESPACE}Analytics
)

target_include_directories(${PROJECT_NAME}
Expand Down
35 changes: 0 additions & 35 deletions Tests/L1Tests/tests/test_Analytics.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions l1tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,3 @@ set(PLUGIN_MAINTENANCEMANAGER ON)
set(PLUGIN_PACKAGER ON)
set(DS_FOUND ON)
set(PLUGIN_SYSTEMAUDIOPLAYER ON)
set(PLUGIN_ANALYTICS ON)
set(PLUGIN_ANALYTICS_SIFT_BACKEND ON)

0 comments on commit fb4e6b3

Please sign in to comment.