Skip to content

Commit

Permalink
RDK-53686: Support generation of IAnalytics stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Oct 17, 2024
1 parent 49e01fc commit bdff736
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 179 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/L1-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
with:
path: |
build/Thunder
build/ThunderInterfaces
build/ThunderTools
install
!install/etc/WPEFramework/plugins
Expand All @@ -55,7 +56,7 @@ jobs:
!install/usr/lib/pkgconfig/gtest.pc
!install/usr/lib/pkgconfig/gtest_main.pc
!install/usr/lib/wpeframework/plugins
key: ${{ runner.os }}-${{ env.THUNDER_REF }}-${{ env.INTERFACES_REF }}-4
key: ${{ runner.os }}-${{ env.THUNDER_REF }}-${{ env.INTERFACES_REF }}-5
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -130,22 +131,24 @@ jobs:
with:
path: rdkservices

- name: Apply patch rdkservices
run: >
cd "${{github.workspace}}/rdkservices"
&&
git apply "${{github.workspace}}/rdkservices/Tests/L1Tests/patches/0001-IAnalytics.h-changes-for-Thunder-R2.patch"
&&
cd ..
- name: Checkout ThunderInterfaces
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: rdkcentral/ThunderInterfaces
path: ThunderInterfaces
ref: ${{env.INTERFACES_REF}}

- name: Apply patches ThunderInterfaces
run: >
cd "${{github.workspace}}/ThunderInterfaces"
&&
git apply "${{github.workspace}}/rdkservices/Tests/L1Tests/patches/0001-Add-IAnalytics-interface-R2.patch"
&&
cd ..
- name: Build ThunderInterfaces
if: steps.cache.outputs.cache-hit != 'true'
run: >
cmake
-S "${{github.workspace}}/ThunderInterfaces"
Expand Down
3 changes: 1 addition & 2 deletions Analytics/Analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#pragma once

#include "Module.h"

#include <interfaces/IAnalytics.h>
#include "IAnalytics.h"

namespace WPEFramework {

Expand Down
25 changes: 0 additions & 25 deletions Analytics/Analytics.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,6 @@
"result": {
"$ref": "#/common/result"
}
},
"setSessionId" : {
"summary": "Set the session ID for the analytics events",
"params": {
"type":"object",
"properties": {
"sessionId":{
"summary": "Session ID",
"type": "string",
"example": "1234567890"
}
},
"required": [
"sessionId"
]
},
"result": {
"$ref": "#/common/result"
}
},
"setTimeReady" : {
"summary": "Let the analytics plugin know that the system time is ready and valid",
"result": {
"$ref": "#/common/result"
}
}
}
}
46 changes: 0 additions & 46 deletions Analytics/AnalyticsJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#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 @@ -34,15 +31,11 @@ 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 @@ -92,45 +85,6 @@ namespace Plugin {
cetListIterator->Release();
returnResponse(result == Core::ERROR_NONE);
}

// 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();

if (mAnalytics != nullptr) {
result = mAnalytics->SetSessionId(sessionId);
}

returnResponse(result == Core::ERROR_NONE);
}

// 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;

if (mAnalytics != nullptr) {
result = mAnalytics->SetTimeReady();
}

returnResponse(result == Core::ERROR_NONE);
}

}

}
3 changes: 3 additions & 0 deletions Analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ All notable changes to this RDK Service will be documented in this file.

For more details, refer to versioning section under Main README.

## [1.0.1] - 2024-10-16
- Analytics improvements phase 2

## [1.0.0] - 2024-07-25
### Added
- New RDK Service Analytics to handle analytics events and send them to dedicated backends
Expand Down
95 changes: 93 additions & 2 deletions Analytics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME})

set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(VERSION_PATCH 1)

add_compile_definitions(ANALYTICS_MAJOR_VERSION=${VERSION_MAJOR})
add_compile_definitions(ANALYTICS_MINOR_VERSION=${VERSION_MINOR})
Expand All @@ -30,7 +30,6 @@ set(MODULE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})

option(PLUGIN_ANALYTICS_SIFT_BACKEND "Enable Sift backend" OFF)


set(PLUGIN_ANALYTICS_STARTUPORDER "" CACHE STRING "To configure startup order of Analytics plugin")
set(PLUGIN_ANALYTICS_AUTOSTART "false" CACHE STRING "Automatically start Analytics plugin")
set(PLUGIN_ANALYTICS_DEVICE_OS_NAME "rdk" CACHE STRING "Device OS name")
Expand Down Expand Up @@ -61,6 +60,98 @@ find_package(CompileSettingsDebug CONFIG REQUIRED)
find_package(DS)
find_package(IARMBus)

# -- Build IAnalytics interface --

find_package(WPEFramework REQUIRED)
find_package(${NAMESPACE}Core REQUIRED)
find_package(CompileSettingsDebug REQUIRED)
find_package(ProxyStubGenerator REQUIRED)
find_package(JsonGenerator REQUIRED)

# Interfaces we want to build
set(INTERFACES_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/IAnalytics.h"
)

# Invoke the code generators
if(NOT GENERATOR_SEARCH_PATH)
set(GENERATOR_SEARCH_PATH ${CMAKE_SYSROOT}${CMAKE_INSTALL_PREFIX}/include/${NAMESPACE})
endif()

message("Using generator search path: ${GENERATOR_SEARCH_PATH}")

ProxyStubGenerator(
INPUT ${INTERFACES_HEADERS}
OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated"
INCLUDE_PATH ${GENERATOR_SEARCH_PATH}
)

JsonGenerator(
CODE
INPUT ${INTERFACES_HEADERS}
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/generated"
INCLUDE_PATH ${GENERATOR_SEARCH_PATH}
)

# Find the generated sources
file(GLOB PROXY_STUB_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/generated/ProxyStubs*.cpp")
file(GLOB JSON_ENUM_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/generated/JsonEnum*.cpp")
file(GLOB JSON_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/generated/J*.h")

# Build the proxystub lib
add_library(AnalyticsProxyStubs SHARED
${PROXY_STUB_SOURCES}
Module.cpp
)

target_link_libraries(AnalyticsProxyStubs
PRIVATE
${NAMESPACE}Core::${NAMESPACE}Core
CompileSettingsDebug::CompileSettingsDebug
)

target_include_directories(AnalyticsProxyStubs
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

# Build the definitions lib if applicable
if(JSON_ENUM_SOURCES)
add_library(AnalyticsDefinitions SHARED
${JSON_ENUM_SOURCES}
)

target_link_libraries(AnalyticsDefinitions
PRIVATE
${NAMESPACE}Core::${NAMESPACE}Core
CompileSettingsDebug::CompileSettingsDebug
)
endif()

# Install libs & headers
string(TOLOWER ${NAMESPACE} NAMESPACE_LIB)
install(TARGETS AnalyticsProxyStubs
EXPORT AnalyticsProxyStubsTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${NAMESPACE_LIB}/proxystubs COMPONENT ${NAMESPACE}_Runtime
)

if(JSON_ENUM_SOURCES)
install(TARGETS AnalyticsDefinitions
EXPORT AnalyticsDefinitionsTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ COMPONENT ${NAMESPACE}_Runtime
)
endif()

install(FILES ${INTERFACES_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${NAMESPACE}/interfaces
)

install(FILES ${JSON_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${NAMESPACE}/interfaces/json
)

# -- end of IAnalytics interface build --

add_library(${MODULE_NAME} SHARED
Analytics.cpp
AnalyticsJsonRpc.cpp
Expand Down
60 changes: 60 additions & 0 deletions Analytics/IAnalytics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#pragma once

#include "Module.h"

// @stubgen:include <com/IIteratorType.h>

#define ID_ANALYTICS_OFFSET 0x1000

namespace WPEFramework {
namespace Exchange {
// @json 1.0.0
struct EXTERNAL IAnalytics : virtual public Core::IUnknown {
enum { ID = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + ID_ANALYTICS_OFFSET };

virtual ~IAnalytics() override = default;

using IStringIterator = RPC::IIteratorType<string, RPC::ID_STRINGITERATOR>;

/**
* @alt sendEvent
* @brief Send an event to the analytics server
* @param eventName Name of the event
* @param eventVersion Version of the event
* @param eventSource Source of the event
* @param eventSourceVersion Version of the event source
* @param cetList List of CETs
* @param epochTimestamp Epoch timestamp of the event
* @param uptimeTimestamp Uptime timestamp of the event
* @param eventPayload Payload of the event
*/
virtual Core::hresult SendEvent(const string& eventName /* @in */,
const string& eventVersion /* @in */,
const string& eventSource /* @in */,
const string& eventSourceVersion /* @in */,
IStringIterator* const& cetList /* @in */,
const uint64_t epochTimestamp /* @in */,
const uint64_t uptimeTimestamp /* @in */,
const string& eventPayload /* @in */ ) = 0;
};
}
}
18 changes: 4 additions & 14 deletions Analytics/Implementation/AnalyticsImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ namespace Plugin {
mThread.join();
}

/* virtual */ uint32_t AnalyticsImplementation::SendEvent(const string& eventName,
/* virtual */ Core::hresult AnalyticsImplementation::SendEvent(const string& eventName,
const string& eventVersion,
const string& eventSource,
const string& eventSourceVersion,
RPC::IStringIterator* const& cetList,
const uint64_t& epochTimestamp,
const uint64_t& uptimeTimestamp,
IStringIterator* const& cetList,
const uint64_t epochTimestamp,
const uint64_t uptimeTimestamp,
const string& eventPayload)
{
std::shared_ptr<Event> event = std::make_shared<Event>();
Expand Down Expand Up @@ -100,16 +100,6 @@ namespace Plugin {
return Core::ERROR_NONE;
}

uint32_t AnalyticsImplementation::SetSessionId(const string& id)
{
return Core::ERROR_NONE;
}

uint32_t AnalyticsImplementation::SetTimeReady()
{
return Core::ERROR_NONE;
}

uint32_t AnalyticsImplementation::Configure(PluginHost::IShell* shell)
{
LOGINFO("Configuring Analytics");
Expand Down
Loading

0 comments on commit bdff736

Please sign in to comment.