Changeset View
Changeset View
Standalone View
Standalone View
src/avahi-publicservice.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 56 | { | |||
---|---|---|---|---|---|
57 | if (fillEntryGroup()) { | 57 | if (fillEntryGroup()) { | ||
58 | commit(); | 58 | commit(); | ||
59 | } else { | 59 | } else { | ||
60 | m_parent->stop(); | 60 | m_parent->stop(); | ||
61 | emit m_parent->published(false); | 61 | emit m_parent->published(false); | ||
62 | } | 62 | } | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | void PublicServicePrivate::gotGlobalStateChanged(int state, | ||||
66 | const QString &error, | ||||
67 | QDBusMessage msg) | ||||
68 | { | ||||
69 | if (!isOurMsg(msg)) { | ||||
70 | return; | ||||
71 | } | ||||
72 | groupStateChanged(state, error); | ||||
73 | } | ||||
74 | | ||||
65 | void PublicService::setServiceName(const QString &serviceName) | 75 | void PublicService::setServiceName(const QString &serviceName) | ||
66 | { | 76 | { | ||
67 | K_D; | 77 | K_D; | ||
68 | d->m_serviceName = serviceName; | 78 | d->m_serviceName = serviceName; | ||
69 | if (d->m_running) { | 79 | if (d->m_running) { | ||
70 | d->m_group->Reset(); | 80 | d->m_group->Reset(); | ||
71 | d->tryApply(); | 81 | d->tryApply(); | ||
72 | } | 82 | } | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 158 | { | |||
152 | } | 162 | } | ||
153 | d->m_running = false; | 163 | d->m_running = false; | ||
154 | d->m_published = false; | 164 | d->m_published = false; | ||
155 | } | 165 | } | ||
156 | bool PublicServicePrivate::fillEntryGroup() | 166 | bool PublicServicePrivate::fillEntryGroup() | ||
157 | { | 167 | { | ||
158 | registerTypes(); | 168 | registerTypes(); | ||
159 | if (!m_group) { | 169 | if (!m_group) { | ||
170 | // Do not race! | ||||
171 | // https://github.com/lathiat/avahi/issues/9 | ||||
172 | // Avahi's DBus API is incredibly racey with signals getting fired | ||||
173 | // immediately after a request was made even though we may not yet be | ||||
174 | // listening. In lieu of a proper upstream fix for this we'll unfortunately | ||||
175 | // have to resort to this hack: | ||||
176 | // We register to all signals regardless of path and then filter them once | ||||
177 | // we know what "our" path is. This is much more fragile than a proper | ||||
178 | // QDBusInterface assisted signal connection but unfortunately the only way | ||||
179 | // we can reliably prevent signals getting lost in the race. | ||||
180 | // This uses a fancy trick whereby using QDBusMessage as last argument will | ||||
181 | // give us the correct signal argument types as well as the underlying | ||||
182 | // message so that we may check the message path. | ||||
183 | QDBusConnection::systemBus() | ||||
184 | .connect("org.freedesktop.Avahi", | ||||
185 | "", | ||||
186 | "org.freedesktop.Avahi.EntryGroup", | ||||
187 | "StateChanged", | ||||
188 | this, | ||||
189 | SLOT(gotGlobalStateChanged(int,QString,QDBusMessage))); | ||||
190 | m_dbusObjectPath.clear(); | ||||
191 | | ||||
160 | QDBusReply<QDBusObjectPath> rep = m_server->EntryGroupNew(); | 192 | QDBusReply<QDBusObjectPath> rep = m_server->EntryGroupNew(); | ||
161 | if (!rep.isValid()) { | 193 | if (!rep.isValid()) { | ||
162 | return false; | 194 | return false; | ||
163 | } | 195 | } | ||
164 | m_group = new org::freedesktop::Avahi::EntryGroup("org.freedesktop.Avahi", rep.value().path(), QDBusConnection::systemBus()); | 196 | | ||
165 | connect(m_group, SIGNAL(StateChanged(int,QString)), this, SLOT(groupStateChanged(int,QString))); | 197 | m_dbusObjectPath = rep.value().path(); | ||
198 | | ||||
199 | m_group = new org::freedesktop::Avahi::EntryGroup("org.freedesktop.Avahi", | ||||
200 | m_dbusObjectPath, | ||||
201 | QDBusConnection::systemBus()); | ||||
166 | } | 202 | } | ||
167 | if (m_serviceName.isNull()) { | 203 | if (m_serviceName.isNull()) { | ||
168 | QDBusReply<QString> rep = m_server->GetHostName(); | 204 | QDBusReply<QString> rep = m_server->GetHostName(); | ||
169 | if (!rep.isValid()) { | 205 | if (!rep.isValid()) { | ||
170 | return false; | 206 | return false; | ||
171 | } | 207 | } | ||
172 | m_serviceName = rep.value(); | 208 | m_serviceName = rep.value(); | ||
173 | } | 209 | } | ||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |