Bug 1052836 - Part 2: Use enums for preferred network type in nsIMobileConnectionService.idl (dom/ipc). r=echen

This commit is contained in:
Jessica Jong 2014-10-30 02:56:00 -04:00
parent 4bdd9018c7
commit 1d4db6b32a
8 changed files with 65 additions and 6 deletions

View File

@ -28,5 +28,24 @@ ASSERT_MOBILE_RADIO_STATE_EQUALITY(Disabled, MOBILE_RADIO_STATE_DISABLED);
#undef ASSERT_MOBILE_RADIO_STATE_EQUALITY
#define ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(webidlState, xpidlState) \
static_assert(static_cast<int32_t>(MobilePreferredNetworkType::webidlState) == nsIMobileConnection::xpidlState, \
"MobilePreferredNetworkType::" #webidlState " should equal to nsIMobileConnection::" #xpidlState)
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma_gsm, PREFERRED_NETWORK_TYPE_WCDMA_GSM);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Gsm, PREFERRED_NETWORK_TYPE_GSM_ONLY);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma, PREFERRED_NETWORK_TYPE_WCDMA_ONLY);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma_gsm_auto, PREFERRED_NETWORK_TYPE_WCDMA_GSM_AUTO);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Cdma_evdo, PREFERRED_NETWORK_TYPE_CDMA_EVDO);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Cdma, PREFERRED_NETWORK_TYPE_CDMA_ONLY);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Evdo, PREFERRED_NETWORK_TYPE_EVDO_ONLY);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Wcdma_gsm_cdma_evdo, PREFERRED_NETWORK_TYPE_WCDMA_GSM_CDMA_EVDO);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte_cdma_evdo, PREFERRED_NETWORK_TYPE_LTE_CDMA_EVDO);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte_wcdma_gsm, PREFERRED_NETWORK_TYPE_LTE_WCDMA_GSM);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte_wcdma_gsm_cdma_evdo, PREFERRED_NETWORK_TYPE_LTE_WCDMA_GSM_CDMA_EVDO);
ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY(Lte, PREFERRED_NETWORK_TYPE_LTE_ONLY);
#undef ASSERT_PREFERRED_NETWORK_TYPE_EQUALITY
} // namespace dom
} // namespace mozilla

View File

@ -477,8 +477,7 @@ MobileConnection::SetPreferredNetworkType(MobilePreferredNetworkType& aType,
return nullptr;
}
nsAutoString type;
CONVERT_ENUM_TO_STRING(MobilePreferredNetworkType, aType, type);
int32_t type = static_cast<int32_t>(aType);
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsRefPtr<MobileConnectionCallback> requestCallback =

View File

@ -15,6 +15,13 @@ namespace mozilla {
namespace dom {
namespace mobileconnection {
#define CONVERT_ENUM_TO_STRING(_enumType, _enum, _string) \
{ \
uint32_t index = uint32_t(_enum); \
_string.AssignASCII(_enumType##Values::strings[index].value, \
_enumType##Values::strings[index].length); \
}
NS_IMPL_ISUPPORTS(MobileConnectionCallback, nsIMobileConnectionCallback)
MobileConnectionCallback::MobileConnectionCallback(nsPIDOMWindow* aWindow,
@ -349,6 +356,18 @@ MobileConnectionCallback::NotifyGetClirStatusSuccess(uint16_t aN, uint16_t aM)
return NotifySuccess(jsResult);
};
NS_IMETHODIMP
MobileConnectionCallback::NotifyGetPreferredNetworkTypeSuccess(int32_t aType)
{
MOZ_ASSERT(aType < static_cast<int32_t>(MobilePreferredNetworkType::EndGuard_));
MobilePreferredNetworkType type = static_cast<MobilePreferredNetworkType>(aType);
nsAutoString typeString;
CONVERT_ENUM_TO_STRING(MobilePreferredNetworkType, type, typeString);
return NotifySuccessWithString(typeString);
};
NS_IMETHODIMP
MobileConnectionCallback::NotifyError(const nsAString& aName,
const nsAString& aMessage,

View File

@ -178,11 +178,10 @@ MobileConnectionChild::SelectNetworkAutomatically(nsIMobileConnectionCallback* a
NS_IMETHODIMP
MobileConnectionChild::SetPreferredNetworkType(const nsAString& aType,
MobileConnectionChild::SetPreferredNetworkType(int32_t aType,
nsIMobileConnectionCallback* aCallback)
{
return SendRequest(SetPreferredNetworkTypeRequest(nsAutoString(aType)),
aCallback)
return SendRequest(SetPreferredNetworkTypeRequest(aType), aCallback)
? NS_OK : NS_ERROR_FAILURE;
}
@ -661,6 +660,12 @@ MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessClirStat
aReply.m()));
}
bool
MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessPreferredNetworkType& aReply)
{
return NS_SUCCEEDED(mRequestCallback->NotifyGetPreferredNetworkTypeSuccess(aReply.type()));
}
bool
MobileConnectionRequestChild::DoReply(const MobileConnectionReplyError& aReply)
{
@ -715,6 +720,8 @@ MobileConnectionRequestChild::Recv__delete__(const MobileConnectionReply& aReply
return DoReply(aReply.get_MobileConnectionReplySuccessCallBarring());
case MobileConnectionReply::TMobileConnectionReplySuccessClirStatus:
return DoReply(aReply.get_MobileConnectionReplySuccessClirStatus());
case MobileConnectionReply::TMobileConnectionReplySuccessPreferredNetworkType:
return DoReply(aReply.get_MobileConnectionReplySuccessPreferredNetworkType());
case MobileConnectionReply::TMobileConnectionReplyError:
return DoReply(aReply.get_MobileConnectionReplyError());
case MobileConnectionReply::TMobileConnectionReplyErrorMmi:

View File

@ -163,6 +163,9 @@ public:
bool
DoReply(const MobileConnectionReplySuccessClirStatus& aReply);
bool
DoReply(const MobileConnectionReplySuccessPreferredNetworkType& aReply);
bool
DoReply(const MobileConnectionReplyError& aReply);

View File

@ -642,6 +642,12 @@ MobileConnectionRequestParent::NotifyGetClirStatusSuccess(uint16_t aN,
return SendReply(MobileConnectionReplySuccessClirStatus(aN, aM));
}
NS_IMETHODIMP
MobileConnectionRequestParent::NotifyGetPreferredNetworkTypeSuccess(int32_t aType)
{
return SendReply(MobileConnectionReplySuccessPreferredNetworkType(aType));
}
NS_IMETHODIMP
MobileConnectionRequestParent::NotifyError(const nsAString& aName,
const nsAString& aMessage,

View File

@ -72,7 +72,7 @@ struct SelectNetworkAutoRequest
struct SetPreferredNetworkTypeRequest
{
nsString type;
int32_t type;
};
struct GetPreferredNetworkTypeRequest

View File

@ -70,6 +70,11 @@ struct MobileConnectionReplySuccessClirStatus
uint16_t m;
};
struct MobileConnectionReplySuccessPreferredNetworkType
{
int32_t type;
};
// Error
struct MobileConnectionReplyError
{
@ -95,6 +100,7 @@ union MobileConnectionReply
MobileConnectionReplySuccessCallForwarding;
MobileConnectionReplySuccessCallBarring;
MobileConnectionReplySuccessClirStatus;
MobileConnectionReplySuccessPreferredNetworkType;
// Error
MobileConnectionReplyError;
MobileConnectionReplyErrorMmi;