nsresult Telephony::NotifyCallsChanged(TelephonyCall* aCall) { if (aCall->CallState() == nsIRadioInterfaceLayer::CALL_STATE_DIALING || aCall->CallState() == nsIRadioInterfaceLayer::CALL_STATE_ALERTING || aCall->CallState() == nsIRadioInterfaceLayer::CALL_STATE_CONNECTED) { NS_ASSERTION(!mActiveCall, "Already have an active call!"); mActiveCall = aCall; } else if (mActiveCall && mActiveCall->CallIndex() == aCall->CallIndex()) { mActiveCall = nullptr; } return DispatchCallEvent(NS_LITERAL_STRING("callschanged"), aCall); }
void TelephonyCall::NotifyError(const nsAString& aError) { // Set the error string NS_ASSERTION(!mError, "Already have an error?"); mError = new mozilla::dom::DOMError(GetOwner(), aError); // Do the state transitions ChangeStateInternal(nsITelephonyProvider::CALL_STATE_DISCONNECTED, true); nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("error"), this); if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch error event!"); } }
void TelephonyCall::ChangeStateInternal(uint16_t aCallState, bool aFireEvents) { nsRefPtr<TelephonyCall> kungFuDeathGrip(this); nsString stateString; switch (aCallState) { case nsITelephonyProvider::CALL_STATE_DIALING: stateString.AssignLiteral("dialing"); break; case nsITelephonyProvider::CALL_STATE_ALERTING: stateString.AssignLiteral("alerting"); break; case nsITelephonyProvider::CALL_STATE_BUSY: stateString.AssignLiteral("busy"); break; case nsITelephonyProvider::CALL_STATE_CONNECTING: stateString.AssignLiteral("connecting"); break; case nsITelephonyProvider::CALL_STATE_CONNECTED: stateString.AssignLiteral("connected"); break; case nsITelephonyProvider::CALL_STATE_HOLDING: stateString.AssignLiteral("holding"); break; case nsITelephonyProvider::CALL_STATE_HELD: stateString.AssignLiteral("held"); break; case nsITelephonyProvider::CALL_STATE_RESUMING: stateString.AssignLiteral("resuming"); break; case nsITelephonyProvider::CALL_STATE_DISCONNECTING: stateString.AssignLiteral("disconnecting"); break; case nsITelephonyProvider::CALL_STATE_DISCONNECTED: stateString.AssignLiteral("disconnected"); break; case nsITelephonyProvider::CALL_STATE_INCOMING: stateString.AssignLiteral("incoming"); break; default: NS_NOTREACHED("Unknown state!"); } mState = stateString; mCallState = aCallState; if (aCallState == nsITelephonyProvider::CALL_STATE_DIALING) { mOutgoing = true; } if (aCallState == nsITelephonyProvider::CALL_STATE_DISCONNECTED) { NS_ASSERTION(mLive, "Should be live!"); mTelephony->RemoveCall(this); mLive = false; } else if (!mLive) { mTelephony->AddCall(this); mLive = true; } if (aFireEvents) { nsresult rv = DispatchCallEvent(NS_LITERAL_STRING("statechange"), this); if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch specific event!"); } // This can change if the statechange handler called back here... Need to // figure out something smarter. if (mCallState == aCallState) { rv = DispatchCallEvent(stateString, this); if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch specific event!"); } } } }