97 const qsizetype stringLength = string.size();
99 if (stringLength < 0) {
100 qCWarning(QT_BT_WINDOWS) <<
"Can not write invalid string value to buffer";
102 }
if (stringLength <= 0xff) {
104 hr = writer->WriteByte(type);
105 RETURN_FALSE_IF_FAILED(
"Could not write string type data.");
106 hr = writer->WriteByte(stringLength);
107 RETURN_FALSE_IF_FAILED(
"Could not write string length.");
108 }
else if (stringLength <= 0xffff) {
110 hr = writer->WriteByte(type);
111 RETURN_FALSE_IF_FAILED(
"Could not write string type data.");
112 hr = writer->WriteUInt16(stringLength);
113 RETURN_FALSE_IF_FAILED(
"Could not write string length.");
116 hr = writer->WriteByte(type);
117 RETURN_FALSE_IF_FAILED(
"Could not write string type data.");
118 hr = writer->WriteUInt32(stringLength);
119 RETURN_FALSE_IF_FAILED(
"Could not write string length.");
121 HStringReference stringRef(
reinterpret_cast<LPCWSTR>(string.utf16()));
122 quint32 bytesWritten;
123 hr = writer->WriteString(stringRef.Get(), &bytesWritten);
124 RETURN_FALSE_IF_FAILED(
"Could not write string to buffer.");
125 if (bytesWritten != size_t(string.size())) {
126 qCWarning(QT_BT_WINDOWS) <<
"Did not write full value to buffer";
134 ComPtr<IDataReaderStatics> dataReaderStatics;
135 HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataReader).Get(),
137 Q_ASSERT_SUCCEEDED(hr);
139 ComPtr<IDataReader> reader;
140 hr = dataReaderStatics->FromBuffer(buffer.Get(), reader.GetAddressOf());
141 Q_ASSERT_SUCCEEDED(hr);
144 hr = reader->ReadByte(&type);
145 Q_ASSERT_SUCCEEDED(hr);
147 qCWarning(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Malformed profile descriptor list read";
151 qint64 length = getLengthForBaseType(type, reader);
152 hr = reader->ReadByte(&type);
153 Q_ASSERT_SUCCEEDED(hr);
156 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Repairing profile descriptor list";
158 hr = reader->ReadUInt16(&uuid);
159 Q_ASSERT_SUCCEEDED(hr);
161 ComPtr<IDataWriter> writer;
162 hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataWriter).Get(),
164 Q_ASSERT_SUCCEEDED(hr);
167 Q_ASSERT_SUCCEEDED(hr);
169 hr = writer->WriteByte(8);
170 Q_ASSERT_SUCCEEDED(hr);
172 Q_ASSERT_SUCCEEDED(hr);
173 hr = writer->WriteByte(7);
174 Q_ASSERT_SUCCEEDED(hr);
176 Q_ASSERT_SUCCEEDED(hr);
177 hr = writer->WriteUInt16(uuid);
178 Q_ASSERT_SUCCEEDED(hr);
181 Q_ASSERT_SUCCEEDED(hr);
182 hr = writer->WriteUInt16(0x100);
183 Q_ASSERT_SUCCEEDED(hr);
185 hr = writer->DetachBuffer(&buffer);
186 Q_ASSERT_SUCCEEDED(hr);
194 ComPtr<IDataWriter> writer;
195 HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataWriter).Get(),
197 Q_ASSERT_SUCCEEDED(hr);
199 switch (attribute.typeId()) {
200 case QMetaType::Void:
201 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::Void:";
203 Q_ASSERT_SUCCEEDED(hr);
205 case QMetaType::UChar:
206 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::UChar:" << attribute.value<quint8>();
208 Q_ASSERT_SUCCEEDED(hr);
209 hr = writer->WriteByte(attribute.value<quint8>());
210 Q_ASSERT_SUCCEEDED(hr);
212 case QMetaType::UShort:
213 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::UShort:" << attribute.value<quint16>();
215 Q_ASSERT_SUCCEEDED(hr);
216 hr = writer->WriteUInt16(attribute.value<quint16>());
217 Q_ASSERT_SUCCEEDED(hr);
219 case QMetaType::UInt:
220 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::UInt:" << attribute.value<quint32>();
222 Q_ASSERT_SUCCEEDED(hr);
223 hr = writer->WriteUInt32(attribute.value<quint32>());
224 Q_ASSERT_SUCCEEDED(hr);
226 case QMetaType::ULongLong:
227 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::ULongLong:" << attribute.value<quint64>();
229 Q_ASSERT_SUCCEEDED(hr);
230 hr = writer->WriteUInt64(attribute.value<quint64>());
231 Q_ASSERT_SUCCEEDED(hr);
233 case QMetaType::Char:
234 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::Char:" << attribute.value<qint8>();
236 Q_ASSERT_SUCCEEDED(hr);
237 hr = writer->WriteByte(attribute.value<qint8>());
238 Q_ASSERT_SUCCEEDED(hr);
240 case QMetaType::Short:
241 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::Short:" << attribute.value<qint16>();
243 Q_ASSERT_SUCCEEDED(hr);
244 hr = writer->WriteInt16(attribute.value<qint16>());
245 Q_ASSERT_SUCCEEDED(hr);
248 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::Int:" << attribute.value<qint32>();
250 Q_ASSERT_SUCCEEDED(hr);
251 hr = writer->WriteInt32(attribute.value<qint32>());
252 Q_ASSERT_SUCCEEDED(hr);
254 case QMetaType::LongLong:
255 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::LongLong:" << attribute.value<qint64>();
257 Q_ASSERT_SUCCEEDED(hr);
258 hr = writer->WriteInt64(attribute.value<qint64>());
259 Q_ASSERT_SUCCEEDED(hr);
261 case QMetaType::QByteArray: {
262 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::QByteArray:" << attribute.value<QString>();
263 const QString stringValue = QString::fromLatin1(attribute.value<QByteArray>().toHex());
264 const bool writeSuccess = writeStringHelper(stringValue, writer);
269 case QMetaType::QString: {
270 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::QString:" << attribute.value<QString>();
271 const QString stringValue = attribute.value<QString>();
272 const bool writeSucces = writeStringHelper(stringValue, writer);
277 case QMetaType::Bool:
278 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering attribute of type QMetaType::Bool:" << attribute.value<
bool>();
280 Q_ASSERT_SUCCEEDED(hr);
281 hr = writer->WriteByte(attribute.value<
bool>());
282 Q_ASSERT_SUCCEEDED(hr);
284 case QMetaType::QUrl:
285 qCWarning(QT_BT_WINDOWS) <<
"Don't know how to register QMetaType::QUrl";
289 if (attribute.userType() == qMetaTypeId<QBluetoothUuid>()) {
290 QBluetoothUuid uuid = attribute.value<QBluetoothUuid>();
291 switch (uuid.minimumSize()) {
293 qCWarning(QT_BT_WINDOWS) <<
"Don't know how to register Uuid of length 0";
296 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering Uuid attribute with length 2:" << uuid;
298 Q_ASSERT_SUCCEEDED(hr);
299 hr = writer->WriteUInt16(uuid.toUInt16());
300 Q_ASSERT_SUCCEEDED(hr);
303 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering Uuid attribute with length 4:" << uuid;
305 Q_ASSERT_SUCCEEDED(hr);
306 hr = writer->WriteUInt32(uuid.toUInt32());
307 Q_ASSERT_SUCCEEDED(hr);
311 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registering Uuid attribute:" << uuid;
313 Q_ASSERT_SUCCEEDED(hr);
314 hr = writer->WriteGuid(uuid);
315 Q_ASSERT_SUCCEEDED(hr);
318 }
else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) {
319 qCDebug(QT_BT_WINDOWS) <<
"Registering sequence attribute";
320 const QBluetoothServiceInfo::Sequence *sequence =
321 static_cast<
const QBluetoothServiceInfo::Sequence *>(attribute.data());
322 ComPtr<IDataWriter> tmpWriter;
323 HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataWriter).Get(),
325 Q_ASSERT_SUCCEEDED(hr);
326 for (
const QVariant &v : *sequence) {
327 ComPtr<IBuffer> tmpBuffer = bufferFromAttribute(v);
329 qCWarning(QT_BT_WINDOWS) <<
"Could not create buffer from attribute in sequence";
333 hr = tmpBuffer->get_Length(&l);
334 Q_ASSERT_SUCCEEDED(hr);
335 hr = tmpWriter->WriteBuffer(tmpBuffer.Get());
336 Q_ASSERT_SUCCEEDED(hr);
338 ComPtr<IBuffer> tmpBuffer;
339 hr = tmpWriter->DetachBuffer(&tmpBuffer);
340 Q_ASSERT_SUCCEEDED(hr);
343 tmpBuffer->get_Length(&length);
344 Q_ASSERT_SUCCEEDED(hr);
347 if (length <= 0xff) {
349 hr = writer->WriteByte(type);
350 Q_ASSERT_SUCCEEDED(hr);
351 hr = writer->WriteByte(length);
352 Q_ASSERT_SUCCEEDED(hr);
353 }
else if (length <= 0xffff) {
355 hr = writer->WriteByte(type);
356 Q_ASSERT_SUCCEEDED(hr);
357 hr = writer->WriteUInt16(length);
358 Q_ASSERT_SUCCEEDED(hr);
361 hr = writer->WriteByte(type);
362 Q_ASSERT_SUCCEEDED(hr);
363 hr = writer->WriteUInt32(length);
364 Q_ASSERT_SUCCEEDED(hr);
367 hr = writer->WriteBuffer(tmpBuffer.Get());
368 Q_ASSERT_SUCCEEDED(hr);
369 qCDebug(QT_BT_WINDOWS) << Q_FUNC_INFO <<
"Registered sequence attribute with length" << length;
370 }
else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Alternative>()) {
371 qCWarning(QT_BT_WINDOWS) <<
"Don't know how to register user type Alternative";
374 qCWarning(QT_BT_WINDOWS) <<
"Unknown variant type" << attribute.userType();
378 ComPtr<IBuffer> buffer;
379 hr = writer->DetachBuffer(&buffer);
380 Q_ASSERT_SUCCEEDED(hr);