Vector<String> BluetoothDevice::uuids() { Vector<String> uuids(m_webDevice.uuids.size()); for (size_t i = 0; i < m_webDevice.uuids.size(); ++i) uuids[i] = m_webDevice.uuids[i]; return uuids; }
void BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue) { const nsString& name = aValue.name(); const BluetoothValue& value = aValue.value(); if (name.EqualsLiteral("Name")) { mName = value.get_nsString(); } else if (name.EqualsLiteral("Path")) { MOZ_ASSERT(value.get_nsString().Length() > 0); mPath = value.get_nsString(); } else if (name.EqualsLiteral("Address")) { mAddress = value.get_nsString(); } else if (name.EqualsLiteral("Class")) { mClass = value.get_uint32_t(); } else if (name.EqualsLiteral("Icon")) { mIcon = value.get_nsString(); } else if (name.EqualsLiteral("Connected")) { mConnected = value.get_bool(); } else if (name.EqualsLiteral("Paired")) { mPaired = value.get_bool(); } else if (name.EqualsLiteral("UUIDs")) { mUuids = value.get_ArrayOfnsString(); AutoJSAPI jsapi; if (!jsapi.Init(GetOwner())) { BT_WARNING("Failed to initialise AutoJSAPI!"); return; } JSContext* cx = jsapi.cx(); JS::Rooted<JSObject*> uuids(cx); if (NS_FAILED(nsTArrayToJSArray(cx, mUuids, &uuids))) { BT_WARNING("Cannot set JS UUIDs object!"); return; } mJsUuids = uuids; Root(); } else if (name.EqualsLiteral("Services")) { mServices = value.get_ArrayOfnsString(); AutoJSAPI jsapi; if (!jsapi.Init(GetOwner())) { BT_WARNING("Failed to initialise AutoJSAPI!"); return; } JSContext* cx = jsapi.cx(); JS::Rooted<JSObject*> services(cx); if (NS_FAILED(nsTArrayToJSArray(cx, mServices, &services))) { BT_WARNING("Cannot set JS Services object!"); return; } mJsServices = services; Root(); } else { nsCString warningMsg; warningMsg.AssignLiteral("Not handling device property: "); warningMsg.Append(NS_ConvertUTF16toUTF8(name)); BT_WARNING(warningMsg.get()); } }
void BluetoothDevice::SetPropertyByValue(const BluetoothNamedValue& aValue) { const nsString& name = aValue.name(); const BluetoothValue& value = aValue.value(); if (name.EqualsLiteral("Name")) { mName = value.get_nsString(); } else if (name.EqualsLiteral("Path")) { MOZ_ASSERT(value.get_nsString().Length() > 0); mPath = value.get_nsString(); } else if (name.EqualsLiteral("Address")) { mAddress = value.get_nsString(); } else if (name.EqualsLiteral("Class")) { mClass = value.get_uint32_t(); } else if (name.EqualsLiteral("Icon")) { mIcon = value.get_nsString(); } else if (name.EqualsLiteral("Connected")) { mConnected = value.get_bool(); } else if (name.EqualsLiteral("Paired")) { mPaired = value.get_bool(); } else if (name.EqualsLiteral("UUIDs")) { mUuids = value.get_ArrayOfnsString(); nsresult rv; nsIScriptContext* sc = GetContextForEventHandlers(&rv); NS_ENSURE_SUCCESS_VOID(rv); NS_ENSURE_TRUE_VOID(sc); AutoPushJSContext cx(sc->GetNativeContext()); JS::Rooted<JSObject*> uuids(cx); if (NS_FAILED(nsTArrayToJSArray(cx, mUuids, uuids.address()))) { BT_WARNING("Cannot set JS UUIDs object!"); return; } mJsUuids = uuids; Root(); } else if (name.EqualsLiteral("Services")) { mServices = value.get_ArrayOfnsString(); nsresult rv; nsIScriptContext* sc = GetContextForEventHandlers(&rv); NS_ENSURE_SUCCESS_VOID(rv); NS_ENSURE_TRUE_VOID(sc); AutoPushJSContext cx(sc->GetNativeContext()); JS::Rooted<JSObject*> services(cx); if (NS_FAILED(nsTArrayToJSArray(cx, mServices, services.address()))) { BT_WARNING("Cannot set JS Services object!"); return; } mJsServices = services; Root(); } else { nsCString warningMsg; warningMsg.AssignLiteral("Not handling device property: "); warningMsg.Append(NS_ConvertUTF16toUTF8(name)); BT_WARNING(warningMsg.get()); } }
void DeviceInterface::Disconnect() { if (uuids().contains(MediaPlayerUuid)) { disconnectMediaPlayer(); } Object::changeProperty(QStringLiteral("Connected"), false); }
std::size_t operator()(const cargo::ipc::UniqueID& id) const { char uuid[37]; // 36 chars for UUID + terminating zero ::uuid_unparse(id.mUUID, uuid); // STL does not provide correct hash implementation for char * // Instead, just convert it to string std::string uuids(uuid); return std::hash<time_t>()(id.mTime.tv_sec) ^ std::hash<long>()(id.mTime.tv_nsec) ^ std::hash<std::string>()(uuids); }
void DeviceInterface::DisconnectProfile(const QString &uuid, const QDBusMessage &msg) { if (!uuids().contains(uuid)) { QDBusMessage error = msg.createErrorReply(QStringLiteral("org.bluez.Error.DoesNotExist"), QStringLiteral("Profile UUID not supported")); QDBusConnection::sessionBus().send(error); return; } if (!m_connectedUuids.contains(uuid)) { QDBusMessage error = msg.createErrorReply(QStringLiteral("org.bluez.Error.NotConnected"), QStringLiteral("Profile not connected")); QDBusConnection::sessionBus().send(error); return; } if (uuid == MediaPlayerUuid) { disconnectMediaPlayer(); } else { Q_UNIMPLEMENTED(); } Object::changeProperty(QStringLiteral("Connected"), false); }