From cd515ebf86fbf26667b271db3098b2aaced58e44 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Mon, 19 Jan 2015 13:46:12 -0800 Subject: [bluemonkey] - added dbus module --- plugins/bluemonkey/CMakeLists.txt | 13 ++++++++++- plugins/bluemonkey/bluemonkey.cpp | 6 +++-- plugins/bluemonkey/bluemonkey.h | 17 ++++---------- plugins/bluemonkey/bmdbus.cpp | 40 ++++++++++++++++++++++++++++++++ plugins/bluemonkey/bmdbus.h | 48 +++++++++++++++++++++++++++++++++++++++ plugins/bluemonkey/config.js | 11 +++++++++ plugins/bluemonkey/db.cpp | 18 +++++++++++++++ plugins/bluemonkey/db.h | 18 +++++++++++++++ plugins/bluemonkey/irccoms.cpp | 18 +++++++++++++++ plugins/bluemonkey/irccoms.h | 18 +++++++++++++++ 10 files changed, 192 insertions(+), 15 deletions(-) create mode 100644 plugins/bluemonkey/bmdbus.cpp create mode 100644 plugins/bluemonkey/bmdbus.h diff --git a/plugins/bluemonkey/CMakeLists.txt b/plugins/bluemonkey/CMakeLists.txt index 71a75692..f829d4fc 100644 --- a/plugins/bluemonkey/CMakeLists.txt +++ b/plugins/bluemonkey/CMakeLists.txt @@ -42,6 +42,17 @@ if(Qt5Sql_FOUND) install(TARGETS bluemonkeyDbModule LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) endif() +find_package(Qt5DBus) + +if(Qt5DBus_FOUND) + message(STATUS "enabling dbus bluemonkey module") + add_library(bluemonkeyDBusModule MODULE bmdbus.cpp) + set_target_properties(bluemonkeyDBusModule PROPERTIES PREFIX "") + target_link_libraries(bluemonkeyDBusModule ${link_libraries} amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${QT_LIBRARIES} ${Qt5DBus_LIBRARIES}) + set(QT_INCLUDE_DIRS ${QT_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) + install(TARGETS bluemonkeyDBusModule LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) +endif() + include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${communi_INCLUDE_DIRS} ${QT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/plugins/common) set(bluemonkeyplugin_headers bluemonkey.h authenticate.h) @@ -51,7 +62,7 @@ add_library(bluemonkeyplugin MODULE ${bluemonkeyplugin_sources}) set_target_properties(bluemonkeyplugin PROPERTIES PREFIX "") target_link_libraries(bluemonkeyplugin dl amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${QT_LIBRARIES} ${communi_LIBRARIES} amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common) -set(config_files ${CMAKE_CURRENT_SOURCE_DIR}/config.js) +set(config_files ${CMAKE_CURRENT_BINARY_DIR}/config.js) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.js ${CMAKE_CURRENT_BINARY_DIR}/config.js @ONLY) install(TARGETS bluemonkeyplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp index 958e43ce..c4078343 100644 --- a/plugins/bluemonkey/bluemonkey.cpp +++ b/plugins/bluemonkey/bluemonkey.cpp @@ -166,6 +166,8 @@ BluemonkeySink::~BluemonkeySink() { dlclose(module); } + + engine->deleteLater(); } @@ -253,7 +255,7 @@ void BluemonkeySink::loadConfig(QString str) file.close(); - DebugOut()<<"evaluating script: "<evaluate(script); @@ -312,7 +314,7 @@ void BluemonkeySink::reloadEngine() if(engine) engine->deleteLater(); - engine = new QJSEngine(this); + engine = new QJSEngine(); QJSValue value = engine->newQObject(this); engine->globalObject().setProperty("bluemonkey", value); diff --git a/plugins/bluemonkey/bluemonkey.h b/plugins/bluemonkey/bluemonkey.h index 13c7c309..f08e9002 100644 --- a/plugins/bluemonkey/bluemonkey.h +++ b/plugins/bluemonkey/bluemonkey.h @@ -20,8 +20,9 @@ #ifndef BluemonkeySink_H #define BluemonkeySink_H -#include "abstractsource.h" -#include "ambpluginimpl.h" +#include +#include +#include #include @@ -30,20 +31,12 @@ #include #include #include -#include "uuidhelper.h" +#include #include "authenticate.h" class QJSEngine; -class ModuleInterface -{ -public: - virtual std::map objects(std::map config) = 0; -}; - -Q_DECLARE_INTERFACE(ModuleInterface, "org.automotive.bluemonkey.moduleinterface") - class Property: public QObject, public AbstractSink { Q_OBJECT @@ -54,7 +47,7 @@ class Property: public QObject, public AbstractSink Q_PROPERTY(int zone READ zone) public: - Property(VehicleProperty::Property, QString srcFilter, AbstractRoutingEngine* re, Zone::Type zone = Zone::None, QObject *parent = 0); + Property(VehicleProperty::Property, QString srcFilter, AbstractRoutingEngine * re, Zone::Type zone = Zone::None, QObject * parent = 0); QString name(); void setType(QString t); diff --git a/plugins/bluemonkey/bmdbus.cpp b/plugins/bluemonkey/bmdbus.cpp new file mode 100644 index 00000000..8f26c7fc --- /dev/null +++ b/plugins/bluemonkey/bmdbus.cpp @@ -0,0 +1,40 @@ +/* + Copyright (C) 2012 Intel Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "bmdbus.h" + +#include +#include + +extern "C" std::map create(std::map config, QObject* parent) +{ + std::map moduleInstances; + moduleInstances["dbus"] = new BMDBus(parent); + return moduleInstances; +} + +BMDBus::BMDBus(QObject *parent) + :QObject(parent) +{ + +} + +QObject *BMDBus::createInterface(const QString &service, const QString &path, const QString &interface, BMDBus::Connection bus) +{ + return new QDBusInterface(service, path, interface, bus == Session ? QDBusConnection::sessionBus() : QDBusConnection::systemBus(), this); +} diff --git a/plugins/bluemonkey/bmdbus.h b/plugins/bluemonkey/bmdbus.h new file mode 100644 index 00000000..903963c3 --- /dev/null +++ b/plugins/bluemonkey/bmdbus.h @@ -0,0 +1,48 @@ +/* + Copyright (C) 2012 Intel Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef BM_DBUS_H_ +#define BM_DBUS_H_ + +#include + +class BMDBus : public QObject +{ + Q_OBJECT + Q_ENUMS(Connection) + +public: + + enum Connection{ + System, + Session + }; + + BMDBus(QObject * parent = nullptr); + +public Q_SLOTS: + + QObject* createInterface(const QString & service, const QString & path, const QString & interface, Connection bus); + +private: ///methods: + + +}; + + +#endif diff --git a/plugins/bluemonkey/config.js b/plugins/bluemonkey/config.js index cb7549e2..131247e8 100644 --- a/plugins/bluemonkey/config.js +++ b/plugins/bluemonkey/config.js @@ -27,6 +27,17 @@ dbusConnected.changed.connect(function () { {'AnswerToTheUniverse' : 'AnswerToTheUniverse'}]); }); +bluemonkey.loadModule("@PLUGIN_INSTALL_PATH@/bluemonkeyDBusModule.so"); + +if(dbus) +{ + var dbusIface = dbus.createInterface("org.freedesktop.DBus", "/", "org.freedesktop.DBus", dbus.Session); + + var reply = dbusIface.GetId(); + + bluemonkey.log("org.freedesktop.DBus.GetId() response: " + reply); +} + bluemonkey.createCustomProperty("VehicleSpeed", 10); bluemonkey.createCustomProperty("EngineSpeed", 5000); bluemonkey.createCustomProperty("PowertrainTorque", 324); diff --git a/plugins/bluemonkey/db.cpp b/plugins/bluemonkey/db.cpp index 07bb9e3f..609e7314 100644 --- a/plugins/bluemonkey/db.cpp +++ b/plugins/bluemonkey/db.cpp @@ -1,3 +1,21 @@ +/* + Copyright (C) 2012 Intel Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #include "db.h" #include diff --git a/plugins/bluemonkey/db.h b/plugins/bluemonkey/db.h index 32716dfe..33298bdc 100644 --- a/plugins/bluemonkey/db.h +++ b/plugins/bluemonkey/db.h @@ -1,3 +1,21 @@ +/* + Copyright (C) 2012 Intel Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #include #include #include diff --git a/plugins/bluemonkey/irccoms.cpp b/plugins/bluemonkey/irccoms.cpp index 3d0eaa47..02beffd7 100644 --- a/plugins/bluemonkey/irccoms.cpp +++ b/plugins/bluemonkey/irccoms.cpp @@ -1,3 +1,21 @@ +/* + Copyright (C) 2012 Intel Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #include "irccoms.h" #include #include diff --git a/plugins/bluemonkey/irccoms.h b/plugins/bluemonkey/irccoms.h index cf0ef0b8..dacfd6a4 100644 --- a/plugins/bluemonkey/irccoms.h +++ b/plugins/bluemonkey/irccoms.h @@ -1,3 +1,21 @@ +/* + Copyright (C) 2012 Intel Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #ifndef COMMUNICATION_H #define COMMUNICATION_H #include -- cgit v1.2.1