Bug 1053116 - Part 2: add error code in NfcGonkMessages.h. r=dimi
authorYoshi Huang <allstars.chh@mozilla.com>
Fri, 15 Aug 2014 10:04:51 +0800
changeset 199727 d7c82822bf6740d05008a326bf2ec54bc61c2350
parent 199726 eb8fcaf1fd4a8cd8c35f37833a6822a1a610f8ac
child 199728 ae77d498ecaeed48319e017eedd7292c3d680918
push id27316
push useremorley@mozilla.com
push dateFri, 15 Aug 2014 15:59:55 +0000
treeherdermozilla-central@e251eb85cc32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1053116
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1053116 - Part 2: add error code in NfcGonkMessages.h. r=dimi
dom/nfc/gonk/NfcGonkMessage.h
dom/nfc/gonk/NfcMessageHandler.cpp
--- a/dom/nfc/gonk/NfcGonkMessage.h
+++ b/dom/nfc/gonk/NfcGonkMessage.h
@@ -6,40 +6,75 @@
 #define NfcGonkMessage_h
 
 namespace mozilla {
 
 #define NFCD_MAJOR_VERSION 1
 #define NFCD_MINOR_VERSION 7
 
 enum NfcRequest {
-  eNfcRequest_Config = 0,
-  eNfcRequest_Connect,
-  eNfcRequest_Close,
-  eNfcRequest_GetDetailsNDEF,
-  eNfcRequest_ReadNDEF,
-  eNfcRequest_WriteNDEF,
-  eNfcRequest_MakeReadOnlyNDEF,
+  ConfigReq = 0,
+  ConnectReq,
+  CloseReq,
+  GetDetailsNDEFReq,
+  ReadNDEFReq,
+  WriteNDEFReq,
+  MakeReadOnlyNDEFReq,
 };
 
 enum NfcResponse {
-  eNfcResponse_General = 1000,
-  eNfcResponse_Config,
-  eNfcResponse_GetDetailsNDEF,
-  eNfcResponse_ReadNDEF,
+  GeneralRsp = 1000,
+  ConfigRsp,
+  GetDetailsNDEFRsp,
+  ReadNDEFRsp,
 };
 
 enum NfcNotification {
-  eNfcNotification_Initialized = 2000,
-  eNfcNotification_TechDiscovered,
-  eNfcNotification_TechLost,
+  Initialized = 2000,
+  TechDiscovered,
+  TechLost,
 };
 
 enum NfcTechlogy {
-  eNfcTechlogy_NDEF = 0,
-  eNfcTechlogy_NDEFWritable,
-  eNfcTechlogy_NDEFFormattable,
-  eNfcTechlogy_P2P,
+  NDEF = 0,
+  NDEFWritable,
+  NDEFFormattable,
+  P2P,
+};
+
+enum NfcErrorCode {
+  Success = 0,
+  IOErr = -1,
+  Cancelled = -2,
+  Timeout = -3,
+  BusyErr = -4,
+  ConnectErr = -5,
+  DisconnectErr = -6,
+  ReadErr = -7,
+  WriteErr = -8,
+  InvalidParam = -9,
+  InsufficientResources = -10,
+  SocketCreation = -11,
+  SocketNotConnected = -12,
+  BufferTooSmall = -13,
+  SapUsed = -14,
+  ServiceNameUsed = -15,
+  SocketOptions = -16,
+  FailEnableDiscovery = -17,
+  FailDisableDiscovery = -18,
+  NotInitialized = -19,
+  InitializeFail = -20,
+  DeinitializeFail = -21,
+  SeConnected = -22,
+  NoSeConnected = -23,
+  NotSupported = -24,
+  BadSessionId = -25,
+  LostTech = -26,
+  BadTechType = -27,
+  SelectSeFail = -28,
+  DeselectSeFail = -29,
+  FailEnableLowPowerMode = -30,
+  FailDisableLowPowerMode = -31,
 };
 
 } // namespace mozilla
 
 #endif // NfcGonkMessage_h
--- a/dom/nfc/gonk/NfcMessageHandler.cpp
+++ b/dom/nfc/gonk/NfcMessageHandler.cpp
@@ -43,60 +43,60 @@ NfcMessageHandler::Marshall(Parcel& aPar
   if (!strcmp(type, kConfigRequest)) {
     result = ConfigRequest(aParcel, aOptions);
   } else if (!strcmp(type, kGetDetailsNDEF)) {
     result = GetDetailsNDEFRequest(aParcel, aOptions);
   } else if (!strcmp(type, kReadNDEFRequest)) {
     result = ReadNDEFRequest(aParcel, aOptions);
   } else if (!strcmp(type, kWriteNDEFRequest)) {
     result = WriteNDEFRequest(aParcel, aOptions);
-    mPendingReqQueue.AppendElement(eNfcRequest_WriteNDEF);
+    mPendingReqQueue.AppendElement(NfcRequest::WriteNDEFReq);
   } else if (!strcmp(type, kMakeReadOnlyNDEFRequest)) {
     result = MakeReadOnlyNDEFRequest(aParcel, aOptions);
-    mPendingReqQueue.AppendElement(eNfcRequest_MakeReadOnlyNDEF);
+    mPendingReqQueue.AppendElement(NfcRequest::MakeReadOnlyNDEFReq);
   } else if (!strcmp(type, kConnectRequest)) {
     result = ConnectRequest(aParcel, aOptions);
-    mPendingReqQueue.AppendElement(eNfcRequest_Connect);
+    mPendingReqQueue.AppendElement(NfcRequest::ConnectReq);
   } else if (!strcmp(type, kCloseRequest)) {
     result = CloseRequest(aParcel, aOptions);
-    mPendingReqQueue.AppendElement(eNfcRequest_Close);
+    mPendingReqQueue.AppendElement(NfcRequest::CloseReq);
   } else {
     result = false;
   }
 
   return result;
 }
 
 bool
 NfcMessageHandler::Unmarshall(const Parcel& aParcel, EventOptions& aOptions)
 {
   bool result;
   uint32_t parcelSize = htonl(aParcel.readInt32());
   int32_t type = aParcel.readInt32();
 
   switch (type) {
-    case eNfcResponse_General:
+    case NfcResponse::GeneralRsp:
       result = GeneralResponse(aParcel, aOptions);
       break;
-    case eNfcResponse_Config:
+    case NfcResponse::ConfigRsp:
       result = ConfigResponse(aParcel, aOptions);
       break;
-    case eNfcResponse_GetDetailsNDEF:
+    case NfcResponse::GetDetailsNDEFRsp:
       result = GetDetailsNDEFResponse(aParcel, aOptions);
       break;
-    case eNfcResponse_ReadNDEF:
+    case NfcResponse::ReadNDEFRsp:
       result = ReadNDEFResponse(aParcel, aOptions);
       break;
-    case eNfcNotification_Initialized:
+    case NfcNotification::Initialized:
       result = InitializeNotification(aParcel, aOptions);
       break;
-    case eNfcNotification_TechDiscovered:
+    case NfcNotification::TechDiscovered:
       result = TechDiscoveredNotification(aParcel, aOptions);
       break;
-    case eNfcNotification_TechLost:
+    case NfcNotification::TechLost:
       result = TechLostNotification(aParcel, aOptions);
       break;
     default:
       result = false;
       break;
   }
 
   return result;
@@ -106,26 +106,26 @@ bool
 NfcMessageHandler::GeneralResponse(const Parcel& aParcel, EventOptions& aOptions)
 {
   const char* type;
   NS_ENSURE_TRUE(!mPendingReqQueue.IsEmpty(), false);
   int pendingReq = mPendingReqQueue[0];
   mPendingReqQueue.RemoveElementAt(0);
 
   switch (pendingReq) {
-    case eNfcRequest_WriteNDEF:
+    case NfcRequest::WriteNDEFReq:
       type = kWriteNDEFResponse;
       break;
-    case eNfcRequest_MakeReadOnlyNDEF:
+    case NfcRequest::MakeReadOnlyNDEFReq:
       type = kMakeReadOnlyNDEFResponse;
       break;
-    case eNfcRequest_Connect:
+    case NfcRequest::ConnectReq:
       type = kConnectResponse;
       break;
-    case eNfcRequest_Close:
+    case NfcRequest::CloseReq:
       type = kCloseResponse;
       break;
   }
 
   aOptions.mType = NS_ConvertUTF8toUTF16(type);
   aOptions.mStatus = aParcel.readInt32();
   aOptions.mSessionId = aParcel.readInt32();
 
@@ -133,17 +133,17 @@ NfcMessageHandler::GeneralResponse(const
   aOptions.mRequestId = mRequestIdQueue[0];
   mRequestIdQueue.RemoveElementAt(0);
   return true;
 }
 
 bool
 NfcMessageHandler::ConfigRequest(Parcel& aParcel, const CommandOptions& aOptions)
 {
-  aParcel.writeInt32(eNfcRequest_Config);
+  aParcel.writeInt32(NfcRequest::ConfigReq);
   aParcel.writeInt32(aOptions.mPowerLevel);
   mRequestIdQueue.AppendElement(aOptions.mRequestId);
   mPowerLevelQueue.AppendElement(aOptions.mPowerLevel);
   return true;
 }
 
 bool
 NfcMessageHandler::ConfigResponse(const Parcel& aParcel, EventOptions& aOptions)
@@ -159,17 +159,17 @@ NfcMessageHandler::ConfigResponse(const 
   aOptions.mPowerLevel = mPowerLevelQueue[0];
   mPowerLevelQueue.RemoveElementAt(0);
   return true;
 }
 
 bool
 NfcMessageHandler::GetDetailsNDEFRequest(Parcel& aParcel, const CommandOptions& aOptions)
 {
-  aParcel.writeInt32(eNfcRequest_GetDetailsNDEF);
+  aParcel.writeInt32(NfcRequest::GetDetailsNDEFReq);
   aParcel.writeInt32(aOptions.mSessionId);
   mRequestIdQueue.AppendElement(aOptions.mRequestId);
   return true;
 }
 
 bool
 NfcMessageHandler::GetDetailsNDEFResponse(const Parcel& aParcel, EventOptions& aOptions)
 {
@@ -185,17 +185,17 @@ NfcMessageHandler::GetDetailsNDEFRespons
   aOptions.mRequestId = mRequestIdQueue[0];
   mRequestIdQueue.RemoveElementAt(0);
   return true;
 }
 
 bool
 NfcMessageHandler::ReadNDEFRequest(Parcel& aParcel, const CommandOptions& aOptions)
 {
-  aParcel.writeInt32(eNfcRequest_ReadNDEF);
+  aParcel.writeInt32(NfcRequest::ReadNDEFReq);
   aParcel.writeInt32(aOptions.mSessionId);
   mRequestIdQueue.AppendElement(aOptions.mRequestId);
   return true;
 }
 
 bool
 NfcMessageHandler::ReadNDEFResponse(const Parcel& aParcel, EventOptions& aOptions)
 {
@@ -208,46 +208,46 @@ NfcMessageHandler::ReadNDEFResponse(cons
   mRequestIdQueue.RemoveElementAt(0);
   ReadNDEFMessage(aParcel, aOptions);
   return true;
 }
 
 bool
 NfcMessageHandler::WriteNDEFRequest(Parcel& aParcel, const CommandOptions& aOptions)
 {
-  aParcel.writeInt32(eNfcRequest_WriteNDEF);
+  aParcel.writeInt32(NfcRequest::WriteNDEFReq);
   aParcel.writeInt32(aOptions.mSessionId);
   WriteNDEFMessage(aParcel, aOptions);
   mRequestIdQueue.AppendElement(aOptions.mRequestId);
   return true;
 }
 
 bool
 NfcMessageHandler::MakeReadOnlyNDEFRequest(Parcel& aParcel, const CommandOptions& aOptions)
 {
-  aParcel.writeInt32(eNfcRequest_MakeReadOnlyNDEF);
+  aParcel.writeInt32(NfcRequest::MakeReadOnlyNDEFReq);
   aParcel.writeInt32(aOptions.mSessionId);
   mRequestIdQueue.AppendElement(aOptions.mRequestId);
   return true;
 }
 
 bool
 NfcMessageHandler::ConnectRequest(Parcel& aParcel, const CommandOptions& aOptions)
 {
-  aParcel.writeInt32(eNfcRequest_Connect);
+  aParcel.writeInt32(NfcRequest::ConnectReq);
   aParcel.writeInt32(aOptions.mSessionId);
   aParcel.writeInt32(aOptions.mTechType);
   mRequestIdQueue.AppendElement(aOptions.mRequestId);
   return true;
 }
 
 bool
 NfcMessageHandler::CloseRequest(Parcel& aParcel, const CommandOptions& aOptions)
 {
-  aParcel.writeInt32(eNfcRequest_Close);
+  aParcel.writeInt32(NfcRequest::CloseReq);
   aParcel.writeInt32(aOptions.mSessionId);
   mRequestIdQueue.AppendElement(aOptions.mRequestId);
   return true;
 }
 
 bool
 NfcMessageHandler::InitializeNotification(const Parcel& aParcel, EventOptions& aOptions)
 {