Skip to content

Commit

Permalink
CPPSDK: test event sample test added
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Oct 10, 2023
1 parent 7b88a18 commit e2c55df
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
36 changes: 36 additions & 0 deletions src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = "{\
Expand Down Expand Up @@ -47,6 +79,10 @@ int main (int argc, char* argv[])
ManageSDKTest::SetDeviceName();
break;
}
case 'C': {
HandleEventListener(Device, NameChanged)
break;
}
case 'B': {
ManageSDKTest::GetClosedCaptionBackgroundOpacity();
break;
Expand Down
41 changes: 34 additions & 7 deletions src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
*/

#include <unistd.h>
#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<int>(error) << endl;
_connected = connected;
cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl;
_connected = connected;
}

void ManageSDKTest::CreateFireboltInstance()
Expand Down Expand Up @@ -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<int>(error) << endl;
cout << "Get Device Name status = " << static_cast<int>(error) << endl;
}
}

Expand All @@ -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<int>(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<int>(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<int>(error) << endl;
cout << "Unsubscribe Device NameChange status = " << static_cast<int>(error) << endl;
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
#pragma once

#include <iostream>
#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;
Expand All @@ -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();
Expand All @@ -43,5 +50,6 @@ class ManageSDKTest {
private:
static void ConnectionChanged(const bool, const Firebolt::Error);
static bool _connected;
static OnDeviceNameChangedNotification _onDeviceNameChangedNotification;
};

0 comments on commit e2c55df

Please sign in to comment.