amb-qt bindings
authorKevron Rees <tripzero.kev@gmail.com>
Fri, 14 Dec 2012 23:43:01 +0000 (15:43 -0800)
committerKevron Rees <tripzero.kev@gmail.com>
Fri, 14 Dec 2012 23:43:01 +0000 (15:43 -0800)
CMakeLists.txt
plugins/dbus/CMakeLists.txt
plugins/dbus/amb-qt/CMakeLists.txt [new file with mode: 0644]
plugins/dbus/amb-qt/amb-qt_global.h [new file with mode: 0644]
plugins/dbus/amb-qt/ambqt.cpp [new file with mode: 0644]
plugins/dbus/amb-qt/ambqt.h [new file with mode: 0644]

index cf56ee1..ebd2bff 100644 (file)
@@ -20,6 +20,7 @@ option(use_qtcore "Use QCoreApplication mainloop " OFF)
 option(tpms_plugin "TPMS plugin " OFF)
 option(obd2_plugin "OBD-II plugin" ON)
 option(database_plugin "Database plugins" OFF)
+option(qt_bindings "AMB Qt DBus bindings" OFF)
 
 find_library(libtool_LIBRARY ltdl DOC "Libtool libraries")
 find_path(libtool_INCLUDE_DIR ltdl.h DOC "Libtool headers")
index 696b7d3..4e9745b 100644 (file)
@@ -12,3 +12,5 @@ target_link_libraries(dbussinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${lin
 
 install (TARGETS dbussinkplugin LIBRARY DESTINATION lib/automotive-message-broker)
 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/amb.conf DESTINATION /etc/dbus-1/system.d )
+
+add_subdirectory(amb-qt)
diff --git a/plugins/dbus/amb-qt/CMakeLists.txt b/plugins/dbus/amb-qt/CMakeLists.txt
new file mode 100644 (file)
index 0000000..90eb726
--- /dev/null
@@ -0,0 +1,22 @@
+if(qt_bindings)
+
+FIND_PACKAGE(Qt4 COMPONENTS QtCore QtDBus REQUIRED)
+include(${QT_USE_FILE})
+ADD_DEFINITIONS(${QT_DEFINITIONS})
+
+set(QT_USE_QTDBUS TRUE)
+set(QT_DONT_USE_QTGUI TRUE)
+set(ambqt_headers ambqt.h amb-qt_global.h)
+set(ambqt_sources ambqt.cpp)
+
+QT4_WRAP_CPP(ambqt_headers_moc ${ambqt_headers})
+
+include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${QT_INCLUDE_DIRS})
+
+add_library(amb-qt MODULE ${ambqt_sources} ${ambqt_headers_moc})
+
+target_link_libraries(amb-qt amb ${QT_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES})
+
+install (TARGETS amb-qt LIBRARY DESTINATION lib)
+
+endif(qt_bindings)
diff --git a/plugins/dbus/amb-qt/amb-qt_global.h b/plugins/dbus/amb-qt/amb-qt_global.h
new file mode 100644 (file)
index 0000000..e971664
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef AMBQT_GLOBAL_H
+#define AMBQT_GLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(AMBQT_LIBRARY)
+#  define AMBQTSHARED_EXPORT Q_DECL_EXPORT
+#else
+#  define AMBQTSHARED_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // AMBQT_GLOBAL_H
diff --git a/plugins/dbus/amb-qt/ambqt.cpp b/plugins/dbus/amb-qt/ambqt.cpp
new file mode 100644 (file)
index 0000000..a63e269
--- /dev/null
@@ -0,0 +1,21 @@
+#include "ambqt.h"
+#include <QDBusConnection>
+#include <QDBusInterface>
+#include <QtDebug>
+
+AmbProperty::AmbProperty(QString objectPath, QString interface, QString propertyName)
+       :QObject(),mPropertyName(propertyName)
+{
+
+       mInterface = new QDBusInterface("org.automotive.message.broker",objectPath, interface,QDBusConnection::systemBus(),this);
+
+       if(!QDBusConnection::systemBus().connect("org.automotive.message.broker", objectPath, interface, propertyName, this, SIGNAL(propertyChanged(QVariant))))
+       {
+               qDebug()<<"Failed to connect to signal";
+               qDebug()<<"path: "<<objectPath;
+               qDebug()<<"interface: "<<interface;
+               qDebug()<<"signal: "<<propertyName;
+               qDebug()<<"Error: "<<QDBusConnection::systemBus().lastError().message();
+       }
+
+}
diff --git a/plugins/dbus/amb-qt/ambqt.h b/plugins/dbus/amb-qt/ambqt.h
new file mode 100644 (file)
index 0000000..4e9cf82
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef AMBQT_H
+#define AMBQT_H
+
+#include <QObject>
+#include <QDBusInterface>
+
+class QDBusInterface;
+
+class AmbProperty: public QObject
+{
+       Q_OBJECT
+public:
+       AmbProperty(QString objectPath, QString interface, QString propertyName);
+
+       QVariant operator()() const
+       {
+               return mInterface->property(mPropertyName.toAscii().data());
+       }
+
+signals:
+       void propertyChanged(QVariant);
+
+private:
+       QString mPropertyName;
+       QDBusInterface* mInterface;
+};
+
+#endif // AMBQT_H