diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp index 7d5c79a13..cbeaefead 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp @@ -1,4 +1,4 @@ - +#include #include "ManageSDKTest.h" void ShowMenu() @@ -16,15 +16,21 @@ void ShowMenu() "\tL : Get Localization Preferred AudioLanguages\n" "\tA : Set Localization Preferred AudioLanguages\n" "\tR : Subscribe/Unsubscribe for Localization Preferred AudioLanguages Change\n" -#ifdef RPC_ONLY - "\tP : Subscribe/Unsubscribe for PinChallenge RequestChallenge\n" -#endif - "\tD : Register for Keyboard Provider\n" - "\tE : Send Keyboard Result to Provider\n" + "\tD : Register for Keyboard Provider and check sequence\n" + "\tK : Register for Acknowledge Challenge Provider and check sequence\n" + "\tP : Register for Pin Challenge Provider and check sequence\n" "\tQ : Quit\n\n" ); } +void ShowProviderMenu(std::string& module) +{ + printf("Invoke %s onRequest sequence from other entity and press\n" + "\tR: To Send Response\n" + "\tE: To Send Error\n" + "\tQ : Quit\n", module.c_str()); +} + void ShowEventMenu() { printf("Enter\n" @@ -56,21 +62,52 @@ void ShowEventMenu() } while (opt != 'Q'); \ } +#define VALUE(string) #string +#define TO_STRING(string) VALUE(string) +#define HandleProviderSequence(Module) \ +{ \ + int opt; \ + do { \ + getchar(); \ + std::string module = TO_STRING(Module); \ + ShowProviderMenu(module); \ + printf("Enter option : "); \ + opt = toupper(getchar()); \ + switch (opt) { \ + case 'R': { \ + ManageSDKTest::SendResponseMessageTo##Module##Provider(); \ + break; \ + } \ + case 'E': { \ + ManageSDKTest::SendErrorMessageTo##Module##Provider(); \ + break; \ + } \ + default: \ + break; \ + } \ + } while (opt != 'Q'); \ +} + +#define options ":hu:" int main (int argc, char* argv[]) { - char* config = "{\ - \"waitTime\": 1000,\ - \"logLevel\": \"Info\",\ - \"workerPool\":{\ - \"queueSize\": 8,\ - \"threadCount\": 3\ - },\ - \"wsUrl\": \"ws://127.0.0.1:9998\"\ -}"; + int c; + std::string url = "ws://127.0.0.1:9998"; + while ((c = getopt (argc, argv, options)) != -1) { + switch (c) + { + case 'u': + url = optarg; + break; + + case 'h': + printf("./TestFireboltManage -u ws://ip:port\n"); + exit(1); + } + } printf("Firebolt Manage SDK Test\n"); - - ManageSDKTest::CreateFireboltInstance(); + ManageSDKTest::CreateFireboltInstance(url); int option; if (ManageSDKTest::WaitOnConnectionReady() == true) { @@ -135,10 +172,18 @@ int main (int argc, char* argv[]) #endif case 'D': { ManageSDKTest::RegisterKeyboardProvider(); + HandleProviderSequence(Keyboard) break; } - case 'E': { - ManageSDKTest::SendMessageToKeyboardProvider(); + case 'K': { + ManageSDKTest::RegisterAcknowledgeChallengeProvider(); + HandleProviderSequence(AcknowledgeChallenge) + break; + } + case 'P': { + ManageSDKTest::RegisterPinChallengeProvider(); + HandleProviderSequence(PinChallenge) + 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 832d4886b..ef29a43c4 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp @@ -29,6 +29,8 @@ ManageSDKTest::OnPreferredAudioLanguagesChangedNotification ManageSDKTest::_pref ManageSDKTest::OnRequestChallengeNotification ManageSDKTest::_requestChallengeNotification; #endif ManageSDKTest::KeyboardProvider ManageSDKTest::_keyboardProvider; +ManageSDKTest::AcknowledgeChallengeProvider ManageSDKTest::_acknowledgeChallengeProvider; +ManageSDKTest::PinChallengeProvider ManageSDKTest::_pinChallengeProvider; void ManageSDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error) { @@ -36,7 +38,7 @@ void ManageSDKTest::ConnectionChanged(const bool connected, const Firebolt::Erro _connected = connected; } -void ManageSDKTest::CreateFireboltInstance() +void ManageSDKTest::CreateFireboltInstance(const std::string& url) { const std::string config = "{\ \"waitTime\": 1000,\ @@ -45,8 +47,7 @@ void ManageSDKTest::CreateFireboltInstance() \"queueSize\": 8,\ \"threadCount\": 3\ },\ - \"wsUrl\": \"ws://127.0.0.1:9998\"\ - }"; + \"wsUrl\": " + url + "}"; _connected = false; Firebolt::IFireboltAccessor::Instance().Initialize(config); @@ -351,7 +352,7 @@ ManageSDKTest::KeyboardProvider::KeyboardProvider() { } -void ManageSDKTest::KeyboardProvider::keyboardLoop() +void ManageSDKTest::KeyboardProvider::SendMessage(bool response) { if (_keyInput) { cout << " Invoking _session->focus " << endl; @@ -361,22 +362,20 @@ void ManageSDKTest::KeyboardProvider::keyboardLoop() string key; cout << _parameters.message << " : "; getline(cin, key); - cout<< " key --> " << key; - Firebolt::Keyboard::KeyboardResult keyboardResult; - keyboardResult.text = key; - keyboardResult.canceled = false; - cout << " Invoking _session->result " << endl; - _session->result(keyboardResult); - - key = ""; - cout<< "\n Enter error message too for testing --> " << key; - getline(cin, key); - Firebolt::Keyboard::KeyboardError keyboardError; - keyboardError.code = 123; - keyboardError.message = key; - cout << " Invoking _session->error " << endl; - _session->error(keyboardError); - + if (response) { + Firebolt::Keyboard::KeyboardResult keyboardResult; + keyboardResult.text = key; + keyboardResult.canceled = false; + cout << " Invoking _session->result " << endl; + _session->result(keyboardResult); + } else { + Firebolt::Keyboard::KeyboardError keyboardError; + keyboardError.code = 123; + keyboardError.message = key; + keyboardError.data = "nothing to send"; + cout << " Invoking _session->error " << endl; + _session->error(keyboardError); + } _keyInput = false; cin.putback('\n'); } else { @@ -414,7 +413,149 @@ void ManageSDKTest::RegisterKeyboardProvider() Firebolt::IFireboltAccessor::Instance().KeyboardInterface().provide(_keyboardProvider); } -void ManageSDKTest::SendMessageToKeyboardProvider() +void ManageSDKTest::SendResponseMessageToKeyboardProvider() +{ + _keyboardProvider.SendMessage(true); +} + +void ManageSDKTest::SendErrorMessageToKeyboardProvider() +{ + _keyboardProvider.SendMessage(false); +} + +ManageSDKTest::AcknowledgeChallengeProvider::AcknowledgeChallengeProvider() + : _session(nullptr) + , _parameters() + , _challengeInput(false) +{ +} + +void ManageSDKTest::AcknowledgeChallengeProvider::SendMessage(bool response) +{ + if (_challengeInput) { + cout << " Invoking _session->focus " << endl; + _session->focus(); + getchar(); + cout << " capability : " << _parameters.capability << endl; + cout << " id : " << _parameters.requestor.id << endl; + cout << " name : " << _parameters.requestor.name << endl; + if (response) { + Firebolt::AcknowledgeChallenge::GrantResult challengeResult; + challengeResult.granted = true; + cout << " Invoking _session->result " << endl; + _session->result(challengeResult); + } else { + string key; + getline(cin, key); + + Firebolt::AcknowledgeChallenge::AcknowledgeChallengeError challengeError; + challengeError.code = 234; + challengeError.message = key; + cout << " Invoking _session->error " << endl; + _session->error(challengeError); + cin.putback('\n'); + } + _challengeInput = false; + } else { + cout << " there is no active acknowledge challenge input session " << endl; + } +} + +void ManageSDKTest::AcknowledgeChallengeProvider::challenge(const Firebolt::AcknowledgeChallenge::Challenge& parameters, std::unique_ptr session) +{ + cout << "KeyboardProvider Standard is invoked" << endl; + startAcknowledgeChallengeSession(parameters, std::move(session)); +} + +void ManageSDKTest::AcknowledgeChallengeProvider::startAcknowledgeChallengeSession( const Firebolt::AcknowledgeChallenge::Challenge& parameters, std::unique_ptr session ) +{ + _session = std::move(session); + _parameters = parameters; + _challengeInput = true; +} + +void ManageSDKTest::RegisterAcknowledgeChallengeProvider() +{ + Firebolt::IFireboltAccessor::Instance().AcknowledgeChallengeInterface().provide(_acknowledgeChallengeProvider); +} + +void ManageSDKTest::SendResponseMessageToAcknowledgeChallengeProvider() +{ + _acknowledgeChallengeProvider.SendMessage(true); +} + +void ManageSDKTest::SendErrorMessageToAcknowledgeChallengeProvider() +{ + _acknowledgeChallengeProvider.SendMessage(false); +} + +ManageSDKTest::PinChallengeProvider::PinChallengeProvider() + : _session(nullptr) + , _parameters() + , _challengeInput(false) +{ +} + +void ManageSDKTest::PinChallengeProvider::SendMessage(bool response) +{ + if (_challengeInput) { + cout << " Invoking _session->focus " << endl; + _session->focus(); + getchar(); + cout << " pinSpace : " << static_cast(_parameters.pinSpace) << endl; + if (_parameters.capability.has_value()) { + cout << " capability : " << _parameters.capability.value() << endl; + } + cout << " id : " << _parameters.requestor.id << endl; + cout << " name : " << _parameters.requestor.name << endl; + + if (response) { + Firebolt::PinChallenge::PinChallengeResult challengeResult; + challengeResult.granted = true; + challengeResult.reason = Firebolt::PinChallenge::ResultReason::CORRECT_PIN; + cout << " Invoking _session->result " << endl; + _session->result(challengeResult); + } else { + string key; + getline(cin, key); + + Firebolt::PinChallenge::PinChallengeError challengeError; + challengeError.code = 234; + challengeError.message = key; + cout << " Invoking _session->error " << endl; + _session->error(challengeError); + cin.putback('\n'); + } + _challengeInput = false; + } else { + cout << " there is no active pin challenge input session " << endl; + } +} + +void ManageSDKTest::PinChallengeProvider::challenge(const Firebolt::PinChallenge::PinChallenge& parameters, std::unique_ptr session) +{ + cout << "KeyboardProvider Standard is invoked" << endl; + startPinChallengeSession(parameters, std::move(session)); +} + +void ManageSDKTest::PinChallengeProvider::startPinChallengeSession( const Firebolt::PinChallenge::PinChallenge& parameters, std::unique_ptr session ) +{ + _session = std::move(session); + _parameters = parameters; + _challengeInput = true; +} + +void ManageSDKTest::RegisterPinChallengeProvider() +{ + Firebolt::IFireboltAccessor::Instance().PinChallengeInterface().provide(_pinChallengeProvider); +} + +void ManageSDKTest::SendResponseMessageToPinChallengeProvider() +{ + _pinChallengeProvider.SendMessage(true); +} + +void ManageSDKTest::SendErrorMessageToPinChallengeProvider() { - _keyboardProvider.keyboardLoop(); + _pinChallengeProvider.SendMessage(false); } diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h index 72812dce7..ccb5ca6f6 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h @@ -54,7 +54,7 @@ class ManageSDKTest { void standard( const Firebolt::Keyboard::KeyboardParameters& parameters, std::unique_ptr session ) override; void password( const Firebolt::Keyboard::KeyboardParameters& parameters, std::unique_ptr session ) override; void email( const Firebolt::Keyboard::KeyboardParameters& parameters, std::unique_ptr session ) override; - void keyboardLoop(); + void SendMessage(bool response); private: void startKeyboardSession(const Firebolt::Keyboard::KeyboardParameters& parameters, std::unique_ptr session); @@ -64,11 +64,42 @@ class ManageSDKTest { Firebolt::Keyboard::KeyboardParameters _parameters; bool _keyInput; }; + class AcknowledgeChallengeProvider : public Firebolt::AcknowledgeChallenge::IAcknowledgeChallengeProvider { + public: + AcknowledgeChallengeProvider(); + ~AcknowledgeChallengeProvider() override = default; + void challenge( const Firebolt::AcknowledgeChallenge::Challenge& parameters, std::unique_ptr session ) override; + void SendMessage(bool response); + + private: + void startAcknowledgeChallengeSession(const Firebolt::AcknowledgeChallenge::Challenge& parameters, std::unique_ptr session); + + private: + std::unique_ptr _session; + Firebolt::AcknowledgeChallenge::Challenge _parameters; + bool _challengeInput; + }; + class PinChallengeProvider : public Firebolt::PinChallenge::IPinChallengeProvider { + public: + PinChallengeProvider(); + ~PinChallengeProvider() override = default; + void challenge( const Firebolt::PinChallenge::PinChallenge& parameters, std::unique_ptr session ) override; + void SendMessage(bool response); + + private: + void startPinChallengeSession(const Firebolt::PinChallenge::PinChallenge& parameters, std::unique_ptr session); + + private: + std::unique_ptr _session; + Firebolt::PinChallenge::PinChallenge _parameters; + bool _challengeInput; + }; + public: ManageSDKTest() = default; virtual ~ManageSDKTest() = default; - static void CreateFireboltInstance(); + static void CreateFireboltInstance(const std::string& url); static void DestroyFireboltInstance(); static void TestManageStaticSDK(); static void GetDeviceName(); @@ -92,7 +123,15 @@ class ManageSDKTest { static void UnsubscribePinChallengeRequestChallenge(); #endif static void RegisterKeyboardProvider(); - static void SendMessageToKeyboardProvider(); + static void SendResponseMessageToKeyboardProvider(); + static void SendErrorMessageToKeyboardProvider(); + + static void RegisterAcknowledgeChallengeProvider(); + static void SendResponseMessageToAcknowledgeChallengeProvider(); + static void SendErrorMessageToAcknowledgeChallengeProvider(); + static void RegisterPinChallengeProvider(); + static void SendResponseMessageToPinChallengeProvider(); + static void SendErrorMessageToPinChallengeProvider(); static bool WaitOnConnectionReady(); private: @@ -106,5 +145,7 @@ class ManageSDKTest { static OnRequestChallengeNotification _requestChallengeNotification; #endif static KeyboardProvider _keyboardProvider; + static AcknowledgeChallengeProvider _acknowledgeChallengeProvider; + static PinChallengeProvider _pinChallengeProvider; };