Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
仰若水
qmdnsengine
Commits
1b8a6052
Unverified
Commit
1b8a6052
authored
7 years ago
by
Nathan Osman
Browse files
Options
Download
Email Patches
Plain Diff
Update documentation for Browser class.
parent
53b697be
master
dev
qt6
0.2.0
0.1.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/qmdnsengine/browser.h
+37
-2
src/include/qmdnsengine/browser.h
src/src/browser.cpp
+8
-5
src/src/browser.cpp
with
45 additions
and
7 deletions
+45
-7
src/include/qmdnsengine/browser.h
View file @
1b8a6052
...
...
@@ -40,7 +40,34 @@ class Service;
class
QMDNSENGINE_EXPORT
BrowserPrivate
;
/**
* @brief Find local services
* @brief %Browser for local services
*
* This class provides a simple way to discover services on the local network.
* A cache may be provided in the constructor to store records for future
* queries.
*
* To browse for services of any type:
*
* @code
* QMdnsEngine::Browser browser(&server, QMdnsEngine::MdnsBrowseType);
* @endcode
*
* To browse for services of a specific type:
*
* @code
* QMdnsEngine::Browser browser(&server, "_http._tcp.local.");
* @endcode
*
* When a service is found, the serviceAdded() signal is emitted:
*
* @code
* connect(&browser, &QMdnsEngine::Browser::serviceAdded, [](const QMdnsEngine::Service &service) {
* qDebug() << "Service added:" << service.name();
* });
* @endcode
*
* The serviceUpdated() and serviceRemoved() signals are emitted when services
* are updated (their properties change) or are removed, respectively.
*/
class
QMDNSENGINE_EXPORT
Browser
:
public
QObject
{
...
...
@@ -61,6 +88,10 @@ Q_SIGNALS:
/**
* @brief Indicate that a new service has been added
*
* This signal is emitted when the PTR and SRV records for a service are
* received. If TXT records are received later, the serviceUpdated()
* signal will be emitted.
*/
void
serviceAdded
(
const
Service
&
service
);
...
...
@@ -68,12 +99,16 @@ Q_SIGNALS:
* @brief Indicate that the specified service was updated
*
* This signal is emitted when the SRV record for a service (identified by
* its name and type) has changed.
* its name and type)
or a TXT record
has changed.
*/
void
serviceUpdated
(
const
Service
&
service
);
/**
* @brief Indicate that the specified service was removed
*
* This signal is emitted when an essential record (PTR or SRV) is
* expiring from the cache. This will also occur when an updated PTR or
* SRV record is received with a TTL of 0.
*/
void
serviceRemoved
(
const
Service
&
service
);
...
...
This diff is collapsed.
Click to expand it.
src/src/browser.cpp
View file @
1b8a6052
...
...
@@ -43,7 +43,6 @@ BrowserPrivate::BrowserPrivate(Browser *browser, AbstractServer *server, const Q
cache
(
existingCache
?
existingCache
:
new
Cache
(
this
))
{
connect
(
server
,
&
AbstractServer
::
messageReceived
,
this
,
&
BrowserPrivate
::
onMessageReceived
);
connect
(
cache
,
&
Cache
::
shouldQuery
,
this
,
&
BrowserPrivate
::
onShouldQuery
);
connect
(
cache
,
&
Cache
::
recordExpired
,
this
,
&
BrowserPrivate
::
onRecordExpired
);
connect
(
&
queryTimer
,
&
QTimer
::
timeout
,
this
,
&
BrowserPrivate
::
onQueryTimeout
);
...
...
@@ -52,6 +51,7 @@ BrowserPrivate::BrowserPrivate(Browser *browser, AbstractServer *server, const Q
queryTimer
.
setSingleShot
(
true
);
serviceTimer
.
setSingleShot
(
true
);
// Immediately begin browsing for services
onQueryTimeout
();
}
...
...
@@ -59,16 +59,19 @@ BrowserPrivate::BrowserPrivate(Browser *browser, AbstractServer *server, const Q
bool
BrowserPrivate
::
updateService
(
const
QByteArray
&
fqName
)
{
QByteArray
serviceName
=
fqName
.
left
(
fqName
.
indexOf
(
'.'
));
QByteArray
serviceType
=
fqName
.
mid
(
fqName
.
indexOf
(
'.'
)
+
1
);
// Split the FQDN into service name and type
int
index
=
fqName
.
indexOf
(
'.'
);
QByteArray
serviceName
=
fqName
.
left
(
index
);
QByteArray
serviceType
=
fqName
.
mid
(
index
+
1
);
// Immediately return if a PTR record does not exist
Record
ptrRecord
,
srvRecord
;
Record
ptrRecord
;
if
(
!
cache
->
lookupRecord
(
serviceType
,
PTR
,
ptrRecord
))
{
return
false
;
}
// If a SRV record is missing, query for it
// If a SRV record is missing, query for it (by returning true)
Record
srvRecord
;
if
(
!
cache
->
lookupRecord
(
fqName
,
SRV
,
srvRecord
))
{
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help