From 00fa3eefa5f961ac60d9ae6bc6d732cccbce76db Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 17 Oct 2019 03:49:38 -0700 Subject: libqtappfw: add initial navigation support Add initial navigation service support in qtappfw for new agl-service-navigation rewrite. Bug-AGL: SPEC-2880 Change-Id: I276de006af3c1e19e669ae3b9d05c92360893467 Signed-off-by: Matt Ranostay (cherry picked from commit af3cbe937762dbf196e0ea5b26f0cb2a088ab599) --- CMakeLists.txt | 1 + message.h | 1 + messageengine.cpp | 4 ++ navigation/CMakeLists.txt | 2 + navigation/navigation.cpp | 150 +++++++++++++++++++++++++++++++++++++++ navigation/navigation.h | 65 +++++++++++++++++ navigation/navigationmessage.cpp | 29 ++++++++ navigation/navigationmessage.h | 41 +++++++++++ 8 files changed, 293 insertions(+) create mode 100644 navigation/CMakeLists.txt create mode 100644 navigation/navigation.cpp create mode 100644 navigation/navigation.h create mode 100644 navigation/navigationmessage.cpp create mode 100644 navigation/navigationmessage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3509b85..d57f663 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ set (SUBDIRS bluetooth map mediaplayer + navigation network pbap radio diff --git a/message.h b/message.h index 2e731df..c39b107 100644 --- a/message.h +++ b/message.h @@ -41,6 +41,7 @@ enum MessageType { PbapEventMessage, RadioEventMessage, MapEventMessage, + NavigationEventMessage, }; class Message : public QObject diff --git a/messageengine.cpp b/messageengine.cpp index 9846519..d057d11 100644 --- a/messageengine.cpp +++ b/messageengine.cpp @@ -19,6 +19,7 @@ #include "bluetoothmessage.h" #include "mapmessage.h" #include "mediaplayermessage.h" +#include "navigationmessage.h" #include "networkmessage.h" #include "pbapmessage.h" #include "radiomessage.h" @@ -124,6 +125,9 @@ void MessageEngine::onTextMessageReceived(QString jsonStr) } else if (api == "mediaplayer") { message = new MediaplayerMessage; type = MediaplayerEventMessage; + } else if (api == "navigation") { + message = new NavigationMessage; + type = NavigationEventMessage; } else if (api == "network-manager") { message = new NetworkMessage; type = NetworkEventMessage; diff --git a/navigation/CMakeLists.txt b/navigation/CMakeLists.txt new file mode 100644 index 0000000..9bea511 --- /dev/null +++ b/navigation/CMakeLists.txt @@ -0,0 +1,2 @@ +add_headers(navigation.h navigationmessage.h) +add_sources(navigation.cpp navigationmessage.cpp) diff --git a/navigation/navigation.cpp b/navigation/navigation.cpp new file mode 100644 index 0000000..de98bea --- /dev/null +++ b/navigation/navigation.cpp @@ -0,0 +1,150 @@ +/* + * 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 "message.h" +#include "messageengine.h" +#include "navigation.h" +#include "navigationmessage.h" +#include "responsemessage.h" + +Navigation::Navigation (QUrl &url, QObject * parent) : + QObject(parent), + m_mloop(nullptr) +{ + m_mloop = new MessageEngine(url); + QObject::connect(m_mloop, &MessageEngine::connected, this, &Navigation::onConnected); + QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Navigation::onDisconnected); + QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Navigation::onMessageReceived); +} + +Navigation::~Navigation() +{ + delete m_mloop; +} + +void Navigation::sendWaypoint(double lat, double lon) +{ + NavigationMessage *nmsg = new NavigationMessage(); + QJsonObject parameter, point; + QJsonArray points; + point.insert("latitude", lat); + point.insert("longitude", lon); + points.append(point); + parameter.insert("points", points); + nmsg->createRequest("broadcast_waypoints", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; +} + +void Navigation::broadcastPosition(double lat, double lon, double drc, double dst) +{ + NavigationMessage *nmsg = new NavigationMessage(); + QJsonObject parameter; + + parameter.insert("position", "car"); + parameter.insert("latitude", lat); + parameter.insert("longitude", lon); + parameter.insert("direction", drc); + parameter.insert("distance", dst); + + nmsg->createRequest("broadcast_position", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; +} + +void Navigation::broadcastRouteInfo(double lat, double lon, double route_lat, double route_lon) +{ + NavigationMessage *nmsg = new NavigationMessage(); + QJsonObject parameter; + + parameter.insert("position", "route"); + parameter.insert("latitude", lat); + parameter.insert("longitude", lon); + parameter.insert("route_latitude", route_lat); + parameter.insert("route_longitude", route_lon); + + nmsg->createRequest("broadcast_position", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; +} + +void Navigation::broadcastStatus(QString state) +{ + NavigationMessage *nmsg = new NavigationMessage(); + QJsonObject parameter; + parameter.insert("state", state); + nmsg->createRequest("broadcast_status", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; +} + +void Navigation::broadcastWaypoints(QJsonObject waypoints) +{ + NavigationMessage *nmsg = new NavigationMessage(); + QJsonObject parameter; + nmsg->createRequest("broadcast_waypoints", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; +} + +void Navigation::onConnected() +{ + QStringListIterator eventIterator(events); + NavigationMessage *nmsg; + + while (eventIterator.hasNext()) { + nmsg = new NavigationMessage(); + QJsonObject parameter; + parameter.insert("value", eventIterator.next()); + nmsg->createRequest("subscribe", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; + } +} + +void Navigation::onDisconnected() +{ + QStringListIterator eventIterator(events); + NavigationMessage *nmsg; + + while (eventIterator.hasNext()) { + nmsg = new NavigationMessage(); + QJsonObject parameter; + parameter.insert("value", eventIterator.next()); + nmsg->createRequest("unsubscribe", parameter); + m_mloop->sendMessage(nmsg); + delete nmsg; + } +} + +void Navigation::onMessageReceived(MessageType type, Message *msg) +{ + if (type == NavigationEventMessage) { + NavigationMessage *tmsg = qobject_cast(msg); + + if (tmsg->isPositionEvent()) { + emit positionEvent(tmsg->eventData().toVariantMap()); + } + if (tmsg->isStatusEvent()) { + emit statusEvent(tmsg->eventData().toVariantMap()); + } + if (tmsg->isWaypointsEvent()) { + emit waypointsEvent(tmsg->eventData().toVariantMap()); + } + } + + msg->deleteLater(); +} diff --git a/navigation/navigation.h b/navigation/navigation.h new file mode 100644 index 0000000..09fae3f --- /dev/null +++ b/navigation/navigation.h @@ -0,0 +1,65 @@ + /* + * 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 NAVIGATION_H +#define NAVIGATION_H + +#include +#include +#include +#include + +#include "messageengine.h" +#include "navigationmessage.h" +#include "responsemessage.h" + +class Navigation : public QObject +{ + Q_OBJECT + + public: + explicit Navigation(QUrl &url, QObject * parent = Q_NULLPTR); + virtual ~Navigation(); + + Q_INVOKABLE void broadcastPosition(double lat, double lon, double drc, double dst); + Q_INVOKABLE void broadcastRouteInfo(double lat, double lon, double route_lat, double route_lon); + Q_INVOKABLE void broadcastStatus(QString state); + Q_INVOKABLE void broadcastWaypoints(QJsonObject waypoints); + + // only support one waypoint for now + Q_INVOKABLE void sendWaypoint(double lat, double lon); + + signals: + void statusEvent(QVariantMap data); + void positionEvent(QVariantMap data); + void waypointsEvent(QVariantMap data); + + private: + MessageEngine *m_mloop; + + // slots + void onMessageReceived(MessageType, Message*); + void onConnected(); + void onDisconnected(); + + const QStringList events { + "status", + "position", + "waypoints", + }; +}; + +#endif // NAVIGATION_H diff --git a/navigation/navigationmessage.cpp b/navigation/navigationmessage.cpp new file mode 100644 index 0000000..363f923 --- /dev/null +++ b/navigation/navigationmessage.cpp @@ -0,0 +1,29 @@ +/* + * 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 +#include +#include + +#include "navigationmessage.h" + +bool NavigationMessage::createRequest(QString verb, QJsonObject parameter) +{ + if (!verbs.contains(verb)) + return false; + + return Message::createRequest("navigation", verb, parameter); +} diff --git a/navigation/navigationmessage.h b/navigation/navigationmessage.h new file mode 100644 index 0000000..8594f51 --- /dev/null +++ b/navigation/navigationmessage.h @@ -0,0 +1,41 @@ +/* + * 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 NAVIGATION_MESSAGE_H +#define NAVIGATION_MESSAGE_H + +#include "message.h" + +class NavigationMessage : public Message +{ + Q_OBJECT + public: + bool createRequest(QString verb, QJsonObject parameter); + bool isStatusEvent() { return (this->eventName() == "status"); }; + bool isPositionEvent() { return (this->eventName() == "position"); }; + bool isWaypointsEvent() { return (this->eventName() == "waypoints"); }; + + private: + QStringList verbs { + "broadcast_status", + "broadcast_position", + "broadcast_waypoints", + "subscribe", + "unsubscribe", + }; +}; + +#endif // NAVIGATION_MESSAGE_H -- cgit 1.2.3-korg