void BluetoothDevice::Notify(const BluetoothSignal& aData) { if (aData.name().EqualsLiteral("PropertyChanged")) { NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue, "PropertyChanged: Invalid value type"); InfallibleTArray<BluetoothNamedValue> arr = aData.value().get_ArrayOfBluetoothNamedValue(); NS_ASSERTION(arr.Length() == 1, "Got more than one property in a change message!"); BluetoothNamedValue v = arr[0]; nsString name = v.name(); SetPropertyByValue(v); if (name.EqualsLiteral("Connected")) { DispatchTrustedEvent(mConnected ? NS_LITERAL_STRING("connected") : NS_LITERAL_STRING("disconnected")); } else { nsRefPtr<BluetoothPropertyEvent> e = BluetoothPropertyEvent::Create(name); e->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("propertychanged")); } } else { #ifdef DEBUG nsCString warningMsg; warningMsg.AssignLiteral("Not handling device signal: "); warningMsg.Append(NS_ConvertUTF16toUTF8(aData.name())); NS_WARNING(warningMsg.get()); #endif } }
void TelephonyCall::NotifyError(const nsAString& aError) { // Set the error string NS_ASSERTION(!mError, "Already have an error?"); mError = DOMError::CreateWithName(aError); // Do the state transitions ChangeStateInternal(nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED, true); // Notify the error event nsRefPtr<CallEvent> event = CallEvent::Create(this); NS_ASSERTION(event, "This should never fail!"); if (NS_FAILED(event->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("error")))) { NS_WARNING("Failed to dispatch error event!"); } }
void TelephonyCall::ChangeStateInternal(PRUint16 aCallState, bool aFireEvents) { nsRefPtr<TelephonyCall> kungFuDeathGrip(this); nsString stateString; switch (aCallState) { case nsIRadioInterfaceLayer::CALL_STATE_DIALING: stateString.AssignLiteral("dialing"); break; case nsIRadioInterfaceLayer::CALL_STATE_RINGING: stateString.AssignLiteral("ringing"); break; case nsIRadioInterfaceLayer::CALL_STATE_BUSY: stateString.AssignLiteral("busy"); break; case nsIRadioInterfaceLayer::CALL_STATE_CONNECTING: stateString.AssignLiteral("connecting"); break; case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED: stateString.AssignLiteral("connected"); break; case nsIRadioInterfaceLayer::CALL_STATE_HOLDING: stateString.AssignLiteral("holding"); break; case nsIRadioInterfaceLayer::CALL_STATE_HELD: stateString.AssignLiteral("held"); break; case nsIRadioInterfaceLayer::CALL_STATE_RESUMING: stateString.AssignLiteral("resuming"); break; case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTING: stateString.AssignLiteral("disconnecting"); break; case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED: stateString.AssignLiteral("disconnected"); break; case nsIRadioInterfaceLayer::CALL_STATE_INCOMING: stateString.AssignLiteral("incoming"); break; default: NS_NOTREACHED("Unknown state!"); } mState = stateString; mCallState = aCallState; if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DIALING) { mOutgoing = true; } if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) { NS_ASSERTION(mLive, "Should be live!"); mTelephony->RemoveCall(this); mLive = false; } else if (!mLive) { mTelephony->AddCall(this); mLive = true; } if (aFireEvents) { nsRefPtr<CallEvent> event = CallEvent::Create(this); NS_ASSERTION(event, "This should never fail!"); if (NS_FAILED(event->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("statechange")))) { NS_WARNING("Failed to dispatch statechange event!"); } // This can change if the statechange handler called back here... Need to // figure out something smarter. if (mCallState == aCallState) { event = CallEvent::Create(this); NS_ASSERTION(event, "This should never fail!"); if (NS_FAILED(event->Dispatch(ToIDOMEventTarget(), stateString))) { NS_WARNING("Failed to dispatch specific event!"); } } } }