diff --git a/tests/leserver.cpp b/tests/leserver.cpp new file mode 100644 index 0000000..6aa7dc7 --- /dev/null +++ b/tests/leserver.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2019 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "leserver.h" + +#include +#include + +#include "adapter.h" +#include "device.h" +#include "initmanagerjob.h" +#include "leadvertisement.h" +#include "leadvertisingmanager.h" +#include "manager.h" +#include "pendingcall.h" + +using namespace BluezQt; + +LeServer::LeServer(Manager *manager, QObject *parent) + : QObject(parent), + m_manager(manager) +{ + auto advertisement = new LEAdvertisement({QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1")}, this); + auto call = m_manager->usableAdapter()->leAdvertisingManager()->registerAdvertisement(advertisement); + // Why does this take so long? And why does it actually succeed, but remote does not send reply? + call->waitForFinished(); + if (call->error()) { + qWarning() << "Error registering advertisement" << call->errorText(); + return; + } +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + qDebug() << "Advertising LE services. Ctrl + C to cancel..."; + + Manager *manager = new Manager(); + InitManagerJob *initJob = manager->init(); + initJob->exec(); + if (initJob->error()) { + qWarning() << "Error initializing manager:" << initJob->errorText(); + return 1; + } + + if (!manager->usableAdapter()) { + qWarning() << "No usable adapter"; + return 2; + } + if (!manager->usableAdapter()->leAdvertisingManager()) { + qWarning() << "No LE advertising manager"; + return 2; + } + + new LeServer(manager); + + return app.exec(); +} diff --git a/tests/leserver.h b/tests/leserver.h new file mode 100644 index 0000000..eaa5527 --- /dev/null +++ b/tests/leserver.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include + +#include "types.h" + +class LeServer : public QObject +{ + Q_OBJECT + +public: + explicit LeServer(BluezQt::Manager *manager, QObject *parent = nullptr); + +private: + BluezQt::Manager *m_manager; +};