summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2019-06-21 11:44:30 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2019-06-28 18:12:00 -0700
commit9d2600f4b4dcbdd3820910967eb00a9b00cd8a17 (patch)
treebb241920f70da4bfca1e05ea8fbb0a196f88036a
parentc7f1b2678189a81a41df3bdf422b5b290cac20f0 (diff)
libqtappfw: bluetooth-map: add initial map supporthalibut_7.99.3halibut/7.99.37.99.3
Add bluetooth-map service support for notifications and message composition. Bug-AGL: SPEC-2561 Change-Id: I956150b9db05334eb02640657c1fc7e03258ab41 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--map/CMakeLists.txt2
-rw-r--r--map/map.cpp80
-rw-r--r--map/map.h50
-rw-r--r--map/mapmessage.cpp29
-rw-r--r--map/mapmessage.h39
-rw-r--r--message.h1
-rw-r--r--messageengine.cpp4
8 files changed, 206 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a3c1fae..3509b85 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw.pc
set (SUBDIRS
bluetooth
+ map
mediaplayer
network
pbap
diff --git a/map/CMakeLists.txt b/map/CMakeLists.txt
new file mode 100644
index 0000000..2e58fbe
--- /dev/null
+++ b/map/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_headers(map.h mapmessage.h)
+add_sources(map.cpp mapmessage.cpp)
diff --git a/map/map.cpp b/map/map.cpp
new file mode 100644
index 0000000..eb3d5e0
--- /dev/null
+++ b/map/map.cpp
@@ -0,0 +1,80 @@
+/*
+ * 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 "map.h"
+#include "mapmessage.h"
+#include "responsemessage.h"
+
+Map::Map (QUrl &url, QObject * parent) :
+ QObject(parent),
+ m_mloop(nullptr)
+{
+ m_mloop = new MessageEngine(url);
+ QObject::connect(m_mloop, &MessageEngine::connected, this, &Map::onConnected);
+ QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Map::onDisconnected);
+ QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Map::onMessageReceived);
+}
+
+Map::~Map()
+{
+ delete m_mloop;
+}
+
+void Map::compose(QString recipient, QString message)
+{
+ MapMessage *tmsg = new MapMessage();
+ QJsonObject parameter;
+ parameter.insert("recipient", recipient);
+ parameter.insert("message", message);
+ tmsg->createRequest("compose", parameter);
+ m_mloop->sendMessage(tmsg);
+ delete tmsg;
+}
+
+void Map::onConnected()
+{
+ MapMessage *tmsg = new MapMessage();
+ QJsonObject parameter;
+ parameter.insert("value", "notification");
+ tmsg->createRequest("subscribe", parameter);
+ m_mloop->sendMessage(tmsg);
+ delete tmsg;
+}
+
+void Map::onDisconnected()
+{
+ MapMessage *tmsg = new MapMessage();
+ QJsonObject parameter;
+ parameter.insert("value", "notification");
+ tmsg->createRequest("unsubscribe", parameter);
+ m_mloop->sendMessage(tmsg);
+ delete tmsg;
+}
+
+void Map::onMessageReceived(MessageType type, Message *msg)
+{
+ if (type == MapEventMessage) {
+ MapMessage *tmsg = qobject_cast<MapMessage*>(msg);
+
+ if (tmsg->isNotificationEvent()) {
+ emit notificationEvent(tmsg->eventData().toVariantMap());
+ }
+ }
+
+ msg->deleteLater();
+}
diff --git a/map/map.h b/map/map.h
new file mode 100644
index 0000000..e712b93
--- /dev/null
+++ b/map/map.h
@@ -0,0 +1,50 @@
+/*
+ * 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 MAP_H
+#define MAP_H
+
+#include <QDebug>
+#include <QObject>
+#include <QJsonArray>
+#include <QtQml/QQmlContext>
+#include <QtQml/QQmlListProperty>
+
+#include "messageengine.h"
+
+class Map : public QObject
+{
+ Q_OBJECT
+
+ public:
+ explicit Map(QUrl &url, QObject * parent = Q_NULLPTR);
+ virtual ~Map();
+
+ Q_INVOKABLE void compose(QString recipient, QString message);
+
+ signals:
+ void notificationEvent(QVariantMap message);
+
+ private:
+ MessageEngine *m_mloop;
+
+ // slots
+ void onConnected();
+ void onDisconnected();
+ void onMessageReceived(MessageType, Message*);
+};
+
+#endif // MAP_H
diff --git a/map/mapmessage.cpp b/map/mapmessage.cpp
new file mode 100644
index 0000000..88957bc
--- /dev/null
+++ b/map/mapmessage.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 <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+
+#include "mapmessage.h"
+
+bool MapMessage::createRequest(QString verb, QJsonObject parameter)
+{
+ if (!verbs.contains(verb))
+ return false;
+
+ return Message::createRequest("bluetooth-map", verb, parameter);
+}
diff --git a/map/mapmessage.h b/map/mapmessage.h
new file mode 100644
index 0000000..4312519
--- /dev/null
+++ b/map/mapmessage.h
@@ -0,0 +1,39 @@
+/*
+ * 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 MAP_MESSAGE_H
+#define MAP_MESSAGE_H
+
+#include "message.h"
+
+class MapMessage : public Message
+{
+ Q_OBJECT
+ public:
+ bool createRequest(QString verb, QJsonObject parameter);
+ bool isNotificationEvent() {return (this->eventName() == "notification"); };
+
+ private:
+ QStringList verbs {
+ "compose",
+ "message",
+ "list_messages",
+ "subscribe",
+ "unsubscribe",
+ };
+};
+
+#endif // MAP_MESSAGE_H
diff --git a/message.h b/message.h
index c89f007..2e731df 100644
--- a/message.h
+++ b/message.h
@@ -40,6 +40,7 @@ enum MessageType {
BluetoothEventMessage,
PbapEventMessage,
RadioEventMessage,
+ MapEventMessage,
};
class Message : public QObject
diff --git a/messageengine.cpp b/messageengine.cpp
index 1cf3843..9846519 100644
--- a/messageengine.cpp
+++ b/messageengine.cpp
@@ -17,6 +17,7 @@
#include "message.h"
#include "messageengine.h"
#include "bluetoothmessage.h"
+#include "mapmessage.h"
#include "mediaplayermessage.h"
#include "networkmessage.h"
#include "pbapmessage.h"
@@ -129,6 +130,9 @@ void MessageEngine::onTextMessageReceived(QString jsonStr)
} else if (api == "radio") {
message = new RadioMessage;
type = RadioEventMessage;
+ } else if (api == "bluetooth-map") {
+ message = new MapMessage;
+ type = MapEventMessage;
} else {
message = new Message;
type = GenericMessage;