mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1137101 - Refactor Response/Notification sent from nfcd. r=dimi
From 80bbb263c548a86287bec29c5983e0ca3714a841 Mon Sep 17 00:00:00 2001 --- dom/nfc/gonk/NfcGonkMessage.h | 12 +++++---- dom/nfc/gonk/NfcMessageHandler.cpp | 52 +++++++++++++++++++++++++------------- dom/nfc/gonk/NfcMessageHandler.h | 5 ++-- 3 files changed, 44 insertions(+), 25 deletions(-)
This commit is contained in:
parent
b3b621864d
commit
265d616d44
@ -8,10 +8,10 @@
|
||||
namespace mozilla {
|
||||
|
||||
#define NFCD_MAJOR_VERSION 1
|
||||
#define NFCD_MINOR_VERSION 20
|
||||
#define NFCD_MINOR_VERSION 21
|
||||
|
||||
enum NfcRequest {
|
||||
ChangeRFStateReq = 0,
|
||||
ChangeRFStateReq,
|
||||
ReadNDEFReq,
|
||||
WriteNDEFReq,
|
||||
MakeReadOnlyReq,
|
||||
@ -20,14 +20,16 @@ enum NfcRequest {
|
||||
};
|
||||
|
||||
enum NfcResponse {
|
||||
GeneralRsp = 1000,
|
||||
ChangeRFStateRsp,
|
||||
ReadNDEFRsp,
|
||||
TransceiveRsp
|
||||
WriteNDEFRsp,
|
||||
MakeReadOnlyRsp,
|
||||
FormatRsp,
|
||||
TransceiveRsp,
|
||||
};
|
||||
|
||||
enum NfcNotification {
|
||||
Initialized = 2000,
|
||||
Initialized,
|
||||
TechDiscovered,
|
||||
TechLost,
|
||||
HCIEventTransaction,
|
||||
|
@ -49,13 +49,10 @@ NfcMessageHandler::Marshall(Parcel& aParcel, const CommandOptions& aOptions)
|
||||
result = ReadNDEFRequest(aParcel, aOptions);
|
||||
} else if (!strcmp(type, kWriteNDEFRequest)) {
|
||||
result = WriteNDEFRequest(aParcel, aOptions);
|
||||
mPendingReqQueue.AppendElement(NfcRequest::WriteNDEFReq);
|
||||
} else if (!strcmp(type, kMakeReadOnlyRequest)) {
|
||||
result = MakeReadOnlyRequest(aParcel, aOptions);
|
||||
mPendingReqQueue.AppendElement(NfcRequest::MakeReadOnlyReq);
|
||||
} else if (!strcmp(type, kFormatRequest)) {
|
||||
result = FormatRequest(aParcel, aOptions);
|
||||
mPendingReqQueue.AppendElement(NfcRequest::FormatReq);
|
||||
} else if (!strcmp(type, kTransceiveRequest)) {
|
||||
result = TransceiveRequest(aParcel, aOptions);
|
||||
} else {
|
||||
@ -68,23 +65,46 @@ NfcMessageHandler::Marshall(Parcel& aParcel, const CommandOptions& aOptions)
|
||||
bool
|
||||
NfcMessageHandler::Unmarshall(const Parcel& aParcel, EventOptions& aOptions)
|
||||
{
|
||||
bool result;
|
||||
mozilla::unused << htonl(aParcel.readInt32()); // parcel size
|
||||
int32_t type = aParcel.readInt32();
|
||||
bool isNotification = type >> 31;
|
||||
int32_t msgType = type & ~(1 << 31);
|
||||
|
||||
switch (type) {
|
||||
case NfcResponse::GeneralRsp:
|
||||
result = GeneralResponse(aParcel, aOptions);
|
||||
break;
|
||||
return isNotification ? ProcessNotification(msgType, aParcel, aOptions) :
|
||||
ProcessResponse(msgType, aParcel, aOptions);
|
||||
}
|
||||
|
||||
bool
|
||||
NfcMessageHandler::ProcessResponse(int32_t aType, const Parcel& aParcel, EventOptions& aOptions)
|
||||
{
|
||||
bool result;
|
||||
switch (aType) {
|
||||
case NfcResponse::ChangeRFStateRsp:
|
||||
result = ChangeRFStateResponse(aParcel, aOptions);
|
||||
break;
|
||||
case NfcResponse::ReadNDEFRsp:
|
||||
result = ReadNDEFResponse(aParcel, aOptions);
|
||||
break;
|
||||
case NfcResponse::WriteNDEFRsp: // Fall through.
|
||||
case NfcResponse::MakeReadOnlyRsp:
|
||||
case NfcResponse::FormatRsp:
|
||||
result = GeneralResponse(aType, aParcel, aOptions);
|
||||
break;
|
||||
case NfcResponse::TransceiveRsp:
|
||||
result = TransceiveResponse(aParcel, aOptions);
|
||||
break;
|
||||
default:
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
NfcMessageHandler::ProcessNotification(int32_t aType, const Parcel& aParcel, EventOptions& aOptions)
|
||||
{
|
||||
bool result;
|
||||
switch (aType) {
|
||||
case NfcNotification::Initialized:
|
||||
result = InitializeNotification(aParcel, aOptions);
|
||||
break;
|
||||
@ -106,25 +126,21 @@ NfcMessageHandler::Unmarshall(const Parcel& aParcel, EventOptions& aOptions)
|
||||
}
|
||||
|
||||
bool
|
||||
NfcMessageHandler::GeneralResponse(const Parcel& aParcel, EventOptions& aOptions)
|
||||
NfcMessageHandler::GeneralResponse(const int32_t aResponse, const Parcel& aParcel, EventOptions& aOptions)
|
||||
{
|
||||
const char* type;
|
||||
NS_ENSURE_TRUE(!mPendingReqQueue.IsEmpty(), false);
|
||||
int pendingReq = mPendingReqQueue[0];
|
||||
mPendingReqQueue.RemoveElementAt(0);
|
||||
|
||||
switch (pendingReq) {
|
||||
case NfcRequest::WriteNDEFReq:
|
||||
switch (aResponse) {
|
||||
case NfcResponse::WriteNDEFRsp:
|
||||
type = kWriteNDEFResponse;
|
||||
break;
|
||||
case NfcRequest::MakeReadOnlyReq:
|
||||
case NfcResponse::MakeReadOnlyRsp:
|
||||
type = kMakeReadOnlyResponse;
|
||||
break;
|
||||
case NfcRequest::FormatReq:
|
||||
case NfcResponse::FormatRsp:
|
||||
type = kFormatResponse;
|
||||
break;
|
||||
default:
|
||||
NMH_LOG("Nfcd, unknown general response %d", pendingReq);
|
||||
NMH_LOG("Nfcd, unknown general aResponse %d", aResponse);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,8 @@ public:
|
||||
bool Unmarshall(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
|
||||
private:
|
||||
bool GeneralResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool ProcessResponse(int32_t aType, const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool GeneralResponse(int32_t aResponse, const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool ChangeRFStateRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
bool ChangeRFStateResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool ReadNDEFRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
@ -35,6 +36,7 @@ private:
|
||||
bool TransceiveRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
bool TransceiveResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
|
||||
bool ProcessNotification(int32_t aType, const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool InitializeNotification(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool TechDiscoveredNotification(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool TechLostNotification(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
@ -44,7 +46,6 @@ private:
|
||||
bool WriteNDEFMessage(android::Parcel& aParcel, const CommandOptions& aOptions);
|
||||
bool ReadTransceiveResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
private:
|
||||
nsTArray<int32_t> mPendingReqQueue;
|
||||
nsTArray<nsString> mRequestIdQueue;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user