本文整理汇总了C++中BluetoothValue::type方法的典型用法代码示例。如果您正苦于以下问题:C++ BluetoothValue::type方法的具体用法?C++ BluetoothValue::type怎么用?C++ BluetoothValue::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BluetoothValue
的用法示例。
在下文中一共展示了BluetoothValue::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
bool
BluetoothAdapter::IsAdapterAttributeChanged(BluetoothAdapterAttribute aType,
const BluetoothValue& aValue)
{
switch(aType) {
case BluetoothAdapterAttribute::State:
MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
return aValue.get_bool() ? mState != BluetoothAdapterState::Enabled
: mState != BluetoothAdapterState::Disabled;
case BluetoothAdapterAttribute::Name:
MOZ_ASSERT(aValue.type() == BluetoothValue::TnsString);
return !mName.Equals(aValue.get_nsString());
case BluetoothAdapterAttribute::Address:
MOZ_ASSERT(aValue.type() == BluetoothValue::TnsString);
return !mAddress.Equals(aValue.get_nsString());
case BluetoothAdapterAttribute::Discoverable:
MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
return mDiscoverable != aValue.get_bool();
case BluetoothAdapterAttribute::Discovering:
MOZ_ASSERT(aValue.type() == BluetoothValue::Tbool);
return mDiscovering != aValue.get_bool();
default:
BT_WARNING("Type %d is not handled", uint32_t(aType));
return false;
}
}
示例2: if
void
BluetoothGatt::Notify(const BluetoothSignal& aData)
{
BT_LOGD("[D] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
BluetoothValue v = aData.value();
if (aData.name().EqualsLiteral("ClientRegistered")) {
MOZ_ASSERT(v.type() == BluetoothValue::Tuint32_t);
mClientIf = v.get_uint32_t();
} else if (aData.name().EqualsLiteral("ClientUnregistered")) {
mClientIf = 0;
} else if (aData.name().EqualsLiteral(GATT_CONNECTION_STATE_CHANGED_ID)) {
MOZ_ASSERT(v.type() == BluetoothValue::Tbool);
BluetoothConnectionState state =
v.get_bool() ? BluetoothConnectionState::Connected
: BluetoothConnectionState::Disconnected;
UpdateConnectionState(state);
} else if (aData.name().EqualsLiteral("ServicesDiscovered")) {
HandleServicesDiscovered(v);
} else if (aData.name().EqualsLiteral("DiscoverCompleted")) {
MOZ_ASSERT(v.type() == BluetoothValue::Tbool);
bool isDiscoverSuccess = v.get_bool();
if (!isDiscoverSuccess) { // Clean all discovered attributes if failed
mServices.Clear();
BluetoothGattBinding::ClearCachedServicesValue(this);
}
mDiscoveringServices = false;
} else {
BT_WARNING("Not handling GATT signal: %s",
NS_ConvertUTF16toUTF8(aData.name()).get());
}
}
示例3: DispatchTrustedEvent
void
BluetoothAdapter::Notify(const BluetoothSignal& aData)
{
InfallibleTArray<BluetoothNamedValue> arr;
BT_LOG("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get());
BluetoothValue v = aData.value();
if (aData.name().EqualsLiteral("DeviceFound")) {
nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value());
nsCOMPtr<nsIDOMEvent> event;
NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), this, nullptr, nullptr);
nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event);
e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicefound"),
false, false, device);
DispatchTrustedEvent(event);
} else if (aData.name().EqualsLiteral("PropertyChanged")) {
MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& arr =
v.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(arr.Length() == 1);
SetPropertyByValue(arr[0]);
} else if (aData.name().EqualsLiteral(PAIRED_STATUS_CHANGED_ID) ||
aData.name().EqualsLiteral(HFP_STATUS_CHANGED_ID) ||
aData.name().EqualsLiteral(SCO_STATUS_CHANGED_ID) ||
aData.name().EqualsLiteral(A2DP_STATUS_CHANGED_ID)) {
MOZ_ASSERT(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& arr =
v.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(arr.Length() == 2 &&
arr[0].value().type() == BluetoothValue::TnsString &&
arr[1].value().type() == BluetoothValue::Tbool);
nsString address = arr[0].value().get_nsString();
bool status = arr[1].value().get_bool();
nsCOMPtr<nsIDOMEvent> event;
NS_NewDOMBluetoothStatusChangedEvent(
getter_AddRefs(event), this, nullptr, nullptr);
nsCOMPtr<nsIDOMBluetoothStatusChangedEvent> e = do_QueryInterface(event);
e->InitBluetoothStatusChangedEvent(aData.name(), false, false,
address, status);
DispatchTrustedEvent(event);
} else {
#ifdef DEBUG
nsCString warningMsg;
warningMsg.AssignLiteral("Not handling adapter signal: ");
warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
NS_WARNING(warningMsg.get());
#endif
}
}
示例4: val
/**
* |SetJsObject| is an internal function used by |BroadcastSystemMessage| only
*/
static bool
SetJsObject(JSContext* aContext,
const BluetoothValue& aValue,
JS::Handle<JSObject*> aObj)
{
MOZ_ASSERT(aContext && aObj);
if (aValue.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
BT_WARNING("SetJsObject: Invalid parameter type");
return false;
}
const nsTArray<BluetoothNamedValue>& arr =
aValue.get_ArrayOfBluetoothNamedValue();
for (uint32_t i = 0; i < arr.Length(); i++) {
JS::Rooted<JS::Value> val(aContext);
const BluetoothValue& v = arr[i].value();
switch(v.type()) {
case BluetoothValue::TBluetoothAddress: {
nsAutoString addressStr;
AddressToString(v.get_BluetoothAddress(), addressStr);
JSString* jsData = JS_NewUCStringCopyN(aContext,
addressStr.BeginReading(),
addressStr.Length());
NS_ENSURE_TRUE(jsData, false);
val.setString(jsData);
break;
}
case BluetoothValue::TnsString: {
JSString* jsData = JS_NewUCStringCopyN(aContext,
v.get_nsString().BeginReading(),
v.get_nsString().Length());
NS_ENSURE_TRUE(jsData, false);
val.setString(jsData);
break;
}
case BluetoothValue::Tuint32_t:
val.setInt32(v.get_uint32_t());
break;
case BluetoothValue::Tbool:
val.setBoolean(v.get_bool());
break;
default:
BT_WARNING("SetJsObject: Parameter is not handled");
break;
}
if (!JS_SetProperty(aContext, aObj,
NS_ConvertUTF16toUTF8(arr[i].name()).get(),
val)) {
BT_WARNING("Failed to set property");
return false;
}
}
return true;
}
示例5: DispatchTrustedEvent
void
BluetoothGatt::HandleCharacteristicChanged(const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& ids =
aValue.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(ids.Length() == 2); // ServiceId, CharId
MOZ_ASSERT(ids[0].name().EqualsLiteral("serviceId"));
MOZ_ASSERT(ids[0].value().type() == BluetoothValue::TBluetoothGattServiceId);
MOZ_ASSERT(ids[1].name().EqualsLiteral("charId"));
MOZ_ASSERT(ids[1].value().type() == BluetoothValue::TBluetoothGattId);
size_t index = mServices.IndexOf(ids[0].value().get_BluetoothGattServiceId());
NS_ENSURE_TRUE_VOID(index != mServices.NoIndex);
nsRefPtr<BluetoothGattService> service = mServices.ElementAt(index);
nsTArray<nsRefPtr<BluetoothGattCharacteristic>> chars;
service->GetCharacteristics(chars);
index = chars.IndexOf(ids[1].value().get_BluetoothGattId());
NS_ENSURE_TRUE_VOID(index != chars.NoIndex);
nsRefPtr<BluetoothGattCharacteristic> characteristic = chars.ElementAt(index);
// Dispatch characteristicchanged event to application
BluetoothGattCharacteristicEventInit init;
init.mCharacteristic = characteristic;
nsRefPtr<BluetoothGattCharacteristicEvent> event =
BluetoothGattCharacteristicEvent::Constructor(
this,
NS_LITERAL_STRING(GATT_CHARACTERISTIC_CHANGED_ID),
init);
DispatchTrustedEvent(event);
}
示例6: DispatchPairingEvent
void
BluetoothPairingListener::Notify(const BluetoothSignal& aData)
{
InfallibleTArray<BluetoothNamedValue> arr;
BluetoothValue value = aData.value();
if (aData.name().EqualsLiteral("PairingRequest")) {
MOZ_ASSERT(value.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& arr =
value.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(arr.Length() == 4 &&
arr[0].value().type() == BluetoothValue::TnsString && // address
arr[1].value().type() == BluetoothValue::TnsString && // name
arr[2].value().type() == BluetoothValue::TnsString && // passkey
arr[3].value().type() == BluetoothValue::TnsString); // type
nsString address = arr[0].value().get_nsString();
nsString name = arr[1].value().get_nsString();
nsString passkey = arr[2].value().get_nsString();
nsString type = arr[3].value().get_nsString();
// Notify pairing listener of pairing requests
DispatchPairingEvent(name, address, passkey, type);
} else {
BT_WARNING("Not handling pairing listener signal: %s",
NS_ConvertUTF16toUTF8(aData.name()).get());
}
}
示例7:
void
BluetoothGatt::HandleDescriptorsDiscovered(const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& values =
aValue.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(values.Length() == 3); // ServiceId, CharacteristicId, Descriptors
MOZ_ASSERT(values[0].name().EqualsLiteral("serviceId"));
MOZ_ASSERT(values[0].value().type() ==
BluetoothValue::TBluetoothGattServiceId);
MOZ_ASSERT(values[1].name().EqualsLiteral("characteristicId"));
MOZ_ASSERT(values[1].value().type() == BluetoothValue::TBluetoothGattId);
MOZ_ASSERT(values[2].name().EqualsLiteral("descriptors"));
MOZ_ASSERT(values[2].value().type() ==
BluetoothValue::TArrayOfBluetoothGattId);
size_t index = mServices.IndexOf(
values[0].value().get_BluetoothGattServiceId());
NS_ENSURE_TRUE_VOID(index != mServices.NoIndex);
RefPtr<BluetoothGattService> service = mServices.ElementAt(index);
service->AssignDescriptors(values[1].value().get_BluetoothGattId(),
values[2].value().get_ArrayOfBluetoothGattId());
}
示例8: ReselectDefaultAdapter
void
BluetoothManager::HandleAdapterRemoved(const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TnsString);
MOZ_ASSERT(DefaultAdapterExists());
// Remove the adapter of given address from adapters array
nsString addressToRemove = aValue.get_nsString();
uint32_t numAdapters = mAdapters.Length();
for (uint32_t i = 0; i < numAdapters; i++) {
nsString address;
mAdapters[i]->GetAddress(address);
if (address.Equals(addressToRemove)) {
mAdapters.RemoveElementAt(i);
if (mDefaultAdapterIndex == (int)i) {
ReselectDefaultAdapter();
}
break;
}
}
// Notify application of removed adapter
BluetoothAdapterEventInit init;
init.mAddress = addressToRemove;
DispatchAdapterEvent(NS_LITERAL_STRING("adapterremoved"), init);
}
示例9: DispatchTrustedEvent
void
BluetoothAdapter::Notify(const BluetoothSignal& aData)
{
InfallibleTArray<BluetoothNamedValue> arr;
BT_LOG("[A] %s: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(aData.name()).get());
BluetoothValue v = aData.value();
if (aData.name().EqualsLiteral("DeviceFound")) {
nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(), mPath, aData.value());
nsCOMPtr<nsIDOMEvent> event;
NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), this, nullptr, nullptr);
nsCOMPtr<nsIDOMBluetoothDeviceEvent> e = do_QueryInterface(event);
e->InitBluetoothDeviceEvent(NS_LITERAL_STRING("devicefound"),
false, false, device);
DispatchTrustedEvent(event);
} else if (aData.name().EqualsLiteral("PropertyChanged")) {
NS_ASSERTION(v.type() == BluetoothValue::TArrayOfBluetoothNamedValue,
"PropertyChanged: Invalid value type");
const InfallibleTArray<BluetoothNamedValue>& arr =
v.get_ArrayOfBluetoothNamedValue();
NS_ASSERTION(arr.Length() == 1,
"Got more than one property in a change message!");
SetPropertyByValue(arr[0]);
} else {
#ifdef DEBUG
nsCString warningMsg;
warningMsg.AssignLiteral("Not handling adapter signal: ");
warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name()));
NS_WARNING(warningMsg.get());
#endif
}
}
示例10: DispatchDeviceEvent
void
BluetoothAdapter::HandleDevicePaired(const BluetoothValue& aValue)
{
if (NS_WARN_IF(mState != BluetoothAdapterState::Enabled)) {
return;
}
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& arr =
aValue.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(arr.Length() == 3 &&
arr[0].value().type() == BluetoothValue::TnsString && // Address
arr[1].value().type() == BluetoothValue::TnsString && // Name
arr[2].value().type() == BluetoothValue::Tbool); // Paired
MOZ_ASSERT(!arr[0].value().get_nsString().IsEmpty() &&
arr[2].value().get_bool());
// Append the paired device if it doesn't exist in adapter's devices array
size_t index = mDevices.IndexOf(arr[0].value().get_nsString());
if (index == mDevices.NoIndex) {
index = mDevices.Length(); // the new device's index
mDevices.AppendElement(
BluetoothDevice::Create(GetOwner(), aValue));
}
// Notify application of paired device
BluetoothDeviceEventInit init;
init.mDevice = mDevices[index];
DispatchDeviceEvent(NS_LITERAL_STRING(DEVICE_PAIRED_ID), init);
}
示例11:
void
BluetoothGattServer::HandleDescriptorHandleUpdated(
const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& arr =
aValue.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(arr.Length() == 4 &&
arr[0].value().type() == BluetoothValue::TBluetoothUuid &&
arr[1].value().type() == BluetoothValue::TBluetoothAttributeHandle &&
arr[2].value().type() == BluetoothValue::TBluetoothAttributeHandle &&
arr[3].value().type() == BluetoothValue::TBluetoothAttributeHandle);
BluetoothUuid descriptorUuid =
arr[0].value().get_BluetoothUuid();
BluetoothAttributeHandle serviceHandle =
arr[1].value().get_BluetoothAttributeHandle();
BluetoothAttributeHandle characteristicHandle =
arr[2].value().get_BluetoothAttributeHandle();
BluetoothAttributeHandle descriptorHandle =
arr[3].value().get_BluetoothAttributeHandle();
NS_ENSURE_TRUE_VOID(mPendingService);
NS_ENSURE_TRUE_VOID(mPendingService->GetServiceHandle() == serviceHandle);
mPendingService->AssignDescriptorHandle(descriptorUuid,
characteristicHandle,
descriptorHandle);
}
示例12: ConvertStringToAdapterAttribute
void
BluetoothAdapter::HandlePropertyChanged(const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& arr =
aValue.get_ArrayOfBluetoothNamedValue();
Sequence<nsString> types;
for (uint32_t i = 0, propCount = arr.Length(); i < propCount; ++i) {
BluetoothAdapterAttribute type =
ConvertStringToAdapterAttribute(arr[i].name());
// Non-BluetoothAdapterAttribute properties
if (type == BluetoothAdapterAttribute::Unknown) {
SetPropertyByValue(arr[i]);
continue;
}
// BluetoothAdapterAttribute properties
if (IsAdapterAttributeChanged(type, arr[i].value())) {
SetPropertyByValue(arr[i]);
BT_APPEND_ENUM_STRING(types, BluetoothAdapterAttribute, type);
}
}
DispatchAttributeEvent(types);
}
示例13:
void
BluetoothGattCharacteristic::HandleCharacteristicValueUpdated(
const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint8_t);
mValue = aValue.get_ArrayOfuint8_t();
}
示例14:
void
BluetoothGattDescriptor::HandleDescriptorValueUpdated(
const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint8_t);
mValue = aValue.get_ArrayOfuint8_t();
}
示例15: value
bool
BroadcastSystemMessage(const nsAString& aType,
const BluetoothValue& aData)
{
mozilla::AutoSafeJSContext cx;
MOZ_ASSERT(!::JS_IsExceptionPending(cx),
"Shouldn't get here when an exception is pending!");
nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
do_GetService("@mozilla.org/system-message-internal;1");
NS_ENSURE_TRUE(systemMessenger, false);
JS::Rooted<JS::Value> value(cx);
if (aData.type() == BluetoothValue::TnsString) {
JSString* jsData = JS_NewUCStringCopyN(cx,
aData.get_nsString().BeginReading(),
aData.get_nsString().Length());
value.setString(jsData);
} else if (aData.type() == BluetoothValue::TArrayOfBluetoothNamedValue) {
JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
if (!obj) {
BT_WARNING("Failed to new JSObject for system message!");
return false;
}
if (!SetJsObject(cx, aData, obj)) {
BT_WARNING("Failed to set properties of system message!");
return false;
}
value = JS::ObjectValue(*obj);
} else {
BT_WARNING("Not support the unknown BluetoothValue type");
return false;
}
nsCOMPtr<nsISupports> promise;
systemMessenger->BroadcastMessage(aType, value,
JS::UndefinedHandleValue,
getter_AddRefs(promise));
return true;
}