From 046adc18ca7f2d35d02b9ce597be6f330c3b1972 Mon Sep 17 00:00:00 2001 From: kdivya153 <121901963+kdivya153@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:29:41 -0400 Subject: [PATCH 1/3] fix: Added Lifecycle template in cpp (#292) * fix: Added Lifecycle template in cpp Added Lifecycle template in cpp * Added comments --- .../core/src/cpp/sdk/cpptest/CoreSDKTest.cpp | 37 ++++- .../core/src/cpp/sdk/cpptest/CoreSDKTest.h | 3 + src/sdks/core/src/cpp/sdk/cpptest/Main.cpp | 5 +- .../cpp/templates/Lifecycle/include/module.h | 60 +++++++ .../templates/Lifecycle/src/module_impl.cpp | 152 ++++++++++++++++++ .../cpp/templates/Lifecycle/src/module_impl.h | 58 +++++++ 6 files changed, 313 insertions(+), 2 deletions(-) create mode 100644 src/sdks/core/src/cpp/templates/Lifecycle/include/module.h create mode 100644 src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.cpp create mode 100644 src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.h diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp index 23ae01e0d..a333c3bef 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp @@ -22,6 +22,7 @@ #include #include "CoreSDKTest.h" + using namespace std; bool CoreSDKTest::_connected; CoreSDKTest::OnPolicyChangedNotification CoreSDKTest::_policyChangedNotification; @@ -727,7 +728,41 @@ EnumMap lifecycleEventSourceMap = { { Firebolt::Lifecycle::LifecycleEventSource::REMOTE, "remote" } }; -void CoreSDKTest::OnBackgroundNotification::onBackground(const Firebolt::Lifecycle::LifecycleEvent& lifecycleEvent) +void CoreSDKTest::LifecycleReady() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().ready(&error); + if (error == Firebolt::Error::None) { + cout << "Lifecycle ready is success" << endl; + } else { + cout << "Lifecycle ready status = " << static_cast(error) << endl; + } +} + +void CoreSDKTest::LifecycleFinished() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().finished(&error); + if (error == Firebolt::Error::None) { + cout << "Lifecycle finished is success" << endl; + } else { + cout << "Lifecycle finished status = " << static_cast(error) << endl; + } +} + +void CoreSDKTest::LifecycleState() +{ + Firebolt::Error error = Firebolt::Error::None; + const std::string state = Firebolt::IFireboltAccessor::Instance().LifecycleInterface().state(&error); + + if (error == Firebolt::Error::None) { + cout << "State of the App = " << state.c_str() << endl; + } else { + cout << "State of the App throws an error = " << static_cast(error) << endl; + } +} + +void CoreSDKTest::OnBackgroundNotification::onBackground( const Firebolt::Lifecycle::LifecycleEvent& lifecycleEvent) { cout <<"onBackground event is triggered" << endl; cout <<"\tstate: " << ConvertFromEnum(lifecycleStateMap, lifecycleEvent.state) << endl; diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h index aacaf02f7..aa15b374c 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h @@ -132,6 +132,9 @@ class CoreSDKTest { static void GetProfileFlags(); static void LifecycleClose(); + static void LifecycleFinished(); + static void LifecycleReady(); + static void LifecycleState(); static void SubscribeLifecycleBackgroundNotification(); static void UnsubscribeLifecycleBackgroundNotification(); static void SubscribeLifecycleForegroundNotification(); diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp index 9105c3fea..6652de37b 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp @@ -90,6 +90,9 @@ void RunAllTests() { // Lifecycle methods // runTest(CoreSDKTest::LifecycleClose, "LifecycleClose"); + runTest(CoreSDKTest::LifecycleReady, "LifecycleReady"); + runTest(CoreSDKTest::LifecycleFinished, "LifecycleFinished"); + runTest(CoreSDKTest::LifecycleState, "LifecycleState"); runTest(CoreSDKTest::SubscribeLifecycleBackgroundNotification, "SubscribeLifecycleBackgroundNotification"); runTest(CoreSDKTest::UnsubscribeLifecycleBackgroundNotification, "UnsubscribeLifecycleBackgroundNotification"); runTest(CoreSDKTest::SubscribeLifecycleForegroundNotification, "SubscribeLifecycleForegroundNotification"); @@ -167,4 +170,4 @@ int main(int argc, char* argv[]) { CoreSDKTest::DestroyFireboltInstance(); return 0; -} +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/templates/Lifecycle/include/module.h b/src/sdks/core/src/cpp/templates/Lifecycle/include/module.h new file mode 100644 index 000000000..1f954f6de --- /dev/null +++ b/src/sdks/core/src/cpp/templates/Lifecycle/include/module.h @@ -0,0 +1,60 @@ +/* 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 "error.h" +#include +/* ${IMPORTS} */ + +${if.declarations}namespace Firebolt { +namespace ${info.Title} { + +${if.enums} +// Enums +/* ${ENUMS} */${end.if.enums} + +${if.types} +// Types +/* ${TYPES} */${end.if.types} + +${if.providers}/* ${PROVIDERS} */${end.if.providers}${if.xuses}/* ${XUSES} */${end.if.xuses} + +${if.methods}struct I${info.Title} { + + virtual ~I${info.Title}() = default; + virtual void ready(Firebolt::Error *err = nullptr) = 0; + virtual void finished(Firebolt::Error *err = nullptr) = 0; + virtual std::string state(Firebolt::Error *err = nullptr) = 0; + + // Methods & Events + /* ${METHODS:declarations} */ +};${end.if.methods} + +// Template for mapping enums to strings +template +using EnumMap = std::unordered_map; + +// Function to convert enum values to string representations +template +inline const std::string& ConvertEnum(EnumMap enumMap, T type) +{ + return enumMap[type]; +} + +} //namespace ${info.Title} +}${end.if.declarations} diff --git a/src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.cpp b/src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.cpp new file mode 100644 index 000000000..233d3f973 --- /dev/null +++ b/src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.cpp @@ -0,0 +1,152 @@ +/* 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} + +EnumMap lifecycleStateMap = { + { Firebolt::Lifecycle::LifecycleState::INITIALIZING, "initializing" }, + { Firebolt::Lifecycle::LifecycleState::INACTIVE, "inactive" }, + { Firebolt::Lifecycle::LifecycleState::FOREGROUND, "foreground" }, + { Firebolt::Lifecycle::LifecycleState::BACKGROUND, "background" }, + { Firebolt::Lifecycle::LifecycleState::UNLOADING, "unloading" }, + { Firebolt::Lifecycle::LifecycleState::SUSPENDED, "suspended" } +}; + + +/* ready - Notify the platform that the app is ready */ +static void readyDispatcher(const void* result) { + Firebolt::IFireboltAccessor::Instance().MetricsInterface().ready(); +} + +// localCallback to update the state +static void onReadyInnerCallback(void* notification, const void* userData, void* jsonResponse ) +{ + const LifecycleImpl* selfConst = static_cast(userData); + LifecycleImpl* self = const_cast(selfConst); + + WPEFramework::Core::ProxyType& proxyResponse = *(reinterpret_cast*>(jsonResponse)); + ASSERT(proxyResponse.IsValid() == true); + + if (proxyResponse.IsValid() == true) { + LifecycleEvent value; + + value.state = proxyResponse->State; + std::string stateStr = ConvertEnum(lifecycleStateMap, value.state); + // Assign stateStr to currentState in ${info.Title}Impl instance + self->currentState = stateStr; + std::cout << "Updated the Current State to: " << self->currentState << std::endl; + + proxyResponse.Release(); + + } +} + + + +/* ready - Notify the platform that the app is ready */ +void ${info.Title}Impl::ready(Firebolt::Error *err) { + Firebolt::Error status = Firebolt::Error::NotConnected; + + JsonObject jsonParameters; + + // Call Prioritize to subscribe to corresponding event, add to internalMap, and prioritize its callback + status = FireboltSDK::Event::Instance().Prioritize("lifecycle.onForeground", jsonParameters, onReadyInnerCallback, (void*)nullptr, this); + status = FireboltSDK::Event::Instance().Prioritize("lifecycle.onBackground", jsonParameters, onReadyInnerCallback, (void*)nullptr, this); + status = FireboltSDK::Event::Instance().Prioritize("lifecycle.onInactive", jsonParameters, onReadyInnerCallback, (void*)nullptr, this); + status = FireboltSDK::Event::Instance().Prioritize("lifecycle.onSuspended", jsonParameters, onReadyInnerCallback, (void*)nullptr, this); + status = FireboltSDK::Event::Instance().Prioritize("lifecycle.onUnloading", jsonParameters, onReadyInnerCallback, (void*)nullptr, this); + + FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); + if (transport != nullptr) { + WPEFramework::Core::JSON::VariantContainer jsonResult; + status = transport->Invoke("lifecycle.ready", jsonParameters, jsonResult); + if (status == Firebolt::Error::None) { + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Lifecycle.ready is successfully invoked"); + + WPEFramework::Core::ProxyType job = WPEFramework::Core::ProxyType(WPEFramework::Core::ProxyType::Create(readyDispatcher, nullptr)); + WPEFramework::Core::IWorkerPool::Instance().Submit(job); + } else { + FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in invoking lifecycle.ready: %d", status); + if (err != nullptr) { + *err = status; + } + } + + } else { + FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); + if (err != nullptr) { + *err = status; + } + } +} + + +/* state - return the state of the app */ +std::string ${info.Title}Impl::state(Firebolt::Error *err) { + std::cout << "**CURRENT STATE OF THE APP::::**" << currentState << std::endl; + return currentState; +} + + + +/* finished - Notify the platform that the app is done unloading */ +void ${info.Title}Impl::finished(Firebolt::Error *err) +{ + Firebolt::Error status = Firebolt::Error::NotConnected; + if(currentState == "unloading") + { + FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); + if (transport != nullptr) { + + JsonObject jsonParameters; + + WPEFramework::Core::JSON::VariantContainer jsonResult; + status = transport->Invoke("lifecycle.finished", jsonParameters, jsonResult); + if (status == Firebolt::Error::None) { + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Lifecycle.finished is successfully invoked"); + + } + + } else { + FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); + } + } + + return; +} + +// Methods +/* ${METHODS} */ + +// Events +/* ${EVENTS} */ + +}//namespace Lifecycle +}${end.if.implementations} +${if.enums} + +namespace WPEFramework { + +/* ${ENUMS} */ +}${end.if.enums} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.h b/src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.h new file mode 100644 index 000000000..79a582da5 --- /dev/null +++ b/src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.h @@ -0,0 +1,58 @@ +/* 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" +#include "firebolt.h" +#include "jsondata_lifecycle.h" +#include "${info.title.lowercase}.h" + +/* ${IMPORTS} */ + + +${if.implementations} +namespace Firebolt { +namespace ${info.Title} { +${if.enums} + +/* ${ENUMS:json-types} */${end.if.enums} +${if.types} +// Types +/* ${TYPES:json-types} */${end.if.types} +${if.methods}class ${info.Title}Impl : public I${info.Title}, public IModule { + +public: + ${info.Title}Impl() = default; + ${info.Title}Impl(const ${info.Title}Impl&) = delete; + ${info.Title}Impl& operator=(const ${info.Title}Impl&) = delete; + ~${info.Title}Impl() override = default; + + std::string currentState = "INITIALIZING"; + + // Methods & Events + /* ${METHODS:declarations-override} */ + + void finished(Firebolt::Error *err = nullptr) override ; + void ready(Firebolt::Error *err = nullptr) override; + std::string state(Firebolt::Error *err = nullptr) override; + +};${end.if.methods} + +} // namespace ${info.Title} +} // namespace Firebolt +${end.if.implementations} \ No newline at end of file From 6510ce6bc5d4e8860bf79ef0b7cea7985165056c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 29 Jul 2024 17:33:40 +0000 Subject: [PATCH 2/3] chore(release): 1.2.1-next.3 [skip ci] ## [1.2.1-next.3](https://github.com/rdkcentral/firebolt-apis/compare/v1.2.1-next.2...v1.2.1-next.3) (2024-07-29) ### Bug Fixes * Added Lifecycle template in cpp ([#292](https://github.com/rdkcentral/firebolt-apis/issues/292)) ([046adc1](https://github.com/rdkcentral/firebolt-apis/commit/046adc18ca7f2d35d02b9ce597be6f330c3b1972)) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- src/sdks/core/package.json | 2 +- src/sdks/discovery/package.json | 2 +- src/sdks/manage/package.json | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 479e710c1..50c8b0b25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.2.1-next.3](https://github.com/rdkcentral/firebolt-apis/compare/v1.2.1-next.2...v1.2.1-next.3) (2024-07-29) + + +### Bug Fixes + +* Added Lifecycle template in cpp ([#292](https://github.com/rdkcentral/firebolt-apis/issues/292)) ([046adc1](https://github.com/rdkcentral/firebolt-apis/commit/046adc18ca7f2d35d02b9ce597be6f330c3b1972)) + ## [1.2.1-next.2](https://github.com/rdkcentral/firebolt-apis/compare/v1.2.1-next.1...v1.2.1-next.2) (2024-07-01) diff --git a/package-lock.json b/package-lock.json index 41a261d7f..20173d52f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@firebolt-js/sdks", - "version": "1.2.1-next.2", + "version": "1.2.1-next.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@firebolt-js/sdks", - "version": "1.2.1-next.2", + "version": "1.2.1-next.3", "license": "Apache-2.0", "workspaces": [ "src/sdks/core", diff --git a/package.json b/package.json index 3c8b0f036..6feecc33f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@firebolt-js/sdks", - "version": "1.2.1-next.2", + "version": "1.2.1-next.3", "description": "The Firebolt JS SDK", "type": "module", "bin": { diff --git a/src/sdks/core/package.json b/src/sdks/core/package.json index b1d245e4f..219eaca68 100644 --- a/src/sdks/core/package.json +++ b/src/sdks/core/package.json @@ -1,6 +1,6 @@ { "name": "@firebolt-js/sdk", - "version": "1.2.1-next.2", + "version": "1.2.1-next.3", "description": "The Firebolt JS SDK", "main": "./dist/lib/firebolt.mjs", "types": "./dist/lib/firebolt.d.ts", diff --git a/src/sdks/discovery/package.json b/src/sdks/discovery/package.json index 0e4ec34e9..5a208d0b6 100644 --- a/src/sdks/discovery/package.json +++ b/src/sdks/discovery/package.json @@ -1,6 +1,6 @@ { "name": "@firebolt-js/discovery-sdk", - "version": "1.2.1-next.2", + "version": "1.2.1-next.3", "description": "The Firebolt Discovery JS SDK", "main": "./dist/lib/firebolt-discovery.mjs", "types": "./dist/lib/firebolt-discovery.d.ts", diff --git a/src/sdks/manage/package.json b/src/sdks/manage/package.json index ef8c41e66..c94f2cad9 100644 --- a/src/sdks/manage/package.json +++ b/src/sdks/manage/package.json @@ -1,6 +1,6 @@ { "name": "@firebolt-js/manage-sdk", - "version": "1.2.1-next.2", + "version": "1.2.1-next.3", "description": "The Firebolt Manage JS SDK", "main": "./dist/lib/firebolt-manage.mjs", "types": "./dist/lib/firebolt-manage.d.ts", From a1f75cb22577c3eded0968ca51ca656336a88506 Mon Sep 17 00:00:00 2001 From: kdivya153 <121901963+kdivya153@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:46:40 -0400 Subject: [PATCH 3/3] fix: Added Static Metrics template in CPP (#293) Added Static Metrics template in CPP Co-authored-by: Keaton Sentak <54916859+ksentak@users.noreply.github.com> --- .../core/src/cpp/sdk/cpptest/CoreSDKTest.cpp | 41 ++++++++++++- .../core/src/cpp/sdk/cpptest/CoreSDKTest.h | 4 +- src/sdks/core/src/cpp/sdk/cpptest/Main.cpp | 25 +++++++- .../cpp/templates/Metrics/include/module.h | 36 +++++++++++ .../cpp/templates/Metrics/src/module_impl.cpp | 61 +++++++++++++------ .../cpp/templates/Metrics/src/module_impl.h | 13 ++-- 6 files changed, 156 insertions(+), 24 deletions(-) create mode 100644 src/sdks/core/src/cpp/templates/Metrics/include/module.h diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp index a333c3bef..f09f554ef 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp @@ -1073,6 +1073,45 @@ void CoreSDKTest::MetricsStopContent() } } +void CoreSDKTest::MetricsReady() +{ + Firebolt::Error error = Firebolt::Error::None; + std::optional entityId; + bool status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().ready(&error); + + if (error == Firebolt::Error::None) { + cout << "Metrics Ready status = " << (status ? "true" : "false") << endl; + } else { + cout << "Metrics Ready status = " << static_cast(error) << endl; + } +} + +void CoreSDKTest::MetricsSignIn() +{ + Firebolt::Error error = Firebolt::Error::None; + std::optional entityId; + bool status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().signIn(&error); + + if (error == Firebolt::Error::None) { + cout << "Metrics signIn status = " << (status ? "true" : "false") << endl; + } else { + cout << "Metrics signIn status = " << static_cast(error) << endl; + } +} + +void CoreSDKTest::MetricsSignOut() +{ + Firebolt::Error error = Firebolt::Error::None; + std::optional entityId; + bool status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().signOut(&error); + + if (error == Firebolt::Error::None) { + cout << "Metrics signOut status = " << (status ? "true" : "false") << endl; + } else { + cout << "Metrics signOut status = " << static_cast(error) << endl; + } +} + void CoreSDKTest::GetSecondScreenDevice() { Firebolt::Error error = Firebolt::Error::None; @@ -1614,4 +1653,4 @@ void CoreSDKTest::OnNavigateToEntityIntentNotification::onNavigateTo(const Fireb void CoreSDKTest::OnNavigateToTuneIntentNotification::onNavigateTo(const Firebolt::Intents::TuneIntent& intent) { cout << "onNavigateTo for action : " << intent.action << endl; -} +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h index aa15b374c..d0fd48c67 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h @@ -155,6 +155,9 @@ class CoreSDKTest { static void MetricsStartContent(); static void MetricsStopContent(); + static void MetricsReady(); + static void MetricsSignIn(); + static void MetricsSignOut(); static void GetSecondScreenDevice(); static void GetSecondScreenProtocols(); @@ -203,4 +206,3 @@ class CoreSDKTest { static KeyboardPasswordAsyncResponse _keyboardPasswordAsyncResponse; static KeyboardStandardAsyncResponse _keyboardStandardAsyncResponse; }; - diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp index 6652de37b..5b235dadb 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 @@ -99,8 +117,13 @@ void RunAllTests() { runTest(CoreSDKTest::UnsubscribeLifecycleForegroundNotification, "UnsubscribeLifecycleForegroundNotification"); // Metrics methods + runTest(CoreSDKTest::MetricsReady, "MetricsReady"); + runTest(CoreSDKTest::MetricsSignIn, "MetricsSignIn"); + runTest(CoreSDKTest::MetricsSignOut, "MetricsSignOut"); runTest(CoreSDKTest::MetricsStartContent, "MetricsStartContent"); runTest(CoreSDKTest::MetricsStopContent, "MetricsStopContent"); + + // SecondScreen methods runTest(CoreSDKTest::GetSecondScreenDevice, "GetSecondScreenDevice"); @@ -119,7 +142,7 @@ void RunAllTests() { runTest(CoreSDKTest::DiscoveryPolicy, "DiscoveryPolicy"); runTest(CoreSDKTest::DiscoveryPurchasedContent, "DiscoveryPurchasedContent"); runTest(CoreSDKTest::DiscoveryWatchNext, "DiscoveryWatchNext"); - // runTest(CoreSDKTest::DiscoveryLaunch, "DiscoveryLaunch"); + runTest(CoreSDKTest::DiscoveryLaunch, "DiscoveryLaunch"); #ifdef POLYMORPHICS_REDUCER_METHODS runTest(CoreSDKTest::DiscoveryWatched, "DiscoveryWatched"); runTest(CoreSDKTest::DiscoveryWatchedReduced, "DiscoveryWatchedReduced"); diff --git a/src/sdks/core/src/cpp/templates/Metrics/include/module.h b/src/sdks/core/src/cpp/templates/Metrics/include/module.h new file mode 100644 index 000000000..ccca61a6a --- /dev/null +++ b/src/sdks/core/src/cpp/templates/Metrics/include/module.h @@ -0,0 +1,36 @@ +#pragma once + +#include "error.h" +/* ${IMPORTS} */ + +${if.declarations}namespace Firebolt { +namespace ${info.Title} { +${if.enums} + +// Enums +/* ${ENUMS} */${end.if.enums} +${if.types} +// Types +/* ${TYPES} */${end.if.types} +${if.providers}/* ${PROVIDERS} */${end.if.providers}${if.xuses}/* ${XUSES} */${end.if.xuses} +${if.methods}struct I${info.Title} { + + virtual ~I${info.Title}() = default; + virtual bool ready( Firebolt::Error *err = nullptr ) = 0 ; + virtual bool signIn( Firebolt::Error *err = nullptr ) = 0 ; + virtual bool signOut( Firebolt::Error *err = nullptr ) = 0 ; + + // Methods & Events + /* ${METHODS:declarations} */ +};${end.if.methods} + +} //namespace ${info.Title} +}${end.if.declarations} + + + + + + + + diff --git a/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.cpp b/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.cpp index 59a50162d..085c4173a 100644 --- a/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.cpp +++ b/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.cpp @@ -18,68 +18,95 @@ #include "${info.title.lowercase}_impl.h" + ${if.implementations} namespace Firebolt { namespace ${info.Title} { ${if.providers} /* ${PROVIDERS} */${end.if.providers} - void ${info.Title}Impl::signIn() + +/* ready - Inform the platform that your app is minimally usable. This method is called automatically by `Lifecycle.ready()` */ + bool ${info.Title}Impl::ready( Firebolt::Error *err ) { Firebolt::Error status = Firebolt::Error::NotConnected; + bool success = false; FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); if (transport != nullptr) { - + JsonObject jsonParameters; - + WPEFramework::Core::JSON::Boolean jsonResult; - status = transport->Invoke("${info.title.lowercase}.signIn", jsonParameters, jsonResult); + status = transport->Invoke("${info.title.lowercase}.ready", jsonParameters, jsonResult); if (status == Firebolt::Error::None) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title.signIn is successfully invoked, status : %s", (jsonResult.Value() ? "true" : "false")); + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Metrics.ready is successfully invoked"); + success = jsonResult.Value(); } } else { FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); } + if (err != nullptr) { + *err = status; + } + + return success; } - void ${info.Title}Impl::signOut() + + /* signIn - Log a sign In event, called by Discovery.signIn(). */ + bool ${info.Title}Impl::signIn( Firebolt::Error *err ) { Firebolt::Error status = Firebolt::Error::NotConnected; + bool success = false; FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); if (transport != nullptr) { - + JsonObject jsonParameters; - + WPEFramework::Core::JSON::Boolean jsonResult; - status = transport->Invoke("${info.title.lowercase}.signOut", jsonParameters, jsonResult); + status = transport->Invoke("${info.title.lowercase}.signIn", jsonParameters, jsonResult); if (status == Firebolt::Error::None) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.signOut is successfully invoked, status : %s", (jsonResult.Value() ? "true" : "false")); + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Metrics.signOut is successfully invoked"); + success = jsonResult.Value(); } } else { FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); } - } + if (err != nullptr) { + *err = status; + } + return success; - void ${info.Title}Impl::ready() + } + /* signOut - Log a sign out event, called by Discovery.signOut(). */ + bool ${info.Title}Impl::signOut( Firebolt::Error *err ) { Firebolt::Error status = Firebolt::Error::NotConnected; + bool success = false; FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); if (transport != nullptr) { - + JsonObject jsonParameters; - + WPEFramework::Core::JSON::Boolean jsonResult; - status = transport->Invoke("${info.title.lowercase}.ready", jsonParameters, jsonResult); + status = transport->Invoke("${info.title.lowercase}.signOut", jsonParameters, jsonResult); if (status == Firebolt::Error::None) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.ready is successfully invoked, status : %s", (jsonResult.Value() ? "true" : "false")); + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Metrics.signOut is successfully invoked"); + success = jsonResult.Value(); } } else { FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); } + if (err != nullptr) { + *err = status; + } + + return success; } + // Methods /* ${METHODS} */ @@ -93,4 +120,4 @@ namespace ${info.Title} { namespace WPEFramework { /* ${ENUMS} */ -}${end.if.enums} +}${end.if.enums} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.h b/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.h index d64b59695..219803938 100644 --- a/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.h +++ b/src/sdks/core/src/cpp/templates/Metrics/src/module_impl.h @@ -20,6 +20,7 @@ #include "FireboltSDK.h" #include "IModule.h" + /* ${IMPORTS} */ #include "${info.title.lowercase}.h" @@ -41,12 +42,16 @@ namespace ${info.Title} { ~${info.Title}Impl() override = default; - static void signIn(); - static void signOut(); - static void ready(); + + bool ready( Firebolt::Error *err = nullptr ) ; + bool signIn( Firebolt::Error *err = nullptr ) ; + bool signOut( Firebolt::Error *err = nullptr ) ; + + + // Methods & Events /* ${METHODS:declarations-override} */ };${end.if.methods} }//namespace ${info.Title} -}${end.if.implementations} +}${end.if.implementations} \ No newline at end of file