57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
#ifndef SCANNER_H
|
|
#define SCANNER_H
|
|
|
|
#include <QObject>
|
|
#include <QThread>
|
|
#include <dns_sd.h>
|
|
|
|
struct Record
|
|
{
|
|
};
|
|
|
|
/**
|
|
* @class Scanner
|
|
* @brief A thread that handles scanning with given mDNS query and returns.
|
|
*
|
|
*/
|
|
class Scanner : public QThread
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
/**
|
|
* @param query: e.g. "_http._tcp"
|
|
*/
|
|
explicit Scanner(QString query, QObject *parent = nullptr);
|
|
|
|
private:
|
|
void run() override;
|
|
|
|
QString m_query;
|
|
|
|
// Caching values to use across callbacks
|
|
// TODO: pass a context struct around instead of this? or does every callback run sequentially?
|
|
QString m_current_service_name;
|
|
QString m_current_host_target;
|
|
uint16_t m_current_port;
|
|
|
|
static void DNSSD_API service_resolve_callback(DNSServiceRef service, DNSServiceFlags flags, uint32_t interface_index,
|
|
DNSServiceErrorType error_code, const char *full_name,
|
|
const char *host_target, uint16_t port, uint16_t txt_len,
|
|
const unsigned char *txt_record, void *context);
|
|
static void DNSSD_API service_browse_callback(DNSServiceRef service, DNSServiceFlags flags, uint32_t interface_index,
|
|
DNSServiceErrorType error_code, const char *service_name,
|
|
const char *regtype, const char *reply_domain, void *context);
|
|
static void DNSSD_API address_info_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
|
|
DNSServiceErrorType errorCode, const char *hostname,
|
|
const struct sockaddr *address, uint32_t ttl, void *context);
|
|
|
|
public slots:
|
|
|
|
signals:
|
|
void service_found(const QString &service_name, const QString &ip, const QString &host, const uint16_t port);
|
|
void error_occurred(const QString &message);
|
|
};
|
|
|
|
#endif // SCANNER_H
|