From: Ville Ranki Date: Wed, 20 Mar 2013 12:49:03 +0000 (+0200) Subject: Give errors instead of crashing if dnssd service init fails. X-Git-Tag: upstream/0.9.0~4^2~42 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7cd4f0d4bad535eee20bb54146d9d91d81e9fbd7;p=deb_shairplay.git Give errors instead of crashing if dnssd service init fails. --- diff --git a/AirTV-Qt/main.cpp b/AirTV-Qt/main.cpp index 6c1724f..a84258c 100644 --- a/AirTV-Qt/main.cpp +++ b/AirTV-Qt/main.cpp @@ -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; + } } diff --git a/AirTV-Qt/mainapplication.cpp b/AirTV-Qt/mainapplication.cpp index 62b3f62..f7b3e4b 100644 --- a/AirTV-Qt/mainapplication.cpp +++ b/AirTV-Qt/mainapplication.cpp @@ -1,6 +1,7 @@ #include "mainapplication.h" #include +#include 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() diff --git a/AirTV-Qt/mainapplication.h b/AirTV-Qt/mainapplication.h index b24b791..3aa4151 100644 --- a/AirTV-Qt/mainapplication.h +++ b/AirTV-Qt/mainapplication.h @@ -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