2
* Copyright (C) 2010, 2011 Tuomo Penttinen, all rights reserved.
4
* Author: Tuomo Penttinen <tp@herqq.org>
6
* This file is part of Herqq UPnP (HUPnP) library.
8
* Herqq UPnP is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
13
* Herqq UPnP is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with Herqq UPnP. If not, see <http://www.gnu.org/licenses/>.
25
#include <HUpnpCore/HUpnp>
27
#include <QtCore/QUuid>
28
#include <QtCore/QMetaType>
37
* \brief This is a class used to depict a <em>Unique Device Name</em> (UDN), which is a
38
* unique device identifier that has to remain the same over time for a
39
* specific device instance.
41
* A valid UDN follows the format \c "uuid:"+"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
42
* where the five hex fields form up a valid UUID.
44
* \headerfile hudn.h HUdn
46
* \remarks This class is not thread-safe.
48
* \ingroup hupnp_common
50
class H_UPNP_CORE_EXPORT HUdn
52
friend H_UPNP_CORE_EXPORT quint32 qHash(const HUdn&);
53
friend H_UPNP_CORE_EXPORT bool operator==(const HUdn&, const HUdn&);
62
* Constructs a new, empty instance.
64
* Instance created by this constructor is not valid, i.e. isValid() will
72
* Constructs a new instance based on the provided value.
74
* \param value specifies the UUID of the UDN. If the provided UUID is invalid,
75
* the created HUdn is invalid as well.
79
HUdn(const QUuid& value);
82
* Constructs a new instance based on the provided value.
84
* \param value specifies the string from which the object is constructed.
85
* The argument has to contain a valid UUID and it can be prefixed with
86
* "uuid:". The UUID part in turn must be formatted along the requirements of \c QUuid:
87
* the string "must be formatted as five hex fields separated
88
* by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"
89
* where 'x' is a hex digit. The curly braces shown here are optional,
90
* but it is normal to include them. If the argument does not form a
91
* proper UUID, the created UDN is invalid.
95
HUdn(const QString& value);
98
* \brief Destroys the instance.
103
* \brief Indicates if the UDN is defined or not.
105
* \param checkLevel specifies whether the check should be done strictly
106
* according to the UDA specifications (1.0 & 1.1). That is, the UDN
107
* has to contain a proper UUID. If \c checkLevel is \e false the UDN is
108
* considered valid if it is not empty.
110
* \return true in case the UDN is valid considering the \c checkLevel argument.
112
inline bool isValid(HValidityCheckLevel checkLevel) const
114
return checkLevel == StrictChecks ? !value().isNull() : !m_value.isEmpty();
118
* \brief Returns the UUID component of the UDN.
120
* \return The UUID component of the UDN.
122
* \remarks if the UDN is not strictly valid, i.e. isValid(true) returns
123
* \e false, this method will return a null \c QUuid.
128
* \brief Returns the complete UDN value.
130
* \returns the complete UDN value when the UDN is valid.
131
* For instance, \c "uuid:5d794fc2-5c5e-4460-a023-f04a51363300" is a valid UDN.
132
* Otherwise an empty string is returned.
134
QString toString() const;
137
* \brief Returns the UUID component of the UDN as string.
139
* \returns the UUID component of the UDN as string when the UDN is valid. For instance,
140
* if the complete UDN is \c "uuid:5d794fc2-5c5e-4460-a023-f04a51363300", this method
141
* will return \c "5d794fc2-5c5e-4460-a023-f04a51363300". Otherwise an
142
* empty string is returned.
144
QString toSimpleUuid() const;
147
* Creates a new strictly valid UDN.
149
* \return a new strictly valid UDN.
151
static HUdn createUdn();
155
* Compares the two objects for equality.
157
* \return true in case the object are logically equivalent.
161
H_UPNP_CORE_EXPORT bool operator==(const HUdn&, const HUdn&);
164
* Compares the two objects for inequality.
166
* \return true in case the objects are not logically equivalent.
170
inline bool operator!=(const HUdn& obj1, const HUdn& obj2)
172
return !(obj1 == obj2);
176
* \brief Returns a value that can be used as a unique key in a hash-map identifying
179
* \param key specifies the \em UDN from which the hash value is created.
181
* \return a value that can be used as a unique key in a hash-map identifying
186
H_UPNP_CORE_EXPORT quint32 qHash(const HUdn& key);
191
Q_DECLARE_METATYPE(Herqq::Upnp::HUdn)