added delay option to example sourc eplugin, fixed amb-qt so it compiles, added amb...
authorKevron Rees <tripzero.kev@gmail.com>
Sun, 8 Dec 2013 01:49:06 +0000 (17:49 -0800)
committerKevron Rees <tripzero.kev@gmail.com>
Tue, 10 Dec 2013 00:26:21 +0000 (16:26 -0800)
examples/dbusconfig
plugins/bluemonkey/CMakeLists.txt
plugins/dbus/abstractdbusinterface.cpp
plugins/dbus/amb-qt/CMakeLists.txt
plugins/dbus/amb-qt/ambqt.cpp
plugins/dbus/amb-qt/ambqt.h
plugins/dbus/amb-qt/ambqtquick.cpp
plugins/dbus/amb-qt/ambqtquick.h
plugins/dbus/amb-qt/test.cpp [new file with mode: 0644]

index a0894db..502f21a 100644 (file)
@@ -3,7 +3,7 @@
                {
                        "name" : "ExampleSouce",
                        "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so",
-                       "delay" : "1"
+                       "delay" : "24"
                }
        ],
        "sinks": [
index ff04573..2a0c733 100644 (file)
@@ -12,7 +12,6 @@ if(Qt5Core_FOUND)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
        message(STATUS "size of void_p: ${CMAKE_SIZEOF_VOID_P}")
        if(CMAKE_SIZEOF_VOID_P MATCHES "8")
-               message(STATUS "can has 64bits")
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large")
        endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
        add_definitions(${Qt5Core_DEFINITIONS})
index 16f3f8c..e2a42b6 100644 (file)
@@ -330,6 +330,7 @@ void AbstractDBusInterface::updateValue(AbstractProperty *property)
        GError *error = NULL;
        GVariant* val = g_variant_ref(property->toGVariant());
 
+       /// TODO deprecate this.  there's no need for two signals to be sent
        g_dbus_connection_emit_signal(mConnection, NULL, mObjectPath.c_str(), mInterfaceName.c_str(), string(property->name() + "Changed").c_str(),
                                                                  g_variant_new("(vd)",val,property->timestamp()), &error);
 
index 742ea70..1bf54b7 100644 (file)
@@ -1,19 +1,29 @@
 if(qt_bindings)
 
-FIND_PACKAGE(Qt4 COMPONENTS QtCore QtDBus QtDeclarative REQUIRED)
-include(${QT_USE_FILE})
-ADD_DEFINITIONS(${QT_DEFINITIONS})
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Quick REQUIRED)
+find_package(Qt5DBus REQUIRED)
+
+if(Qt5Core_FOUND)
+       message(STATUS "using Qt5")
+
+       set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ${Qt5Quick_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS})
+       set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Quick_LIBRARIES} ${Qt5DBus_LIBRARIES})
+       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
+       message(STATUS "size of void_p: ${CMAKE_SIZEOF_VOID_P}")
+       if(CMAKE_SIZEOF_VOID_P MATCHES "8")
+               message(STATUS "can has 64bits")
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcmodel=large")
+       endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
+       add_definitions(${Qt5Core_DEFINITIONS})
+       set(CMAKE_AUTOMOC ON)
+endif(Qt5Core_FOUND)
 
-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)
 set(ambqtquick_sources ambqtquick.cpp)
 set(ambqtquick_headers ambqtquick.h)
 
-QT4_WRAP_CPP(ambqt_headers_moc ${ambqt_headers})
-QT4_WRAP_CPP(ambqtquick_headers_moc ${ambqtquick_headers})
-
 include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${QT_INCLUDE_DIRS})
 
 add_library(amb-qt SHARED ${ambqt_sources} ${ambqt_headers_moc})
@@ -22,10 +32,13 @@ add_library(ambqtquick MODULE ${ambqtquick_sources} ${ambqtquick_headers_moc})
 target_link_libraries(amb-qt amb ${QT_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES})
 target_link_libraries(ambqtquick amb-qt ${QT_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES})
 
+add_executable(ambtestclient test.cpp)
+target_link_libraries(ambtestclient amb amb-qt ${QT_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES})
+
 install (TARGETS amb-qt LIBRARY DESTINATION lib${LIB_SUFFIX})
 
 install (FILES ${ambqt_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/ COMPONENT Devel)
-install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/qmldir DESTINATION ${LIB_INSTALL_DIR}/qt4/imports/amb COMPONENT Devel)
-install (TARGETS ambqtquick DESTINATION ${LIB_INSTALL_DIR}/qt4/imports/amb)
-
+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/qmldir DESTINATION ${LIB_INSTALL_DIR}/qt5/qml/amb COMPONENT Devel)
+install (TARGETS ambqtquick DESTINATION ${LIB_INSTALL_DIR}/qt5/qml/amb)
+install (TARGETS ambtestclient RUNTIME DESTINATION bin)
 endif(qt_bindings)
index 1e8eac7..6a3faeb 100644 (file)
@@ -2,18 +2,26 @@
 #include <QDBusConnection>
 #include <QDBusInterface>
 #include <QtDebug>
+#include <QDBusReply>
 
 AmbProperty::AmbProperty(QString op, QString iface, QString propName)
-       :QObject(), mPropertyName(propName),mInterfaceName(iface), mObjectPath(op),mDBusInterface(NULL)
+       :QObject(), mPropertyName(propName),mInterfaceName(iface), mObjectPath(op),mDBusInterface(NULL),mZone(0)
 {
        connect();
 }
 
 
-void AmbProperty::propertyChangedSlot(QDBusVariant val, double ts)
+void AmbProperty::propertyChangedSlot(QString, QVariantMap values, QVariantMap )
 {
-       valueChanged(val.variant());
-       propertyChanged(val.variant(), ts);
+       valueChanged(values);
+}
+
+void AmbProperty::propertyChanged1(QDBusVariant val, double t)
+{
+       mTime = t;
+       mValue = val.variant();
+
+       signalChanged(mValue);
 }
 
 void AmbProperty::connect()
@@ -22,6 +30,13 @@ void AmbProperty::connect()
        {
                delete mDBusInterface;
        }
+
+       if(mObjectPath.isEmpty())
+               getObjectPath();
+
+       if(mInterfaceName.isEmpty())
+               mInterfaceName = "org.automotive."+mPropertyName;
+
        mDBusInterface = new QDBusInterface("org.automotive.message.broker",objectPath(), interfaceName(), QDBusConnection::systemBus(),this);
 
        if(!mDBusInterface->isValid())
@@ -35,7 +50,20 @@ void AmbProperty::connect()
        QString signalName = propertyName() + "Changed";
 
 
-       if(!QDBusConnection::systemBus().connect("org.automotive.message.broker", objectPath(), interfaceName(), signalName, this, SLOT(propertyChangedSlot(QDBusVariant,double))))
+       if(!QDBusConnection::systemBus().connect("org.automotive.message.broker", objectPath(), "org.freedesktop.DBus.Properties",
+                                                                                        "PropertiesChanged", this, SLOT(propertyChangedSlot(QString,QVariantMap,QVariantMap))))
+       {
+               qDebug()<<"Failed to connect to signal";
+               qDebug()<<"path: "<<objectPath();
+               qDebug()<<"interface: "<<interfaceName();
+               qDebug()<<"signal: "<<propertyName();
+               qDebug()<<"Error: "<<QDBusConnection::systemBus().lastError().message();
+       }
+
+       ///TODO: only use PropertiesChanged...  treat AmbProperty like an object rather than a representation of just a single property in the object
+
+       if(!QDBusConnection::systemBus().connect("org.automotive.message.broker", objectPath(), mInterfaceName,
+                                                                                        signalName, this, SLOT(propertyChanged1(QDBusVariant,double))))
        {
                qDebug()<<"Failed to connect to signal";
                qDebug()<<"path: "<<objectPath();
@@ -44,3 +72,21 @@ void AmbProperty::connect()
                qDebug()<<"Error: "<<QDBusConnection::systemBus().lastError().message();
        }
 }
+
+void AmbProperty::getObjectPath()
+{
+       QDBusInterface managerIface("org.automotive.message.broker","/","org.automotive.Manager", QDBusConnection::systemBus(), this);
+
+       if(!managerIface.isValid())
+       {
+               qDebug()<<"Failed to create manager interface";
+               return;
+       }
+
+       QDBusReply<QDBusObjectPath> reply = managerIface.call("FindObjectForZone", mPropertyName, mZone);
+
+       if(reply.isValid())
+       {
+               mObjectPath = reply.value().path();
+       }
+}
index d004197..3d7e793 100644 (file)
@@ -24,26 +24,20 @@ class AmbProperty: public QObject
        AUTOPROPERTY(QString, interfaceName, InterfaceName)
        Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath)
        AUTOPROPERTY(QString, objectPath, ObjectPath)
+       Q_PROPERTY(int zone READ zone WRITE setZone)
+       AUTOPROPERTY(int, zone, Zone)
+       Q_PROPERTY(double time READ time)
+
 
        public:
 
-               AmbProperty():mDBusInterface(NULL) { }
+               AmbProperty():mDBusInterface(NULL),mZone(0),mTime(0) { }
 
        AmbProperty(QString op, QString iface, QString propName);
 
        QVariant value()
        {
-               if(!mDBusInterface || !mDBusInterface->isValid())
-               {
-                       qDebug()<<"error Interface is not valid: "<<interfaceName();
-                       return QVariant::Invalid;
-               }
-
-               QVariant value = mDBusInterface->property(propertyName().toAscii().data());
-
-               qDebug()<<"property "<<propertyName()<<" value: "<<value<<" isvalid? "<<(QVariant::Invalid == value);
-
-               return value;
+               return mValue;
        }
 
        void setValue(QVariant v)
@@ -53,19 +47,29 @@ class AmbProperty: public QObject
                        qDebug()<<"error Interface is not valid "<<interfaceName();
                }
 
-               mDBusInterface->setProperty(propertyName().toAscii(), v);
+               mDBusInterface->setProperty(propertyName().toUtf8(), v);
        }
 
-Q_SIGNALS:
-       void propertyChanged(QVariant val, double time);
+       double time(){ return mTime; }
+
+Q_SIGNALS:     
        void valueChanged(QVariant val);
 
+       ///TODO: remove
+       void signalChanged(QVariant val);
+
 public Q_SLOTS:
-       void propertyChangedSlot(QDBusVariant val, double ts);
        void connect();
 
+private Q_SLOTS:
+       void propertyChangedSlot(QString, QVariantMap values, QVariantMap);
+       void propertyChanged1(QDBusVariant, double);
+
 private:
+       void getObjectPath();
        QDBusInterface* mDBusInterface;
+       double mTime;
+       QVariant mValue;
 };
 
 #endif // AMBQT_H
index 0c9d60a..c5102a9 100644 (file)
@@ -1,15 +1,14 @@
 #include "ambqtquick.h"
-
-#include <QtDeclarative>
+#include <QtQml/qqml.h>
 
 void Components::registerTypes(const char *uri)
 {
        qmlRegisterType<AmbProperty>(uri,0,1,"AutomotivePropertyItem");
+
 }
 
-void Components::initializeEngine(QDeclarativeEngine *, const char *)
+void Components::initializeEngine(QQmlEngine *, const char *)
 {
 
 }
 
-Q_EXPORT_PLUGIN(Components)
index 07054c3..a48104a 100644 (file)
@@ -1,12 +1,14 @@
-#include <QDeclarativeExtensionPlugin>
+#include <QQmlExtensionPlugin>
 #include "ambqt.h"
 
-class Components : public QDeclarativeExtensionPlugin
+class Components : public QQmlExtensionPlugin
 {
        Q_OBJECT
+       Q_PLUGIN_METADATA(IID "org.automotive.qmlplugin")
 public:
 
+
        void registerTypes(const char *uri);
-       void initializeEngine(QDeclarativeEngine *engine, const char *uri);
+       void initializeEngine(QQmlEngine *engine, const char *uri);
 
 };
diff --git a/plugins/dbus/amb-qt/test.cpp b/plugins/dbus/amb-qt/test.cpp
new file mode 100644 (file)
index 0000000..6eb88eb
--- /dev/null
@@ -0,0 +1,35 @@
+#include "ambqt.h"
+#include "timestamp.h"
+
+#include <QCoreApplication>
+
+#include <debugout.h>
+#include <iostream>
+
+int main(int argc, char** argv)
+{
+       QCoreApplication app(argc,argv);
+
+       AmbProperty speed;
+
+       double totalLatency=0;
+       int numSamples=0;
+
+       QObject::connect(&speed, &AmbProperty::signalChanged,[&](QVariant val)
+       {
+               double t1 = speed.time();
+               double t2 = amb::currentTime();
+
+               double latency = (t2-t1)*1000.0;
+
+               DebugOut(0)<<"latency: "<<latency<<std::endl;
+               totalLatency+=latency;
+               numSamples++;
+               DebugOut(0)<<"Average: "<<totalLatency / numSamples<<std::endl;
+       });
+
+       speed.setPropertyName("VehicleSpeed");
+       speed.connect();
+
+       return app.exec();
+}