summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-11-13 20:23:26 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-11-13 20:24:08 +0900
commitfba31345d5cf777492313fa518651dff4f97ae8c (patch)
treea3caa4b57627c4b4a68fb8b0ddc99f7e65d648fb
parent17bf0eb61fb73d94f43a1fb79a3cb3867b9421a4 (diff)
Link to qlibsoundmanagersandbox/knimitz/hmi-framework
* Remove qlibsoundmanager.* * Modified main.cpp * Add package config to .pc file Change-Id: I7ef69f090e2f4ce7993cc0eca4b6fe38804f7d56 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--app/app.pro6
-rw-r--r--app/main.cpp2
-rw-r--r--app/qlibsoundmanager.cpp154
-rw-r--r--app/qlibsoundmanager.h60
4 files changed, 4 insertions, 218 deletions
diff --git a/app/app.pro b/app/app.pro
index a432b80..aef6d8d 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -1,11 +1,11 @@
TARGET = radio
QT = quickcontrols2 qml
-HEADERS = PresetDataObject.h qlibsoundmanager.h
-SOURCES = main.cpp PresetDataObject.cpp qlibsoundmanager.cpp
+HEADERS = PresetDataObject.h
+SOURCES = main.cpp PresetDataObject.cpp
CONFIG += link_pkgconfig
-PKGCONFIG += libsoundmanager qlibwindowmanager qlibhomescreen
+PKGCONFIG += qlibsoundmanager qlibwindowmanager qlibhomescreen
RESOURCES += \
radio.qrc \
diff --git a/app/main.cpp b/app/main.cpp
index c7c3290..288c4b8 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -28,7 +28,7 @@
#include "PresetDataObject.h"
#include <qlibhomescreen.h>
#include <qlibwindowmanager.h>
-#include "qlibsoundmanager.h"
+#include <qlibsoundmanager.h>
static QLibHomeScreen* hs;
static QLibWindowmanager* qwm;
diff --git a/app/qlibsoundmanager.cpp b/app/qlibsoundmanager.cpp
deleted file mode 100644
index 9615f64..0000000
--- a/app/qlibsoundmanager.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
- *
- * 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 "qlibsoundmanager.h"
-#include <QJsonDocument>
-using namespace std;
-
-static int create_json_object(const QJsonObject& obj, struct json_object* jobj);
-static bool put_val_to_jobj(const char* key, const QJsonValue& val, struct json_object* jobj);
-QLibSoundmanager* me;
-
-static void cbEvent_static(const std::string& event, struct json_object* event_contents)
-{
- const QString event_name = QString(event.c_str());
- QString str = QString(json_object_get_string(event_contents));
- QJsonParseError error;
- QJsonDocument jdoc = QJsonDocument::fromJson(str.toUtf8(), &error);
- const QJsonObject jobj = jdoc.object();
- emit me->event(event_name, jobj);
-}
-
-static void cbReply_static(struct json_object* replyContents)
-{
- if(me == nullptr){
- return;
- }
- QString str = QString(json_object_get_string(replyContents));
- QJsonParseError error;
- QJsonDocument jdoc = QJsonDocument::fromJson(str.toUtf8(), &error);
- QJsonObject jobj = jdoc.object();
- emit me->reply(jobj);
-}
-
-QLibSoundmanager::QLibSoundmanager(QObject *parent) :
- QObject(parent)
-{
- /* This is not enabled */
- libsm = new LibSoundmanager();
-}
-
-QLibSoundmanager::~QLibSoundmanager()
-{
- delete libsm;
-}
-
-int QLibSoundmanager::init(int port, const QString& token)
-{
- if(libsm == nullptr){
- return -1;
- }
- string ctoken = token.toStdString();
- int rc = libsm->init(port, ctoken);
- if(rc != 0){
- return rc;
- }
- me = this;
-
- libsm->register_callback(
- cbEvent_static,
- cbReply_static);
- return rc;
-}
-
-int QLibSoundmanager::call(const QString &verb, const QJsonObject &arg)
-{
- // translate QJsonObject to struct json_object
- struct json_object* jobj = json_object_new_object();
- int ret = create_json_object(arg, jobj);
- if(ret < 0)
- {
- return -1;
- }
- return libsm->call(verb.toStdString().c_str(), jobj);
-}
-
-int QLibSoundmanager::connect(int sourceID, const QString& sinkName){
- string str = sinkName.toStdString();
- return libsm->connect(sourceID, str);
-}
-int QLibSoundmanager::disconnect(int connectionID){
- return libsm->disconnect(connectionID);
-}
-int QLibSoundmanager::ackSetSourceState(int handle, int errorcode){
- return libsm->ackSetSourceState(handle, errorcode);
-}
-int QLibSoundmanager::registerSource(const QString& name){
- string str = name.toStdString();
- return libsm->registerSource(str);
-}
-
-static int create_json_object(const QJsonObject& obj, struct json_object* jobj)
-{
- try{
- for(auto itr = obj.begin(); itr != obj.end();++itr)
- {
- string key = itr.key().toStdString();
- //const char* key = itr.key().toStdString().c_str(); // Do not code like this. string is removed if size is over 16!!
-
- bool ret = put_val_to_jobj(key.c_str(), itr.value(),jobj);
- if(!ret){
- /*This is not implemented*/
- qDebug("JsonArray can't parse for now");
- return -1;
- }
- }
- }
- catch(...){
- qDebug("Json parse error occured");
- return -1;
- }
- return 0;
-}
-
-static bool put_val_to_jobj(const char* key, const QJsonValue& val, struct json_object* jobj)
-{
- if(val.isArray()){
- return false; // Array can't input
- }
- if(val.isString()){
- string value = val.toString().toStdString();
- json_object_object_add(jobj, key, json_object_new_string(value.c_str()));
- }
- else{
- const int value = val.toInt();
- json_object_object_add(jobj, key, json_object_new_int(value));
- }
- return true;
-}
-
-
-void QLibSoundmanager::subscribe(const QString event_name)
-{
- std::string str = event_name.toStdString();
- libsm->subscribe(str);
-}
-
-void QLibSoundmanager::unsubscribe(const QString event_name)
-{
- std::string str = event_name.toStdString();
- libsm->unsubscribe(str);
-}
diff --git a/app/qlibsoundmanager.h b/app/qlibsoundmanager.h
deleted file mode 100644
index 57d8c6a..0000000
--- a/app/qlibsoundmanager.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
- *
- * 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 QLIBSOUNDMANAGER_H
-#define QLIBSOUNDMANAGER_H
-
- #include <QObject>
- #include <QVariant>
- #include <QtCore/QJsonObject>
- #include <libsoundmanager.hpp>
- #include <QString>
- #include <string>
-
-
-class QLibSoundmanager : public QObject
-{
- Q_OBJECT
-public: // method
- explicit QLibSoundmanager(QObject *parent = nullptr);
- ~QLibSoundmanager();
- int init(int port, const QString& token);
-
- using sm_event_handler = std::function<void(int sourceid, int handle)>;
-
- void subscribe(const QString event_name);
- void unsubscribe(const QString event_name);
-
- void emit_event(const QString &event, const QJsonObject &msg);
- void emit_reply(const QJsonObject &msg);
-
-public:
-
- Q_INVOKABLE int call(const QString &verb, const QJsonObject &arg);
- Q_INVOKABLE int connect(int sourceID, const QString& sinkName);
- Q_INVOKABLE int disconnect(int connectionID);
- Q_INVOKABLE int ackSetSourceState(int handle, int errorcode);
- Q_INVOKABLE int registerSource(const QString& name);
-
-signals:
- void reply(const QVariant &msg);
- void event(const QVariant &event, const QVariant &msg);
-
-private:
- LibSoundmanager* libsm;
-};
-
-
-#endif /*QLIBSOUNDMANAGER_H*/