From ae1cd80371e5395edba67f8847ed04b4c291d567 Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:34:48 +0530 Subject: [PATCH] CPPSDK: test event sample test added (#192) * CPPSDK: test event sample test added * CPPSDK: more event test added --- src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp | 60 +++++- .../src/cpp/sdk/cpptest/ManageSDKTest.cpp | 190 +++++++++++++++++- .../src/cpp/sdk/cpptest/ManageSDKTest.h | 40 +++- 3 files changed, 277 insertions(+), 13 deletions(-) diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp index 843f53eaf..2d20299ff 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp @@ -6,16 +6,52 @@ void ShowMenu() printf("Enter\n" "\tN : Get Device Name\n" "\tS : Set Device Name\n" + "\tC : Subscribe/Unsubscribe for Device Name Change\n" "\tB : Get ClosedCaption Background Opacity\n" "\tO : Set ClosedCaption Background Opacity\n" + "\tY : Subscribe/Unsubscribe for ClosedCaption Background Opacity Change\n" "\tF : Get ClosedCaption Font Family\n" "\tM : Set ClosedCaption Font Family\n" + "\tI : Subscribe/Unsubscribe for ClosedCaption Font Family Change\n" "\tL : Get Localization Preferred AudioLanguages\n" - "\tP : Set Localization Preferred AudioLanguages\n" + "\tA : Set Localization Preferred AudioLanguages\n" + "\tR : Subscribe/Unsubscribe for Localization Preferred AudioLanguages Change\n" + "\tP : Subscribe/Unsubscribe for PinChallenge RequestChallenge\n" "\tQ : Quit\n\n" ); } +void ShowEventMenu() +{ + printf("Enter\n" + "\tS: Subscribe Event\n" + "\tU: Unsubscribe Event\n" + "\tQ : Quit\n"); +} + +#define HandleEventListener(Module, eventFuncName) \ +{ \ + int opt; \ + do { \ + getchar(); \ + ShowEventMenu(); \ + printf("Enter option : "); \ + opt = toupper(getchar()); \ + switch (opt) { \ + case 'S': { \ + ManageSDKTest::Subscribe##Module##eventFuncName(); \ + break; \ + } \ + case 'U': { \ + ManageSDKTest::Unsubscribe##Module##eventFuncName(); \ + break; \ + } \ + default: \ + break; \ + } \ + } while (opt != 'Q'); \ +} + int main (int argc, char* argv[]) { char* config = "{\ @@ -47,6 +83,10 @@ int main (int argc, char* argv[]) ManageSDKTest::SetDeviceName(); break; } + case 'C': { + HandleEventListener(Device, NameChanged) + break; + } case 'B': { ManageSDKTest::GetClosedCaptionBackgroundOpacity(); break; @@ -55,6 +95,10 @@ int main (int argc, char* argv[]) ManageSDKTest::SetClosedCaptionBackgroundOpacity(); break; } + case 'Y': { + HandleEventListener(ClosedCaptions, BackgroundOpacityChanged) + break; + } case 'F': { ManageSDKTest::GetClosedCaptionFontFamily(); break; @@ -63,14 +107,26 @@ int main (int argc, char* argv[]) ManageSDKTest::SetClosedCaptionFontFamily(); break; } + case 'I': { + HandleEventListener(ClosedCaptions, FontFamilyChanged) + break; + } case 'L': { ManageSDKTest::GetLocalizationPreferredAudioLanguages(); break; } - case 'P': { + case 'A': { ManageSDKTest::SetLocalizationPreferredAudioLanguages(); break; } + case 'R': { + HandleEventListener(Localization, PreferredAudioLanguagesChanged) + break; + } + case 'P': { + HandleEventListener(PinChallenge, RequestChallenge) + break; + } default: break; diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp index 37b013e48..522343396 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp @@ -17,16 +17,20 @@ */ #include -#include "firebolt.h" #include "ManageSDKTest.h" using namespace std; bool ManageSDKTest::_connected; +ManageSDKTest::OnDeviceNameChangedNotification ManageSDKTest::_deviceNameChangedNotification; +ManageSDKTest::OnFontFamilyChangedNotification ManageSDKTest::_fontFamilyChangedNotification; +ManageSDKTest::OnBackgroundOpacityChangedNotification ManageSDKTest::_backgroundOpacityChangedNotification; +ManageSDKTest::OnPreferredAudioLanguagesChangedNotification ManageSDKTest::_preferredAudioLanguagesChangedNotification; +ManageSDKTest::OnRequestChallengeNotification ManageSDKTest::_requestChallengeNotification; void ManageSDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error) { - cout << "Change in connection: connected: " << connected << " error: " << static_cast(error) << endl; - _connected = connected; + cout << "Change in connection: connected: " << connected << " error: " << static_cast(error) << endl; + _connected = connected; } void ManageSDKTest::CreateFireboltInstance() @@ -75,9 +79,9 @@ void ManageSDKTest::GetDeviceName() const std::string name = Firebolt::IFireboltAccessor::Instance().DeviceInterface().Name(&error); if (error == Firebolt::Error::None) { - cout << "Get DeviceName = " << name.c_str() << endl; + cout << "Get Device Name = " << name.c_str() << endl; } else { - cout << "Get DeviceName status = " << static_cast(error) << endl; + cout << "Get Device Name status = " << static_cast(error) << endl; } } @@ -87,9 +91,36 @@ void ManageSDKTest::SetDeviceName() Firebolt::IFireboltAccessor::Instance().DeviceInterface().SetName("Hello", &error); if (error == Firebolt::Error::None) { - cout << "Set DeviceName is success" << endl; + cout << "Set Device Name is success" << endl; } else { - cout << "Set DeviceName status = " << static_cast(error) << endl; + cout << "Set Device Name status = " << static_cast(error) << endl; + } +} + +void ManageSDKTest::OnDeviceNameChangedNotification::OnDeviceNameChanged( const std::string& name) +{ + cout << "Name changed, new name --> " << name << endl; +} + +void ManageSDKTest::SubscribeDeviceNameChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().DeviceInterface().Subscribe(_deviceNameChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Subscribe Device NameChange is success" << endl; + } else { + cout << "Subscribe Device NameChange status = " << static_cast(error) << endl; + } +} + +void ManageSDKTest::UnsubscribeDeviceNameChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().DeviceInterface().Unsubscribe(_deviceNameChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe Device NameChange is success" << endl; + } else { + cout << "Unsubscribe Device NameChange status = " << static_cast(error) << endl; } } @@ -117,13 +148,54 @@ void ManageSDKTest::SetClosedCaptionBackgroundOpacity() } } +void ManageSDKTest::OnBackgroundOpacityChangedNotification::OnBackgroundOpacityChanged( const float opacity ) +{ + cout << "BackgroundOpacity changed, new value --> " << opacity << endl; +} + +void ManageSDKTest::SubscribeClosedCaptionsBackgroundOpacityChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Subscribe(_backgroundOpacityChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Subscribe ClosedCaptions BackgroundOpacityChange is success" << endl; + } else { + cout << "Subscribe ClosedCaptions BackgroundOpacityChange status = " << static_cast(error) << endl; + } +} + +void ManageSDKTest::UnsubscribeClosedCaptionsBackgroundOpacityChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Unsubscribe(_backgroundOpacityChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe ClosedCaptions BackgroundOpacityChange is success" << endl; + } else { + cout << "Unsubscribe ClosedCaptions BackgroundOpacityChange status = " << static_cast(error) << endl; + } +} + +using FontFamilyMap = std::unordered_map; +FontFamilyMap fontFamilyMap = { + { Firebolt::Accessibility::FontFamily::MONOSPACED_SERIF, "MonospacedSerif" }, + { Firebolt::Accessibility::FontFamily::PROPORTIONAL_SERIF, "ProportionalSerif" }, + { Firebolt::Accessibility::FontFamily::MONOSPACED_SANSERIF, "MonospacedSanserif" }, + { Firebolt::Accessibility::FontFamily::PROPORTIONAL_SANSERIF, "ProportionalSanserif" }, + { Firebolt::Accessibility::FontFamily::SMALLCAPS, "SmallCaps" }, + { Firebolt::Accessibility::FontFamily::CURSIVE, "Cursive" }, + { Firebolt::Accessibility::FontFamily::CASUAL, "Casual" }}; +inline const string& ConvertToFontFamilyStr(Firebolt::Accessibility::FontFamily family) +{ + return fontFamilyMap[family]; +} + void ManageSDKTest::GetClosedCaptionFontFamily() { Firebolt::Error error = Firebolt::Error::None; const Firebolt::Accessibility::FontFamily value = Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().FontFamily(&error); if (error == Firebolt::Error::None) { - cout << "Get ClosedCaption FontFamily = " << static_cast(value) << endl; + cout << "Get ClosedCaption FontFamily value = " << ConvertToFontFamilyStr(value) << endl; } else { cout << "Get ClosedCaption FontFamily status = " << static_cast(error) << endl; } @@ -141,6 +213,33 @@ void ManageSDKTest::SetClosedCaptionFontFamily() } } +void ManageSDKTest::OnFontFamilyChangedNotification::OnFontFamilyChanged( const Firebolt::Accessibility::FontFamily& family ) +{ + cout << "FontFamily changed, new code --> " << ConvertToFontFamilyStr(family) << endl; +} + +void ManageSDKTest::SubscribeClosedCaptionsFontFamilyChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Subscribe(_fontFamilyChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Subscribe ClosedCaptions FontFamilyChange is success" << endl; + } else { + cout << "Subscribe ClosedCaptions FontFamilyChange status = " << static_cast(error) << endl; + } +} + +void ManageSDKTest::UnsubscribeClosedCaptionsFontFamilyChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Unsubscribe(_fontFamilyChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe ClosedCaptions FontFamilyChange is success" << endl; + } else { + cout << "Unsubscribe ClosedCaptions FontFamilyChange status = " << static_cast(error) << endl; + } +} + void ManageSDKTest::GetLocalizationPreferredAudioLanguages() { Firebolt::Error error = Firebolt::Error::None; @@ -149,8 +248,8 @@ void ManageSDKTest::GetLocalizationPreferredAudioLanguages() if (error == Firebolt::Error::None) { cout << "Get Localization PreferredAudioLanguages : " << endl; for (auto language: languages) { - cout << "----- > " < " < " << endl; + for (auto language : languages) { + cout << " -> " << language << endl; + } +} + +void ManageSDKTest::SubscribeLocalizationPreferredAudioLanguagesChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LocalizationInterface().Subscribe(_preferredAudioLanguagesChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Subscribe Localization PreferredAudioLanguagesChange is success" << endl; + } else { + cout << "Subscribe Localization PreferredAudioLanguagesChange status = " << static_cast(error) << endl; + } +} + +void ManageSDKTest::UnsubscribeLocalizationPreferredAudioLanguagesChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LocalizationInterface().Unsubscribe(_preferredAudioLanguagesChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe Localization PreferredAudioLanguagesChange is success" << endl; + } else { + cout << "Unsubscribe Localization PreferredAudioLanguagesChange status = " << static_cast(error) << endl; + } +} + +using PinSpaceMap = std::unordered_map; +PinSpaceMap pinSpaceMap = { + { Firebolt::PinChallenge::PinChallengePinSpace::PURCHASE, "Purchase" }, + { Firebolt::PinChallenge::PinChallengePinSpace::CONTENT, "Content" }}; +inline const string& ConvertToPinSpaceStr(Firebolt::PinChallenge::PinChallengePinSpace pinSpace) +{ + return pinSpaceMap[pinSpace]; +} + + +void ManageSDKTest::OnRequestChallengeNotification::OnRequestChallenge( const Firebolt::PinChallenge::PinChallengeProviderRequest& pinChallenge ) +{ + cout << "RequestChallenge, new challenge --> " << endl; + cout << "CorrelationId : " << pinChallenge.correlationId << endl; + cout << "PinChallenge.ChallengeRequestor.Id : " << pinChallenge.parameters.requestor.id << endl; + cout << "PinChallenge.ChallengeRequestor.Name : " << pinChallenge.parameters.requestor.name << endl; + cout << "PinChallenge.PinChallengePinSpace : " << ConvertToPinSpaceStr(pinChallenge.parameters.pinSpace) << endl; + cout << "PinChallenge.Capability : " << *(pinChallenge.parameters.capability) << endl; +} + +void ManageSDKTest::SubscribePinChallengeRequestChallenge() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().PinChallengeInterface().Subscribe(_requestChallengeNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Subscribe PinChallenge RequestChallenge is success" << endl; + } else { + cout << "Subscribe PinChallenge RequestChallenge status = " << static_cast(error) << endl; + } +} + +void ManageSDKTest::UnsubscribePinChallengeRequestChallenge() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().PinChallengeInterface().Unsubscribe(_requestChallengeNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe PinChallenge RequestChallenge is success" << endl; + } else { + cout << "Unsubscribe PinChallenge RequestChallenge status = " << static_cast(error) << endl; + } +} diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h index 52412aba0..7631da092 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h @@ -19,10 +19,32 @@ #pragma once #include -#include "error.h" +#include "firebolt.h" class ManageSDKTest { + class OnDeviceNameChangedNotification : public Firebolt::Device::IDevice::IOnDeviceNameChangedNotification { + public: + void OnDeviceNameChanged( const std::string& ) override; + }; + + class OnFontFamilyChangedNotification : public Firebolt::ClosedCaptions::IClosedCaptions::IOnFontFamilyChangedNotification { + void OnFontFamilyChanged( const Firebolt::Accessibility::FontFamily& ) override; + }; + + class OnBackgroundOpacityChangedNotification : public Firebolt::ClosedCaptions::IClosedCaptions::IOnBackgroundOpacityChangedNotification { + void OnBackgroundOpacityChanged( const float ) override; + }; + + class OnPreferredAudioLanguagesChangedNotification : public Firebolt::Localization::ILocalization::IOnPreferredAudioLanguagesChangedNotification { + public: + void OnPreferredAudioLanguagesChanged( const std::vector& ) override; + }; + + struct OnRequestChallengeNotification : public Firebolt::PinChallenge::IPinChallenge::IOnRequestChallengeNotification { + public: + void OnRequestChallenge( const Firebolt::PinChallenge::PinChallengeProviderRequest& ) override; + }; public: ManageSDKTest() = default; virtual ~ManageSDKTest() = default; @@ -32,16 +54,32 @@ class ManageSDKTest { static void TestManageStaticSDK(); static void GetDeviceName(); static void SetDeviceName(); + static void SubscribeDeviceNameChanged(); + static void UnsubscribeDeviceNameChanged(); static void GetClosedCaptionBackgroundOpacity(); static void SetClosedCaptionBackgroundOpacity(); + static void SubscribeClosedCaptionsBackgroundOpacityChanged(); + static void UnsubscribeClosedCaptionsBackgroundOpacityChanged(); static void GetClosedCaptionFontFamily(); static void SetClosedCaptionFontFamily(); + static void SubscribeClosedCaptionsFontFamilyChanged(); + static void UnsubscribeClosedCaptionsFontFamilyChanged(); static void GetLocalizationPreferredAudioLanguages(); static void SetLocalizationPreferredAudioLanguages(); + static void SubscribeLocalizationPreferredAudioLanguagesChanged(); + static void UnsubscribeLocalizationPreferredAudioLanguagesChanged(); + static void SubscribePinChallengeRequestChallenge(); + static void UnsubscribePinChallengeRequestChallenge(); + static bool WaitOnConnectionReady(); private: static void ConnectionChanged(const bool, const Firebolt::Error); static bool _connected; + static OnDeviceNameChangedNotification _deviceNameChangedNotification; + static OnFontFamilyChangedNotification _fontFamilyChangedNotification; + static OnBackgroundOpacityChangedNotification _backgroundOpacityChangedNotification; + static OnPreferredAudioLanguagesChangedNotification _preferredAudioLanguagesChangedNotification; + static OnRequestChallengeNotification _requestChallengeNotification; };