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

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

@ -65,15 +65,10 @@ MobileConnectionCallback::NotifySuccess(JS::Handle<JS::Value> aResult)
return rs->FireSuccessAsync(mRequest, aResult); return rs->FireSuccessAsync(mRequest, aResult);
} }
// nsIMobileConnectionCallback /**
* Notify Success with string.
NS_IMETHODIMP */
MobileConnectionCallback::NotifySuccess() nsresult
{
return NotifySuccess(JS::UndefinedHandleValue);
}
NS_IMETHODIMP
MobileConnectionCallback::NotifySuccessWithString(const nsAString& aResult) MobileConnectionCallback::NotifySuccessWithString(const nsAString& aResult)
{ {
AutoJSAPI jsapi; AutoJSAPI jsapi;
@ -92,6 +87,14 @@ MobileConnectionCallback::NotifySuccessWithString(const nsAString& aResult)
return NotifySuccess(jsResult); return NotifySuccess(jsResult);
} }
// nsIMobileConnectionCallback
NS_IMETHODIMP
MobileConnectionCallback::NotifySuccess()
{
return NotifySuccess(JS::UndefinedHandleValue);
}
NS_IMETHODIMP NS_IMETHODIMP
MobileConnectionCallback::NotifySuccessWithBoolean(bool aResult) MobileConnectionCallback::NotifySuccessWithBoolean(bool aResult)
{ {
@ -368,6 +371,18 @@ MobileConnectionCallback::NotifyGetPreferredNetworkTypeSuccess(int32_t aType)
return NotifySuccessWithString(typeString); 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 NS_IMETHODIMP
MobileConnectionCallback::NotifyError(const nsAString& aName, MobileConnectionCallback::NotifyError(const nsAString& aName,
const nsAString& aMessage, const nsAString& aMessage,

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

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

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

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

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

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

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

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

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

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

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

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