Permalink
Browse files

Give errors instead of crashing if dnssd service init fails.

  • Loading branch information...
1 parent f41fdad commit 7cd4f0d4bad535eee20bb54146d9d91d81e9fbd7 @vranki vranki committed with Mar 20, 2013
Showing with 22 additions and 9 deletions.
  1. +5 −2 AirTV-Qt/main.cpp
  2. +16 −5 AirTV-Qt/mainapplication.cpp
  3. +1 −2 AirTV-Qt/mainapplication.h
View
@@ -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;
+ }
}
@@ -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()
@@ -31,7 +31,7 @@ class MainApplication : public QObject
explicit MainApplication(QObject *parent = 0);
~MainApplication();
- void start();
+ bool start();
void stop();
private:
@@ -48,7 +48,6 @@ class MainApplication : public QObject
public slots:
void aboutToQuit();
-
};
#endif // MAINAPPLICATION_H

0 comments on commit 7cd4f0d

Please sign in to comment.