void
BluetoothProfileController::Next()
{
    MOZ_ASSERT(NS_IsMainThread());
    MOZ_ASSERT(!mDeviceAddress.IsEmpty());
    MOZ_ASSERT(mProfilesIndex < mProfiles.Length());

    if (++mProfilesIndex < mProfiles.Length()) {
        BT_LOGR_PROFILE(mProfiles[mProfilesIndex], "");

        if (mConnect) {
            mProfiles[mProfilesIndex]->Connect(mDeviceAddress, this);
        } else {
            mProfiles[mProfilesIndex]->Disconnect(this);
        }
        return;
    }

    MOZ_ASSERT(mRunnable && mCallback);

    // The action has been completed, so the dom request is replied and then
    // the callback is invoked
    if (mSuccess) {
        DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString());
    } else {
        DispatchBluetoothReply(mRunnable, BluetoothValue(),
                               NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
    }
    mCallback();
}
void
BluetoothProfileController::AddProfileWithServiceClass(
    BluetoothServiceClass aClass)
{
    BluetoothProfileManagerBase* profile;
    switch (aClass) {
    case BluetoothServiceClass::HANDSFREE:
    case BluetoothServiceClass::HEADSET:
        profile = BluetoothHfpManager::Get();
        break;
    case BluetoothServiceClass::A2DP:
        profile = BluetoothA2dpManager::Get();
        break;
    case BluetoothServiceClass::OBJECT_PUSH:
        profile = BluetoothOppManager::Get();
        break;
    case BluetoothServiceClass::HID:
        profile = BluetoothHidManager::Get();
        break;
    default:
        DispatchBluetoothReply(mRunnable, BluetoothValue(),
                               NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE));
        mCallback();
        return;
    }

    AddProfile(profile);
}
void
BluetoothProfileController::AddProfile(BluetoothProfileManagerBase* aProfile,
                                       bool aCheckConnected)
{
    if (!aProfile) {
        DispatchBluetoothReply(mRunnable, BluetoothValue(),
                               NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
        mCallback();
        return;
    }

    if (aCheckConnected && !aProfile->IsConnected()) {
        BT_WARNING("The profile is not connected.");
        return;
    }

    mProfiles.AppendElement(aProfile);
}
Example #4
0
void
DispatchReplySuccess(BluetoothReplyRunnable* aRunnable)
{
  DispatchReplySuccess(aRunnable, BluetoothValue(true));
}