6#include <QtBluetooth/qbluetoothserviceinfo.h>
7#include <QtBluetooth/private/qbluetoothserver_ohos_p.h>
8#include <QtBluetooth/private/qohosbluetoothserver_p.h>
10#include <QtCore/qloggingcategory.h>
22 if (serverChannel < 0) {
23 qCWarning(QT_BT_OHOS,
"%s: Only RFCOMM services can be registered on HarmonyOS", Q_FUNC_INFO);
27 if (serverChannel == 0) {
29 QT_BT_OHOS,
"%s: No RFCOMM port in the service. Cannot register service.", Q_FUNC_INFO);
33 return static_cast<quint16>(serverChannel);
47 const auto serverProxy = registeredServerProxy.lock();
48 return serverProxy && optRegisteredServiceId
49 && serverProxy->tryGetRegisteredServiceId() == optRegisteredServiceId;
54 return registered && isRegisteredWithServerProxy();
64 if (isRegisteredWithServerProxy()) {
65 registeredServerProxy.lock()->close();
68 QT_BT_OHOS,
"%s: the server is already closed. The service is unregistered anyway.",
72 registeredServerProxy.reset();
73 optRegisteredServiceId.reset();
80 if (!localAdapter.isNull()) {
83 "%s: HarmonyOS does not support multi device adapters. Ignoring local adapter address ...",
91 registeredServerProxy.reset();
92 optRegisteredServiceId.reset();
94 const auto optPort = tryGetRfcommServerPort(serverChannel());
98 const auto serviceName = attributes.value(QBluetoothServiceInfo::ServiceName).toString();
99 const auto uuid = attributes.value(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>();
101 if (serviceName.isEmpty()) {
103 QT_BT_OHOS,
"%s: No service name in the service. Cannot register service.",
110 QT_BT_OHOS,
"%s: No service UUID in the service. Cannot register service.",
115 if (QtOhosBluetooth::isServiceNameAlreadyRegistered(serviceName)) {
116 qCCritical(QT_BT_OHOS,
"%s: Server with such service name is registered", Q_FUNC_INFO);
120 auto serverProxyContext = QtOhosBluetooth::tryGetServerProxyContext(*optPort);
121 if (!serverProxyContext) {
122 qCCritical(QT_BT_OHOS,
"%s: Server is not active. Cannot register services.", Q_FUNC_INFO);
126 auto proxy = serverProxyContext->bluetoothServerProxy;
128 if (proxy->isServiceRegistered()) {
130 QT_BT_OHOS,
"%s: Server has already registered service. Cannot register services.",
135 const auto secure = (serverProxyContext->securityFlags != QBluetooth::Security::NoSecurity);
137 if (!proxy->listen(serviceName, uuid.toString(QUuid::WithoutBraces), secure))
140 if (!proxy->accept()) {
146 registeredServerProxy = proxy;
147 optRegisteredServiceId = proxy->tryGetRegisteredServiceId();
bool registerService(const QBluetoothAddress &localAdapter=QBluetoothAddress())
bool isRegistered() const
~QBluetoothServiceInfoPrivate()
std::optional< quint16 > tryGetRfcommServerPort(int serverChannel)
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)