JDNS
Loading...
Searching...
No Matches
QJDnsSharedRequest Class Reference

Performs a DNS operation using QJDnsShared. More...

#include <qjdnsshared.h>

Inheritance diagram for QJDnsSharedRequest:

Public Types

enum  Type { Query , Publish }
 Operation type. More...
 
enum  Error {
  ErrorNoNet , ErrorGeneric , ErrorNXDomain , ErrorTimeout ,
  ErrorConflict
}
 Request error. More...
 

Signals

void resultsReady ()
 Indicates that the operation has something to report.
 

Public Member Functions

 QJDnsSharedRequest (QJDnsShared *jdnsShared, QObject *parent=0)
 Constructs a new object with the given jdnsShared and parent.
 
 ~QJDnsSharedRequest ()
 Destroys the object.
 
Type type ()
 The type of operation being performed.
 
void query (const QByteArray &name, int type)
 Perform a query operation.
 
void publish (QJDns::PublishMode m, const QJDns::Record &record)
 Perform a publish operation.
 
void publishUpdate (const QJDns::Record &record)
 Update a record that is currently published.
 
void cancel ()
 Cancels the current operation.
 
bool success () const
 Indicates whether or not the operation was successful.
 
Error error () const
 Returns the reason for error.
 
QList< QJDns::Recordresults () const
 Returns the results of the operation.
 

Friends

class QJDnsShared
 
class QJDnsSharedPrivate
 
class QJDnsSharedRequestPrivate
 

Detailed Description

Performs a DNS operation using QJDnsShared.

Note
Iris users should utilize NetNames for DNS capabilities, not QJDnsSharedRequest. See the QJDnsShared documentation for more information.

QJDnsSharedRequest is used to perform DNS operations on a QJDnsShared object. Many requests may be performed simultaneously, such that a single QJDnsShared object can be "shared" across the application. Please see the QJDnsShared documentation for more complete information about how the overall system works.

Call query() to perform a query. Call publish() (or publishUpdate()) to make DNS records available on the local network (QJDnsShared::Multicast mode only). When the operation has something to report, the resultsReady() signal is emitted. Call success() to determine the status of the operation. If success() returns false, then the operation has failed and the reason for the failure can be determined with error(). If success() returns true, then the meaning differs depending on the type of operation being performed:

Here is how you might look up an A record:

QJDnsSharedRequest *req = new QJDnsSharedRequest(jdnsShared);
connect(req, SIGNAL(resultsReady()), SLOT(req_resultsReady()));
req->query("psi-im.org", QJDns::A);
...
void req_resultsReady()
{
if(req->success())
{
// print all of the IP addresses obtained
QList<QJDns::Record> results = req->results();
foreach(QJDns::Record r, results)
{
if(r.type == QJDns::A)
printf("%s\n", qPrintable(r.address.toString()));
}
}
else
printf("Error resolving!\n");
}
Performs a DNS operation using QJDnsShared.
Definition qjdnsshared.h:236
void query(const QByteArray &name, int type)
Perform a query operation.
void resultsReady()
Indicates that the operation has something to report.
QList< QJDns::Record > results() const
Returns the results of the operation.
QJDnsSharedRequest(QJDnsShared *jdnsShared, QObject *parent=0)
Constructs a new object with the given jdnsShared and parent.
bool success() const
Indicates whether or not the operation was successful.
Definition qjdns.h:100
QHostAddress address
for A, Aaaa
Definition qjdns.h:109

Here is an example of publishing a record:

QJDnsSharedRequest *pub = new QJDnsSharedRequest(jdnsShared);
connect(pub, SIGNAL(resultsReady()), SLOT(pub_resultsReady()));
// let's publish an A record
rec.owner = "SomeComputer.local.";
rec.type = QJDns::A;
rec.ttl = 120;
rec.haveKnown = true;
rec.address = QHostAddress("192.168.0.32");
pub->publish(QJDns::Unique, rec);
...
void pub_resultsReady()
{
if(pub->success())
printf("Record published\n");
else
printf("Error publishing!\n");
}
void publish(QJDns::PublishMode m, const QJDns::Record &record)
Perform a publish operation.

To update an existing record, use publishUpdate():

// the IP address of the host changed, so make a new record
rec.owner = "SomeComputer.local.";
rec.type = QJDns::A;
rec.ttl = 120;
rec.haveKnown = true;
rec.address = QHostAddress("192.168.0.64");
// update it
pub->publishUpdate(rec);
void publishUpdate(const QJDns::Record &record)
Update a record that is currently published.

As a special exception, the address value can be left unspecified for A and Aaaa record types, which tells QJDnsShared to substitute the address value with the address of whatever interfaces the record gets published on. This is the preferred way to publish the IP address of your own machine, and in fact it is the only way to do so if you have multiple interfaces, because there will likely be a different IP address value for each interface (the record resolves to a different answer depending on which interface a query comes from).

// let's publish our own A record
rec.owner = "MyComputer.local.";
rec.type = QJDns::A;
rec.ttl = 120;
rec.haveKnown = true;
rec.address = QHostAddress();
pub->publish(QJDns::Unique, rec);

When you want to unpublish, call cancel() or destroy the QJDnsSharedRequest.

See also
QJDnsShared

Member Enumeration Documentation

◆ Error

Request error.

Enumerator
ErrorNoNet 

There are no available network interfaces to operate on.

This happens if QJDnsShared::addInterface() was not called.

ErrorGeneric 

Generic error during the operation.


ErrorNXDomain 

The name looked up does not exist.


ErrorTimeout 

The operation timed out.


ErrorConflict 

Attempt to publish an already published unique record.


◆ Type

Operation type.

Enumerator
Query 

Query operation, initiated by query()

Publish 

Publish operation, initiated by publish() or publishUpdate()

Constructor & Destructor Documentation

◆ ~QJDnsSharedRequest()

QJDnsSharedRequest::~QJDnsSharedRequest ( )

Destroys the object.

If there is an active operation, it is cancelled.

Member Function Documentation

◆ resultsReady

void QJDnsSharedRequest::resultsReady ( )
signal

Indicates that the operation has something to report.

After receiving this signal, call success() to check on the status of the operation, followed by results() or error() as appropriate.


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