QMdnsEngine  0.1.0
Multicast DNS library for Qt applications
Signals | Public Member Functions | List of all members
QMdnsEngine::Cache Class Reference

Cache for DNS records More...

#include <qmdnsengine/cache.h>

Inheritance diagram for QMdnsEngine::Cache:

Signals

void recordExpired (const Record &record)
 Indicate that the specified record expired. More...
 
void shouldQuery (const Record &record)
 Indicate that a record will expire soon and a new query should be issued. More...
 

Public Member Functions

 Cache (QObject *parent=0)
 Create an empty cache.
 
void addRecord (const Record &record)
 Add a record to the cache. More...
 
bool lookupRecord (const QByteArray &name, quint16 type, Record &record) const
 Retrieve a single record from the cache. More...
 
bool lookupRecords (const QByteArray &name, quint16 type, QList< Record > &records) const
 Retrieve multiple records from the cache. More...
 

Detailed Description

Records are added to the cache using the addRecord() method which are then stored in the cache until they are considered to have expired, at which point they are purged. The shouldQuery() signal is used to indicate when a record is approaching expiry and the recordExpired() signal indicates when a record has expired (at which point it is removed).

The cache can be queried to retrieve one or more records matching a given type. For example, to retrieve all TXT records that match a given name:

Cache cache;
QList<QMdnsEngine::Record> records;
cache.lookupRecords("My Service._http._tcp.local.", QMdnsEngine::TXT, records);
foreach (QMdnsEngine::Record record, records) {
qDebug() << "Record:" << record.name();
}

Alternatively, lookupRecord() can be used to find a single record.

Member Function Documentation

◆ addRecord()

void QMdnsEngine::Cache::addRecord ( const Record record)
Parameters
recordadd this record to the cache

The TTL for the record will be added to the current time to calculate when the record expires. Existing records of the same name and type will be replaced, resetting their expiration.

◆ lookupRecord()

bool QMdnsEngine::Cache::lookupRecord ( const QByteArray &  name,
quint16  type,
Record record 
) const
Parameters
namename of record to retrieve or null for any
typetype of record to retrieve or ANY for all types
recordstorage for the record retrieved
Returns
true if a record was retrieved

Some record types allow multiple records to be stored with identical names and types. This method will only retrieve the first matching record. Use lookupRecords() to obtain all of the records.

◆ lookupRecords()

bool QMdnsEngine::Cache::lookupRecords ( const QByteArray &  name,
quint16  type,
QList< Record > &  records 
) const
Parameters
namename of records to retrieve or null for any
typetype of records to retrieve or ANY for all types
recordsstorage for the records retrieved
Returns
true if records were retrieved

◆ recordExpired

void QMdnsEngine::Cache::recordExpired ( const Record record)
signal
Parameters
recordreference to the record that has expired

◆ shouldQuery

void QMdnsEngine::Cache::shouldQuery ( const Record record)
signal
Parameters
recordreference to the record that will soon expire

This signal is emitted when a record reaches approximately 50%, 85%, 90%, and 95% of its lifetime.


The documentation for this class was generated from the following file: