[NFC] Remove try/catch to adjust to google coding style - part 2
authorLukasz Bardeli <l.bardeli@samsung.com>
Tue, 24 Feb 2015 12:51:27 +0000 (13:51 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 24 Feb 2015 14:58:10 +0000 (23:58 +0900)
Change-Id: I32d703e9e74a5917907b056042df8e2397425748
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/nfc/nfc_adapter.cc
src/nfc/nfc_adapter.h
src/nfc/nfc_api.js
src/nfc/nfc_instance.cc
src/nfc/nfc_util.cc
src/nfc/nfc_util.h

index 84244a27ebf88ef652d68907fed44eff58a7a215..f1c6f3893352e7062ad9238d974035e0c4e1a4b9 100644 (file)
@@ -39,6 +39,7 @@ NFCAdapter::NFCAdapter():
             m_is_transaction_ese_listener_set(false),
             m_is_transaction_uicc_listener_set(false),
             m_is_peer_listener_set(false),
+            m_is_tag_listener_set(false),
             m_latest_peer_id(0),
             m_peer_handle(NULL),
             m_is_ndef_listener_set(false),
@@ -176,14 +177,14 @@ static void se_event_callback(nfc_se_event_e se_event, void *user_data) {
   picojson::object& obj = event.get<picojson::object>();
   tools::ReportSuccess(obj);
 
-  string result;
+  string result = "";
   switch (se_event) {
     case NFC_SE_EVENT_SE_TYPE_CHANGED:
-      result = NFCAdapter::GetInstance()->GetActiveSecureElement();
+      NFCAdapter::GetInstance()->GetActiveSecureElement(&result);
       obj.insert(make_pair(LISTENER_ID, ACTIVE_SECURE_ELEMENT_CHANGED));
       break;
     case NFC_SE_EVENT_CARD_EMULATION_CHANGED:
-      result = NFCAdapter::GetInstance()->GetCardEmulationMode();
+      NFCAdapter::GetInstance()->GetCardEmulationMode(&result);
       obj.insert(make_pair(LISTENER_ID, CARD_EMULATION_MODE_CHANGED));
       break;
     default:
@@ -340,22 +341,22 @@ PlatformResult NFCAdapter::SetPowered(const picojson::value& args) {
 }
 
 
-std::string NFCAdapter::GetCardEmulationMode() {
+PlatformResult NFCAdapter::GetCardEmulationMode(std::string *mode) {
 
   LoggerD("Entered");
 
-  nfc_se_card_emulation_mode_type_e mode;
-  int ret = nfc_se_get_card_emulation_mode(&mode);
+  nfc_se_card_emulation_mode_type_e card_mode;
+  int ret = nfc_se_get_card_emulation_mode(&card_mode);
 
   if (NFC_ERROR_NONE != ret) {
     LoggerE("Failed to get card emulation mode %d", ret);
-    NFCUtil::throwNFCException(ret, "Failed to get card emulation mode");
+    return NFCUtil::CodeToResult(ret, "Failed to get card emulation mode");
   }
 
-  return NFCUtil::toStringCardEmulationMode(mode);
+  return NFCUtil::ToStringCardEmulationMode(card_mode, mode);
 }
 
-void NFCAdapter::SetCardEmulationMode(std::string mode) {
+PlatformResult NFCAdapter::SetCardEmulationMode(std::string mode) {
 
   LoggerD("Entered");
 
@@ -363,12 +364,17 @@ void NFCAdapter::SetCardEmulationMode(std::string mode) {
       NFCUtil::toCardEmulationMode(mode);
   LoggerD("Card emulation mode value: %x", (int)new_mode);
 
-  std::string current_mode = GetCardEmulationMode();
+  std::string current_mode = "";
+  PlatformResult result = GetCardEmulationMode(&current_mode);
+
+  if (result.IsError()) {
+    return result;
+  }
 
   if (mode.compare(current_mode) == 0) {
     LoggerD("Card emulation mode already set to given value (%s)",
             mode.c_str());
-    return;
+    return PlatformResult(ErrorCode::NO_ERROR);
   }
 
   int ret = NFC_ERROR_NONE;
@@ -381,55 +387,69 @@ void NFCAdapter::SetCardEmulationMode(std::string mode) {
       break;
     default:
       // Should never go here - in case of invalid mode
-      // exception is thrown from convertert few lines above
+      // platformResult is returned from convertert few lines above
       LoggerE("Invalid card emulation mode: %s", mode.c_str());
-      throw InvalidValuesException("Invalid card emulation mode given");
+      return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
+                            "Invalid card emulation mode given.");
   }
 
   if (NFC_ERROR_NONE != ret) {
     LoggerE("Failed to set card emulation mode %d", ret);
-    NFCUtil::throwNFCException(ret, "Failed to set card emulation mode");
+    return NFCUtil::CodeToResult(ret, "Failed to set card emulation mode");
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-std::string NFCAdapter::GetActiveSecureElement() {
+PlatformResult NFCAdapter::GetActiveSecureElement(std::string *type) {
 
   LoggerD("Entered");
 
-  nfc_se_type_e type;
-  int ret = nfc_manager_get_se_type(&type);
+  nfc_se_type_e se_type = NFC_SE_TYPE_DISABLE;
+  int ret = nfc_manager_get_se_type(&se_type);
   if (NFC_ERROR_NONE != ret) {
     LoggerE("Failed to get active secure element type: %d", ret);
-    NFCUtil::throwNFCException(ret, "Unable to get active secure element type");
+    return NFCUtil::CodeToResult(ret, "Unable to get active secure element type");
   }
 
-  return NFCUtil::toStringSecureElementType(type);
+  return NFCUtil::ToStringSecureElementType(se_type, type);
 }
 
-void NFCAdapter::SetActiveSecureElement(std::string element) {
+PlatformResult NFCAdapter::SetActiveSecureElement(std::string element) {
 
   LoggerD("Entered");
 
   // if given value is not correct secure element type then
   // there's no sense to get current value for comparison
-  nfc_se_type_e new_type = NFCUtil::toSecureElementType(element);
+  nfc_se_type_e new_type = NFC_SE_TYPE_DISABLE;
+  PlatformResult result = NFCUtil::ToSecureElementType(element, &new_type);
+
+  if (result.IsError()) {
+    return result;
+  }
   LoggerD("Secure element type value: %x", (int)new_type);
 
-  std::string current_type = GetActiveSecureElement();
+  std::string current_type = "";
+  result = GetActiveSecureElement(&current_type);
+
+  if (result.IsError()) {
+    return result;
+  }
+
   if (element == current_type) {
     LoggerD("Active secure element type already set to: %s", element.c_str());
-    return;
+    return PlatformResult(ErrorCode::NO_ERROR);
   }
 
   int ret = nfc_manager_set_se_type(new_type);
   if (NFC_ERROR_NONE != ret) {
     LoggerE("Failed to set active secure element type: %d", ret);
-    NFCUtil::throwNFCException(ret,
+    return NFCUtil::CodeToResult(ret,
                                "Unable to set active secure element type");
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-void NFCAdapter::SetExclusiveModeForTransaction(bool exmode) {
+PlatformResult NFCAdapter::SetExclusiveModeForTransaction(bool exmode) {
 
   LoggerD("Entered");
 
@@ -442,40 +462,48 @@ void NFCAdapter::SetExclusiveModeForTransaction(bool exmode) {
 
   if (NFC_ERROR_NONE != ret) {
     LoggerE("Failed to set exclusive mode for transaction: %d", ret);
-    NFCUtil::throwNFCException(ret,
+    return NFCUtil::CodeToResult(ret,
                                "Setting exclusive mode for transaction failed.");
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-void NFCAdapter::AddCardEmulationModeChangeListener() {
+PlatformResult NFCAdapter::AddCardEmulationModeChangeListener() {
   if (!m_is_listener_set) {
     int ret = nfc_manager_set_se_event_cb(se_event_callback, NULL);
     if (NFC_ERROR_NONE != ret) {
       LOGE("AddCardEmulationModeChangeListener failed: %d", ret);
-      NFCUtil::throwNFCException(ret,
+      return NFCUtil::CodeToResult(ret,
                                  NFCUtil::getNFCErrorMessage(ret).c_str());
     }
   }
 
   m_is_listener_set = true;
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-void NFCAdapter::RemoveCardEmulationModeChangeListener() {
+PlatformResult NFCAdapter::RemoveCardEmulationModeChangeListener() {
   if (!nfc_manager_is_supported()) {
-    throw NotSupportedException("NFC Not Supported");
+    LOGE("NFC Not Supported");
+    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "NFC Not Supported");
   }
 
   if (m_is_listener_set) {
     nfc_manager_unset_se_event_cb();
   }
   m_is_listener_set = false;
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 
-void NFCAdapter::AddTransactionEventListener(const picojson::value& args) {
+PlatformResult NFCAdapter::AddTransactionEventListener(const picojson::value& args) {
 
-  nfc_se_type_e se_type = NFCUtil::toSecureElementType(
-      args.get("type").get<string>());
+  nfc_se_type_e se_type = NFC_SE_TYPE_DISABLE;
+  PlatformResult result = NFCUtil::ToSecureElementType(
+      args.get("type").get<string>(), &se_type);
+  if (result.IsError()) {
+    return result;
+  }
   int ret = NFC_ERROR_NONE;
 
   if (NFC_SE_TYPE_ESE == se_type) {
@@ -494,15 +522,20 @@ void NFCAdapter::AddTransactionEventListener(const picojson::value& args) {
 
   if (NFC_ERROR_NONE != ret) {
     LOGE("AddTransactionEventListener failed: %d", ret);
-    NFCUtil::throwNFCException(ret,
+    return NFCUtil::CodeToResult(ret,
                                NFCUtil::getNFCErrorMessage(ret).c_str());
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-void NFCAdapter::RemoveTransactionEventListener(const picojson::value& args) {
+PlatformResult NFCAdapter::RemoveTransactionEventListener(const picojson::value& args) {
 
-  nfc_se_type_e se_type = NFCUtil::toSecureElementType(
-      args.get("type").get<string>());
+  nfc_se_type_e se_type = NFC_SE_TYPE_DISABLE;
+  PlatformResult result = NFCUtil::ToSecureElementType(
+      args.get("type").get<string>(), &se_type);
+  if (result.IsError()) {
+    return result;
+  }
 
   nfc_manager_unset_se_transaction_event_cb(se_type);
 
@@ -511,30 +544,34 @@ void NFCAdapter::RemoveTransactionEventListener(const picojson::value& args) {
   } else {
     m_is_transaction_uicc_listener_set = false;
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-void NFCAdapter::AddActiveSecureElementChangeListener() {
+PlatformResult NFCAdapter::AddActiveSecureElementChangeListener() {
   if (!m_is_listener_set) {
     int ret = nfc_manager_set_se_event_cb(se_event_callback, NULL);
     if (NFC_ERROR_NONE != ret) {
       LOGE("AddActiveSecureElementChangeListener failed: %d", ret);
-      NFCUtil::throwNFCException(ret,
+      return NFCUtil::CodeToResult(ret,
                                  NFCUtil::getNFCErrorMessage(ret).c_str());
     }
   }
 
   m_is_listener_set = true;
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-void NFCAdapter::RemoveActiveSecureElementChangeListener() {
+PlatformResult NFCAdapter::RemoveActiveSecureElementChangeListener() {
   if (!nfc_manager_is_supported()) {
-    throw NotSupportedException("NFC Not Supported");
+    LOGE("NFC Not Supported");
+    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "NFC Not Supported");
   }
 
   if (m_is_listener_set) {
     nfc_manager_unset_se_event_cb();
   }
   m_is_listener_set = false;
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 void NFCAdapter::SetPeerHandle(nfc_p2p_target_h handle) {
@@ -553,9 +590,9 @@ void NFCAdapter::IncreasePeerId() {
   m_latest_peer_id++;
 }
 
-PlatformResult NFCAdapter::PeerIsConnectedGetter(int peer_id, bool &state) {
+PlatformResult NFCAdapter::PeerIsConnectedGetter(int peer_id, bool *state) {
   if (m_latest_peer_id != peer_id || !m_peer_handle) {
-    state = false;
+    *state = false;
     return PlatformResult(ErrorCode::NO_ERROR);
   }
 
@@ -567,7 +604,7 @@ PlatformResult NFCAdapter::PeerIsConnectedGetter(int peer_id, bool &state) {
     return NFCUtil::CodeToResult(ret, "Failed to get connected target.");
   }
 
-  state = (m_peer_handle == handle);
+  *state = (m_peer_handle == handle);
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
@@ -637,7 +674,7 @@ PlatformResult NFCAdapter::SetReceiveNDEFListener(int peer_id) {
 
   //check if peer object is still connected
   bool is_connected = false;
-  PlatformResult result = PeerIsConnectedGetter(peer_id, is_connected);
+  PlatformResult result = PeerIsConnectedGetter(peer_id, &is_connected);
   if (result.IsError()) {
     return result;
   }
@@ -662,7 +699,7 @@ PlatformResult NFCAdapter::UnsetReceiveNDEFListener(int peer_id) {
     //check if peer object is still connected
 
     bool is_connected = false;
-    PlatformResult result = PeerIsConnectedGetter(peer_id, is_connected);
+    PlatformResult result = PeerIsConnectedGetter(peer_id, &is_connected);
     if (result.IsError()) {
       return result;
     }
@@ -1179,7 +1216,7 @@ static gboolean sendNDEFErrorCB(void * user_data) {
 PlatformResult NFCAdapter::sendNDEF(int peer_id, const picojson::value& args) {
 
   bool is_connected = false;
-  PlatformResult result = PeerIsConnectedGetter(peer_id, is_connected);
+  PlatformResult result = PeerIsConnectedGetter(peer_id, &is_connected);
   if (result.IsError()) {
     return result;
   }
index c526136d1bad7d3232e3ac835e27da646f7d6094..5c2fb117dce07b4d2a848ff36769ae3c476f15fe 100644 (file)
@@ -31,28 +31,28 @@ class NFCAdapter {
   common::PlatformResult SetPowered(const picojson::value& args);
 
   // cardEmulationMode getter and setter
-  std::string GetCardEmulationMode();
-  void SetCardEmulationMode(std::string mode);
+  common::PlatformResult GetCardEmulationMode(std::string *mode);
+  common::PlatformResult SetCardEmulationMode(std::string mode);
   // activeSecureElement getter and setter
-  std::string GetActiveSecureElement();
-  void SetActiveSecureElement(std::string element);
+  common::PlatformResult GetActiveSecureElement(std::string *type);
+  common::PlatformResult SetActiveSecureElement(std::string element);
 
   // Adapter methods
-  void SetExclusiveModeForTransaction(bool exmode);
-
-  void AddCardEmulationModeChangeListener();
-  void RemoveCardEmulationModeChangeListener();
-  void AddTransactionEventListener(const picojson::value& args);
-  void RemoveTransactionEventListener(const picojson::value& args);
-  void AddActiveSecureElementChangeListener();
-  void RemoveActiveSecureElementChangeListener();
+  common::PlatformResult  SetExclusiveModeForTransaction(bool exmode);
+
+  common::PlatformResult AddCardEmulationModeChangeListener();
+  common::PlatformResult RemoveCardEmulationModeChangeListener();
+  common::PlatformResult AddTransactionEventListener(const picojson::value& args);
+  common::PlatformResult RemoveTransactionEventListener(const picojson::value& args);
+  common::PlatformResult AddActiveSecureElementChangeListener();
+  common::PlatformResult RemoveActiveSecureElementChangeListener();
   void GetCachedMessage(picojson::object& out);
 
   void SetPeerHandle(nfc_p2p_target_h handle);
   nfc_p2p_target_h GetPeerHandle();
   int GetPeerId();
   void IncreasePeerId();
-  common::PlatformResult PeerIsConnectedGetter(int peer_id, bool &state);
+  common::PlatformResult PeerIsConnectedGetter(int peer_id, bool *state);
   common::PlatformResult SetPeerListener();
   common::PlatformResult UnsetPeerListener();
   common::PlatformResult SetReceiveNDEFListener(int peer_id);
index d6e850074bae901bb3b9a7137cb0357b7bf336d4..e659def9b0223affaefd47156c4b502dd6d09211 100644 (file)
@@ -165,7 +165,7 @@ function NFCAdapter() {
         var result = native_.callSync('NFCAdapter_cardEmulationModeGetter');
 
         if (native_.isFailure(result)) {
-            throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+            throw native_.getErrorObject(result);
         }
 
         return native_.getResultObject(result);
@@ -183,7 +183,7 @@ function NFCAdapter() {
         );
 
         if(native_.isFailure(result)) {
-            throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+            throw native_.getErrorObject(result);
         }
         return;
     }
@@ -193,7 +193,7 @@ function NFCAdapter() {
         var result = native_.callSync('NFCAdapter_activeSecureElementGetter');
 
         if (native_.isFailure(result)) {
-            throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+            throw native_.getErrorObject(result);
         }
 
         return native_.getResultObject(result);
@@ -211,7 +211,7 @@ function NFCAdapter() {
         );
 
         if(native_.isFailure(result)) {
-            throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+            throw native_.getErrorObject(result);
         }
         return;
     }
@@ -309,7 +309,7 @@ NFCAdapter.prototype.setTagListener  = function() {
     if(!native_.isListenerSet(TAG_LISTENER)) {
         var result = native_.callSync('NFCAdapter_setTagListener');
         if (native_.isFailure(result)) {
-            throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+            throw native_.getErrorObject(result);
         }
     }
 
@@ -337,7 +337,7 @@ NFCAdapter.prototype.setPeerListener = function() {
     if (!native_.isListenerSet(PEER_LISTENER)) {
         var result = native_.callSync('NFCAdapter_setPeerListener');
         if (native_.isFailure(result)) {
-            throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+            throw native_.getErrorObject(result);
         }
     }
 
@@ -351,7 +351,7 @@ NFCAdapter.prototype.unsetTagListener = function() {
 
     var result = native_.callSync('NFCAdapter_unsetTagListener');
     if (native_.isFailure(result)) {
-        throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+        throw native_.getErrorObject(result);
     }
 
     return;
@@ -362,7 +362,7 @@ NFCAdapter.prototype.unsetPeerListener = function() {
 
     var result = native_.callSync('NFCAdapter_unsetPeerListener');
     if (native_.isFailure(result)) {
-        throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+        throw native_.getErrorObject(result);
     }
 
     return;
@@ -512,7 +512,7 @@ NFCAdapter.prototype.getCachedMessage = function() {
     var result = native_.callSync('NFCAdapter_getCachedMessage');
 
     if (native_.isFailure(result)) {
-        throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+        throw native_.getErrorObject(result);
     }
 
     if (!result.records) {
@@ -537,8 +537,7 @@ NFCAdapter.prototype.setExclusiveModeForTransaction = function() {
     );
 
     if(native_.isFailure(result)) {
-        throw new tizen.WebAPIException(0, result.error.message, result.error.name);
-        // throw native_.getErrorObject(result);
+         throw native_.getErrorObject(result);
     }
     return;
 };
@@ -824,7 +823,7 @@ NFCPeer.prototype.setReceiveNDEFListener = function() {
 
     var result = native_.callSync('NFCPeer_setReceiveNDEFListener', {'id' : this._my_id});
     if (native_.isFailure(result)) {
-        throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+        throw native_.getErrorObject(result);
     }
 
     native_.addListener(RECEIVE_NDEF_LISTENER, listener);
@@ -836,7 +835,7 @@ NFCPeer.prototype.unsetReceiveNDEFListener = function() {
 
     var result = native_.callSync('NFCPeer_unsetReceiveNDEFListener', {'id' : this._my_id});
     if (native_.isFailure(result)) {
-        throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+        throw native_.getErrorObject(result);
     }
 
     return;
index 4876f026e694cc838cca2d832f193c5f2b158458..f42591445b42b79e46e46299b6e5f90c473e51d5 100644 (file)
@@ -123,6 +123,7 @@ void NFCInstance::GetDefaultAdapter(
 void NFCInstance::SetExclusiveMode(
     const picojson::value& args, picojson::object& out) {
 
+  CHECK_EXIST(args, "exclusiveMode", out);
   bool exmode = args.get("exclusiveMode").get<bool>();
   int ret = NFC_ERROR_NONE;
 
@@ -155,52 +156,49 @@ void NFCInstance::GetPowered(
 void NFCInstance::CardEmulationModeSetter(
     const picojson::value& args, picojson::object& out) {
 
+  CHECK_EXIST(args, "emulationMode", out);
   std::string mode = args.get("emulationMode").get<std::string>();
-  try {
-    NFCAdapter::GetInstance()->SetCardEmulationMode(mode);
+  PlatformResult result = NFCAdapter::GetInstance()->SetCardEmulationMode(mode);
+  if (result.IsSuccess()) {
     ReportSuccess(out);
-  }
-  catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
 void NFCInstance::CardEmulationModeGetter(
     const picojson::value& args, picojson::object& out) {
 
-  std::string mode;
-  try {
-    mode = NFCAdapter::GetInstance()->GetCardEmulationMode();
+  std::string mode = "";
+  PlatformResult result = NFCAdapter::GetInstance()->GetCardEmulationMode(&mode);
+  if (result.IsSuccess()) {
     ReportSuccess(picojson::value(mode), out);
-  }
-  catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
 void NFCInstance::ActiveSecureElementSetter(
     const picojson::value& args, picojson::object& out) {
-
+  CHECK_EXIST(args, "secureElement", out);
   std::string ase = args.get("secureElement").get<std::string>();
-  try {
-    NFCAdapter::GetInstance()->SetActiveSecureElement(ase);
+  PlatformResult result = NFCAdapter::GetInstance()->SetActiveSecureElement(ase);
+  if (result.IsSuccess()) {
     ReportSuccess(out);
-  }
-  catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
 void NFCInstance::ActiveSecureElementGetter(
     const picojson::value& args, picojson::object& out) {
 
-  std::string ase;
-  try {
-    ase = NFCAdapter::GetInstance()->GetActiveSecureElement();
+  std::string ase = "";
+  PlatformResult result = NFCAdapter::GetInstance()->GetActiveSecureElement(&ase);
+  if (result.IsSuccess()) {
     ReportSuccess(picojson::value(ase), out);
-  }
-  catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
@@ -222,7 +220,7 @@ void NFCInstance::PeerIsConnectedGetter(
 
   int peer_id = (int)args.get("id").get<double>();
   bool ret = false;
-  PlatformResult result = NFCAdapter::GetInstance()->PeerIsConnectedGetter(peer_id, ret);
+  PlatformResult result = NFCAdapter::GetInstance()->PeerIsConnectedGetter(peer_id, &ret);
 
   if (result.IsSuccess()) {
     ReportSuccess(picojson::value(ret), out);
@@ -253,58 +251,73 @@ void NFCInstance::UnsetTagListener(
 void NFCInstance::UnsetPeerListener(
     const picojson::value& args, picojson::object& out) {
 
-  try {
-    NFCAdapter::GetInstance()->UnsetPeerListener();
+  PlatformResult result = NFCAdapter::GetInstance()->UnsetPeerListener();
+  if (result.IsSuccess()) {
     ReportSuccess(out);
-  }
-  catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
 void NFCInstance::AddCardEmulationModeChangeListener(
     const picojson::value& args, picojson::object& out) {
-  try {
-    NFCAdapter::GetInstance()->AddCardEmulationModeChangeListener();
+
+  PlatformResult result = NFCAdapter::GetInstance()->AddCardEmulationModeChangeListener();
+  if (result.IsSuccess()) {
     ReportSuccess(out);
-  } catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
 void NFCInstance::RemoveCardEmulationModeChangeListener(
     const picojson::value& args, picojson::object& out) {
-  NFCAdapter::GetInstance()->RemoveCardEmulationModeChangeListener();
+  PlatformResult result = NFCAdapter::GetInstance()->RemoveCardEmulationModeChangeListener();
+  if (result.IsSuccess()) {
+    ReportSuccess(out);
+  } else {
+    ReportError(result, &out);
+  }
 }
 
 void NFCInstance::AddTransactionEventListener(
     const picojson::value& args, picojson::object& out) {
-  try {
-    NFCAdapter::GetInstance()->AddTransactionEventListener(args);
+  PlatformResult result = NFCAdapter::GetInstance()->AddTransactionEventListener(args);
+  if (result.IsSuccess()) {
     ReportSuccess(out);
-  } catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
 void NFCInstance::RemoveTransactionEventListener(
     const picojson::value& args, picojson::object& out) {
-  NFCAdapter::GetInstance()->RemoveTransactionEventListener(args);
+  PlatformResult result = NFCAdapter::GetInstance()->RemoveTransactionEventListener(args);
+  if (result.IsSuccess()) {
+    ReportSuccess(out);
+  } else {
+    ReportError(result, &out);
+  }
 }
 
 void NFCInstance::AddActiveSecureElementChangeListener(
     const picojson::value& args, picojson::object& out) {
-  try {
-    NFCAdapter::GetInstance()->AddActiveSecureElementChangeListener();
+  PlatformResult result = NFCAdapter::GetInstance()->AddActiveSecureElementChangeListener();
+  if (result.IsSuccess()) {
     ReportSuccess(out);
-  } catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
 void NFCInstance::RemoveActiveSecureElementChangeListener(
     const picojson::value& args, picojson::object& out) {
-  NFCAdapter::GetInstance()->RemoveActiveSecureElementChangeListener();
+  PlatformResult result = NFCAdapter::GetInstance()->RemoveActiveSecureElementChangeListener();
+  if (result.IsSuccess()) {
+    ReportSuccess(out);
+  } else {
+    ReportError(result, &out);
+  }
 }
 
 void NFCInstance::GetCachedMessage(
@@ -325,16 +338,15 @@ void NFCInstance::GetCachedMessage(
 void NFCInstance::SetExclusiveModeForTransaction(
     const picojson::value& args, picojson::object& out) {
 
-  bool transaction_mode = args.get("transactionMode").get<bool>();
-  int ret = NFC_ERROR_NONE;
+  CHECK_EXIST(args, "transactionMode", out);
 
-  try {
-    NFCAdapter::GetInstance()->SetExclusiveModeForTransaction(
+  bool transaction_mode = args.get("transactionMode").get<bool>();
+  PlatformResult result = NFCAdapter::GetInstance()->SetExclusiveModeForTransaction(
         transaction_mode);
+  if (result.IsSuccess()) {
     ReportSuccess(out);
-  }
-  catch(const common::PlatformException& ex) {
-    ReportError(ex, out);
+  } else {
+    ReportError(result, &out);
   }
 }
 
index 9e4a5cad2a126beccbe10e0a2dff8c0cdb016c1c..0ce73bd0ea0a7639f446c6c2ffcd3c26ddc32cbb 100644 (file)
@@ -234,19 +234,22 @@ nfc_tag_type_e NFCUtil::toNfcTagString(const std::string& type_string)
   }
 }
 
-std::string NFCUtil::toStringCardEmulationMode(
-    const nfc_se_card_emulation_mode_type_e mode)
+PlatformResult NFCUtil::ToStringCardEmulationMode(
+    const nfc_se_card_emulation_mode_type_e card_mode, std::string *mode)
 {
-  switch (mode)
+  switch (card_mode)
   {
     case NFC_SE_CARD_EMULATION_MODE_OFF:
-      return OFF;
+      *mode = OFF;
+      break;
     case NFC_SE_CARD_EMULATION_MODE_ON:
-      return ALWAYS_ON;
+      *mode = ALWAYS_ON;
+      break;
     default:
-      LOGE("No Match Card Emulation mode: %x", mode);
-      throw TypeMismatchException("No Match Card Emulation mode");
+      LOGE("No Match Card Emulation mode: %x", card_mode);
+      return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "No Match Card Emulation mode");
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 nfc_se_card_emulation_mode_type_e NFCUtil::toCardEmulationMode(
@@ -262,29 +265,33 @@ nfc_se_card_emulation_mode_type_e NFCUtil::toCardEmulationMode(
   }
 }
 
-std::string NFCUtil::toStringSecureElementType(const nfc_se_type_e type)
+PlatformResult NFCUtil::ToStringSecureElementType(const nfc_se_type_e se_type, std::string *type)
 {
-  switch (type) {
+  switch (se_type) {
     case NFC_SE_TYPE_ESE:
-      return ESE;
+      *type = ESE;
+      break;
     case NFC_SE_TYPE_UICC:
-      return UICC;
+      *type = UICC;
+      break;
     default:
-      LOGE("No Match Secure Element Type: %x", type);
-      throw TypeMismatchException("No Match Secure Element Type");
+      LOGE("No Match Secure Element Type: %x", se_type);
+      return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "No Match Secure Element Type");
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-nfc_se_type_e NFCUtil::toSecureElementType(const std::string &type_string)
+PlatformResult NFCUtil::ToSecureElementType(const std::string &type_string, nfc_se_type_e *type)
 {
   if (type_string == ESE) {
-    return NFC_SE_TYPE_ESE;
+    *type = NFC_SE_TYPE_ESE;
   } else if (type_string == UICC) {
-    return NFC_SE_TYPE_UICC;
+    *type = NFC_SE_TYPE_UICC;
   } else {
-    LOGE("No Match Secure Element Type: %s", type_string.c_str());
-    throw TypeMismatchException("No Match Secure Element Type");
+    LoggerE("No Match Secure Element Type: %s", type_string.c_str());
+    return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "No Match Secure Element Type");
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 void NFCUtil::setDefaultFilterValues(std::vector<nfc_tag_type_e>& filter)
index 06d6d4e961d346ac7d06b8a8e379655d94af8aa1..590c58f131ba0620c29560404cfe7dc41494d1dd 100644 (file)
@@ -59,12 +59,12 @@ class NFCUtil
   static std::string getNFCErrorMessage(const int error_code);
   static std::string toStringNFCTag(const nfc_tag_type_e tag_type);
   static nfc_tag_type_e toNfcTagString(const std::string& type_string);
-  static std::string toStringCardEmulationMode(
-      const nfc_se_card_emulation_mode_type_e mode);
+  static common::PlatformResult ToStringCardEmulationMode(
+      const nfc_se_card_emulation_mode_type_e card_mode, std::string *mode);
   static nfc_se_card_emulation_mode_type_e toCardEmulationMode(
       const std::string& mode_string);
-  static std::string toStringSecureElementType(const nfc_se_type_e type);
-  static nfc_se_type_e toSecureElementType(const std::string& type_string);
+  static common::PlatformResult ToStringSecureElementType(const nfc_se_type_e se_type, std::string *type);
+  static common::PlatformResult ToSecureElementType(const std::string& type_string, nfc_se_type_e *type);
   static void setDefaultFilterValues(std::vector<nfc_tag_type_e>& filter);
 };