From ae208a6a303982535c44a7f124f38b4252528ab4 Mon Sep 17 00:00:00 2001 From: Raquel Medina Date: Mon, 1 Jun 2020 00:54:11 +0200 Subject: split qtappfw in independent qtappfw-* modules Bug-AGL: SPEC-3390 Signed-off-by: Raquel Medina Change-Id: Ib8096c8dd2d59d3728e824ae13ba401da0971dc4 --- CMakeLists.txt | 67 ++++------------ bluetooth/CMakeLists.txt | 21 ++++- bluetooth/qtappfw-bt.pc.in | 12 +++ callmessage.cpp | 55 ------------- callmessage.h | 52 ------------ core/CMakeLists.txt | 28 +++++++ core/callmessage.cpp | 55 +++++++++++++ core/callmessage.h | 52 ++++++++++++ core/eventmessage.cpp | 67 ++++++++++++++++ core/eventmessage.h | 61 ++++++++++++++ core/message.cpp | 79 ++++++++++++++++++ core/message.h | 71 +++++++++++++++++ core/messageengine.cpp | 90 +++++++++++++++++++++ core/messageengine.h | 55 +++++++++++++ core/messageenginefactory.cpp | 39 +++++++++ core/messageenginefactory.h | 41 ++++++++++ core/messagefactory.cpp | 39 +++++++++ core/messagefactory.h | 42 ++++++++++ core/qtappfw-core.pc.in | 12 +++ core/responsemessage.cpp | 101 ++++++++++++++++++++++++ core/responsemessage.h | 88 +++++++++++++++++++++ eventmessage.cpp | 67 ---------------- eventmessage.h | 61 -------------- hvac/CMakeLists.txt | 21 ++++- hvac/qtappfw-hvac.pc.in | 12 +++ map/CMakeLists.txt | 21 ++++- map/qtappfw-bt-map.pc.in | 12 +++ mediaplayer/CMakeLists.txt | 21 ++++- mediaplayer/qtappfw-mediaplayer.pc.in | 12 +++ message.cpp | 79 ------------------ message.h | 71 ----------------- messageengine.cpp | 90 --------------------- messageengine.h | 55 ------------- messageenginefactory.cpp | 39 --------- messageenginefactory.h | 41 ---------- messagefactory.cpp | 39 --------- messagefactory.h | 42 ---------- navigation/CMakeLists.txt | 21 ++++- navigation/qtappfw-navigation.pc.in | 12 +++ network/CMakeLists.txt | 33 ++++++-- network/qtappfw-network.pc.in | 12 +++ pbap/CMakeLists.txt | 21 ++++- pbap/qtappfw-bt-pbap.pc.in | 12 +++ qtappfw.pc.in | 12 --- radio/CMakeLists.txt | 21 ++++- radio/qtappfw-radio.pc.in | 12 +++ responsemessage.cpp | 101 ------------------------ responsemessage.h | 86 -------------------- signal-composer/CMakeLists.txt | 21 ++++- signal-composer/qtappfw-signal-composer.pc.in | 12 +++ telephony/CMakeLists.txt | 22 +++++- telephony/qtappfw-phone.pc.in | 12 +++ voice-capabilities/CMakeLists.txt | 21 ++++- voice-capabilities/qtappfw-voice-metadata.pc.in | 12 +++ voice/CMakeLists.txt | 26 +++++- voice/qtappfw-voice.pc.in | 12 +++ weather/CMakeLists.txt | 21 ++++- weather/qtappfw-weather.pc.in | 12 +++ 58 files changed, 1350 insertions(+), 974 deletions(-) create mode 100644 bluetooth/qtappfw-bt.pc.in delete mode 100644 callmessage.cpp delete mode 100644 callmessage.h create mode 100644 core/CMakeLists.txt create mode 100644 core/callmessage.cpp create mode 100644 core/callmessage.h create mode 100644 core/eventmessage.cpp create mode 100644 core/eventmessage.h create mode 100644 core/message.cpp create mode 100644 core/message.h create mode 100644 core/messageengine.cpp create mode 100644 core/messageengine.h create mode 100644 core/messageenginefactory.cpp create mode 100644 core/messageenginefactory.h create mode 100644 core/messagefactory.cpp create mode 100644 core/messagefactory.h create mode 100644 core/qtappfw-core.pc.in create mode 100644 core/responsemessage.cpp create mode 100644 core/responsemessage.h delete mode 100644 eventmessage.cpp delete mode 100644 eventmessage.h create mode 100644 hvac/qtappfw-hvac.pc.in create mode 100644 map/qtappfw-bt-map.pc.in create mode 100644 mediaplayer/qtappfw-mediaplayer.pc.in delete mode 100644 message.cpp delete mode 100644 message.h delete mode 100644 messageengine.cpp delete mode 100644 messageengine.h delete mode 100644 messageenginefactory.cpp delete mode 100644 messageenginefactory.h delete mode 100644 messagefactory.cpp delete mode 100644 messagefactory.h create mode 100644 navigation/qtappfw-navigation.pc.in create mode 100644 network/qtappfw-network.pc.in create mode 100644 pbap/qtappfw-bt-pbap.pc.in delete mode 100644 qtappfw.pc.in create mode 100644 radio/qtappfw-radio.pc.in delete mode 100644 responsemessage.cpp delete mode 100644 responsemessage.h create mode 100644 signal-composer/qtappfw-signal-composer.pc.in create mode 100644 telephony/qtappfw-phone.pc.in create mode 100644 voice-capabilities/qtappfw-voice-metadata.pc.in create mode 100644 voice/qtappfw-voice.pc.in create mode 100644 weather/qtappfw-weather.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a37ee3..28b724c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.7.2) -project(libqtappfw VERSION 1.0.0 LANGUAGES CXX) +project(qtappfw VERSION 1.0.0 LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) @@ -11,41 +11,25 @@ find_package(Qt5WebSockets REQUIRED) include(GNUInstallDirs) -macro (add_headers) - file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") - foreach (_hdr ${ARGN}) - if (_relPath) - list (APPEND HDRS "${_relPath}/${_hdr}") - else() - list (APPEND HDRS "${_hdr}") - endif() - endforeach() - if (_relPath) - set (HDRS ${HDRS} PARENT_SCOPE) - endif() -endmacro() - -macro (add_sources) - file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") - foreach (_src ${ARGN}) - if (_relPath) - list (APPEND SRCS "${_relPath}/${_src}") - else() - list (APPEND SRCS "${_src}") - endif() - endforeach() - if (_relPath) - set (SRCS ${SRCS} PARENT_SCOPE) - endif() -endmacro() - 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) +set(PRIVATE_LIBS "${PRIVATE_LIBS} -lqtappfw-core + -lqtappfw-bt + -lqtappfw-hvac + -lqtappfw-bt-map + -lqtappfw-mediaplayer + -lqtappfw-navigation + -lqtappfw-network + -lqtappfw-bt-pbap + -lqtappfw-radio + -lqtappfw-signal-composer + -lqtappfw-phone + -lqtappfw-voice + -lqtappfw-voice-metadata + -lqtappfw-weather") + set (SUBDIRS + core docs bluetooth hvac @@ -61,23 +45,6 @@ set (SUBDIRS voice-capabilities weather) -add_headers(message.h messagefactory.h messageengine.h messageenginefactory.h responsemessage.h callmessage.h eventmessage.h) -add_sources(message.cpp messagefactory.cpp messageengine.cpp messageenginefactory.cpp responsemessage.cpp callmessage.cpp eventmessage.cpp) - foreach(subdir ${SUBDIRS}) add_subdirectory(${subdir}) endforeach() - -add_library(qtappfw SHARED ${SRCS}) - -target_link_libraries(qtappfw Qt5::WebSockets) -set_target_properties(qtappfw PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION 1 - PUBLIC_HEADER "${HDRS}") - -target_include_directories(qtappfw PRIVATE . ${SUBDIRS}) - -install(TARGETS qtappfw - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw) diff --git a/bluetooth/CMakeLists.txt b/bluetooth/CMakeLists.txt index 0e05d3b..e514aab 100644 --- a/bluetooth/CMakeLists.txt +++ b/bluetooth/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(bluetooth.h bluetoothmodel.h) -add_sources(bluetooth.cpp bluetoothmodel.cpp) + +CONFIGURE_FILE("qtappfw-bt.pc.in" "qtappfw-bt.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-bt.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-bt SHARED bluetooth.cpp bluetoothmodel.cpp) + +target_include_directories(qtappfw-bt PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-bt PRIVATE "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-bt qtappfw-core) +set_target_properties(qtappfw-bt PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER "bluetooth.h;bluetoothmodel.h") + +install(TARGETS qtappfw-bt + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-bt) diff --git a/bluetooth/qtappfw-bt.pc.in b/bluetooth/qtappfw-bt.pc.in new file mode 100644 index 0000000..d32e8ac --- /dev/null +++ b/bluetooth/qtappfw-bt.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-bt +Description: Library wrapping AGL AppFW bluetooth data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-bt +Cflags: -I${includedir}/qtappfw-bt diff --git a/callmessage.cpp b/callmessage.cpp deleted file mode 100644 index 1dfa72e..0000000 --- a/callmessage.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2020 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 - -#include "callmessage.h" -#include "message.h" - - -bool CallMessage::createRequest(QString api, QString verb, QJsonValue parameter) -{ - if (!m_request.isEmpty()){ - qWarning("Message instance has already been used. Cannot send another request."); - return false; - } - - m_request["msgid"] = static_cast(MessageId::Call); - m_request["callid"] = 0; - m_request["api"] = api; - m_request["verb"] = verb; - m_request["parameter"] = parameter; - - m_init = true; - - return m_init; -} - -QByteArray CallMessage::serialize(QJsonDocument::JsonFormat format) -{ - QJsonArray array; - array.append(m_request["msgid"].toInt()); - array.append(m_request["callid"].toInt()); - array.append(m_request["api"].toString() + "/" + m_request["verb"].toString()); - array.append(m_request["parameter"].toJsonValue()); - - m_jdoc.setArray(array); - - return m_jdoc.toJson(format).data(); -} diff --git a/callmessage.h b/callmessage.h deleted file mode 100644 index d08024e..0000000 --- a/callmessage.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2020 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 CALLMESSAGE_H -#define CALLMESSAGE_H - -#include "message.h" - - -class CallMessage : public Message -{ - public: - bool createRequest(QString api, QString verb, QJsonValue parameter = "None"); - - bool isEvent() override - { - return false; - } - - bool isReply() override - { - return false; - } - - void updateCallId(unsigned int id) override - { - m_request["callid"] = qint32(id); - } - - QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override; - - private: - QMap m_request; - - CallMessage() = default; - friend class MessageFactory; -}; - -#endif // CALLMESSAGE_H diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt new file mode 100644 index 0000000..3102f3b --- /dev/null +++ b/core/CMakeLists.txt @@ -0,0 +1,28 @@ + +CONFIGURE_FILE("qtappfw-core.pc.in" "qtappfw-core.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-core.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-core SHARED message.cpp + messagefactory.cpp + messageengine.cpp + messageenginefactory.cpp + responsemessage.cpp + callmessage.cpp + eventmessage.cpp) + +target_include_directories(qtappfw-core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-core PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-core Qt5::WebSockets) + +set_target_properties(qtappfw-core PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER "message.h;messagefactory.h;messageengine.h;messageenginefactory.h;responsemessage.h;callmessage.h;eventmessage.h") + + +install(TARGETS qtappfw-core + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-core) + diff --git a/core/callmessage.cpp b/core/callmessage.cpp new file mode 100644 index 0000000..1dfa72e --- /dev/null +++ b/core/callmessage.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2020 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 + +#include "callmessage.h" +#include "message.h" + + +bool CallMessage::createRequest(QString api, QString verb, QJsonValue parameter) +{ + if (!m_request.isEmpty()){ + qWarning("Message instance has already been used. Cannot send another request."); + return false; + } + + m_request["msgid"] = static_cast(MessageId::Call); + m_request["callid"] = 0; + m_request["api"] = api; + m_request["verb"] = verb; + m_request["parameter"] = parameter; + + m_init = true; + + return m_init; +} + +QByteArray CallMessage::serialize(QJsonDocument::JsonFormat format) +{ + QJsonArray array; + array.append(m_request["msgid"].toInt()); + array.append(m_request["callid"].toInt()); + array.append(m_request["api"].toString() + "/" + m_request["verb"].toString()); + array.append(m_request["parameter"].toJsonValue()); + + m_jdoc.setArray(array); + + return m_jdoc.toJson(format).data(); +} diff --git a/core/callmessage.h b/core/callmessage.h new file mode 100644 index 0000000..d08024e --- /dev/null +++ b/core/callmessage.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 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 CALLMESSAGE_H +#define CALLMESSAGE_H + +#include "message.h" + + +class CallMessage : public Message +{ + public: + bool createRequest(QString api, QString verb, QJsonValue parameter = "None"); + + bool isEvent() override + { + return false; + } + + bool isReply() override + { + return false; + } + + void updateCallId(unsigned int id) override + { + m_request["callid"] = qint32(id); + } + + QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override; + + private: + QMap m_request; + + CallMessage() = default; + friend class MessageFactory; +}; + +#endif // CALLMESSAGE_H diff --git a/core/eventmessage.cpp b/core/eventmessage.cpp new file mode 100644 index 0000000..818830f --- /dev/null +++ b/core/eventmessage.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2020 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 +#include + +#include "eventmessage.h" + +EventMessage::EventMessage(QJsonDocument content): Message() +{ + QJsonArray msg = content.array(); + if (!msg[2].isObject()) { + qWarning("Invalid appfw payload: no JSON object"); + return; + } + + //deserialize: + QJsonObject payload = msg[2].toObject(); + + 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; + } + QStringList event_strings = event_string.split(QRegExp("/")); + if (event_strings.size() != 2) { + qWarning("Invalid appfw event message: malformed event name"); + return; + } + m_event_api = event_strings[0]; + m_event_name = event_strings[1]; + m_init = true; +} + +QByteArray EventMessage::serialize(QJsonDocument::JsonFormat format) +{ + QJsonArray array; + array.append(static_cast(MessageId::Event)); + array.append(0); //unused field + array.append(m_event_api + "/" + m_event_name); + array.append(m_event_data); + + QJsonDocument jdoc; + jdoc.setArray(array); + + return jdoc.toJson(format).data(); +} diff --git a/core/eventmessage.h b/core/eventmessage.h new file mode 100644 index 0000000..133574c --- /dev/null +++ b/core/eventmessage.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020 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 EVENTMESSAGE_H +#define EVENTMESSAGE_H + +#include "message.h" + + +class EventMessage : public Message +{ + public: + inline QString eventApi() const + { + return m_event_api; + } + + inline QString eventName() const + { + return m_event_name; + } + + inline QJsonObject eventData() const + { + return m_event_data; + } + + bool isEvent() override + { + return true; + } + + bool isReply() override + { + return false; + } + + QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override; + + private: + QString m_event_api, m_event_name; + QJsonObject m_event_data; + + explicit EventMessage(QJsonDocument data); + friend class MessageFactory; +}; + +#endif // EVENTMESSAGE_H diff --git a/core/message.cpp b/core/message.cpp new file mode 100644 index 0000000..1865f14 --- /dev/null +++ b/core/message.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2017-2020 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 + +#include "message.h" + +MessageId Message::isValid(QJsonDocument candidate) +{ + MessageId id = MessageId::Invalid; + + // Validate message is array + if (!candidate.isArray()) { + qWarning("Invalid appfw message: not an array"); + return id; + } + QJsonArray msg = candidate.array(); + + // Validate array is proper length + if ((msg.size() < 3) || (msg.size() > 4)) { + qWarning("Invalid appfw message: invalid array size"); + return id; + } + + // Validate msgid type + double msgid; + if (msg[0].isDouble()) { + msgid = msg[0].toDouble(); + } else { + qWarning("Invalid appfw message: invalid msgid type"); + return id; + } + + // Validate msgid element + if ((msgid >= static_cast(MessageId::Call)) && (msgid <= static_cast(MessageId::Event))) + id = static_cast(msgid); + + return id; +} + +Message::Message() + : m_init(false) +{ +} + +QByteArray Message::serialize(QJsonDocument::JsonFormat format) +{ + QByteArray dummy; + return dummy; + } + +QByteArray Message::send(QWebSocket& transport, unsigned int id) +{ + QByteArray blob; + qint64 size = 0; + updateCallId(id); + if (m_init) + blob = serialize().data(); + if (!blob.isEmpty()) + size = transport.sendTextMessage(blob); + + return blob; +} diff --git a/core/message.h b/core/message.h new file mode 100644 index 0000000..acbbefd --- /dev/null +++ b/core/message.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2017-2020 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 +#include +#include +#include +#include +#include + +enum class MessageId { + Invalid = 0, + Call = 2, + RetOk = 3, + RetErr = 4, + Event = 5, +}; + +class QWebSocket; + +class Message +{ + public: + Message(); + virtual bool setAdditionalData(QByteArray data) + { + return false; + } + QByteArray send(QWebSocket& transport, unsigned int callid); + + inline bool isComplete() const + { + return m_init; + } + + virtual bool getCallId(unsigned int *id) const + { + return false; + } + + static MessageId isValid(QJsonDocument ); + + virtual bool isEvent() = 0; + virtual bool isReply() = 0; + + protected: + virtual void updateCallId(unsigned int id) {}; + virtual QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact); + + bool m_init; + QJsonDocument m_jdoc; +}; +Q_DECLARE_METATYPE(std::shared_ptr) + +#endif // MESSAGE_H diff --git a/core/messageengine.cpp b/core/messageengine.cpp new file mode 100644 index 0000000..42fe95b --- /dev/null +++ b/core/messageengine.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2017-2020 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 "message.h" +#include "messagefactory.h" +#include "messageengine.h" + + +MessageEngine::MessageEngine(const QUrl &url) : + QObject(Q_NULLPTR), + m_callid(0), + 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(std::unique_ptr msg) +{ + if (!msg) + return false; + + unsigned int callid = m_callid++; + QByteArray forkeeps = msg->send(m_websocket, callid); + if (forkeeps.isEmpty()) + return false; + + std::lock_guard localguard(m_mutex); + m_calls.insert(callid, forkeeps); + + 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); + emit disconnected(); +} + +void MessageEngine::onTextMessageReceived(QString jsonStr) +{ + jsonStr = jsonStr.simplified(); + QJsonDocument jdoc(QJsonDocument::fromJson(jsonStr.toUtf8())); + if (jdoc.isEmpty()) { + qWarning() << "Received invalid JSON: empty appfw message"; + return; + } + + MessageId id = Message::isValid(jdoc); + if (id == MessageId::Invalid) { + qWarning() << "Received unknown message, discarding"; + return; + } + + std::shared_ptr message = MessageFactory::getInstance().createInboundMessage(id, jdoc); + + unsigned int callid; + if (message->isReply() && message->getCallId(&callid)) { + message->setAdditionalData(m_calls[callid]); + std::lock_guard localguard(m_mutex); + m_calls.remove(callid); + } + + if (message->isComplete()) + emit messageReceived(message); +} diff --git a/core/messageengine.h b/core/messageengine.h new file mode 100644 index 0000000..12aa5e9 --- /dev/null +++ b/core/messageengine.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2017-2020 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 +#include +#include +#include +#include + +#include "message.h" + +class MessageEngine : public QObject +{ + Q_OBJECT + public: + bool sendMessage(std::unique_ptr message); + + Q_SIGNALS: + void disconnected(); + void connected(); + void messageReceived(std::shared_ptr message); + + private Q_SLOTS: + void onConnected(); + void onDisconnected(); + void onTextMessageReceived(QString message); + + private: + QWebSocket m_websocket; + std::mutex m_mutex; + QMap m_calls; + QUrl m_url; + std::atomic m_callid; + + explicit MessageEngine(const QUrl &url); + friend class MessageEngineFactory; +}; + +#endif // MESSAGEENGINE_H diff --git a/core/messageenginefactory.cpp b/core/messageenginefactory.cpp new file mode 100644 index 0000000..04fb741 --- /dev/null +++ b/core/messageenginefactory.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 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 +#include "messageenginefactory.h" +#include "messageengine.h" + +std::shared_ptr MessageEngineFactory::getMessageEngine(const QUrl& url) +{ + static std::unordered_map> lut; + static std::mutex m; + + std::lock_guard localguard(m); + auto urlstr = url.toString(); + auto pme = lut[urlstr]; + if (!pme){ + pme = std::shared_ptr{new MessageEngine(url)}; + lut[urlstr] = pme; + } + + return pme; +} diff --git a/core/messageenginefactory.h b/core/messageenginefactory.h new file mode 100644 index 0000000..1ce107b --- /dev/null +++ b/core/messageenginefactory.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2020 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 MESSAGEENGINEFACTORY_H +#define MESSAGEENGINEFACTORY_H + +#include + +class MessageEngine; +class QUrl; + + +class MessageEngineFactory { + public: + static MessageEngineFactory& getInstance() { + static MessageEngineFactory instance; + return instance; + } + std::shared_ptr getMessageEngine(const QUrl &ur); + MessageEngineFactory(MessageEngineFactory const&) = delete; + void operator=(MessageEngineFactory const&) = delete; + + private: + MessageEngineFactory() = default; + ~MessageEngineFactory() = default; +}; + +#endif // MESSAGENGINEEFACTORY_H diff --git a/core/messagefactory.cpp b/core/messagefactory.cpp new file mode 100644 index 0000000..6740e25 --- /dev/null +++ b/core/messagefactory.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 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 "messagefactory.h" +#include "message.h" +#include "responsemessage.h" +#include "eventmessage.h" +#include "callmessage.h" + +std::unique_ptr MessageFactory::createInboundMessage(MessageId id, QJsonDocument data) +{ + std::unique_ptr msg(nullptr); + if ((id == MessageId::RetOk) || (id == MessageId::RetErr)) + msg.reset(new ResponseMessage(data)); + else if (id == MessageId::Event) + msg.reset(new EventMessage(data)); + return msg; +} + +std::unique_ptr MessageFactory::createOutboundMessage(MessageId id) +{ + std::unique_ptr msg(nullptr); + if (id == MessageId::Call) + msg.reset(new CallMessage()); + return msg; +} diff --git a/core/messagefactory.h b/core/messagefactory.h new file mode 100644 index 0000000..f826483 --- /dev/null +++ b/core/messagefactory.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2020 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 MESSAGEFACTORY_H +#define MESSAGEFACTORY_H + +#include +#include + +class Message; +enum class MessageId; + +class MessageFactory { + public: + static MessageFactory& getInstance() { + static MessageFactory instance; + return instance; + } + std::unique_ptr createInboundMessage(MessageId id, QJsonDocument content); + std::unique_ptr createOutboundMessage(MessageId); + MessageFactory(MessageFactory const&) = delete; + void operator=(MessageFactory const&) = delete; + + private: + MessageFactory() = default; + ~MessageFactory() = default; +}; + +#endif // MESSAGEFACTORY_H diff --git a/core/qtappfw-core.pc.in b/core/qtappfw-core.pc.in new file mode 100644 index 0000000..bfef2e0 --- /dev/null +++ b/core/qtappfw-core.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-core +Description: Library wrapping AGL AppFW messages and bindings in Qt objects +Version: 1.0.0 + +Requires: Qt5WebSockets +Libs: -L${libdir} -lqtappfw-core +Cflags: -I${includedir}/qtappfw-core diff --git a/core/responsemessage.cpp b/core/responsemessage.cpp new file mode 100644 index 0000000..9f8e6f2 --- /dev/null +++ b/core/responsemessage.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2018-2020 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 +#include + +#include "responsemessage.h" + + +ResponseMessage::ResponseMessage(QJsonDocument content) +{ + m_jdoc = content; + QJsonArray msg = content.array(); + if (!msg[2].isObject()) { + qWarning("Invalid appfw payload: no JSON object"); + return; + } + + //deserialize: + auto callid = msg[1].toString().toInt(); + QJsonObject payload = msg[2].toObject(); + + auto request_iter = payload.find("request"); + auto request = request_iter.value().toObject(); + if (request.empty()) { + qWarning("Invalid appfw reply message: empty request data"); + return; + } + + auto status_iter = request.find("status"); + auto info_iter = request.find("info"); + auto response_iter = payload.find("response"); + auto response = response_iter.value().toObject(); + m_reply_status = status_iter.value().toString(); + m_reply_info = info_iter.value().toString(); + m_reply_data = response; + m_reply_callid = callid; + m_init = false; //not complete yet, missing matching request data +} + +bool ResponseMessage::setAdditionalData(QByteArray data) +{ + QJsonDocument jdoc(QJsonDocument::fromJson(data)); + if (!jdoc.isArray()) { + qWarning("Invalid data: not an array"); + return false; + } + + QJsonArray content = jdoc.array(); + if (content.size() != 4) { + qWarning("Invalid data: invalid array size"); + return false; + } + + QStringList api_str_list = content[2].toString().split(QRegExp("/")); + m_request["msgid"] = content.at(0); + m_request["callid"] = content.at(1); + m_request["api"] = api_str_list[0]; + m_request["verb"] = api_str_list[1]; + m_request["parameter"] = content.at(3); + m_init = true; + return true; +} + +bool ResponseMessage::copyCallId(unsigned int *id) +{ + *id = m_reply_callid; + return true; +} + +QByteArray ResponseMessage::serialize(QJsonDocument::JsonFormat format) +{ + QJsonArray array; + (m_reply_status == "failed")? + array.append(static_cast(MessageId::RetErr)) : + array.append(static_cast(MessageId::RetOk)); + array.append(static_cast(m_reply_callid)); + array.append(m_request["api"].toString() + "/" + m_request["verb"].toString()); + array.append(m_reply_data); + + QJsonDocument jdoc; + jdoc.setArray(array); + + return jdoc.toJson(format).data(); +} diff --git a/core/responsemessage.h b/core/responsemessage.h new file mode 100644 index 0000000..af6bda5 --- /dev/null +++ b/core/responsemessage.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2018-2020 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 RESPONSEMESSAGE_H +#define RESPONSEMESSAGE_H + + +#include "message.h" + +class ResponseMessage : public Message +{ + + + public: + inline QString requestApi() const + { + return m_request["api"].toString(); + } + + inline QString requestVerb() const + { + return m_request["verb"].toString(); + } + + inline QVariantMap requestParameters() const + { + return m_request["parameter"].toMap(); + } + + inline QString replyStatus() const + { + return m_reply_status; + } + + inline QString replyInfo() const + { + return m_reply_info; + } + + inline QJsonObject replyData() const + { + return m_reply_data; + } + + bool getCallId(unsigned int *id) const override + { + *id = m_reply_callid; + return true; + } + bool isEvent() override + { + return false; + } + + bool isReply() override + { + return true; + } + + bool setAdditionalData(QByteArray data) override; + bool copyCallId(unsigned int *id); + + QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override; + + private: + QString m_reply_info, m_reply_status, m_reply_uuid; + unsigned int m_reply_callid; + QJsonObject m_reply_data; + QMap m_request; + + explicit ResponseMessage(QJsonDocument data); + friend class MessageFactory; +}; + +#endif // RESPONSEMESSAGE_H diff --git a/eventmessage.cpp b/eventmessage.cpp deleted file mode 100644 index 818830f..0000000 --- a/eventmessage.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2020 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 -#include - -#include "eventmessage.h" - -EventMessage::EventMessage(QJsonDocument content): Message() -{ - QJsonArray msg = content.array(); - if (!msg[2].isObject()) { - qWarning("Invalid appfw payload: no JSON object"); - return; - } - - //deserialize: - QJsonObject payload = msg[2].toObject(); - - 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; - } - QStringList event_strings = event_string.split(QRegExp("/")); - if (event_strings.size() != 2) { - qWarning("Invalid appfw event message: malformed event name"); - return; - } - m_event_api = event_strings[0]; - m_event_name = event_strings[1]; - m_init = true; -} - -QByteArray EventMessage::serialize(QJsonDocument::JsonFormat format) -{ - QJsonArray array; - array.append(static_cast(MessageId::Event)); - array.append(0); //unused field - array.append(m_event_api + "/" + m_event_name); - array.append(m_event_data); - - QJsonDocument jdoc; - jdoc.setArray(array); - - return jdoc.toJson(format).data(); -} diff --git a/eventmessage.h b/eventmessage.h deleted file mode 100644 index 133574c..0000000 --- a/eventmessage.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2020 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 EVENTMESSAGE_H -#define EVENTMESSAGE_H - -#include "message.h" - - -class EventMessage : public Message -{ - public: - inline QString eventApi() const - { - return m_event_api; - } - - inline QString eventName() const - { - return m_event_name; - } - - inline QJsonObject eventData() const - { - return m_event_data; - } - - bool isEvent() override - { - return true; - } - - bool isReply() override - { - return false; - } - - QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override; - - private: - QString m_event_api, m_event_name; - QJsonObject m_event_data; - - explicit EventMessage(QJsonDocument data); - friend class MessageFactory; -}; - -#endif // EVENTMESSAGE_H diff --git a/hvac/CMakeLists.txt b/hvac/CMakeLists.txt index b5124cb..c0ebf49 100644 --- a/hvac/CMakeLists.txt +++ b/hvac/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(hvac.h) -add_sources(hvac.cpp) + +CONFIGURE_FILE("qtappfw-hvac.pc.in" "qtappfw-hvac.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-hvac.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-hvac SHARED hvac.cpp) + +target_include_directories(qtappfw-hvac PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-hvac PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-hvac qtappfw-core) +set_target_properties(qtappfw-hvac PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER hvac.h) + +install(TARGETS qtappfw-hvac + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-hvac) diff --git a/hvac/qtappfw-hvac.pc.in b/hvac/qtappfw-hvac.pc.in new file mode 100644 index 0000000..60ce631 --- /dev/null +++ b/hvac/qtappfw-hvac.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-hvac +Description: Library wrapping AGL AppFW hvac data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-hvac +Cflags: -I${includedir}/qtappfw-hvac diff --git a/map/CMakeLists.txt b/map/CMakeLists.txt index 044f81a..8ca3e2c 100644 --- a/map/CMakeLists.txt +++ b/map/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(map.h) -add_sources(map.cpp) + +CONFIGURE_FILE("qtappfw-bt-map.pc.in" "qtappfw-bt-map.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-bt-map.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-bt-map SHARED map.cpp) + +target_include_directories(qtappfw-bt-map PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-bt-map PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-bt-map qtappfw-core) +set_target_properties(qtappfw-bt-map PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER map.h) + +install(TARGETS qtappfw-bt-map + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-bt-map) diff --git a/map/qtappfw-bt-map.pc.in b/map/qtappfw-bt-map.pc.in new file mode 100644 index 0000000..d5e5dac --- /dev/null +++ b/map/qtappfw-bt-map.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-bt-map +Description: Library wrapping AGL AppFW bluetooth messaging data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-bt-map +Cflags: -I${includedir}/qtappfw-bt-map diff --git a/mediaplayer/CMakeLists.txt b/mediaplayer/CMakeLists.txt index 75bbca1..e21b590 100644 --- a/mediaplayer/CMakeLists.txt +++ b/mediaplayer/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(mediaplayer.h) -add_sources(mediaplayer.cpp) + +CONFIGURE_FILE("qtappfw-mediaplayer.pc.in" "qtappfw-mediaplayer.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-mediaplayer.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-mediaplayer SHARED mediaplayer.cpp) + +target_include_directories(qtappfw-mediaplayer PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-mediaplayer PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-mediaplayer qtappfw-core) +set_target_properties(qtappfw-mediaplayer PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER mediaplayer.h) + +install(TARGETS qtappfw-mediaplayer + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-mediaplayer) diff --git a/mediaplayer/qtappfw-mediaplayer.pc.in b/mediaplayer/qtappfw-mediaplayer.pc.in new file mode 100644 index 0000000..933e9dc --- /dev/null +++ b/mediaplayer/qtappfw-mediaplayer.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-mediaplayer +Description: Library wrapping AGL AppFW mediaplayer data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-mediaplayer +Cflags: -I${includedir}/qtappfw-mediaplayer diff --git a/message.cpp b/message.cpp deleted file mode 100644 index 1865f14..0000000 --- a/message.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2017-2020 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 - -#include "message.h" - -MessageId Message::isValid(QJsonDocument candidate) -{ - MessageId id = MessageId::Invalid; - - // Validate message is array - if (!candidate.isArray()) { - qWarning("Invalid appfw message: not an array"); - return id; - } - QJsonArray msg = candidate.array(); - - // Validate array is proper length - if ((msg.size() < 3) || (msg.size() > 4)) { - qWarning("Invalid appfw message: invalid array size"); - return id; - } - - // Validate msgid type - double msgid; - if (msg[0].isDouble()) { - msgid = msg[0].toDouble(); - } else { - qWarning("Invalid appfw message: invalid msgid type"); - return id; - } - - // Validate msgid element - if ((msgid >= static_cast(MessageId::Call)) && (msgid <= static_cast(MessageId::Event))) - id = static_cast(msgid); - - return id; -} - -Message::Message() - : m_init(false) -{ -} - -QByteArray Message::serialize(QJsonDocument::JsonFormat format) -{ - QByteArray dummy; - return dummy; - } - -QByteArray Message::send(QWebSocket& transport, unsigned int id) -{ - QByteArray blob; - qint64 size = 0; - updateCallId(id); - if (m_init) - blob = serialize().data(); - if (!blob.isEmpty()) - size = transport.sendTextMessage(blob); - - return blob; -} diff --git a/message.h b/message.h deleted file mode 100644 index acbbefd..0000000 --- a/message.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2017-2020 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 -#include -#include -#include -#include -#include - -enum class MessageId { - Invalid = 0, - Call = 2, - RetOk = 3, - RetErr = 4, - Event = 5, -}; - -class QWebSocket; - -class Message -{ - public: - Message(); - virtual bool setAdditionalData(QByteArray data) - { - return false; - } - QByteArray send(QWebSocket& transport, unsigned int callid); - - inline bool isComplete() const - { - return m_init; - } - - virtual bool getCallId(unsigned int *id) const - { - return false; - } - - static MessageId isValid(QJsonDocument ); - - virtual bool isEvent() = 0; - virtual bool isReply() = 0; - - protected: - virtual void updateCallId(unsigned int id) {}; - virtual QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact); - - bool m_init; - QJsonDocument m_jdoc; -}; -Q_DECLARE_METATYPE(std::shared_ptr) - -#endif // MESSAGE_H diff --git a/messageengine.cpp b/messageengine.cpp deleted file mode 100644 index 42fe95b..0000000 --- a/messageengine.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2017-2020 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 "message.h" -#include "messagefactory.h" -#include "messageengine.h" - - -MessageEngine::MessageEngine(const QUrl &url) : - QObject(Q_NULLPTR), - m_callid(0), - 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(std::unique_ptr msg) -{ - if (!msg) - return false; - - unsigned int callid = m_callid++; - QByteArray forkeeps = msg->send(m_websocket, callid); - if (forkeeps.isEmpty()) - return false; - - std::lock_guard localguard(m_mutex); - m_calls.insert(callid, forkeeps); - - 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); - emit disconnected(); -} - -void MessageEngine::onTextMessageReceived(QString jsonStr) -{ - jsonStr = jsonStr.simplified(); - QJsonDocument jdoc(QJsonDocument::fromJson(jsonStr.toUtf8())); - if (jdoc.isEmpty()) { - qWarning() << "Received invalid JSON: empty appfw message"; - return; - } - - MessageId id = Message::isValid(jdoc); - if (id == MessageId::Invalid) { - qWarning() << "Received unknown message, discarding"; - return; - } - - std::shared_ptr message = MessageFactory::getInstance().createInboundMessage(id, jdoc); - - unsigned int callid; - if (message->isReply() && message->getCallId(&callid)) { - message->setAdditionalData(m_calls[callid]); - std::lock_guard localguard(m_mutex); - m_calls.remove(callid); - } - - if (message->isComplete()) - emit messageReceived(message); -} diff --git a/messageengine.h b/messageengine.h deleted file mode 100644 index 12aa5e9..0000000 --- a/messageengine.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2017-2020 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 -#include -#include -#include -#include - -#include "message.h" - -class MessageEngine : public QObject -{ - Q_OBJECT - public: - bool sendMessage(std::unique_ptr message); - - Q_SIGNALS: - void disconnected(); - void connected(); - void messageReceived(std::shared_ptr message); - - private Q_SLOTS: - void onConnected(); - void onDisconnected(); - void onTextMessageReceived(QString message); - - private: - QWebSocket m_websocket; - std::mutex m_mutex; - QMap m_calls; - QUrl m_url; - std::atomic m_callid; - - explicit MessageEngine(const QUrl &url); - friend class MessageEngineFactory; -}; - -#endif // MESSAGEENGINE_H diff --git a/messageenginefactory.cpp b/messageenginefactory.cpp deleted file mode 100644 index 04fb741..0000000 --- a/messageenginefactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 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 -#include "messageenginefactory.h" -#include "messageengine.h" - -std::shared_ptr MessageEngineFactory::getMessageEngine(const QUrl& url) -{ - static std::unordered_map> lut; - static std::mutex m; - - std::lock_guard localguard(m); - auto urlstr = url.toString(); - auto pme = lut[urlstr]; - if (!pme){ - pme = std::shared_ptr{new MessageEngine(url)}; - lut[urlstr] = pme; - } - - return pme; -} diff --git a/messageenginefactory.h b/messageenginefactory.h deleted file mode 100644 index 1ce107b..0000000 --- a/messageenginefactory.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2020 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 MESSAGEENGINEFACTORY_H -#define MESSAGEENGINEFACTORY_H - -#include - -class MessageEngine; -class QUrl; - - -class MessageEngineFactory { - public: - static MessageEngineFactory& getInstance() { - static MessageEngineFactory instance; - return instance; - } - std::shared_ptr getMessageEngine(const QUrl &ur); - MessageEngineFactory(MessageEngineFactory const&) = delete; - void operator=(MessageEngineFactory const&) = delete; - - private: - MessageEngineFactory() = default; - ~MessageEngineFactory() = default; -}; - -#endif // MESSAGENGINEEFACTORY_H diff --git a/messagefactory.cpp b/messagefactory.cpp deleted file mode 100644 index 6740e25..0000000 --- a/messagefactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 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 "messagefactory.h" -#include "message.h" -#include "responsemessage.h" -#include "eventmessage.h" -#include "callmessage.h" - -std::unique_ptr MessageFactory::createInboundMessage(MessageId id, QJsonDocument data) -{ - std::unique_ptr msg(nullptr); - if ((id == MessageId::RetOk) || (id == MessageId::RetErr)) - msg.reset(new ResponseMessage(data)); - else if (id == MessageId::Event) - msg.reset(new EventMessage(data)); - return msg; -} - -std::unique_ptr MessageFactory::createOutboundMessage(MessageId id) -{ - std::unique_ptr msg(nullptr); - if (id == MessageId::Call) - msg.reset(new CallMessage()); - return msg; -} diff --git a/messagefactory.h b/messagefactory.h deleted file mode 100644 index f826483..0000000 --- a/messagefactory.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2020 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 MESSAGEFACTORY_H -#define MESSAGEFACTORY_H - -#include -#include - -class Message; -enum class MessageId; - -class MessageFactory { - public: - static MessageFactory& getInstance() { - static MessageFactory instance; - return instance; - } - std::unique_ptr createInboundMessage(MessageId id, QJsonDocument content); - std::unique_ptr createOutboundMessage(MessageId); - MessageFactory(MessageFactory const&) = delete; - void operator=(MessageFactory const&) = delete; - - private: - MessageFactory() = default; - ~MessageFactory() = default; -}; - -#endif // MESSAGEFACTORY_H diff --git a/navigation/CMakeLists.txt b/navigation/CMakeLists.txt index ec76041..bb972e0 100644 --- a/navigation/CMakeLists.txt +++ b/navigation/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(navigation.h) -add_sources(navigation.cpp) + +CONFIGURE_FILE("qtappfw-navigation.pc.in" "qtappfw-navigation.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-navigation.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-navigation SHARED navigation.cpp) + +target_include_directories(qtappfw-navigation PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-navigation PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-navigation qtappfw-core) +set_target_properties(qtappfw-navigation PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER navigation.h) + +install(TARGETS qtappfw-navigation + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-navigation) diff --git a/navigation/qtappfw-navigation.pc.in b/navigation/qtappfw-navigation.pc.in new file mode 100644 index 0000000..8f1fa2c --- /dev/null +++ b/navigation/qtappfw-navigation.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-navigation +Description: Library wrapping AGL AppFW navigation data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-navigation +Cflags: -I${includedir}/qtappfw-navigation diff --git a/network/CMakeLists.txt b/network/CMakeLists.txt index fcf21ac..162325c 100644 --- a/network/CMakeLists.txt +++ b/network/CMakeLists.txt @@ -1,8 +1,25 @@ -add_headers(network.h - networkadapter.h wifiadapter.h wiredadapter.h - wifinetworkmodel.h wirednetworkmodel.h abstractnetworkmodel.h - connectionprofile.h) -add_sources(network.cpp - wifiadapter.cpp wiredadapter.cpp - wifinetworkmodel.cpp wirednetworkmodel.cpp abstractnetworkmodel.cpp - connectionprofile.cpp) + +CONFIGURE_FILE("qtappfw-network.pc.in" "qtappfw-network.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-network.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-network SHARED network.cpp + wifiadapter.cpp + wiredadapter.cpp + wifinetworkmodel.cpp + wirednetworkmodel.cpp + abstractnetworkmodel.cpp + connectionprofile.cpp) + +target_include_directories(qtappfw-network PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-network PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-network qtappfw-core) +set_target_properties(qtappfw-network PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER "network.h;networkadapter.h;wifiadapter.h;wiredadapter.h;wifinetworkmodel.h;wirednetworkmodel.h;abstractnetworkmodel.h;connectionprofile.h") + +install(TARGETS qtappfw-network + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-network) diff --git a/network/qtappfw-network.pc.in b/network/qtappfw-network.pc.in new file mode 100644 index 0000000..50b34a0 --- /dev/null +++ b/network/qtappfw-network.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-network +Description: Library wrapping AGL AppFW network data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-network +Cflags: -I${includedir}/qtappfw-network diff --git a/pbap/CMakeLists.txt b/pbap/CMakeLists.txt index 441280f..04f9c67 100644 --- a/pbap/CMakeLists.txt +++ b/pbap/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(pbap.h) -add_sources(pbap.cpp) + +CONFIGURE_FILE("qtappfw-bt-pbap.pc.in" "qtappfw-bt-pbap.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-bt-pbap.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-bt-pbap SHARED pbap.cpp) + +target_include_directories(qtappfw-bt-pbap PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-bt-pbap PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-bt-pbap qtappfw-core) +set_target_properties(qtappfw-bt-pbap PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER pbap.h) + +install(TARGETS qtappfw-bt-pbap + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-bt-pbap) diff --git a/pbap/qtappfw-bt-pbap.pc.in b/pbap/qtappfw-bt-pbap.pc.in new file mode 100644 index 0000000..2da9c53 --- /dev/null +++ b/pbap/qtappfw-bt-pbap.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-bt-pbap +Description: Library wrapping AGL AppFW bluetooth pbap data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-bt-pbap +Cflags: -I${includedir}/qtappfw-bt-pbap diff --git a/qtappfw.pc.in b/qtappfw.pc.in deleted file mode 100644 index afbbbbd..0000000 --- a/qtappfw.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -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 - -Requires: Qt5WebSockets Qt5Qml -Libs: -L${libdir} @PRIVATE_LIBS@ -Cflags: -I${includedir}/qtappfw diff --git a/radio/CMakeLists.txt b/radio/CMakeLists.txt index a6b8db4..8cce350 100644 --- a/radio/CMakeLists.txt +++ b/radio/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(radio.h) -add_sources(radio.cpp) + +CONFIGURE_FILE("qtappfw-radio.pc.in" "qtappfw-radio.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-radio.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-radio SHARED radio.cpp) + +target_include_directories(qtappfw-radio PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-radio PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-radio qtappfw-core) +set_target_properties(qtappfw-radio PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER radio.h) + +install(TARGETS qtappfw-radio + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-radio) diff --git a/radio/qtappfw-radio.pc.in b/radio/qtappfw-radio.pc.in new file mode 100644 index 0000000..8f42e39 --- /dev/null +++ b/radio/qtappfw-radio.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-radio +Description: Library wrapping AGL AppFW radio data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-radio +Cflags: -I${includedir}/qtappfw-radio diff --git a/responsemessage.cpp b/responsemessage.cpp deleted file mode 100644 index 9f8e6f2..0000000 --- a/responsemessage.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2018-2020 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 -#include - -#include "responsemessage.h" - - -ResponseMessage::ResponseMessage(QJsonDocument content) -{ - m_jdoc = content; - QJsonArray msg = content.array(); - if (!msg[2].isObject()) { - qWarning("Invalid appfw payload: no JSON object"); - return; - } - - //deserialize: - auto callid = msg[1].toString().toInt(); - QJsonObject payload = msg[2].toObject(); - - auto request_iter = payload.find("request"); - auto request = request_iter.value().toObject(); - if (request.empty()) { - qWarning("Invalid appfw reply message: empty request data"); - return; - } - - auto status_iter = request.find("status"); - auto info_iter = request.find("info"); - auto response_iter = payload.find("response"); - auto response = response_iter.value().toObject(); - m_reply_status = status_iter.value().toString(); - m_reply_info = info_iter.value().toString(); - m_reply_data = response; - m_reply_callid = callid; - m_init = false; //not complete yet, missing matching request data -} - -bool ResponseMessage::setAdditionalData(QByteArray data) -{ - QJsonDocument jdoc(QJsonDocument::fromJson(data)); - if (!jdoc.isArray()) { - qWarning("Invalid data: not an array"); - return false; - } - - QJsonArray content = jdoc.array(); - if (content.size() != 4) { - qWarning("Invalid data: invalid array size"); - return false; - } - - QStringList api_str_list = content[2].toString().split(QRegExp("/")); - m_request["msgid"] = content.at(0); - m_request["callid"] = content.at(1); - m_request["api"] = api_str_list[0]; - m_request["verb"] = api_str_list[1]; - m_request["parameter"] = content.at(3); - m_init = true; - return true; -} - -bool ResponseMessage::copyCallId(unsigned int *id) -{ - *id = m_reply_callid; - return true; -} - -QByteArray ResponseMessage::serialize(QJsonDocument::JsonFormat format) -{ - QJsonArray array; - (m_reply_status == "failed")? - array.append(static_cast(MessageId::RetErr)) : - array.append(static_cast(MessageId::RetOk)); - array.append(static_cast(m_reply_callid)); - array.append(m_request["api"].toString() + "/" + m_request["verb"].toString()); - array.append(m_reply_data); - - QJsonDocument jdoc; - jdoc.setArray(array); - - return jdoc.toJson(format).data(); -} diff --git a/responsemessage.h b/responsemessage.h deleted file mode 100644 index 304a6e3..0000000 --- a/responsemessage.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2018-2020 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 RESPONSEMESSAGE_H -#define RESPONSEMESSAGE_H - - -#include "message.h" - -class ResponseMessage : public Message -{ - public: - inline QString requestApi() const - { - return m_request["api"].toString(); - } - - inline QString requestVerb() const - { - return m_request["verb"].toString(); - } - - inline QVariantMap requestParameters() const - { - return m_request["parameter"].toMap(); - } - - inline QString replyStatus() const - { - return m_reply_status; - } - - inline QString replyInfo() const - { - return m_reply_info; - } - - inline QJsonObject replyData() const - { - return m_reply_data; - } - - bool getCallId(unsigned int *id) const override - { - *id = m_reply_callid; - return true; - } - bool isEvent() override - { - return false; - } - - bool isReply() override - { - return true; - } - - bool setAdditionalData(QByteArray data) override; - bool copyCallId(unsigned int *id); - - QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override; - - private: - QString m_reply_info, m_reply_status, m_reply_uuid; - unsigned int m_reply_callid; - QJsonObject m_reply_data; - QMap m_request; - - explicit ResponseMessage(QJsonDocument data); - friend class MessageFactory; -}; - -#endif // RESPONSEMESSAGE_H diff --git a/signal-composer/CMakeLists.txt b/signal-composer/CMakeLists.txt index f517d27..e8c51e3 100644 --- a/signal-composer/CMakeLists.txt +++ b/signal-composer/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(signalcomposer.h) -add_sources(signalcomposer.cpp) + +CONFIGURE_FILE("qtappfw-signal-composer.pc.in" "qtappfw-signal-composer.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-signal-composer.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-signal-composer SHARED signalcomposer.cpp) + +target_include_directories(qtappfw-signal-composer PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-signal-composer PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-signal-composer qtappfw-core) +set_target_properties(qtappfw-signal-composer PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER signalcomposer.h) + +install(TARGETS qtappfw-signal-composer + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-signal-composer) diff --git a/signal-composer/qtappfw-signal-composer.pc.in b/signal-composer/qtappfw-signal-composer.pc.in new file mode 100644 index 0000000..f00ba19 --- /dev/null +++ b/signal-composer/qtappfw-signal-composer.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-signal-composer +Description: Library wrapping AGL AppFW signal composer data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-signal-composer +Cflags: -I${includedir}/qtappfw-signal-composer diff --git a/telephony/CMakeLists.txt b/telephony/CMakeLists.txt index 196ad53..7c4e5b5 100644 --- a/telephony/CMakeLists.txt +++ b/telephony/CMakeLists.txt @@ -1,2 +1,20 @@ -add_headers(telephony.h) -add_sources(telephony.cpp) + +CONFIGURE_FILE("qtappfw-phone.pc.in" "qtappfw-phone.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-phone.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-phone SHARED telephony.cpp) + +target_include_directories(qtappfw-phone PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-phone PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-phone qtappfw-core) +set_target_properties(qtappfw-phone PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER telephony.h) + +install(TARGETS qtappfw-phone + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-phone) + diff --git a/telephony/qtappfw-phone.pc.in b/telephony/qtappfw-phone.pc.in new file mode 100644 index 0000000..949542f --- /dev/null +++ b/telephony/qtappfw-phone.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-phone +Description: Library wrapping AGL AppFW phone data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-phone +Cflags: -I${includedir}/qtappfw-phone diff --git a/voice-capabilities/CMakeLists.txt b/voice-capabilities/CMakeLists.txt index e3c0de7..1751e71 100644 --- a/voice-capabilities/CMakeLists.txt +++ b/voice-capabilities/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(guimetadata.h) -add_sources(guimetadata.cpp) + +CONFIGURE_FILE("qtappfw-voice-metadata.pc.in" "qtappfw-voice-metadata.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-voice-metadata.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-voice-metadata SHARED guimetadata.cpp) + +target_include_directories(qtappfw-voice-metadata PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-voice-metadata PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-voice-metadata qtappfw-core) +set_target_properties(qtappfw-voice-metadata PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER guimetadata.h) + +install(TARGETS qtappfw-voice-metadata + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-voice-metadata) diff --git a/voice-capabilities/qtappfw-voice-metadata.pc.in b/voice-capabilities/qtappfw-voice-metadata.pc.in new file mode 100644 index 0000000..7f69783 --- /dev/null +++ b/voice-capabilities/qtappfw-voice-metadata.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-voice-metadata +Description: Library wrapping AGL AppFW voice metadata in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-voice-metadata +Cflags: -I${includedir}/qtappfw-voice-metadata diff --git a/voice/CMakeLists.txt b/voice/CMakeLists.txt index 6363c3b..3de0586 100644 --- a/voice/CMakeLists.txt +++ b/voice/CMakeLists.txt @@ -1,4 +1,22 @@ -add_headers(voice.h - voiceagentregistry.h voiceagentprofile.h voiceagentmodel.h) -add_sources(voice.cpp - voiceagentregistry.cpp voiceagentprofile.cpp voiceagentmodel.cpp) + +CONFIGURE_FILE("qtappfw-voice.pc.in" "qtappfw-voice.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-voice.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-voice SHARED voice.cpp + voiceagentregistry.cpp + voiceagentprofile.cpp + voiceagentmodel.cpp) + +target_include_directories(qtappfw-voice PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-voice PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-voice qtappfw-core) +set_target_properties(qtappfw-voice PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER "voice.h;voiceagentregistry.h;voiceagentprofile.h;voiceagentmodel.h") + +install(TARGETS qtappfw-voice + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-voice) diff --git a/voice/qtappfw-voice.pc.in b/voice/qtappfw-voice.pc.in new file mode 100644 index 0000000..ebc5276 --- /dev/null +++ b/voice/qtappfw-voice.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-voice +Description: Library wrapping AGL AppFW voice data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-voice +Cflags: -I${includedir}/qtappfw-voice diff --git a/weather/CMakeLists.txt b/weather/CMakeLists.txt index bd94755..11d4f91 100644 --- a/weather/CMakeLists.txt +++ b/weather/CMakeLists.txt @@ -1,2 +1,19 @@ -add_headers(weather.h) -add_sources(weather.cpp) + +CONFIGURE_FILE("qtappfw-weather.pc.in" "qtappfw-weather.pc" @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-weather.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) + +add_library(qtappfw-weather SHARED weather.cpp) + +target_include_directories(qtappfw-weather PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(qtappfw-weather PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}") + +target_link_libraries(qtappfw-weather qtappfw-core) +set_target_properties(qtappfw-weather PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER weather.h) + +install(TARGETS qtappfw-weather + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-weather) diff --git a/weather/qtappfw-weather.pc.in b/weather/qtappfw-weather.pc.in new file mode 100644 index 0000000..1e3e5e1 --- /dev/null +++ b/weather/qtappfw-weather.pc.in @@ -0,0 +1,12 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: qtappfw-weather +Description: Library wrapping AGL AppFW weather data in Qt objects +Version: 1.0.0 + +Requires: Qt5Qml +Libs: -L${libdir} -lqtappfw-weather +Cflags: -I${includedir}/qtappfw-weather -- cgit 1.2.3-korg