Skip to content

Commit

Permalink
feat: CPP App-Passthrough Logic (#286)
Browse files Browse the repository at this point in the history
* feat: Update tests for app-passthrough

* fix: Add copyright comment to main.cpp files

* feat: Add discovery cpp testing files

* fix cpp test template

* fix: Add static modules for discovery.content
  • Loading branch information
ksentak authored Jul 29, 2024
1 parent b1519b7 commit 4eb84ee
Show file tree
Hide file tree
Showing 12 changed files with 915 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/openrpc/discovery.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
35 changes: 29 additions & 6 deletions src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,32 @@ void CoreSDKTest::DiscoveryWatchNext()
}
}

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<int>(error) << endl;
}
}

void CoreSDKTest::DiscoveryPolicy()
{
Firebolt::Error error = Firebolt::Error::None;
Expand Down Expand Up @@ -1485,15 +1511,12 @@ void CoreSDKTest::DiscoveryPurchasedContent()
void CoreSDKTest::DiscoveryLaunch()
{
Firebolt::Error error = Firebolt::Error::None;
cout << "Enter appId :";
getchar();
std::string appId;
getline(cin, appId);
std::string appId = "123";
{
std::optional<Firebolt::Intents::TuneIntent> intent = std::make_optional<Firebolt::Intents::TuneIntent>();
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<std::string> appContentData;
Expand All @@ -1502,6 +1525,7 @@ void CoreSDKTest::DiscoveryLaunch()
intent.value().context.source = "voice";
cout << "Calling Discovery Launch TuneIntent method " << endl;
bool status = Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().launch(appId, intent, &error);

if (error == Firebolt::Error::None) {
cout << "Discovery Launch TuneIntent is " << (status ? "true" : "false") << endl;
} else {
Expand Down Expand Up @@ -1539,7 +1563,6 @@ void CoreSDKTest::DiscoveryLaunch()
throw std::runtime_error("DiscoveryLaunch failed. " + errorMessage);
}
}
cin.putback('\n');
}
#ifdef POLYMORPHICS_REDUCER_METHODS
void CoreSDKTest::DiscoveryWatched()
Expand Down
1 change: 1 addition & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class CoreSDKTest {
static void SubscribeDiscoveryOnNavigateToLaunchNotification();
static void UnsubscribeDiscoveryOnNavigateToLaunchNotification();
static void DiscoveryWatchNext();
static void DiscoveryUserInterest();

static void ParametersInitialization();

Expand Down
3 changes: 3 additions & 0 deletions src/sdks/discovery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
75 changes: 75 additions & 0 deletions src/sdks/discovery/src/cpp/sdk/cpptest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${FIREBOLT_PATH}/usr/include/${FIREBOLT_NAMESPACE}SDK>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/../>
)

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
)
102 changes: 102 additions & 0 deletions src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <unistd.h>
#include <cstring>
#include <string>
#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<int>(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<typename T>
using EnumMap = std::unordered_map<T, string>;
template <typename T>
inline const string& ConvertFromEnum(EnumMap<T> enumMap, T type)
{
return enumMap[type];
}
template <typename T>
inline const T ConvertToEnum(EnumMap<T> 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<int>(error));
throw std::runtime_error("SampleTest failed. " + errorMessage);
}
}
41 changes: 41 additions & 0 deletions src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#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;
};
Loading

0 comments on commit 4eb84ee

Please sign in to comment.