main: instantiate a afm_user_daemon proxy 41/9341/1
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Wed, 10 May 2017 12:09:46 +0000 (14:09 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Wed, 10 May 2017 12:09:46 +0000 (14:09 +0200)
* Create a single org::AGL::afm::user instance.
* Do not make use of static object construction/destruction.
* Use QScopedPointer in main() to manage the resource.
* Users of this instance use an extern declaration of the global
  variable.

Change-Id: Ia6db7aae8c8f6b135fe62bda495c68fdef004081
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
homescreen/src/main.cpp

index 47d4f16..59a259e 100644 (file)
 #include "statusbarmodel.h"
 #include "applicationmodel.h"
 
+#include "afm_user_daemon_proxy.h"
+
+// XXX: We want this DBus connection to be shared across the different
+// QML objects, is there another way to do this, a nice way, perhaps?
+org::AGL::afm::user *afm_user_daemon_proxy;
+
+namespace {
+
+struct Cleanup {
+    static inline void cleanup(org::AGL::afm::user *p) {
+        delete p;
+        afm_user_daemon_proxy = Q_NULLPTR;
+    }
+};
+
 void noOutput(QtMsgType, const QMessageLogContext &, const QString &)
 {
 }
 
+}
+
 int main(int argc, char *argv[])
 {
     QGuiApplication a(argc, argv);
 
+    QScopedPointer<org::AGL::afm::user, Cleanup> afm_user_daemon_proxy(new org::AGL::afm::user("org.AGL.afm.user",
+                                                                                               "/org/AGL/afm/user",
+                                                                                               QDBusConnection::sessionBus(),
+                                                                                               0));
+    ::afm_user_daemon_proxy = afm_user_daemon_proxy.data();
+
     QCoreApplication::setOrganizationDomain("LinuxFoundation");
     QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
     QCoreApplication::setApplicationName("HomeScreen");