summaryrefslogtreecommitdiffstats
path: root/voice
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2019-12-09 18:32:02 +0100
committerRaquel Medina <raquel.medina@konsulko.com>2019-12-12 02:18:37 +0100
commit0ff12f7c22e2be3238b0c436c08634cd18f5bd06 (patch)
tree6699d634a1952a62ee4315a71aa60c7405bd48a4 /voice
parentc4e293365c1a16135d49af3bf6de173547326f79 (diff)
voice: remove vshl-capabilities dependencies
Various fixes for voice component: - fix incorrect check on vap (voice agent profile) pointers; - remove dependencies on vshl-capabilities: this module will communicate via vshl-core api; - remove dependencis on alexa-voiceagent; - use a more generic name for cbl related operations. CBL in this environment is understood as code based login (for voice agent authorization via user login to a cloud service), however, in the case of alexa it is known as code based linking; - add check for voice_xxx_event eventdata which in ocasions is an empty object, i.e., the payload is missing. Bug-AGL: SPEC-2981 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: Icaab7a21bedb3e2696d541567162ec46b047a305
Diffstat (limited to 'voice')
-rw-r--r--voice/voice.cpp105
-rw-r--r--voice/voice.h9
-rw-r--r--voice/voiceagentregistry.cpp14
-rw-r--r--voice/voiceagentregistry.h6
-rw-r--r--voice/voicemessage.cpp16
-rw-r--r--voice/voicemessage.h73
6 files changed, 85 insertions, 138 deletions
diff --git a/voice/voice.cpp b/voice/voice.cpp
index 71c93d2..2a83c94 100644
--- a/voice/voice.cpp
+++ b/voice/voice.cpp
@@ -45,7 +45,7 @@ Voice::~Voice()
void Voice::scan()
{
- VoiceMessage *vmsg = new VshlCoreVoiceMessage();
+ VoiceMessage *vmsg = new VoiceMessage();
QJsonObject parameter;
vmsg->createRequest("enumerateVoiceAgents", parameter);
@@ -55,18 +55,13 @@ void Voice::scan()
void Voice::getCBLpair(QString id)
{
- VoiceMessage *vmsg = new AlexaVoiceMessage();
- QJsonObject parameter;
-
- vmsg->createRequest("subscribeToCBLEvents", parameter);
- m_loop->sendMessage(vmsg);
- delete vmsg;
+ subscribeAgentToLoginEvents(id);
}
void Voice::subscribeAgentToVshlEvents(QString id)
{
QJsonArray events = QJsonArray::fromStringList(vshl_events);
- VoiceMessage *vmsg = new VshlCoreVoiceMessage();
+ VoiceMessage *vmsg = new VoiceMessage();
QJsonObject parameter;
parameter.insert("va_id", id);
@@ -79,7 +74,7 @@ void Voice::subscribeAgentToVshlEvents(QString id)
void Voice::unsubscribeAgentFromVshlEvents(QString id)
{
QJsonArray events = QJsonArray::fromStringList(vshl_events);
- VoiceMessage *vmsg = new VshlCoreVoiceMessage();
+ VoiceMessage *vmsg = new VoiceMessage();
QJsonObject parameter;
parameter.insert("va_id", id);
@@ -89,15 +84,18 @@ void Voice::unsubscribeAgentFromVshlEvents(QString id)
delete vmsg;
}
-void Voice::subscribeAgentToCblEvents(QString id)
+void Voice::subscribeAgentToLoginEvents(QString id)
{
- QJsonArray events = QJsonArray::fromStringList(cbl_events);
- VoiceMessage *vmsg = new AlexaVoiceMessage();
+ QJsonArray events = QJsonArray::fromStringList(login_events);
+ VoiceMessage *vmsg = new VoiceMessage();
QJsonObject parameter;
parameter.insert("va_id", id);
parameter.insert("events", events);
- vmsg->createRequest("subscribeToCBLEvent", parameter);
+ vmsg->createRequest("subscribeToLoginEvents", parameter);
+ m_loop->sendMessage(vmsg);
+ //subscribe to events from vshl:
+ vmsg->createRequest("subscribe", parameter);
m_loop->sendMessage(vmsg);
delete vmsg;
}
@@ -121,49 +119,68 @@ void Voice::processVshlEvent(VoiceMessage *vmsg)
strlist = str.split('#');
QString agentId = (strlist.isEmpty())? m_var->getDefaultId() :
strlist.takeLast();
+ if (obj.isEmpty()) {
+ qWarning() << "vshl event has no eventdata" << str;
+ return;
+ }
if (vmsg->isAuthStateEvent()) {
const QString authstate = obj.value("state").toString();
- m_var->setAuthState(
- agentId,
- static_cast<VoiceAgentRegistry::ServiceAuthState>(
- m_var->stringToEnum(authstate, "ServiceAuthState")));
+ if (!authstate.isEmpty())
+ m_var->setAuthState(
+ agentId,
+ static_cast<VoiceAgentRegistry::ServiceAuthState>(
+ m_var->stringToEnum(authstate, "ServiceAuthState")));
} else if (vmsg->isConnectionStateEvent()) {
const QString connstate = obj.value("state").toString();
- m_var->setConnectionState(
- agentId,
- static_cast<VoiceAgentRegistry::AgentConnectionState>(
- m_var->stringToEnum(connstate, "AgentConnectionState")));
+ if (!connstate.isEmpty())
+ m_var->setConnectionState(
+ agentId,
+ static_cast<VoiceAgentRegistry::AgentConnectionState>(
+ m_var->stringToEnum(connstate, "AgentConnectionState")));
} else if (vmsg->isDialogStateEvent()) {
const QString dialogstate = obj.value("state").toString();
- m_var->setDialogState(
- agentId,
- static_cast<VoiceAgentRegistry::VoiceDialogState>(
- m_var->stringToEnum(dialogstate, "VoiceDialogState")));
+ if (!dialogstate.isEmpty())
+ m_var->setDialogState(
+ agentId,
+ static_cast<VoiceAgentRegistry::VoiceDialogState>(
+ m_var->stringToEnum(dialogstate, "VoiceDialogState")));
} else
- qWarning() << "Discarding vshl event:" << str;
+ processLoginEvent(vmsg);
}
-void Voice::processCblEvent(VoiceMessage *vmsg)
+void Voice::processLoginEvent(VoiceMessage *vmsg)
{
const QString str = vmsg->eventName();
const QJsonObject obj = vmsg->eventData();
- QStringList strlist;
+ if (obj.isEmpty()) {
+ qWarning() << "no data for event:" << str;
+ return;
+ }
+
+ QStringList strlist;
if (str.contains('#'))
strlist = str.split('#');
- QString cblevent = (strlist.isEmpty())? QString() : strlist.takeFirst();
- QString agentId = (strlist.isEmpty())? m_var->getDefaultId() :
- strlist.takeLast();
- if (cblevent == "voice_cbl_codepair_received_event") {
- QString code = obj.value("code").toString();
- QString url = obj.value("url").toString();
- m_var->updateCblPair(agentId, code, url, false);
- } else if (cblevent == "voice_cbl_codepair_expired_event") {
- QString code = obj.value("code").toString();
- QString url = obj.value("url").toString();
- m_var->updateCblPair(agentId, code, url, true);
+ QString loginevent = (strlist.isEmpty())? str : strlist.takeFirst();
+ QString agentId = (strlist.isEmpty())?
+ m_var->getDefaultId() : strlist.takeLast();
+
+ if (loginevent.contains("codepair_received")) {
+ QString id = obj.value("va_id").toString();
+ QJsonObject payload = obj.value("payload").toObject();
+ QJsonObject payload2 = payload.value("payload").toObject();
+ auto data_iter = payload2.find("code");
+ auto url_iter = payload2.find("url");
+ QString code = data_iter.value().toString();
+ QString url = url_iter.value().toString();
+ m_var->updateLoginData(id, code, url, false);
+ } else if (loginevent.contains("codepair_expired")) {
+ QString id = obj.value("va_id").toString();
+ QString code = QString();
+ QString url = QString();
+ m_var->updateLoginData(id, code, url, true);
} else
- qWarning() << "Discarding cbl event:" << str;
+ qWarning() << "Discarding event:" << str;
}
void Voice::processEvent(VoiceMessage *vmsg)
@@ -171,20 +188,20 @@ void Voice::processEvent(VoiceMessage *vmsg)
const QString api = vmsg->eventApi();
if (api == "vshl-core")
processVshlEvent(vmsg);
- else if (api == "alexa-voiceagent")
- processCblEvent(vmsg);
else
qWarning() << "Unknown api:" << api;
}
void Voice::processReply(ResponseMessage *rmsg)
{
- if (rmsg->requestVerb() == "enumerateVoiceAgents") {
+ if (rmsg->replyStatus() == "failed") {
+ qWarning() << "Reply Failed received for verb:" << rmsg->requestVerb();
+ } else if (rmsg->requestVerb() == "enumerateVoiceAgents") {
parseAgentsList(rmsg->replyData().value("agents").toArray());
m_var->setDefaultId(
rmsg->replyData().value("default").toString());
} else
- qWarning() << "Reply received for unknown verb:" <<
+ qWarning() << "success reply received for verb:" <<
rmsg->requestVerb();
}
diff --git a/voice/voice.h b/voice/voice.h
index 1da7ca6..be3d15d 100644
--- a/voice/voice.h
+++ b/voice/voice.h
@@ -37,8 +37,9 @@ class Voice : public QObject
QObject * parent = Q_NULLPTR);
virtual ~Voice();
- // controls
+ //enumerate agents:
Q_INVOKABLE void scan();
+ //obtain code based login params:
Q_INVOKABLE void getCBLpair(QString id);
private:
@@ -47,10 +48,10 @@ class Voice : public QObject
void subscribeAgentToVshlEvents(QString id);
void unsubscribeAgentFromVshlEvents(QString id);
- void subscribeAgentToCblEvents(QString id);
+ void subscribeAgentToLoginEvents(QString id);
void parseAgentsList(QJsonArray agents);
void processVshlEvent(VoiceMessage *vmsg);
- void processCblEvent(VoiceMessage *vmsg);
+ void processLoginEvent(VoiceMessage *vmsg);
void processEvent(VoiceMessage *vmsg);
void processReply(ResponseMessage *rmsg);
@@ -65,7 +66,7 @@ class Voice : public QObject
"voice_dialogstate_event",
"voice_connectionstate_event",
};
- const QStringList cbl_events {
+ const QStringList login_events {
"voice_cbl_codepair_received_event",
"voice_cbl_codepair_expired_event",
};
diff --git a/voice/voiceagentregistry.cpp b/voice/voiceagentregistry.cpp
index 22c7051..bbd9857 100644
--- a/voice/voiceagentregistry.cpp
+++ b/voice/voiceagentregistry.cpp
@@ -26,7 +26,7 @@
VoiceAgentRegistry::VoiceAgentRegistry(Voice *voice, QQmlContext *context, QObject *parent) :
QObject(parent),
m_model(nullptr),
- m_voice(voice)
+ vc(voice)
{
m_model = new VoiceAgentModel();
QSortFilterProxyModel *model = new QSortFilterProxyModel();
@@ -102,7 +102,7 @@ void VoiceAgentRegistry::setAuthState(QString id, ServiceAuthState state)
const auto stateStr =
QMetaEnum::fromType<VoiceAgentRegistry::ServiceAuthState>().valueToKey(state);
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (!vap)
+ if (vap)
vap->setAuthState(stateStr);
}
@@ -111,7 +111,7 @@ void VoiceAgentRegistry::setConnectionState(QString id, AgentConnectionState sta
const auto stateStr =
QMetaEnum::fromType<VoiceAgentRegistry::AgentConnectionState>().valueToKey(state);
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (!vap)
+ if (vap)
vap->setConnState(stateStr);
}
@@ -120,15 +120,15 @@ void VoiceAgentRegistry::setDialogState(QString id, VoiceDialogState state)
const auto stateStr =
QMetaEnum::fromType<VoiceAgentRegistry::VoiceDialogState>().valueToKey(state);
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (!vap)
+ if (vap)
vap->setDialogState(stateStr);
}
-void VoiceAgentRegistry::updateCblPair(QString id, QString code, QString url,
- bool expired)
+void VoiceAgentRegistry::updateLoginData(QString id, QString code, QString url,
+ bool expired)
{
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (!vap) {
+ if (vap) {
vap->setLoginCode(code);
vap->setLoginUrl(code);
vap->setLoginPairExpired(expired);
diff --git a/voice/voiceagentregistry.h b/voice/voiceagentregistry.h
index 2a69294..4394017 100644
--- a/voice/voiceagentregistry.h
+++ b/voice/voiceagentregistry.h
@@ -63,12 +63,12 @@ class VoiceAgentRegistry : public QObject
void setAuthState(QString id, ServiceAuthState state);
void setConnectionState(QString id, AgentConnectionState state);
void setDialogState(QString id, VoiceDialogState state);
- void updateCblPair(QString id, QString code, QString url,
- bool expired);
+ void updateLoginData(QString id, QString code, QString url,
+ bool expired);
int stringToEnum(QString value, QString enumtype);
private:
VoiceAgentModel *m_model;
- Voice *m_voice;
+ Voice *vc;
QString m_default_aid;
QStringList m_regids;
};
diff --git a/voice/voicemessage.cpp b/voice/voicemessage.cpp
index c338879..6e5c634 100644
--- a/voice/voicemessage.cpp
+++ b/voice/voicemessage.cpp
@@ -21,23 +21,9 @@
#include "voicemessage.h"
-bool VshlCoreVoiceMessage::createRequest(QString verb, QJsonObject parameter)
+bool VoiceMessage::createRequest(QString verb, QJsonObject parameter)
{
if (!verbs.contains(verb))
return false;
return Message::createRequest("vshl-core", verb, parameter);
}
-
-bool VshlCpbltsVoiceMessage::createRequest(QString verb, QJsonObject parameter)
-{
- if (!verbs.contains(verb))
- return false;
- return Message::createRequest("vshl-capabilities", verb, parameter);
-}
-
-bool AlexaVoiceMessage::createRequest(QString verb, QJsonObject parameter)
-{
- if (!verbs.contains(verb))
- return false;
- return Message::createRequest("alexa-voiceagent", verb, parameter);
-}
diff --git a/voice/voicemessage.h b/voice/voicemessage.h
index 00ed847..27aa06d 100644
--- a/voice/voicemessage.h
+++ b/voice/voicemessage.h
@@ -24,24 +24,15 @@ class VoiceMessage : public Message
Q_OBJECT
public:
virtual ~VoiceMessage() {};
- virtual bool isAuthStateEvent() const = 0;
- virtual bool isConnectionStateEvent() const = 0;
- virtual bool isDialogStateEvent() const = 0;
- virtual bool createRequest(QString verb, QJsonObject parameter) = 0;
-};
-
-class VshlCoreVoiceMessage : public VoiceMessage
-{
- Q_OBJECT
- public:
- virtual ~VshlCoreVoiceMessage() {};
- bool isAuthStateEvent() const override {
+ bool isAuthStateEvent() const {
return (this->eventName().contains("voice_authstate_event")); };
- bool isConnectionStateEvent() const override {
+ bool isConnectionStateEvent() const {
return (this->eventName().contains("voice_connectionstate_event")); };
- bool isDialogStateEvent() const override {
+ bool isDialogStateEvent() const {
return (this->eventName().contains("voice_dialogstate_event")); };
- bool createRequest(QString verb, QJsonObject parameter) override;
+ bool isCblEvent() const {
+ return (this->eventName().contains("cbl")); };
+ bool createRequest(QString verb, QJsonObject parameter);
private:
QStringList verbs {
@@ -51,64 +42,16 @@ class VshlCoreVoiceMessage : public VoiceMessage
"unsubscribe",
"enumerateVoiceAgents",
"setDefaultVoiceAgent",
+ "subscribeToLoginEvents",
};
QStringList events {
"voice_authstate_event",
"voice_dialogstate_event",
"voice_connectionstate_event",
- };
-};
-
-class VshlCpbltsVoiceMessage : public VoiceMessage
-{
- Q_OBJECT
- public:
- virtual ~VshlCpbltsVoiceMessage() {};
- bool isAuthStateEvent() const override { return false; };
- bool isConnectionStateEvent() const override { return false; };
- bool isDialogStateEvent() const override { return false; };
- bool createRequest(QString verb, QJsonObject parameter) override;
-
- private:
- QStringList verbs {
- "guiMetadataSubscribe",
- "guiMetadataPublish",
- "phonecontrolSubscribe",
- "phonecontrolPublish",
- "navigationSubscribe",
- "navigationPublish",
- "playbackControllerSubscribe",
- "playbackControllerPublish",
- };
- QStringList events {
- "voice_authstate_event",
- "voice_dialogstate_event",
- "voice_connectionstate_event",
- };
-};
-
-/* We shouldnt access an agent directly, but CBL events
- * are not abstracted/forwarded by vshl bindings.
- */
-class AlexaVoiceMessage : public VoiceMessage
-{
- Q_OBJECT
- public:
- virtual ~AlexaVoiceMessage() {};
- bool isAuthStateEvent() const override {
- return (events.contains(this->eventName())); };
- bool isConnectionStateEvent() const override { return false; };
- bool isDialogStateEvent() const override { return false; };
- bool createRequest(QString verb, QJsonObject parameter) override;
-
- private:
- QStringList verbs {
- "subscribeToCBLEvents",
- };
- QStringList events {
"voice_cbl_codepair_received_event",
"voice_cbl_codepair_expired_event",
};
};
+
#endif // VOICE_MESSAGE_H