From 24229edf18574cf895b2cf77d04c47958d0273cb Mon Sep 17 00:00:00 2001 From: Ben Hsu Date: Wed, 24 Dec 2014 00:35:00 -0500 Subject: [PATCH] Bug 1077075 - Part 6: Internal architecture (IPC). r=aknow --HG-- extra : histedit_source : 219eeae82328717287bb56c495ccff452d0cbe39 --- dom/telephony/ipc/PTelephony.ipdl | 45 +++-- dom/telephony/ipc/TelephonyIPCService.cpp | 30 ++-- dom/telephony/ipc/TelephonyParent.cpp | 192 +++++++--------------- dom/telephony/ipc/TelephonyParent.h | 27 --- 4 files changed, 113 insertions(+), 181 deletions(-) diff --git a/dom/telephony/ipc/PTelephony.ipdl b/dom/telephony/ipc/PTelephony.ipdl index 25c9a4d43afc..28054f80e4cd 100644 --- a/dom/telephony/ipc/PTelephony.ipdl +++ b/dom/telephony/ipc/PTelephony.ipdl @@ -35,12 +35,47 @@ struct HangUpConferenceRequest uint32_t clientId; }; +struct AnswerCallRequest +{ + uint32_t clientId; + uint32_t callIndex; +}; + +struct HangUpCallRequest +{ + uint32_t clientId; + uint32_t callIndex; +}; + +struct RejectCallRequest +{ + uint32_t clientId; + uint32_t callIndex; +}; + +struct HoldCallRequest +{ + uint32_t clientId; + uint32_t callIndex; +}; + +struct ResumeCallRequest +{ + uint32_t clientId; + uint32_t callIndex; +}; + union IPCTelephonyRequest { EnumerateCallsRequest; DialRequest; USSDRequest; HangUpConferenceRequest; + AnswerCallRequest; + HangUpCallRequest; + RejectCallRequest; + HoldCallRequest; + ResumeCallRequest; }; sync protocol PTelephony { @@ -76,16 +111,6 @@ parent: UnregisterListener(); - HangUpCall(uint32_t aClientId, uint32_t aCallIndex); - - AnswerCall(uint32_t aClientId, uint32_t aCallIndex); - - RejectCall(uint32_t aClientId, uint32_t aCallIndex); - - HoldCall(uint32_t aClientId, uint32_t aCallIndex); - - ResumeCall(uint32_t aClientId, uint32_t aCallIndex); - ConferenceCall(uint32_t aClientId); SeparateCall(uint32_t aClientId, uint32_t aCallIndex); diff --git a/dom/telephony/ipc/TelephonyIPCService.cpp b/dom/telephony/ipc/TelephonyIPCService.cpp index 4712f2292d01..bbd9dfcfc3ad 100644 --- a/dom/telephony/ipc/TelephonyIPCService.cpp +++ b/dom/telephony/ipc/TelephonyIPCService.cpp @@ -171,63 +171,63 @@ TelephonyIPCService::Dial(uint32_t aClientId, const nsAString& aNumber, } NS_IMETHODIMP -TelephonyIPCService::HangUp(uint32_t aClientId, uint32_t aCallIndex) +TelephonyIPCService::AnswerCall(uint32_t aClientId, uint32_t aCallIndex, + nsITelephonyCallback *aCallback) { if (!mPTelephonyChild) { NS_WARNING("TelephonyService used after shutdown has begun!"); return NS_ERROR_FAILURE; } - mPTelephonyChild->SendHangUpCall(aClientId, aCallIndex); - return NS_OK; + return SendRequest(nullptr, aCallback, AnswerCallRequest(aClientId, aCallIndex)); } NS_IMETHODIMP -TelephonyIPCService::AnswerCall(uint32_t aClientId, uint32_t aCallIndex) +TelephonyIPCService::HangUpCall(uint32_t aClientId, uint32_t aCallIndex, + nsITelephonyCallback *aCallback) { if (!mPTelephonyChild) { NS_WARNING("TelephonyService used after shutdown has begun!"); return NS_ERROR_FAILURE; } - mPTelephonyChild->SendAnswerCall(aClientId, aCallIndex); - return NS_OK; + return SendRequest(nullptr, aCallback, HangUpCallRequest(aClientId, aCallIndex)); } NS_IMETHODIMP -TelephonyIPCService::RejectCall(uint32_t aClientId, uint32_t aCallIndex) +TelephonyIPCService::RejectCall(uint32_t aClientId, uint32_t aCallIndex, + nsITelephonyCallback *aCallback) { if (!mPTelephonyChild) { NS_WARNING("TelephonyService used after shutdown has begun!"); return NS_ERROR_FAILURE; } - mPTelephonyChild->SendRejectCall(aClientId, aCallIndex); - return NS_OK; + return SendRequest(nullptr, aCallback, RejectCallRequest(aClientId, aCallIndex)); } NS_IMETHODIMP -TelephonyIPCService::HoldCall(uint32_t aClientId, uint32_t aCallIndex) +TelephonyIPCService::HoldCall(uint32_t aClientId, uint32_t aCallIndex, + nsITelephonyCallback *aCallback) { if (!mPTelephonyChild) { NS_WARNING("TelephonyService used after shutdown has begun!"); return NS_ERROR_FAILURE; } - mPTelephonyChild->SendHoldCall(aClientId, aCallIndex); - return NS_OK; + return SendRequest(nullptr, aCallback, HoldCallRequest(aClientId, aCallIndex)); } NS_IMETHODIMP -TelephonyIPCService::ResumeCall(uint32_t aClientId, uint32_t aCallIndex) +TelephonyIPCService::ResumeCall(uint32_t aClientId, uint32_t aCallIndex, + nsITelephonyCallback *aCallback) { if (!mPTelephonyChild) { NS_WARNING("TelephonyService used after shutdown has begun!"); return NS_ERROR_FAILURE; } - mPTelephonyChild->SendResumeCall(aClientId, aCallIndex); - return NS_OK; + return SendRequest(nullptr, aCallback, ResumeCallRequest(aClientId, aCallIndex)); } NS_IMETHODIMP diff --git a/dom/telephony/ipc/TelephonyParent.cpp b/dom/telephony/ipc/TelephonyParent.cpp index e895f7790cae..ae27972f65f4 100644 --- a/dom/telephony/ipc/TelephonyParent.cpp +++ b/dom/telephony/ipc/TelephonyParent.cpp @@ -37,16 +37,71 @@ TelephonyParent::RecvPTelephonyRequestConstructor(PTelephonyRequestParent* aActo const IPCTelephonyRequest& aRequest) { TelephonyRequestParent* actor = static_cast(aActor); + nsCOMPtr service = do_GetService(TELEPHONY_SERVICE_CONTRACTID); + + if (!service) { + return NS_SUCCEEDED(actor->NotifyError(NS_LITERAL_STRING("InvalidStateError"))); + } switch (aRequest.type()) { - case IPCTelephonyRequest::TEnumerateCallsRequest: - return actor->DoRequest(aRequest.get_EnumerateCallsRequest()); - case IPCTelephonyRequest::TDialRequest: - return actor->DoRequest(aRequest.get_DialRequest()); - case IPCTelephonyRequest::TUSSDRequest: - return actor->DoRequest(aRequest.get_USSDRequest()); - case IPCTelephonyRequest::THangUpConferenceRequest: - return actor->DoRequest(aRequest.get_HangUpConferenceRequest()); + case IPCTelephonyRequest::TEnumerateCallsRequest: { + nsresult rv = service->EnumerateCalls(actor); + if (NS_FAILED(rv)) { + return NS_SUCCEEDED(EnumerateCallStateComplete()); + } else { + return true; + } + } + + case IPCTelephonyRequest::TDialRequest: { + const DialRequest& request = aRequest.get_DialRequest(); + service->Dial(request.clientId(), request.number(), + request.isEmergency(), actor); + return true; + } + + case IPCTelephonyRequest::TUSSDRequest: { + const USSDRequest& request = aRequest.get_USSDRequest(); + service->SendUSSD(request.clientId(), request.ussd(), actor); + return true; + } + + case IPCTelephonyRequest::THangUpConferenceRequest: { + const HangUpConferenceRequest& request = aRequest.get_HangUpConferenceRequest(); + service->HangUpConference(request.clientId(), actor); + return true; + } + + case IPCTelephonyRequest::TAnswerCallRequest: { + const AnswerCallRequest& request = aRequest.get_AnswerCallRequest(); + service->AnswerCall(request.clientId(), request.callIndex(), actor); + return true; + } + + case IPCTelephonyRequest::THangUpCallRequest: { + const HangUpCallRequest& request = aRequest.get_HangUpCallRequest(); + service->HangUpCall(request.clientId(), request.callIndex(), actor); + return true; + } + + case IPCTelephonyRequest::TRejectCallRequest: { + const RejectCallRequest& request = aRequest.get_RejectCallRequest(); + service->RejectCall(request.clientId(), request.callIndex(), actor); + return true; + } + + case IPCTelephonyRequest::THoldCallRequest: { + const HoldCallRequest& request = aRequest.get_HoldCallRequest(); + service->HoldCall(request.clientId(), request.callIndex(), actor); + return true; + } + + case IPCTelephonyRequest::TResumeCallRequest: { + const ResumeCallRequest& request = aRequest.get_ResumeCallRequest(); + service->ResumeCall(request.clientId(), request.callIndex(), actor); + return true; + } + default: MOZ_CRASH("Unknown type!"); } @@ -105,66 +160,6 @@ TelephonyParent::RecvUnregisterListener() return true; } -bool -TelephonyParent::RecvHangUpCall(const uint32_t& aClientId, - const uint32_t& aCallIndex) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - NS_ENSURE_TRUE(service, true); - - service->HangUp(aClientId, aCallIndex); - return true; -} - -bool -TelephonyParent::RecvAnswerCall(const uint32_t& aClientId, - const uint32_t& aCallIndex) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - NS_ENSURE_TRUE(service, true); - - service->AnswerCall(aClientId, aCallIndex); - return true; -} - -bool -TelephonyParent::RecvRejectCall(const uint32_t& aClientId, - const uint32_t& aCallIndex) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - NS_ENSURE_TRUE(service, true); - - service->RejectCall(aClientId, aCallIndex); - return true; -} - -bool -TelephonyParent::RecvHoldCall(const uint32_t& aClientId, - const uint32_t& aCallIndex) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - NS_ENSURE_TRUE(service, true); - - service->HoldCall(aClientId, aCallIndex); - return true; -} - -bool -TelephonyParent::RecvResumeCall(const uint32_t& aClientId, - const uint32_t& aCallIndex) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - NS_ENSURE_TRUE(service, true); - - service->ResumeCall(aClientId, aCallIndex); - return true; -} - bool TelephonyParent::RecvConferenceCall(const uint32_t& aClientId) { @@ -406,67 +401,6 @@ TelephonyRequestParent::ActorDestroy(ActorDestroyReason why) mActorDestroyed = true; } -bool -TelephonyRequestParent::DoRequest(const EnumerateCallsRequest& aRequest) -{ - nsresult rv = NS_ERROR_FAILURE; - - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - if (service) { - rv = service->EnumerateCalls(this); - } - - if (NS_FAILED(rv)) { - return NS_SUCCEEDED(EnumerateCallStateComplete()); - } - - return true; -} - -bool -TelephonyRequestParent::DoRequest(const DialRequest& aRequest) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - if (service) { - service->Dial(aRequest.clientId(), aRequest.number(), - aRequest.isEmergency(), this); - } else { - return NS_SUCCEEDED(NotifyError(NS_LITERAL_STRING("InvalidStateError"))); - } - - return true; -} - -bool -TelephonyRequestParent::DoRequest(const USSDRequest& aRequest) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - if (service) { - service->SendUSSD(aRequest.clientId(), aRequest.ussd(), this); - } else { - return NS_SUCCEEDED(NotifyError(NS_LITERAL_STRING("InvalidStateError"))); - } - - return true; -} - -bool -TelephonyRequestParent::DoRequest(const HangUpConferenceRequest& aRequest) -{ - nsCOMPtr service = - do_GetService(TELEPHONY_SERVICE_CONTRACTID); - if (service) { - service->HangUpConference(aRequest.clientId(), this); - } else { - return NS_SUCCEEDED(NotifyError(NS_LITERAL_STRING("InvalidStateError"))); - } - - return true; -} - nsresult TelephonyRequestParent::SendResponse(const IPCTelephonyResponse& aResponse) { diff --git a/dom/telephony/ipc/TelephonyParent.h b/dom/telephony/ipc/TelephonyParent.h index cfaec304ff57..21def5ae389d 100644 --- a/dom/telephony/ipc/TelephonyParent.h +++ b/dom/telephony/ipc/TelephonyParent.h @@ -46,21 +46,6 @@ protected: virtual bool RecvUnregisterListener() MOZ_OVERRIDE; - virtual bool - RecvHangUpCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE; - - virtual bool - RecvAnswerCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE; - - virtual bool - RecvRejectCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE; - - virtual bool - RecvHoldCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE; - - virtual bool - RecvResumeCall(const uint32_t& aClientId, const uint32_t& aCallIndex) MOZ_OVERRIDE; - virtual bool RecvConferenceCall(const uint32_t& aClientId) MOZ_OVERRIDE; @@ -120,18 +105,6 @@ protected: private: bool mActorDestroyed; - - bool - DoRequest(const EnumerateCallsRequest& aRequest); - - bool - DoRequest(const DialRequest& aRequest); - - bool - DoRequest(const USSDRequest& aRequest); - - bool - DoRequest(const HangUpConferenceRequest& aRequest); }; END_TELEPHONY_NAMESPACE