From e2c55dfc2c90627838f1fc867beeac3fee1cf513 Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Tue, 10 Oct 2023 09:19:38 -0400 Subject: [PATCH] CPPSDK: test event sample test added --- src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp | 36 ++++++++++++++++ .../src/cpp/sdk/cpptest/ManageSDKTest.cpp | 41 +++++++++++++++---- .../src/cpp/sdk/cpptest/ManageSDKTest.h | 10 ++++- 3 files changed, 79 insertions(+), 8 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..ff8c94e4c 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp @@ -6,6 +6,7 @@ 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" "\tF : Get ClosedCaption Font Family\n" @@ -16,6 +17,37 @@ void ShowMenu() ); } +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 +79,10 @@ int main (int argc, char* argv[]) ManageSDKTest::SetDeviceName(); break; } + case 'C': { + HandleEventListener(Device, NameChanged) + break; + } case 'B': { ManageSDKTest::GetClosedCaptionBackgroundOpacity(); 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..f438abdf4 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp @@ -17,16 +17,21 @@ */ #include -#include "firebolt.h" #include "ManageSDKTest.h" using namespace std; bool ManageSDKTest::_connected; +ManageSDKTest::OnDeviceNameChangedNotification ManageSDKTest::_onDeviceNameChangedNotification; + +void ManageSDKTest::OnDeviceNameChangedNotification::OnDeviceNameChanged( const std::string& name) +{ + cout << "Name changed, new name --> " << name << endl; +} 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 +80,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 +92,31 @@ 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 Device Name status = " << static_cast(error) << endl; + } +} + +void ManageSDKTest::SubscribeDeviceNameChanged() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().DeviceInterface().Subscribe(_onDeviceNameChangedNotification, &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(_onDeviceNameChangedNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe Device NameChange is success" << endl; } else { - cout << "Set DeviceName status = " << static_cast(error) << endl; + cout << "Unsubscribe Device NameChange 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..8f02a6fc3 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h @@ -19,10 +19,15 @@ #pragma once #include -#include "error.h" +#include "firebolt.h" class ManageSDKTest { + class OnDeviceNameChangedNotification : public Firebolt::Device::IDevice::IOnDeviceNameChangedNotification { + public: + void OnDeviceNameChanged( const std::string& name) override; + }; + public: ManageSDKTest() = default; virtual ~ManageSDKTest() = default; @@ -32,6 +37,8 @@ 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 GetClosedCaptionFontFamily(); @@ -43,5 +50,6 @@ class ManageSDKTest { private: static void ConnectionChanged(const bool, const Firebolt::Error); static bool _connected; + static OnDeviceNameChangedNotification _onDeviceNameChangedNotification; };