KDNSSD 5.109.0
servicebase.h
1/*
2 This file is part of the KDE project
3
4 SPDX-FileCopyrightText: 2004 Jakub Stachowski <qbast@go2.pl>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KDNSSDSERVICEBASE_H
10#define KDNSSDSERVICEBASE_H
11
12#include "kdnssd_export.h"
13#include <QExplicitlySharedDataPointer>
14#include <QMap>
15#include <QString>
16#include <memory>
17
18namespace KDNSSD
19{
20class ServiceBasePrivate;
21
40class KDNSSD_EXPORT ServiceBase : public QSharedData // krazy:exclude=dpointer (protected)
41{
42public:
43 typedef QExplicitlySharedDataPointer<ServiceBase> Ptr;
44
62 explicit ServiceBase(const QString &name = QString(),
63 const QString &type = QString(),
64 const QString &domain = QString(),
65 const QString &host = QString(),
66 unsigned short port = 0);
67
68 virtual ~ServiceBase();
69
73 QString serviceName() const;
74
83 QString type() const;
84
90 QString domain() const;
91
102 QString hostName() const;
103
114 unsigned short port() const;
115
146 QMap<QString, QByteArray> textData() const;
147
160 bool operator==(const ServiceBase &o) const;
173 bool operator!=(const ServiceBase &o) const;
174
175protected:
176 KDNSSD_NO_EXPORT explicit ServiceBase(ServiceBasePrivate *const d);
177
178 virtual void virtual_hook(int, void *);
179
180protected:
181 std::unique_ptr<ServiceBasePrivate> const d;
182 // We cannot use Q_DECLARE_PRIVATE_D & Q_D here because of multiple inheritance with some
183 // of the subclasses of ServiceBasePrivate, where ServiceBasePrivate is not the first base class,
184 // so reinterpret_cast as used by the functions defined with Q_DECLARE_PRIVATE_D would fail.
185 // Using a custom macro here with static_cast would require to know about the type definition
186 // of the private classes, which we though want to avoid here in the public class.
187 // So instead some custom KDNSSD_D macros are used internally...
188};
189
190/* Utility functions */
191
197bool domainIsLocal(const QString &domain);
198
199}
200
201#endif
Describes a service.
Definition servicebase.h:41
ServiceBase(const QString &name=QString(), const QString &type=QString(), const QString &domain=QString(), const QString &host=QString(), unsigned short port=0)
Creates a ServiceBase object.
bool operator==(const ServiceBase &o) const
Compares services based on name, type and domain.
bool operator!=(const ServiceBase &o) const
Compares services based on name, type and domain.
QString serviceName() const
The name of the service.
unsigned short port() const
The port number of the service.
QMap< QString, QByteArray > textData() const
Additional text data associated with the service.
QString domain() const
The domain that the service belongs to.
QString hostName() const
The hostname of the service.
QString type() const
The type of the service.