From 209b342bb9fb52380fca9dea63e3fa601a7d3648 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Wed, 16 Jan 2013 15:48:04 +0100 Subject: [PATCH] Re-order avahi calls to make it more obvious what's going on. --- src/networkremote/avahi.cpp | 74 ++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/networkremote/avahi.cpp b/src/networkremote/avahi.cpp index c00ff6f56..799d1f442 100644 --- a/src/networkremote/avahi.cpp +++ b/src/networkremote/avahi.cpp @@ -9,26 +9,40 @@ namespace { -void LogCommit(QDBusPendingReply<> reply) { - qLog(Debug) << "Remote interface published on Avahi:" << reply.error(); -} +void AddService( + const QString domain, + const QString type, + const QString name, + quint16 port, + QDBusPendingReply path_reply); +void Commit(OrgFreedesktopAvahiEntryGroupInterface* interface); +void LogCommit(QDBusPendingReply<> reply); -void Commit(OrgFreedesktopAvahiEntryGroupInterface* interface) { - QDBusPendingReply<> reply = interface->Commit(); +} // namespace + +void Avahi::Publish( + const QString& domain, + const QString& type, + const QString& name, + quint16 port) { + OrgFreedesktopAvahiServerInterface server_interface( + "org.freedesktop.Avahi", + "/", + QDBusConnection::systemBus()); + QDBusPendingReply reply = server_interface.EntryGroupNew(); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply); - QObject::connect( - watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - watcher, SLOT(deleteLater())); - QObject::connect( - watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - interface, SLOT(deleteLater())); NewClosure( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - &LogCommit, - reply); + &AddService, + domain, type, name, port, reply); + QObject::connect( + watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + watcher, SLOT(deleteLater())); } +namespace { + void AddService( const QString domain, const QString type, @@ -72,25 +86,25 @@ void AddService( watcher, SLOT(deleteLater())); } -} // namespace - -void Avahi::Publish( - const QString& domain, - const QString& type, - const QString& name, - quint16 port) { - OrgFreedesktopAvahiServerInterface server_interface( - "org.freedesktop.Avahi", - "/", - QDBusConnection::systemBus()); - QDBusPendingReply reply = server_interface.EntryGroupNew(); +void Commit(OrgFreedesktopAvahiEntryGroupInterface* interface) { + QDBusPendingReply<> reply = interface->Commit(); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply); - NewClosure( - watcher, - SIGNAL(finished(QDBusPendingCallWatcher*)), - &AddService, - domain, type, name, port, reply); QObject::connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), watcher, SLOT(deleteLater())); + QObject::connect( + watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + interface, SLOT(deleteLater())); + NewClosure( + watcher, + SIGNAL(finished(QDBusPendingCallWatcher*)), + &LogCommit, + reply); } + +void LogCommit(QDBusPendingReply<> reply) { + qLog(Debug) << "Remote interface published on Avahi:" << reply.error(); +} + +} // namespace +