diff options
author | Scott Murray <scott.murray@konsulko.com> | 2021-12-16 15:07:44 -0500 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2021-12-16 16:03:51 -0500 |
commit | fad93b42c285ffb463e9494070f40d3b339d732f (patch) | |
tree | 6ae60914c578bd34b8ebbde9b271859e8b87ab65 /voice | |
parent | fe20f1b029f67dee1f790ade7a9114086f2abd38 (diff) |
Initial rework to replace app framework usage
Changes:
- Remove "core" code related to WebSocket messaging for the app
framework.
- Stub out hvac, navigation, network, and weather interfaces. This
allows building several of the demo applications without modification
for now. The network interface will definitely be reused to plumb
in a new connman-glib library derived from the previous network
binding. The others may potentially be reused to plumb in other
new backend implementations.
- Update the Network interface object constructor arguments to add a
agent registration flag. This prepares for the connman-glib
switch and means users will not need to be updated twice.
- Update the Bluetooth interface to use a new bluez-glib library that
is derived from the previous Bluetooth binding. This has been
successfully tested with a the Settings application.
- Remove signal-composer and voice API interface code as there are no
direct replacements planned. The signal-composer interface was
effectively exposing the binding events, so has little reuse
potential with a new backend. For the voice interface, if some form
of Alexa support becomes desirable, it can potentially be brought
back for adaptation if required.
- Disable compilation of the remaining interfaces for now. Some like
map, pbap, and mediaplayer are very likely to be used as the basis
for updating their associated applications, so keeping the code for
the planned iterative development seems easier.
- Updated copyright lines in all touched files.
Bug-AGL: SPEC-4182
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: Ib717ac8ac68ec457eaee74755dcf9d4f36b79d12
Diffstat (limited to 'voice')
-rw-r--r-- | voice/CMakeLists.txt | 22 | ||||
-rw-r--r-- | voice/qtappfw-voice.pc.in | 12 | ||||
-rw-r--r-- | voice/voice.cpp | 210 | ||||
-rw-r--r-- | voice/voice.h | 71 | ||||
-rw-r--r-- | voice/voiceagentmodel.cpp | 223 | ||||
-rw-r--r-- | voice/voiceagentmodel.h | 66 | ||||
-rw-r--r-- | voice/voiceagentprofile.cpp | 142 | ||||
-rw-r--r-- | voice/voiceagentprofile.h | 78 | ||||
-rw-r--r-- | voice/voiceagentregistry.cpp | 148 | ||||
-rw-r--r-- | voice/voiceagentregistry.h | 78 |
10 files changed, 0 insertions, 1050 deletions
diff --git a/voice/CMakeLists.txt b/voice/CMakeLists.txt deleted file mode 100644 index 3de0586..0000000 --- a/voice/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ - -CONFIGURE_FILE("qtappfw-voice.pc.in" "qtappfw-voice.pc" @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-voice.pc - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) - -add_library(qtappfw-voice SHARED voice.cpp - voiceagentregistry.cpp - voiceagentprofile.cpp - voiceagentmodel.cpp) - -target_include_directories(qtappfw-voice PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") -target_include_directories(qtappfw-voice PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") - -target_link_libraries(qtappfw-voice qtappfw-core) -set_target_properties(qtappfw-voice PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION 1 - PUBLIC_HEADER "voice.h;voiceagentregistry.h;voiceagentprofile.h;voiceagentmodel.h") - -install(TARGETS qtappfw-voice - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-voice) diff --git a/voice/qtappfw-voice.pc.in b/voice/qtappfw-voice.pc.in deleted file mode 100644 index ebc5276..0000000 --- a/voice/qtappfw-voice.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -prefix=@DEST_DIR@ -exec_prefix=${prefix} -libdir=${prefix}/lib -includedir=${prefix}/include - -Name: qtappfw-voice -Description: Library wrapping AGL AppFW voice data in Qt objects -Version: 1.0.0 - -Requires: Qt5Qml -Libs: -L${libdir} -lqtappfw-voice -Cflags: -I${includedir}/qtappfw-voice diff --git a/voice/voice.cpp b/voice/voice.cpp deleted file mode 100644 index 396984a..0000000 --- a/voice/voice.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) 2019, 2020 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <QDebug> -#include <QStringList> - -#include "callmessage.h" -#include "responsemessage.h" -#include "eventmessage.h" -#include "messagefactory.h" -#include "messageengine.h" -#include "messageenginefactory.h" -#include "voiceagentregistry.h" -#include "voice.h" - -Voice::Voice (QUrl &url, QQmlContext *context, QObject *parent) : - QObject(parent) -{ - m_loop = MessageEngineFactory::getInstance().getMessageEngine(url); - m_var = new VoiceAgentRegistry(this, context, parent); - - QObject::connect(m_loop.get(), &MessageEngine::connected, - this, &Voice::onConnected); - QObject::connect(m_loop.get(), &MessageEngine::disconnected, - this, &Voice::onDisconnected); - QObject::connect(m_loop.get(), &MessageEngine::messageReceived, - this, &Voice::onMessageReceived); -} - -Voice::~Voice() -{ - delete m_var; -} - -void Voice::scan() -{ - std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call); - if (!msg) - return; - - CallMessage *vmsg = static_cast<CallMessage*>(msg.get()); - QJsonObject parameter; - - vmsg->createRequest("vshl-core", "enumerateVoiceAgents", parameter); - m_loop->sendMessage(std::move(msg)); -} - -void Voice::getCBLpair(QString id) -{ - triggerCBLProcess(id); -} - -void Voice::subscribeAgentToVshlEvents(QString id) -{ - std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call); - if (!msg) - return; - - CallMessage *vmsg = static_cast<CallMessage*>(msg.get()); - QJsonArray events = QJsonArray::fromStringList(vshl_events); - QJsonObject parameter; - - parameter.insert("va_id", id); - parameter.insert("events", events); - vmsg->createRequest("vshl-core", "subscribe", parameter); - m_loop->sendMessage(std::move(msg)); -} - -void Voice::unsubscribeAgentFromVshlEvents(QString id) -{ - std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call); - if (!msg) - return; - - CallMessage *vmsg = static_cast<CallMessage*>(msg.get()); - QJsonArray events = QJsonArray::fromStringList(vshl_events); - QJsonObject parameter; - - parameter.insert("va_id", id); - parameter.insert("events", events); - vmsg->createRequest("vshl-core", "unsubscribe", parameter); - m_loop->sendMessage(std::move(msg)); -} - -void Voice::triggerCBLProcess(QString id) -{ - std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call); - if (!msg) - return; - - CallMessage *vmsg = static_cast<CallMessage*>(msg.get()); - QJsonArray events; - QJsonObject parameter; - - parameter.insert("va_id", id); - parameter.insert("events", events); - vmsg->createRequest("vshl-core", "subscribeToLoginEvents", parameter); - m_loop->sendMessage(std::move(msg)); -} - -void Voice::parseAgentsList(QJsonArray agents) -{ - for (auto value : agents) { - QJsonObject a = value.toObject(); - QString id = m_var->addAgent(a); - subscribeAgentToVshlEvents(id); - } -} - - - -void Voice::processEvent(std::shared_ptr<Message> msg) -{ - std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg); - QString eapi = emsg->eventApi(); - - if (eapi != "vshl-core") - return; - - QString ename = emsg->eventName(); - QJsonObject data = emsg->eventData(); - QString agentId = data.value("va_id").toString(); - QString state = data.value("state").toString(); - - if (ename.contains("voice_authstate_event")) { - m_var->setAuthState( - agentId, - static_cast<VoiceAgentRegistry::ServiceAuthState>( - m_var->stringToEnum(state, "ServiceAuthState"))); - - return; - } - else if (ename.contains("voice_connectionstate_event")) { - m_var->setConnectionState( - agentId, - static_cast<VoiceAgentRegistry::AgentConnectionState>( - m_var->stringToEnum(state, "AgentConnectionState"))); - return; - } - else if (ename.contains("voice_dialogstate_event")) { - m_var->setDialogState( - agentId, - static_cast<VoiceAgentRegistry::VoiceDialogState>( - m_var->stringToEnum(state, "VoiceDialogState"))); - return; - } - else if (ename.contains("cbl")) { - QJsonObject payload = data.value("payload").toObject(); - QString url = payload.value("url").toString(); - QString code = payload.value("code").toString(); - if (ename.contains("expired")) - m_var->updateLoginData(agentId, code, url, true); - else if (ename.contains("received")) { - m_var->updateLoginData(agentId, code, url, false); - } else - qWarning() << "Unknown cbl event"; - return; - } - - qWarning() << "Unknown vshl event:" << ename; -} - -void Voice::processReply(std::shared_ptr<Message> msg) -{ - std::shared_ptr<ResponseMessage> rmsg = std::static_pointer_cast<ResponseMessage>(msg); - QString verb = rmsg->requestVerb(); - QJsonObject data = rmsg->replyData(); - if (rmsg->replyStatus() == "failed") { - qWarning() << "Reply Failed received for verb:" << verb; - } else if (verb == "enumerateVoiceAgents") { - parseAgentsList(data.value("agents").toArray()); - m_var->setDefaultId(data.value("default").toString()); - } else - qDebug() << "discarding reply received for verb:" << verb; -} - -void Voice::onConnected() -{ - scan(); -} - -void Voice::onDisconnected() -{ - QStringList mvarlist = m_var->getAgentsListById(); - QStringList::iterator it; - for (it = mvarlist.begin(); it != mvarlist.end(); ++it) - unsubscribeAgentFromVshlEvents(*it); -} - -void Voice::onMessageReceived(std::shared_ptr<Message> msg) -{ - if (msg->isEvent()) { - processEvent(msg); - } else if (msg->isReply()) { - processReply(msg); - } else - qWarning() << "Received invalid inbound message"; -} diff --git a/voice/voice.h b/voice/voice.h deleted file mode 100644 index 2dc38c3..0000000 --- a/voice/voice.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2019, 2020 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VOICE_H -#define VOICE_H - -#include <memory> -#include <QObject> -#include <QJsonArray> -#include <QtQml/QQmlContext> - -class VoiceAgentRegistry; -class MessageEngine; -class Message; - -class Voice : public QObject -{ - Q_OBJECT - - public: - explicit Voice(QUrl &url, QQmlContext *context, - QObject * parent = Q_NULLPTR); - virtual ~Voice(); - - //enumerate agents: - Q_INVOKABLE void scan(); - //obtain code based login params: - Q_INVOKABLE void getCBLpair(QString id); - - private: - std::shared_ptr<MessageEngine> m_loop; - VoiceAgentRegistry *m_var; - - void subscribeAgentToVshlEvents(QString id); - void unsubscribeAgentFromVshlEvents(QString id); - void triggerCBLProcess(QString id); - void parseAgentsList(QJsonArray agents); - void processVshlEvent(std::shared_ptr<Message> msg); - void processLoginEvent(std::shared_ptr<Message> msg); - - void processEvent(std::shared_ptr<Message> emsg); - void processReply(std::shared_ptr<Message> rmsg); - - // slots - void onConnected(); - void onDisconnected(); - void onMessageReceived(std::shared_ptr<Message> msg); - - const QStringList vshl_events { - "voice_authstate_event", - "voice_dialogstate_event", - "voice_connectionstate_event", - "voice_cbl_codepair_received_event", - "voice_cbl_codepair_expired_event", - }; -}; - -#endif // VOICE_H diff --git a/voice/voiceagentmodel.cpp b/voice/voiceagentmodel.cpp deleted file mode 100644 index 90ddf01..0000000 --- a/voice/voiceagentmodel.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (C) 2019 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "voiceagentmodel.h" -#include "voiceagentprofile.h" -#include <QVector> -#include <QDebug> - -VoiceAgentModel::VoiceAgentModel(QObject *parent) - : QAbstractListModel(parent) -{ -} - -QVariant VoiceAgentModel::data(const QModelIndex &index, int role) const -{ - QVariant ret; - - if (!index.isValid()) - return ret; - - if (index.row() < 0 || index.row() >= m_agents.count()) - return ret; - - const VoiceAgentProfile *vap = m_agents[index.row()]; - switch (role) { - case IdRole: - return vap->vaid(); - case NameRole: - return vap->name(); - case WuwRole: - return vap->activewuw(); - case AuthStateRole: - return vap->authstate(); - case ConnStateRole: - return vap->connstate(); - case DialogStateRole: - return vap->dialogstate(); - case LoginParamsRole: - return readLoginParams(index); - case ActiveRole: - return vap->isactive()? "active" : "inactive"; - case VendorRole: - return vap->vendor(); - } - return ret; -} - -int VoiceAgentModel::rowCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return m_agents.count(); -} - -QVariantList VoiceAgentModel::readLoginParams(const QModelIndex &index) const -{ - QVariantList ret; - - if (!index.isValid()) - return ret; - - if (index.row() < 0 || index.row() >= this->m_agents.count()) - return ret; - - const VoiceAgentProfile *vap = this->m_agents[index.row()]; - ret.append(vap->logincode()); - ret.append(vap->loginurl()); - ret.append(vap->isloginpairexpired()? "expired" : "valid"); - return ret; -} - -void VoiceAgentModel::addAgent(VoiceAgentProfile *vap) -{ - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_agents.insert(rowCount(), vap); - endInsertRows(); -} - -void VoiceAgentModel::removeAgent(VoiceAgentProfile *vap) -{ - if (m_agents.isEmpty()) - return; - - int row = m_agents.indexOf(vap); - beginRemoveRows(QModelIndex(), row, row); - m_agents.removeAt(row); - endRemoveRows(); - delete vap; -} - -void VoiceAgentModel::removeAll() -{ - if (m_agents.isEmpty()) - return; - - beginRemoveRows(QModelIndex(), 0, m_agents.count() -1); - qDeleteAll(m_agents.begin(), m_agents.end()); - endRemoveRows(); - m_agents.clear(); -} - -bool VoiceAgentModel::agentExists(QString name, QString id, QString api) const -{ - VoiceAgentProfile *vap = getAgentFromName(name); - if (!vap) - return false; - bool sameid = id == vap->vaid(); - bool sameapi = api == vap->vaapi(); - return sameapi && (sameid || id != "UNKNOWN"); -} - -VoiceAgentProfile* VoiceAgentModel::getAgentFromName(QString name) const -{ - if (m_agents.isEmpty()) - return nullptr; - - for (auto agent : m_agents) { - if (agent->name() == name) - return agent; - } - return nullptr; -} - -VoiceAgentProfile* VoiceAgentModel::getAgentFromId(QString id) const -{ - if (m_agents.isEmpty()) - return nullptr; - - for (auto agent : m_agents) { - if (agent->vaid() == id) - return agent; - } - return nullptr; -} - -void VoiceAgentModel::updateAgentProperties(QString name, QString id, QString api, - bool active, QString wuw) -{ - QVector<int> vroles; - VoiceAgentProfile *vap = getAgentFromName(name); - if (!vap) { - qWarning() << "Unknown agent"; - return; - } - if ((vap->vaapi() == api) && (vap->vaid() != id) && (id != "UNKNOWN")) { - vap->setVaid(id); - vroles.push_back(IdRole); - } - vap->setActive(active); - vroles.push_back(ActiveRole); - if (!wuw.isEmpty()) { - vap->setWuw(wuw); - 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); -} - -QModelIndex VoiceAgentModel::indexOf(VoiceAgentProfile *vap) -{ - int row = m_agents.indexOf(vap); - return index(row); -} - -QHash<int, QByteArray> VoiceAgentModel::roleNames() const -{ - QHash<int, QByteArray> roles; - roles[NameRole] = "name"; - roles[IdRole] = "id"; - roles[WuwRole] = "wuw"; - roles[AuthStateRole] = "authstate"; - roles[ConnStateRole] = "connstate"; - roles[DialogStateRole] = "dialogstate"; - roles[LoginParamsRole] = "usrauth"; - roles[ActiveRole] = "active"; - roles[VendorRole] = "vendor"; - return roles; -} diff --git a/voice/voiceagentmodel.h b/voice/voiceagentmodel.h deleted file mode 100644 index 0be9637..0000000 --- a/voice/voiceagentmodel.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2019 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VOICEAGENTMODEL_H -#define VOICEAGENTMODEL_H - -#include <QAbstractListModel> -#include <QStringList> -#include <QtQml/QQmlContext> -#include <QJsonObject> - -#include "voiceagentprofile.h" - -class VoiceAgentModel : public QAbstractListModel -{ - Q_OBJECT - - public: - enum VoiceAgentRoles { - IdRole = Qt::UserRole + 1, - NameRole, - WuwRole, - AuthStateRole, - ConnStateRole, - DialogStateRole, - LoginParamsRole, - ActiveRole, - VendorRole, - }; - - VoiceAgentModel(QObject *parent = Q_NULLPTR); - - QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - QVariantList readLoginParams(const QModelIndex &index) const; - void addAgent(VoiceAgentProfile *vap); - void removeAgent(VoiceAgentProfile* vap); - void removeAll(); - bool agentExists(QString name, QString id, QString api) const; - VoiceAgentProfile *getAgentFromName(QString name) const; - 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; - QModelIndex indexOf(VoiceAgentProfile *agent); - QHash<int, QByteArray> roleNames() const; -}; -#endif // VOICEAGENTMODEL_H diff --git a/voice/voiceagentprofile.cpp b/voice/voiceagentprofile.cpp deleted file mode 100644 index 43d8b34..0000000 --- a/voice/voiceagentprofile.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 2019 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "voiceagentprofile.h" - -VoiceAgentProfile::VoiceAgentProfile(const QString &name, - const QString &id, - const QString &api, - bool active, - const QString &wuw, - const QString &vendor, - const QString &wuws) - : m_name(name), m_vaid(id), m_vaapi(api), m_active(active), - m_activewuw(wuw), m_vendor(vendor), m_wuws(wuws), - m_authstate("UNINITIALIZED"), m_connstate("DISCONNECTED"), - m_dialogstate("MICROPHONEOFF"), m_logincode(QString()), - m_loginurl(QString()), m_expired(true) -{ -} - -QString VoiceAgentProfile::name() const -{ - return m_name; -} - -QString VoiceAgentProfile::vaid() const -{ - return m_vaid; -} - -QString VoiceAgentProfile::vaapi() const -{ - return m_vaapi; -} - -bool VoiceAgentProfile::isactive() const -{ - return m_active; -} - -QString VoiceAgentProfile::activewuw() const -{ - return m_activewuw; -} - -QString VoiceAgentProfile::vendor() const -{ - return m_vendor; -} - -QString VoiceAgentProfile::wuws() const -{ - return m_wuws; -} - -QString VoiceAgentProfile::authstate() const -{ - return m_authstate; -} - -QString VoiceAgentProfile::connstate() const -{ - return m_connstate; -} - -QString VoiceAgentProfile::dialogstate() const -{ - return m_dialogstate; -} - -QString VoiceAgentProfile::logincode() const -{ - return m_logincode; -} - -QString VoiceAgentProfile::loginurl() const -{ - return m_loginurl; -} - -bool VoiceAgentProfile::isloginpairexpired() const -{ - return m_expired; -} - -void VoiceAgentProfile::setVaid(const QString id) -{ - m_vaid = id; -} - -void VoiceAgentProfile::setActive(bool active) -{ - m_active = active; -} - -void VoiceAgentProfile::setAuthState(const QString state) -{ - m_authstate = state; -} - -void VoiceAgentProfile::setConnState(const QString state) -{ - m_connstate = state; -} - -void VoiceAgentProfile::setDialogState(const QString state) -{ - m_dialogstate = state; -} - -void VoiceAgentProfile::setLoginCode(const QString usrcode) -{ - m_logincode = usrcode; -} - -void VoiceAgentProfile::setLoginUrl(const QString usrurl) -{ - m_loginurl = usrurl; -} - -void VoiceAgentProfile::setLoginPairExpired(bool expired) -{ - m_expired = expired; -} - -void VoiceAgentProfile::setWuw(const QString newwuw) -{ - m_activewuw = newwuw; -} diff --git a/voice/voiceagentprofile.h b/voice/voiceagentprofile.h deleted file mode 100644 index dda96c5..0000000 --- a/voice/voiceagentprofile.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2019 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VOICEAGENTPROFILE_H -#define VOICEAGENTPROFILE_H - -#include <QString> - -class VoiceAgentProfile -{ - public: - VoiceAgentProfile(const QString &name, - const QString &id, - const QString &api, - bool active, - const QString &wuw, - const QString &vendor, - const QString &wuws); - - QString name() const; - QString vaid() const; - QString vaapi() const; - bool isactive() const; - QString activewuw() const; - QString vendor() const; - QString wuws() const; - QString authstate() const; - QString connstate() const; - QString dialogstate() const; - QString logincode() const; - QString loginurl() const; - bool isloginpairexpired() const; - - void setVaid(const QString newid); - void setActive(bool activemode); - void setAuthState(const QString newauthstate); - void setConnState(const QString newconnstate); - void setDialogState(const QString newdialogstate); - void setLoginCode(const QString newtoken); - void setLoginUrl(const QString newurl); - void setLoginPairExpired(bool expired); - void setWuw(const QString newwuw); - - bool operator==(const VoiceAgentProfile& rhs) { - return (m_name == rhs.name() && - m_vaid == rhs.vaid() && - m_vaapi == rhs.vaapi()); }; - - private: - QString m_name; - QString m_vaid; - QString m_vaapi; - bool m_active; - QString m_activewuw; - QString m_vendor; - QString m_wuws; - QString m_authstate; - QString m_connstate; - QString m_dialogstate; - QString m_logincode; - QString m_loginurl; - bool m_expired; -}; - -#endif // VOICEAGENTPROFILE_H diff --git a/voice/voiceagentregistry.cpp b/voice/voiceagentregistry.cpp deleted file mode 100644 index 00eed87..0000000 --- a/voice/voiceagentregistry.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2019 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <QMetaEnum> -#include <QSortFilterProxyModel> -#include <QtQml/QQmlEngine> - -#include "voice.h" -#include "voiceagentregistry.h" -#include "voiceagentmodel.h" -#include "voiceagentprofile.h" - -VoiceAgentRegistry::VoiceAgentRegistry(Voice *voice, QQmlContext *context, QObject *parent) : - QObject(parent), - m_model(nullptr), - vc(voice) -{ - m_model = new VoiceAgentModel(); - context->setContextProperty("VoiceAgentModel", m_model); - context->setContextProperty("VoiceAgent", this); -} - -VoiceAgentRegistry::~VoiceAgentRegistry() -{ - delete m_model; -} - -QString VoiceAgentRegistry::addAgent(QJsonObject va) -{ - bool active = va.value("active").toBool(); - QString wuw = va.value("activewakeword").toString(); - QString api = va.value("api").toString(); - QString desc = va.value("description").toString(); - QString id = va.value("id").toString(); - QString name = va.value("name").toString(); - QString vendor = va.value("vendor").toString(); - QString wuws = va.value("wakewords").toString(); - - if (!m_model->agentExists(name, id, api)) { - VoiceAgentProfile *vap = new VoiceAgentProfile(name, id, api, - active, wuw, - vendor, wuws); - m_model->addAgent(vap); - m_regids.append(id); - } - else - m_model->updateAgentProperties(name, id, api, active, wuw); - return id; -} - -bool VoiceAgentRegistry::removeAgent(QString id) -{ - VoiceAgentProfile *vap = m_model->getAgentFromId(id); - if (!vap) - return false; - m_model->removeAgent(vap); - return true; -} - -void VoiceAgentRegistry::clearRegistry() -{ - m_default_aid.clear(); - m_regids.clear(); - m_model->removeAll(); -} - -QStringList VoiceAgentRegistry::getAgentsListById() const -{ - return m_regids; -} - -QString VoiceAgentRegistry::getDefaultId() const -{ - return m_default_aid.isEmpty()? "UNKNOWN" : m_default_aid; -} -void VoiceAgentRegistry::setDefaultId(QString id) -{ - m_default_aid = id; -} - -void VoiceAgentRegistry::setAuthState(QString id, ServiceAuthState state) -{ - QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::ServiceAuthState>(); - auto stateStr = metaEnum.valueToKey(state); - VoiceAgentProfile *vap = m_model->getAgentFromId(id); - if (vap) { - vap->setAuthState(stateStr); - m_model->updateAgentState(id); - } -} - -void VoiceAgentRegistry::setConnectionState(QString id, AgentConnectionState state) -{ - QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::AgentConnectionState>(); - auto stateStr = metaEnum.valueToKey(state); - - VoiceAgentProfile *vap = m_model->getAgentFromId(id); - if (vap) { - vap->setConnState(stateStr); - m_model->updateAgentState(id); - } -} - -void VoiceAgentRegistry::setDialogState(QString id, VoiceDialogState state) -{ - QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::VoiceDialogState>(); - auto stateStr = metaEnum.valueToKey(state); - - VoiceAgentProfile *vap = m_model->getAgentFromId(id); - if (vap) { - vap->setDialogState(stateStr); - m_model->updateAgentState(id); - } -} - -void VoiceAgentRegistry::updateLoginData(QString id, QString code, QString url, - bool expired) -{ - VoiceAgentProfile *vap = m_model->getAgentFromId(id); - if (vap) { - 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().constData()); - QMetaEnum metaEnum = metaObject->enumerator(enumIndex); - int value = metaEnum.keyToValue(key.toUtf8().constData()); - return (value < 0)? 0 : value; -} diff --git a/voice/voiceagentregistry.h b/voice/voiceagentregistry.h deleted file mode 100644 index e0a48c5..0000000 --- a/voice/voiceagentregistry.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2019 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VOICEAGENTREGISTRY_H -#define VOICEAGENTREGISTRY_H - -#include <QDebug> -#include <QObject> -#include <QJsonArray> -#include <QtQml/QQmlContext> - -class Voice; -class VoiceAgentModel; - -class VoiceAgentRegistry : public QObject -{ - Q_OBJECT - public: - explicit VoiceAgentRegistry(Voice *voice, QQmlContext *context, - QObject *parent); - virtual ~VoiceAgentRegistry(); - - enum AgentConnectionState { - DISCONNECTED = 0, - CONNECTED, - }; - Q_ENUM(AgentConnectionState) - - enum VoiceDialogState { - IDLE = 0, - LISTENING, - THINKING, - SPEAKING, - MICROPHONEOFF, - }; - Q_ENUM(VoiceDialogState) - - enum ServiceAuthState { - UNINITIALIZED = 0, - REFRESHED, - EXPIRED, - UNRECOVERABLE_ERROR - }; - Q_ENUM(ServiceAuthState) - - QString addAgent(QJsonObject va); - bool removeAgent(QString id); - void clearRegistry(); - QStringList getAgentsListById() const; - QString getDefaultId() const; - void setDefaultId(QString id); - void setAuthState(QString id, ServiceAuthState state); - void setConnectionState(QString id, AgentConnectionState state); - void setDialogState(QString id, VoiceDialogState state); - void updateLoginData(QString id, QString code, QString url, - bool expired); - int stringToEnum(QString value, QString enumtype); - private: - VoiceAgentModel *m_model; - Voice *vc; - QString m_default_aid; - QStringList m_regids; -}; - -#endif // VOICEAGENTREGISTRY_H |