summaryrefslogtreecommitdiffstats
path: root/src/plugins/core
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2019-12-09 02:25:25 +0100
committerScott Murray <scott.murray@konsulko.com>2019-12-20 17:51:21 +0000
commit9a4ec5a5793ce904333f6087cf31d7819206c101 (patch)
tree1aeb4d13352ff0f4b31a9f46fa5ab0fc761e1a69 /src/plugins/core
parent01c999956ea5fba52c4eaf35998c023047587171 (diff)
Add CBL processing
CBL: Code Based Linking in the case of Alexa voice agent, or more generally Code Based Logging. It provides a url and code which allows the user to complete the authorization process and start using the authorized voice services. - add subscribeToLoginEvents verb - add cbl events handling - include new verb in vshl-core-api.json Bug-AGL: SPEC-2981 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: If342d45638125682621cba707eac1d4ff5ad244c (cherry picked from commit ed834a643e3843c0f805ea33363c9f2889d2bab3)
Diffstat (limited to 'src/plugins/core')
-rw-r--r--src/plugins/core/VRRequestProcessor.h6
-rw-r--r--src/plugins/core/VRRequestProcessorImpl.cpp14
-rw-r--r--src/plugins/core/include/VRRequest.h6
-rw-r--r--src/plugins/core/include/VRRequestProcessorDelegate.h4
-rw-r--r--src/plugins/core/src/VRRequestImpl.cpp16
-rw-r--r--src/plugins/core/src/VRRequestProcessorDelegateImpl.cpp26
6 files changed, 72 insertions, 0 deletions
diff --git a/src/plugins/core/VRRequestProcessor.h b/src/plugins/core/VRRequestProcessor.h
index 97e277a..037b27f 100644
--- a/src/plugins/core/VRRequestProcessor.h
+++ b/src/plugins/core/VRRequestProcessor.h
@@ -17,6 +17,7 @@
#include <memory>
#include <unordered_map>
+#include <list>
#include "core/include/VRRequest.h"
#include "core/include/VRRequestProcessorDelegate.h"
@@ -43,6 +44,11 @@ public:
// is returned.
string startListening();
+ // Triggers a voiceagent to generate events to provide info to allow
+ // the user to complete the authorization process (if required).
+ // Returns the request ID. An empty request ID is returned on failure.
+ string subscribeToLoginEvents(string va_id, list<string> *args);
+
// Cancels all the active requests
void cancel();
diff --git a/src/plugins/core/VRRequestProcessorImpl.cpp b/src/plugins/core/VRRequestProcessorImpl.cpp
index c07f745..d9fa846 100644
--- a/src/plugins/core/VRRequestProcessorImpl.cpp
+++ b/src/plugins/core/VRRequestProcessorImpl.cpp
@@ -57,6 +57,20 @@ string VRRequestProcessor::startListening() {
return mDelegate->startRequestForVoiceAgent(defaultVA);
}
+string VRRequestProcessor::subscribeToLoginEvents(std::string va_id, std::list<std::string> *args) {
+ // Currently simply send the request to the default voice agent, ignoring va_id
+ shared_ptr<vshlcore::common::interfaces::IVoiceAgent> defaultVA = mDelegate->getDefaultVoiceAgent();
+ if (!defaultVA) {
+ mLogger->log(Level::ERROR, TAG, "Failed to subscribeToLoginEvents. No default voiceagent found.");
+ return "";
+ }
+
+ // If the requests container is not empty, then clear the
+ // existing requests in flight and create a new request.
+ mDelegate->cancelAllRequests();
+ return mDelegate->loginEventsRequestForVoiceAgent(defaultVA, args);
+}
+
void VRRequestProcessor::cancel() {
// Cancel all pending requests
mDelegate->cancelAllRequests();
diff --git a/src/plugins/core/include/VRRequest.h b/src/plugins/core/include/VRRequest.h
index 8b9e842..feeac6d 100644
--- a/src/plugins/core/include/VRRequest.h
+++ b/src/plugins/core/include/VRRequest.h
@@ -16,6 +16,7 @@
#define VSHL_CORE_INCLUDE_VR_REQUEST_H_
#include <memory>
+#include <list>
#include "interfaces/afb/IAFBApi.h"
#include "interfaces/utilities/logging/ILogger.h"
@@ -32,6 +33,7 @@ class VRRequest {
public:
// API Verbs
static std::string VA_VERB_STARTLISTENING;
+ static std::string VA_VERB_SUBSCRIBETOCBLEVENTS;
static std::string VA_VERB_CANCEL;
// Create a VRRequest.
@@ -48,6 +50,10 @@ public:
// Returns true if started successfully. False otherwise.
bool startListening();
+ // Invokes the underlying voiceagent's subscribe to login events API.
+ // Returns true if successful, false otherwise.
+ bool subscribeToLoginEvents(std::list<std::string> *args);
+
// Cancels the voice recognition in the unlerlying voiceagent.
// Returns true if canceled successfully. False otherwise.
bool cancel();
diff --git a/src/plugins/core/include/VRRequestProcessorDelegate.h b/src/plugins/core/include/VRRequestProcessorDelegate.h
index 2c36d38..2ada2fb 100644
--- a/src/plugins/core/include/VRRequestProcessorDelegate.h
+++ b/src/plugins/core/include/VRRequestProcessorDelegate.h
@@ -17,6 +17,7 @@
#include <memory>
#include <unordered_map>
+#include <list>
#include "core/include/VRRequest.h"
#include "interfaces/afb/IAFBApi.h"
@@ -55,6 +56,9 @@ public:
// voiceagent is called.
string startRequestForVoiceAgent(shared_ptr<vshlcore::common::interfaces::IVoiceAgent> voiceAgent);
+ string loginEventsRequestForVoiceAgent(shared_ptr<vshlcore::common::interfaces::IVoiceAgent> voiceAgent,
+ std::list<std::string> *args);
+
// Cancel all requests
void cancelAllRequests();
diff --git a/src/plugins/core/src/VRRequestImpl.cpp b/src/plugins/core/src/VRRequestImpl.cpp
index 63302d8..d1a18ac 100644
--- a/src/plugins/core/src/VRRequestImpl.cpp
+++ b/src/plugins/core/src/VRRequestImpl.cpp
@@ -32,6 +32,7 @@ namespace core {
string VRRequest::VA_VERB_STARTLISTENING = "startListening";
string VRRequest::VA_VERB_CANCEL = "cancel";
+string VRRequest::VA_VERB_SUBSCRIBETOCBLEVENTS = "subscribeToCBLEvents";
unique_ptr<VRRequest> VRRequest::create(
shared_ptr<vshlcore::common::interfaces::ILogger> logger,
@@ -76,6 +77,21 @@ bool VRRequest::startListening() {
return true;
}
+ bool VRRequest::subscribeToLoginEvents(std::list<std::string> *args) {
+ json_object* argsJ = json_object_new_object();
+ json_object* evJ = json_object_new_array();
+ json_object* resultJ;
+ std::string error, info;
+ bool result = true;
+
+ json_object_object_add(argsJ, "events", evJ);
+ int rc = mApi->callSync(mVoiceAgent->getApi(), VA_VERB_SUBSCRIBETOCBLEVENTS, argsJ, &resultJ, error, info);
+
+ FREEIF(resultJ);
+
+ return true;
+}
+
bool VRRequest::cancel() {
json_object* object = NULL;
std::string error, info;
diff --git a/src/plugins/core/src/VRRequestProcessorDelegateImpl.cpp b/src/plugins/core/src/VRRequestProcessorDelegateImpl.cpp
index 78ef10a..57fc592 100644
--- a/src/plugins/core/src/VRRequestProcessorDelegateImpl.cpp
+++ b/src/plugins/core/src/VRRequestProcessorDelegateImpl.cpp
@@ -62,6 +62,32 @@ string VRRequestProcessorDelegate::startRequestForVoiceAgent(
return newReqId;
}
+string VRRequestProcessorDelegate::loginEventsRequestForVoiceAgent(
+ shared_ptr<vshlcore::common::interfaces::IVoiceAgent> voiceAgent,
+ std::list<std::string> *args) {
+ if (!mApi) {
+ mLogger->log(Level::ERROR, TAG, "Failed to loginEventsRequestForVoiceAgent: " + voiceAgent->getId() + ", No API.");
+ return "";
+ }
+
+ // Generate a new request ID.
+ string newReqId = vshlcore::utilities::uuid::generateUUID();
+
+ // Create a new request and start listening.
+ shared_ptr<VRRequest> newRequest = VRRequest::create(mLogger, mApi, newReqId, voiceAgent);
+
+ mLogger->log(Level::DEBUG, TAG, "Starting login request with ID: " + newReqId);
+ if (!newRequest->subscribeToLoginEvents(args)) {
+ mLogger->log(Level::ERROR, TAG, "Failed to subscribe to login events.");
+ return "";
+ }
+
+ // Insert only if its started successfully.
+ mVRRequests.insert(make_pair(voiceAgent->getId(), newRequest));
+
+ return newReqId;
+}
+
void VRRequestProcessorDelegate::cancelAllRequests() {
// Cancel Pending requests
if (!mVRRequests.empty()) {