From 15c49599dc3cf04f900b4a1278ab28e4955a5a12 Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Tue, 2 Jul 2024 16:17:19 -0400 Subject: [PATCH 1/5] feat: Update tests for app-passthrough --- src/openrpc/discovery.json | 2 +- .../core/src/cpp/sdk/cpptest/CoreSDKTest.cpp | 27 ++++++++++++++++++- .../core/src/cpp/sdk/cpptest/CoreSDKTest.h | 1 + src/sdks/core/src/cpp/sdk/cpptest/Main.cpp | 5 ++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/openrpc/discovery.json b/src/openrpc/discovery.json index c3706de03..01ab2205e 100644 --- a/src/openrpc/discovery.json +++ b/src/openrpc/discovery.json @@ -642,7 +642,7 @@ "name": "identifiers", "summary": "A set of content identifiers for this call to action", "schema": { - "$ref": "https://meta.comcast.com/firebolt/entity#/definitions/Entity" + "$ref": "https://meta.comcast.com/firebolt/entertainment#/definitions/ContentIdentifiers" }, "required": true }, diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp index 065cfea6b..e82dc74a0 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp @@ -1110,6 +1110,31 @@ void CoreSDKTest::DiscoveryWatchNext() cout << "Discovery Watched Next status = " << static_cast(error) << endl; } } +void CoreSDKTest::DiscoveryUserInterest() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::Discovery::InterestType type = Firebolt::Discovery::InterestType::INTEREST; + Firebolt::Discovery::InterestReason reason = Firebolt::Discovery::InterestReason::PLAYLIST; + + // Set up the entity details + Firebolt::Entity::EntityDetails entity; + + // Identifiers + entity.identifiers = "{\"entityId\": \"123\"}"; + + // Optional Info Metadata + entity.info = Firebolt::Entity::Metadata(); + entity.info->title = "A Cool Show"; + entity.info->synopsis = "A cool show synopsis"; + + Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().userInterest(type, reason, entity, &error); + + if (error == Firebolt::Error::None) { + cout << "Discovery User Interest is success" << endl; + } else { + cout << "Discovery User Interest status = " << static_cast(error) << endl; + } +} void CoreSDKTest::DiscoveryPolicy() { Firebolt::Error error = Firebolt::Error::None; @@ -1269,7 +1294,7 @@ void CoreSDKTest::DiscoveryLaunch() std::optional intent = std::make_optional(); intent.value().action = "tune"; intent.value().data.entity.entityType = "channel"; - intent.value().data.entity.channelType = Firebolt::Intents::ChannelEntityChannelType::STREAMING; + intent.value().data.entity.channelType = Firebolt::Entity::ChannelEntityChannelType::STREAMING; intent.value().data.entity.entityId = "an-ott-channel"; std::string entityId; std::optional appContentData; diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h index 9b8d056ea..698884ea4 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h @@ -174,6 +174,7 @@ class CoreSDKTest { static void SubscribeDiscoveryOnNavigateToLaunchNotification(); static void UnsubscribeDiscoveryOnNavigateToLaunchNotification(); static void DiscoveryWatchNext(); + static void DiscoveryUserInterest(); static void ParametersInitialization(); diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp index 2e8bbba9b..7c4441792 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp @@ -122,6 +122,7 @@ void ShowDiscoveryMenu() "\tP : Policy\n" "\tU : PurchasedContent\n" "\tN : WatchNext\n" + "\tF : UserInterest\n" "\tL : Launch\n" #ifdef POLYMORPHICS_REDUCER_METHODS "\tW : Watched\n" @@ -472,6 +473,10 @@ void HandleDiscoveryMethod() CoreSDKTest::DiscoveryWatchNext(); break; } + case 'F': { + CoreSDKTest::DiscoveryUserInterest(); + break; + } case 'L': { CoreSDKTest::DiscoveryLaunch(); break; From 7d8133e5c376bf7826fbded2cd341212e8bedc18 Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Tue, 2 Jul 2024 20:36:29 -0400 Subject: [PATCH 2/5] fix: Add copyright comment to main.cpp files --- src/sdks/core/src/cpp/sdk/cpptest/Main.cpp | 18 ++++++++++++++++++ src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp index ac6f6653f..c4087ad94 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp @@ -1,3 +1,21 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + #include #include #include diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp index c28aa7e0c..4d2698dbe 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp @@ -1,3 +1,21 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + #include #include #include From c1fb3d13fffe78a5eb17f0dc1bf313d53e7b89d3 Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Tue, 2 Jul 2024 21:15:03 -0400 Subject: [PATCH 3/5] feat: Add discovery cpp testing files --- src/sdks/discovery/package.json | 3 + .../src/cpp/sdk/cpptest/CMakeLists.txt | 75 +++++++++++++ .../src/cpp/sdk/cpptest/DiscoverySDKTest.cpp | 102 ++++++++++++++++++ .../src/cpp/sdk/cpptest/DiscoverySDKTest.h | 41 +++++++ .../discovery/src/cpp/sdk/cpptest/Main.cpp | 89 +++++++++++++++ .../discovery/src/cpp/sdk/cpptest/build.sh | 41 +++++++ 6 files changed, 351 insertions(+) create mode 100644 src/sdks/discovery/src/cpp/sdk/cpptest/CMakeLists.txt create mode 100644 src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp create mode 100644 src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h create mode 100644 src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp create mode 100644 src/sdks/discovery/src/cpp/sdk/cpptest/build.sh diff --git a/src/sdks/discovery/package.json b/src/sdks/discovery/package.json index 0e4ec34e9..f2384861c 100644 --- a/src/sdks/discovery/package.json +++ b/src/sdks/discovery/package.json @@ -12,6 +12,9 @@ "validate": "npx firebolt-openrpc validate --input ./dist/firebolt-discovery-open-rpc.json", "sdk": "npx firebolt-openrpc sdk --input ./dist/firebolt-discovery-open-rpc.json --template ./src/js --output ./build/javascript/src", "native": "npx firebolt-openrpc sdk --input ./dist/firebolt-discovery-open-rpc.json --template ./src/js --output ./build/c/src --language ../../../node_modules/@firebolt-js/openrpc/languages/c", + "cpp": "npm run cpp:compile && npm run cpp:install", + "cpp:compile": "npx firebolt-openrpc sdk --input ./dist/firebolt-discovery-open-rpc.json --template ./src/cpp --output ./build/cpp/src --static-module Platform --language ../../../node_modules/@firebolt-js/openrpc/languages/cpp", + "cpp:install": "./build/cpp/src/scripts/install.sh -i ./build/cpp/src -s ./build/cpp/src/ -m discovery", "compile": "cd ../../.. && npm run compile", "slice": "npx firebolt-openrpc slice -i ../../../dist/firebolt-open-rpc.json --sdk ./sdk.config.json -o ./dist/firebolt-discovery-open-rpc.json", "docs": "npx firebolt-openrpc docs --input ./dist/firebolt-discovery-open-rpc.json --output build/docs/markdown --as-path", diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/CMakeLists.txt b/src/sdks/discovery/src/cpp/sdk/cpptest/CMakeLists.txt new file mode 100644 index 000000000..e2fc88793 --- /dev/null +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/CMakeLists.txt @@ -0,0 +1,75 @@ +# Copyright 2023 Comcast Cable Communications Management, LLC +# +# 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. +# +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.3) + +project(FireboltDiscoverySDKTests) + +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${SYSROOT_PATH}/usr" CACHE INTERNAL "" FORCE) + set(CMAKE_PREFIX_PATH ${SYSROOT_PATH}/usr/lib/cmake CACHE INTERNAL "" FORCE) +endif() + +list(APPEND CMAKE_MODULE_PATH + "${SYSROOT_PATH}/usr/lib/cmake" + "${SYSROOT_PATH}/tools/cmake") +message("FIREBOLT_PATH inside cmake " ${FIREBOLT_PATH}) +if (FIREBOLT_PATH) + set(CMAKE_FIREBOLT_PATH + "${FIREBOLT_PATH}/usr/lib/cmake/Firebolt" + "${FIREBOLT_PATH}/usr/lib/cmake/FireboltSDK") + list(APPEND CMAKE_PREFIX_PATH ${CMAKE_FIREBOLT_PATH}) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_FIREBOLT_PATH}) +else () + set(FIREBOLT_PATH "${SYSROOT_PATH}" CACHE INTERNAL "" FORCE) +endif () + +find_package(WPEFramework CONFIG REQUIRED) +find_package(${NAMESPACE}Core CONFIG REQUIRED) +find_package(Firebolt CONFIG REQUIRED) +find_package(${FIREBOLT_NAMESPACE}SDK CONFIG REQUIRED) + +set(TESTAPP TestFireboltDiscovery) + +message("Setup ${TESTAPP}") + +add_executable(${TESTAPP} DiscoverySDKTest.cpp Main.cpp) + +target_link_libraries(${TESTAPP} + PRIVATE + ${NAMESPACE}Core::${NAMESPACE}Core + ${FIREBOLT_NAMESPACE}SDK::${FIREBOLT_NAMESPACE}SDK +) + +target_include_directories(${TESTAPP} + PRIVATE + $ + $ + $ +) + +set_target_properties(${TESTAPP} PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES +) + +add_custom_command( + TARGET ${TESTAPP} + POST_BUILD + COMMENT "=================== Installing TestApp ======================" + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${TESTAPP} ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin +) diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp new file mode 100644 index 000000000..9a0dad7bf --- /dev/null +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp @@ -0,0 +1,102 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include "DiscoverySDKTest.h" + +using namespace std; +bool DiscoverySDKTest::_connected; + +void DiscoverySDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error) +{ + cout << "Change in connection: connected: " << connected << " error: " << static_cast(error) << endl; + _connected = connected; +} + +void DiscoverySDKTest::CreateFireboltInstance(const std::string& url) +{ + const std::string config = "{\ + \"waitTime\": 100000,\ + \"logLevel\": \"Info\",\ + \"workerPool\":{\ + \"queueSize\": 8,\ + \"threadCount\": 3\ + },\ + \"wsUrl\": " + url + "}"; + + _connected = false; + Firebolt::IFireboltAccessor::Instance().Initialize(config); + Firebolt::IFireboltAccessor::Instance().Connect(ConnectionChanged); +} + +void DiscoverySDKTest::DestroyFireboltInstance() +{ + Firebolt::IFireboltAccessor::Instance().Disconnect(); + Firebolt::IFireboltAccessor::Instance().Deinitialize(); + Firebolt::IFireboltAccessor::Instance().Dispose(); +} + +bool DiscoverySDKTest::WaitOnConnectionReady() +{ + uint32_t waiting = 10000; + static constexpr uint32_t SLEEPSLOT_TIME = 100; + + // Right, a wait till connection is closed is requested.. + while ((waiting > 0) && (_connected == false)) { + + uint32_t sleepSlot = (waiting > SLEEPSLOT_TIME ? SLEEPSLOT_TIME : waiting); + // Right, lets sleep in slices of 100 ms + usleep(sleepSlot); + waiting -= sleepSlot; + } + return _connected; +} + +template +using EnumMap = std::unordered_map; +template +inline const string& ConvertFromEnum(EnumMap enumMap, T type) +{ + return enumMap[type]; +} +template +inline const T ConvertToEnum(EnumMap enumMap, const string& str) +{ + T value; + for (auto element: enumMap) { + if (element.second == str) { + value = element.first; + break; + } + } + return value; +} + +void DiscoverySDKTest::SampleTest() +{ + Firebolt::Error error = Firebolt::Error::None; + + if (error === Firebolt::Error::None) { + cout << "Sample Test Passed!" << endl; + } else { + std::string errorMessage = "Error: " + std::to_string(static_cast(error)); + throw std::runtime_error("SampleTest failed. " + errorMessage); + } +} diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h new file mode 100644 index 000000000..2fcd2bcc0 --- /dev/null +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include "firebolt.h" + +class DiscoverySDKTest { + +public: + DiscoverySDKTest() = default; + virtual ~DiscoverySDKTest() = default; + + static void CreateFireboltInstance(const std::string& url); + static void DestroyFireboltInstance(); + static void TestDiscoveryStaticSDK(); + + static void SampleTest(); + + static bool WaitOnConnectionReady(); + +private: + static void ConnectionChanged(const bool, const Firebolt::Error); + static bool _connected; +}; \ No newline at end of file diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp new file mode 100644 index 000000000..8e56bae39 --- /dev/null +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp @@ -0,0 +1,89 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include "DiscoverySDKTest.h" + +using namespace std; + +const char* options = ":hu:"; + +void RunAllTests() { + bool allTestsPassed = true; + vector errorMessages; + + auto runTest = [&allTestsPassed, &errorMessages](auto testFunction, const string& testName) { + try { + testFunction(); + } catch (const exception& e) { + errorMessages.push_back("Test " + testName + " failed: " + e.what()); + allTestsPassed = false; + } + }; + + // Ensure the connection is ready before running tests + if (DiscoverySDKTest::WaitOnConnectionReady()) { + // Add tests here + + // runTest(DiscoverySDKTest::TestName, "TestName"); + + if (allTestsPassed) { + cout << "============================" << endl; + cout << "ALL DISCOVERY SDK TESTS SUCCEEDED!" << endl; + cout << "============================" << endl; + } else { + cout << "============================" << endl; + cout << "SOME TESTS FAILED:" << endl; + for (const auto& errorMessage : errorMessages) { + cout << errorMessage << endl; + } + cout << "============================" << endl; + exit(1); + } + } else { + cout << "Discovery Test not able to connect with server..." << endl; + exit(1); + } +} + +int main(int argc, char* argv[]) { + int c; + string url = "ws://127.0.0.1:9998"; + while ((c = getopt(argc, argv, options)) != -1) { + switch (c) { + case 'u': + url = optarg; + break; + case 'h': + printf("./TestFireboltDiscovery -u ws://ip:port\n"); + exit(1); + } + } + + printf("Firebolt Discovery SDK Test\n"); + + DiscoverySDKTest::CreateFireboltInstance(url); + RunAllTests(); + DiscoverySDKTest::DestroyFireboltInstance(); + + return 0; +} \ No newline at end of file diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/build.sh b/src/sdks/discovery/src/cpp/sdk/cpptest/build.sh new file mode 100644 index 000000000..b404a78f3 --- /dev/null +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/build.sh @@ -0,0 +1,41 @@ +#!/bin/bash +usage() +{ + echo "options:" + echo " -t test path" + echo " -s sysroot path" + echo " -f firebolt path" + echo " -c clear build" + echo " -h : help" + echo + echo "usage: " + echo " ./build.sh -t testpath -c -f fireboltpath -s sysrootpath" +} + +TestPath="." +FireboltPath=${FIREBOLT_PATH} +SysrootPath=${SYSROOT_PATH} +ClearBuild="N" +while getopts t:s:f:ch flag +do + case "${flag}" in + t) TestPath="${OPTARG}";; + s) SysrootPath="${OPTARG}";; + f) FireboltPath="${OPTARG}";; + c) ClearBuild="Y";; + h) usage && exit 1;; + esac +done + +if [ "${ClearBuild}" == "Y" ]; +then + rm -rf ${TestPath}/build +fi + +echo "TestPath" +echo "${TestPath}" +echo "FireboltPath" +echo ${FireboltPath} +cmake -B${TestPath}/build -S${TestPath} -DSYSROOT_PATH=${SysrootPath} -DFIREBOLT_PATH=${FireboltPath} +# -DPOLYMORPHICS_METHODS=ON // Enable this to test +cmake --build ${TestPath}/build From 4f5f8e105c63b5e8f7c4a9d9d868b55efcdf690e Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Wed, 17 Jul 2024 11:15:21 -0400 Subject: [PATCH 4/5] fix cpp test template --- src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp | 2 +- src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp | 2 +- src/sdks/discovery/src/cpp/sdk/cpptest/build.sh | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp index 9a0dad7bf..27fe67244 100644 --- a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp @@ -93,7 +93,7 @@ void DiscoverySDKTest::SampleTest() { Firebolt::Error error = Firebolt::Error::None; - if (error === Firebolt::Error::None) { + if (error == Firebolt::Error::None) { cout << "Sample Test Passed!" << endl; } else { std::string errorMessage = "Error: " + std::to_string(static_cast(error)); diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp index 8e56bae39..26e2b5dc6 100644 --- a/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp @@ -44,7 +44,7 @@ void RunAllTests() { if (DiscoverySDKTest::WaitOnConnectionReady()) { // Add tests here - // runTest(DiscoverySDKTest::TestName, "TestName"); + runTest(DiscoverySDKTest::SampleTest, "SampleTest"); if (allTestsPassed) { cout << "============================" << endl; diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/build.sh b/src/sdks/discovery/src/cpp/sdk/cpptest/build.sh index b404a78f3..4db39cbe8 100644 --- a/src/sdks/discovery/src/cpp/sdk/cpptest/build.sh +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/build.sh @@ -37,5 +37,4 @@ echo "${TestPath}" echo "FireboltPath" echo ${FireboltPath} cmake -B${TestPath}/build -S${TestPath} -DSYSROOT_PATH=${SysrootPath} -DFIREBOLT_PATH=${FireboltPath} -# -DPOLYMORPHICS_METHODS=ON // Enable this to test cmake --build ${TestPath}/build From 62993bc54e63170ec5a4867489551607577dcf33 Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Tue, 23 Jul 2024 12:23:32 -0400 Subject: [PATCH 5/5] fix: Add static modules for discovery.content --- .../cpp/templates/Content/src/module_impl.cpp | 380 ++++++++++++++++++ .../cpp/templates/Content/src/module_impl.h | 136 +++++++ 2 files changed, 516 insertions(+) create mode 100644 src/sdks/discovery/src/cpp/templates/Content/src/module_impl.cpp create mode 100644 src/sdks/discovery/src/cpp/templates/Content/src/module_impl.h diff --git a/src/sdks/discovery/src/cpp/templates/Content/src/module_impl.cpp b/src/sdks/discovery/src/cpp/templates/Content/src/module_impl.cpp new file mode 100644 index 000000000..1b174038b --- /dev/null +++ b/src/sdks/discovery/src/cpp/templates/Content/src/module_impl.cpp @@ -0,0 +1,380 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "${info.title.lowercase}_impl.h" + +${if.implementations} +namespace Firebolt { +namespace ${info.Title} { +${if.providers} +/* ${PROVIDERS} */${end.if.providers} + + // Methods + /* requestUserInterest - Provide information about the entity currently displayed or selected on the screen. */ + InterestResult ContentImpl::requestUserInterest( const Discovery::InterestType& type, const Discovery::InterestReason& reason, Firebolt::Error *err ) + { + Firebolt::Error status = Firebolt::Error::NotConnected; + InterestResult interest; + FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); + if (transport != nullptr) { + + JsonObject jsonParameters; + Firebolt::Discovery::JsonData_InterestType jsonType = type; + WPEFramework::Core::JSON::Variant typeVariant(jsonType.Data()); + jsonParameters.Set(_T("type"), typeVariant); + Firebolt::Discovery::JsonData_InterestReason jsonReason = reason; + WPEFramework::Core::JSON::Variant reasonVariant(jsonReason.Data()); + jsonParameters.Set(_T("reason"), reasonVariant); + JsonData_InterestResult jsonResult; + status = transport->Invoke("content.requestUserInterest", jsonParameters, jsonResult); + if (status == Firebolt::Error::None) { + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Content.requestUserInterest is successfully invoked"); + InterestResult interestResult; + interestResult.appId = jsonResult.AppId.Value(); + { + string identifiersStr; + jsonResult.Entity.Identifiers.ToString(identifiersStr); + interestResult.entity.identifiers = identifiersStr; + if (jsonResult.Entity.Info.IsSet()) { + interestResult.entity.info = std::make_optional(); + if (jsonResult.Entity.Info.Title.IsSet()) { + interestResult.entity.info.value().title = jsonResult.Entity.Info.Title; + } + if (jsonResult.Entity.Info.Synopsis.IsSet()) { + interestResult.entity.info.value().synopsis = jsonResult.Entity.Info.Synopsis; + } + if (jsonResult.Entity.Info.SeasonNumber.IsSet()) { + interestResult.entity.info.value().seasonNumber = jsonResult.Entity.Info.SeasonNumber; + } + if (jsonResult.Entity.Info.SeasonCount.IsSet()) { + interestResult.entity.info.value().seasonCount = jsonResult.Entity.Info.SeasonCount; + } + if (jsonResult.Entity.Info.EpisodeNumber.IsSet()) { + interestResult.entity.info.value().episodeNumber = jsonResult.Entity.Info.EpisodeNumber; + } + if (jsonResult.Entity.Info.EpisodeCount.IsSet()) { + interestResult.entity.info.value().episodeCount = jsonResult.Entity.Info.EpisodeCount; + } + if (jsonResult.Entity.Info.ReleaseDate.IsSet()) { + interestResult.entity.info.value().releaseDate = jsonResult.Entity.Info.ReleaseDate; + } + if (jsonResult.Entity.Info.ContentRatings.IsSet()) { + interestResult.entity.info.value().contentRatings = std::make_optional>(); + auto index(jsonResult.Entity.Info.ContentRatings.Elements()); + while (index.Next() == true) { + Entertainment::ContentRating contentRatingsResult1; + Firebolt::Entertainment::JsonData_ContentRating jsonResult = index.Current(); + { + contentRatingsResult1.scheme = jsonResult.Scheme; + contentRatingsResult1.rating = jsonResult.Rating; + if (jsonResult.Advisories.IsSet()) { + contentRatingsResult1.advisories = std::make_optional>(); + auto index(jsonResult.Advisories.Elements()); + while (index.Next() == true) { + contentRatingsResult1.advisories.value().push_back(index.Current().Value()); + } + } + } + interestResult.entity.info.value().contentRatings->push_back(contentRatingsResult1); + } + } + } + if (jsonResult.Entity.WaysToWatch.IsSet()) { + interestResult.entity.waysToWatch = std::make_optional>(); + auto index(jsonResult.Entity.WaysToWatch.Elements()); + while (index.Next() == true) { + Entertainment::WayToWatch waysToWatchResult1; + Firebolt::Entertainment::JsonData_WayToWatch jsonResult = index.Current(); + { + { + if (jsonResult.Identifiers.AssetId.IsSet()) { + waysToWatchResult1.identifiers.assetId = jsonResult.Identifiers.AssetId; + } + if (jsonResult.Identifiers.EntityId.IsSet()) { + waysToWatchResult1.identifiers.entityId = jsonResult.Identifiers.EntityId; + } + if (jsonResult.Identifiers.SeasonId.IsSet()) { + waysToWatchResult1.identifiers.seasonId = jsonResult.Identifiers.SeasonId; + } + if (jsonResult.Identifiers.SeriesId.IsSet()) { + waysToWatchResult1.identifiers.seriesId = jsonResult.Identifiers.SeriesId; + } + if (jsonResult.Identifiers.AppContentData.IsSet()) { + waysToWatchResult1.identifiers.appContentData = jsonResult.Identifiers.AppContentData; + } + } + if (jsonResult.Expires.IsSet()) { + waysToWatchResult1.expires = jsonResult.Expires; + } + if (jsonResult.Entitled.IsSet()) { + waysToWatchResult1.entitled = jsonResult.Entitled; + } + if (jsonResult.EntitledExpires.IsSet()) { + waysToWatchResult1.entitledExpires = jsonResult.EntitledExpires; + } + if (jsonResult.OfferingType.IsSet()) { + waysToWatchResult1.offeringType = jsonResult.OfferingType; + } + if (jsonResult.HasAds.IsSet()) { + waysToWatchResult1.hasAds = jsonResult.HasAds; + } + if (jsonResult.Price.IsSet()) { + waysToWatchResult1.price = jsonResult.Price; + } + if (jsonResult.VideoQuality.IsSet()) { + waysToWatchResult1.videoQuality = std::make_optional>(); + auto index(jsonResult.VideoQuality.Elements()); + while (index.Next() == true) { + waysToWatchResult1.videoQuality.value().push_back(index.Current().Value()); + } + } + auto index(jsonResult.AudioProfile.Elements()); + while (index.Next() == true) { + waysToWatchResult1.audioProfile.push_back(index.Current().Value()); + } + if (jsonResult.AudioLanguages.IsSet()) { + waysToWatchResult1.audioLanguages = std::make_optional>(); + auto index(jsonResult.AudioLanguages.Elements()); + while (index.Next() == true) { + waysToWatchResult1.audioLanguages.value().push_back(index.Current().Value()); + } + } + if (jsonResult.ClosedCaptions.IsSet()) { + waysToWatchResult1.closedCaptions = std::make_optional>(); + auto index(jsonResult.ClosedCaptions.Elements()); + while (index.Next() == true) { + waysToWatchResult1.closedCaptions.value().push_back(index.Current().Value()); + } + } + if (jsonResult.Subtitles.IsSet()) { + waysToWatchResult1.subtitles = std::make_optional>(); + auto index(jsonResult.Subtitles.Elements()); + while (index.Next() == true) { + waysToWatchResult1.subtitles.value().push_back(index.Current().Value()); + } + } + if (jsonResult.AudioDescriptions.IsSet()) { + waysToWatchResult1.audioDescriptions = std::make_optional>(); + auto index(jsonResult.AudioDescriptions.Elements()); + while (index.Next() == true) { + waysToWatchResult1.audioDescriptions.value().push_back(index.Current().Value()); + } + } + } + interestResult.entity.waysToWatch->push_back(waysToWatchResult1); + } + } + } + interest = interestResult; + } + + } else { + FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); + } + if (err != nullptr) { + *err = status; + } + + return interest; + } + + + // Events + /* onUserInterest - Provide information about the entity currently displayed or selected on the screen. */ + static void onUserInterestInnerCallback( void* notification, const void* userData, void* jsonResponse ) + { + WPEFramework::Core::ProxyType& proxyResponse = *(reinterpret_cast*>(jsonResponse)); + + ASSERT(proxyResponse.IsValid() == true); + + if (proxyResponse.IsValid() == true) { + InterestEvent interest; + + interest.appId = proxyResponse->AppId; + interest.type = proxyResponse->Type; + interest.reason = proxyResponse->Reason; + { + string identifiersStr; + (*proxyResponse).Entity.Identifiers.ToString(identifiersStr); + interest.entity.identifiers = identifiersStr; + if ((*proxyResponse).Entity.Info.IsSet()) { + interest.entity.info = std::make_optional(); + if ((*proxyResponse).Entity.Info.Title.IsSet()) { + interest.entity.info.value().title = (*proxyResponse).Entity.Info.Title; + } + if ((*proxyResponse).Entity.Info.Synopsis.IsSet()) { + interest.entity.info.value().synopsis = (*proxyResponse).Entity.Info.Synopsis; + } + if ((*proxyResponse).Entity.Info.SeasonNumber.IsSet()) { + interest.entity.info.value().seasonNumber = (*proxyResponse).Entity.Info.SeasonNumber; + } + if ((*proxyResponse).Entity.Info.SeasonCount.IsSet()) { + interest.entity.info.value().seasonCount = (*proxyResponse).Entity.Info.SeasonCount; + } + if ((*proxyResponse).Entity.Info.EpisodeNumber.IsSet()) { + interest.entity.info.value().episodeNumber = (*proxyResponse).Entity.Info.EpisodeNumber; + } + if ((*proxyResponse).Entity.Info.EpisodeCount.IsSet()) { + interest.entity.info.value().episodeCount = (*proxyResponse).Entity.Info.EpisodeCount; + } + if ((*proxyResponse).Entity.Info.ReleaseDate.IsSet()) { + interest.entity.info.value().releaseDate = (*proxyResponse).Entity.Info.ReleaseDate; + } + if ((*proxyResponse).Entity.Info.ContentRatings.IsSet()) { + interest.entity.info.value().contentRatings = std::make_optional>(); + auto index((*proxyResponse).Entity.Info.ContentRatings.Elements()); + while (index.Next() == true) { + Entertainment::ContentRating contentRatingsResult1; + Firebolt::Entertainment::JsonData_ContentRating jsonResult = index.Current(); + contentRatingsResult1.scheme = jsonResult.Scheme; + contentRatingsResult1.rating = jsonResult.Rating; + if (jsonResult.Advisories.IsSet()) { + contentRatingsResult1.advisories = std::make_optional>(); + auto index(jsonResult.Advisories.Elements()); + while (index.Next() == true) { + contentRatingsResult1.advisories.value().push_back(index.Current().Value()); + } + } + interest.entity.info.value().contentRatings.value().push_back(contentRatingsResult1); + } + } + } + if ((*proxyResponse).Entity.WaysToWatch.IsSet()) { + interest.entity.waysToWatch = std::make_optional>(); + auto index((*proxyResponse).Entity.WaysToWatch.Elements()); + while (index.Next() == true) { + Entertainment::WayToWatch waysToWatchResult1; + Firebolt::Entertainment::JsonData_WayToWatch jsonResult = index.Current(); + { + if (jsonResult.Identifiers.AssetId.IsSet()) { + waysToWatchResult1.identifiers.assetId = jsonResult.Identifiers.AssetId; + } + if (jsonResult.Identifiers.EntityId.IsSet()) { + waysToWatchResult1.identifiers.entityId = jsonResult.Identifiers.EntityId; + } + if (jsonResult.Identifiers.SeasonId.IsSet()) { + waysToWatchResult1.identifiers.seasonId = jsonResult.Identifiers.SeasonId; + } + if (jsonResult.Identifiers.SeriesId.IsSet()) { + waysToWatchResult1.identifiers.seriesId = jsonResult.Identifiers.SeriesId; + } + if (jsonResult.Identifiers.AppContentData.IsSet()) { + waysToWatchResult1.identifiers.appContentData = jsonResult.Identifiers.AppContentData; + } + } + if (jsonResult.Expires.IsSet()) { + waysToWatchResult1.expires = jsonResult.Expires; + } + if (jsonResult.Entitled.IsSet()) { + waysToWatchResult1.entitled = jsonResult.Entitled; + } + if (jsonResult.EntitledExpires.IsSet()) { + waysToWatchResult1.entitledExpires = jsonResult.EntitledExpires; + } + if (jsonResult.OfferingType.IsSet()) { + waysToWatchResult1.offeringType = jsonResult.OfferingType; + } + if (jsonResult.HasAds.IsSet()) { + waysToWatchResult1.hasAds = jsonResult.HasAds; + } + if (jsonResult.Price.IsSet()) { + waysToWatchResult1.price = jsonResult.Price; + } + if (jsonResult.VideoQuality.IsSet()) { + waysToWatchResult1.videoQuality = std::make_optional>(); + auto index(jsonResult.VideoQuality.Elements()); + while (index.Next() == true) { + waysToWatchResult1.videoQuality.value().push_back(index.Current().Value()); + } + } + auto index(jsonResult.AudioProfile.Elements()); + while (index.Next() == true) { + waysToWatchResult1.audioProfile.push_back(index.Current().Value()); + } + if (jsonResult.AudioLanguages.IsSet()) { + waysToWatchResult1.audioLanguages = std::make_optional>(); + auto index(jsonResult.AudioLanguages.Elements()); + while (index.Next() == true) { + waysToWatchResult1.audioLanguages.value().push_back(index.Current().Value()); + } + } + if (jsonResult.ClosedCaptions.IsSet()) { + waysToWatchResult1.closedCaptions = std::make_optional>(); + auto index(jsonResult.ClosedCaptions.Elements()); + while (index.Next() == true) { + waysToWatchResult1.closedCaptions.value().push_back(index.Current().Value()); + } + } + if (jsonResult.Subtitles.IsSet()) { + waysToWatchResult1.subtitles = std::make_optional>(); + auto index(jsonResult.Subtitles.Elements()); + while (index.Next() == true) { + waysToWatchResult1.subtitles.value().push_back(index.Current().Value()); + } + } + if (jsonResult.AudioDescriptions.IsSet()) { + waysToWatchResult1.audioDescriptions = std::make_optional>(); + auto index(jsonResult.AudioDescriptions.Elements()); + while (index.Next() == true) { + waysToWatchResult1.audioDescriptions.value().push_back(index.Current().Value()); + } + } + interest.entity.waysToWatch.value().push_back(waysToWatchResult1); + } + } + } + + proxyResponse.Release(); + + IContent::IOnUserInterestNotification& notifier = *(reinterpret_cast(notification)); + notifier.onUserInterest(interest); + } + } + void ContentImpl::subscribe( IContent::IOnUserInterestNotification& notification, Firebolt::Error *err ) + { + const string eventName = _T("content.onUserInterest"); + Firebolt::Error status = Firebolt::Error::None; + + JsonObject jsonParameters; + + status = FireboltSDK::Event::Instance().Subscribe(eventName, jsonParameters, onUserInterestInnerCallback, reinterpret_cast(¬ification), nullptr); + + if (err != nullptr) { + *err = status; + } + } + void ContentImpl::unsubscribe( IContent::IOnUserInterestNotification& notification, Firebolt::Error *err ) + { + Firebolt::Error status = FireboltSDK::Event::Instance().Unsubscribe(_T("content.onUserInterest"), reinterpret_cast(¬ification)); + + if (err != nullptr) { + *err = status; + } + } + + +}//namespace ${info.Title} +}${end.if.implementations} + +${if.enums} + +namespace WPEFramework { + +/* ${ENUMS} */ +}${end.if.enums} + diff --git a/src/sdks/discovery/src/cpp/templates/Content/src/module_impl.h b/src/sdks/discovery/src/cpp/templates/Content/src/module_impl.h new file mode 100644 index 000000000..a01a3eb3e --- /dev/null +++ b/src/sdks/discovery/src/cpp/templates/Content/src/module_impl.h @@ -0,0 +1,136 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "FireboltSDK.h" +#include "IModule.h" +/* ${IMPORTS} */ +#include "${info.title.lowercase}.h" + +${if.implementations} +namespace Firebolt { +namespace ${info.Title} { + + + // Types + class JsonData_InterestResult: public WPEFramework::Core::JSON::Container { + public: + ~JsonData_InterestResult() override = default; + + public: + JsonData_InterestResult() + : WPEFramework::Core::JSON::Container() + { + Add(_T("appId"), &AppId); + Add(_T("entity"), &Entity); + } + + JsonData_InterestResult(const JsonData_InterestResult& other) + { + Add(_T("appId"), &AppId); + AppId = other.AppId; + Add(_T("entity"), &Entity); + Entity = other.Entity; + } + + JsonData_InterestResult& operator=(const JsonData_InterestResult& other) + { + Add(_T("appId"), &AppId); + AppId = other.AppId; + Add(_T("entity"), &Entity); + Entity = other.Entity; + return (*this); + } + + public: + FireboltSDK::JSON::String AppId; + Firebolt::Entity::JsonData_EntityDetails Entity; + }; + + class JsonData_InterestEvent: public WPEFramework::Core::JSON::Container { + public: + ~JsonData_InterestEvent() override = default; + + public: + JsonData_InterestEvent() + : WPEFramework::Core::JSON::Container() + { + Add(_T("appId"), &AppId); + Add(_T("type"), &Type); + Add(_T("reason"), &Reason); + Add(_T("entity"), &Entity); + } + + JsonData_InterestEvent(const JsonData_InterestEvent& other) + { + Add(_T("appId"), &AppId); + AppId = other.AppId; + Add(_T("type"), &Type); + Type = other.Type; + Add(_T("reason"), &Reason); + Reason = other.Reason; + Add(_T("entity"), &Entity); + Entity = other.Entity; + } + + JsonData_InterestEvent& operator=(const JsonData_InterestEvent& other) + { + Add(_T("appId"), &AppId); + AppId = other.AppId; + Add(_T("type"), &Type); + Type = other.Type; + Add(_T("reason"), &Reason); + Reason = other.Reason; + Add(_T("entity"), &Entity); + Entity = other.Entity; + return (*this); + } + + public: + FireboltSDK::JSON::String AppId; + Firebolt::Discovery::JsonData_InterestType Type; + Firebolt::Discovery::JsonData_InterestReason Reason; + Firebolt::Entity::JsonData_EntityDetails Entity; + }; + + class ContentImpl : public IContent, public IModule { + + public: + ContentImpl() = default; + ContentImpl(const ContentImpl&) = delete; + ContentImpl& operator=(const ContentImpl&) = delete; + + ~ContentImpl() override = default; + + // Methods & Events + // signature callback params: + // method result properties : + void subscribe( IContent::IOnUserInterestNotification& notification, Firebolt::Error *err = nullptr ) override; + void unsubscribe( IContent::IOnUserInterestNotification& notification, Firebolt::Error *err = nullptr ) override; + + /* + requestUserInterest + Provide information about the entity currently displayed or selected on the screen. + */ + InterestResult requestUserInterest( const Discovery::InterestType& type, const Discovery::InterestReason& reason, Firebolt::Error *err = nullptr ) override; + + }; + +}//namespace ${info.Title} +}${end.if.implementations}