summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Porter <mporter@konsulko.com>2017-11-08 08:57:32 -0500
committerMatt Porter <mporter@konsulko.com>2017-11-09 08:24:23 -0500
commit112fc8be473f02befc7596750ad7044113f29849 (patch)
tree5e70e7dc6c33a5cde68bad84165144ea9a86d7ab
parenta2fa6ce695f8532a8f974990b3b12dded18caa92 (diff)
Add base AGL libqtappfw and Telephony supporteel_4.99.3eel/4.99.34.99.3
Implements several QtObject subclasses that wrap functionality provided by the AGL Application Framework. * Message provides facilities to create new AppFW requests and parse AppFw replies/events from a JSON buffer. * MessageEngine provides a websocket message processing client that can send or receive Messages on a given websocket address. * TelephonyMessage subclasses Message to provide accessors and methods specific to the AGL Telephony API. * Telephony provides a complete set of Qt properties/signals/methods that expose the AGL Telephony functionality to Qt/QML applications. An application normally instantiates only this class and has no need to handle low-level AppFW messages. Bug-AGL: SPEC-1064 Change-Id: I2e41fb866bb4f867c81ccaf9bf33d627893879c8 Signed-off-by: Matt Porter <mporter@konsulko.com>
-rw-r--r--CMakeLists.txt26
-rw-r--r--LICENSE54
-rw-r--r--message.cpp137
-rw-r--r--message.h86
-rw-r--r--messageengine.cpp88
-rw-r--r--messageengine.h48
-rw-r--r--qtappfw.pc.in11
-rw-r--r--telephony.cpp110
-rw-r--r--telephony.h72
-rw-r--r--telephonymessage.cpp34
-rw-r--r--telephonymessage.h36
11 files changed, 702 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..122c193
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 3.7.2)
+project(libqtappfw VERSION 1.0.0 LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+
+find_package(Qt5WebSockets REQUIRED)
+
+include(GNUInstallDirs)
+
+set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")
+set(PRIVATE_LIBS "${PRIVATE_LIBS} -lqtappfw")
+CONFIGURE_FILE("qtappfw.pc.in" "qtappfw.pc" @ONLY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw.pc
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
+
+add_library(qtappfw SHARED message.cpp messageengine.cpp telephony.cpp telephonymessage.cpp)
+target_link_libraries(qtappfw Qt5::WebSockets)
+set_target_properties(qtappfw PROPERTIES
+ VERSION ${PROJECT_VERSION}
+ SOVERSION 1
+ PUBLIC_HEADER "message.h;messageengine.h;telephony.h;telephonymessage.h")
+target_include_directories(qtappfw PRIVATE .)
+install(TARGETS qtappfw
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..31c692a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,54 @@
+Apache License
+
+Version 2.0, January 2004
+
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
diff --git a/message.cpp b/message.cpp
new file mode 100644
index 0000000..014e8e7
--- /dev/null
+++ b/message.cpp
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2017 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 <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonValue>
+
+#include "message.h"
+
+Message::Message()
+ : m_init(false), m_event(false), m_reply(false)
+{
+}
+
+bool Message::createRequest(QString api, QString verb, QJsonValue parameter)
+{
+ QJsonArray *request = new QJsonArray;
+ request->append(Call);
+ request->append(9999);
+ request->append(api + (QString)("/") + verb);
+ request->append(QJsonValue(parameter));
+
+ QJsonDocument jdoc;
+ jdoc.setArray(*request);
+
+ m_jdoc = jdoc;
+ m_init = true;
+
+ return true;
+}
+
+bool Message::fromJson(QByteArray jsonData)
+{
+ QJsonDocument jdoc(QJsonDocument::fromJson(jsonData));
+
+ if (jdoc.isNull()) {
+ qWarning("Imported invalid JSON: empty appfw message");
+ return false;
+ }
+
+ return Message::fromJDoc(jdoc);
+}
+
+bool Message::fromJDoc(QJsonDocument jdoc)
+{
+ // Validate message is array
+ if (!jdoc.isArray()) {
+ qWarning("Invalid appfw message: not an array");
+ return false;
+ }
+ QJsonArray msg = jdoc.array();
+
+ // Validate array is proper length
+ if ((msg.size() < 3) || (msg.size() > 4)) {
+ qWarning("Invalid appfw message: invalid array size");
+ return false;
+ }
+
+ // Validate msgid type
+ double msgid;
+ if (msg[0].isDouble()) {
+ msgid = msg[0].toDouble();
+ } else {
+ qWarning("Invalid appfw message: invalid msgid type");
+ return false;
+ }
+
+ // Validate msgid element
+ if ((msgid < Call) || (msgid > Event)) {
+ qWarning("Invalid appfw message: msgid out of range");
+ return false;
+ }
+
+ // Validate that the payload has a request object
+ QJsonObject payload;
+ if (msg[2].isObject()) {
+ payload = msg[2].toObject();
+ } else {
+ qWarning("Invalid appfw payload: no JSON object");
+ return false;
+ }
+
+ if ((msgid == RetOk) || (msgid == RetErr)) {
+ auto request_iter = payload.find("request");
+ auto request = request_iter.value().toObject();
+ if (request.empty()) {
+ qWarning("Invalid appfw reply message: empty request data");
+ return false;
+ }
+ auto status_iter = request.find("status");
+ m_reply_status = status_iter.value().toString();
+ m_reply = true;
+ } else if (msgid == Event) {
+ // If event, save data object
+ auto data_iter = payload.find("data");
+ m_event_data = data_iter.value().toObject();
+
+ auto event_iter = payload.find("event");
+ auto event_string = event_iter.value().toString();
+ if (event_string.isEmpty()) {
+ qWarning("Invalid appfw event message: empty event name");
+ return false;
+ }
+ QStringList event_strings = event_string.split(QRegExp("/"));
+ if (event_strings.size() != 2) {
+ qWarning("Invalid appfw event message: malformed event name");
+ return false;
+ }
+ m_event_api = event_strings[0];
+ m_event_name = event_strings[1];
+ m_event = true;
+ }
+
+ m_jdoc = jdoc;
+ m_init = true;
+ return m_init;
+}
+
+QByteArray Message::toJson(QJsonDocument::JsonFormat format)
+{
+ return m_jdoc.toJson(format).data();
+}
diff --git a/message.h b/message.h
new file mode 100644
index 0000000..e9d915a
--- /dev/null
+++ b/message.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 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 MESSAGE_H
+#define MESSAGE_H
+
+#include <QObject>
+#include <QJsonDocument>
+#include <QJsonObject>
+
+enum MessageId {
+ Call = 2,
+ RetOk = 3,
+ RetErr = 4,
+ Event = 5,
+};
+
+enum MessageType {
+ GenericMessage,
+ TelephonyEventMessage,
+};
+
+class Message : public QObject
+{
+ Q_OBJECT
+ Q_ENUM(MessageId)
+ Q_ENUM(MessageType)
+
+ public:
+ Message();
+
+ bool fromJson(QByteArray jsonData);
+ bool fromJDoc(QJsonDocument jdocData);
+ QByteArray toJson(QJsonDocument::JsonFormat format = QJsonDocument::Compact);
+ bool createRequest(QString api, QString verb, QJsonValue parameter = "None");
+ inline QString eventApi() const
+ {
+ return m_event_api;
+ }
+
+ inline QString eventName() const
+ {
+ return m_event_name;
+ }
+
+ inline QJsonObject eventData() const
+ {
+ return m_event_data;
+ }
+
+ inline bool isEvent() const
+ {
+ return m_event;
+ }
+
+ inline bool isReply() const
+ {
+ return m_reply;
+ }
+
+ inline bool isValid() const
+ {
+ return m_init;
+ }
+
+ protected:
+ bool m_event, m_init, m_reply;
+ QString m_event_api, m_event_name, m_reply_status, m_reply_uuid;
+ QJsonDocument m_jdoc;
+ QJsonObject m_event_data;
+};
+
+#endif // MESSAGE_H
diff --git a/messageengine.cpp b/messageengine.cpp
new file mode 100644
index 0000000..7d53694
--- /dev/null
+++ b/messageengine.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2017 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 "telephonymessage.h"
+
+#include <QJsonArray>
+
+MessageEngine::MessageEngine(const QUrl &url, QObject *parent) :
+ QObject(parent),
+ m_url(url)
+{
+ connect(&m_websocket, &QWebSocket::connected, this, &MessageEngine::onConnected);
+ connect(&m_websocket, &QWebSocket::disconnected, this, &MessageEngine::onDisconnected);
+
+ m_websocket.open(url);
+}
+
+bool MessageEngine::sendMessage(Message *message)
+{
+ if (!message->isValid())
+ return false;
+
+ qint64 size = m_websocket.sendTextMessage(message->toJson().data());
+ if (size == 0)
+ return false;
+
+ return true;
+}
+
+void MessageEngine::onConnected()
+{
+ connect(&m_websocket, &QWebSocket::textMessageReceived, this, &MessageEngine::onTextMessageReceived);
+ emit connected();
+}
+
+void MessageEngine::onDisconnected()
+{
+ disconnect(&m_websocket, &QWebSocket::textMessageReceived, this, &MessageEngine::onTextMessageReceived);
+ m_websocket.deleteLater();
+ emit disconnected();
+}
+
+void MessageEngine::onTextMessageReceived(QString jsonStr)
+{
+ QJsonDocument jdoc(QJsonDocument::fromJson(jsonStr.toUtf8()));
+ if (jdoc.isEmpty()) {
+ qWarning() << "Received invalid JSON: empty appfw message";
+ return;
+ }
+
+ QJsonArray msg = jdoc.array();
+ QStringList api_str_list = msg[1].toString().split(QRegExp("/"));
+ QString api = api_str_list[0];
+
+ Message *message;
+ MessageType type;
+ // FIXME: This should be rewritten using a factory class with a
+ // parser parameter to remove API specific handling here
+ if (api == "telephony") {
+ message = new TelephonyMessage;
+ type = TelephonyEventMessage;
+ } else {
+ message = new Message;
+ type = GenericMessage;
+ }
+
+ if (message->fromJDoc(jdoc) == false) {
+ delete message;
+ return;
+ }
+
+ emit messageReceived(type, message);
+}
diff --git a/messageengine.h b/messageengine.h
new file mode 100644
index 0000000..0ba75fa
--- /dev/null
+++ b/messageengine.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 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 MESSAGEENGINE_H
+#define MESSAGEENGINE_H
+
+#include <QThread>
+#include <QUrl>
+#include <QWebSocket>
+
+#include "message.h"
+
+class MessageEngine : public QObject
+{
+ Q_OBJECT
+ public:
+ explicit MessageEngine(const QUrl &url, QObject *parent = Q_NULLPTR);
+ bool sendMessage(Message *message);
+
+ Q_SIGNALS:
+ void disconnected();
+ void connected();
+ void messageReceived(MessageType type, Message *message);
+
+ private Q_SLOTS:
+ void onConnected();
+ void onDisconnected();
+ void onTextMessageReceived(QString message);
+
+ private:
+ QWebSocket m_websocket;
+ QUrl m_url;
+};
+
+#endif // MESSAGEENGINE_H
diff --git a/qtappfw.pc.in b/qtappfw.pc.in
new file mode 100644
index 0000000..8c015d9
--- /dev/null
+++ b/qtappfw.pc.in
@@ -0,0 +1,11 @@
+prefix=@DEST_DIR@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: qtappfw
+Description: Library wrapping AGL AppFW messages and bindings in Qt objects
+Version: 1.0.0
+
+Libs: -L${libdir} @PRIVATE_LIBS@
+Cflags: -I${includedir}/qtappfw
diff --git a/telephony.cpp b/telephony.cpp
new file mode 100644
index 0000000..7f6a571
--- /dev/null
+++ b/telephony.cpp
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2017 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 "telephony.h"
+#include "telephonymessage.h"
+
+Telephony::Telephony (QUrl &url, QObject * parent) :
+ QObject(parent),
+ m_connected(false),
+ m_mloop(nullptr),
+ m_call_state("disconnected")
+{
+ m_mloop = new MessageEngine(url);
+ QObject::connect(m_mloop, &MessageEngine::connected, this, &Telephony::onConnected);
+ QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Telephony::onDisconnected);
+ QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Telephony::onMessageReceived);
+}
+
+Telephony::~Telephony()
+{
+ delete m_mloop;
+}
+
+void Telephony::dial(QString number)
+{
+ TelephonyMessage *tmsg = new TelephonyMessage();
+ tmsg->createRequest("dial", number);
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+}
+
+void Telephony::answer()
+{
+ TelephonyMessage *tmsg = new TelephonyMessage();
+ tmsg->createRequest("answer");
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+}
+
+void Telephony::hangup()
+{
+ TelephonyMessage *tmsg = new TelephonyMessage();
+ tmsg->createRequest("hangup");
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+}
+
+void Telephony::onConnected()
+{
+ QStringList events {
+ "callStateChanged",
+ "dialingCall",
+ "incomingCall",
+ "terminatedCall"};
+ QStringListIterator eventIterator(events);
+ TelephonyMessage *tmsg;
+
+ while (eventIterator.hasNext()) {
+ tmsg = new TelephonyMessage();
+ tmsg->createRequest("subscribe", eventIterator.next());
+ m_mloop->sendMessage(tmsg);
+ tmsg->deleteLater();
+ }
+
+ setConnected(true);
+}
+
+void Telephony::onDisconnected()
+{
+ setConnected(false);
+}
+
+void Telephony::onMessageReceived(MessageType type, Message *message)
+{
+ if (type == TelephonyEventMessage) {
+ TelephonyMessage *tmsg = qobject_cast<TelephonyMessage*>(message);
+
+ if (tmsg->isEvent()) {
+ if (tmsg->isCallStateChanged()) {
+ setCallState(tmsg->state());
+ } else if (tmsg->isDialingCall()) {
+ m_colp = tmsg->colp();
+ setCallState("dialing");
+ } else if (tmsg->isIncomingCall()) {
+ m_clip = tmsg->clip();
+ setCallState("incoming");
+ } else if (tmsg->isTerminatedCall()) {
+ setCallState("disconnected");
+ m_colp = "";
+ m_clip = "";
+ }
+ }
+ }
+ message->deleteLater();
+}
diff --git a/telephony.h b/telephony.h
new file mode 100644
index 0000000..7cff598
--- /dev/null
+++ b/telephony.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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 TELEPHONY_H
+#define TELEPHONY_H
+
+#include <QDebug>
+#include <QObject>
+
+#include "messageengine.h"
+
+class Telephony : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool connected READ connected WRITE setConnected NOTIFY connectedChanged)
+ Q_PROPERTY(QString callState READ callState WRITE setCallState NOTIFY callStateChanged)
+ Q_PROPERTY(QString callClip READ callClip)
+ Q_PROPERTY(QString callColp READ callColp)
+
+ public:
+ explicit Telephony(QUrl &url, QObject * parent = Q_NULLPTR);
+ virtual ~Telephony();
+ Q_INVOKABLE void dial(QString number);
+ Q_INVOKABLE void answer();
+ Q_INVOKABLE void hangup();
+
+ void setConnected(bool state)
+ {
+ m_connected = state;
+ emit connectedChanged(state);
+ }
+
+ void setCallState(QString callState)
+ {
+ m_call_state = callState;
+ emit callStateChanged(m_call_state);
+ }
+
+ bool connected() { return m_connected; }
+ QString callState() { return m_call_state; }
+ QString callClip() { return m_clip; }
+ QString callColp() { return m_colp; }
+
+ signals:
+ void connectedChanged(bool);
+ void callStateChanged(QString);
+
+ private:
+ bool m_connected;
+ MessageEngine *m_mloop;
+ QString m_call_state;
+ QString m_clip;
+ QString m_colp;
+ void onConnected();
+ void onDisconnected();
+ void onMessageReceived(MessageType, Message*);
+};
+
+#endif // TELEPHONY_H
diff --git a/telephonymessage.cpp b/telephonymessage.cpp
new file mode 100644
index 0000000..67128cf
--- /dev/null
+++ b/telephonymessage.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2017 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 <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+
+#include "telephonymessage.h"
+
+bool TelephonyMessage::createRequest(QString verb, QString value)
+{
+ QStringList verbs {"dial", "answer", "hangup", "subscribe", "unsubscribe"};
+ if (!verbs.contains(verb))
+ return false;
+
+ QJsonObject parameter;
+ parameter.insert("value", value);
+
+ return Message::createRequest("telephony", verb, parameter);
+}
diff --git a/telephonymessage.h b/telephonymessage.h
new file mode 100644
index 0000000..87d06a6
--- /dev/null
+++ b/telephonymessage.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 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 TELEPHONY_MESSAGE_H
+#define TELEPHONY_MESSAGE_H
+
+#include "message.h"
+
+class TelephonyMessage : public Message
+{
+ Q_OBJECT
+ public:
+ bool isCallStateChanged() { return (this->eventName() == "callStateChanged"); };
+ bool isDialingCall() { return m_event ? (this->eventName() == "dialingCall") : false; };
+ bool isIncomingCall() { return m_event ? (this->eventName() == "incomingCall") : false; };
+ bool isTerminatedCall() { return (this->eventName() == "terminatedCall"); };
+ QString clip() { return m_event_data.find("clip").value().toString(); };
+ QString colp() { return m_event_data.find("colp").value().toString(); };
+ QString state() { return m_event_data.find("state").value().toString(); };
+ bool createRequest(QString verb, QString value = "None");
+};
+
+#endif // TELEPHONY_MESSAGE_H