{
"name" : "ExampleSouce",
"path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so",
- "delay" : "1"
+ "delay" : "24"
}
],
"sinks": [
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})
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);
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})
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)
#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()
{
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())
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();
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();
+ }
+}
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)
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
#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)
-#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);
};
--- /dev/null
+#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();
+}