本文整理汇总了C++中BluetoothValue类的典型用法代码示例。如果您正苦于以下问题:C++ BluetoothValue类的具体用法?C++ BluetoothValue怎么用?C++ BluetoothValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BluetoothValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MOZ_ASSERT
void
BluetoothGattCharacteristic::HandleCharacteristicValueUpdated(
const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint8_t);
mValue = aValue.get_ArrayOfuint8_t();
}
示例2: MOZ_ASSERT
void
BluetoothGattDescriptor::HandleDescriptorValueUpdated(
const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfuint8_t);
mValue = aValue.get_ArrayOfuint8_t();
}
示例3: BT_LOG
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: BT_LOGD
void
BluetoothAdapter::Notify(const BluetoothSignal& aData)
{
BT_LOGD("[A] %s", NS_ConvertUTF16toUTF8(aData.name()).get());
NS_ENSURE_TRUE_VOID(mSignalRegistered);
BluetoothValue v = aData.value();
if (aData.name().EqualsLiteral("PropertyChanged")) {
HandlePropertyChanged(v);
} else if (aData.name().EqualsLiteral("DeviceFound")) {
/*
* DeviceFound signal will be distributed to all existing adapters while
* doing discovery operations.
* The signal needs to be handled only if this adapter is holding a valid
* discovery handle, which means that the discovery operation is triggered
* by this adapter.
*/
if (mDiscoveryHandleInUse) {
HandleDeviceFound(v);
}
} else if (aData.name().EqualsLiteral(DEVICE_PAIRED_ID)) {
HandleDevicePaired(aData.value());
} else if (aData.name().EqualsLiteral(DEVICE_UNPAIRED_ID)) {
HandleDeviceUnpaired(aData.value());
} else if (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();
BluetoothStatusChangedEventInit init;
init.mBubbles = false;
init.mCancelable = false;
init.mAddress = address;
init.mStatus = status;
nsRefPtr<BluetoothStatusChangedEvent> event =
BluetoothStatusChangedEvent::Constructor(this, aData.name(), init);
DispatchTrustedEvent(event);
} else if (aData.name().EqualsLiteral(PAIRING_ABORTED_ID) ||
aData.name().EqualsLiteral(REQUEST_MEDIA_PLAYSTATUS_ID)) {
DispatchEmptyEvent(aData.name());
} else {
BT_WARNING("Not handling adapter signal: %s",
NS_ConvertUTF16toUTF8(aData.name()).get());
}
}
示例5: SetJsObject
BEGIN_BLUETOOTH_NAMESPACE
bool
SetJsObject(JSContext* aContext,
const BluetoothValue& aValue,
JSObject* aObj)
{
MOZ_ASSERT(aContext && aObj);
if (aValue.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
NS_WARNING("SetJsObject: Invalid parameter type");
return false;
}
const nsTArray<BluetoothNamedValue>& arr =
aValue.get_ArrayOfBluetoothNamedValue();
for (uint32_t i = 0; i < arr.Length(); i++) {
jsval val;
const BluetoothValue& v = arr[i].value();
JSString* jsData;
switch(v.type()) {
case BluetoothValue::TnsString:
jsData = JS_NewUCStringCopyN(aContext,
v.get_nsString().BeginReading(),
v.get_nsString().Length());
NS_ENSURE_TRUE(jsData, false);
val = STRING_TO_JSVAL(jsData);
break;
case BluetoothValue::Tuint32_t:
val = INT_TO_JSVAL(v.get_uint32_t());
break;
case BluetoothValue::Tbool:
val = BOOLEAN_TO_JSVAL(v.get_bool());
break;
default:
NS_WARNING("SetJsObject: Parameter is not handled");
break;
}
if (!JS_SetProperty(aContext, aObj,
NS_ConvertUTF16toUTF8(arr[i].name()).get(),
&val)) {
NS_WARNING("Failed to set property");
return false;
}
}
return true;
}
示例6: SetJsObject
/**
* |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::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;
}
示例7: ParseSuccessfulReply
virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
{
aValue.setUndefined();
const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
BT_WARNING("Not a BluetoothNamedValue array!");
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
return false;
}
const InfallibleTArray<BluetoothNamedValue>& values =
v.get_ArrayOfBluetoothNamedValue();
nsTArray<nsRefPtr<BluetoothDevice> > devices;
for (uint32_t i = 0; i < values.Length(); i++) {
const BluetoothValue properties = values[i].value();
if (properties.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
BT_WARNING("Not a BluetoothNamedValue array!");
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
return false;
}
nsRefPtr<BluetoothDevice> d =
BluetoothDevice::Create(mAdapterPtr->GetOwner(),
mAdapterPtr->GetPath(),
properties);
devices.AppendElement(d);
}
nsresult rv;
nsIScriptContext* sc = mAdapterPtr->GetContextForEventHandlers(&rv);
if (!sc) {
BT_WARNING("Cannot create script context!");
SetError(NS_LITERAL_STRING("BluetoothScriptContextError"));
return false;
}
AutoPushJSContext cx(sc->GetNativeContext());
JSObject* JsDevices = nullptr;
rv = nsTArrayToJSArray(cx, devices, &JsDevices);
if (!JsDevices) {
BT_WARNING("Cannot create JS array!");
SetError(NS_LITERAL_STRING("BluetoothError"));
return false;
}
aValue.setObject(*JsDevices);
return true;
}
示例8: MOZ_ASSERT
void
BluetoothGatt::HandleServicesDiscovered(const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothGattServiceId);
const InfallibleTArray<BluetoothGattServiceId>& serviceIds =
aValue.get_ArrayOfBluetoothGattServiceId();
for (uint32_t i = 0; i < serviceIds.Length(); i++) {
mServices.AppendElement(new BluetoothGattService(
GetParentObject(), mAppUuid, serviceIds[i]));
}
BluetoothGattBinding::ClearCachedServicesValue(this);
}
示例9: MOZ_ASSERT
void
BluetoothGattService::HandleCharacteristicsDiscovered(
const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothGattId);
const InfallibleTArray<BluetoothGattId>& characteristicIds =
aValue.get_ArrayOfBluetoothGattId();
for (uint32_t i = 0; i < characteristicIds.Length(); i++) {
mCharacteristics.AppendElement(new BluetoothGattCharacteristic(
GetParentObject(), this, characteristicIds[i]));
}
BluetoothGattServiceBinding::ClearCachedCharacteristicsValue(this);
}
示例10: nsDOMEventTargetHelper
BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aWindow,
const BluetoothValue& aValue)
: nsDOMEventTargetHelper(aWindow)
, BluetoothPropertyContainer(BluetoothObjectType::TYPE_ADAPTER)
, mJsUuids(nullptr)
, mJsDeviceAddresses(nullptr)
, mDiscoverable(false)
, mDiscovering(false)
, mPairable(false)
, mPowered(false)
, mIsRooted(false)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(IsDOMBinding());
BindToOwner(aWindow);
const InfallibleTArray<BluetoothNamedValue>& values =
aValue.get_ArrayOfBluetoothNamedValue();
for (uint32_t i = 0; i < values.Length(); ++i) {
SetPropertyByValue(values[i]);
}
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
}
示例11: ParseSuccessfulReply
virtual bool ParseSuccessfulReply(JS::MutableHandle<JS::Value> aValue)
{
aValue.setUndefined();
const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
BT_WARNING("Not a BluetoothNamedValue array!");
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
return false;
}
const InfallibleTArray<BluetoothNamedValue>& values =
v.get_ArrayOfBluetoothNamedValue();
nsTArray<nsRefPtr<BluetoothDevice> > devices;
for (uint32_t i = 0; i < values.Length(); i++) {
const BluetoothValue properties = values[i].value();
if (properties.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
BT_WARNING("Not a BluetoothNamedValue array!");
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
return false;
}
nsRefPtr<BluetoothDevice> d =
BluetoothDevice::Create(mAdapterPtr->GetOwner(),
mAdapterPtr->GetPath(),
properties);
devices.AppendElement(d);
}
AutoJSAPI jsapi;
if (!jsapi.Init(mAdapterPtr->GetOwner())) {
BT_WARNING("Failed to initialise AutoJSAPI!");
SetError(NS_LITERAL_STRING("BluetoothAutoJSAPIInitError"));
return false;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> JsDevices(cx);
if (NS_FAILED(nsTArrayToJSArray(cx, devices, &JsDevices))) {
BT_WARNING("Cannot create JS array!");
SetError(NS_LITERAL_STRING("BluetoothError"));
return false;
}
aValue.setObject(*JsDevices);
return true;
}
示例12: BT_LOGD
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());
}
}
示例13: MOZ_ASSERT
void
BluetoothManager::AppendAdapter(const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
// Create a new BluetoothAdapter and append it to adapters array
const InfallibleTArray<BluetoothNamedValue>& values =
aValue.get_ArrayOfBluetoothNamedValue();
nsRefPtr<BluetoothAdapter> adapter =
BluetoothAdapter::Create(GetOwner(), values);
mAdapters.AppendElement(adapter);
// Set this adapter as default adapter if no adapter exists
if (!DefaultAdapterExists()) {
MOZ_ASSERT(mAdapters.Length() == 1);
ReselectDefaultAdapter();
}
}
示例14: BroadcastSystemMessage
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;
}
示例15: MOZ_ASSERT
void
BluetoothGattServer::HandleServiceHandleUpdated(const BluetoothValue& aValue)
{
MOZ_ASSERT(aValue.type() == BluetoothValue::TArrayOfBluetoothNamedValue);
const InfallibleTArray<BluetoothNamedValue>& arr =
aValue.get_ArrayOfBluetoothNamedValue();
MOZ_ASSERT(arr.Length() == 2 &&
arr[0].value().type() == BluetoothValue::TBluetoothGattServiceId &&
arr[1].value().type() == BluetoothValue::TBluetoothAttributeHandle);
BluetoothGattServiceId serviceId =
arr[0].value().get_BluetoothGattServiceId();
BluetoothAttributeHandle serviceHandle =
arr[1].value().get_BluetoothAttributeHandle();
NS_ENSURE_TRUE_VOID(mPendingService);
NS_ENSURE_TRUE_VOID(mPendingService->GetServiceId() == serviceId);
mPendingService->AssignServiceHandle(serviceHandle);
}