Give errors instead of crashing if dnssd service init fails.
authorVille Ranki <ville.ranki@iki.fi>
Wed, 20 Mar 2013 12:49:03 +0000 (14:49 +0200)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Sat, 23 Mar 2013 20:36:58 +0000 (22:36 +0200)
AirTV-Qt/main.cpp
AirTV-Qt/mainapplication.cpp
AirTV-Qt/mainapplication.h

index 6c1724f4e9c17900cc0c00ad705b4438ae06697b..a84258cf7bd2a8cb22e7be37bd7c7fd42343188a 100644 (file)
@@ -38,7 +38,10 @@ int main(int argc, char *argv[])
     MainApplication m;
     QObject::connect(&m, SIGNAL(quitRequested()), &a, SLOT(quit()));
     QObject::connect(&a, SIGNAL(aboutToQuit()), &m, SLOT(aboutToQuit()));
-    m.start();
 
-    return a.exec();
+    if(m.start()) {
+        return a.exec();
+    } else {
+        return EXIT_FAILURE;
+    }
 }
index 62b3f62857f2c39b46f91189f9fef765525428ce..f7b3e4baaa76a20c924520126ce0c8b060d4e558 100644 (file)
@@ -1,6 +1,7 @@
 #include "mainapplication.h"
 
 #include <QDebug>
+#include <QCoreApplication>
 
 MainApplication::MainApplication(QObject *parent) :
     QObject(parent)
@@ -9,10 +10,6 @@ MainApplication::MainApplication(QObject *parent) :
     dnssdService = new DnssdService(0);
     trayIconMenu = new QMenu(0);
 
-    // Initialize the service
-    raopService->init(10, &m_callbacks);
-    dnssdService->init();
-
     quitAction = new QAction(tr("&Quit"), trayIconMenu);
     connect(quitAction, SIGNAL(triggered()), this, SIGNAL(quitRequested()));
     trayIconMenu->addAction(quitAction);
@@ -30,14 +27,28 @@ MainApplication::~MainApplication()
     delete raopService;
 }
 
-void MainApplication::start()
+bool MainApplication::start()
 {
+    // Initialize the service
+    bool initSuccess = false;
+    initSuccess = raopService->init(10, &m_callbacks);
+    if(!initSuccess) {
+        qDebug() << "Error initializing raop service";
+        return false;
+    }
+    initSuccess &= dnssdService->init();
+    if(!initSuccess) {
+        qDebug() << "Error initializing dnssd service";
+        return false;
+    }
+
     char chwaddr[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB };
     QByteArray hwaddr(chwaddr, sizeof(chwaddr));
 
     raopService->start(5000, hwaddr);
     dnssdService->registerRaop("Shairplay", 5000, hwaddr);
     trayIcon->show();
+    return true;
 }
 
 void MainApplication::stop()
index b24b791680ce4ae40c1ff662ab772cd5730d4c0f..3aa415112f4f2200b0a732b0666e730ebcdfa1c0 100644 (file)
@@ -31,7 +31,7 @@ public:
     explicit MainApplication(QObject *parent = 0);
     ~MainApplication();
 
-    void start();
+    bool start();
     void stop();
 
 private:
@@ -48,7 +48,6 @@ signals:
 
 public slots:
     void aboutToQuit();
-
 };
 
 #endif // MAINAPPLICATION_H