From: Lukasz Bardeli Date: Mon, 15 Dec 2014 13:54:11 +0000 (+0100) Subject: [NFC] Initial commit to NFC module X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~821 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b385fa7d8748a637eb91d3b26f412fc8ea687ac;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [NFC] Initial commit to NFC module [Verification] Code compiles without errors. Change-Id: I1cfbe765d7e544b0b26cc43e325a4d050fdb2243 Signed-off-by: Lukasz Bardeli --- diff --git a/src/nfc/nfc.gyp b/src/nfc/nfc.gyp new file mode 100644 index 00000000..ec59f33d --- /dev/null +++ b/src/nfc/nfc.gyp @@ -0,0 +1,30 @@ +{ + 'includes':[ + '../common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_nfc', + 'type': 'loadable_module', + 'sources': [ + 'nfc_api.js', + 'nfc_extension.cc', + 'nfc_extension.h', + 'nfc_instance.cc', + 'nfc_instance.h' + ], + 'includes': [ + '../common/pkg-config.gypi', + ], + 'conditions': [ + ['tizen == 1', { + 'variables': { + 'packages': [ + + ] + }, + }], + ], + }, + ], +} \ No newline at end of file diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js new file mode 100644 index 00000000..8bca6c95 --- /dev/null +++ b/src/nfc/nfc_api.js @@ -0,0 +1,223 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var validator_ = xwalk.utils.validator; +var types_ = validator_.Types; +var native_ = new xwalk.utils.NativeManager(extension); + +//enumeration NDEFRecordTextEncoding //////////////////////////////////////////////////// +var NDEFRecordTextEncoding = { + UTF8 : 'UTF8', + UTF16 : 'UTF16' +}; + +//enumeration NFCTagType //////////////////////////////////////////////////// +var NFCTagType = { + GENERIC_TARGET : 'GENERIC_TARGET', + ISO14443_A : 'ISO14443_A', + ISO14443_4A : 'ISO14443_4A', + ISO14443_3A : 'ISO14443_3A', + MIFARE_MINI : 'MIFARE_MINI', + MIFARE_1K : 'MIFARE_1K', + MIFARE_4K : 'MIFARE_4K', + MIFARE_ULTRA : 'MIFARE_ULTRA', + MIFARE_DESFIRE : 'MIFARE_DESFIRE', + ISO14443_B : 'ISO14443_B', + ISO14443_4B : 'ISO14443_4B', + ISO14443_BPRIME : 'ISO14443_BPRIME', + FELICA : 'FELICA', + JEWEL : 'JEWEL', + ISO15693 : 'ISO15693', + UNKNOWN_TARGET : 'UNKNOWN_TARGET' +}; + +////enumeration CardEmulationMode //////////////////////////////////////////////////// +var CardEmulationMode = { + ALWAYS_ON : 'ALWAYS_ON', + OFF : 'OFF' +}; + +////enumeration SecureElementType //////////////////////////////////////////////////// +var SecureElementType = { + ESE : 'ESE', + UICC : 'UICC' +}; + +//////////////////NFCManager ///////////////// + +function NFCManager() { + Object.defineProperties(this, { + NFC_RECORD_TNF_EMPTY: {value: 0, writable: false, enumerable: true}, + NFC_RECORD_TNF_WELL_KNOWN: {value: 1, writable: false, enumerable: true}, + NFC_RECORD_TNF_MIME_MEDIA: {value: 2, writable: false, enumerable: true}, + NFC_RECORD_TNF_URI: {value: 3, writable: false, enumerable: true}, + NFC_RECORD_TNF_EXTERNAL_RTD: {value: 4, writable: false, enumerable: true}, + NFC_RECORD_TNF_UNKNOWN: {value: 5, writable: false, enumerable: true}, + NFC_RECORD_TNF_UNCHANGED: {value: 6, writable: false, enumerable: true} + }); +} + +NFCManager.prototype.getDefaultAdapter = function() { + return new NFCAdapter(); +}; + +NFCManager.prototype.setExclusiveMode = function() { + +}; + +//////////////////NFCAdapter ///////////////// + +function NFCAdapter() { + Object.defineProperties(this, { + powered: {enumerable: true, + set : function(){}, + get : function(){}}, + cardEmulationMode: {enumerable: true, + set : function(){}, + get : function(){}}, + activeSecureElement: {enumerable: true, + set : function(){}, + get : function(){}} + }); +}; + +NFCAdapter.prototype.setPowered = function() { + +}; + +NFCAdapter.prototype.setTagListener = function() { + +}; + +NFCAdapter.prototype.setPeerListener = function() { + +}; + +NFCAdapter.prototype.unsetTagListener = function() { + +}; + +NFCAdapter.prototype.unsetPeerListener = function() { + +}; + +NFCAdapter.prototype.addCardEmulationModeChangeListener = function() { + +}; + +NFCAdapter.prototype.removeCardEmulationModeChangeListener = function() { + +}; + +NFCAdapter.prototype.addTransactionEventListener = function() { + +}; + +NFCAdapter.prototype.removeTransactionEventListener = function() { + +}; + +NFCAdapter.prototype.addActiveSecureElementChangeListener = function() { + +}; + +NFCAdapter.prototype.removeActiveSecureElementChangeListener = function() { + +}; + +NFCAdapter.prototype.getCachedMessage = function() { + +}; + +NFCAdapter.prototype.setExclusiveModeForTransaction = function() { + +}; + +//////////////////NFCTag ///////////////// + +function NFCTag(data) { + Object.defineProperties(this, { + type: {value: data.type, writable: false, enumerable: true}, + isSupportedNDEF: {value: data.isSupportedNDEF, + writable: true, enumerable: true}, + ndefSize: {value: data.ndefSize, + writable: true, enumerable: true}, + properties: {value: data.properties, writable: true, enumerable: true}, + isConnected: {value: data.isConnected, + writable: true, enumerable: true} + }); +} + +NFCTag.prototype.readNDEF = function() { + +}; + +NFCTag.prototype.writeNDEF = function() { + +}; + +NFCTag.prototype.transceive = function() { + +}; + +//////////////////NFCPeer ///////////////// + +function NFCPeer(data) { + Object.defineProperties(this, { + isConnected: {value: data.isConnected, + writable: true, enumerable: true} + }); +} + +NFCPeer.prototype.setReceiveNDEFListener = function() { + +}; + +NFCPeer.prototype.unsetReceiveNDEFListener = function() { + +}; + +NFCPeer.prototype.sendNDEF = function() { + +}; + +//////////////////NDEFMessage ///////////////// + +tizen.NDEFMessage = function(data) { + +}; + +tizen.NDEFMessage.prototype.toByte = function() { + +}; + +//////////////////NDEFRecord ///////////////// + +tizen.NDEFRecord = function(data, type, payload, id) { + +}; + +//////////////////NDEFRecordText ///////////////// + +tizen.NDEFRecordText = function(text, languageCode, encoding) { + +}; + +//////////////////NDEFRecordURI ///////////////// + +tizen.NDEFRecordURI = function(uri) { + +}; + +//////////////////NDEFRecordMedia ///////////////// + +tizen.NDEFRecordMedia = function(mimeType, data) { + +}; + +//Exports +var NFCManagerObject = new NFCManager(); + +exports.getDefaultAdapter = NFCManagerObject.getDefaultAdapter; +exports.setExclusiveMode = NFCManagerObject.setExclusiveMode; diff --git a/src/nfc/nfc_extension.cc b/src/nfc/nfc_extension.cc new file mode 100644 index 00000000..6f7ee3f9 --- /dev/null +++ b/src/nfc/nfc_extension.cc @@ -0,0 +1,25 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "nfc/nfc_extension.h" + +#include "nfc/nfc_instance.h" + +// This will be generated from messageport_api.js. +extern const char kSource_nfc_api[]; + +common::Extension* CreateExtension() { + return new NFCExtension; +} + +NFCExtension::NFCExtension() { + SetExtensionName("tizen.nfc"); + SetJavaScriptAPI(kSource_nfc_api); +} + +NFCExtension::~NFCExtension() {} + +common::Instance* NFCExtension::CreateInstance() { + return new extension::nfc::NFCInstance; +} diff --git a/src/nfc/nfc_extension.h b/src/nfc/nfc_extension.h new file mode 100644 index 00000000..12e954bc --- /dev/null +++ b/src/nfc/nfc_extension.h @@ -0,0 +1,19 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NFC_NFC_EXTENSION_H_ +#define NFC_NFC_EXTENSION_H_ + +#include "common/extension.h" + +class NFCExtension : public common::Extension { +public: + NFCExtension(); + virtual ~NFCExtension(); +private: + // common::Extension implementation. + virtual common::Instance* CreateInstance(); +}; + +#endif // NFC_NFC_EXTENSION_H_ diff --git a/src/nfc/nfc_instance.cc b/src/nfc/nfc_instance.cc new file mode 100644 index 00000000..1c0c63ad --- /dev/null +++ b/src/nfc/nfc_instance.cc @@ -0,0 +1,164 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "nfc/nfc_instance.h" + +#include "common/picojson.h" +#include "common/logger.h" +#include "common/platform_exception.h" + + +namespace extension { +namespace nfc { + +using namespace common; + +NFCInstance::NFCInstance() { + using namespace std::placeholders; +#define REGISTER_SYNC(c,x) \ + RegisterSyncHandler(c, std::bind(&NFCInstance::x, this, _1, _2)); + REGISTER_SYNC("NFCManager_getDefaultAdapter", GetDefaultAdapter); + REGISTER_SYNC("NFCManager_setExclusiveMode", SetExclusiveMode); + REGISTER_SYNC("NFCAdapter_setPeerListener", SetPeerListener); + REGISTER_SYNC("NFCAdapter_setTagListener", SetTagListener); + REGISTER_SYNC("NFCAdapter_setPeerListener", SetPeerListener); + REGISTER_SYNC("NFCAdapter_unsetTagListener", UnsetTagListener); + REGISTER_SYNC("NFCAdapter_unsetPeerListener", UnsetPeerListener); + REGISTER_SYNC("NFCAdapter_addCardEmulationModeChangeListener", + AddCardEmulationModeChangeListener); + REGISTER_SYNC("NFCAdapter_removeCardEmulationModeChangeListener", + RemoveCardEmulationModeChangeListener); + REGISTER_SYNC("NFCAdapter_addTransactionEventListener", + AddTransactionEventListener); + REGISTER_SYNC("NFCAdapter_addActiveSecureElementChangeListener", + AddActiveSecureElementChangeListener); + REGISTER_SYNC("NFCAdapter_removeActiveSecureElementChangeListener", + RemoveActiveSecureElementChangeListener); + REGISTER_SYNC("NFCAdapter_getCachedMessage", GetCachedMessage); + REGISTER_SYNC("NFCAdapter_setExclusiveModeForTransaction", + SetExclusiveModeForTransaction); + REGISTER_SYNC("NFCPeer_unsetReceiveNDEFListener", UnsetReceiveNDEFListener); + REGISTER_SYNC("NDEFMessage_toByte", ToByte); +#undef REGISTER_SYNC +#define REGISTER(c,x) \ + RegisterHandler(c, std::bind(&NFCInstance::x, this, _1, _2)); + REGISTER("NFCAdapter_setPowered", SetPowered); + REGISTER("NFCTag_readNDEF", ReadNDEF); + REGISTER("NFCTag_writeNDEF", WriteNDEF); + REGISTER("NFCTag_transceive ", Transceive ); + REGISTER("NFCPeer_setReceiveNDEFListener", SetReceiveNDEFListener); + REGISTER("NFCPeer_sendNDEF", SendNDEF); +#undef REGISTER +} + +NFCInstance::~NFCInstance() { +} + +void NFCInstance::GetDefaultAdapter( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::SetExclusiveMode( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::SetPowered( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::SetTagListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::SetPeerListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::UnsetTagListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::UnsetPeerListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::AddCardEmulationModeChangeListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::RemoveCardEmulationModeChangeListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::AddTransactionEventListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::AddActiveSecureElementChangeListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::RemoveActiveSecureElementChangeListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::GetCachedMessage( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::SetExclusiveModeForTransaction( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::ReadNDEF( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::WriteNDEF( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::Transceive( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::SetReceiveNDEFListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::UnsetReceiveNDEFListener( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::SendNDEF( + const picojson::value& args, picojson::object& out) { + +} + +void NFCInstance::ToByte( + const picojson::value& args, picojson::object& out) { + +} + +} // namespace nfc +} // namespace extension diff --git a/src/nfc/nfc_instance.h b/src/nfc/nfc_instance.h new file mode 100644 index 00000000..88918f42 --- /dev/null +++ b/src/nfc/nfc_instance.h @@ -0,0 +1,49 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NFC_NFC_INSTANCE_H_ +#define NFC_NFC_INSTANCE_H_ + +#include "common/extension.h" + +#include "nfc/nfc_extension.h" + +namespace extension { +namespace nfc { + +class NFCInstance: public common::ParsedInstance { +public: + NFCInstance(); + virtual ~NFCInstance(); + +private: + void GetDefaultAdapter(const picojson::value& args, picojson::object& out); + void SetExclusiveMode(const picojson::value& args, picojson::object& out); + void SetPowered(const picojson::value& args, picojson::object& out); + void SetTagListener(const picojson::value& args, picojson::object& out); + void SetPeerListener(const picojson::value& args, picojson::object& out); + void UnsetTagListener(const picojson::value& args, picojson::object& out); + void UnsetPeerListener(const picojson::value& args, picojson::object& out); + void AddCardEmulationModeChangeListener(const picojson::value& args, picojson::object& out); + void RemoveCardEmulationModeChangeListener(const picojson::value& args, picojson::object& out); + void AddTransactionEventListener(const picojson::value& args, picojson::object& out); + void RemoveTransactionEventListener(const picojson::value& args, picojson::object& out); + void AddActiveSecureElementChangeListener(const picojson::value& args, picojson::object& out); + void RemoveActiveSecureElementChangeListener(const picojson::value& args, picojson::object& out); + void GetCachedMessage(const picojson::value& args, picojson::object& out); + void SetExclusiveModeForTransaction(const picojson::value& args, picojson::object& out); + void ReadNDEF(const picojson::value& args, picojson::object& out); + void WriteNDEF(const picojson::value& args, picojson::object& out); + void Transceive(const picojson::value& args, picojson::object& out); + void SetReceiveNDEFListener(const picojson::value& args, picojson::object& out); + void UnsetReceiveNDEFListener(const picojson::value& args, picojson::object& out); + void SendNDEF(const picojson::value& args, picojson::object& out); + void ToByte(const picojson::value& args, picojson::object& out); + +}; + +} // namespace nfc +} // namespace extension + +#endif // NFC_NFC_INSTANCE_H_ diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index 7cd3c980..5775ba1c 100644 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -24,6 +24,7 @@ 'calendar/calendar.gyp:*', 'datasync/datasync.gyp:*', 'messaging/messaging.gyp:*', + 'nfc/nfc.gyp:*' ], }, ],