File indexing completed on 2024-04-28 15:22:05

0001 /*
0002     This file is part of the KDE project
0003 
0004     SPDX-FileCopyrightText: 2018 Harald Sitter <sitter@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef AVAHILISTENER_H
0010 #define AVAHILISTENER_H
0011 
0012 #include <QDBusMessage>
0013 #include <QString>
0014 
0015 namespace KDNSSD
0016 {
0017 // Assists with listening to Avahi for all signals and then checking if the
0018 // a given dbus message is meant for us or not.
0019 // Subclass and set the object path to object path you should be listening to.
0020 // Messages may then be run through isOurMsg to determine if they target the
0021 // object at hand.
0022 class AvahiListener
0023 {
0024 public:
0025     explicit AvahiListener();
0026     virtual ~AvahiListener();
0027 
0028     // This method gets called a lot but doesn't do much. Suggest inlining.
0029     inline bool isOurMsg(const QDBusMessage &msg) const
0030     {
0031         if (m_dbusObjectPath.isEmpty() || m_dbusObjectPath != msg.path()) {
0032             return false;
0033         }
0034         return true;
0035     }
0036 
0037     QString m_dbusObjectPath; // public so !Private objects can access it
0038 };
0039 
0040 } // namespace KDNSSD
0041 
0042 #endif // AVAHILISTENER_H