From: Marcin Kaminski Date: Thu, 18 Dec 2014 16:52:35 +0000 (+0100) Subject: [NFC] NFCManager::getDefaultAdapter() improved X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~774^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c749072b0ea45ed5fb81ec66ffe042fffb8120b0;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [NFC] NFCManager::getDefaultAdapter() improved NFC support and exception throwing at the beginning of getDefaultAdapter() function added. Change-Id: I5e881cbd964724d3deca115b9be6e8f0b0c2bc21 Signed-off-by: Marcin Kaminski --- diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js index 2457139a..3df9efde 100644 --- a/src/nfc/nfc_api.js +++ b/src/nfc/nfc_api.js @@ -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: // diff --git a/src/nfc/nfc_instance.cc b/src/nfc/nfc_instance.cc index 170b906d..13eb6978 100644 --- a/src/nfc/nfc_instance.cc +++ b/src/nfc/nfc_instance.cc @@ -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(