[NFC] NFCManager::setExclusiveMode added
authorMarcin Kaminski <marcin.ka@samsung.com>
Mon, 15 Dec 2014 18:25:44 +0000 (19:25 +0100)
committerMarcin Kaminski <marcin.ka@samsung.com>
Wed, 17 Dec 2014 08:01:58 +0000 (09:01 +0100)
Modified API export directives.

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

index e71284e038d725db2d5b2a4e93701d7664ef47d1..0647b413ad79815d89d1d8d77aef9ab3461f38cc 100644 (file)
@@ -64,6 +64,25 @@ NFCManager.prototype.getDefaultAdapter = function() {
 
 NFCManager.prototype.setExclusiveMode = function() {
 
+    var args = validator_.validateArgs(arguments, [
+        {name: 'exclusiveMode', type: types_.BOOLEAN}
+    ]);
+
+    var result = native_.callSync(
+        'NFCManager_setExclusiveMode',
+        { 'exclusiveMode': args.exclusiveMode}
+    );
+
+    // If failed then exception should be thrown.
+    if(native_.isFailure(result)) {
+        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:
+        //
+        //throw native_.getErrorObject(result);
+    }
+    // Otherwise just return
+    return;
 };
 
 //////////////////NFCAdapter /////////////////
@@ -230,7 +249,4 @@ tizen.NDEFRecordMedia = function(mimeType, data) {
 };
 
 //Exports
-var NFCManagerObject = new NFCManager();
-
-exports.getDefaultAdapter = NFCManagerObject.getDefaultAdapter;
-exports.setExclusiveMode = NFCManagerObject.setExclusiveMode;
+exports = new NFCManager();
index 6c3208690d4997c9105a98b53f18fdc3df1bdee5..b0edb6eeb67d873c3569ddb3603f4b4de22264b0 100644 (file)
@@ -8,11 +8,15 @@
 #include "common/logger.h"
 #include "common/platform_exception.h"
 
+// platform header
+#include <nfc.h>
+
 
 namespace extension {
 namespace nfc {
 
 using namespace common;
+using namespace extension::nfc;
 
 NFCInstance::NFCInstance() {
     using namespace std::placeholders;
@@ -51,9 +55,18 @@ NFCInstance::NFCInstance() {
     REGISTER("NFCPeer_setReceiveNDEFListener", SetReceiveNDEFListener);
     REGISTER("NFCPeer_sendNDEF", SendNDEF);
 #undef REGISTER
+    // NFC library initialization
+    int result = nfc_manager_initialize();
+    if (NFC_ERROR_NONE != result) {
+        LoggerE("Could not initialize NFC Manager.");
+    }
 }
 
 NFCInstance::~NFCInstance() {
+    int result = nfc_manager_deinitialize();
+    if (NFC_ERROR_NONE != result) {
+        LoggerE("NFC Manager deinitialization failed.");
+    }
 }
 
 void NFCInstance::GetDefaultAdapter(
@@ -64,6 +77,42 @@ void NFCInstance::GetDefaultAdapter(
 void NFCInstance::SetExclusiveMode(
         const picojson::value& args, picojson::object& out) {
 
+    bool exmode = args.get("exclusiveMode").get<bool>();
+    int ret = NFC_ERROR_NONE;
+
+    if(exmode) {
+        ret = nfc_manager_enable_transaction_fg_dispatch();
+    }
+    else {
+        ret = nfc_manager_disable_transaction_fg_dispatch();
+    }
+
+    if (NFC_ERROR_NONE != ret) {
+        LoggerE("setExclusiveModeForTransaction failed: %d", ret);
+        switch(ret) {
+            case NFC_ERROR_SECURITY_RESTRICTED:
+            {
+                auto ex = common::SecurityException("Not allowed to set exclusive mode");
+                ReportError(ex, out);
+                break;
+            }
+            case NFC_ERROR_OPERATION_FAILED:
+            {
+                auto ex = common::UnknownException("Setting exclusive mode failed (IPC fail)");
+                ReportError(ex, out);
+                break;
+            }
+            default:
+            {
+                auto ex = common::UnknownException("Unkown error");
+                ReportError(ex, out);
+                break;
+            }
+        }
+    }
+    else {
+        ReportSuccess(out);
+    }
 }
 
 void NFCInstance::SetPowered(