summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--message.h3
-rw-r--r--messageengine.cpp4
-rw-r--r--pbap.cpp73
-rw-r--r--pbap.h47
-rw-r--r--pbapmessage.cpp29
-rw-r--r--pbapmessage.h37
7 files changed, 194 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5ffaaa..249f3ac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,13 +18,14 @@ add_library(qtappfw SHARED message.cpp messageengine.cpp
responsemessage.cpp
bluetooth.cpp bluetoothmessage.cpp
mediaplayer.cpp mediaplayermessage.cpp
+ pbap.cpp pbapmessage.cpp
telephony.cpp telephonymessage.cpp
weather.cpp weathermessage.cpp)
target_link_libraries(qtappfw Qt5::WebSockets)
set_target_properties(qtappfw PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
- PUBLIC_HEADER "message.h;messageengine.h;bluetooth.h;bluetoothmessage.h;mediaplayer.h;mediaplayermessage.h;responsemessage.h;telephony.h;telephonymessage.h;weather.h;weathermessage.h")
+ PUBLIC_HEADER "message.h;messageengine.h;bluetooth.h;bluetoothmessage.h;mediaplayer.h;mediaplayermessage.h;pbap.h;pbapmessage.h;responsemessage.h;telephony.h;telephonymessage.h;weather.h;weathermessage.h")
target_include_directories(qtappfw PRIVATE .)
install(TARGETS qtappfw
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
diff --git a/message.h b/message.h
index 062ca58..f997055 100644
--- a/message.h
+++ b/message.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 Konsulko Group
+ * Copyright (C) 2017, 2018 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ enum MessageType {
WeatherEventMessage,
MediaplayerEventMessage,
BluetoothEventMessage,
+ PbapEventMessage,
};
class Message : public QObject
diff --git a/messageengine.cpp b/messageengine.cpp
index 87c2630..bb7745f 100644
--- a/messageengine.cpp
+++ b/messageengine.cpp
@@ -18,6 +18,7 @@
#include "messageengine.h"
#include "bluetoothmessage.h"
#include "mediaplayermessage.h"
+#include "pbapmessage.h"
#include "responsemessage.h"
#include "telephonymessage.h"
#include "weathermessage.h"
@@ -109,6 +110,9 @@ void MessageEngine::onTextMessageReceived(QString jsonStr)
if (api == "Bluetooth-Manager") {
message = new BluetoothMessage;
type = BluetoothEventMessage;
+ } else if (api == "bluetooth-pbap") {
+ message = new PbapMessage;
+ type = PbapEventMessage;
} else if (api == "telephony") {
message = new TelephonyMessage;
type = TelephonyEventMessage;
diff --git a/pbap.cpp b/pbap.cpp
new file mode 100644
index 0000000..a833b9f
--- /dev/null
+++ b/pbap.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2018 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 "pbap.h"
+#include "pbapmessage.h"
+#include "responsemessage.h"
+
+Pbap::Pbap (QUrl &url, QObject * parent) :
+ QObject(parent),
+ m_mloop(nullptr)
+{
+ m_mloop = new MessageEngine(url);
+ QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Pbap::onMessageReceived);
+}
+
+Pbap::~Pbap()
+{
+ delete m_mloop;
+}
+
+void Pbap::search(QString number)
+{
+ PbapMessage *tmsg = new PbapMessage();
+ QJsonObject parameter;
+
+ if (!number.isEmpty())
+ parameter.insert("number", number);
+ parameter.insert("max_entries", 1);
+
+ tmsg->createRequest("search", parameter);
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+}
+
+void Pbap::sendSearchResults(QJsonArray results)
+{
+ QString name;
+
+ if (results.empty())
+ name = "Not Found";
+ else
+ name = results.at(0).toObject().value("name").toString();
+
+ emit searchResults(name);
+}
+
+void Pbap::onMessageReceived(MessageType type, Message *msg)
+{
+ if (msg->isReply() && type == ResponseRequestMessage) {
+ ResponseMessage *tmsg = qobject_cast<ResponseMessage*>(msg);
+
+ if (tmsg->requestVerb() == "search") {
+ sendSearchResults(tmsg->replyData().value("results").toArray());
+ }
+ }
+
+ msg->deleteLater();
+}
diff --git a/pbap.h b/pbap.h
new file mode 100644
index 0000000..f5e675b
--- /dev/null
+++ b/pbap.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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 PBAP_H
+#define PBAP_H
+
+#include <QDebug>
+#include <QObject>
+#include <QJsonArray>
+
+#include "messageengine.h"
+
+class Pbap : public QObject
+{
+ Q_OBJECT
+
+ public:
+ explicit Pbap(QUrl &url, QObject * parent = Q_NULLPTR);
+ virtual ~Pbap();
+
+ Q_INVOKABLE void search(QString number);
+
+ signals:
+ void searchResults(QString name);
+
+ private:
+ MessageEngine *m_mloop;
+ void sendSearchResults(QJsonArray);
+
+ // slots
+ void onMessageReceived(MessageType, Message*);
+};
+
+#endif // PBAP_H
diff --git a/pbapmessage.cpp b/pbapmessage.cpp
new file mode 100644
index 0000000..751bb9f
--- /dev/null
+++ b/pbapmessage.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 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 "pbapmessage.h"
+
+bool PbapMessage::createRequest(QString verb, QJsonObject parameter)
+{
+ if (!verbs.contains(verb))
+ return false;
+
+ return Message::createRequest("bluetooth-pbap", verb, parameter);
+}
diff --git a/pbapmessage.h b/pbapmessage.h
new file mode 100644
index 0000000..e3d78c2
--- /dev/null
+++ b/pbapmessage.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 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 PBAP_MESSAGE_H
+#define PBAP_MESSAGE_H
+
+#include "message.h"
+
+class PbapMessage : public Message
+{
+ Q_OBJECT
+ public:
+ bool createRequest(QString verb, QJsonObject parameter);
+
+ private:
+ QStringList verbs {
+ "contacts",
+ "entry",
+ "history",
+ "search",
+ };
+};
+
+#endif // PBAP_MESSAGE_H