From: Marcin Kaminski Date: Mon, 15 Dec 2014 18:25:44 +0000 (+0100) Subject: [NFC] NFCManager::setExclusiveMode added X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~773^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0cdfbf63fb128a9fad530aa0d4e124fcf0873b98;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [NFC] NFCManager::setExclusiveMode added Modified API export directives. Change-Id: I1bded3c9bb3418230c89dd651a0de5ef59542370 Signed-off-by: Marcin Kaminski --- diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js index e71284e0..0647b413 100644 --- a/src/nfc/nfc_api.js +++ b/src/nfc/nfc_api.js @@ -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(); diff --git a/src/nfc/nfc_instance.cc b/src/nfc/nfc_instance.cc index 6c320869..b0edb6ee 100644 --- a/src/nfc/nfc_instance.cc +++ b/src/nfc/nfc_instance.cc @@ -8,11 +8,15 @@ #include "common/logger.h" #include "common/platform_exception.h" +// platform header +#include + 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(); + 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(