[NFC] NFCManager::getDefaultAdapter() improved
authorMarcin Kaminski <marcin.ka@samsung.com>
Thu, 18 Dec 2014 16:52:35 +0000 (17:52 +0100)
committerMarcin Kaminski <marcin.ka@samsung.com>
Fri, 19 Dec 2014 10:19:58 +0000 (19:19 +0900)
NFC support and exception throwing at the beginning
of getDefaultAdapter() function added.

Change-Id: I5e881cbd964724d3deca115b9be6e8f0b0c2bc21
Signed-off-by: Marcin Kaminski <marcin.ka@samsung.com>
src/nfc/nfc_api.js
src/nfc/nfc_instance.cc

index 2457139a1bd938cabb03a5af021fd56acbd24fa7..3df9efdea7f7dafc8ad75d79587e24cc4af35954 100644 (file)
@@ -59,6 +59,17 @@ function NFCManager() {
 }
 
 NFCManager.prototype.getDefaultAdapter = function() {
+    // First check NFC suppor on C++ level
+    var result = native_.callSync(
+        'NFCManager_getDefaultAdapter',
+        {}
+    );
+    if(native_.isFailure(result)) {
+        throw new tizen.WebAPIException(0, result.error.message,
+                result.error.name);
+    }
+
+    // If NFC is supported then return new NFCAdapter instance
     return new NFCAdapter();
 };
 
@@ -75,7 +86,8 @@ NFCManager.prototype.setExclusiveMode = function() {
 
     // If failed then exception should be thrown.
     if(native_.isFailure(result)) {
-        throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+        throw new tizen.WebAPIException(0, result.error.message,
+                result.error.name);
         // Uncoment line below (and remove line above) when problem
         // with error conversion is fixed:
         //
index 170b906d6c0c21c734391c7a5af4bcd4ec395471..13eb6978f02b88983aab6cf5590e3da66836804f 100644 (file)
@@ -101,6 +101,19 @@ void NFCInstance::InstanceReportError(const PlatformException& ex, picojson::obj
 void NFCInstance::GetDefaultAdapter(
         const picojson::value& args, picojson::object& out) {
 
+    // Default NFC adapter is created at JS level
+    // Here there's only check for NFC support
+    LoggerD("Entered");
+    if(!nfc_manager_is_supported()) {
+        LoggerE("NFC manager is not supported");
+        // According to API reference only Security and Unknown
+        // exceptions are allowed here
+        auto ex = common::UnknownException("NFC manager not supported");
+        ReportError(ex, out);
+    }
+    else {
+        ReportSuccess(out);
+    }
 }
 
 void NFCInstance::SetExclusiveMode(