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 {
|
namespace mozilla {
|
||||||
|
|
||||||
#define NFCD_MAJOR_VERSION 1
|
#define NFCD_MAJOR_VERSION 1
|
||||||
#define NFCD_MINOR_VERSION 20
|
#define NFCD_MINOR_VERSION 21
|
||||||
|
|
||||||
enum NfcRequest {
|
enum NfcRequest {
|
||||||
ChangeRFStateReq = 0,
|
ChangeRFStateReq,
|
||||||
ReadNDEFReq,
|
ReadNDEFReq,
|
||||||
WriteNDEFReq,
|
WriteNDEFReq,
|
||||||
MakeReadOnlyReq,
|
MakeReadOnlyReq,
|
||||||
@ -20,14 +20,16 @@ enum NfcRequest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum NfcResponse {
|
enum NfcResponse {
|
||||||
GeneralRsp = 1000,
|
|
||||||
ChangeRFStateRsp,
|
ChangeRFStateRsp,
|
||||||
ReadNDEFRsp,
|
ReadNDEFRsp,
|
||||||
TransceiveRsp
|
WriteNDEFRsp,
|
||||||
|
MakeReadOnlyRsp,
|
||||||
|
FormatRsp,
|
||||||
|
TransceiveRsp,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum NfcNotification {
|
enum NfcNotification {
|
||||||
Initialized = 2000,
|
Initialized,
|
||||||
TechDiscovered,
|
TechDiscovered,
|
||||||
TechLost,
|
TechLost,
|
||||||
HCIEventTransaction,
|
HCIEventTransaction,
|
||||||
|
@ -49,13 +49,10 @@ NfcMessageHandler::Marshall(Parcel& aParcel, const CommandOptions& aOptions)
|
|||||||
result = ReadNDEFRequest(aParcel, aOptions);
|
result = ReadNDEFRequest(aParcel, aOptions);
|
||||||
} else if (!strcmp(type, kWriteNDEFRequest)) {
|
} else if (!strcmp(type, kWriteNDEFRequest)) {
|
||||||
result = WriteNDEFRequest(aParcel, aOptions);
|
result = WriteNDEFRequest(aParcel, aOptions);
|
||||||
mPendingReqQueue.AppendElement(NfcRequest::WriteNDEFReq);
|
|
||||||
} else if (!strcmp(type, kMakeReadOnlyRequest)) {
|
} else if (!strcmp(type, kMakeReadOnlyRequest)) {
|
||||||
result = MakeReadOnlyRequest(aParcel, aOptions);
|
result = MakeReadOnlyRequest(aParcel, aOptions);
|
||||||
mPendingReqQueue.AppendElement(NfcRequest::MakeReadOnlyReq);
|
|
||||||
} else if (!strcmp(type, kFormatRequest)) {
|
} else if (!strcmp(type, kFormatRequest)) {
|
||||||
result = FormatRequest(aParcel, aOptions);
|
result = FormatRequest(aParcel, aOptions);
|
||||||
mPendingReqQueue.AppendElement(NfcRequest::FormatReq);
|
|
||||||
} else if (!strcmp(type, kTransceiveRequest)) {
|
} else if (!strcmp(type, kTransceiveRequest)) {
|
||||||
result = TransceiveRequest(aParcel, aOptions);
|
result = TransceiveRequest(aParcel, aOptions);
|
||||||
} else {
|
} else {
|
||||||
@ -68,23 +65,46 @@ NfcMessageHandler::Marshall(Parcel& aParcel, const CommandOptions& aOptions)
|
|||||||
bool
|
bool
|
||||||
NfcMessageHandler::Unmarshall(const Parcel& aParcel, EventOptions& aOptions)
|
NfcMessageHandler::Unmarshall(const Parcel& aParcel, EventOptions& aOptions)
|
||||||
{
|
{
|
||||||
bool result;
|
|
||||||
mozilla::unused << htonl(aParcel.readInt32()); // parcel size
|
mozilla::unused << htonl(aParcel.readInt32()); // parcel size
|
||||||
int32_t type = aParcel.readInt32();
|
int32_t type = aParcel.readInt32();
|
||||||
|
bool isNotification = type >> 31;
|
||||||
|
int32_t msgType = type & ~(1 << 31);
|
||||||
|
|
||||||
switch (type) {
|
return isNotification ? ProcessNotification(msgType, aParcel, aOptions) :
|
||||||
case NfcResponse::GeneralRsp:
|
ProcessResponse(msgType, aParcel, aOptions);
|
||||||
result = GeneralResponse(aParcel, aOptions);
|
}
|
||||||
break;
|
|
||||||
|
bool
|
||||||
|
NfcMessageHandler::ProcessResponse(int32_t aType, const Parcel& aParcel, EventOptions& aOptions)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
switch (aType) {
|
||||||
case NfcResponse::ChangeRFStateRsp:
|
case NfcResponse::ChangeRFStateRsp:
|
||||||
result = ChangeRFStateResponse(aParcel, aOptions);
|
result = ChangeRFStateResponse(aParcel, aOptions);
|
||||||
break;
|
break;
|
||||||
case NfcResponse::ReadNDEFRsp:
|
case NfcResponse::ReadNDEFRsp:
|
||||||
result = ReadNDEFResponse(aParcel, aOptions);
|
result = ReadNDEFResponse(aParcel, aOptions);
|
||||||
break;
|
break;
|
||||||
|
case NfcResponse::WriteNDEFRsp: // Fall through.
|
||||||
|
case NfcResponse::MakeReadOnlyRsp:
|
||||||
|
case NfcResponse::FormatRsp:
|
||||||
|
result = GeneralResponse(aType, aParcel, aOptions);
|
||||||
|
break;
|
||||||
case NfcResponse::TransceiveRsp:
|
case NfcResponse::TransceiveRsp:
|
||||||
result = TransceiveResponse(aParcel, aOptions);
|
result = TransceiveResponse(aParcel, aOptions);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
NfcMessageHandler::ProcessNotification(int32_t aType, const Parcel& aParcel, EventOptions& aOptions)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
switch (aType) {
|
||||||
case NfcNotification::Initialized:
|
case NfcNotification::Initialized:
|
||||||
result = InitializeNotification(aParcel, aOptions);
|
result = InitializeNotification(aParcel, aOptions);
|
||||||
break;
|
break;
|
||||||
@ -106,25 +126,21 @@ NfcMessageHandler::Unmarshall(const Parcel& aParcel, EventOptions& aOptions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
NfcMessageHandler::GeneralResponse(const Parcel& aParcel, EventOptions& aOptions)
|
NfcMessageHandler::GeneralResponse(const int32_t aResponse, const Parcel& aParcel, EventOptions& aOptions)
|
||||||
{
|
{
|
||||||
const char* type;
|
const char* type;
|
||||||
NS_ENSURE_TRUE(!mPendingReqQueue.IsEmpty(), false);
|
switch (aResponse) {
|
||||||
int pendingReq = mPendingReqQueue[0];
|
case NfcResponse::WriteNDEFRsp:
|
||||||
mPendingReqQueue.RemoveElementAt(0);
|
|
||||||
|
|
||||||
switch (pendingReq) {
|
|
||||||
case NfcRequest::WriteNDEFReq:
|
|
||||||
type = kWriteNDEFResponse;
|
type = kWriteNDEFResponse;
|
||||||
break;
|
break;
|
||||||
case NfcRequest::MakeReadOnlyReq:
|
case NfcResponse::MakeReadOnlyRsp:
|
||||||
type = kMakeReadOnlyResponse;
|
type = kMakeReadOnlyResponse;
|
||||||
break;
|
break;
|
||||||
case NfcRequest::FormatReq:
|
case NfcResponse::FormatRsp:
|
||||||
type = kFormatResponse;
|
type = kFormatResponse;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NMH_LOG("Nfcd, unknown general response %d", pendingReq);
|
NMH_LOG("Nfcd, unknown general aResponse %d", aResponse);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,8 @@ public:
|
|||||||
bool Unmarshall(const android::Parcel& aParcel, EventOptions& aOptions);
|
bool Unmarshall(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||||
|
|
||||||
private:
|
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 ChangeRFStateRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||||
bool ChangeRFStateResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
bool ChangeRFStateResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||||
bool ReadNDEFRequest(android::Parcel& aParcel, const CommandOptions& options);
|
bool ReadNDEFRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||||
@ -35,6 +36,7 @@ private:
|
|||||||
bool TransceiveRequest(android::Parcel& aParcel, const CommandOptions& options);
|
bool TransceiveRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||||
bool TransceiveResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
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 InitializeNotification(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||||
bool TechDiscoveredNotification(const android::Parcel& aParcel, EventOptions& aOptions);
|
bool TechDiscoveredNotification(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||||
bool TechLostNotification(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 WriteNDEFMessage(android::Parcel& aParcel, const CommandOptions& aOptions);
|
||||||
bool ReadTransceiveResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
bool ReadTransceiveResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||||
private:
|
private:
|
||||||
nsTArray<int32_t> mPendingReqQueue;
|
|
||||||
nsTArray<nsString> mRequestIdQueue;
|
nsTArray<nsString> mRequestIdQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user