summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--message.cpp8
-rw-r--r--messageengine.cpp1
-rw-r--r--voice/voice.cpp122
-rw-r--r--voice/voiceagentmodel.cpp35
-rw-r--r--voice/voiceagentmodel.h2
-rw-r--r--voice/voiceagentregistry.cpp33
-rw-r--r--voice/voiceagentregistry.h2
7 files changed, 113 insertions, 90 deletions
diff --git a/message.cpp b/message.cpp
index 3cd4bb9..e4cd191 100644
--- a/message.cpp
+++ b/message.cpp
@@ -114,7 +114,13 @@ bool Message::fromJDoc(QJsonDocument jdoc)
} else if (msgid == Event) {
// If event, save data object
auto data_iter = payload.find("data");
- m_event_data = data_iter.value().toObject();
+ auto data = data_iter.value().toObject();
+ auto data_string = data_iter.value().toString();
+ if (!data_string.isEmpty())
+ data_string.remove('\n');
+
+ QJsonDocument datadoc = QJsonDocument::fromJson(data_string.toUtf8());
+ m_event_data = datadoc.object();
auto event_iter = payload.find("event");
auto event_string = event_iter.value().toString();
diff --git a/messageengine.cpp b/messageengine.cpp
index d4413e5..d2644e8 100644
--- a/messageengine.cpp
+++ b/messageengine.cpp
@@ -85,6 +85,7 @@ void MessageEngine::onDisconnected()
void MessageEngine::onTextMessageReceived(QString jsonStr)
{
+ jsonStr = jsonStr.simplified();
QJsonDocument jdoc(QJsonDocument::fromJson(jsonStr.toUtf8()));
if (jdoc.isEmpty()) {
qWarning() << "Received invalid JSON: empty appfw message";
diff --git a/voice/voice.cpp b/voice/voice.cpp
index f200b95..40349d1 100644
--- a/voice/voice.cpp
+++ b/voice/voice.cpp
@@ -106,87 +106,59 @@ void Voice::parseAgentsList(QJsonArray agents)
}
}
-void Voice::processVshlEvent(VoiceMessage *vmsg)
-{
- const QString str = vmsg->eventName();
- const QJsonObject obj = vmsg->eventData();
- QStringList strlist;
-
- if (str.contains('#'))
- 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();
- 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();
- 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();
- if (!dialogstate.isEmpty())
- m_var->setDialogState(
- agentId,
- static_cast<VoiceAgentRegistry::VoiceDialogState>(
- m_var->stringToEnum(dialogstate, "VoiceDialogState")));
- } else
- processLoginEvent(vmsg);
-}
-void Voice::processLoginEvent(VoiceMessage *vmsg)
+
+void Voice::processEvent(VoiceMessage *vmsg)
{
const QString str = vmsg->eventName();
- const QJsonObject obj = vmsg->eventData();
+ QJsonObject data = vmsg->eventData();
+ QString agentId = data.value("va_id").toString();
+ QString state = data.value("state").toString();
+
+ if (vmsg->isAuthStateEvent()) {
+ m_var->setAuthState(
+ agentId,
+ static_cast<VoiceAgentRegistry::ServiceAuthState>(
+ m_var->stringToEnum(state, "ServiceAuthState")));
- if (obj.isEmpty()) {
- qWarning() << "no data for event:" << str;
+ return;
+ }
+ else if (vmsg->isConnectionStateEvent()) {
+ m_var->setConnectionState(
+ agentId,
+ static_cast<VoiceAgentRegistry::AgentConnectionState>(
+ m_var->stringToEnum(state, "AgentConnectionState")));
+ return;
+ }
+ else if (vmsg->isDialogStateEvent()) {
+ m_var->setDialogState(
+ agentId,
+ static_cast<VoiceAgentRegistry::VoiceDialogState>(
+ m_var->stringToEnum(state, "VoiceDialogState")));
+ return;
+ }
+ else if (vmsg->isCblEvent()) {
+ auto payload_iter = data.find("payload");
+ if (payload_iter == data.end())
+ qWarning() << "no top-level payload field in event";
+ auto payload_stringval = payload_iter.value().toString();
+ if (!payload_stringval.isEmpty())
+ payload_stringval.remove('\n');
+ QJsonDocument infodoc = QJsonDocument::fromJson(payload_stringval.toUtf8());
+ QJsonObject info = infodoc.object();
+ QJsonObject properties = info.value("payload").toObject();
+ QString url = properties.value("url").toString();
+ QString code = properties.value("code").toString();
+ if (str.contains("expired"))
+ m_var->updateLoginData(agentId, code, url, true);
+ else if (str.contains("received")) {
+ m_var->updateLoginData(agentId, code, url, false);
+ } else
+ qWarning() << "unknown cbl event";
return;
}
- QStringList strlist;
- if (str.contains('#'))
- strlist = str.split('#');
- 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 event:" << str;
-}
-
-void Voice::processEvent(VoiceMessage *vmsg)
-{
- const QString api = vmsg->eventApi();
- if (api == "vshl-core")
- processVshlEvent(vmsg);
- else
- qWarning() << "Unknown api:" << api;
+ qWarning() << "Unknown vshl event:" << str;
}
void Voice::processReply(ResponseMessage *rmsg)
@@ -198,7 +170,7 @@ void Voice::processReply(ResponseMessage *rmsg)
m_var->setDefaultId(
rmsg->replyData().value("default").toString());
} else
- qWarning() << "success reply received for verb:" <<
+ qWarning() << "discarding reply received for verb:" <<
rmsg->requestVerb();
}
diff --git a/voice/voiceagentmodel.cpp b/voice/voiceagentmodel.cpp
index e0f9bfb..3f4f50d 100644
--- a/voice/voiceagentmodel.cpp
+++ b/voice/voiceagentmodel.cpp
@@ -73,8 +73,8 @@ QVariantList VoiceAgentModel::readLoginParams(const QModelIndex &index) const
return ret;
const VoiceAgentProfile *vap = this->m_agents[index.row()];
- ret.append(vap->loginurl());
ret.append(vap->logincode());
+ ret.append(vap->loginurl());
ret.append(vap->isloginpairexpired()? "expired" : "valid");
return ret;
}
@@ -163,6 +163,39 @@ void VoiceAgentModel::updateAgentProperties(QString name, QString id, QString ap
vroles.push_back(WuwRole);
}
if (!vroles.isEmpty())
+ emit dataChanged(indexOf(vap), indexOf(vap), vroles);
+}
+
+void VoiceAgentModel::updateAgentState(QString id)
+{
+ QVector<int> vroles;
+ VoiceAgentProfile *vap = getAgentFromId(id);
+
+ if (!vap) {
+ qWarning() << "Unknown agent";
+ return;
+ }
+
+ vroles.push_back(AuthStateRole);
+ vroles.push_back(ConnStateRole);
+ vroles.push_back(DialogStateRole);
+
+ if (!vroles.isEmpty())
+ emit dataChanged(indexOf(vap), indexOf(vap), vroles);
+}
+
+void VoiceAgentModel::updateAgentLoginData(QString id)
+{
+ QVector<int> vroles;
+ VoiceAgentProfile *vap = getAgentFromId(id);
+
+ if (!vap) {
+ qWarning() << "Unknown agent";
+ return;
+ }
+
+ vroles.push_back(LoginParamsRole);
+ if (!vroles.isEmpty())
emit dataChanged(indexOf(vap), indexOf(vap), vroles);
}
diff --git a/voice/voiceagentmodel.h b/voice/voiceagentmodel.h
index 30d295b..3cd84e6 100644
--- a/voice/voiceagentmodel.h
+++ b/voice/voiceagentmodel.h
@@ -54,6 +54,8 @@ class VoiceAgentModel : public QAbstractListModel
VoiceAgentProfile *getAgentFromId(QString id) const;
void updateAgentProperties(QString name, QString id,
QString api, bool active, QString wuw);
+ void updateAgentState(QString id);
+ void updateAgentLoginData(QString id);
private:
QList<VoiceAgentProfile *> m_agents;
diff --git a/voice/voiceagentregistry.cpp b/voice/voiceagentregistry.cpp
index bbd9857..62e8cd6 100644
--- a/voice/voiceagentregistry.cpp
+++ b/voice/voiceagentregistry.cpp
@@ -99,29 +99,37 @@ void VoiceAgentRegistry::setDefaultId(QString id)
void VoiceAgentRegistry::setAuthState(QString id, ServiceAuthState state)
{
- const auto stateStr =
- QMetaEnum::fromType<VoiceAgentRegistry::ServiceAuthState>().valueToKey(state);
+ QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::ServiceAuthState>();
+ auto stateStr = metaEnum.valueToKey(state);
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (vap)
+ if (vap) {
vap->setAuthState(stateStr);
+ m_model->updateAgentState(id);
+ }
}
void VoiceAgentRegistry::setConnectionState(QString id, AgentConnectionState state)
{
- const auto stateStr =
- QMetaEnum::fromType<VoiceAgentRegistry::AgentConnectionState>().valueToKey(state);
+ QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::AgentConnectionState>();
+ auto stateStr = metaEnum.valueToKey(state);
+
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (vap)
+ if (vap) {
vap->setConnState(stateStr);
+ m_model->updateAgentState(id);
+ }
}
void VoiceAgentRegistry::setDialogState(QString id, VoiceDialogState state)
{
- const auto stateStr =
- QMetaEnum::fromType<VoiceAgentRegistry::VoiceDialogState>().valueToKey(state);
+ QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::VoiceDialogState>();
+ auto stateStr = metaEnum.valueToKey(state);
+
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (vap)
+ if (vap) {
vap->setDialogState(stateStr);
+ m_model->updateAgentState(id);
+ }
}
void VoiceAgentRegistry::updateLoginData(QString id, QString code, QString url,
@@ -129,17 +137,18 @@ void VoiceAgentRegistry::updateLoginData(QString id, QString code, QString url,
{
VoiceAgentProfile *vap = m_model->getAgentFromId(id);
if (vap) {
- vap->setLoginCode(code);
+ vap->setLoginCode(url);
vap->setLoginUrl(code);
vap->setLoginPairExpired(expired);
+ m_model->updateAgentLoginData(id);
};
}
int VoiceAgentRegistry::stringToEnum(const QString key, const QString enumtype)
{
const QMetaObject *metaObject = VoiceAgentRegistry::metaObject();
- int enumIndex = metaObject->indexOfEnumerator(enumtype.toUtf8().data());
+ int enumIndex = metaObject->indexOfEnumerator(enumtype.toUtf8().constData());
QMetaEnum metaEnum = metaObject->enumerator(enumIndex);
- int value = metaEnum.keyToValue(key.toUtf8().data());
+ int value = metaEnum.keyToValue(key.toUtf8().constData());
return (value < 0)? 0 : value;
}
diff --git a/voice/voiceagentregistry.h b/voice/voiceagentregistry.h
index 4394017..cd7dc2c 100644
--- a/voice/voiceagentregistry.h
+++ b/voice/voiceagentregistry.h
@@ -49,7 +49,7 @@ class VoiceAgentRegistry : public QObject
Q_ENUM(VoiceDialogState)
enum ServiceAuthState {
- UNITIALIZED = 0,
+ UNINITIALIZED = 0,
REFRESHED,
};
Q_ENUM(ServiceAuthState)