Bug 1141457 - Part 3: add a CommandMsgTable. r=dimi

From 7650a8e6a0ab634b90c85c0fa85a096e7d0f4ec9 Mon Sep 17 00:00:00 2001
---
 dom/nfc/gonk/Nfc.js | 36 +++++++++++++-----------------------
 1 file changed, 13 insertions(+), 23 deletions(-)
This commit is contained in:
Yoshi Huang 2015-03-10 17:06:56 +08:00
parent 18606077c9
commit 1f2cf2602d

View File

@ -91,6 +91,14 @@ const NfcRequestType = {
TRANSCEIVE: "transceive"
};
const CommandMsgTable = {};
CommandMsgTable["NFC:ChangeRFState"] = NfcRequestType.CHANGE_RF_STATE;
CommandMsgTable["NFC:ReadNDEF"] = NfcRequestType.READ_NDEF;
CommandMsgTable["NFC:WriteNDEF"] = NfcRequestType.WRITE_NDEF;
CommandMsgTable["NFC:MakeReadOnly"] = NfcRequestType.MAKE_READ_ONLY;
CommandMsgTable["NFC:Format"] = NfcRequestType.FORMAT;
CommandMsgTable["NFC:Transceive"] = NfcRequestType.TRANSCEIVE;
// Should be consistent with NfcResponseType defined in NfcOptions.webidl.
const NfcResponseType = {
CHANGE_RF_STATE_RSP: "changeRFStateRsp",
@ -690,31 +698,13 @@ Nfc.prototype = {
message.data.sessionId = SessionHelper.getId(message.data.sessionToken);
}
switch (message.name) {
case "NFC:ChangeRFState":
this.sendToNfcService(NfcRequestType.CHANGE_RF_STATE, message.data);
break;
case "NFC:ReadNDEF":
this.sendToNfcService(NfcRequestType.READ_NDEF, message.data);
break;
case "NFC:WriteNDEF":
this.sendToNfcService(NfcRequestType.WRITE_NDEF, message.data);
break;
case "NFC:MakeReadOnly":
this.sendToNfcService(NfcRequestType.MAKE_READ_ONLY, message.data);
break;
case "NFC:Format":
this.sendToNfcService(NfcRequestType.FORMAT, message.data);
break;
case "NFC:Transceive":
this.sendToNfcService(NfcRequestType.TRANSCEIVE, message.data);
break;
default:
debug("UnSupported : Message Name " + message.name);
return null;
let command = CommandMsgTable[message.name];
if (!command) {
debug("Unknown message: " + message.name);
return null;
}
this.targetsByRequestId[message.data.requestId] = message.target;
this.sendToNfcService(command, message.data);
return null;
},