Changeset View
Changeset View
Standalone View
Standalone View
src/avahi_listener.cpp
Show All 13 Lines | |||||
14 | * | 14 | * | ||
15 | * You should have received a copy of the GNU Library General Public License | 15 | * You should have received a copy of the GNU Library General Public License | ||
16 | * along with this library; see the file COPYING.LIB. If not, write to | 16 | * along with this library; see the file COPYING.LIB. If not, write to | ||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "avahi_listener_p.h" | 21 | #include "avahi_listener_p.h" | ||
22 | #include "avahi-disconn-handler.h" | ||||
22 | 23 | | |||
23 | namespace KDNSSD { | 24 | namespace KDNSSD { | ||
24 | 25 | | |||
25 | AvahiListener::AvahiListener() | 26 | AvahiListener::AvahiListener() | ||
26 | { | 27 | { | ||
28 | m_connection = QObject::connect(&AvahiDisconnectHandler::instance(), &AvahiDisconnectHandler::avahiDisconnected, | ||||
jpalecek: ##m_connection## is needed to manually manage the connection, because ##AvahiListener## is not… | |||||
sitter: use a member initializer list here | |||||
29 | [this]() { | ||||
30 | m_dbusObjectPath.clear(); | ||||
31 | }); | ||||
27 | } | 32 | } | ||
The other classes ctors look super repetitive and could maybe just be moved in here. couldn't you simply make a pure virtual reset() in here that is implemented in all avahi listeners and connect to that? Specifically since the expectation is that every dbus based object switches state when avahi disappears/appears the best way to express that in a way that one doesn't forget about it moving forward would be making the compiler throw a tantrum on a not implemented reset functionality. sitter: The other classes ctors look super repetitive and could maybe just be moved in here. couldn't… | |||||
28 | 33 | | |||
29 | AvahiListener::~AvahiListener() | 34 | AvahiListener::~AvahiListener() | ||
30 | { | 35 | { | ||
36 | QObject::disconnect(m_connection); | ||||
31 | } | 37 | } | ||
32 | 38 | | |||
33 | 39 | | |||
34 | 40 | | |||
35 | } // namespace KDNSSD | 41 | } // namespace KDNSSD |
m_connection is needed to manually manage the connection, because AvahiListener is not a QObject. It is inherited by QObjects, but relying on that (and casting) would need that the QObject is initialized first which would be brittle. OTOH saving the connection handle seems hassle-free.