本文整理汇总了C++中BluetoothService::CreatePairedDeviceInternal方法的典型用法代码示例。如果您正苦于以下问题:C++ BluetoothService::CreatePairedDeviceInternal方法的具体用法?C++ BluetoothService::CreatePairedDeviceInternal怎么用?C++ BluetoothService::CreatePairedDeviceInternal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BluetoothService
的用法示例。
在下文中一共展示了BluetoothService::CreatePairedDeviceInternal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BluetoothVoidReplyRunnable
already_AddRefed<DOMRequest>
BluetoothAdapter::PairUnpair(bool aPair, const nsAString& aDeviceAddress,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsresult rv;
if (aPair) {
rv = bs->CreatePairedDeviceInternal(aDeviceAddress,
kCreatePairedDeviceTimeout,
results);
} else {
rv = bs->RemoveDeviceInternal(aDeviceAddress, results);
}
if (NS_FAILED(rv)) {
BT_WARNING("Pair/Unpair failed!");
aRv.Throw(rv);
return nullptr;
}
return request.forget();
}
示例2: BluetoothVoidReplyRunnable
nsresult
BluetoothAdapter::PairUnpair(bool aPair,
nsIDOMBluetoothDevice* aDevice,
nsIDOMDOMRequest** aRequest)
{
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv;
rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(req);
nsAutoString addr;
aDevice->GetAddress(addr);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
if (aPair) {
rv = bs->CreatePairedDeviceInternal(addr,
kCreatePairedDeviceTimeout,
results);
} else {
rv = bs->RemoveDeviceInternal(addr, results);
}
if (NS_FAILED(rv)) {
NS_WARNING("Pair/Unpair failed!");
return NS_ERROR_FAILURE;
}
req.forget(aRequest);
return NS_OK;
}
示例3: BluetoothVoidReplyRunnable
already_AddRefed<Promise>
BluetoothAdapter::PairUnpair(bool aPair, const nsAString& aDeviceAddress,
ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if (!global) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
/**
* Ensure
* - device address is not empty,
* - adapter is already enabled, and
* - BluetoothService is available.
*/
BT_ENSURE_TRUE_REJECT(!aDeviceAddress.IsEmpty(),
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
nsresult rv;
if (aPair) {
nsRefPtr<BluetoothReplyRunnable> result =
new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */,
promise,
NS_LITERAL_STRING("Pair"));
rv = bs->CreatePairedDeviceInternal(aDeviceAddress,
kCreatePairedDeviceTimeout,
result);
} else {
nsRefPtr<BluetoothReplyRunnable> result =
new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */,
promise,
NS_LITERAL_STRING("Unpair"));
rv = bs->RemoveDeviceInternal(aDeviceAddress, result);
}
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), promise, NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
示例4: BluetoothVoidReplyRunnable
nsresult
BluetoothAdapter::PairUnpair(bool aPair,
nsIDOMBluetoothDevice* aDevice,
nsIDOMDOMRequest** aRequest)
{
BluetoothService* bs = BluetoothService::Get();
if (!bs) {
NS_WARNING("BluetoothService not available!");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMRequestService> rs = do_GetService("@mozilla.org/dom/dom-request-service;1");
if (!rs) {
NS_WARNING("No DOMRequest Service!");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = rs->CreateRequest(GetOwner(), getter_AddRefs(req));
if (NS_FAILED(rv)) {
NS_WARNING("Can't create DOMRequest!");
return NS_ERROR_FAILURE;
}
nsRefPtr<BluetoothVoidReplyRunnable> results = new BluetoothVoidReplyRunnable(req);
nsString addr;
aDevice->GetAddress(addr);
if (aPair) {
rv = bs->CreatePairedDeviceInternal(mPath,
addr,
kCreatePairedDeviceTimeout,
results);
} else {
rv = bs->RemoveDeviceInternal(mPath, addr, results);
}
if (NS_FAILED(rv)) {
NS_WARNING("Pair/Unpair failed!");
return NS_ERROR_FAILURE;
}
req.forget(aRequest);
return NS_OK;
}