Files
utun2/tools/chatgui/transport/desktop_ble.h
T
evgeny ba1c4cf160 Add cross-platform BLE transport and Bluetooth settings
Integrate shared C transport with desktop and Android frontends, add radio probes and detailed Windows diagnostics, and fix GUI build dependencies and early configuration startup errors.
2026-10-29 10:51:19 +01:00

41 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Desktop-владелец общего C BLE API. Создание/apply/snapshot/destroy — в uasync-потоке,
* вне BLE callbacks. GUI получает копию snapshot через UtunNode, а не handle ядра.
* Приёмные пакеты остаются в ll_queue транспорта до чтения потребителем C API. */
#pragma once
#include "../../../lib/ble/ble_transport.h"
#include <QString>
#include <QStringList>
#include <QMap>
#include <QElapsedTimer>
struct DesktopBleSnapshot {
int flags = 0; // 1: транспорт, 2: объявление node_id/имени, 4: входящие подключения
ble_state state = BLE_CLOSED, advertising = BLE_CLOSED;
QString reason, advertisingReason; // Последние причины изменения состояния backend.
QStringList peers; // Свежие объявления: имя, node_id, RSSI; не более 64 узлов.
int connections = 0; // Готовые GATT-сессии.
};
class DesktopBle {
public:
DesktopBle(UASYNC* ua, uint64_t nodeId);
~DesktopBle();
DesktopBle(const DesktopBle&) = delete;
DesktopBle& operator=(const DesktopBle&) = delete;
void apply(int flags, const char* name); // Обновить политику/имя; повтор с теми же значениями — no-op.
DesktopBleSnapshot snapshot(); // Удалить объявления старше 30 секунд и вернуть копию.
ble_transport* transport() const { return m_transport; } // Заимствован только внутри uasync, до выключения.
private:
void advertise();
UASYNC* m_ua;
uint64_t m_nodeId;
ble_transport* m_transport = nullptr;
DesktopBleSnapshot m_snapshot;
QByteArray m_name, m_identity;
QElapsedTimer m_clock;
struct Peer { QString text; qint64 seen; };
QMap<uint64_t, Peer> m_peers;
QMap<ble_link_id, bool> m_connections;
};