添加广播MDNS服务
This commit is contained in:
13
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/CMakeLists.txt
vendored
Normal file
13
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
set(EXAMPLES
|
||||
browser
|
||||
provider
|
||||
)
|
||||
|
||||
foreach(EXAMPLE ${EXAMPLES})
|
||||
set(EXAMPLE_DIR "${EXAMPLES_INSTALL_DIR}/${EXAMPLE}")
|
||||
add_subdirectory(${EXAMPLE})
|
||||
install(DIRECTORY ${EXAMPLE}
|
||||
DESTINATION "${EXAMPLES_INSTALL_DIR}"
|
||||
COMPONENT examples
|
||||
)
|
||||
endforeach()
|
||||
18
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/CMakeLists.txt
vendored
Normal file
18
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
set(SRC
|
||||
browser.cpp
|
||||
mainwindow.cpp
|
||||
servicemodel.cpp
|
||||
)
|
||||
|
||||
add_executable(browser WIN32 ${SRC})
|
||||
|
||||
set_target_properties(browser PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
)
|
||||
|
||||
target_link_libraries(browser qmdnsengine Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
install(TARGETS browser
|
||||
RUNTIME DESTINATION "${EXAMPLE_DIR}"
|
||||
COMPONENT examples
|
||||
)
|
||||
37
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/browser.cpp
vendored
Normal file
37
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/browser.cpp
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
145
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/mainwindow.cpp
vendored
Normal file
145
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/mainwindow.cpp
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLineEdit>
|
||||
#include <QListView>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QSplitter>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include <qmdnsengine/mdns.h>
|
||||
#include <qmdnsengine/service.h>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "servicemodel.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QMdnsEngine::Service)
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: mServiceModel(nullptr),
|
||||
mResolver(nullptr)
|
||||
{
|
||||
setWindowTitle(tr("mDNS Browser"));
|
||||
resize(640, 480);
|
||||
|
||||
mServiceType = new QLineEdit(tr("_http._tcp.local."));
|
||||
mStartStop = new QPushButton(tr("Browse"));
|
||||
mServices = new QListView;
|
||||
mAddresses = new QListWidget;
|
||||
mAttributes = new QTableWidget;
|
||||
mAttributes->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
QVBoxLayout *rootLayout = new QVBoxLayout;
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(rootLayout);
|
||||
setCentralWidget(widget);
|
||||
|
||||
QCheckBox *any = new QCheckBox(tr("Any"));
|
||||
|
||||
QHBoxLayout *typeLayout = new QHBoxLayout;
|
||||
typeLayout->addWidget(mServiceType, 1);
|
||||
typeLayout->addWidget(any);
|
||||
typeLayout->addWidget(mStartStop);
|
||||
rootLayout->addLayout(typeLayout);
|
||||
|
||||
QSplitter *vSplitter = new QSplitter;
|
||||
vSplitter->setOrientation(Qt::Vertical);
|
||||
vSplitter->addWidget(mAddresses);
|
||||
vSplitter->addWidget(mAttributes);
|
||||
|
||||
QSplitter *hSplitter = new QSplitter;
|
||||
hSplitter->addWidget(mServices);
|
||||
hSplitter->addWidget(vSplitter);
|
||||
|
||||
QHBoxLayout *servicesLayout = new QHBoxLayout;
|
||||
servicesLayout->addWidget(hSplitter);
|
||||
rootLayout->addLayout(servicesLayout);
|
||||
|
||||
connect(any, &QCheckBox::toggled, this, &MainWindow::onToggled);
|
||||
connect(mStartStop, &QPushButton::clicked, this, &MainWindow::onClicked);
|
||||
}
|
||||
|
||||
void MainWindow::onToggled(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
mServiceType->setText(QMdnsEngine::MdnsBrowseType);
|
||||
}
|
||||
mServiceType->setEnabled(!checked);
|
||||
}
|
||||
|
||||
void MainWindow::onClicked()
|
||||
{
|
||||
if (mServiceModel) {
|
||||
mServices->setModel(nullptr);
|
||||
delete mServiceModel;
|
||||
mAttributes->clear();
|
||||
mAttributes->setColumnCount(0);
|
||||
}
|
||||
|
||||
mServiceModel = new ServiceModel(&mServer, mServiceType->text().toUtf8());
|
||||
mServices->setModel(mServiceModel);
|
||||
|
||||
connect(mServices->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::onSelectionChanged);
|
||||
}
|
||||
|
||||
void MainWindow::onSelectionChanged(const QItemSelection &selected, const QItemSelection &)
|
||||
{
|
||||
mAddresses->clear();
|
||||
mAttributes->clear();
|
||||
mAttributes->setColumnCount(0);
|
||||
|
||||
if (mResolver) {
|
||||
delete mResolver;
|
||||
mResolver = nullptr;
|
||||
}
|
||||
|
||||
if (selected.count()) {
|
||||
auto service = mServiceModel->data(selected.at(0).topLeft(), Qt::UserRole).value<QMdnsEngine::Service>();
|
||||
|
||||
// Show TXT values
|
||||
auto attributes = service.attributes();
|
||||
mAttributes->setRowCount(attributes.keys().count());
|
||||
mAttributes->setColumnCount(2);
|
||||
mAttributes->setHorizontalHeaderLabels({tr("Key"), tr("Value")});
|
||||
mAttributes->horizontalHeader()->setStretchLastSection(true);
|
||||
mAttributes->verticalHeader()->setVisible(false);
|
||||
int row = 0;
|
||||
for (auto i = attributes.constBegin(); i != attributes.constEnd(); ++i, ++row) {
|
||||
mAttributes->setItem(row, 0, new QTableWidgetItem(QString(i.key())));
|
||||
mAttributes->setItem(row, 1, new QTableWidgetItem(QString(i.value())));
|
||||
}
|
||||
|
||||
// Resolve the address
|
||||
mResolver = new QMdnsEngine::Resolver(&mServer, service.hostname(), nullptr, this);
|
||||
connect(mResolver, &QMdnsEngine::Resolver::resolved, [this](const QHostAddress &address) {
|
||||
mAddresses->addItem(address.toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
70
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/mainwindow.h
vendored
Normal file
70
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/mainwindow.h
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <qmdnsengine/server.h>
|
||||
#include <qmdnsengine/resolver.h>
|
||||
|
||||
class QItemSelection;
|
||||
class QLineEdit;
|
||||
class QListView;
|
||||
class QListWidget;
|
||||
class QPushButton;
|
||||
class QTableWidget;
|
||||
|
||||
class ServiceModel;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
MainWindow();
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void onToggled(bool checked);
|
||||
void onClicked();
|
||||
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
|
||||
private:
|
||||
|
||||
QMdnsEngine::Server mServer;
|
||||
ServiceModel *mServiceModel;
|
||||
|
||||
QLineEdit *mServiceType;
|
||||
QPushButton *mStartStop;
|
||||
QListView *mServices;
|
||||
QListWidget *mAddresses;
|
||||
QTableWidget *mAttributes;
|
||||
|
||||
QMdnsEngine::Resolver *mResolver;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
97
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/servicemodel.cpp
vendored
Normal file
97
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/servicemodel.cpp
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "servicemodel.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QMdnsEngine::Service)
|
||||
|
||||
ServiceModel::ServiceModel(QMdnsEngine::Server *server, const QByteArray &type)
|
||||
: mBrowser(server, type, &cache)
|
||||
{
|
||||
connect(&mBrowser, &QMdnsEngine::Browser::serviceAdded, this, &ServiceModel::onServiceAdded);
|
||||
connect(&mBrowser, &QMdnsEngine::Browser::serviceUpdated, this, &ServiceModel::onServiceUpdated);
|
||||
connect(&mBrowser, &QMdnsEngine::Browser::serviceRemoved, this, &ServiceModel::onServiceRemoved);
|
||||
}
|
||||
|
||||
int ServiceModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return mServices.count();
|
||||
}
|
||||
|
||||
QVariant ServiceModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// Ensure the index points to a valid row
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= mServices.count()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QMdnsEngine::Service service = mServices.at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return QString("%1 (%2)")
|
||||
.arg(QString(service.name()))
|
||||
.arg(QString(service.type()));
|
||||
case Qt::UserRole:
|
||||
return QVariant::fromValue(service);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ServiceModel::onServiceAdded(const QMdnsEngine::Service &service)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), mServices.count(), mServices.count());
|
||||
mServices.append(service);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ServiceModel::onServiceUpdated(const QMdnsEngine::Service &service)
|
||||
{
|
||||
int i = findService(service.name());
|
||||
if (i != -1) {
|
||||
mServices.replace(i, service);
|
||||
emit dataChanged(index(i), index(i));
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceModel::onServiceRemoved(const QMdnsEngine::Service &service)
|
||||
{
|
||||
int i = findService(service.name());
|
||||
if (i != -1) {
|
||||
beginRemoveRows(QModelIndex(), i, i);
|
||||
mServices.removeAt(i);
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
int ServiceModel::findService(const QByteArray &name)
|
||||
{
|
||||
for (auto i = mServices.constBegin(); i != mServices.constEnd(); ++i) {
|
||||
if ((*i).name() == name) {
|
||||
return i - mServices.constBegin();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
62
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/servicemodel.h
vendored
Normal file
62
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/browser/servicemodel.h
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SERVICEMODEL_H
|
||||
#define SERVICEMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QList>
|
||||
|
||||
#include <qmdnsengine/browser.h>
|
||||
#include <qmdnsengine/cache.h>
|
||||
#include <qmdnsengine/service.h>
|
||||
#include <qmdnsengine/server.h>
|
||||
|
||||
class ServiceModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
ServiceModel(QMdnsEngine::Server *server, const QByteArray &type);
|
||||
|
||||
virtual int rowCount(const QModelIndex &parent) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void onServiceAdded(const QMdnsEngine::Service &service);
|
||||
void onServiceUpdated(const QMdnsEngine::Service &service);
|
||||
void onServiceRemoved(const QMdnsEngine::Service &service);
|
||||
|
||||
private:
|
||||
|
||||
int findService(const QByteArray &name);
|
||||
|
||||
QMdnsEngine::Cache cache;
|
||||
QMdnsEngine::Browser mBrowser;
|
||||
QList<QMdnsEngine::Service> mServices;
|
||||
};
|
||||
|
||||
#endif // SERVICEMODEL_H
|
||||
BIN
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider.zip
vendored
Normal file
BIN
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider.zip
vendored
Normal file
Binary file not shown.
13
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/CMakeLists.txt
vendored
Normal file
13
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
set(SRC
|
||||
mainwindow.cpp
|
||||
provider.cpp
|
||||
)
|
||||
|
||||
add_executable(provider WIN32 ${SRC})
|
||||
|
||||
target_link_libraries(provider qmdnsengine Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
install(TARGETS provider
|
||||
RUNTIME DESTINATION "${EXAMPLE_DIR}"
|
||||
COMPONENT examples
|
||||
)
|
||||
133
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/mainwindow.cpp
vendored
Normal file
133
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/mainwindow.cpp
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QIntValidator>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <qmdnsengine/dns.h>
|
||||
#include <qmdnsengine/query.h>
|
||||
#include <qmdnsengine/service.h>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: mHostname(&mServer),
|
||||
mProvider(0),
|
||||
mServiceName(new QLineEdit(tr("Test Service"))),
|
||||
mServiceType(new QLineEdit(tr("_test._tcp.local."))),
|
||||
mServicePort(new QLineEdit("1234")),
|
||||
mButton(new QPushButton(buttonCaption())),
|
||||
mShowQueries(new QCheckBox(tr("Show queries"))),
|
||||
mLog(new QTextEdit(tr("Initializing application")))
|
||||
{
|
||||
setWindowTitle(tr("mDNS Provider"));
|
||||
resize(640, 480);
|
||||
|
||||
mServicePort->setValidator(new QIntValidator(1, 65535, this));
|
||||
mLog->setReadOnly(true);
|
||||
|
||||
// Create the root layout
|
||||
QVBoxLayout *rootLayout = new QVBoxLayout;
|
||||
QWidget *widget = new QWidget;
|
||||
widget->setLayout(rootLayout);
|
||||
setCentralWidget(widget);
|
||||
|
||||
// Create the horizontal layout for the grid and buttons
|
||||
QHBoxLayout *upperLayout = new QHBoxLayout;
|
||||
rootLayout->addLayout(upperLayout);
|
||||
|
||||
// Create the grid layout for the line edits
|
||||
QGridLayout *gridLayout = new QGridLayout;
|
||||
gridLayout->addWidget(new QLabel(tr("Service name:")), 0, 0);
|
||||
gridLayout->addWidget(mServiceName, 0, 1);
|
||||
gridLayout->addWidget(new QLabel(tr("Service type:")), 1, 0);
|
||||
gridLayout->addWidget(mServiceType, 1, 1);
|
||||
gridLayout->addWidget(new QLabel(tr("Service port:")), 2, 0);
|
||||
gridLayout->addWidget(mServicePort, 2, 1);
|
||||
upperLayout->addLayout(gridLayout);
|
||||
|
||||
// Create the layout for the buttons
|
||||
QVBoxLayout *buttonLayout = new QVBoxLayout;
|
||||
buttonLayout->addWidget(mButton);
|
||||
buttonLayout->addWidget(mShowQueries);
|
||||
buttonLayout->addWidget(new QWidget, 1);
|
||||
upperLayout->addLayout(buttonLayout);
|
||||
|
||||
// Add the log
|
||||
rootLayout->addWidget(mLog, 1);
|
||||
|
||||
connect(mButton, &QPushButton::clicked, this, &MainWindow::onClicked);
|
||||
connect(&mHostname, &QMdnsEngine::Hostname::hostnameChanged, this, &MainWindow::onHostnameChanged);
|
||||
connect(&mServer, &QMdnsEngine::Server::messageReceived, this, &MainWindow::onMessageReceived);
|
||||
}
|
||||
|
||||
void MainWindow::onClicked()
|
||||
{
|
||||
if (mProvider) {
|
||||
mLog->append(tr("Destroying provider"));
|
||||
delete mProvider;
|
||||
mProvider = 0;
|
||||
} else {
|
||||
mLog->append(tr("Creating provider"));
|
||||
QMdnsEngine::Service service;
|
||||
service.setName(mServiceName->text().toUtf8());
|
||||
service.setType(mServiceType->text().toUtf8());
|
||||
service.setPort(mServicePort->text().toUShort());
|
||||
mProvider = new QMdnsEngine::Provider(&mServer, &mHostname, this);
|
||||
mProvider->update(service);
|
||||
}
|
||||
mButton->setText(buttonCaption());
|
||||
}
|
||||
|
||||
void MainWindow::onHostnameChanged(const QByteArray &hostname)
|
||||
{
|
||||
mLog->append(tr("Hostname changed to %1").arg(QString(hostname)));
|
||||
}
|
||||
|
||||
void MainWindow::onMessageReceived(const QMdnsEngine::Message &message)
|
||||
{
|
||||
if (!mShowQueries->isChecked()) {
|
||||
return;
|
||||
}
|
||||
const auto queries = message.queries();
|
||||
for (const QMdnsEngine::Query &query : queries) {
|
||||
mLog->append(
|
||||
tr("[%1] %2")
|
||||
.arg(QMdnsEngine::typeName(query.type()))
|
||||
.arg(QString(query.name()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
QString MainWindow::buttonCaption() const
|
||||
{
|
||||
return mProvider ? tr("Stop") : tr("Start");
|
||||
}
|
||||
72
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/mainwindow.h
vendored
Normal file
72
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/mainwindow.h
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <qmdnsengine/server.h>
|
||||
#include <qmdnsengine/hostname.h>
|
||||
#include <qmdnsengine/message.h>
|
||||
#include <qmdnsengine/provider.h>
|
||||
|
||||
class QCheckBox;
|
||||
class QPushButton;
|
||||
class QLineEdit;
|
||||
class QTextEdit;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
MainWindow();
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void onClicked();
|
||||
void onHostnameChanged(const QByteArray &hostname);
|
||||
void onMessageReceived(const QMdnsEngine::Message &message);
|
||||
|
||||
private:
|
||||
|
||||
QString buttonCaption() const;
|
||||
|
||||
QMdnsEngine::Server mServer;
|
||||
QMdnsEngine::Hostname mHostname;
|
||||
QMdnsEngine::Provider *mProvider;
|
||||
|
||||
QLineEdit *mServiceName;
|
||||
QLineEdit *mServiceType;
|
||||
QLineEdit *mServicePort;
|
||||
|
||||
QPushButton *mButton;
|
||||
QCheckBox *mShowQueries;
|
||||
|
||||
QTextEdit *mLog;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
37
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/provider.cpp
vendored
Normal file
37
FactoryTestTool/ThirdParty/qmdnsengine-master/examples/provider/provider.cpp
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user