From 9d2600f4b4dcbdd3820910967eb00a9b00cd8a17 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Fri, 21 Jun 2019 11:44:30 -0700 Subject: libqtappfw: bluetooth-map: add initial map support Add bluetooth-map service support for notifications and message composition. Bug-AGL: SPEC-2561 Change-Id: I956150b9db05334eb02640657c1fc7e03258ab41 Signed-off-by: Matt Ranostay --- CMakeLists.txt | 1 + map/CMakeLists.txt | 2 ++ map/map.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ map/map.h | 50 ++++++++++++++++++++++++++++++++++ map/mapmessage.cpp | 29 ++++++++++++++++++++ map/mapmessage.h | 39 ++++++++++++++++++++++++++ message.h | 1 + messageengine.cpp | 4 +++ 8 files changed, 206 insertions(+) create mode 100644 map/CMakeLists.txt create mode 100644 map/map.cpp create mode 100644 map/map.h create mode 100644 map/mapmessage.cpp create mode 100644 map/mapmessage.h 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(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 +#include +#include +#include +#include + +#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 +#include +#include + +#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; -- cgit 1.2.3-korg