Bug 1052848 - Part 2: Use enums for MobileRoamingMode in nsIMobileConnectionProvider.idl (dom/ipc). r=echen

This commit is contained in:
Jessica Jong 2014-11-10 17:56:13 +08:00
Родитель 5fa7de6764
Коммит 9f245f49e3
8 изменённых файлов: 54 добавлений и 45 удалений

Просмотреть файл

@ -39,13 +39,6 @@
} \
}
#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); \
}
using mozilla::ErrorResult;
using namespace mozilla::dom;
using namespace mozilla::dom::mobileconnection;
@ -523,8 +516,7 @@ MobileConnection::SetRoamingPreference(MobileRoamingMode& aMode,
return nullptr;
}
nsAutoString mode;
CONVERT_ENUM_TO_STRING(MobileRoamingMode, aMode, mode);
int32_t mode = static_cast<int32_t>(aMode);
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsRefPtr<MobileConnectionCallback> requestCallback =

Просмотреть файл

@ -65,15 +65,10 @@ MobileConnectionCallback::NotifySuccess(JS::Handle<JS::Value> aResult)
return rs->FireSuccessAsync(mRequest, aResult);
}
// nsIMobileConnectionCallback
NS_IMETHODIMP
MobileConnectionCallback::NotifySuccess()
{
return NotifySuccess(JS::UndefinedHandleValue);
}
NS_IMETHODIMP
/**
* Notify Success with string.
*/
nsresult
MobileConnectionCallback::NotifySuccessWithString(const nsAString& aResult)
{
AutoJSAPI jsapi;
@ -92,6 +87,14 @@ MobileConnectionCallback::NotifySuccessWithString(const nsAString& aResult)
return NotifySuccess(jsResult);
}
// nsIMobileConnectionCallback
NS_IMETHODIMP
MobileConnectionCallback::NotifySuccess()
{
return NotifySuccess(JS::UndefinedHandleValue);
}
NS_IMETHODIMP
MobileConnectionCallback::NotifySuccessWithBoolean(bool aResult)
{
@ -368,6 +371,18 @@ MobileConnectionCallback::NotifyGetPreferredNetworkTypeSuccess(int32_t aType)
return NotifySuccessWithString(typeString);
};
NS_IMETHODIMP
MobileConnectionCallback::NotifyGetRoamingPreferenceSuccess(int32_t aMode)
{
MOZ_ASSERT(aMode < static_cast<int32_t>(MobileRoamingMode::EndGuard_));
MobileRoamingMode mode = static_cast<MobileRoamingMode>(aMode);
nsAutoString modeString;
CONVERT_ENUM_TO_STRING(MobileRoamingMode, mode, modeString);
return NotifySuccessWithString(modeString);
};
NS_IMETHODIMP
MobileConnectionCallback::NotifyError(const nsAString& aName,
const nsAString& aMessage,

Просмотреть файл

@ -38,6 +38,9 @@ private:
nsresult
NotifySuccess(JS::Handle<JS::Value> aResult);
nsresult
NotifySuccessWithString(const nsAString& aResult);
nsresult
NotifySendCancelMmiSuccess(const MozMMIResult& aResult);

Просмотреть файл

@ -193,11 +193,10 @@ MobileConnectionChild::GetPreferredNetworkType(nsIMobileConnectionCallback* aCal
}
NS_IMETHODIMP
MobileConnectionChild::SetRoamingPreference(const nsAString& aMode,
MobileConnectionChild::SetRoamingPreference(int32_t aMode,
nsIMobileConnectionCallback* aCallback)
{
return SendRequest(SetRoamingPreferenceRequest(nsAutoString(aMode)),
aCallback)
return SendRequest(SetRoamingPreferenceRequest(aMode), aCallback)
? NS_OK : NS_ERROR_FAILURE;
}
@ -547,12 +546,6 @@ MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccess& aReply
return NS_SUCCEEDED(mRequestCallback->NotifySuccess());
}
bool
MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessString& aReply)
{
return NS_SUCCEEDED(mRequestCallback->NotifySuccessWithString(aReply.result()));
}
bool
MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessBoolean& aReply)
{
@ -666,6 +659,12 @@ MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessPreferre
return NS_SUCCEEDED(mRequestCallback->NotifyGetPreferredNetworkTypeSuccess(aReply.type()));
}
bool
MobileConnectionRequestChild::DoReply(const MobileConnectionReplySuccessRoamingPreference& aReply)
{
return NS_SUCCEEDED(mRequestCallback->NotifyGetRoamingPreferenceSuccess(aReply.mode()));
}
bool
MobileConnectionRequestChild::DoReply(const MobileConnectionReplyError& aReply)
{
@ -706,8 +705,6 @@ MobileConnectionRequestChild::Recv__delete__(const MobileConnectionReply& aReply
switch (aReply.type()) {
case MobileConnectionReply::TMobileConnectionReplySuccess:
return DoReply(aReply.get_MobileConnectionReplySuccess());
case MobileConnectionReply::TMobileConnectionReplySuccessString:
return DoReply(aReply.get_MobileConnectionReplySuccessString());
case MobileConnectionReply::TMobileConnectionReplySuccessBoolean:
return DoReply(aReply.get_MobileConnectionReplySuccessBoolean());
case MobileConnectionReply::TMobileConnectionReplySuccessNetworks:
@ -722,6 +719,8 @@ MobileConnectionRequestChild::Recv__delete__(const MobileConnectionReply& aReply
return DoReply(aReply.get_MobileConnectionReplySuccessClirStatus());
case MobileConnectionReply::TMobileConnectionReplySuccessPreferredNetworkType:
return DoReply(aReply.get_MobileConnectionReplySuccessPreferredNetworkType());
case MobileConnectionReply::TMobileConnectionReplySuccessRoamingPreference:
return DoReply(aReply.get_MobileConnectionReplySuccessRoamingPreference());
case MobileConnectionReply::TMobileConnectionReplyError:
return DoReply(aReply.get_MobileConnectionReplyError());
case MobileConnectionReply::TMobileConnectionReplyErrorMmi:

Просмотреть файл

@ -142,9 +142,6 @@ public:
bool
DoReply(const MobileConnectionReplySuccess& aReply);
bool
DoReply(const MobileConnectionReplySuccessString& aReply);
bool
DoReply(const MobileConnectionReplySuccessBoolean& aReply);
@ -166,6 +163,9 @@ public:
bool
DoReply(const MobileConnectionReplySuccessPreferredNetworkType& aReply);
bool
DoReply(const MobileConnectionReplySuccessRoamingPreference& aMode);
bool
DoReply(const MobileConnectionReplyError& aReply);

Просмотреть файл

@ -537,12 +537,6 @@ MobileConnectionRequestParent::NotifySuccess()
return SendReply(MobileConnectionReplySuccess());
}
NS_IMETHODIMP
MobileConnectionRequestParent::NotifySuccessWithString(const nsAString& aResult)
{
return SendReply(MobileConnectionReplySuccessString(nsAutoString(aResult)));
}
NS_IMETHODIMP
MobileConnectionRequestParent::NotifySuccessWithBoolean(bool aResult)
{
@ -648,6 +642,12 @@ MobileConnectionRequestParent::NotifyGetPreferredNetworkTypeSuccess(int32_t aTyp
return SendReply(MobileConnectionReplySuccessPreferredNetworkType(aType));
}
NS_IMETHODIMP
MobileConnectionRequestParent::NotifyGetRoamingPreferenceSuccess(int32_t aMode)
{
return SendReply(MobileConnectionReplySuccessRoamingPreference(aMode));
}
NS_IMETHODIMP
MobileConnectionRequestParent::NotifyError(const nsAString& aName,
const nsAString& aMessage,

Просмотреть файл

@ -81,7 +81,7 @@ struct GetPreferredNetworkTypeRequest
struct SetRoamingPreferenceRequest
{
nsString mode;
int32_t mode;
};
struct GetRoamingPreferenceRequest

Просмотреть файл

@ -30,11 +30,6 @@ struct MobileConnectionReplySuccess
{
};
struct MobileConnectionReplySuccessString
{
nsString result;
};
struct MobileConnectionReplySuccessBoolean
{
bool result;
@ -75,6 +70,11 @@ struct MobileConnectionReplySuccessPreferredNetworkType
int32_t type;
};
struct MobileConnectionReplySuccessRoamingPreference
{
int32_t mode;
};
// Error
struct MobileConnectionReplyError
{
@ -93,7 +93,6 @@ union MobileConnectionReply
{
// Success
MobileConnectionReplySuccess;
MobileConnectionReplySuccessString;
MobileConnectionReplySuccessBoolean;
MobileConnectionReplySuccessNetworks;
MobileConnectionReplySuccessMmi;
@ -101,6 +100,7 @@ union MobileConnectionReply
MobileConnectionReplySuccessCallBarring;
MobileConnectionReplySuccessClirStatus;
MobileConnectionReplySuccessPreferredNetworkType;
MobileConnectionReplySuccessRoamingPreference;
// Error
MobileConnectionReplyError;
MobileConnectionReplyErrorMmi;