From 3bb8b99c95b4fe678ca5315ec1da9052770c9d59 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 01:50:53 +0900 Subject: [PATCH] Tizen 2.1 base --- CMakeLists.txt | 111 +++ LICENSE.APLv2.0 | 202 ++++ LICENSE.Flora | 206 +++++ NOTICE | 9 + inc/FNetNfc.h | 67 ++ inc/FNetNfcINdefMessageDiscoveryEventListener.h | 105 +++ inc/FNetNfcINdefPushManagerListener.h | 89 ++ inc/FNetNfcINdefTagConnectionListener.h | 127 +++ inc/FNetNfcINfcDeviceDiscoveryEventListener.h | 94 ++ inc/FNetNfcINfcManagerEventListener.h | 129 +++ inc/FNetNfcINfcTagDiscoveryEventListener.h | 112 +++ inc/FNetNfcITagConnectionListener.h | 111 +++ inc/FNetNfcNdefMessage.h | 298 ++++++ inc/FNetNfcNdefPushManager.h | 176 ++++ inc/FNetNfcNdefRecord.h | 216 +++++ inc/FNetNfcNdefRecordType.h | 260 ++++++ inc/FNetNfcNdefTagConnection.h | 242 +++++ inc/FNetNfcNfcManager.h | 477 ++++++++++ inc/FNetNfcNfcTag.h | 136 +++ inc/FNetNfcNfcTypes.h | 99 ++ inc/FNetNfcTagConnection.h | 284 ++++++ osp-nfc.manifest | 5 + osp-nfc.pc.in | 14 + packaging/osp-nfc.spec | 92 ++ src/FNetNfcNdefMessage.cpp | 160 ++++ src/FNetNfcNdefPushManager.cpp | 126 +++ src/FNetNfcNdefRecord.cpp | 124 +++ src/FNetNfcNdefRecordType.cpp | 99 ++ src/FNetNfcNdefTagConnection.cpp | 71 ++ src/FNetNfcNfcManager.cpp | 309 +++++++ src/FNetNfcNfcTag.cpp | 62 ++ src/FNetNfcTagConnection.cpp | 70 ++ src/FNetNfc_NdefMessageDiscoveryEvent.cpp | 152 +++ src/FNetNfc_NdefMessageDiscoveryEvent.h | 103 +++ src/FNetNfc_NdefMessageDiscoveryEventArg.cpp | 55 ++ src/FNetNfc_NdefMessageDiscoveryEventArg.h | 76 ++ src/FNetNfc_NdefMessageImpl.cpp | 362 ++++++++ src/FNetNfc_NdefMessageUtil.cpp | 805 ++++++++++++++++ src/FNetNfc_NdefPushManagerEvent.cpp | 66 ++ src/FNetNfc_NdefPushManagerEvent.h | 82 ++ src/FNetNfc_NdefPushManagerEventArg.cpp | 49 + src/FNetNfc_NdefPushManagerEventArg.h | 73 ++ src/FNetNfc_NdefPushManagerImpl.cpp | 167 ++++ src/FNetNfc_NdefRecordImpl.cpp | 277 ++++++ src/FNetNfc_NdefRecordTypeImpl.cpp | 274 ++++++ src/FNetNfc_NfcAuthorityController.cpp | 165 ++++ src/FNetNfc_NfcAuthorityController.h | 101 ++ src/FNetNfc_NfcDeviceDiscoveryEvent.cpp | 75 ++ src/FNetNfc_NfcDeviceDiscoveryEvent.h | 84 ++ src/FNetNfc_NfcDeviceDiscoveryEventArg.cpp | 52 ++ src/FNetNfc_NfcDeviceDiscoveryEventArg.h | 90 ++ src/FNetNfc_NfcIpcMessages.cpp | 44 + src/FNetNfc_NfcIpcProxy.cpp | 181 ++++ src/FNetNfc_NfcIpcProxy.h | 124 +++ src/FNetNfc_NfcManagerEvent.cpp | 77 ++ src/FNetNfc_NfcManagerEvent.h | 88 ++ src/FNetNfc_NfcManagerEventArg.cpp | 53 ++ src/FNetNfc_NfcManagerEventArg.h | 98 ++ src/FNetNfc_NfcManagerImpl.cpp | 1118 +++++++++++++++++++++++ src/FNetNfc_NfcSystemAdapter.cpp | 1002 ++++++++++++++++++++ src/FNetNfc_NfcSystemAdapter.h | 350 +++++++ src/FNetNfc_NfcTagDiscoveryEvent.cpp | 93 ++ src/FNetNfc_NfcTagDiscoveryEvent.h | 84 ++ src/FNetNfc_NfcTagDiscoveryEventArg.cpp | 63 ++ src/FNetNfc_NfcTagDiscoveryEventArg.h | 102 +++ src/FNetNfc_NfcTagImpl.cpp | 108 +++ src/FNetNfc_TagConnectionEvent.cpp | 160 ++++ src/FNetNfc_TagConnectionEvent.h | 84 ++ src/FNetNfc_TagConnectionEventArg.cpp | 136 +++ src/FNetNfc_TagConnectionEventArg.h | 129 +++ src/FNetNfc_TagConnectionImpl.cpp | 509 +++++++++++ src/inc/FNetNfc_ConnectivityIpcMessages.h | 38 + src/inc/FNetNfc_ITagConnectionListener.h | 103 +++ src/inc/FNetNfc_NdefMessageImpl.h | 233 +++++ src/inc/FNetNfc_NdefMessageUtil.h | 115 +++ src/inc/FNetNfc_NdefPushManagerImpl.h | 126 +++ src/inc/FNetNfc_NdefRecordImpl.h | 181 ++++ src/inc/FNetNfc_NdefRecordTypeImpl.h | 168 ++++ src/inc/FNetNfc_NfcManagerImpl.h | 317 +++++++ src/inc/FNetNfc_NfcTagImpl.h | 124 +++ src/inc/FNetNfc_TagConnectionImpl.h | 216 +++++ 81 files changed, 14014 insertions(+) create mode 100755 CMakeLists.txt create mode 100755 LICENSE.APLv2.0 create mode 100755 LICENSE.Flora create mode 100755 NOTICE create mode 100644 inc/FNetNfc.h create mode 100644 inc/FNetNfcINdefMessageDiscoveryEventListener.h create mode 100644 inc/FNetNfcINdefPushManagerListener.h create mode 100644 inc/FNetNfcINdefTagConnectionListener.h create mode 100644 inc/FNetNfcINfcDeviceDiscoveryEventListener.h create mode 100644 inc/FNetNfcINfcManagerEventListener.h create mode 100644 inc/FNetNfcINfcTagDiscoveryEventListener.h create mode 100644 inc/FNetNfcITagConnectionListener.h create mode 100644 inc/FNetNfcNdefMessage.h create mode 100755 inc/FNetNfcNdefPushManager.h create mode 100644 inc/FNetNfcNdefRecord.h create mode 100644 inc/FNetNfcNdefRecordType.h create mode 100644 inc/FNetNfcNdefTagConnection.h create mode 100755 inc/FNetNfcNfcManager.h create mode 100644 inc/FNetNfcNfcTag.h create mode 100644 inc/FNetNfcNfcTypes.h create mode 100644 inc/FNetNfcTagConnection.h create mode 100644 osp-nfc.manifest create mode 100755 osp-nfc.pc.in create mode 100755 packaging/osp-nfc.spec create mode 100644 src/FNetNfcNdefMessage.cpp create mode 100644 src/FNetNfcNdefPushManager.cpp create mode 100644 src/FNetNfcNdefRecord.cpp create mode 100644 src/FNetNfcNdefRecordType.cpp create mode 100644 src/FNetNfcNdefTagConnection.cpp create mode 100644 src/FNetNfcNfcManager.cpp create mode 100644 src/FNetNfcNfcTag.cpp create mode 100644 src/FNetNfcTagConnection.cpp create mode 100644 src/FNetNfc_NdefMessageDiscoveryEvent.cpp create mode 100644 src/FNetNfc_NdefMessageDiscoveryEvent.h create mode 100644 src/FNetNfc_NdefMessageDiscoveryEventArg.cpp create mode 100644 src/FNetNfc_NdefMessageDiscoveryEventArg.h create mode 100644 src/FNetNfc_NdefMessageImpl.cpp create mode 100644 src/FNetNfc_NdefMessageUtil.cpp create mode 100644 src/FNetNfc_NdefPushManagerEvent.cpp create mode 100644 src/FNetNfc_NdefPushManagerEvent.h create mode 100644 src/FNetNfc_NdefPushManagerEventArg.cpp create mode 100644 src/FNetNfc_NdefPushManagerEventArg.h create mode 100644 src/FNetNfc_NdefPushManagerImpl.cpp create mode 100644 src/FNetNfc_NdefRecordImpl.cpp create mode 100644 src/FNetNfc_NdefRecordTypeImpl.cpp create mode 100644 src/FNetNfc_NfcAuthorityController.cpp create mode 100644 src/FNetNfc_NfcAuthorityController.h create mode 100644 src/FNetNfc_NfcDeviceDiscoveryEvent.cpp create mode 100644 src/FNetNfc_NfcDeviceDiscoveryEvent.h create mode 100644 src/FNetNfc_NfcDeviceDiscoveryEventArg.cpp create mode 100644 src/FNetNfc_NfcDeviceDiscoveryEventArg.h create mode 100644 src/FNetNfc_NfcIpcMessages.cpp create mode 100644 src/FNetNfc_NfcIpcProxy.cpp create mode 100644 src/FNetNfc_NfcIpcProxy.h create mode 100644 src/FNetNfc_NfcManagerEvent.cpp create mode 100644 src/FNetNfc_NfcManagerEvent.h create mode 100644 src/FNetNfc_NfcManagerEventArg.cpp create mode 100644 src/FNetNfc_NfcManagerEventArg.h create mode 100644 src/FNetNfc_NfcManagerImpl.cpp create mode 100644 src/FNetNfc_NfcSystemAdapter.cpp create mode 100644 src/FNetNfc_NfcSystemAdapter.h create mode 100644 src/FNetNfc_NfcTagDiscoveryEvent.cpp create mode 100644 src/FNetNfc_NfcTagDiscoveryEvent.h create mode 100644 src/FNetNfc_NfcTagDiscoveryEventArg.cpp create mode 100644 src/FNetNfc_NfcTagDiscoveryEventArg.h create mode 100644 src/FNetNfc_NfcTagImpl.cpp create mode 100644 src/FNetNfc_TagConnectionEvent.cpp create mode 100644 src/FNetNfc_TagConnectionEvent.h create mode 100644 src/FNetNfc_TagConnectionEventArg.cpp create mode 100644 src/FNetNfc_TagConnectionEventArg.h create mode 100644 src/FNetNfc_TagConnectionImpl.cpp create mode 100644 src/inc/FNetNfc_ConnectivityIpcMessages.h create mode 100644 src/inc/FNetNfc_ITagConnectionListener.h create mode 100644 src/inc/FNetNfc_NdefMessageImpl.h create mode 100644 src/inc/FNetNfc_NdefMessageUtil.h create mode 100644 src/inc/FNetNfc_NdefPushManagerImpl.h create mode 100644 src/inc/FNetNfc_NdefRecordImpl.h create mode 100644 src/inc/FNetNfc_NdefRecordTypeImpl.h create mode 100644 src/inc/FNetNfc_NfcManagerImpl.h create mode 100644 src/inc/FNetNfc_NfcTagImpl.h create mode 100644 src/inc/FNetNfc_TagConnectionImpl.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..8f20e8e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,111 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET (this_target osp-nfc) + +SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output) + +INCLUDE_DIRECTORIES( + inc + src + src/inc + /usr/include/chromium + /usr/include/glib-2.0 + /usr/lib/glib-2.0/include + /usr/include/system + /usr/include/network + /usr/include/osp + /usr/include/osp/app + /usr/include/osp/base + /usr/include/osp/io + /usr/include/osp/net + /usr/include/osp/security + /usr/include/osp/system + ) + +SET (${this_target}_SOURCE_FILES + src/FNetNfcNdefMessage.cpp + src/FNetNfcNdefRecord.cpp + src/FNetNfcNdefRecordType.cpp + src/FNetNfcNdefTagConnection.cpp + src/FNetNfcNfcManager.cpp + src/FNetNfcNfcTag.cpp + src/FNetNfcTagConnection.cpp + src/FNetNfcNdefPushManager.cpp + src/FNetNfc_NdefMessageDiscoveryEvent.cpp + src/FNetNfc_NdefMessageDiscoveryEventArg.cpp + src/FNetNfc_NdefMessageImpl.cpp + src/FNetNfc_NdefMessageUtil.cpp + src/FNetNfc_NdefRecordImpl.cpp + src/FNetNfc_NdefRecordTypeImpl.cpp + src/FNetNfc_NfcAuthorityController.cpp + src/FNetNfc_NfcIpcMessages.cpp + src/FNetNfc_NfcIpcProxy.cpp + src/FNetNfc_NfcManagerEvent.cpp + src/FNetNfc_NfcManagerEventArg.cpp + src/FNetNfc_NfcManagerImpl.cpp + src/FNetNfc_NfcSystemAdapter.cpp + src/FNetNfc_NfcTagDiscoveryEvent.cpp + src/FNetNfc_NfcTagDiscoveryEventArg.cpp + src/FNetNfc_NfcTagImpl.cpp + src/FNetNfc_TagConnectionEvent.cpp + src/FNetNfc_TagConnectionEventArg.cpp + src/FNetNfc_TagConnectionImpl.cpp + src/FNetNfc_NdefPushManagerImpl.cpp + src/FNetNfc_NfcDeviceDiscoveryEvent.cpp + src/FNetNfc_NfcDeviceDiscoveryEventArg.cpp + src/FNetNfc_NdefPushManagerEventArg.cpp + src/FNetNfc_NdefPushManagerEvent.cpp +) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" ) + +## SET C COMPILER FLAGS +SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## SET CPP COMPILER FLAGS +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") +SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## Create Library +ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES}) + +## SET LINKER FLAGS +SET(CMAKE_SHARED_LINKER_FLAGS -Wl,--no-undefined) + +TARGET_LINK_LIBRARIES(${this_target} "-lchromium" ) +TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw -losp-net" ) +TARGET_LINK_LIBRARIES(${this_target} "-lcapi-network-nfc" ) +TARGET_LINK_LIBRARIES(${this_target} "-lpthread" ) + +SET_TARGET_PROPERTIES(${this_target} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 + ) + +ADD_CUSTOM_COMMAND(TARGET ${this_target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${MAJORVER} + COMMAND ${CMAKE_STRIP} --strip-unneeded ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMENT "strip ${this_target}" + ) + +INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/ DESTINATION lib/osp + FILES_MATCHING PATTERN "*.so*" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ) +INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/debug/ DESTINATION lib/osp/debug + FILES_MATCHING PATTERN "*.so*" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ) + +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/inc/ DESTINATION include/osp FILES_MATCHING PATTERN "*.h") +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src/inc/ DESTINATION include/osp/net FILES_MATCHING PATTERN "*.h") + +# pkgconfig file +CONFIGURE_FILE(${this_target}.pc.in ${CMAKE_SOURCE_DIR}/${this_target}.pc @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/${this_target}.pc DESTINATION lib/pkgconfig) diff --git a/LICENSE.APLv2.0 b/LICENSE.APLv2.0 new file mode 100755 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2.0 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE.Flora b/LICENSE.Flora new file mode 100755 index 0000000..9c95663 --- /dev/null +++ b/LICENSE.Flora @@ -0,0 +1,206 @@ +Flora License + +Version 1.0, May, 2012 + +http://floralicense.org/license/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and +all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of +this definition, "control" means (i) the power, direct or indirect, +to cause the direction or management of such entity, +whether by contract or otherwise, or (ii) ownership of fifty percent (50%) +or more of the outstanding shares, or (iii) beneficial ownership of +such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice +that is included in or attached to the work (an example is provided +in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, +or merely link (or bind by name) to the interfaces of, the Work and +Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual or +Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or +its representatives, including but not limited to communication on +electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated +in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies +with the standards set forth in the Compatibility Definition Document +and passes the Compatibility Test Suite as defined from time to time +by the Tizen Technical Steering Group and certified by the Tizen +Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work +solely as incorporated into a Tizen Certified Platform, where such +license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work solely +as incorporated into a Tizen Certified Platform to which such +Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim +in a lawsuit) alleging that the Work or a Contribution incorporated +within the Work constitutes direct or contributory patent infringement, +then any patent licenses granted to You under this License for that +Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof pursuant to the copyright license +above, in any medium, with or without modifications, and in Source or +Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works + a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating + that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that + You distribute, all copyright, patent, trademark, and attribution + notices from the Source form of the Work, excluding those notices + that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, + then any Derivative Works that You distribute must include a readable + copy of the attribution notices contained within such NOTICE file, + excluding those notices that do not pertain to any part of + the Derivative Works, in at least one of the following places: + within a NOTICE text file distributed as part of the Derivative Works; + within the Source form or documentation, if provided along with the + Derivative Works; or, within a display generated by the Derivative Works, + if and wherever such third-party notices normally appear. + The contents of the NOTICE file are for informational purposes only + and do not modify the License. + +You may add Your own attribution notices within Derivative Works +that You distribute, alongside or as an addendum to the NOTICE text +from the Work, provided that such additional attribution notices +cannot be construed as modifying the License. You may add Your own +copyright statement to Your modifications and may provide additional or +different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works +as a whole, provided Your use, reproduction, and distribution of +the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Flora License, Version 1.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://floralicense.org/license/ + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/NOTICE b/NOTICE new file mode 100755 index 0000000..cca4178 --- /dev/null +++ b/NOTICE @@ -0,0 +1,9 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE file for Apache License terms and conditions. + +Several source codes may have its original copyright owner and/or +be licensed under other than Apache License, Version 2, say, Flora License, Version 1. +Please, see copyright and license comments section in the header of each file, +and the LICENSE.Flora for Flora License terms and conditions. + diff --git a/inc/FNetNfc.h b/inc/FNetNfc.h new file mode 100644 index 0000000..9ababb8 --- /dev/null +++ b/inc/FNetNfc.h @@ -0,0 +1,67 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc.h + * @brief This is the header file for the %Nfc namespace. + * + * This header file contains the declarations and descriptions of the %Nfc namespace. + */ +#ifndef _FNET_NFC_H_ +#define _FNET_NFC_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Tizen { namespace Net +{ +/** + * @namespace Tizen::Net::Nfc + * @brief This namespace contains the classes and interfaces for the Near Field Communication (NFC) services. + * @since 2.0 + * + * @remarks @b Header @b %file: @b \#include @b @n + * @b Library : @b osp-nfc @n + * + * The %Nfc namespace contains the various classes and interfaces for the Near Field Communication (NFC) programming that + * enables the devices to share information within a distance of less than @c 4 centimeters. + * + * For more information on the NFC namespace features, see + * NFC Guide. + * + * + * The following diagram illustrates the relationships between the classes belonging to the %Nfc namespace. + * @image html net_nfc_using_the_apis_classdiagram.png + * + */ +namespace Nfc +{ +} } } // Tizen::Net::Nfc +#endif // _FNET_NFC_H_ diff --git a/inc/FNetNfcINdefMessageDiscoveryEventListener.h b/inc/FNetNfcINdefMessageDiscoveryEventListener.h new file mode 100644 index 0000000..285c8e9 --- /dev/null +++ b/inc/FNetNfcINdefMessageDiscoveryEventListener.h @@ -0,0 +1,105 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcINdefMessageDiscoveryEventListener.h + * @brief This is the header file for the %INdefMessageDiscoveryEventListener interface. + * + * This header file contains the declarations of the %INdefMessageDiscoveryEventListener interface. + */ + +#ifndef _FNET_NFC_INDEF_MESSAGE_DISCOVERY_EVENT_LISTENER_H_ +#define _FNET_NFC_INDEF_MESSAGE_DISCOVERY_EVENT_LISTENER_H_ + +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NdefMessage; + +/** + * @interface INdefMessageDiscoveryEventListener + * @brief This interface provides a listener for the events related to the NDEF message discovery. + * + * @since 2.0 + * + * The %INdefMessageDiscoveryEventListener interface specifies the methods used for creating notifications about the NDEF message discovered from the + * target tag. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ INdefMessageDiscoveryEventListener + : public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~INdefMessageDiscoveryEventListener(void) {} + + /** + * Called to notify the application when an NDEF message, that includes the NDEF records with the specified filter + * type, is detected. + * + * @since 2.0 + * + * @param[in] pMessage The detected NDEF message + * @remarks This method can be used for read-only access to the data on the target without opening a connection + * to it. @n + * The input NdefMessage object must be deleted by the application after use, even outside this + * method. The NdefMessage::RemoveAllRecords() method must be called with @c true as the input value + * immediately before the NdefMessage object is deleted. + */ + virtual void OnNdefMessageDetectedN(NdefMessage* pMessage) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefMessageDiscoveryEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefMessageDiscoveryEventListener_Reserved2(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefMessageDiscoveryEventListener_Reserved3(void) {} +}; // INdefMessageDiscoveryEventListener + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_INDEF_MESSAGE_DISCOVERY_EVENT_LISTENER_H_ diff --git a/inc/FNetNfcINdefPushManagerListener.h b/inc/FNetNfcINdefPushManagerListener.h new file mode 100644 index 0000000..cae1656 --- /dev/null +++ b/inc/FNetNfcINdefPushManagerListener.h @@ -0,0 +1,89 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcINdefPushManagerListener.h + * @brief This is the header file for the %INdefPushManagerListener interface. + * + * This header file contains the declarations of the %INdefPushManagerListener interface. + */ + +#ifndef _FNET_NFC_INDEF_PUSH_MANAGER_LISTENER_H_ +#define _FNET_NFC_INDEF_PUSH_MANAGER_LISTENER_H_ + +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ +/** + * @interface INdefPushManagerListener + * @brief This interface provides a listener for the events related to the %NfcPushManager. + * @since 2.0 + * + * The %INdefPushManagerListener interface specifies the methods used for receiving the status of the pushed NDEF message asynchronously. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ INdefPushManagerListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~INdefPushManagerListener(void) {} + + /** + * Called when the push operation to the target device is completed. + * + * @since 2.0 + * + * @param[in] r The result of pushed NDEF message @ + * Following exceptions may be given through this parameter. + * @exception E_SUCCESS The method is successful. + * @exception E_NOT_RESPONDING The device is not responding. + * @exception E_OPERATION_FAILED The operation has failed. + */ + virtual void OnNdefPushMessageSent(result r) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // The following methods are reserved, and the name of methods can be changed at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefPushManagerListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // The following methods are reserved, and the name of methods can be changed at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefPushManagerListener_Reserved2(void) {} +}; // INdefPushManagerListener + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_INDEF_PUSH_MANAGER_LISTENER_H_ diff --git a/inc/FNetNfcINdefTagConnectionListener.h b/inc/FNetNfcINdefTagConnectionListener.h new file mode 100644 index 0000000..e29a747 --- /dev/null +++ b/inc/FNetNfcINdefTagConnectionListener.h @@ -0,0 +1,127 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcINdefTagConnectionListener.h + * @brief This is the header file for the %INdefTagConnectionListener interface. + * + * This header file contains the declarations of the %INdefTagConnectionListener interface. + */ + +#ifndef _FNET_NFC_INDEF_TAG_CONNECTION_LISTENER_H_ +#define _FNET_NFC_INDEF_TAG_CONNECTION_LISTENER_H_ + +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NdefMessage; + +/** + * @interface INdefTagConnectionListener + * @brief This interface provides a listener for the events related to the NDEF tag connection. + * + * @since 2.0 + * + * The %INdefTagConnectionListener interface specifies the methods used for creating the notifications about the result of an action for the + * NdefTagConnection, such as reading and writing the NDEF data. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ INdefTagConnectionListener + : public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~INdefTagConnectionListener(void) {} + + /** + * Called to notify the application when the read operation from the target tag is completed. + * + * @since 2.0 + * + * @param[in] pMessage The read %NdefMessage object, @n + * else @c null if the method is not successful + * @param[in] r An error code + * @exception E_SUCCESS The method is successful. + * @exception E_DATA_NOT_FOUND The target tag has no NDEF record. + * @exception E_INVALID_FORMAT The read data cannot be formulated to the NDEF message. + * @exception E_NOT_RESPONDING The target tag is not responding. + * @exception E_SYSTEM A system error has occurred. + * @see NdefTagConnection::Read() + * @remarks The input NdefMessage object must be deleted by the application after use, even outside this + * method. The NdefMessage::RemoveAllRecords() method must be called with @c true as the input value + * right before the NdefMessage object is deleted. + */ + virtual void OnNdefReadCompletedN(NdefMessage* pMessage, result r) = 0; + + /** + * Called to notify the application when the write operation on the target tag is completed. + * + * @since 2.0 + * + * @param[in] r An error code + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The write operation on the target tag is denied. @n + * The target tag is locked or protected for the write operation. + * @exception E_STORAGE_FULL The storage capacity of the target tag is full. + * @exception E_NOT_RESPONDING The target tag is not responding. + * @exception E_SYSTEM A system error has occurred. + * @see NdefTagConnection::Write() + */ + virtual void OnNdefWriteCompleted(result r) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefTagConnectionListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefTagConnectionListener_Reserved2(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INdefTagConnectionListener_Reserved3(void) {} +}; // INdefTagConnectionListener + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_INDEF_TAG_CONNECTION_LISTENER_H_ diff --git a/inc/FNetNfcINfcDeviceDiscoveryEventListener.h b/inc/FNetNfcINfcDeviceDiscoveryEventListener.h new file mode 100644 index 0000000..a14f26a --- /dev/null +++ b/inc/FNetNfcINfcDeviceDiscoveryEventListener.h @@ -0,0 +1,94 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcINfcDeviceDiscoveryEventListener.h + * @brief This is the header file for the %INfcDeviceDiscoveryEventListener interface. + * + * This header file contains the declarations of the %INfcDeviceDiscoveryEventListener interface. + */ + +#ifndef _FNET_NFC_INFC_DEVICE_DISCOVERY_EVENT_LISTENER_H_ +#define _FNET_NFC_INFC_DEVICE_DISCOVERY_EVENT_LISTENER_H_ + +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @interface INfcDeviceDiscoveryEventListener + * @brief This interface provides a listener for the events related to device discovery. + * @since 2.0 + * + * The %INfcDeviceDiscoveryEventListener interface specifies the methods used for creating the notifications + * about detecting a device. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ INfcDeviceDiscoveryEventListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~INfcDeviceDiscoveryEventListener(void) {} + + /** + * Called to notify the application when a device is detected. + * + * @since 2.0 + */ + virtual void OnNfcDeviceDetected(void) = 0; + + /** + * Called to notify the application when a device is lost. + * + * @since 2.0 + */ + virtual void OnNfcDeviceLost(void) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, + // and consistency-related issues in the application. + // + // The following methods are reserved, and the name of methods can be changed at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcDeviceDiscoveryEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, + // and consistency-related issues in the application. + // + // The following methods are reserved, and the name of methods can be changed at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcDeviceDiscoveryEventListener_Reserved2(void) {} +}; // INfcDeviceDiscoveryEventListener + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_INFC_DEVICE_DISCOVERY_EVENT_LISTENER_H_ diff --git a/inc/FNetNfcINfcManagerEventListener.h b/inc/FNetNfcINfcManagerEventListener.h new file mode 100644 index 0000000..c145204 --- /dev/null +++ b/inc/FNetNfcINfcManagerEventListener.h @@ -0,0 +1,129 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcINfcManagerEventListener.h + * @brief This is the header file for the %INfcManagerEventListener interface. + * + * This header file contains the declarations of the %INfcManagerEventListener interface. + */ + +#ifndef _FNET_NFC_INFC_MANAGER_EVENT_LISTENER_H_ +#define _FNET_NFC_INFC_MANAGER_EVENT_LISTENER_H_ + +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @interface INfcManagerEventListener + * @brief This interface provides a listener for the events related to the Near field Communication (NFC) + * manager. + * + * @since 2.0 + * + * The %INfcManagerEventListener interface specifies the method used for creating the notifications about a change in the NfcManager status. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ INfcManagerEventListener + : public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~INfcManagerEventListener(void) {} + + /** + * Called to notify when the NFC feature is activated on the device. + * + * @since 2.0 + * + * @param[in] r The activation status + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + */ + virtual void OnNfcActivated(result r) = 0; + + /** + * Called to notify when the NFC feature is deactivated on the device. + * + * @since 2.0 + * + * @param[in] r The deactivation status + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + */ + virtual void OnNfcDeactivated(result r) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcManagerEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcManagerEventListener_Reserved2(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcManagerEventListener_Reserved3(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcManagerEventListener_Reserved4(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcManagerEventListener_Reserved5(void) {} + +}; // INfcManagerEventListener + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_INFC_MANAGER_EVENT_LISTENER_H_ diff --git a/inc/FNetNfcINfcTagDiscoveryEventListener.h b/inc/FNetNfcINfcTagDiscoveryEventListener.h new file mode 100644 index 0000000..d204fbb --- /dev/null +++ b/inc/FNetNfcINfcTagDiscoveryEventListener.h @@ -0,0 +1,112 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcINfcTagDiscoveryEventListener.h + * @brief This is the header file for the %INfcTagDiscoveryEventListener interface. + * + * This header file contains the declarations of the %INfcTagDiscoveryEventListener interface. + */ + +#ifndef _FNET_NFC_INFC_TAG_DISCOVERY_EVENT_LISTENER_H_ +#define _FNET_NFC_INFC_TAG_DISCOVERY_EVENT_LISTENER_H_ + +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class TagConnection; + +/** + * @interface INfcTagDiscoveryEventListener + * @brief This interface provides a listener for the events related to tag discovery. + * + * @since 2.0 + * + * The %INfcTagDiscoveryEventListener interface specifies the methods used for creating the notifications about detecting the target tag. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ INfcTagDiscoveryEventListener + : public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~INfcTagDiscoveryEventListener(void) {} + + /** + * Called to notify the application when the tag is detected by the device. + * + * @since 2.0 + * + * @param[in] pConnection The connection established with the detected tag + * @remarks TagConnection is inherited by NdefTagConnection if the current attached tag supports NDEF + * operations. + * To verify this, use TagConnection::IsNdefConnection(). + */ + virtual void OnNfcTagDetectedN(TagConnection* pConnection) = 0; + + /** + * Called to notify the application when the tag is lost by the device. + * + * @since 2.0 + * + * @remarks The operations of TagConnection returned by OnNfcTagDetectedN() are not processed further after + * this event is called, that is, the target tag is lost. Moreover, the TagConnection object cannot be + * reused even though the same tag is detected again by the device. + */ + virtual void OnNfcTagLost(void) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcTagDiscoveryEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcTagDiscoveryEventListener_Reserved2(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void INfcTagDiscoveryEventListener_Reserved3(void) {} +}; // INfcTagDiscoveryEventListener + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_INFC_TAG_DISCOVERY_EVENT_LISTENER_H_ diff --git a/inc/FNetNfcITagConnectionListener.h b/inc/FNetNfcITagConnectionListener.h new file mode 100644 index 0000000..a9716ca --- /dev/null +++ b/inc/FNetNfcITagConnectionListener.h @@ -0,0 +1,111 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcITagConnectionListener.h + * @brief This is the header file for the %ITagConnectionListener interface. + * + * This header file contains the declarations of the %ITagConnectionListener interface. + */ + +#ifndef _FNET_NFC_ITAG_CONNECTION_LISTENER_H_ +#define _FNET_NFC_ITAG_CONNECTION_LISTENER_H_ + +#include +#include + +namespace Tizen { namespace Base +{ +class ByteBuffer; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @interface ITagConnectionListener + * @brief This interface provides a listener for the events related to the tag connection. + * + * @since 2.0 + * + * The %ITagConnectionListener interface provides methods that are used for creating notifications for the result of the actions of the + * TagConnection, such as sending a command. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ ITagConnectionListener + : public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~ITagConnectionListener(void) {} + + /** + * Called to notify the application when the response is received from the remote tag. + * + * @since 2.0 + * + * @param[in] pResponse The response of the command as the ByteBuffer object, @n + * else @c null if the method is not successful + * @param[in] r An error code + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The sent command is denied by the target. @n + * The target tag is locked or protected for executing the command. + * @exception E_NOT_RESPONDING The target tag is not responding. + * @exception E_SYSTEM A system error has occurred. + * @see TagConnection::SendCommand() + * @remarks The input response (@c pResponse) must be deleted by the application to prevent memory leak. + */ + virtual void OnNfcResponseReceivedN(Tizen::Base::ByteBuffer* pResponse, result r) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ITagConnectionListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ITagConnectionListener_Reserved2(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ITagConnectionListener_Reserved3(void) {} +}; // ITagConnectionListener + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_ITAG_CONNECTION_LISTENER_H_ diff --git a/inc/FNetNfcNdefMessage.h b/inc/FNetNfcNdefMessage.h new file mode 100644 index 0000000..8d79f7f --- /dev/null +++ b/inc/FNetNfcNdefMessage.h @@ -0,0 +1,298 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefMessage.h + * @brief This is the header file for the %NdefMessage class. + * + * This header file contains the declarations of the %NdefMessage class. + */ + +#ifndef _FNET_NFC_NDEF_MESSAGE_H_ +#define _FNET_NFC_NDEF_MESSAGE_H_ + +#include +#include + +namespace Tizen { namespace Base +{ +class ByteBuffer; +class String; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NdefMessageImpl; +class NdefRecord; + +/** + * @class NdefMessage + * @brief This class represents an NDEF message. + * + * @since 2.0 + * + * The %NdefMessage class represents an NDEF message. An NDEF message is composed of 1 or more NDEF records. Therefore, this class + * has NdefRecord instances and provides the operations to manipulate the list of those instances. These operations are + * very similar to those of the Tizen::Base::Collection::IList class. + * + * If a new NDEF record is inserted, the uniqueness of its payload identifier is checked. This class also provides + * methods which convert %NdefMessage to Tizen::Base::ByteBuffer and vice versa. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ NdefMessage + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + NdefMessage(void); + + /** + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.0 + * + * @param[in] value An instance of %NdefMessage + * @remarks This performs a deep copy. + */ + NdefMessage(const NdefMessage& value); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~NdefMessage(void); + + /** + * Compares the calling instance with the specified instance. + * + * @since 2.0 + * @return @c true if the specified instance of %Object is equal to the calling %NdefMessage instance, @n + * else @c false + * @param[in] obj The object to compare + * @remark Two %NdefMessage instances are equal only if they contain the same %NdefRecord instances in the + * same order. + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Gets the number of NDEF records in this NDEF message. + * + * @since 2.0 + * + * @return The number of NDEF records + */ + int GetRecordsCount(void) const; + + /** + * Searches for an NdefRecord object in this class. @n + * Gets the index of the NdefRecord object if the record is present. + * + * @since 2.0 + * + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The specified record is not found. + * @remarks This method verifies the equality of its pointers, but does not check the content of the specified + * record. + */ + result IndexOf(const NdefRecord& record, int& index) const; + + /** + * Gets the NdefRecord object from the specified location. + * + * @since 2.0 + * + * @return The requested NdefRecord object, @n + * else @c null if the index is not valid + * @param[in] index The index of the NDEF record to get + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index parameter is either greater than or equal to the number + * of elements or less than @c 0. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + NdefRecord* GetRecordAt(int index) const; + + /** + * Gets the NdefRecord object with the specified payload identifier. + * + * @since 2.0 + * + * @return The requested NdefRecord object, @n + * else @c null if no record matches + * @param[in] payloadId The payload identifier of the NDEF record to get + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The specified @c id is not found in any of the NDEF records. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + NdefRecord* GetRecord(const Tizen::Base::String& payloadId) const; + + /** + * Appends the specified NDEF record at the end of the last record in the NDEF message. + * + * @since 2.0 + * + * @return An error code + * @param[in] record The NDEF record to be appended + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified NDEF record is invalid. @n + * For example, the record has the same payload identifier as the other records in + * this NDEF message. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks This method performs a shallow copy. It adds just the pointer, not the NdefRecord instance. + */ + result AppendRecord(const NdefRecord& record); + + /** + * Inserts the specified NDEF record in the NDEF message at the specified location. + * + * @since 2.0 + * + * @return An error code + * @param[in] record The NDEF record to be inserted + * @param[in] index The index at which the NDEF record must be inserted + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index is greater than the number of elements or less than + * @c 0. + * @exception E_INVALID_ARG The specified NDEF record is invalid. @n + * For example, the record has the same payload identifier as the other records in + * this NDEF message. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The NDEF records that appear after the insertion point move downwards to accommodate the inserted + * NDEF record. + * This method performs a shallow copy. It adds just the pointer, not the NdefRecord instance. + */ + result InsertRecordAt(const NdefRecord& record, int index); + + /** + * Replaces the NDEF record from the specified location with the specified NDEF record. + * + * @since 2.0 + * + * @return An error code + * @param[in] record The NDEF record to be set + * @param[in] index The index at which the NDEF record is to be set + * @param[in] deallocate Set to @c true to deallocate the replaced record, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index is either equal to or greater than the number of + * elements or less than @c 0. + * @exception E_INVALID_ARG The specified NDEF record is invalid. @n + * For example, the record has the same payload identifier as the other records in + * this NDEF message. + * @remarks This method performs a shallow copy. It adds just the pointer, not the NdefRecord instance. + */ + result SetRecordAt(const NdefRecord& record, int index, bool deallocate = false); + + /** + * Removes the NDEF record from a specified location. + * + * @since 2.0 + * + * @return An error code + * @param[in] index The index from where the NDEF record is removed + * @param[in] deallocate Set to @c true to deallocate the record, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index is either equal to or greater than the number of + * elements or less than @c 0. + * @remarks The NDEF records that appear after the deletion point move upwards to occupy the vacated spot. + */ + result RemoveRecordAt(int index, bool deallocate = false); + + /** + * Removes all the records in the NDEF message. @n + * If the specified @c deallocate parameter is set to @c true, it deallocates all the NdefRecord instances in the + * message. + * + * @since 2.0 + * + * @param[in] deallocate Set to @c true to deallocate the record, @n + * else @c false + */ + void RemoveAllRecords(bool deallocate = false); + + /** + * Converts the entire NDEF message with all the NDEF records into a byte sequence as per the NDEF specification. + * + * @since 2.0 + * + * @return The NDEF message as a ByteBuffer, @n + * else @c null if the conversion fails + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA The specified NDEF message does not contain any NDEF records. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* ToByteBufferN(void) const; + + /** + * Gets a new instance of the NDEF message from the specified ByteBuffer. + * + * @since 2.0 + * + * @return The instance of the created NDEF message, @n + * else @c null if the conversion fails + * @param[in] buffer An NDEF message as a byte sequence + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_FORMAT The specified @c buffer cannot be formulated to the NDEF message. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + static NdefMessage* GetInstanceN(const Tizen::Base::ByteBuffer& buffer); + + /** + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.0 + * + * @return A reference to the %NdefMessage instance + * @param[in] rhs A reference to the %NdefMessage instance to copy + */ + NdefMessage& operator =(const NdefMessage& rhs); + +private: + _NdefMessageImpl* __pImpl; + + friend class __pImpl; + +}; // NdefMessage + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NDEF_MESSAGE_H_ diff --git a/inc/FNetNfcNdefPushManager.h b/inc/FNetNfcNdefPushManager.h new file mode 100755 index 0000000..8f64839 --- /dev/null +++ b/inc/FNetNfcNdefPushManager.h @@ -0,0 +1,176 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefPushManager.h + * @brief This is the header file for the %NdefPushManager class. + * + * This header file contains the declarations of the %NdefPushManager class. + */ +#ifndef _FNET_NFC_NDEF_PUSH_MANAGER_H_ +#define _FNET_NFC_NDEF_PUSH_MANAGER_H_ + +#include +#include + +namespace Tizen { namespace Base +{ +class String; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +class INdefPushManagerListener; +class NdefMessage; +class _NdefPushManagerImpl; + +/** + * @class NdefPushManager + * @brief This is the class for pushing an NDEF message to a device. + * + * @since 2.0 + * + * @final This class is not intended for extension. + * + * The %NdefPushManager class is the class for pushing an NDEF message to a device. + * + * For more information on the class features, see + * NFC Guide. + * + */ +class _OSP_EXPORT_ NdefPushManager + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + NdefPushManager(void); + + /** + * This destructor overrides Object::~Object(). + * + * @since 2.0 + */ + ~NdefPushManager(void); + + /** + * Sets a listener for receiving the result of pushing an NDEF message. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.p2p + * + * @return An error code + * @param[in] pListener An instance of %INdefPushManagerListener. @n + * If it is null, it will reset the listener. + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OPERATION_FAILED The operation has failed. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + */ + result SetNdefPushManagerListener(INdefPushManagerListener* pListener); + + /** + * Pushes the NDEF message. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.p2p + * + * @return An error code + * @param[in] message The NDEF message to be sent + * @exception E_SUCCESS The method is successful. + * @exception E_DEVICE_BUSY The device is processing preceding job. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_STATE This instance is in an invalid state. @n + * For example, the NFC feature is not activated @n + * or a peer device is not attached. + * @exception E_INVALID_ARG The input @c message is invalid. @n + * For example, it does not contain any NDEF records. + * @exception E_OPERATION_FAILED The operation has failed. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks + */ + result Push(const NdefMessage& message); + + + /** + * Registers an NDEF message to be pushed if the home screen or the main menu is on top of the screen in the local + * device when a peer device is detected. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.p2p + * + * @return An error code + * @param[in] message The NDEF message to be registered + * @param[in] description The description for the NDEF message to be registered @n + * This description is used in Reserved Push UI, for example, UI for getting + * user consent to send the registered message. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The input @c message is invalid. @n + * For example, it does not contain any NDEF records. + * @exception E_UNSUPPORTED_OPERATION The method has failed because the device does not support the NFC or the + * Reserved Push feature. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @remarks An application can register only one NDEF message. So the previously registered message will be + * replaced by the new one.@n + * The registered NDEF message is pushed only if it is selected by the user through the Setting + * application. + */ + static result RegisterNdefPushMessage(const NdefMessage& message, const Tizen::Base::String& description); + + /** + * Unregisters an NDEF message if the NDEF message to be pushed is registered. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.p2p + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_OPERATION The method has failed because the device does not support the NFC feature + * or the Reserved Push feature. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + */ + static result UnregisterNdefPushMessage(void); + +private: + /** + * The implementation of this copy constructor is intentionally blank to prohibit copying of objects. + * + * @since 2.0 + */ + NdefPushManager(const NdefPushManager& value); + + /** + * The implementation of this copy assignment operator is intentionally blank to prohibit copying of objects. + * + * @since 2.0 + */ + NdefPushManager& operator =(const NdefPushManager& value); + +private: + _NdefPushManagerImpl* __pImpl; + + friend class _NdefPushManagerImpl; +}; // NdefPushManager + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NDEF_PUSH_MANAGER_H_ diff --git a/inc/FNetNfcNdefRecord.h b/inc/FNetNfcNdefRecord.h new file mode 100644 index 0000000..d1aadee --- /dev/null +++ b/inc/FNetNfcNdefRecord.h @@ -0,0 +1,216 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefRecord.h + * @brief This is the header file for the %NdefRecord class. + * + * This header file contains the declarations of the %NdefRecord class. + */ + +#ifndef _FNET_NFC_NDEF_RECORD_H_ +#define _FNET_NFC_NDEF_RECORD_H_ + +#include +#include + +namespace Tizen { namespace Base +{ +class ByteBuffer; +class String; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NdefRecordImpl; +class NdefMessage; +class NdefRecordType; + +/** + * @class NdefRecord + * @brief This class represents an NDEF record. + * + * @since 2.0 + * + * The %NdefRecord class represents an NDEF record, including certain attributes such as the type, the payload, and the payload + * identifier. It provides the operations to manipulate them. However, this class does not expose all the attributes of + * an NDEF record. Some attributes defined in the NDEF specification are hidden because they are not important for + * applications. @n + * The NDEF record may contain an NDEF message in the payload. It can be converted from a Tizen::Base::ByteBuffer + * instance to an NdefMessage instance through the NdefMessage::GetInstanceN() method. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ NdefRecord + : public Tizen::Base::Object +{ +public: + /** + * Initializes this instance of %NdefRecord with the specified parameter. + * + * @since 2.0 + * + * @param[in] recordType A specified NDEF record type + */ + NdefRecord(const NdefRecordType& recordType); + + /** + * Copying of objects using this copy constructor is allowed. + * + * @since 2.0 + * + * @param[in] value An instance of %NdefRecord + * @remarks It performs a deep copy. + */ + NdefRecord(const NdefRecord& value); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~NdefRecord(void); + + /** + * Compares the calling instance with the specified instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of %Object is equal to the calling %NdefRecord instance, @n + * else @c false + * @param[in] obj The object to compare + * @remark Two %NdefRecord instances are equal only if they contain the same %NdefRecordType instances, + * payload ID, and payload. + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Gets the payload identifier for this NDEF record. + * + * @since 2.0 + * + * @return The identifier of the payload, @n + * else an empty string if the identifier does not exist in the NDEF record + */ + Tizen::Base::String GetPayloadId(void) const; + + /** + * Gets the payload in this record as ByteBuffer. + * + * @since 2.0 + * + * @return The payload, @n + * else @c null if the NDEF record does not have the payload + * @remarks If the payload is modified after it is fetched, the payload of this record also changes. + */ + Tizen::Base::ByteBuffer* GetPayload(void) const; + + /** + * Gets the record type of the NDEF record. + * + * @since 2.0 + * + * @return The record type of the NDEF record + */ + NdefRecordType GetRecordType(void) const; + + /** + * Sets the record type of the NDEF record. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The record type to be set + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The input argument is invalid. @n + * For example, NDEF_TNF_EMPTY is not allowed as the input value if the identifier + * is not an empty string or the payload is not @c null. + */ + result SetRecordType(NdefRecordType& type); + + /** + * Sets the identifier of the payload. + * + * @since 2.0 + * + * @return An error code + * @param[in] id The identifier of the payload + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is not allowed if the type name format of this record is + * NDEF_TNF_EMPTY. + * @exception E_INVALID_ARG The specified identifier is not unique compared to the other records in + * the same NDEF message. + * @exception E_INVALID_ENCODING_RANGE The specified input string contains code points that are outside the + * bounds specified by the US_ASCII encoding scheme. + * @exception E_MAX_EXCEEDED The length of @c id exceeds @c 256 characters. + * @remarks The identifier is compared with other records only if this NDEF record is already included in an + * NDEF message. + */ + result SetPayloadId(const Tizen::Base::String& id); + + /** + * Sets the specified data in the payload of this NDEF record. + * + * @since 2.0 + * + * @return An error code + * @param[in] payload The specified payload data + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is not allowed if the type name format of this record is + * NDEF_TNF_EMPTY. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_ARG The @c payload is invalid. @n + * For example, @c payload is not constructed. + * @remarks The view of the specified @c payload parameter is copied and the data is shared. Therefore, if the + * data of @c payload is modified after setting, the data of the payload in this record also changes. + */ + result SetPayload(const Tizen::Base::ByteBuffer& payload); + + /** + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.0 + * + * @return A reference to the %NdefRecord instance + * @param[in] rhs A reference to the %NdefRecord instance to copy + */ + NdefRecord& operator =(const NdefRecord& rhs); + +private: + NdefRecord(void); + +private: + _NdefRecordImpl* __pImpl; + + friend class _NdefRecordImpl; + +}; // NdefRecord + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NDEF_RECORD_H_ diff --git a/inc/FNetNfcNdefRecordType.h b/inc/FNetNfcNdefRecordType.h new file mode 100644 index 0000000..db2bedd --- /dev/null +++ b/inc/FNetNfcNdefRecordType.h @@ -0,0 +1,260 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefRecordType.h + * @brief This is the header file for the %NdefRecordType class. + * + * This header file contains the declarations of the %NdefRecordType class. + */ + +#ifndef _FNET_NFC_NDEF_RECORD_TYPE_H_ +#define _FNET_NFC_NDEF_RECORD_TYPE_H_ + +#include +#include +#include + +namespace Tizen { namespace Base +{ +class String; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NdefRecordTypeImpl; + +/** + * @if OSPDEPREC + * Defines the NDEF RTD Smart Poster type. + * + * @brief [Deprecated] + * @deprecated This object is provided only for backward compatibility and will be deleted in a future release. + * Use NFC_NDEF_RTD_SMART_POSTER instead of this object. + * @since 2.0 + * @endif + */ +_OSP_EXPORT_ extern const Tizen::Base::String NDEF_RTD_SMART_POSTER; + +/** +* Defines the NDEF RTD Smart Poster type. ("Sp") +* +* @since 2.0 +*/ +_OSP_EXPORT_ extern const wchar_t NFC_NDEF_RTD_SMART_POSTER[]; + +/** + * @if OSPDEPREC + * Defines the NDEF RTD %Text type. + * + * @brief [Deprecated] + * @deprecated This object is provided only for backward compatibility and will be deleted in a future release. + * Use NFC_NDEF_RTD_TEXT instead of this object. + * @since 2.0 + * @endif + */ +_OSP_EXPORT_ extern const Tizen::Base::String NDEF_RTD_TEXT; + +/** +* Defines the NDEF RTD %Text type. ("T") +* +* @since 2.0 +*/ +_OSP_EXPORT_ extern const wchar_t NFC_NDEF_RTD_TEXT[]; + +/** + * @if OSPDEPREC + * Defines the NDEF RTD URI type. + * + * @brief [Deprecated] + * @deprecated This object is provided only for backward compatibility and will be deleted in a future release. + * Use NFC_NDEF_RTD_URI instead of this object. + * @since 2.0 + * @endif + */ +_OSP_EXPORT_ extern const Tizen::Base::String NDEF_RTD_URI; + +/** +* Defines the NDEF RTD URI type. ("U") +* +* @since 2.0 +*/ +_OSP_EXPORT_ extern const wchar_t NFC_NDEF_RTD_URI[]; + +/** + * @class NdefRecordType + * @brief This class represents the type of an NDEF record. + * + * @since 2.0 + * + * The %NdefRecordType class represents the type of an NDEF record. It encapsulates the name and the name format of the NDEF record + * type. @n + * The name format is represented by the enumeration type, Tizen::Net::Nfc::NdefRecordTypeNameFormat. The name is encoded + * using the US_ASCII character set and follows the rules defined by the NFC forum RTDs and RFCs. The name does not + * include the prefix @c "urn:nfc:wkt:" and @c "urn:nfc:ext:" defined by the NFC forum. + * + * For more information on the class features, see + * NFC Guide. + */ + +class _OSP_EXPORT_ NdefRecordType + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. @n + * Initializes this instance of %NdefRecordType with the specified parameter. + * + * @since 2.0 + * + * @param[in] format The NDEF record type name format + */ + NdefRecordType(NdefRecordTypeNameFormat format = NDEF_TNF_EMPTY); + + /** + * Copying of objects using this copy constructor is allowed. + * + * @since 2.0 + * + * @param[in] recordType An instance of %NdefRecordType + */ + NdefRecordType(const NdefRecordType& recordType); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~NdefRecordType(void); + + /** + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.0 + * + * @param[in] rhs An instance of %NdefRecordType + */ + NdefRecordType& operator =(const NdefRecordType& rhs); + + /** + * Compares the specified instance of an Object with the calling instance of %NdefRecordType. + * + * @since 2.0 + * + * @return @c true if the values match, @n + * else @c false + * @param[in] obj The Object to be compared + * @remarks The method returns @c false if the specified object is not an %NdefRecordType instance. @n + * Additionally, the comparison rules for the record type name are different depending on the Type + * Name Format (TNF) value, as follows: @n + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Type Name Format (TNF) valueThe comparison rule for the record type name
NDEF_TNF_WELL_KNOWNCompares a name, character by character in a case-sensitive manner
NDEF_TNF_MIME_MEDIA Compares a name, character by character in a case-insensitive manner until the first semi-colon (;) + * appears
NDEF_TNF_ABSOLUTE_URI The reserved characters must be percent encoded and the hexadecimal digits are normalized to upper-case + * letters. The URI scheme and host parts of the URI must be normalized to lower case. After this, the URIs + * are compared character by character in a case-sensitive manner.
NDEF_TNF_EXTERNAL Compares a name, character by character in a case-insensitive manner
NDEF_TNF_EMPTY | NDEF_TNF_UNKNOWN Both record type names must be empty
+ */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + * @remarks The two equal %NdefRecordType instances return the same hash value. + */ + virtual int GetHashCode(void) const; + + /** + * Gets the name format of this record type. + * + * @since 2.0 + * + * @return The name format of this record type + */ + NdefRecordTypeNameFormat GetNameFormat(void) const; + + /** + * Gets the name of this record type. + * + * @since 2.0 + * + * @return The name of this record type, @n + * else an empty string if the name format is NDEF_TNF_EMPTY or NDEF_TNF_UNKNOWN + * @remarks The returned name does not have the prefix @c "urn:nfc:wkt:" and @c "urn:nfc:ext:" defined by the + * NFC forum. + * In case of NDEF_TNF_ABSOLUTE_URI name format, this method returns the name in the same format as it + * is given in the constructor, that is, with or without percent encoding. The name consists of the + * characters encoded using the US_ASCII character set. + */ + Tizen::Base::String GetName(void) const; + + /** + * Sets the name of this record type. + * + * @since 2.0 + * + * @return An error code + * @param[in] name The name of this record type + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is not allowed if the name format is NDEF_TNF_EMPTY, + * NDEF_TNF_UNKNOWN, or NDEF_TNF_ALL. + * @exception E_INVALID_ENCODING_RANGE The specified input string contains the code points that are outside + * the bounds specified by the US_ASCII encoding scheme. + * @exception E_INVALID_FORMAT The specified format of the @c name is invalid as per the + * specifications defined for each type of the name format. + * @exception E_MAX_EXCEEDED The length of the name exceeds @c 256 characters. + * @remarks The input name must not have the prefix defined by the NFC forum such as @c "urn:nfc:wkt:" and + * @c "urn:nfc:ext:". + */ + result SetName(const Tizen::Base::String& name); + +private: + _NdefRecordTypeImpl* __pImpl; + + friend class _NdefRecordTypeImpl; + +}; // NdefRecordType + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NDEF_RECORD_TYPE_H_ diff --git a/inc/FNetNfcNdefTagConnection.h b/inc/FNetNfcNdefTagConnection.h new file mode 100644 index 0000000..17bc908 --- /dev/null +++ b/inc/FNetNfcNdefTagConnection.h @@ -0,0 +1,242 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefTagConnection.h + * @brief This is the header file for the %NdefTagConnection class. + * + * This header file contains the declarations of the %NdefTagConnection class. + */ + +#ifndef _FNET_NFC_NDEF_TAG_CONNECTION_H_ +#define _FNET_NFC_NDEF_TAG_CONNECTION_H_ + +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NdefTagConnectionImpl; +class NdefMessage; +class INdefTagConnectionListener; + +/** + * @class NdefTagConnection + * @brief This class represents the connection with an NFC tag that has the NDEF data. + * + * @since 2.0 + * + * The %NdefTagConnection class provides the mechanism to communicate with the tag that has NFC Data Exchange Format (NDEF) data and + * supports the NDEF message operations. @n + * This class can be derived from the TagConnection class. Use the IsNdefConnection() method to check the availability + * of the derivation. @n + * Use the Read() and Write() methods to read and write the NDEF data. After the completion of the read and write + * operations, the response is received by the INdefTagConnectionListener::OnNdefReadCompletedN() and + * INdefTagConnectionListener::OnNdefWriteCompleted() event handlers, respectively. + * + * For more information on the class features, see + * NFC Guide. + * + * The following example demonstrates how to use the %NdefTagConnection class. + * @code + * // MyClass.h + * #include + * + * class MyClass + * : public Tizen::Net::Nfc::INfcManagerEventListener + * , public Tizen::Net::Nfc::INfcTagDiscoveryEventListener + * , public Tizen::Net::Nfc::INdefTagConnectionListener + * { + * public: + * void WriteNdefMessageSample(void); + * virtual void OnNfcTagDetectedN(Tizen::Net::Nfc::TagConnection* pConnection); + * virtual void OnNfcTagLost(void); + * virtual void OnNdefWriteCompleted(result r); + * // Other methods are hidden for the sake of simplicity. + * + * private: + * Tizen::Net::Nfc::NfcManager* __pNfcManager; + * Tizen::Net::Nfc::NdefTagConnection* __pNdefConnection; + * }; + * + * // MyClass.cpp + * #include "MyClass.h" + * + * using namespace Tizen::Net::Nfc; + * + * MyClass::MyClass(void) + * : __pNfcManager(null) + * , __pNdefConnection(null) + * { + * __pNfcManager = new NfcManager(); + * } + * + * MyClass::~MyClass(void) + * { + * // Removes the tag discovery event listener for all the NDEF tag types + * __pNfcManager->RemoveTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL_NDEF_COMPATIBLE); + * + * delete __pNfcManager; + * } + * + * void + * MyClass::WriteNdefMessageSample(void) + * { + * // Creates NfcManager instance and registers the manager event listener + * __pNfcManager->Construct(*this); + * + * // Adds the tag discovery event listener for all the NDEF tag types + * __pNfcManager->AddTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL_NDEF_COMPATIBLE); + * } + * + * // This method is invoked when a new NDEF tag is detected + * void + * MyClass::OnNfcTagDetectedN(TagConnection* pConnection) + * { + * // Checks whether the connection supports NDEF operations, + * // but the evaluation result of the below code is always true in this example + * if (pConnection->IsNdefConnection()) + * { + * __pNdefConnection = dynamic_cast(pConnection); + * + * // Registers the NDEF tag connection listener + * __pNdefConnection->SetNdefTagConnectionListener(this); + * + * NdefMessage message; + * // Fills up the NdefMessage object here + * + * __pNdefConnection->Write(message); + * } + * } + * + * // This method is invoked when the target tag is lost + * void + * MyClass::OnNfcTagLost(void) + * { + * // The acquired NdefTagConnection should be deallocated + * delete __pNdefConnection; + * } + * + * // This method is invoked when the write request is completed + * void + * MyClass::OnNdefWriteCompleted(result r) + * { + * if (r == E_SUCCESS) + * { + * // Writing NdefMessage is successful + * } + * } + * @endcode + */ +class _OSP_EXPORT_ NdefTagConnection + : public TagConnection +{ +public: + /** + * Checks whether the connection supports the NDEF message operations. + * + * @since 2.0 + * + * @return @c true if the connection supports the NDEF message operations, @n + * else @c false + */ + virtual bool IsNdefConnection(void) const; + + /** + * Sets a listener for receiving the result of reading or writing on this NDEF tag connection. + * + * @since 2.0 + * + * @return An error code + * @param[in] pListener The listener to be added + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @remarks At the most, one event listener can be registered. If the input parameter is @c null, the listener + * that is currently registered gets unregistered. + */ + result SetNdefTagConnectionListener(INdefTagConnectionListener* pListener); + + /** + * Reads the NDEF data from the NDEF tag. + * + * @since 2.0 + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_IN_PROGRESS The read process is in progress. + * @exception E_CONNECTION_BUSY The connection is busy. Therefore, the method cannot process the read request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or it has failed. + * @exception E_SYSTEM A system error has occurred. + * @see INdefTagConnectionListener::OnNdefReadCompletedN() + */ + result Read(void); + + /** + * Writes the NDEF data to the NDEF tag. + * + * @since 2.0 + * + * @return An error code + * @param[in] message The NDEF message to be written to the target + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The input @c message is invalid. @n + * For example, it does not contain any NDEF records. + * @exception E_IN_PROGRESS The write process is in progress. + * @exception E_CONNECTION_BUSY The connection is busy. Therefore, the method cannot process the write request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or it has failed. + * @exception E_SYSTEM A system error has occurred. + * @see INdefTagConnectionListener::OnNdefWriteCompleted() + */ + result Write(const NdefMessage& message); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~NdefTagConnection(void); + +private: + NdefTagConnection(void); + + /* + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %NdefTagConnection + */ + NdefTagConnection(const NdefTagConnection& value); + + /* + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %NdefTagConnection + */ + NdefTagConnection& operator =(const NdefTagConnection& value); + +private: + _NdefTagConnectionImpl* __pNdefImpl; + + friend class _TagConnectionImpl; + friend class _NdefTagConnectionImpl; + +}; // NdefTagConnection + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NDEF_TAG_CONNECTION_H_ diff --git a/inc/FNetNfcNfcManager.h b/inc/FNetNfcNfcManager.h new file mode 100755 index 0000000..f8c609c --- /dev/null +++ b/inc/FNetNfcNfcManager.h @@ -0,0 +1,477 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNfcManager.h + * @brief This is the header file for the %NfcManager class. + * + * This header file contains the declarations of the %NfcManager class. + */ +#ifndef _FNET_NFC_NFC_MANAGER_H_ +#define _FNET_NFC_NFC_MANAGER_H_ + +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class INfcManagerEventListener; +class INfcTransactionEventListener; +class INfcTagDiscoveryEventListener; +class INdefMessageDiscoveryEventListener; +class INfcDeviceDiscoveryEventListener; +class NdefMessage; +class NdefRecordType; +class TagConnection; +class _NfcManagerImpl; + +/** + * @class NfcManager + * @brief This is the manager class for the NFC features. + * + * @since 2.0 + * + * The %NfcManager class is the manager class for NFC features that includes the methods for enabling and disabling the NFC feature of + * the device and the mechanism for establishing a connection with the detected tag. It is also used to detect the NFC + * tags and NDEF messages. @n + * There are two ways to get the TagConnection instance established with the detected tag. @n + * @li Use the INfcTagDiscoveryEventListener::OnNfcTagDetectedN() method that is invoked immediately when the target + * tag is detected. + * @li Invoke the GetCurrentTagConnectionN() method after the tag is detected. + * + * If the target tag is lost, the INfcTagDiscoveryEventListener::OnNfcTagLost() method is called and the old + * TagConnection instance becomes invalid. Therefore, the operations performed by the TagConnection class are not + * processed anymore. Moreover, the TagConnection instance cannot be used again even if the same tags are detected + * again by the device. + * + * For more information on the class features, see + * NFC Guide. + * + * The following example demonstrates how to use the %NfcManager class. + * + * @code + * // MyClass.h + * #include + * + * class MyClass + * : public Tizen::Net::Nfc::INfcManagerEventListener + * , public Tizen::Net::Nfc::INfcTagDiscoveryEventListener + * , public Tizen::Net::Nfc::INdefMessageDiscoveryEventListener + * { + * public: + * // The method declarations are hidden for the sake of simplicity + * + * private: + * Tizen::Net::Nfc::NfcManager* __pNfcManager; + * Tizen::Net::Nfc::TagConnection* __pConnection; + * }; + * + * // MyClass.cpp + * #include "MyClass.h" + * + * using namespace Tizen::Net::Nfc; + * + * MyClass::MyClass(void) + * : __pNfcManager(null) + * , __pConnection(null) + * { + * __pNfcManager = new NfcManager(); + * } + * + * MyClass::~MyClass(void) + * { + * // Removes the tag discovery event listener for all the NFC tag types + * __pNfcManager->RemoveTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL); + * // Removes the NDEF message discovery event listener for all the TNF types + * __pNfcManager->RemoveNdefMessageDiscoveryEventListener(*this, NdefRecordType(NDEF_TNF_ALL)); + * + * delete __pNfcManager; + * } + * + * void + * MyClass::DiscoverySample(void) + * { + * // Creates the NfcManager instance and registers the manager event listener + * __pNfcManager->Construct(*this); + * + * if (__pNfcManager->IsTagConnected()) + * { + * // This is the way to get the connection already established with the detected tag + * __pConnection = __pNfcManager->GetCurrentTagConnectionN(); + * + * // Performs connection operations here + * } + * + * // Adds the tag discovery event listener for all the NFC tag types + * // This is the method to establish the connection with tags that are detected hereafter + * __pNfcManager->AddTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ALL); + * + * // Adds the NDEF message discovery event listener for all the TNF types + * // This is the method to get NDEF messages that are detected hereafter + * __pNfcManager->AddNdefMessageDiscoveryEventListener(*this, NdefRecordType(NDEF_TNF_ALL)); + * } + * + * // This method is invoked when a new tag is detected + * void + * MyClass::OnNfcTagDetectedN(TagConnection* pConnection) + * { + * __pConnection = pConnection; + * + * // Performs connection operations here + * } + * + * // This method is invoked when the target tag is lost + * void + * MyClass::OnNfcTagLost(void) + * { + * // The acquired TagConnection should be deallocated + * delete __pConnection; + * } + * + * // This method is invoked when a new NDEF message is detected + * void + * MyClass::OnNdefMessageDetectedN(NdefMessage* pMessage) + * { + * // Manipulates the received message here + * + * // Deallocates the received NdefMessage + * pMessage->RemoveAllRecords(true); + * delete pMessage; + * } + * @endcode + */ +class _OSP_EXPORT_ NfcManager + : public Tizen::Base::Object +{ +public: + /** + * The object is not fully constructed after this constructor is called. @n + * For full construction, the Construct() method must be called right after calling this constructor. + * + * @since 2.0 + * + * @remarks After creating an instance of this class, the Construct() method must be called explicitly to + * initialize this instance. + * @see Construct() + */ + NfcManager(void); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~NfcManager(void); + + /** + * Initializes this instance of %NfcManager with the specified listener. + * + * @since 2.0 + * + * @return An error code + * @param[in] listener The %INfcManagerEventListener instance to be added + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_OPERATION The device does not support the NFC feature. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + result Construct(INfcManagerEventListener& listener); + + /** + * Activates the NFC feature of the device. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.admin + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_IN_PROGRESS The activation process is in progress. + * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified + * operation. @n + * For example, the NFC feature is already activated. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @see INfcManagerEventListener::OnNfcActivated() + */ + result Activate(void); + + /** + * Deactivates the NFC feature of the device. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.admin + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_IN_PROGRESS The deactivation process is in progress. + * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified + * operation. @n + * For example, the NFC feature is already deactivated. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @see INfcManagerEventListener::OnNfcDeactivated() + */ + result Deactivate(void); + + /** + * Checks whether the NFC feature is activated. + * + * @since 2.0 + * + * @return @c true if the NFC feature is activated, @n + * else @c false + */ + bool IsActivated(void) const; + + /** + * Checks whether the NFC tag is currently connected with the device. + * + * @since 2.0 + * + * @return @c true if the NFC tag is currently connected, @n + * else @c false + */ + bool IsTagConnected(void) const; + + /** + * Gets the tag connection with the currently detected tag. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.tag + * + * @return The tag connection with the currently detected tag, @n + * else @c null if no tag is connected or if the connection fails + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_STATE This instance is in an invalid state. @n + * For example, this instance has not been constructed as yet or the NFC + * feature is not activated. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or has failed. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @remarks The NdefTagConnection class can inherit the TagConnection class if the currently detected tag + * supports the NDEF operations. To check whether the TagConnection class is inherited, use the + * TagConnection::IsNdefConnection() method. + * The specific error code can be accessed using the GetLastResult() method. + */ + TagConnection* GetCurrentTagConnectionN(void) const; + + /** + * Adds the specified %INfcTagDiscoveryEventListener instance for the tag events with the specified tag type. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.tag + * + * @return An error code + * @param[in] listener The listener to be added + * @param[in] type The tag type for which the listener is added + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_ALREADY_EXIST The listener with the specified type is already added. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @remarks This method can be invoked several times with different Tizen::Net::Nfc::NfcTagType values for the + * same listener instance. In this case, the listener is called if the specified type of the target + * tag matches with any one of the registered type. + */ + result AddTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type); + + /** + * Removes the specified %INfcTagDiscoveryEventListener instance. @n + * The removed listener cannot listen to the events that are fired. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.tag + * + * @return An error code + * @param[in] listener The listener to be removed + * @param[in] type The tag type for which the listener is removed + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The listener with the specified type is not found. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + */ + result RemoveTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type); + + /** + * Adds the specified %INdefMessageDiscoveryEventListener instance for the events related to an NDEF message that + * includes the NDEF record with the specified type. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.common + * + * @return An error code + * @param[in] listener The listener to be added + * @param[in] type The type of the NDEF record for which the listener is added + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. @n + * For example, the name of the record type is an empty string if the name + * format is NDEF_TNF_WELL_KNOWN, NDEF_TNF_MIME_MEDIA, NDEF_TNF_ABSOLUTE_URI, + * or NDEF_TNF_EXTERNAL. + * @exception E_OBJ_ALREADY_EXIST The listener with the specified type is already added. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @remarks This method can be invoked several times with different NdefRecordType values for the same listener + * instance. In this case, the listener is called if the record type in the detected NDEF records + * matches with one of the registered types. + * In case of the MIME %Media type as Type Name Format (TNF), asterisks can be used in the type name + * for wildcard matching, such as @htmlonly "image/*" @endhtmlonly. + */ + result AddNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, const NdefRecordType& type); + + /** + * Removes the specified %INdefMessageDiscoveryEventListener instance. @n + * The removed listener cannot listen to the events that are fired. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.common + * + * @return An error code + * @param[in] listener The listener to be removed + * @param[in] type The type of the NDEF record for which the listener is removed + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. @n + * For example, the name of the record type is an empty string if the name + * format is NDEF_TNF_WELL_KNOWN, NDEF_TNF_MIME_MEDIA, NDEF_TNF_ABSOLUTE_URI, + * or NDEF_TNF_EXTERNAL. + * @exception E_OBJ_NOT_FOUND The listener with the specified type is not found. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + */ + result RemoveNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, const NdefRecordType& type); + + /** + * Adds the specified %INfcDeviceDiscoveryEventListener instance for the device discovery events. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.p2p + * + * @return An error code + * @param[in] listener The listener to be added + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_ALREADY_EXIST The listener was already added. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + */ + result AddDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener); + + /** + * Removes the specified %INfcDeviceDiscoveryEventListener instance. @n + * The removed listener cannot listen to the events that are fired. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.p2p + * + * @return An error code + * @param[in] listener The listener to be removed + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + */ + result RemoveDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener); + + /** + * Checks whether peer device has been detected. + * + * @since 2.0 + * + * @return @c true if peer device has been detected, @n + * else @c false + */ + bool IsDeviceDetected(void) const; + + + /** + * Gets the NDEF message cached when the tag is detected. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.common + * + * @return The cached %NdefMessage instance, @n + * else @c null if the method is not successful + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_OPERATION The method has failed because the device does not support the NFC feature. + * @exception E_ILLEGAL_ACCESS This operation is not allowed because the application is not launched by + * Conditional %App Launch. + * @exception E_INVALID_FORMAT The cached data cannot be converted to the NDEF message. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @remarks This method is available only to the application that is launched by Conditional %App Launch until + * the application is terminated or another tag is detected. + * The input NdefMessage instance should be deleted by the application after it is used, even outside + * this method. The NdefMessage::RemoveAllRecords() method should be called with @c true as the input + * value immediately before the NdefMessage instance is deleted. + * The specific error code can be accessed using the GetLastResult() method. + * @see + * The Conditional NFC App Launch guide + * @see Tizen::App::AppManager::RegisterAppLaunch + */ + static NdefMessage* GetCachedNdefMessageN(void); + + /** + * Enables or disables the Conditional NFC %App Launch pop-up. @n + * The pop-up includes all kinds of UI components that the system raises about NFC as well as a pop-up for + * selecting the launching application when a tag is detected. + * + * @since 2.0 + * @privilege %http://tizen.org/privilege/nfc.common + * + * @return An error code + * @param[in] enable Set to @c true to enable the Conditional NFC %App Launch pop-up, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_UNSUPPORTED_OPERATION The method has failed because the device does not support the NFC feature. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_SYSTEM A system error has occurred. + * @remarks Note that this method is used to enable or disable the launch pop-up when the application is in the + * foreground. Although the application disables the launch pop-up by invoking this method, it is + * automatically enabled when the application goes to the background. The launch pop-up is enabled by + * default. + * @see + * The Conditional NFC App Launch guide + */ + static result SetLaunchPopupEnabled(bool enable); + +private: + /* + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %NfcManager + */ + NfcManager(const NfcManager& value); + + /* + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %NfcManager + */ + NfcManager& operator =(const NfcManager& value); + +private: + _NfcManagerImpl* __pImpl; + + friend class _NfcManagerImpl; +}; // NfcManager + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NFC_MANAGER_H_ diff --git a/inc/FNetNfcNfcTag.h b/inc/FNetNfcNfcTag.h new file mode 100644 index 0000000..b267003 --- /dev/null +++ b/inc/FNetNfcNfcTag.h @@ -0,0 +1,136 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNfcTag.h + * @brief This is the header file for the %NfcTag class. + * + * This header file contains the declarations of the %NfcTag class. + */ + +#ifndef _FNET_NFC_NFC_TAG_H_ +#define _FNET_NFC_NFC_TAG_H_ + +#include +#include +#include + +namespace Tizen { namespace Base +{ +class ByteBuffer; +namespace Collection +{ +template class IListT; +} +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NfcTagImpl; + +/** + * @class NfcTag + * @brief This class represents the NFC target tag. + * + * @since 2.0 + * + * The %NfcTag class provides information about the detected NFC tag. @n + * This class has multiple tag types for the target tag. For example, the GetTagTypeList() method returns a list of tag + * types that include NFC_TAG_TYPE_MIFARE_UL and NFC_TAG_TYPE_FORUM_TYPE_2, because the tag is a Mifare Ultralight tag + * and it is also an NFC Forum tag type 2. + * + * For more information on the class features, see + * NFC Guide. + */ +class _OSP_EXPORT_ NfcTag + : public Tizen::Base::Object +{ +public: + /** + * Gets the list of the tag types. + * + * @since 2.0 + * + * @return The list of the tag types + * @remarks The return list includes single or multiple tags. For example, if the target tag is Mifare + * Ultralight tag type and the NFC Forum tag 2 type, the list includes NFC_TAG_TYPE_MIFARE_UL and + * NFC_TAG_TYPE_FORUM_TYPE_2. + */ + const Tizen::Base::Collection::IListT * GetTagTypeList(void) const; + + /** + * Checks whether the tag has the specified tag type. + * + * @since 2.0 + * + * @return @c true if the tag has the specified tag type, @n + * else @c false + * @param[in] type The tag type to be checked + */ + bool HasTagType(NfcTagType type) const; + + /** + * Gets the ID of the tag. + * + * @since 2.0 + * + * @return The ID of the tag, @n + * else @c null if the tag has no ID + * @remarks Most tags have an unique ID (UID) or a random ID (RID) that is generated every time when they are + * discovered. Some tags, however, do not have any ID. + */ + const Tizen::Base::ByteBuffer* GetId(void) const; + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~NfcTag(void); + +private: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + */ + NfcTag(void); + + /* + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %NfcTag + */ + NfcTag(const NfcTag& value); + + /* + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %NfcTag + */ + NfcTag& operator =(const NfcTag& value); + +private: + _NfcTagImpl* __pImpl; + + friend class _NfcTagImpl; + +}; // NfcTag + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NFC_TAG_H_ diff --git a/inc/FNetNfcNfcTypes.h b/inc/FNetNfcNfcTypes.h new file mode 100644 index 0000000..d4c8c61 --- /dev/null +++ b/inc/FNetNfcNfcTypes.h @@ -0,0 +1,99 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @file FNetNfcNfcTypes.h +* @brief This is the header file for defining types in the %Nfc namespace. +* +* This header file contains the definition of common types and enumerators for the %NFC features. +*/ +#ifndef _FNET_NFC_NFC_TYPES_H_ +#define _FNET_NFC_NFC_TYPES_H_ + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @enum NfcTagType + * + * Defines the types of the NFC tag. + * + * @since 2.0 + */ +enum NfcTagType +{ + NFC_TAG_TYPE_UNKNOWN = 0x00, /**< The unknown tag type + * @remarks This type should not be used for the event filtering + * purpose as the input argument of + * NfcManager::AddTagDiscoveryEventListener(). + */ + NFC_TAG_TYPE_ISO14443_3A, /**< The ISO14443 Part 3A tag type @n + * For example, the Mifare UL, the Mifare Classic, and the Mifare DESFire + * tags belong to this type. + */ + NFC_TAG_TYPE_ISO14443_3B, /**< The ISO14443 Part 3B tag type @n + * For example, the Picopass 2K/32K tags belong to this type. + */ + NFC_TAG_TYPE_FELICA, /**< The FeliCa tag type */ + NFC_TAG_TYPE_ISO15693, /**< The ISO15693 general RFID tag type */ + NFC_TAG_TYPE_TOPAZ_JEWEL, /**< The Topaz/Jewel tag type */ + NFC_TAG_TYPE_MIFARE_UL, /**< The Mifare Ultralight/Ultralight C tag type */ + NFC_TAG_TYPE_MIFARE_CLASSIC, /**< The Mifare Classic (1K/4K) tag type */ + NFC_TAG_TYPE_ISO14443_4, /**< The ISO14443 Part 4 tag type @n + * For example, the Mifare DESFire tag belongs to this type. + */ + NFC_TAG_TYPE_FORUM_TYPE_1, /**< The NFC forum type 1 */ + NFC_TAG_TYPE_FORUM_TYPE_2, /**< The NFC forum type 2 */ + NFC_TAG_TYPE_FORUM_TYPE_3, /**< The NFC forum type 3 */ + NFC_TAG_TYPE_FORUM_TYPE_4, /**< The NFC forum type 4 */ + NFC_TAG_TYPE_ALL_NDEF_COMPATIBLE = 0xfe, /**< The all NDEF compatible tag type + * @remarks This type should be used only for event filtering as the + * input argument of + * NfcManager::AddTagDiscoveryEventListener(). + */ + NFC_TAG_TYPE_ALL = 0xff, /**< The all tag type + * @remarks This type should be used only for event filtering as the + * input argument of + * NfcManager::AddTagDiscoveryEventListener(). + */ +}; + +/** + * @enum NdefRecordTypeNameFormat + * + * Defines the type name formats of the NDEF record. + * + * @since 2.0 + */ +// Refer to NFCForum-TS-NDEF_1.0 +enum NdefRecordTypeNameFormat +{ + NDEF_TNF_EMPTY = 0x00, /**< The empty record type */ + NDEF_TNF_WELL_KNOWN = 0x01, /**< The NFC forum defined record type */ + NDEF_TNF_MIME_MEDIA = 0x02, /**< The RFC2046 MIME media record type */ + NDEF_TNF_ABSOLUTE_URI = 0x03, /**< The absolute URI record type */ + NDEF_TNF_EXTERNAL = 0x04, /**< The user-defined record type (application specific) */ + NDEF_TNF_UNKNOWN = 0x05, /**< The unknown record type */ + NDEF_TNF_ALL = 0xff, /**< The all record type + * @remarks This type should be used only for event filtering as the + * input argument of + * NfcManager::AddNdefMessageDiscoveryEventListener(). + */ +}; + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_NFC_TYPES_H_ diff --git a/inc/FNetNfcTagConnection.h b/inc/FNetNfcTagConnection.h new file mode 100644 index 0000000..9d8ea55 --- /dev/null +++ b/inc/FNetNfcTagConnection.h @@ -0,0 +1,284 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcTagConnection.h + * @brief This is the header file for the %TagConnection class. + * + * This header file contains the declarations of the %TagConnection class. + */ + +#ifndef _FNET_NFC_TAG_CONNECTION_H_ +#define _FNET_NFC_TAG_CONNECTION_H_ + +#include +#include + +namespace Tizen { namespace Base +{ +class ByteBuffer; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NfcTag; +class _TagConnectionImpl; +class ITagConnectionListener; + +/** + * @class TagConnection + * @brief This class represents the connection with an NFC tag. It provides the mechanism to communicate with the NFC + * tag through ISO14443 or a general Radio Frequency Identification (RFID) manner. + * + * @since 2.0 + * + * The %TagConnection class represents the connection with an NFC tag. It provides the mechanism to communicate with the NFC tag + * through ISO14443 or a general Radio Frequency Identification (RFID) manner. @n + * The class has an NfcTag instance that represents the target tag. This class can be inherited by the + * NdefTagConnection class if the target tag supports the NFC Data Exchange Format (NDEF) operations. + * + * For more information on the class features, see + * NFC Guide. + * + * The following example demonstrates how to use the %TagConnection class. + * + * @code + * // MyClass.h + * #include + * + * class MyClass + * : public Tizen::Net::Nfc::INfcManagerEventListener + * , public Tizen::Net::Nfc::INfcTagDiscoveryEventListener + * , public Tizen::Net::Nfc::ITagConnectionListener + * { + * public: + * // Method declarations are hidden for the sake of simplicity. + * + * private: + * Tizen::Net::Nfc::NfcManager* __pNfcManager; + * Tizen::Net::Nfc::TagConnection* __pConnection; + * }; + * + * // MyClass.cpp + * #include "MyClass.h" + * + * using namespace Tizen::Net::Nfc; + * + * MyClass::MyClass(void) + * : __pNfcManager(null) + * , __pConnection(null) + * { + * __pNfcManager = new NfcManager(); + * } + * + * MyClass::~MyClass(void) + * { + * // Removes the tag discovery event listener for the ISO14443-4 tag type. + * __pNfcManager->RemoveTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ISO14443_4); + * + * delete __pNfcManager; + * } + * + * void + * MyClass::SendApduCommandSample(void) + * { + * // Creates an instance of NfcManager and registers the manager event listener + * __pNfcManager->Construct(*this); + * + * // Adds the tag discovery event listener for the ISO14443-4 tag type + * __pNfcManager->AddTagDiscoveryEventListener(*this, NFC_TAG_TYPE_ISO14443_4); + * } + * + * // This method is invoked when a new ISO14443-4 tag like a Mifare DESFire is detected + * void + * MyClass::OnNfcTagDetectedN(TagConnection* pConnection) + * { + * // Checks whether the connection supports ISO14443-4, + * // but the evaluation result of the below code is always true in this example + * if (pConnection->GetTargetTag()->HasTagType(NFC_TAG_TYPE_ISO14443_4)) + * { + * __pConnection = pConnection; + * + * // Registers the tag connection listener + * __pConnection->SetTagConnectionListener(this); + * + * Tizen::Base::ByteBuffer command; + * // Makes an APDU(ISO7816-4) command here + * + * __pConnection->SendCommand(command); + * } + * } + * + * // This method is invoked when the target tag is lost + * void + * MyClass::OnNfcTagLost(void) + * { + * // The acquired TagConnection should be deallocated + * delete __pConnection; + * } + * + * // This method is invoked when the response of the command is received + * void + * MyClass::OnNfcResponseReceivedN(Tizen::Base::ByteBuffer* pResponse, result r) + * { + * if (r == E_SUCCESS) + * { + * // Uses the response data here + * + * // Deallocates the response data + * delete pResponse; + * } + * } + * @endcode + */ +class _OSP_EXPORT_ TagConnection + : public Tizen::Base::Object +{ +public: + /** + * Checks whether the connection supports the NDEF message operations. + * + * @since 2.0 + * + * @return @c true if the connection supports the NDEF message operations, @n + * else @c false + */ + virtual bool IsNdefConnection(void) const; + + /** + * Gets the target tag object with which this connection is established. + * + * @since 2.0 + * + * @return The tag object + */ + const NfcTag* GetTargetTag(void) const; + + /** + * Sets a listener for receiving the response of the command sent on this tag connection. + * + * @since 2.0 + * + * @return An error code + * @param[in] pListener The listener to be added + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @remarks Only one event listener can be registered. If the input parameter is @c null, the listener that is + * already registered gets unregistered. + */ + result SetTagConnectionListener(ITagConnectionListener* pListener); + + /** + * Sends the specified command to the target tag. + * + * @since 2.0 + * + * @return An error code + * @param[in] command The command to be sent + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The input @c command is invalid. + * @exception E_IN_PROGRESS The previous send request is in progress. + * @exception E_CONNECTION_BUSY The connection is busy. Therefore, the method cannot process the send request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or it has failed. + * @exception E_SYSTEM A system error has occurred. + * @see ITagConnectionListener::OnNfcResponseReceivedN() + */ + result SendCommand(const Tizen::Base::ByteBuffer& command); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~TagConnection(void); + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, + // and consistency-related issues in the application. + // + // This is the default constructor for this class. + // + // @since 2.0 + // + TagConnection(void); + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, + // and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void TagConnection_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, + // and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void TagConnection_Reserved2(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, + // and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void TagConnection_Reserved3(void) {} + +private: + /* + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %TagConnection + */ + TagConnection(const TagConnection& value); + + /* + * The implementation of this copy assignment operator is intentionally blank + * and declared as private to prohibit copying of objects. + * + * @param[in] value An instance of %TagConnection + */ + TagConnection& operator =(const TagConnection& value); + +protected: + // + // This variable is for internal use only. Using this variable can cause behavioral, + // security-related, and consistency-related issues in the application. + // + // The point for indicating the implementation object. + // + // @since 2.0 + // + _TagConnectionImpl* _pImpl; + + friend class _TagConnectionImpl; + +}; // TagConnection + +} } } // Tizen::Net::Nfc + +#endif // _FNET_NFC_TAG_CONNECTION_H_ diff --git a/osp-nfc.manifest b/osp-nfc.manifest new file mode 100644 index 0000000..ae3e6f7 --- /dev/null +++ b/osp-nfc.manifest @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/osp-nfc.pc.in b/osp-nfc.pc.in new file mode 100755 index 0000000..eb6c3b7 --- /dev/null +++ b/osp-nfc.pc.in @@ -0,0 +1,14 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib/osp +includedir=/usr/include/osp + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} + diff --git a/packaging/osp-nfc.spec b/packaging/osp-nfc.spec new file mode 100755 index 0000000..1f2c546 --- /dev/null +++ b/packaging/osp-nfc.spec @@ -0,0 +1,92 @@ +%define debug_package %{nil} +%define __strip /bin/true + +Name: osp-nfc +Summary: osp nfc library +Version: 1.2.0.0 +Release: 2 +Group: System/Libraries +License: TO_BE/FILLED_IN +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(chromium) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(capi-system-device) +BuildRequires: pkgconfig(capi-network-nfc) +BuildRequires: pkgconfig(osp-appfw) +BuildRequires: osp-appfw-internal-devel +BuildRequires: pkgconfig(osp-net) +BuildRequires: osp-net-internal-devel + +# runtime requires +Requires: osp-appfw +Requires: osp-net + +%description +osp nfc library + +%package devel +Summary: osp nfc library (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel +osp nfc library (DEV) + +%package internal-devel +Summary: osp nfc library (Internal) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description internal-devel +osp nfc library (Internal-DEV) + +%package debug +Summary: osp nfc library (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description debug +osp nfc library (DEV) + +%prep +%setup -q + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%ifarch %{ix86} +CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%else +CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%endif + +# Call make instruction with smp support +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license +cp %{_builddir}/%{name}-%{version}/LICENSE.Flora %{buildroot}/usr/share/license/%{name} +cat %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 >> %{buildroot}/usr/share/license/%{name} + +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest osp-nfc.manifest +/usr/share/license/%{name} +%{_libdir}/osp/*.so* + +%files devel +%{_includedir}/osp/*.h +%{_libdir}/pkgconfig/osp-nfc.pc + +%files internal-devel +%{_includedir}/osp/net/*.h + +%files debug +%{_libdir}/osp/debug/*.so* diff --git a/src/FNetNfcNdefMessage.cpp b/src/FNetNfcNdefMessage.cpp new file mode 100644 index 0000000..6d9276c --- /dev/null +++ b/src/FNetNfcNdefMessage.cpp @@ -0,0 +1,160 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefMessage.cpp +// @brief This is the implementation file for NdefMessage class. +// +// This file contains the implementation of NdefMessage class. +// + +#include +#include +#include +#include +#include +#include "FNetNfc_NdefMessageImpl.h" +#include "FNetNfc_NdefMessageUtil.h" + +using namespace Tizen::Net::Nfc; + +namespace Tizen { namespace Net { namespace Nfc +{ + +NdefMessage::NdefMessage(void) + : __pImpl(null) +{ + __pImpl = new (std::nothrow) _NdefMessageImpl; + SysTryReturnVoidResult(NID_NET_NFC, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + +} + +NdefMessage::NdefMessage(const NdefMessage& value) + : __pImpl(null) +{ + __pImpl = new (std::nothrow) _NdefMessageImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_NET_NFC, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); +} + +NdefMessage::~NdefMessage(void) +{ + if (__pImpl != null) + { + delete __pImpl; + } +} + +bool +NdefMessage::Equals(const Tizen::Base::Object& obj) const +{ + const NdefMessage* pOther = dynamic_cast (&obj); + + if (pOther == null) + { + return false; + } + + if (pOther == this) + { + return true; + } + + return(__pImpl->Equals(*(pOther->__pImpl))); +} + +int +NdefMessage::GetHashCode() const +{ + return __pImpl->GetHashCode(); +} + +result +NdefMessage::AppendRecord(const NdefRecord& record) +{ + return __pImpl->AppendRecord(record); +} + +int +NdefMessage::GetRecordsCount() const +{ + return __pImpl->GetRecordsCount(); +} + +NdefRecord* +NdefMessage::GetRecordAt(int index) const +{ + return __pImpl->GetRecordAt(index); +} + +NdefRecord* +NdefMessage::GetRecord(const Tizen::Base::String& payloadId) const +{ + return __pImpl->GetRecord(payloadId); +} + +result +NdefMessage::IndexOf(const NdefRecord& record, int& index) const +{ + return __pImpl->IndexOf(record, index); +} + +result +NdefMessage::InsertRecordAt(const NdefRecord& record, int index) +{ + return __pImpl->InsertRecordAt(record, index); +} + +result +NdefMessage::RemoveRecordAt(int index, bool deallocate) +{ + return __pImpl->RemoveRecordAt(index, deallocate); +} + +result +NdefMessage::SetRecordAt(const NdefRecord& record, int index, bool deallocate) +{ + return __pImpl->SetRecordAt(record, index, deallocate); +} + +void +NdefMessage::RemoveAllRecords(bool deallocate) +{ + return __pImpl->RemoveAllRecords(deallocate); +} + +Tizen::Base::ByteBuffer* +NdefMessage::ToByteBufferN() const +{ + return __pImpl->ToByteBufferN(*this); +} + +NdefMessage* +NdefMessage::GetInstanceN(const Tizen::Base::ByteBuffer& buffer) +{ + return _NdefMessageUtil::ToNdefMessageN(buffer); +} + +NdefMessage& +NdefMessage::operator =(const NdefMessage& rhs) +{ + if (this != &rhs) + { + *__pImpl = *rhs.__pImpl; + } + + return *this; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfcNdefPushManager.cpp b/src/FNetNfcNdefPushManager.cpp new file mode 100644 index 0000000..68ad930 --- /dev/null +++ b/src/FNetNfcNdefPushManager.cpp @@ -0,0 +1,126 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefPushManager.cpp +// @brief This is the implementation file for %NdefPushManager class. +// +// This file contains the implementation of %NdefPushManager class. +// + +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NdefPushManagerImpl.h" + +using namespace Tizen::System; +using namespace Tizen::Security; + +namespace Tizen { namespace Net { namespace Nfc +{ + +NdefPushManager::NdefPushManager(void) + : __pImpl(null) +{ + __pImpl = new (std::nothrow) _NdefPushManagerImpl; + SysTryReturnVoidResult(NID_NET_NFC, __pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); +} + +NdefPushManager::~NdefPushManager(void) +{ + delete __pImpl; +} + +result +NdefPushManager::SetNdefPushManagerListener(INdefPushManagerListener* pListener) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_P2P); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + r = __pImpl->SetNdefPushManagerListener(pListener); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "[%s] Failed to add the callback to _NfcSystemAdapter.", GetErrorMessage(r)); + + return r; +} + +result +NdefPushManager::Push(const NdefMessage& message) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_NET_NFC, message.GetRecordsCount() != 0, E_INVALID_ARG, E_INVALID_ARG, + "Invalid argument is used. NDEF message does not contain any NDEF records"); + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_P2P); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + r = __pImpl->Push(message); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "[%s] Failed to push NDEF message.", GetErrorMessage(r)); + + return r; +} + +result +NdefPushManager::RegisterNdefPushMessage(const NdefMessage& message, const Tizen::Base::String& description) +{ + result r = E_SUCCESS; + bool isNfcSupported = false; + + r = _SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/nfc", isNfcSupported); + TryReturn((r == E_SUCCESS) && (isNfcSupported == true), E_UNSUPPORTED_OPERATION, + "[E_UNSUPPORTED_OPERATION] NFC is not supported."); + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_P2P); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + return _NdefPushManagerImpl::RegisterNdefPushMessage(message, description); +} + +result +NdefPushManager::UnregisterNdefPushMessage(void) +{ + result r = E_SUCCESS; + bool isNfcSupported = false; + + r = _SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/nfc", isNfcSupported); + TryReturn((r == E_SUCCESS) && (isNfcSupported == true), E_UNSUPPORTED_OPERATION, + "[E_UNSUPPORTED_OPERATION] NFC is not supported."); + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_P2P); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + return _NdefPushManagerImpl::UnregisterNdefPushMessage(); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfcNdefRecord.cpp b/src/FNetNfcNdefRecord.cpp new file mode 100644 index 0000000..a5c0a94 --- /dev/null +++ b/src/FNetNfcNdefRecord.cpp @@ -0,0 +1,124 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefRecord.cpp +// @brief This is the implementation file for NdefRecord class. +// +// This file contains the implementation of NdefRecord class. +// + +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NdefRecordImpl.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +NdefRecord::NdefRecord(const NdefRecord& value) + : __pImpl(null) +{ + __pImpl = new (std::nothrow) _NdefRecordImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_NET_NFC, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); +} + +NdefRecord::NdefRecord(const NdefRecordType& recordType) + : __pImpl(null) +{ + __pImpl = new (std::nothrow) _NdefRecordImpl(recordType); + SysTryReturnVoidResult(NID_NET_NFC, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); +} + +NdefRecord::~NdefRecord(void) +{ + delete __pImpl; +} + +bool +NdefRecord::Equals(const Tizen::Base::Object& obj) const +{ + const NdefRecord* pOther = dynamic_cast (&obj); + + if (pOther == null) + { + return false; + } + + if (pOther == this) + { + return true; + } + + return(__pImpl->Equals(*(pOther->__pImpl))); +} + +int +NdefRecord::GetHashCode() const +{ + return __pImpl->GetHashCode(); +} + +Tizen::Base::String +NdefRecord::GetPayloadId() const +{ + return __pImpl->GetPayloadId(); +} + +Tizen::Base::ByteBuffer* +NdefRecord::GetPayload() const +{ + return __pImpl->GetPayload(); +} + +NdefRecordType +NdefRecord::GetRecordType() const +{ + return __pImpl->GetRecordType(); +} + +result +NdefRecord::SetRecordType(NdefRecordType& type) +{ + return __pImpl->SetRecordType(type); +} + +result +NdefRecord::SetPayloadId(const Tizen::Base::String& id) +{ + return __pImpl->SetPayloadId(id); +} + +result +NdefRecord::SetPayload(const Tizen::Base::ByteBuffer& payload) +{ + return __pImpl->SetPayload(payload); +} + +NdefRecord& +NdefRecord::operator =(const NdefRecord& rhs) +{ + if (this != &rhs) + { + *__pImpl = *rhs.__pImpl; + } + + return *this; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfcNdefRecordType.cpp b/src/FNetNfcNdefRecordType.cpp new file mode 100644 index 0000000..c1edaa1 --- /dev/null +++ b/src/FNetNfcNdefRecordType.cpp @@ -0,0 +1,99 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefRecordType.cpp +// @brief This is the implementation file for NdefRecordType class. +// +// This file contains the implementation of NdefRecordType class. +// + +#include +#include +#include +#include +#include "FNetNfc_NdefRecordTypeImpl.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +const wchar_t NFC_NDEF_RTD_SMART_POSTER[] = L"Sp"; +const wchar_t NFC_NDEF_RTD_TEXT[] = L"T"; +const wchar_t NFC_NDEF_RTD_URI[] = L"U"; + +NdefRecordType::NdefRecordType(NdefRecordTypeNameFormat format) + : __pImpl(null) +{ + __pImpl = new (std::nothrow) _NdefRecordTypeImpl(format); + SysTryReturnVoidResult(NID_NET_NFC, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); +} + +NdefRecordType::NdefRecordType(const NdefRecordType& recordType) + : __pImpl(null) +{ + if (recordType.__pImpl != null) + { + __pImpl = new (std::nothrow) _NdefRecordTypeImpl(*recordType.__pImpl); + SysTryReturnVoidResult(NID_NET_NFC, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + } +} + +NdefRecordType::~NdefRecordType(void) +{ + delete __pImpl; +} + +NdefRecordType& +NdefRecordType::operator =(const NdefRecordType& rhs) +{ + if (this != &rhs) + { + *__pImpl = *rhs.__pImpl; + } + + return *this; +} + +bool +NdefRecordType::Equals(const Tizen::Base::Object& obj) const +{ + return __pImpl->Equals(obj); +} + +int +NdefRecordType::GetHashCode() const +{ + return __pImpl->GetHashCode(); +} + +NdefRecordTypeNameFormat +NdefRecordType::GetNameFormat(void) const +{ + return __pImpl->GetNameFormat(); +} + +Tizen::Base::String +NdefRecordType::GetName(void) const +{ + return __pImpl->GetName(); +} + +result +NdefRecordType::SetName(const Tizen::Base::String& name) +{ + return __pImpl->SetName(name); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfcNdefTagConnection.cpp b/src/FNetNfcNdefTagConnection.cpp new file mode 100644 index 0000000..353a011 --- /dev/null +++ b/src/FNetNfcNdefTagConnection.cpp @@ -0,0 +1,71 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefTagConnection.cpp +// @brief This is the implementation file for NdefTagConnection class. +// +// This file contains the implementation of NdefTagConnection class. +// + +#include +#include +#include +#include +#include "FNetNfc_TagConnectionImpl.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +NdefTagConnection::NdefTagConnection(void) + : __pNdefImpl(null) +{ + // This class uses not __pNdefImpl but _pImpl of its parent class, TagConnection. + // __pNdefImpl, however, is just reserved for later use. + + // NOTICE: + // This constructor is a private method, so it must be called by only _TagConnectionImpl class which is a friend class of this class. + // _TagConnectionImpl class definitely assigns its instance to _pImpl after generating NdefTagConnection instance. +} + +NdefTagConnection::~NdefTagConnection(void) +{ +} + +bool +NdefTagConnection::IsNdefConnection(void) const +{ + return true; +} + +result +NdefTagConnection::SetNdefTagConnectionListener(INdefTagConnectionListener* pListener) +{ + return _pImpl->SetNdefTagConnectionListener(pListener); +} + +result +NdefTagConnection::Read(void) +{ + return _pImpl->Read(); +} + +result +NdefTagConnection::Write(const NdefMessage& message) +{ + return _pImpl->Write(message); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfcNfcManager.cpp b/src/FNetNfcNfcManager.cpp new file mode 100644 index 0000000..a4b86ef --- /dev/null +++ b/src/FNetNfcNfcManager.cpp @@ -0,0 +1,309 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNfcManager.cpp +// @brief This is the implementation file for NfcManager class. +// +// This file contains the implementation of NfcManager class. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NfcManagerImpl.h" +#include "FNetNfc_NdefMessageUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; +using namespace Tizen::Base::Collection; +using namespace Tizen::System; +using namespace Tizen::Security; + +namespace Tizen { namespace Net { namespace Nfc +{ + +NfcManager::NfcManager(void) + : __pImpl(null) +{ +} + +NfcManager::~NfcManager(void) +{ + delete __pImpl; +} + +result +NfcManager::Construct(INfcManagerEventListener& listener) +{ + result r = E_SUCCESS; + bool isNfcSupported = false; + + r = _SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/nfc", isNfcSupported); + TryReturn((r == E_SUCCESS) && (isNfcSupported == true), E_UNSUPPORTED_OPERATION, + "[E_UNSUPPORTED_OPERATION] NFC is not supported."); + + SysAssertf(__pImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + + + __pImpl = new (std::nothrow) _NfcManagerImpl; + + TryReturn(__pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Creating __pImpl instance failed."); + + r = __pImpl->Construct(listener); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + + if (r != E_SUCCESS) + { + delete __pImpl; + __pImpl = null; + + SysLogException(NID_NET_NFC, r, + "[%s] Internal error occurred on construction of a NfcManager instance.", GetErrorMessage(r)); + } + + return r; +} + +result +NfcManager::Activate(void) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_ADMIN); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + + return __pImpl->Activate(); +} + +result +NfcManager::Deactivate(void) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_ADMIN); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->Deactivate(); +} + +bool +NfcManager::IsActivated(void) const +{ + SysTryReturn(NID_NET_NFC, __pImpl != null, false, E_SYSTEM, "NfcManager is not constructed."); + + return __pImpl->IsActivated(); +} + +bool +NfcManager::IsTagConnected(void) const +{ + SysTryReturn(NID_NET_NFC, __pImpl != null, false, E_SYSTEM, "NfcManager is not constructed."); + + return __pImpl->IsTagConnected(); +} + +TagConnection* +NfcManager::GetCurrentTagConnectionN(void) const +{ + result r = E_SUCCESS; + + ClearLastResult(); + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_TAG); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + TryCatch(r == E_SUCCESS, , "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r)); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->GetCurrentTagConnectionN(); + + CATCH: + SetLastResult(r); + + return null; +} + +NdefMessage* +NfcManager::GetCachedNdefMessageN(void) +{ + result r = E_SUCCESS; + bool isNfcSupported = false; + + ClearLastResult(); + + r = _SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/nfc", isNfcSupported); + TryCatch((r == E_SUCCESS) && (isNfcSupported == true), r = E_UNSUPPORTED_OPERATION, + "[E_UNSUPPORTED_OPERATION] NFC is not supported."); + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_COMMON); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + TryCatch(r == E_SUCCESS, , "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r)); + + return _NfcManagerImpl::GetCachedNdefMessageN(); + +CATCH: + SetLastResult(r); + + return null; +} + +result +NfcManager::SetLaunchPopupEnabled(bool enable) +{ + result r = E_SUCCESS; + bool isNfcSupported = false; + + r = _SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/nfc", isNfcSupported); + TryReturn((r == E_SUCCESS) && (isNfcSupported == true), E_UNSUPPORTED_OPERATION, + "[E_UNSUPPORTED_OPERATION] NFC is not supported."); + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_COMMON); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + return _NfcManagerImpl::SetLaunchPopupEnabled(enable); +} + +result +NfcManager::AddTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_TAG); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->AddTagDiscoveryEventListener(listener, type); +} + +result +NfcManager::RemoveTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_TAG); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->RemoveTagDiscoveryEventListener(listener, type); +} + +result +NfcManager::AddNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, const NdefRecordType& type) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_COMMON); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->AddNdefMessageDiscoveryEventListener(listener, type); +} + +result +NfcManager::RemoveNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, + const NdefRecordType& type) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_COMMON); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->RemoveNdefMessageDiscoveryEventListener(listener, type); +} + + +result +NfcManager::AddDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_P2P); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->AddDeviceDiscoveryEventListener(listener); +} + +result +NfcManager::RemoveDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener) +{ + result r = E_SUCCESS; + + // Privilege check + r = _AccessController::CheckUserPrivilege(_PRV_NFC_P2P); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "The application does not have the privilege to call this method."); + + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->RemoveDeviceDiscoveryEventListener(listener); +} + +bool +NfcManager::IsDeviceDetected(void) const +{ + SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); + + return __pImpl->IsDeviceDetected(); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfcNfcTag.cpp b/src/FNetNfcNfcTag.cpp new file mode 100644 index 0000000..ff1a7ac --- /dev/null +++ b/src/FNetNfcNfcTag.cpp @@ -0,0 +1,62 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNfcTag.cpp +// @brief This is the implementation file for NfcTag class. +// +// This file contains the implementation of NfcTag class. +// + +#include +#include +#include +#include "FNetNfc_NfcTagImpl.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +NfcTag::NfcTag(void) + : __pImpl(null) +{ + // NOTICE: + // This constructor is a private method, so it must be called by only _NfcTagImpl class which is a friend class of this class. + // _NfcTagImpl class definitely assigns its instance to __pImpl after generating NfcTag instance. +} + +NfcTag::~NfcTag(void) +{ + delete __pImpl; +} + +const Tizen::Base::Collection::IListT * +NfcTag::GetTagTypeList(void) const +{ + return __pImpl->GetTagTypeList(); +} + +bool +NfcTag::HasTagType(NfcTagType type) const +{ + return __pImpl->HasTagType(type); +} + +const Tizen::Base::ByteBuffer* +NfcTag::GetId(void) const +{ + return __pImpl->GetId(); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfcTagConnection.cpp b/src/FNetNfcTagConnection.cpp new file mode 100644 index 0000000..f9ee354 --- /dev/null +++ b/src/FNetNfcTagConnection.cpp @@ -0,0 +1,70 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcTagConnection.cpp +// @brief This is the implementation file for TagConnection class. +// +// This file contains the implementation of TagConnection class. +// + +#include +#include +#include +#include +#include +#include "FNetNfc_TagConnectionImpl.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +TagConnection::TagConnection(void) + : _pImpl(null) +{ + // NOTICE: + // This constructor is a private method, so it must be called by only _TagConnectionImpl class which is a friend class of this class. + // _TagConnectionImpl class definitely assigns its instance to _pImpl after generating NdefTagConnection instance. +} + +TagConnection::~TagConnection(void) +{ + delete _pImpl; +} + +bool +TagConnection::IsNdefConnection(void) const +{ + return false; +} + +const NfcTag* +TagConnection::GetTargetTag(void) const +{ + return _pImpl->GetTargetTag(); +} + +result +TagConnection::SetTagConnectionListener(ITagConnectionListener* pListener) +{ + return _pImpl->SetTagConnectionListener(pListener); +} + +result +TagConnection::SendCommand(const Tizen::Base::ByteBuffer& command) +{ + return _pImpl->SendCommand(command); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefMessageDiscoveryEvent.cpp b/src/FNetNfc_NdefMessageDiscoveryEvent.cpp new file mode 100644 index 0000000..b061b9c --- /dev/null +++ b/src/FNetNfc_NdefMessageDiscoveryEvent.cpp @@ -0,0 +1,152 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefMessageDiscoveryEvent.cpp +// @brief This is the implementation file for _NdefMessageDiscoveryEvent class. +// +// This file contains the implementation of _NdefMessageDiscoveryEvent class. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NdefMessageDiscoveryEvent.h" +#include "FNetNfc_NdefMessageDiscoveryEventArg.h" +#include "FNetNfc_NdefMessageUtil.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefMessageDiscoveryEvent::_NdefMessageDiscoveryEvent(void) + : __listenerCount(0) +{ +} + +_NdefMessageDiscoveryEvent::~_NdefMessageDiscoveryEvent(void) +{ +} + +result +_NdefMessageDiscoveryEvent::Construct(void) +{ + return _Event::Initialize(); +} + +result +_NdefMessageDiscoveryEvent::AddListener(const Tizen::Base::Runtime::IEventListener& listener, bool calledByCallerThread) +{ + result r = E_SUCCESS; + + r = _Event::AddListener(listener, calledByCallerThread); + + if (r == E_SUCCESS) + { + __listenerCount++; + } + + return r; +} + +result +_NdefMessageDiscoveryEvent::RemoveListener(const Tizen::Base::Runtime::IEventListener& listener) +{ + result r = E_SUCCESS; + + r = _Event::RemoveListener(listener); + + if (r == E_SUCCESS) + { + __listenerCount--; + } + + return r; +} + +int +_NdefMessageDiscoveryEvent::GetListenerCount() const +{ + return __listenerCount; +} + +void +_NdefMessageDiscoveryEvent::FireImpl(IEventListener& listener, const IEventArg& arg) +{ + NdefMessage* pMessage = null; + NdefRecord* pNdefRecord = null; + + result r = E_SUCCESS; + + INdefMessageDiscoveryEventListener* pEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_NET_NFC, pEventListener != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + const _NdefMessageDiscoveryEventArg* pEventArg = dynamic_cast (&arg); + SysTryReturnVoidResult(NID_NET_NFC, pEventArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + pMessage = pEventArg->GetNdefMessage(); + int recordCount = pMessage->GetRecordsCount(); + + unique_ptr pCopiedMessage(new (std::nothrow) NdefMessage()); + SysTryReturnVoidResult(NID_NET_NFC , pCopiedMessage != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + // If listener is only one, do shallow copy (for performance issues). Otherwise, do deep copy. + if (GetListenerCount() == 1) + { + // shallow copy + for (int i = 0; i < recordCount; i++) + { + pNdefRecord = new (std::nothrow) NdefRecord(pMessage->GetRecordAt(i)->GetRecordType()); + SysTryReturnVoidResult(NID_NET_NFC, pNdefRecord != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pNdefRecord->SetPayloadId(pMessage->GetRecordAt(i)->GetPayloadId()); + ByteBuffer* pOrigPayload = pMessage->GetRecordAt(i)->GetPayload(); + if (pOrigPayload) + { + ByteBuffer* pNewPayload = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_NET_NFC, pNewPayload != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pNewPayload->Construct(*pOrigPayload); + pNdefRecord->SetPayload(*pNewPayload); + + delete pNewPayload; + } + r = pCopiedMessage->AppendRecord(*pNdefRecord); + SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + } + } + else + { + // deep copy + for (int i = 0; i < recordCount; i++) + { + pNdefRecord = new (std::nothrow) NdefRecord(*(pMessage->GetRecordAt(i))); + SysTryReturnVoidResult(NID_NET_NFC, pNdefRecord != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + r = pCopiedMessage->AppendRecord(*pNdefRecord); + SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + } + + } + pEventListener->OnNdefMessageDetectedN(pCopiedMessage.release()); + +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefMessageDiscoveryEvent.h b/src/FNetNfc_NdefMessageDiscoveryEvent.h new file mode 100644 index 0000000..03e569e --- /dev/null +++ b/src/FNetNfc_NdefMessageDiscoveryEvent.h @@ -0,0 +1,103 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefMessageDiscoveryEvent.h + * @brief This is the header file for the _NdefMessageDiscoveryEvent class. + * + * This header file contains declaration of the _NdefMessageDiscoveryEvent class. + * The _NdefMessageDiscoveryEvent class can call methods of INdefMessageDiscoveryEventListener class. + */ +#ifndef _FNET_NFC_INTERNAL_NDEF_MESSAGE_DISCOVERY_EVENT_H_ +#define _FNET_NFC_INTERNAL_NDEF_MESSAGE_DISCOVERY_EVENT_H_ + +#include +#include +#include + +namespace Tizen { namespace Base { namespace Runtime +{ +class IEventArg; +class IEventListener; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @class _NdefMessageDiscoveryEvent + * @brief This class handles the events related to the discovery of NDEF message. + * + * When an NDEF message is discovered, the _NdefMessageDiscoveryEvent object finds a INdefMessageDiscoveryEventListener + * object and calls an appropriate method of the listener. + */ +class _NdefMessageDiscoveryEvent + : public Tizen::Base::Runtime::_Event +{ +public: + /** + * This is the default constructor. + */ + _NdefMessageDiscoveryEvent(); + + /** + * This is the class destructor. + */ + virtual ~_NdefMessageDiscoveryEvent(void); + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + + /** + * Adds a listener object. + * This method overrides Tizen::Base::Runtime::AddListener() + */ + result AddListener(const Tizen::Base::Runtime::IEventListener& listener, bool calledByCallerThread = false); + + /** + * Removes a listener object. + * This method overrides Tizen::Base::Runtime::RemoveListener() + */ + result RemoveListener(const Tizen::Base::Runtime::IEventListener& listener); + + /** + * Gets the number of listener objects. + */ + int GetListenerCount(void) const; + +protected: + /** + * Calls the specified listener's method with the specified argument when event is generated. + * + * @param[in] listener The event listener which will be received the event + * @param[in] arg The event argument to be passed by + */ + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _NdefMessageDiscoveryEvent(const _NdefMessageDiscoveryEvent& value); + _NdefMessageDiscoveryEvent& operator =(const _NdefMessageDiscoveryEvent& value); + +private: + int __listenerCount; + +}; // _NdefMessageDiscoveryEvent + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NDEF_MESSAGE_DISCOVERY_EVENT_H_ diff --git a/src/FNetNfc_NdefMessageDiscoveryEventArg.cpp b/src/FNetNfc_NdefMessageDiscoveryEventArg.cpp new file mode 100644 index 0000000..0643da4 --- /dev/null +++ b/src/FNetNfc_NdefMessageDiscoveryEventArg.cpp @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NdefMessageDiscoveryEventArg.cpp +// @brief This is the implementation file for _NdefMessageDiscoveryEventArg class. +// +// This file contains the implementation of _NdefMessageDiscoveryEventArg class. +// + +#include +#include +#include +#include +#include "FNetNfc_NdefMessageDiscoveryEventArg.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefMessageDiscoveryEventArg::_NdefMessageDiscoveryEventArg(NdefMessage& message) + : __pNdefMessage(null) +{ + __pNdefMessage = new (std::nothrow) NdefMessage(message); + SysTryReturnVoidResult(NID_NET_NFC, __pNdefMessage != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + +} + +_NdefMessageDiscoveryEventArg::~_NdefMessageDiscoveryEventArg(void) +{ + if (__pNdefMessage) + { + __pNdefMessage->RemoveAllRecords(true); + delete __pNdefMessage; + } +} + +Tizen::Net::Nfc::NdefMessage* +_NdefMessageDiscoveryEventArg::GetNdefMessage(void) const +{ + return __pNdefMessage; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefMessageDiscoveryEventArg.h b/src/FNetNfc_NdefMessageDiscoveryEventArg.h new file mode 100644 index 0000000..dc75009 --- /dev/null +++ b/src/FNetNfc_NdefMessageDiscoveryEventArg.h @@ -0,0 +1,76 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefMessageArg.h + * @brief This is the header file for the _NdefMessageDiscoveryEventArg class. + * + * This header file contains declaration of the _NdefMessageDiscoveryEventArg class. + */ +#ifndef _FNET_NFC_INTERNAL_NDEF_MESSAGE_DISCOVERY_EVENT_ARG_H_ +#define _FNET_NFC_INTERNAL_NDEF_MESSAGE_DISCOVERY_EVENT_ARG_H_ + +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NdefMessage; + +/** + * @class _NdefMessageDiscoveryEventArg + * @brief This class is used as an argument of methods of the _NdefMessageDiscoveryEvent class. + * + * When an NDEF message is discovered, the INdefMessageDiscoveryEventListener objects registered to the event are called + * with this argument class. + */ +class _NdefMessageDiscoveryEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ +public: + /** + * This is the constructor. + * @param[in] message The detected NDEF message + */ + _NdefMessageDiscoveryEventArg(NdefMessage& message); + + /** + * This is the class destructor. + */ + ~_NdefMessageDiscoveryEventArg(void); + + /** + * Gets the NDEF Message . + * + * @return The detected NDEF message + */ + NdefMessage* GetNdefMessage(void) const; + +private: + _NdefMessageDiscoveryEventArg(const _NdefMessageDiscoveryEventArg& value); + _NdefMessageDiscoveryEventArg& operator =(const _NdefMessageDiscoveryEventArg& value); + +private: + NdefMessage* __pNdefMessage; + +}; // _NdefMessageDiscoveryEventArg + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NDEF_MESSAGE_DISCOVERY_EVENT_ARG_H_ diff --git a/src/FNetNfc_NdefMessageImpl.cpp b/src/FNetNfc_NdefMessageImpl.cpp new file mode 100644 index 0000000..a787ba0 --- /dev/null +++ b/src/FNetNfc_NdefMessageImpl.cpp @@ -0,0 +1,362 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NdefMessageImpl.cpp +// @brief This is the implementation file for _NdefMessageImpl class. +// +// This file contains the implementation of _NdefMessageImpl class. +// + +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NdefMessageImpl.h" +#include "FNetNfc_NdefMessageUtil.h" +#include "FNetNfc_NdefRecordImpl.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefMessageImpl::_NdefMessageImpl(void) + : __pRecordList(null) +{ + unique_ptr pRecordList(new (std::nothrow) LinkedList()); + SysTryReturnVoidResult(NID_NET_NFC, pRecordList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pRecordList = move(pRecordList); +} + +_NdefMessageImpl::_NdefMessageImpl(const _NdefMessageImpl& value) +{ + IList* pSourceList = value.__pRecordList.get(); + int srcRecordCount = pSourceList->GetCount(); + + unique_ptr pRecordList(new (std::nothrow) LinkedList()); + SysTryReturnVoidResult(NID_NET_NFC, pRecordList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + for (int i = 0; i < srcRecordCount; i++) + { + NdefRecord* pSrcRecord = dynamic_cast(pSourceList->GetAt(i)); + SysTryReturnVoidResult(NID_NET_NFC, pSrcRecord != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + NdefRecord* pNewRecord = new (std::nothrow) NdefRecord(*pSrcRecord); + SysTryReturnVoidResult(NID_NET_NFC, pNewRecord != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pRecordList->Add(*pNewRecord); + } + __pRecordList = move(pRecordList); +} + +_NdefMessageImpl::~_NdefMessageImpl(void) +{ + +} + +bool +_NdefMessageImpl::Equals(const Tizen::Base::Object& obj) const +{ + const _NdefMessageImpl* pOther = dynamic_cast (&obj); + + if (pOther == null) + { + return false; + } + + if (pOther == this) + { + return true; + } + + return __pRecordList->Equals(*(pOther->__pRecordList)); +} + +int +_NdefMessageImpl::GetHashCode(void) const +{ + return __pRecordList->GetHashCode(); +} + +result +_NdefMessageImpl::AppendRecord(const NdefRecord& record) +{ + result r = E_SUCCESS; + String recordId; + NdefRecordType recordType; + NdefRecordTypeNameFormat tnf = NDEF_TNF_EMPTY; + String typeName; + + recordId = record.GetPayloadId(); + + if (!recordId.IsEmpty()) + { + // Checks whether the same id already exists or not + NdefRecord* pRecord = GetRecord(recordId); + TryReturn(pRecord == null, E_INVALID_ARG, + "[E_INVALID_ARG] Invalid argument is used. NDEF record with the same payload identifier already exists."); + } + + recordType = record.GetRecordType(); + tnf = recordType.GetNameFormat(); + typeName = recordType.GetName(); + + if (((tnf == NDEF_TNF_WELL_KNOWN) || (tnf == NDEF_TNF_MIME_MEDIA) || (tnf == NDEF_TNF_ABSOLUTE_URI) || + (tnf == NDEF_TNF_EXTERNAL)) + && typeName.IsEmpty()) + { + SysLogException(NID_NET_NFC, E_INVALID_ARG, + "Invalid argument is used. The NDEF record to be appended has an empty string as the type name."); + return E_INVALID_ARG; + } + + // Propagates the result (E_SUCCESS or E_OUT_OF_MEMORY) + r = __pRecordList->Add(record); + + // Makes a link to NdefMesasge + _NdefRecordImpl::SetMessageImpl(record, this); + + return r; +} + +int +_NdefMessageImpl::GetRecordsCount() const +{ + return __pRecordList->GetCount(); +} + +NdefRecord* +_NdefMessageImpl::GetRecordAt(int index) const +{ + return dynamic_cast(__pRecordList->GetAt(index)); +} + +NdefRecord* +_NdefMessageImpl::GetRecord(const Tizen::Base::String& payloadId) const +{ + int count = __pRecordList->GetCount(); + NdefRecord* pRecord = null; + ClearLastResult(); + + for (int i = 0; i < count; i++) + { + pRecord = dynamic_cast(__pRecordList->GetAt(i)); + if (pRecord && pRecord->GetPayloadId() == payloadId) + { + return pRecord; + } + } + + SetLastResult(E_OBJ_NOT_FOUND); + return null; +} + +result +_NdefMessageImpl::IndexOf(const NdefRecord& record, int& index) const +{ + return __pRecordList->IndexOf(record, index); +} + +result +_NdefMessageImpl::InsertRecordAt(const NdefRecord& record, int index) +{ + result r = E_SUCCESS; + String recordId; + NdefRecordType recordType; + NdefRecordTypeNameFormat tnf = NDEF_TNF_EMPTY; + String typeName; + + recordId = record.GetPayloadId(); + + if (!recordId.IsEmpty()) + { + // Checks whether the same id already exists or not + NdefRecord* pRecord = GetRecord(recordId); + TryReturn(pRecord == null, E_INVALID_ARG, + "[E_INVALID_ARG] Invalid argument is used. NDEF record with the same payload identifier already exists."); + } + + recordType = record.GetRecordType(); + tnf = recordType.GetNameFormat(); + typeName = recordType.GetName(); + + if (((tnf == NDEF_TNF_WELL_KNOWN) || (tnf == NDEF_TNF_MIME_MEDIA) || (tnf == NDEF_TNF_ABSOLUTE_URI) || + (tnf == NDEF_TNF_EXTERNAL)) + && typeName.IsEmpty()) + { + SysLogException(NID_NET_NFC, E_INVALID_ARG, + "Invalid argument is used. The NDEF record to be appended has an empty string as the type name."); + return E_INVALID_ARG; + } + + // Propagates the result (E_SUCCESS, E_OUT_OF_RANGE, or E_OUT_OF_MEMORY) + r = __pRecordList->InsertAt(record, index); + + // Makes a link to NdefMesasge + if (r == E_SUCCESS) + { + _NdefRecordImpl::SetMessageImpl(record, this); + } + + + return r; +} + +result +_NdefMessageImpl::RemoveRecordAt(int index, bool deallocate) +{ + result r = E_OUT_OF_RANGE; + NdefRecord* pPrivNdefRecord = null; + + pPrivNdefRecord = dynamic_cast(__pRecordList->GetAt(index)); + + if (pPrivNdefRecord) + { + // Propagates the result (E_SUCCESS or E_OUT_OF_RANGE) + r = __pRecordList->RemoveAt(index, deallocate); + + // Removes the link to NdefMesasge + if (r == E_SUCCESS && deallocate == false) + { + _NdefRecordImpl::SetMessageImpl(*pPrivNdefRecord, null); + } + } + + return r; +} + +result +_NdefMessageImpl::SetRecordAt(const NdefRecord& record, int index, bool deallocate) +{ + result r = E_OUT_OF_RANGE; + NdefRecord* pPrivNdefRecord = null; + String recordId; + NdefRecordType recordType; + NdefRecordTypeNameFormat tnf = NDEF_TNF_EMPTY; + String typeName; + + recordId = record.GetPayloadId(); + + if (!recordId.IsEmpty()) + { + // Checks whether the same id already exists or not + NdefRecord* pRecord = GetRecord(recordId); + + if (pRecord) + { + int searchIndex = -1; + result res = E_SUCCESS; + res = __pRecordList->IndexOf(*pRecord, searchIndex); + TryReturn(searchIndex == index, E_INVALID_ARG, + "[E_INVALID_ARG] Invalid argument is used. NDEF record with the same payload identifier already exists."); + } + } + + recordType = record.GetRecordType(); + tnf = recordType.GetNameFormat(); + typeName = recordType.GetName(); + + if (((tnf == NDEF_TNF_WELL_KNOWN) || (tnf == NDEF_TNF_MIME_MEDIA) || (tnf == NDEF_TNF_ABSOLUTE_URI) || + (tnf == NDEF_TNF_EXTERNAL)) + && typeName.IsEmpty()) + { + SysLogException(NID_NET_NFC, E_INVALID_ARG, + "Invalid argument is used. The NDEF record to be appended has an empty string as the type name."); + return E_INVALID_ARG; + } + + pPrivNdefRecord = dynamic_cast( __pRecordList->GetAt(index)); + + if (pPrivNdefRecord) + { + // Propagates the result (E_SUCCESS or E_OUT_OF_RANGE) + r = __pRecordList->SetAt(record, index, deallocate); + if (r == E_SUCCESS) + { + _NdefRecordImpl::SetMessageImpl(record, this); + + // Remove the link to NdefMesasge + if (deallocate == false) + { + _NdefRecordImpl::SetMessageImpl(*pPrivNdefRecord, null); + } + } + } + + return r; +} + +void +_NdefMessageImpl::RemoveAllRecords(bool deallocate) +{ + int count = __pRecordList->GetCount(); + NdefRecord* pPrivNdefRecord = null; + + // Removes the link to NdefMesasge + if (deallocate == false) + { + for (int i = 0; i < count; i++) + { + pPrivNdefRecord = dynamic_cast(__pRecordList->GetAt(i)); + + if (pPrivNdefRecord) + { + _NdefRecordImpl::SetMessageImpl(*pPrivNdefRecord, null); + } + } + } + + __pRecordList->RemoveAll(deallocate); +} + +ByteBuffer* +_NdefMessageImpl::ToByteBufferN(const NdefMessage& message) const +{ + return _NdefMessageUtil::ToByteBufferN(message); +} + +_NdefMessageImpl& +_NdefMessageImpl::operator =(const _NdefMessageImpl& rhs) +{ + IList* pSourceList = null; + unique_ptr pTempList; + int recordCount = 0; + + if (this != &rhs) + { + pSourceList = rhs.__pRecordList.get(); + pTempList.reset(new (std::nothrow) LinkedList()); + SysTryReturn(NID_NET_NFC, pTempList != null, *this, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + recordCount = pSourceList->GetCount(); + + for (int i = 0; i < recordCount; i++) + { + NdefRecord* pSrcRecord = static_cast(pSourceList->GetAt(i)); + NdefRecord* pNewRecord = new (std::nothrow) NdefRecord(*pSrcRecord); + SysTryReturn(NID_NET_NFC, pNewRecord != null, *this, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pTempList->Add(*pNewRecord); + } + __pRecordList.reset(pTempList.release()); + } + + return *this; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefMessageUtil.cpp b/src/FNetNfc_NdefMessageUtil.cpp new file mode 100644 index 0000000..d947d6e --- /dev/null +++ b/src/FNetNfc_NdefMessageUtil.cpp @@ -0,0 +1,805 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NdefMessageUtil.cpp +// @brief This is the implementation file for _NdefMessageUtil Class. +// +// This file contains the implementation of _NdefMessageUtil Class. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NdefMessageUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Net { namespace Nfc +{ + +enum _NDEFRercodFlags +{ + NDEF_IL = 0x08, // idLen is present. + NDEF_SR = 0x10, // Short record. + NDEF_CF = 0x20, // Chunk flag. + NDEF_ME = 0x40, // Message end. + NDEF_MB = 0x80 // Message begin. +}; + +static const int MINIMUM_RECORD_SIZE = 3; +static const String DNS_SYMBOLS(L".-"); +static const String OTHER_SYMBOLS(L"()+,-:=@;$_!*'."); + + +_NdefMessageUtil::_NdefMessageUtil(void) +{ +} + +_NdefMessageUtil::~_NdefMessageUtil(void) +{ +} + +result +ParseRecord(NdefRecordType& recordtype, bool& cf, String& payloadId, ByteBuffer& buf_payload, Tizen::Base::ByteBuffer& data) +{ + result r = E_SUCCESS; + String typeName; + char* pType = null; + char* pId = null; + byte flags = 0; + byte tnf = 0; + byte idLen = 0; + unsigned int payloadLen = 0; + bool isShortRecord = false; + bool isIdLenExist = false; + + r = data.GetByte(flags); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get Bytes from Byte Buffer"); + + // The first byte + // + // +____+____+____+____+____+____+____+____+ + // | MB | ME | CF | SR | IL | TNF | + // +____+____+____+____+____+____+____+____+ + // + + tnf = flags & 0x07; + + NdefRecordType recordType = NdefRecordType((NdefRecordTypeNameFormat) tnf); + + isIdLenExist = flags & NDEF_IL; + isShortRecord = flags & NDEF_SR; + cf = flags & NDEF_CF; + + // The second byte + byte typeLen = 0; + r = data.GetByte(typeLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get Bytes from Byte Buffer"); + + // The third byte + if (isShortRecord == true) + { + r = data.GetByte(flags); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get Bytes from Byte Buffer"); + payloadLen = (unsigned int) flags; + } + else + { + byte temp = 0; + for (int i = 3; i >= 0; i--) + { + r = data.GetByte(temp); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get Bytes from Byte Buffer"); + payloadLen |= (temp << 8 * i); + } + } + + // ID Length. + if (isIdLenExist == true) + { + r = data.GetByte(idLen); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Unable to get Bytes from Byte Buffer"); + } + + // Type + pType = new (std::nothrow) char[typeLen + 1]; + SysTryCatch(NID_NET_NFC, pType != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + if (typeLen > 0) + { + r = data.GetArray((byte*) pType, 0, (int) typeLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] Unable to get Array from Byte Buffer"); + } + pType[typeLen] = '\0'; + typeName.Append(pType); + delete[] pType; + pType = null; + + if (recordType.GetNameFormat() != NDEF_TNF_EMPTY) + { + recordType.SetName(typeName); + } + recordtype = recordType; + + if (isIdLenExist == true && idLen > 0) + { + pId = new (std::nothrow) char[idLen + 1]; + SysTryCatch(NID_NET_NFC, pId != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Insufficient Memory"); + r = data.GetArray((byte*) pId, 0, (int) idLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] Unable to get Array from Byte Buffer"); + pId[idLen] = '\0'; + String temp(pId); + + delete[] pId; + pId = null; + payloadId = temp; + } + if (payloadLen > 0) + { + buf_payload.Construct(payloadLen); + + SysTryCatch(NID_NET_NFC, data.GetRemaining() >= (int) payloadLen, r = E_SYSTEM, r, "[E_SYSTEM] Unable to get payload"); + + r = buf_payload.SetArray(data.GetPointer(), data.GetPosition(), payloadLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] Unable to set Array from Byte Buffer"); + // Move Current Position as paylaod length + data.SetPosition(data.GetPosition() + payloadLen); + buf_payload.SetPosition(0); + } + + SysLog(NID_NET_NFC, "Record: [TNF:0x%02X, Chunk:%s, SR(Short Record):%s, ID:%s, Payload:%dbytes]", + tnf, cf ? "Yes" : "No", isShortRecord ? "Yes" : "No", isIdLenExist ? "Exist" : "Not Exist", payloadLen); + + return r; + +CATCH: + if (pType) + { + delete[] pType; + } + + if (pId) + { + delete[] pId; + } + + return r; +} + +Tizen::Base::ByteBuffer* +_NdefMessageUtil::ToByteBufferN(const NdefMessage& ndefMessage) +{ + result r = E_SUCCESS; + + ByteBuffer* pMessage = null; + ByteBuffer* pId = null; + ByteBuffer* pType = null; + + byte flags = 0; + int messageSize = 0; + int payloadLen = 0; + + int recordCount = ndefMessage.GetRecordsCount(); + + if (recordCount == 0) + { + SetLastResult(E_INVALID_DATA); + SysLog(NID_NET_NFC, "The NDEF message does not contain any NDEF records"); + return null; + } + + ByteBuffer* pRecords = new (std::nothrow) ByteBuffer[recordCount]; + SysTryCatch(NID_NET_NFC, pRecords != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + for (int i = 0; i < recordCount; i++) + { + bool sr = false; + bool il = false; + flags = 0; + + // first record + if (i == 0) + { + flags |= NDEF_MB; + } + + // last record + if (i == recordCount - 1) + { + flags |= NDEF_ME; + } + + NdefRecord* pRecord = ndefMessage.GetRecordAt(i); + SysTryCatch(NID_NET_NFC, pRecord != null, r = E_SYSTEM, r, "Record is invalid"); + + const ByteBuffer* pPayload = pRecord->GetPayload(); + if (pPayload) + { + payloadLen = pPayload->GetRemaining(); + if (payloadLen < 256) + { + sr = true; + flags |= NDEF_SR; + } + } + else + { + payloadLen = 0; + sr = true; + flags |= NDEF_SR; + } + + String id = pRecord->GetPayloadId(); + + unsigned char idLen = id.GetLength(); + + if (idLen > 0) + { + flags |= NDEF_IL; + il = true; + } + NdefRecordType recordtype = pRecord->GetRecordType(); + NdefRecordTypeNameFormat tnf = recordtype.GetNameFormat(); + flags |= tnf; + + String typeName = recordtype.GetName(); + + byte typeLen = typeName.GetLength(); + + int recordSize = 0; + recordSize = 1 + //first byte flags + 1 + //type length + ((sr == true) ? 1 : 4) + //payload length + ((il == true) ? 1 : 0) + //id length + typeLen + //type + idLen + //id + payloadLen; // payload + + SysLog(NID_NET_NFC, "Record: [TNF:0x%02X, SR(Short Record):%s, ID:%s, Payload:%dbytes]", + tnf, sr ? "Yes" : "No", il ? "Exist" : "Not Exist", payloadLen); + + r = pRecords[i].Construct(recordSize); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + // Set Flags + r = pRecords[i].SetByte(flags); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + + // Set Type Length + r = pRecords[i].SetByte(typeLen); + + // Set Payload Length + if (sr == true) + { + r = pRecords[i].SetByte((byte) payloadLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + } + else + { + for (int j = 3; j >= 0; j--) + { + byte temp = (byte) ((payloadLen >> 8 * j) & 0x000000ff); + SysLog(NID_NET_NFC, "PayloadLen = %d, byte[%d] = %x", payloadLen, 3 - j, temp); + r = pRecords[i].SetByte(temp); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + } + } + + //Set Id Length + if (il == true) + { + r = pRecords[i].SetByte(idLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + } + + //set type name + if (typeLen > 0) + { + pType = Tizen::Base::Utility::StringUtil::StringToUtf8N(typeName); + if (pType != null) + { + r = pRecords[i].SetArray(pType->GetPointer(), 0, typeLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + delete pType; + pType = null; + } + } + + //set id name + if (il == true) + { + pId = Tizen::Base::Utility::StringUtil::StringToUtf8N(id); + if (pId != null) + { + r = pRecords[i].SetArray(pId->GetPointer(), 0, idLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + delete pId; + pId = null; + } + } + + //set Payload + if (pPayload) + { + r = pRecords[i].SetArray(pPayload->GetPointer(), 0, payloadLen); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + } + + pRecords[i].SetPosition(0); + messageSize += recordSize; + } + + pMessage = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_NET_NFC, pMessage != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = pMessage->Construct(messageSize); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + + for (int i = 0; i < recordCount; i++) + { + r = pMessage->CopyFrom(pRecords[i]); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred."); + } + pMessage->Flip(); + + delete[] pRecords; + + SetLastResult(E_SUCCESS); + return pMessage; + +CATCH: + SetLastResult(r); + + delete[] pRecords; + delete pId; + delete pType; + delete pMessage; + + return null; +} + +NdefMessage* +_NdefMessageUtil::ToNdefMessageN(const Tizen::Base::ByteBuffer& buffer) +{ + + result r = E_SUCCESS; + ByteBuffer* pBuffer = null; + NdefMessage* pNdefMessage = null; + NdefRecord* pRecord = null; + LinkedList* pChunkedPayloadList = null; + ByteBuffer* pPayload = null; + + int size = buffer.GetRemaining(); + SysTryCatch(NID_NET_NFC, size > 0, r = E_INVALID_FORMAT, r, "[E_INVALID_FORMAT] Cannot be formulated to NDEF message"); + + // copy view of buffer + pBuffer = new (std::nothrow) ByteBuffer; + SysTryCatch(NID_NET_NFC, pBuffer != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory Insufficient"); + r = pBuffer->Construct(buffer); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A failure occurred from the underlying system"); + + // New NdefMessage + pNdefMessage = new (std::nothrow) NdefMessage(); + SysTryCatch(NID_NET_NFC, pNdefMessage != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + while (pBuffer->GetRemaining() >= MINIMUM_RECORD_SIZE) + { + + NdefRecordType recordType; + bool cf = false; + String payloadId; + + pPayload = new (std::nothrow) ByteBuffer(); + TryCatch(pPayload != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = ParseRecord(recordType, cf, payloadId, *pPayload, *pBuffer); + if (r != E_SUCCESS) + { + break; + } + + pRecord = new (std::nothrow) NdefRecord(recordType); + SysTryCatch(NID_NET_NFC, pRecord != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + if (payloadId.IsEmpty() == false) + { + r = pRecord->SetPayloadId(payloadId); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, , r, ""); + } + + // TODO: Handle Only 0x00~Ox05 + // Chunk Assembly + if (cf == 1) + { + int payloadLen = 0; + ByteBuffer* pAssembledPayload = null; + + pChunkedPayloadList = new (std::nothrow) LinkedList(); + TryCatch(pChunkedPayloadList != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + int chunkedPayloadLen = pPayload->GetRemaining(); + + payloadLen += chunkedPayloadLen; + + pChunkedPayloadList->Add(*pPayload); + + do + { + pPayload = new (std::nothrow) ByteBuffer(); + TryCatch(pPayload != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + r = ParseRecord(recordType, cf, payloadId, *pPayload, *pBuffer); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_INVALID_FORMAT, r, + "[E_INVALID_FORMAT] Cannot be formulated to NDEF message"); + SysTryCatch(NID_NET_NFC, + recordType.GetNameFormat() == 0x06, r = E_INVALID_FORMAT, r, + "[E_INVALID_FORMAT] Cannot be formulated to NDEF message"); + + pChunkedPayloadList->Add(*pPayload); + payloadLen += chunkedPayloadLen; + + } + while (cf == 1); + + // Assemble Payload; + pAssembledPayload = new (std::nothrow) ByteBuffer(); + TryCatch(pAssembledPayload != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pAssembledPayload->Construct(payloadLen); + for (int i = 0; i < pChunkedPayloadList->GetCount(); i++) + { + r = pAssembledPayload->CopyFrom(*((ByteBuffer*) (pChunkedPayloadList->GetAt(i)))); + } + + r = pRecord->SetPayload(*pAssembledPayload); + delete pAssembledPayload; + + r = pNdefMessage->AppendRecord(*pRecord); + + pChunkedPayloadList->RemoveAll(true); + delete pChunkedPayloadList; + pChunkedPayloadList = null; + + } + else + { + r = pRecord->SetPayload(*pPayload); + delete pPayload; + pPayload = null; + r = pNdefMessage->AppendRecord(*pRecord); + } + + + } + + SysTryCatch(NID_NET_NFC, + pNdefMessage->GetRecordsCount() != 0, r = E_INVALID_FORMAT, r, + "[E_INVALID_FORMAT] Cannot be formulated to NDEF message"); + + delete pBuffer; + pBuffer = null; + SetLastResult(E_SUCCESS); + return pNdefMessage; + +CATCH: + SetLastResult(r); + + if (pPayload) + { + delete pPayload; + } + + if (pBuffer) + { + delete pBuffer; + } + if (pNdefMessage) + { + pNdefMessage->RemoveAllRecords(true); + delete pNdefMessage; + } + + // Not appended record + if (pRecord != null) + { + delete pRecord; + pRecord = null; + } + + if (pChunkedPayloadList) + { + pChunkedPayloadList->RemoveAll(true); + delete pChunkedPayloadList; + pChunkedPayloadList = null; + } + return null; +} + +bool +IsValidMIMEChar(const Tizen::Base::String& name) +{ + wchar_t chr = 0; + int index = 0; + + String unSupportedSymbols = "\"()/:;<=>&\\"; + + for (int i = 0; i < name.GetLength(); i++) + { + name.GetCharAt(i, chr); + unSupportedSymbols.IndexOf(chr, 0, index); + SysTryReturn(NID_NET_NFC, index == -1, false, E_SYSTEM, "Name contains unsupported character"); + } + + return true; +} + +bool +IsValidMIMEType(const Tizen::Base::String& name) +{ + //Assume that there won't be "Content Type:" prefix for MIME type name + + int index = 0; + int indexSubType = 0; + String type; + String subType; + result r = E_SUCCESS; + + r = name.IndexOf(L"/", 0, index); + SysTryReturn(NID_NET_NFC, index != -1, false, E_SYSTEM, "Cannot find type seperator"); + + + r = name.IndexOf(L";", index, indexSubType); + if (IsFailed(r)) + { + SysLog(NID_NET_NFC, "Cannot find type ';'"); + } + + r = name.SubString(0, index, type); + if (indexSubType != -1) + { + r = name.SubString(index + 1, (indexSubType - index - 1), subType); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, false, E_SYSTEM, "Failed to get Substring"); + } + else + { + r = name.SubString(index + 1, subType); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, false, E_SYSTEM, "Failed to get Substring"); + } + + SysTryReturn(NID_NET_NFC, IsValidMIMEChar(type), false, E_SYSTEM, "Invalid Type"); + SysTryReturn(NID_NET_NFC, IsValidMIMEChar(subType), false, E_SYSTEM, "Invalid Subtype"); + + return true; +} + +bool +IsValidDnsChar(const Tizen::Base::String& name) +{ + wchar_t chr = 0; + int index = 0; + for (int i = 0; i < name.GetLength(); i++) + { + name.GetCharAt(i, chr); + + if (Character::IsDigit(chr) || Character::IsLetter(chr)) + { + continue; + } + + DNS_SYMBOLS.IndexOf(chr, 0, index); + SysTryReturn(NID_NET_NFC, index != -1, false, E_SYSTEM, "Name contains non-WTK Character"); + } + return true; +} + +bool +IsValidWktChar(const Tizen::Base::String& name) +{ + wchar_t chr = 0; + int index = 0; + + for (int i = 0; i < name.GetLength(); i++) + { + name.GetCharAt(i, chr); + + if (Character::IsDigit(chr) || Character::IsLetter(chr)) + { + continue; + } + + OTHER_SYMBOLS.IndexOf(chr, 0, index); + SysTryReturn(NID_NET_NFC, index != -1, false, E_SYSTEM, "Name contains non-WTK Character"); + } + return true; +} + +bool +IsValidExtName(const Tizen::Base::String& name) +{ + result r = E_SUCCESS; + + String dnsPart; + String namePart; + int index = 0; + + // Currently, name doesn't contain prefix + // SysTryLogReturn (NID_NET_NFC,(name.StartsWith(PREFIX_EXT,0) && name.GetLength() > PREFIX_EXT.GetLength()), + // false, "Name doesn't contain prefix urn:nfc:wkt: ")); + + + r = name.IndexOf(L":", 0, index); + SysTryReturn(NID_NET_NFC, index > 0 && index < (name.GetLength() - 1), false, E_SYSTEM, "Name doesn't contain ':'"); + + r = name.SubString(0, index, dnsPart); + r = name.SubString(index + 1, namePart); + + SysTryReturn(NID_NET_NFC, IsValidDnsChar(dnsPart), false, E_SYSTEM, "Invalid DNS Part"); + SysTryReturn(NID_NET_NFC, IsValidWktChar(namePart), false, E_SYSTEM, "Invalid Name Part"); + + return true; +} + +bool +IsValidWKTName(const Tizen::Base::String& name) +{ + wchar_t chr = 0; + + // Currently, name doesn't contain prefix + // SysTryLogReturn (MID,FNETNFC,(name.StartsWith(PREFIX_WKT,0) && name.GetLength() > PREFIX_WKT.GetLength()), + // false, "Name doesn't contain prefix urn:nfc:wkt: ")); + + + // First symbol must be a letter or digit only + name.GetCharAt(0, chr); + SysTryReturn(NID_NET_NFC, Character::IsLetter(chr) || Character::IsDigit( + chr), false, E_SYSTEM, "First symbol must be a letter or digit only"); + + SysTryReturn(NID_NET_NFC, IsValidWktChar(name), false, E_SYSTEM, "Invalid WKT name"); + + return true; +} + +bool +_NdefMessageUtil::IsValidRecordType(NdefRecordTypeNameFormat type, const Tizen::Base::String& name) +{ + switch (type) + { + case NDEF_TNF_EMPTY: + case NDEF_TNF_UNKNOWN: + return true; + + case NDEF_TNF_WELL_KNOWN: + return IsValidWKTName(name); + + case NDEF_TNF_MIME_MEDIA: + return IsValidMIMEType(name); + + case NDEF_TNF_ABSOLUTE_URI: + return true; + + case NDEF_TNF_EXTERNAL: + return IsValidExtName(name); + + default: + SysLog(NID_NET_NFC, "Unknown record type name format: %d ", type); + return false; + } + +} + +IList* +_NdefMessageUtil::GetEquivalentRecordTypesN(const NdefRecordType& recordType) +{ + + result r = E_SUCCESS; + + NdefRecordTypeNameFormat tnf = recordType.GetNameFormat(); + NdefRecordType* pRecordType = null; + LinkedList* pList = null; + String name; + int subTypeStartIndex = 0; + int subTypeEndIndex = 0; + String type; + String subType; + String mimeName; + + pList = new (std::nothrow) LinkedList(); + TryCatch(pList != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + switch (tnf) + { + case NDEF_TNF_EMPTY: + case NDEF_TNF_WELL_KNOWN: + case NDEF_TNF_ABSOLUTE_URI: + case NDEF_TNF_EXTERNAL: + case NDEF_TNF_UNKNOWN: + pRecordType = new (std::nothrow) NdefRecordType(recordType); + TryCatch(pRecordType != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pList->Add(*pRecordType); + break; + + case NDEF_TNF_MIME_MEDIA: + name = recordType.GetName(); + + pRecordType = new (std::nothrow) NdefRecordType(recordType); + TryCatch(pRecordType != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pList->Add(*pRecordType); + + if (name.StartsWith(L"*", 0) == false) + { + r = name.IndexOf(L"/", 0, subTypeStartIndex); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] name doesn't contain '/'"); + + r = name.SubString(0, subTypeStartIndex, type); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error occurred on getting the type"); + + r = name.IndexOf(L";", subTypeStartIndex, subTypeEndIndex); + if (r == E_SUCCESS) + { + r = name.SubString(subTypeStartIndex + 1, (subTypeEndIndex - subTypeStartIndex - 1), subType); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error occurred on getting substring"); + } + else + { + r = name.SubString(subTypeStartIndex + 1, subType); + SysTryCatch(NID_NET_NFC, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] A system error occurred on getting substring"); + } + + if (subType.Equals(L"*", false) == false) + { + // Add "type/*" + pRecordType = new (std::nothrow) NdefRecordType(NDEF_TNF_MIME_MEDIA); + SysTryCatch(NID_NET_NFC, pRecordType != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + mimeName.Append(type); + mimeName.Append("/*"); + pRecordType->SetName(mimeName); + pList->Add(*pRecordType); + } + + // Add */* + pRecordType = new (std::nothrow) NdefRecordType(NDEF_TNF_MIME_MEDIA); + SysTryCatch(NID_NET_NFC, pRecordType != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + pRecordType->SetName(L"*/*"); + pList->Add(*pRecordType); + } + break; + + default: + break; + } + + return pList; + +CATCH: + SetLastResult(r); + + if (pList != null) + { + pList->RemoveAll(true); + delete pList; + pList = null; + } + + return null; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefPushManagerEvent.cpp b/src/FNetNfc_NdefPushManagerEvent.cpp new file mode 100644 index 0000000..4df139c --- /dev/null +++ b/src/FNetNfc_NdefPushManagerEvent.cpp @@ -0,0 +1,66 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NdefPushManagerEvent.cpp +// @brief This is the implementation file for _NdefPushManagerEvent class. +// +// This file contains the implementation of _NdefPushManagerEvent class. +// + +#include +#include +#include +#include +#include "FNetNfc_NdefPushManagerEvent.h" +#include "FNetNfc_NdefPushManagerEventArg.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefPushManagerEvent::_NdefPushManagerEvent(void) +{ +} + +_NdefPushManagerEvent::~_NdefPushManagerEvent(void) +{ +} + +result +_NdefPushManagerEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_NdefPushManagerEvent::FireImpl(IEventListener& listener, const IEventArg& arg) +{ + result r = E_SUCCESS; + + INdefPushManagerListener* pListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_NET_NFC, pListener != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + const _NdefPushManagerEventArg* pArg = dynamic_cast (&arg); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + r = pArg->GetResult(); + + pListener->OnNdefPushMessageSent(r); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefPushManagerEvent.h b/src/FNetNfc_NdefPushManagerEvent.h new file mode 100644 index 0000000..5ad750e --- /dev/null +++ b/src/FNetNfc_NdefPushManagerEvent.h @@ -0,0 +1,82 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NdefPushManagerEvent.h + * @brief This is the header file for the _NdefPushManagerEvent class. + * + * This header file contains declaration of the _NdefPushManagerEvent class. + * The _NdefPushManagerEvent class can call methods of INdefMessageDiscoveryEventListener class. + */ +#ifndef _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_EVENT_H_ +#define _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_EVENT_H_ + +#include +#include +#include + +namespace Tizen { namespace Base { namespace Runtime +{ +class IEventArg; +class IEventListener; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @class _NdefPushManagerEvent + * @brief This class handles the events related to the push of NDEF message. + * + * When an NDEF message is pushed, the _NdefPushManagerEvent object finds a %INdefPushManagerListener + * object and calls an appropriate method of the listener. + */ +class _NdefPushManagerEvent + : public Tizen::Base::Runtime::_Event +{ +public: + /** + * This is the default constructor. + */ + _NdefPushManagerEvent(void); + + /** + * This is the class destructor. + */ + virtual ~_NdefPushManagerEvent(void); + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + +protected: + /** + * Calls the specified listener's method with the specified argument when event is generated. + * + * @param[in] listener The event listener which will be received the event + * @param[in] arg The event argument to be passed by + */ + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _NdefPushManagerEvent(const _NdefPushManagerEvent& value); + _NdefPushManagerEvent& operator =(const _NdefPushManagerEvent& value); +}; // _NdefPushManagerEvent + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_EVENT_H_ diff --git a/src/FNetNfc_NdefPushManagerEventArg.cpp b/src/FNetNfc_NdefPushManagerEventArg.cpp new file mode 100644 index 0000000..073f57e --- /dev/null +++ b/src/FNetNfc_NdefPushManagerEventArg.cpp @@ -0,0 +1,49 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NdefPushManagerEventArg.cpp +// @brief This is the implementation file for _NdefPushManagerEventArg class. +// +// This file contains the implementation of _NdefPushManagerEventArg class. +// + +#include +#include "FNetNfc_NdefPushManagerEventArg.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefPushManagerEventArg::_NdefPushManagerEventArg(void) + : __r(E_SUCCESS) +{ +} + +_NdefPushManagerEventArg::_NdefPushManagerEventArg(result r) + : __r(r) +{ +} + +_NdefPushManagerEventArg::~_NdefPushManagerEventArg(void) +{ +} + +result +_NdefPushManagerEventArg::GetResult(void) const +{ + return __r; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefPushManagerEventArg.h b/src/FNetNfc_NdefPushManagerEventArg.h new file mode 100644 index 0000000..85fd0d6 --- /dev/null +++ b/src/FNetNfc_NdefPushManagerEventArg.h @@ -0,0 +1,73 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NdefPushManagerEventArg.h + * @brief This is the header file for the _NdefMessageDiscoveryEventArg class. + * + * This header file contains declaration of the _NdefMessageDiscoveryEventArg class. + */ +#ifndef _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_EVENT_ARG_H_ +#define _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_EVENT_ARG_H_ + +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ +/** + * @class _NdefMessageDiscoveryEventArg + * @brief This class is used as an argument of methods of the _NdefMessageDiscoveryEvent class. + * + * When an NDEF message is discovered, the INdefMessageDiscoveryEventListener objects registered to the event are called + * with this argument class. + */ +class _NdefPushManagerEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ +public: + /** + * This is the constructor. + * @param[in] r The sent result. + */ + _NdefPushManagerEventArg(result r); + + /** + * This is the class destructor. + */ + ~_NdefPushManagerEventArg(void); + + /** + * Gets the sent result. + * + * @return The sent result + */ + result GetResult(void) const; + +private: + _NdefPushManagerEventArg(void); + _NdefPushManagerEventArg(const _NdefPushManagerEventArg& value); + _NdefPushManagerEventArg& operator =(const _NdefPushManagerEventArg& value); + +private: + result __r; + +}; // _NdefPushManagerEventArg + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_EVENT_ARG_H_ diff --git a/src/FNetNfc_NdefPushManagerImpl.cpp b/src/FNetNfc_NdefPushManagerImpl.cpp new file mode 100644 index 0000000..bbec373 --- /dev/null +++ b/src/FNetNfc_NdefPushManagerImpl.cpp @@ -0,0 +1,167 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NdefPushManagerImpl.cpp +// @brief This is the implementation file for _NdefPushManagerImpl class. +// +// This file contains the implementation of _NdefPushManagerImpl class. +// + +#include +#include +#include +#include "FNetNfc_NfcIpcProxy.h" +#include "FNetNfc_NdefMessageUtil.h" +#include "FNetNfc_NdefPushManagerImpl.h" +#include "FNetNfc_NdefPushManagerEvent.h" +#include "FNetNfc_NdefPushManagerEventArg.h" +#include "FNetNfc_NfcSystemAdapter.h" + +using namespace std; +using namespace Tizen::Base; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefPushManagerImpl::_NdefPushManagerImpl(void) + : __p2pTargetHandle(null) + , __pNdefPushManagerEvent(null) + , __pPreviousListener(null) +{ + // Create the NfcSystemAdapter + __pSystemAdapter = _NfcSystemAdapter::GetInstance(); + SysTryReturnVoidResult(NID_NET_NFC, __pSystemAdapter != null, E_SYSTEM, "Failed to get the instance of _NfcSystemAdapter."); + + unique_ptr<_NdefPushManagerEvent> pNdefPushManagerEvent(new (std::nothrow) _NdefPushManagerEvent()); + SysTryReturnVoidResult(NID_NET_NFC, pNdefPushManagerEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + result r = __pSystemAdapter->AddNdefPushManagerImpl(*this); + SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to add the callack to _NfcSystemAdapter."); + + __pNdefPushManagerEvent = move(pNdefPushManagerEvent); +} + +_NdefPushManagerImpl::~_NdefPushManagerImpl(void) +{ + if (__pSystemAdapter != null) + { + __pSystemAdapter->RemoveNdefPushManagerImpl(*this); + __pSystemAdapter = null; + } +} + +result +_NdefPushManagerImpl::SetNdefPushManagerListener(INdefPushManagerListener* pListener) +{ + result r = E_SUCCESS; + + if (__pPreviousListener) + { + if (pListener) + { + __pNdefPushManagerEvent->RemoveListener(*__pPreviousListener); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Failed to add the callback to _NfcSystemAdapter. [%s]", GetErrorMessage(r)); + } + __pPreviousListener = null; + } + + if (pListener) + { + r = __pNdefPushManagerEvent->AddListener(*pListener); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Failed to add the callback to _NfcSystemAdapter. [%s]", GetErrorMessage(r)); + __pPreviousListener = pListener; + } + + return r; +} + +result +_NdefPushManagerImpl::Push(const NdefMessage& message) +{ + result r = E_SUCCESS; + + r = __pSystemAdapter->Push(message); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, + "[%s] Failed to send the NDEF message.", GetErrorMessage(r)); + + return r; +} + +void +_NdefPushManagerImpl::OnNdefPushMessageSent(result r) +{ + _NdefPushManagerEventArg* pArg = null; + + pArg = new (std::nothrow) _NdefPushManagerEventArg(r); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + if (__pNdefPushManagerEvent) + { + __pNdefPushManagerEvent->Fire(*pArg); + } +} + +result +_NdefPushManagerImpl::RegisterNdefPushMessage(const NdefMessage& message, const Tizen::Base::String& description) +{ + result r = E_SUCCESS; + _NfcIpcProxy* pProxy = null; + ByteBuffer* pMessageBuffer = null; + + SysTryReturnResult(NID_NET_NFC, message.GetRecordsCount() != 0, E_INVALID_ARG, + "Invalid argument is used. NDEF message does not contain any NDEF records"); + + pProxy = _NfcIpcProxy::GetInstance(); + SysTryReturnResult(NID_NET_NFC, pProxy != null, E_SYSTEM, "Creating _NfcIpcProxy has failed."); + + pMessageBuffer = _NdefMessageUtil::ToByteBufferN(message); + SysTryReturn(NID_NET_NFC, pMessageBuffer != null, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r)); + + r = pProxy->RegisterNdefPushMessage(*pMessageBuffer, description); + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, E_SYSTEM, "[E_SYSTEM] Registering the NDEF push message has failed."); + } + else + { + SysLog(NID_NET_NFC, "Registering the NDEF push message is successful."); + } + + delete pMessageBuffer; + + return r; +} + +result +_NdefPushManagerImpl::UnregisterNdefPushMessage(void) +{ + result r = E_SUCCESS; + _NfcIpcProxy* pProxy = null; + + pProxy = _NfcIpcProxy::GetInstance(); + SysTryReturnResult(NID_NET_NFC, pProxy != null, E_SYSTEM, "Creating _NfcIpcProxy has failed."); + + r = pProxy->UnregisterNdefPushMessage(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Unregistering the NDEF push message has failed."); + + SysLog(NID_NET_NFC, "Unregistering the NDEF push message is successful."); + + return E_SUCCESS; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefRecordImpl.cpp b/src/FNetNfc_NdefRecordImpl.cpp new file mode 100644 index 0000000..53cd440 --- /dev/null +++ b/src/FNetNfc_NdefRecordImpl.cpp @@ -0,0 +1,277 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefRecordImpl.cpp +// @brief This is the implementation file for _NdefRecordImpl class. +// +// This file contains the implementation of _NdefRecordImpl class. +// + +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NdefRecordImpl.h" +#include "FNetNfc_NdefMessageUtil.h" +#include "FNetNfc_NdefMessageImpl.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Text; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefRecordImpl::_NdefRecordImpl(void) + : __type() + , __id() + , __pPayload(null) + , __pMessageImpl(null) +{ +} + +_NdefRecordImpl::_NdefRecordImpl(const NdefRecordType& recordType) + : __type(recordType) + , __id() + , __pPayload(null) + , __pMessageImpl(null) +{ +} + +_NdefRecordImpl::_NdefRecordImpl(const _NdefRecordImpl& value) + : __type(value.__type) + , __id(value.__id) + , __pPayload(null) + , __pMessageImpl(null) +{ + (void) CopyPayloadFrom(value.__pPayload.get()); +} + +_NdefRecordImpl::~_NdefRecordImpl(void) +{ + +} + +bool +_NdefRecordImpl::Equals(const Tizen::Base::Object& obj) const +{ + const _NdefRecordImpl* pOther = dynamic_cast (&obj); + + if (pOther == null) + { + return false; + } + + if (pOther == this) + { + return true; + } + + if ((__type.Equals(pOther->__type) == true) && (__id.Equals(pOther->__id) == true)) + { + if ((__pPayload == null) && (pOther->__pPayload == null)) + { + return true; + } + else if ((__pPayload != null) && (pOther->__pPayload != null)) + { + return __pPayload->Equals(*(pOther->__pPayload)); + } + } + + return false; +} + +int +_NdefRecordImpl::GetHashCode(void) const +{ + int value = 0; + + value = __type.GetHashCode(); + value ^= __id.GetHashCode(); + value ^= __pPayload->GetHashCode(); + + return value; +} + +Tizen::Base::String +_NdefRecordImpl::GetPayloadId(void) const +{ + return __id; +} + +Tizen::Base::ByteBuffer* +_NdefRecordImpl::GetPayload(void) const +{ + return __pPayload.get(); +} + +NdefRecordType +_NdefRecordImpl::GetRecordType(void) const +{ + return __type; +} + +result +_NdefRecordImpl::SetRecordType(NdefRecordType& type) +{ + NdefRecordTypeNameFormat tnf = type.GetNameFormat(); + + if (tnf == NDEF_TNF_ALL) + { + return E_INVALID_ARG; + } + else if (tnf == NDEF_TNF_EMPTY) + { + if ((__id.GetLength() > 0) || (__pPayload != null)) + { + return E_INVALID_ARG; + } + } + + __type = type; + + return E_SUCCESS; +} + +result +_NdefRecordImpl::SetPayloadId(const Tizen::Base::String& id) +{ + result r = E_SUCCESS; + NdefRecord* pNdefRecord = null; + + TryReturn( + __type.GetNameFormat() != NDEF_TNF_EMPTY, E_INVALID_OPERATION, + "[E_INVALID_OPERATION] The record type is NDEF_TNF_EMPTY."); + + TryReturn(id.GetLength() < 256, E_MAX_EXCEEDED, "[E_MAX_EXCEEDED] The length of the id should be less than 256."); + + if (id.IsEmpty() == false) + { + // check if id includes non US-ASCII character or not + AsciiEncoding ascii; + ByteBuffer* pBuff = ascii.GetBytesN(id); + r = GetLastResult(); + TryReturn(pBuff != null, E_INVALID_ENCODING_RANGE, + "[E_INVALID_ENCODING_RANGE] Name contains characters outside US-ASCII range"); + delete pBuff; + + // checks the uniqueness of id among all records in the NDEF message and return E_INVALID_ARG. + if (__pMessageImpl != null) + { + pNdefRecord = __pMessageImpl->GetRecord(id); + TryReturn((pNdefRecord == null || pNdefRecord->__pImpl == this), E_INVALID_ARG, + "[E_INVALID_ARG] Invalid argument is used. The id already exists in the other records of the same NDEF message."); + } + } + __id = id; + + return r; +} + +result +_NdefRecordImpl::SetPayload(const Tizen::Base::ByteBuffer& payload) +{ + result r = E_SUCCESS; + unique_ptr pTempPayload; + + TryReturn(__type.GetNameFormat() != NDEF_TNF_EMPTY, E_INVALID_OPERATION, + "[E_INVALID_OPERATION] The record type is NDEF_TNF_EMPTY"); + + pTempPayload.reset(new (std::nothrow) ByteBuffer()); + TryReturn(pTempPayload != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + // Propagates the result (E_SUCCESS or E_INVALID_ARG) + r = pTempPayload->Construct(payload); + + if (r == E_SUCCESS) + { + //makes the position same as that of specified payload + pTempPayload->SetPosition(payload.GetPosition()); + + __pPayload.reset(pTempPayload.release()); + } + + return r; +} + +void +_NdefRecordImpl::SetMessageImpl(const NdefRecord& record, const _NdefMessageImpl* pNdefMessageImpl) +{ + record.__pImpl->__pMessageImpl = const_cast <_NdefMessageImpl*>(pNdefMessageImpl); +} + +_NdefRecordImpl& +_NdefRecordImpl::operator =(const _NdefRecordImpl& rhs) +{ + result r = E_SUCCESS; + + if (this != &rhs) + { + r = CopyPayloadFrom(rhs.__pPayload.get()); + + if (!IsFailed(r)) + { + __type = rhs.__type; + __id = rhs.__id; + } + } + + return *this; +} + +result +_NdefRecordImpl::CopyPayloadFrom(const Tizen::Base::ByteBuffer* pPayload) +{ + ByteBuffer tempView; + std::unique_ptr pNewPayload; + result r = E_SUCCESS; + + if (pPayload) + { + // Creates view of payload to use CopyFrom. + tempView.Construct(*pPayload); + + // Creates a new payload from the view. + unique_ptr pNewPayload(new (std::nothrow) ByteBuffer); + + if (pNewPayload) + { + pNewPayload->Construct(pPayload->GetCapacity()); + pNewPayload->CopyFrom(tempView); + pNewPayload->SetPosition(pPayload->GetPosition()); + pNewPayload->SetLimit(pPayload->GetLimit()); + + // Changes the member variable to the new payload after completely generated. + __pPayload.reset(pNewPayload.release()); + } + else + { + r = E_OUT_OF_MEMORY; + SysLogException(NID_NET_NFC, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + } + } + else + { + __pPayload.reset(); + } + + return r; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NdefRecordTypeImpl.cpp b/src/FNetNfc_NdefRecordTypeImpl.cpp new file mode 100644 index 0000000..51f9faf --- /dev/null +++ b/src/FNetNfc_NdefRecordTypeImpl.cpp @@ -0,0 +1,274 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNdefRecordTypeImpl.cpp +// @brief This is the implementation file for _NdefRecordTypeImpl class. +// +// This file contains the implementation of _NdefRecordTypeImpl class. +// + +#include +#include +#include +#include +#include +#include "FNetNfc_NdefRecordTypeImpl.h" +#include "FNetNfc_NdefMessageUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Utility; +using namespace Tizen::Text; + +static const String NDEF_TNF_WELL_KNOWN_PREFIX("urn:nfc:wkt:"); +static const String NDEF_TNF_EXTERNAL_PREFIX("urn:nfc:ext:"); + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NdefRecordTypeImpl::_NdefRecordTypeImpl(void) + : __format(NDEF_TNF_EMPTY) + , __name(L"") +{ +} + +_NdefRecordTypeImpl::_NdefRecordTypeImpl(NdefRecordTypeNameFormat format) + : __format(format) + , __name(L"") +{ +} + +_NdefRecordTypeImpl::_NdefRecordTypeImpl(const _NdefRecordTypeImpl& value) + : __format(value.__format) + , __name(value.__name) +{ +} + +_NdefRecordTypeImpl::~_NdefRecordTypeImpl(void) +{ +} + +_NdefRecordTypeImpl& +_NdefRecordTypeImpl::operator =(const _NdefRecordTypeImpl& rhs) +{ + if (this != &rhs) + { + __format = rhs.__format; + __name = rhs.__name; + } + + return *this; +} + + +bool +_NdefRecordTypeImpl::Equals(const Tizen::Base::Object& obj) const +{ + int index1 = 0; + int index2 = 0; + String subType1; + String subType2; + Uri uri1; + Uri uri2; + result r = E_SUCCESS; + + const NdefRecordType* pTarget = dynamic_cast (&obj); + + if (pTarget == null) + { + return false; // Invalid class type; fails to down-cast Object to NdefRecordType instance + } + + NdefRecordTypeNameFormat format = pTarget->GetNameFormat(); + String name = pTarget->GetName(); + + if (__format != format) + { + return false; + } + + switch (format) + { + case NDEF_TNF_WELL_KNOWN: + // character-by-character in case-sensitive manner. + return name.Equals(__name, true); + + case NDEF_TNF_MIME_MEDIA: + // character-by-character in case-insensitive manner up to the first ";" + r = name.IndexOf(';', 0, index1); + r = __name.IndexOf(';', 0, index2); + + if (index1 != -1 && index2 != -1) + { + r = name.SubString(0, index1, subType1); + r = __name.SubString(0, index2, subType2); + return subType1.Equals(subType2, false); + } + else if (index1 != -1) + { + r = name.SubString(0, index1, subType1); + return subType1.Equals(__name, false); + + } + else if (index2 != -1) + { + r = __name.SubString(0, index2, subType2); + return name.Equals(subType2, false); + } + else + { + return name.Equals(__name, false); + } + + break; + + // Reserved characters must be percent-encoded and the hexadecimal digits in those normalized to upper-case letters. + // URI The scheme and host parts of the URI must be normalized to lower-case. + // After this the URIs are compared in the character-by-character in case-sensitive manner + case NDEF_TNF_ABSOLUTE_URI: + // should be implemented + r = uri1.SetUri(name); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, false, r, "[%s] URI error has been occurred.", GetErrorMessage(r)); + r = uri2.SetUri(__name); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, false, r, "[%s] URI error has been occurred.", GetErrorMessage(r)); + return uri1.Equals(uri2); + + // character-by-character in case-insensitive manner + case NDEF_TNF_EXTERNAL: + if (name.Equals(__name, false)) + { + return true; + } + break; + + // Both record type names must be empty string + case NDEF_TNF_EMPTY: + case NDEF_TNF_UNKNOWN: + case NDEF_TNF_ALL: + if (name.IsEmpty() == true && __name.IsEmpty() == true) + { + return true; + } + break; + + default: + return false; + } + return false; + +} + +// HashCode value MUST be equal if the Record type is equal +int +_NdefRecordTypeImpl::GetHashCode() const +{ + int index1 = 0; + String name1; + Uri uri1; + result r = E_SUCCESS; + + switch (__format) + { + case NDEF_TNF_WELL_KNOWN: + return __name.GetHashCode() ^ __format; + + case NDEF_TNF_MIME_MEDIA: + r = __name.IndexOf(';', 0, index1); + + if (r == E_SUCCESS) + { + r = __name.SubString(0, index1, name1); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, -1, r, "[%s] MIME type error has been occurred.", GetErrorMessage(r)); + name1.ToLowerCase(); + } + else + { + r = __name.ToLowerCase(name1); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, -1, r, "[%s] MIME type error has been occurred.", GetErrorMessage(r)); + } + + return name1.GetHashCode() ^ __format; + + case NDEF_TNF_ABSOLUTE_URI: + // should be implemented + r = uri1.SetUri(__name); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, -1, r, "[%s] URI type error has been occurred.", GetErrorMessage(r)); + return uri1.GetHashCode() ^ __format; + + // character-by-character in case-insensitive manner + case NDEF_TNF_EXTERNAL: + r = __name.ToLowerCase(name1); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, -1, r, "[%s] External type error has been occurred.", GetErrorMessage(r)); + return name1.GetHashCode() ^ __format; + + // Both record type names must be empty string + case NDEF_TNF_EMPTY: + case NDEF_TNF_UNKNOWN: + case NDEF_TNF_ALL: + return __format; + + default: + return -1; + } +} + +NdefRecordTypeNameFormat +_NdefRecordTypeImpl::GetNameFormat() const +{ + return __format; +} + +Tizen::Base::String +_NdefRecordTypeImpl::GetName() const +{ + return __name; +} + +result +_NdefRecordTypeImpl::SetName(const Tizen::Base::String& name) +{ + bool isValid = false; + AsciiEncoding ascii; + ByteBuffer* pBuff = null; + + TryReturn((__format != NDEF_TNF_EMPTY) && (__format != NDEF_TNF_UNKNOWN) && (__format != NDEF_TNF_ALL), + E_INVALID_OPERATION, "[E_INVALID_OPERATION] The record type is NDEF_TNF_EMPTY or NDEF_TNF_UNKNOWN"); + + TryReturn(name.GetLength() < 256, E_MAX_EXCEEDED, "[E_MAX_EXCEEDED] The length of the name should be less than 256"); + + if (name.IsEmpty()) + { + SysLogException(NID_NET_NFC, E_INVALID_FORMAT, "[E_INVALID_FORMAT] The type name to be set is an empty string."); + return E_INVALID_FORMAT; + } + else + { + // check if name includes non US-ASCII character or not + pBuff = ascii.GetBytesN(name); + TryReturn(pBuff != null, E_INVALID_ENCODING_RANGE, + "[E_INVALID_ENCODING_RANGE] Name contains characters outside US-ASCII range"); + delete pBuff; + + isValid = _NdefMessageUtil::IsValidRecordType(__format, name); + TryReturn(isValid == true, E_INVALID_FORMAT, "[E_INVALID_FORMAT] Invalid name"); + + } + + __name = name; + + return E_SUCCESS; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcAuthorityController.cpp b/src/FNetNfc_NfcAuthorityController.cpp new file mode 100644 index 0000000..7a65bd0 --- /dev/null +++ b/src/FNetNfc_NfcAuthorityController.cpp @@ -0,0 +1,165 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// @file FNetNfcNfcLaunchPopupController.cpp +// @brief This is the implementation file for the __NfcAuthorityController Class. +// +// This file contains the implementation of the __NfcAuthorityController Class. +// +#include +#include +#include +#include "FNetNfc_NfcIpcProxy.h" +#include "FNetNfc_NfcAuthorityController.h" + +using namespace std; +using namespace Tizen::App; + +namespace Tizen { namespace Net { namespace Nfc { + +_NfcAuthorityController* _NfcAuthorityController::__pSingleton = null; + +_NfcAuthorityController::_NfcAuthorityController(void) + : __popupEnabled(true) + , __pIpcProxy(null) + , __currentAppId() + , __isActive(false) +{ +} + +_NfcAuthorityController::~_NfcAuthorityController(void) +{ + _AppManagerImpl::GetInstance()->RemoveActiveAppEventListener(*this); + __pSingleton = null; +} + +void +_NfcAuthorityController::InitSingleton(void) +{ + unique_ptr<_NfcAuthorityController> pInst(new (std::nothrow) _NfcAuthorityController()); + SysTryReturnVoidResult(NID_NET_NFC, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + result r = pInst->Construct(); + SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + __pSingleton = pInst.release(); + std::atexit(DestroySingleton); +} + +void +_NfcAuthorityController::DestroySingleton(void) +{ + delete __pSingleton; +} + +_NfcAuthorityController* +_NfcAuthorityController::GetInstance(void) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + + if (!__pSingleton) + { + ClearLastResult(); + pthread_once(&onceBlock, InitSingleton); + result r = GetLastResult(); + if (IsFailed(r)) + { + onceBlock = PTHREAD_ONCE_INIT; + } + } + + return __pSingleton; +} + +result +_NfcAuthorityController::Construct(void) +{ + result r = E_SUCCESS; + AppId activeAppId; + + __pIpcProxy = _NfcIpcProxy::GetInstance(); + SysTryReturnResult(NID_NET_NFC, __pIpcProxy != null, E_SYSTEM, "Failed to create _NfcIpcProxy."); + + r = __pIpcProxy->InitializeNfc(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, + "Failed to initialize the NFC service of osp-connectivity-service."); + + __currentAppId = Tizen::App::App::GetInstance()->GetAppId(); + _AppManagerImpl::GetInstance()->GetActiveApp(activeAppId); + + if (__currentAppId.Equals(activeAppId)) + { + __isActive = true; + } + + _AppManagerImpl::GetInstance()->AddActiveAppEventListener(*this); + + return E_SUCCESS; +} + +result +_NfcAuthorityController::SetLaunchPopupEnabled(bool enable) +{ + result r = E_SUCCESS; + + if (__popupEnabled != enable) + { + // set the enabling option immediately if the current app is the active app which includes the active window + if (__isActive) + { + r = __pIpcProxy->SetLaunchPopupEnabled(enable); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Propagating."); + + __popupEnabled = enable; + } + else + { + // the enabling option will be applied when the application is active (appears on foreground). + __popupEnabled = enable; + } + } + + return r; +} + +void +_NfcAuthorityController::OnActiveAppChanged(const Tizen::App::AppId& appId) +{ + result r = E_SUCCESS; + + if (!__popupEnabled) // the actual setting is processed only if the enable option is 'disable' + { + if (__currentAppId.Equals(appId)) // when the application becomes active (appears on foreground) + { + __isActive = true; + + // set the launch popup disabled + r = __pIpcProxy->SetLaunchPopupEnabled(false); + SysLog(NID_NET_NFC, "Disabling the NFC launch popup %s.", IsFailed(r) ? "fails" : "is successful"); + } + else if (__isActive) // when the application becomes deactive (disappears from foreground). + { + __isActive = false; + + // set the launch popup enabled + r = __pIpcProxy->SetLaunchPopupEnabled(true); + SysLog(NID_NET_NFC, "Enabling the NFC launch popup %s.", IsFailed(r) ? "fails" : "is successful"); + } + } +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcAuthorityController.h b/src/FNetNfc_NfcAuthorityController.h new file mode 100644 index 0000000..d084d19 --- /dev/null +++ b/src/FNetNfc_NfcAuthorityController.h @@ -0,0 +1,101 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NfcAuthorityController.h + * @brief This is the header file for the %_NfcAuthorityController class. + * + * This header file contains the declarations of the %_NfcAuthorityController class. + */ + +#ifndef _FNET_NFC_INTERNAL_NFC_AUTHORITY_CONTROLLER_H_ +#define _FNET_NFC_INTERNAL_NFC_AUTHORITY_CONTROLLER_H_ + +#include +#include +#include +#include +#include +#include + +namespace Tizen { namespace App { +class _AppManagerImpl; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NfcIpcProxy; + +/** + * @class _NfcAuthorityController + * @brief This class represents an authority controller for an NFC application. + * + * This class especially controls the application's authority related to the underlying NFC subsystem + * according to the foreground/background state of the application. + */ +class _NfcAuthorityController + : public Tizen::App::IActiveAppEventListener +{ +public: + /** + * Creates an instance of this class if there is no instance in this application context. + * Gets the exist instance, otherwise because this class is a singleton. + * + * @return the instance of this class + */ + static _NfcAuthorityController* GetInstance(void); + + /** + * Enables or disables the NFC Conditional %App Launch popup. + * + * @return An error code + * @param[in] enable Set to true, to enable the NFC Conditional %App Launch popup @n + * false, otherwise + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + */ + result SetLaunchPopupEnabled(bool enable); + + /** + * Callback method which implements IActiveAppEventListner + */ + virtual void OnActiveAppChanged(const Tizen::App::AppId& appId); + +private: + _NfcAuthorityController(void); + virtual ~_NfcAuthorityController(void); + result Construct(void); + static void InitSingleton(void); + static void DestroySingleton(void); + + + _NfcAuthorityController(const _NfcAuthorityController& value); + _NfcAuthorityController& operator =(const _NfcAuthorityController& rhs); + +private: + bool __popupEnabled; + _NfcIpcProxy* __pIpcProxy; + Tizen::App::AppId __currentAppId; + bool __isActive; + static _NfcAuthorityController* __pSingleton; + +friend class std::default_delete<_NfcAuthorityController>; +}; // _NfcAuthorityController + +} } } +#endif // _FNET_NFC_INTERNAL_NFC_AUTHORITY_CONTROLLER_H_ diff --git a/src/FNetNfc_NfcDeviceDiscoveryEvent.cpp b/src/FNetNfc_NfcDeviceDiscoveryEvent.cpp new file mode 100644 index 0000000..ed01d04 --- /dev/null +++ b/src/FNetNfc_NfcDeviceDiscoveryEvent.cpp @@ -0,0 +1,75 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NfcDeviceDiscoveryEvent.cpp +// @brief This is the implementation file for _NfcDeviceDiscoveryEvent class. +// +// This file contains the implementation of _NfcDeviceDiscoveryEvent class. +// + +#include +#include +#include +#include +#include "FNetNfc_NfcDeviceDiscoveryEvent.h" +#include "FNetNfc_NfcDeviceDiscoveryEventArg.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NfcDeviceDiscoveryEvent::_NfcDeviceDiscoveryEvent(void) +{ +} + +_NfcDeviceDiscoveryEvent::~_NfcDeviceDiscoveryEvent(void) +{ +} + +result +_NfcDeviceDiscoveryEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_NfcDeviceDiscoveryEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + _NfcDeviceDiscoveryEventType type; + + INfcDeviceDiscoveryEventListener* pEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_NET_NFC, pEventListener != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + const _NfcDeviceDiscoveryEventArg* pEventArg = dynamic_cast (&arg); + SysTryReturnVoidResult(NID_NET_NFC, pEventArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + type = pEventArg->GetType(); + + switch (type) + { + case _NFC_DEVICE_DISCOVERY_EVENT_TYPE_DETECTED: + pEventListener->OnNfcDeviceDetected(); + break; + + case _NFC_DEVICE_DISCOVERY_EVENT_TYPE_LOST: + pEventListener->OnNfcDeviceLost(); + break; + + default: + break; + } +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcDeviceDiscoveryEvent.h b/src/FNetNfc_NfcDeviceDiscoveryEvent.h new file mode 100644 index 0000000..e3bec45 --- /dev/null +++ b/src/FNetNfc_NfcDeviceDiscoveryEvent.h @@ -0,0 +1,84 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NfcDeviceDiscoveryEvent.h + * @brief This is the header file for the _NfcDeviceDiscoveryEvent class. + * + * This header file contains declaration of the _NfcDeviceDiscoveryEvent class. + * The _NfcDeviceDiscoveryEvent class can call methods of a INfcDeviceDiscoveryEventListener class. + */ +#ifndef _FNET_NFC_INTERNAL_NFC_DEVICE_DISCOVERY_EVENT_H_ +#define _FNET_NFC_INTERNAL_NFC_DEVICE_DISCOVERY_EVENT_H_ + +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base { namespace Runtime +{ +class IEventArg; +class IEventListener; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @class _NfcDeviceDiscoveryEvent + * @brief This class handles the events related to the discovery of NFC P2P device. + * + * When a NFC P2P device is discovered, the _NfcDeviceDiscoveryEvent object finds a INfcDeviceDiscoveryEventListener object and + * calls an appropriate method of the listener. + */ +class _NfcDeviceDiscoveryEvent + : public Tizen::Base::Runtime::_Event +{ +public: + /** + * This is the default constructor. + */ + _NfcDeviceDiscoveryEvent(); + + /** + * This is the class destructor. + */ + virtual ~_NfcDeviceDiscoveryEvent(void); + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + +protected: + /** + * Calls the specified listener's method with the specified argument when event is generated. + * + * @param[in] listener The event listener which will be received the event + * @param[in] arg The event argument to be passed by + */ + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _NfcDeviceDiscoveryEvent(const _NfcDeviceDiscoveryEvent& value); + _NfcDeviceDiscoveryEvent& operator =(const _NfcDeviceDiscoveryEvent& value); + +}; // _NfcDeviceDiscoveryEvent + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NFC_DEVICE_DISCOVERY_EVENT_H_ diff --git a/src/FNetNfc_NfcDeviceDiscoveryEventArg.cpp b/src/FNetNfc_NfcDeviceDiscoveryEventArg.cpp new file mode 100644 index 0000000..e2f0d22 --- /dev/null +++ b/src/FNetNfc_NfcDeviceDiscoveryEventArg.cpp @@ -0,0 +1,52 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NfcDeviceDiscoveryEventArg.cpp +// @brief This is the implementation file for _NfcDeviceDiscoveryEventArg class. +// +// This file contains the implementation of _NfcDeviceDiscoveryEventArg class. +// + +#include +#include +#include +#include +#include "FNetNfc_NfcDeviceDiscoveryEventArg.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NfcDeviceDiscoveryEventArg::_NfcDeviceDiscoveryEventArg(void) + : __eventType(_NFC_DEVICE_DISCOVERY_EVENT_TYPE_LOST) +{ +} + +_NfcDeviceDiscoveryEventArg::_NfcDeviceDiscoveryEventArg(_NfcDeviceDiscoveryEventType type) + : __eventType(type) +{ +} + +_NfcDeviceDiscoveryEventArg::~_NfcDeviceDiscoveryEventArg(void) +{ +} + +_NfcDeviceDiscoveryEventType +_NfcDeviceDiscoveryEventArg::GetType(void) const +{ + return __eventType; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcDeviceDiscoveryEventArg.h b/src/FNetNfc_NfcDeviceDiscoveryEventArg.h new file mode 100644 index 0000000..963699f --- /dev/null +++ b/src/FNetNfc_NfcDeviceDiscoveryEventArg.h @@ -0,0 +1,90 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NfcDeviceDiscoveryEventArg.h + * @brief This is the header file for the _NfcDeviceDiscoveryEventArg class. + * + * This header file contains declaration of the _NfcDeviceDiscoveryEventArg class. + */ +#ifndef _FNET_NFC_INTERNAL_NFC_DEVICE_DISCOVERY_EVENT_ARG_H_ +#define _FNET_NFC_INTERNAL_NFC_DEVICE_DISCOVERY_EVENT_ARG_H_ + +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @enum _NfcDeviceDiscoveryEventType + * + * Type for specifying the device event + */ +enum _NfcDeviceDiscoveryEventType +{ + _NFC_DEVICE_DISCOVERY_EVENT_TYPE_DETECTED, /**< For notifying NFC device detected */ + _NFC_DEVICE_DISCOVERY_EVENT_TYPE_LOST /**< For notifying NFC device lost */ +}; + + +/** + * @class _NfcDeviceDiscoveryEventArg + * @brief This class is used as an argument of methods of the _NfcDeviceDiscoveryEvent class. + * + * When a P2P device is discovered, the INfcDeviceDiscoveryEventListener objects registered to the event are called + * with this argument class. + */ +class _NfcDeviceDiscoveryEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ +public: + /** + * This is the constructor. + */ + _NfcDeviceDiscoveryEventArg(void); + + /** + * This is the constructor. + * + * @param[in] type The device discovery event type + */ + _NfcDeviceDiscoveryEventArg(_NfcDeviceDiscoveryEventType type); + + /** + * This is the class destructor. + */ + ~_NfcDeviceDiscoveryEventArg(void); + + /** + * Gets the device discovery event type. + * + * @return The device discovery event type + */ + _NfcDeviceDiscoveryEventType GetType(void) const; + +private: + _NfcDeviceDiscoveryEventArg(const _NfcDeviceDiscoveryEventArg& rhs); + _NfcDeviceDiscoveryEventArg& operator =(const _NfcDeviceDiscoveryEventArg& rhs); + +private: + _NfcDeviceDiscoveryEventType __eventType; +}; // _NfcDeviceDiscoveryEventArg + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NFC_DEVICE_DISCOVERY_EVENT_ARG_H_ diff --git a/src/FNetNfc_NfcIpcMessages.cpp b/src/FNetNfc_NfcIpcMessages.cpp new file mode 100644 index 0000000..89064cf --- /dev/null +++ b/src/FNetNfc_NfcIpcMessages.cpp @@ -0,0 +1,44 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FNetNfc_NfcIpcMessages + * @brief This is the generator of IPC messages for the Connectivity service daemon. + */ + +#define IPC_MESSAGE_IMPL +#include "FNetNfc_ConnectivityIpcMessages.h" + +// Generate constructors. +#include +#include "FNetNfc_ConnectivityIpcMessages.h" + +// Generate destructors. +#include +#include "FNetNfc_ConnectivityIpcMessages.h" + +// Generate param traits write methods. +#include +namespace IPC { +#include "FNetNfc_ConnectivityIpcMessages.h" +} // namespace IPC + +// Generate param traits read methods. +#include +namespace IPC { +#include "FNetNfc_ConnectivityIpcMessages.h" +} // namespace IPC diff --git a/src/FNetNfc_NfcIpcProxy.cpp b/src/FNetNfc_NfcIpcProxy.cpp new file mode 100644 index 0000000..6d5bda0 --- /dev/null +++ b/src/FNetNfc_NfcIpcProxy.cpp @@ -0,0 +1,181 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// @file FNetNfc_NfcIpcProxy.cpp +// @brief This is the implementation file for the %_NfcIpcProxy class. +// +// This file contains the implementation of the %_NfcIpcProxy class. +// + +#include +#include +#include +#include +#include "FNetNfc_NfcIpcProxy.h" +#include "FNetNfc_ConnectivityIpcMessages.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Io; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NfcIpcProxy* _NfcIpcProxy::__pSingleton = null; + +_NfcIpcProxy::_NfcIpcProxy(void) : + __pIpcClient(null) +{ +} + +_NfcIpcProxy::~_NfcIpcProxy(void) +{ + delete __pIpcClient; +} + +result +_NfcIpcProxy::Construct(void) +{ + result r = E_SUCCESS; + + unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient); + SysTryReturnResult(NID_NET_NFC, pIpcClient != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pIpcClient->Construct(NFC_CONNECTIVITY_IPC_SERVER_NAME, null); + + SysLog(NID_NET_NFC, "An instance of the Nfc IPC Proxy has been constructed."); + + __pIpcClient = pIpcClient.release(); + + return r; +} + +void +_NfcIpcProxy::InitSingleton(void) +{ + unique_ptr<_NfcIpcProxy> pInst(new (std::nothrow) _NfcIpcProxy()); + SysTryReturnVoidResult(NID_NET_NFC, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + result r = pInst->Construct(); + SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + __pSingleton = pInst.release(); + std::atexit(DestroySingleton); +} + +void +_NfcIpcProxy::DestroySingleton(void) +{ + delete __pSingleton; +} + +_NfcIpcProxy* +_NfcIpcProxy::GetInstance(void) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + + if (!__pSingleton) + { + ClearLastResult(); + pthread_once(&onceBlock, InitSingleton); + result r = GetLastResult(); + if (IsFailed(r)) + { + onceBlock = PTHREAD_ONCE_INIT; + } + } + + return __pSingleton; +} + +result +_NfcIpcProxy::InitializeNfc(void) const +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) ConnectivityNfcServiceMsg_initialize(&ret); + SysTryReturnResult(NID_NET_NFC, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS && ret == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_NET_NFC, "Initializing the NFC of osp-connectivity-service through IPC is successful."); + + return E_SUCCESS; +} + +result +_NfcIpcProxy::SetLaunchPopupEnabled(bool enable) const +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) ConnectivityNfcServiceMsg_setLaunchPopupEnabled(enable, &ret); + SysTryReturnResult(NID_NET_NFC, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS && ret == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_NET_NFC, "Setting the NFC popup enabled option through IPC is successful."); + + return ret; +} + +result +_NfcIpcProxy::RegisterNdefPushMessage(const Tizen::Base::ByteBuffer& message, const Tizen::Base::String& description) const +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) ConnectivityNfcServiceMsg_registerPushMessage(message, description, &ret); + SysTryReturnResult(NID_NET_NFC, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS && ret == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_NET_NFC, "Registering the NDEF push message to osp-connectivity-service through IPC is successful."); + + return E_SUCCESS; +} + +result +_NfcIpcProxy::UnregisterNdefPushMessage(void) const +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) ConnectivityNfcServiceMsg_unregisterPushMessage(&ret); + SysTryReturnResult(NID_NET_NFC, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS && ret == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_NET_NFC, "Unregistering the NDEF push message from osp-connectivity-service through IPC is successful."); + + return E_SUCCESS; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcIpcProxy.h b/src/FNetNfc_NfcIpcProxy.h new file mode 100644 index 0000000..5c1823d --- /dev/null +++ b/src/FNetNfc_NfcIpcProxy.h @@ -0,0 +1,124 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NfcIpcProxy.h + * @brief This is the header file for the %_NfcIpcProxy class. + * + * This header file contains the declarations of the %_NfcIpcProxy class. + */ + +#ifndef _FNET_NFC_INTERNAL_NFC_IPC_PROXY_H_ +#define _FNET_NFC_INTERNAL_NFC_IPC_PROXY_H_ + +#include +#include +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Io +{ +class _IpcClient; +} } + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +class String; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @class _NfcIpcProxy + * @brief This class represents an IPC proxy for %Nfc service. + * + * This class represents an IPC proxy for %Nfc service to communicate with Connectivity service daemon. + */ +class _NfcIpcProxy + : public Tizen::Base::Object +{ +public: + /** + * Gets the instance. + * + * @return The pointer to %_NfcIpcProxy + */ + static _NfcIpcProxy* GetInstance(void); + + /** + * Initialize Nfc of osp-connectivity-service daemon using IPC Proxy. + * + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + */ + result InitializeNfc(void) const; + + /** + * Sets the enabling option of NFC Conditional Launch Popup using IPC Proxy. + * + * @return An error code + * @param[in] enable Set to @c true to enable the Conditional NFC App Launch pop-up, @n + * @c else false + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + */ + result SetLaunchPopupEnabled(bool enable) const; + + /** + * Registers an NDEF message to be pushed if the home screen or the main menu is on top of the screen in the local + * device when a peer device is detected. + * + * @return An error code + * @param[in] message The NDEF message to be registered + * @param[in] description The description for the NDEF message to be registered + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + */ + result RegisterNdefPushMessage(const Tizen::Base::ByteBuffer& message, const Tizen::Base::String& description) const; + + /** + * Unregisters an NDEF message if the NDEF message to be pushed is registered. + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + */ + result UnregisterNdefPushMessage(void) const; + +private: + _NfcIpcProxy(void); + virtual ~_NfcIpcProxy(void); + result Construct(void); + static void InitSingleton(void); + static void DestroySingleton(void); + + _NfcIpcProxy(const _NfcIpcProxy& value); + _NfcIpcProxy& operator =(const _NfcIpcProxy& rhs); + +private: + Tizen::Io::_IpcClient* __pIpcClient; + static _NfcIpcProxy* __pSingleton; + friend class std::default_delete< _NfcIpcProxy >; +}; // _NfcIpcProxy + +} } } +#endif // _FNET_NFC_INTERNAL_NFC_IPC_PROXY_H_ diff --git a/src/FNetNfc_NfcManagerEvent.cpp b/src/FNetNfc_NfcManagerEvent.cpp new file mode 100644 index 0000000..66615bd --- /dev/null +++ b/src/FNetNfc_NfcManagerEvent.cpp @@ -0,0 +1,77 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcManagerEvent.cpp +// @brief This is the implementation file for _NfcManagerEvent class. +// +// This file contains the implementation of _NfcManagerEvent class. +// + +#include +#include +#include +#include "FNetNfc_NfcManagerEvent.h" +#include "FNetNfc_NfcManagerEventArg.h" +#include "FNetNfcINfcManagerEventListener.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NfcManagerEvent::_NfcManagerEvent(void) +{ +} + +_NfcManagerEvent::~_NfcManagerEvent(void) +{ +} + +result +_NfcManagerEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_NfcManagerEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + _NfcManagerEventType status; + result r = E_SUCCESS; + + INfcManagerEventListener* pEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_NET_NFC, pEventListener != null, E_SYSTEM, "[E_SYSTEM] Failed to get the listener."); + + const _NfcManagerEventArg* pEventArg = dynamic_cast (&arg); + SysTryReturnVoidResult(NID_NET_NFC, pEventArg != null, E_SYSTEM, "[E_SYSTEM] Failed to get the listener argument."); + + status = pEventArg->GetEventType(); + r = pEventArg->GetResult(); + + switch (status) + { + case _NFC_MGR_EVENT_TYPE_ACTIVATED: + pEventListener->OnNfcActivated(r); + break; + + case _NFC_MGR_EVENT_TYPE_DEACTIVATED: + pEventListener->OnNfcDeactivated(r); + break; + + default: + break; + } +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcManagerEvent.h b/src/FNetNfc_NfcManagerEvent.h new file mode 100644 index 0000000..1d14d80 --- /dev/null +++ b/src/FNetNfc_NfcManagerEvent.h @@ -0,0 +1,88 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNfcManagerEvent.h + * @brief This is the header file for the _NfcManagerEvent class. + * + * This header file contains declaration of the _NfcManagerEvent class. + * The _NfcManagerEvent class can call methods of a INfcManagerEventListener class. + */ +#ifndef _FNET_NFC_INTERNAL_NFC_MANAGER_EVENT_H_ +#define _FNET_NFC_INTERNAL_NFC_MANAGER_EVENT_H_ + +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base { namespace Runtime +{ +class IEventArg; +class IEventListener; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @class _NfcManagerEvent + * @brief This class handles the events related to the NFC Manager(Agent) status. + * + * When the NFC Manager's status is changed, the _NfcManagerEvent object finds a INfcManagerEventListener object and + * calls an appropriate method of the listener. + */ +class _NfcManagerEvent + : public Tizen::Base::Runtime::_Event +{ +public: + /** + * This is the default constructor. + * + * @remarks After creating an instance of this class, you must explicitly call the construction method to + * initialize the instance. + * @see Construct + */ + _NfcManagerEvent(); + + /** + * This is the class destructor. + */ + virtual ~_NfcManagerEvent(void); + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + +protected: + /** + * Calls the specified listener's method with the specified argument when event is generated. + * + * @param[in] listener The event listener which will be received the event + * @param[in] arg The event argument to be passed by + */ + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _NfcManagerEvent(const _NfcManagerEvent& value); + _NfcManagerEvent& operator =(const _NfcManagerEvent& value); + +}; // _NfcManagerEvent + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NFC_MANAGER_EVENT_H_ diff --git a/src/FNetNfc_NfcManagerEventArg.cpp b/src/FNetNfc_NfcManagerEventArg.cpp new file mode 100644 index 0000000..d3e48de --- /dev/null +++ b/src/FNetNfc_NfcManagerEventArg.cpp @@ -0,0 +1,53 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcManagerEventArg.h +// @brief This is the implementation file for _NfcManagerEventArg Class. +// +// This file contains the implementation of _NfcManagerEventArg Class. +// + +#include "FNetNfc_NfcManagerEventArg.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +// +// This is a class constructor for _NFC_MGR_EVENT_TYPE_ACTIVATED and _NFC_MGR_EVENT_TYPE_DEACTIVATED event. +// +_NfcManagerEventArg::_NfcManagerEventArg(_NfcManagerEventType type, result r) + : __type(type) + , __result(r) +{ +} + +_NfcManagerEventArg::~_NfcManagerEventArg(void) +{ +} + +_NfcManagerEventType +_NfcManagerEventArg::GetEventType(void) const +{ + return __type; +} + +result +_NfcManagerEventArg::GetResult(void) const +{ + return __result; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcManagerEventArg.h b/src/FNetNfc_NfcManagerEventArg.h new file mode 100644 index 0000000..4c15bfe --- /dev/null +++ b/src/FNetNfc_NfcManagerEventArg.h @@ -0,0 +1,98 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcManagerEventArg.h + * @brief This is the header file for the _NfcManagerEventArg class. + * + * This header file contains declaration of the _NfcManagerEventArg class. + */ +#ifndef _FNET_NFC_INTERNAL_NFC_MANAGER_EVENT_ARG_H_ +#define _FNET_NFC_INTERNAL_NFC_MANAGER_EVENT_ARG_H_ + +#include +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @enum _NfcManagerEventType + * + * Type for specifying the type of NFC status + */ +enum _NfcManagerEventType +{ + _NFC_MGR_EVENT_TYPE_ACTIVATED, /**< For notifying activation */ + _NFC_MGR_EVENT_TYPE_DEACTIVATED /**< For notifying deactivation */ +}; + +/** + * @class _NfcManagerEventArg + * @brief This class is used as an argument of methods of the _NfcManagerEvent class. + * + * When the NFC Manager's status is changed, the INfcManagerEventListener objects registered to the event are called + * with this argument class. + */ +class _NfcManagerEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ +public: + /** + * This is a class constructor for _NFC_MGR_EVENT_TYPE_ACTIVATED and _NFC_MGR_EVENT_TYPE_DEACTIVATED event. + * + * @param[in] type The type of the event + * @param[in] r The result of the event + * @exception E_SUCCESS The action was successful. + * @exception E_SYSTEM The action failed due to a system error. + */ + _NfcManagerEventArg(_NfcManagerEventType type, result r); + + /** + * This is the class destructor. + * + */ + ~_NfcManagerEventArg(void); + + /** + * Gets the tag event type. + * + * @return The type of the event + */ + _NfcManagerEventType GetEventType(void) const; + + /** + * Gets the action result. + * + * @return The error code + */ + result GetResult(void) const; + +private: + _NfcManagerEventArg(const _NfcManagerEventArg& value); + _NfcManagerEventArg& operator =(const _NfcManagerEventArg& value); + +private: + _NfcManagerEventType __type; + result __result; + +}; // _NfcManagerEventArg + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NFC_MANAGER_EVENT_ARG_H_ diff --git a/src/FNetNfc_NfcManagerImpl.cpp b/src/FNetNfc_NfcManagerImpl.cpp new file mode 100644 index 0000000..b98d1fd --- /dev/null +++ b/src/FNetNfc_NfcManagerImpl.cpp @@ -0,0 +1,1118 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNfcManagerAgent.cpp +// @brief This is the implementation file for _NfcManagerAgent class. +// +// This file contains the implementation of _NfcManagerAgent class. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NfcManagerImpl.h" +#include "FNetNfc_NfcManagerEvent.h" +#include "FNetNfc_NfcManagerEventArg.h" +#include "FNetNfc_NfcTagDiscoveryEvent.h" +#include "FNetNfc_NfcTagDiscoveryEventArg.h" +#include "FNetNfc_NdefMessageDiscoveryEvent.h" +#include "FNetNfc_NdefMessageDiscoveryEventArg.h" +#include "FNetNfc_NdefMessageUtil.h" +#include "FNetNfc_NfcTagImpl.h" +#include "FNetNfc_TagConnectionImpl.h" +#include "FNetNfc_NfcAuthorityController.h" +#include "FNetNfc_NfcSystemAdapter.h" +#include "FNetNfc_NfcDeviceDiscoveryEvent.h" +#include "FNetNfc_NfcDeviceDiscoveryEventArg.h" + + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Net { namespace Nfc +{ + +typedef HashMapT _NfcTagEventMap; +typedef IMapEnumeratorT _NfcTagEventMapEnumerator; +typedef HashMapT _NdefMsgEventMap; +typedef IMapEnumeratorT _NdefMsgEventMapEnumerator; + +_NfcManagerImpl::_NfcManagerImpl(void) + : __pSystemAdapter(null) + , __pCurrentTagImpl(null) + , __pMgrEvent(null) + , __pTagConditionMap(null) + , __pNdefConditionMap(null) + , __pDeviceDiscoveryEvent(null) + , __stateMutex() + , __currentState(_NFC_MANAGER_STATE_DISABLED) +{ +} + +_NfcManagerImpl::~_NfcManagerImpl(void) +{ + if (__pSystemAdapter != null) + { + // Removes the callback from _NfcSystemManager : for Device Event + __pSystemAdapter->RemoveNfcManagerImpl(*this); + } + + delete __pCurrentTagImpl; + delete __pMgrEvent; + delete __pTagConditionMap; + delete __pNdefConditionMap; + delete __pDeviceDiscoveryEvent; +} + +result +_NfcManagerImpl::Construct(INfcManagerEventListener& listener) +{ + result r = E_SUCCESS; + unique_ptr pTagConditionMap; + unique_ptr pNdefConditionMap; + unique_ptr<_NfcManagerEvent> pMgrEvent; + unique_ptr<_NfcDeviceDiscoveryEvent> pDevEvent; + + r = __stateMutex.Create(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to create the state mutex."); + + // Create the Mananger Event and add the specified listener to it + pMgrEvent.reset(new (std::nothrow) _NfcManagerEvent()); + SysTryReturnResult(NID_NET_NFC, pMgrEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pMgrEvent->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Construct of an event instance failed."); + + r = pMgrEvent->AddListener(listener, true); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Adding a new listener has failed."); + + // Create the Device Discovery Event + pDevEvent.reset(new (std::nothrow) _NfcDeviceDiscoveryEvent()); + SysTryReturnResult(NID_NET_NFC, pDevEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pDevEvent->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Construct of an event instance failed."); + + // Create the tag condition map which includes a TNF value as the key (condition) and an event map as the value. + pTagConditionMap.reset(new (std::nothrow) HashMap(SingleObjectDeleter)); + SysTryReturnResult(NID_NET_NFC, pTagConditionMap != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pTagConditionMap->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construct of the tag condition map failed."); + + // Create the NDEF condition map which includes a NDEF record type as the key (condition) and an event map as the value. + pNdefConditionMap.reset(new (std::nothrow) HashMap(SingleObjectDeleter)); + SysTryReturnResult(NID_NET_NFC, pNdefConditionMap != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pNdefConditionMap->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construct of the NDEF condition map failed."); + + // Create the NfcSystemAdapter + __pSystemAdapter = _NfcSystemAdapter::GetInstance(); + SysTryReturnResult(NID_NET_NFC, __pSystemAdapter != null, E_SYSTEM, "Failed to get the instance of _NfcSystemAdapter."); + + // Adds the callback to _NfcSystemManager + r = __pSystemAdapter->AddNfcManagerImpl(*this); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to register the callback to _NfcSystemAdapter."); + + // get the current state of the manager + __stateMutex.Acquire(); + + if (__pSystemAdapter->IsActivated()) + { + if (__pSystemAdapter->IsTagConnected()) + { + __currentState = _NFC_MANAGER_STATE_CONNECTED; + + // get the target tag if it is connected with the device + __pCurrentTagImpl = __pSystemAdapter->GetCurrentTagImplN(); + if (__pCurrentTagImpl) + { + // display the information of the connected tag + PrintTag(*__pCurrentTagImpl); + } + else + { + SysLog(NID_NET_NFC, "Failed to get the connected tag in spite of the connected state!\n"); + } + } + else if (__pSystemAdapter->IsDeviceDetected()) + { + __currentState = _NFC_MANAGER_STATE_CONNECTED; + } + else + { + __currentState = _NFC_MANAGER_STATE_IDLE; + } + } + + __stateMutex.Release(); + + __pMgrEvent = pMgrEvent.release(); + __pDeviceDiscoveryEvent = pDevEvent.release(); + __pTagConditionMap = pTagConditionMap.release(); + __pNdefConditionMap = pNdefConditionMap.release(); + + return E_SUCCESS; +} + +result +_NfcManagerImpl::Activate(void) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + result r = E_SUCCESS; + + __stateMutex.Acquire(); + + switch (__currentState) + { + case _NFC_MANAGER_STATE_DISABLED: + r = __pSystemAdapter->Activate(); + if (r == E_SUCCESS) + { + __currentState = _NFC_MANAGER_STATE_ACTIVATING; + } + break; + + case _NFC_MANAGER_STATE_ACTIVATING: + r = E_IN_PROGRESS; + break; + + default: + r = E_INVALID_OPERATION; + break; + } + + __stateMutex.Release(); + + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred on activating NFC.", GetErrorMessage(r)); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + return r; +} + +result +_NfcManagerImpl::Deactivate(void) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + result r = E_SUCCESS; + + __stateMutex.Acquire(); + + switch (__currentState) + { + case _NFC_MANAGER_STATE_IDLE: + case _NFC_MANAGER_STATE_CONNECTED: + r = __pSystemAdapter->Deactivate(); + if (r == E_SUCCESS) + { + __currentState = _NFC_MANAGER_STATE_DEACTIVATING; + } + break; + + case _NFC_MANAGER_STATE_DEACTIVATING: + r = E_IN_PROGRESS; + break; + + default: + r = E_INVALID_OPERATION; + break; + } + + __stateMutex.Release(); + + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred on deactivating NFC.", GetErrorMessage(r)); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + return r; +} + +bool +_NfcManagerImpl::IsActivated(void) const +{ + if ((__currentState == _NFC_MANAGER_STATE_IDLE) || (__currentState == _NFC_MANAGER_STATE_CONNECTED)) + { + return true; + } + else + { + return false; + } +} + +bool +_NfcManagerImpl::IsTagConnected(void) const +{ + if ((__currentState == _NFC_MANAGER_STATE_CONNECTED) && (__pSystemAdapter->IsTagConnected())) + { + return true; + } + else + { + return false; + } +} + +bool +_NfcManagerImpl::IsDeviceDetected(void) const +{ + if ((__currentState == _NFC_MANAGER_STATE_CONNECTED) && (__pSystemAdapter->IsDeviceDetected())) + { + return true; + } + else + { + return false; + } +} + +TagConnection* +_NfcManagerImpl::GetCurrentTagConnectionN(void) const +{ + TagConnection* pCurrentConnection = null; + + ClearLastResult(); + + SysTryReturn(NID_NET_NFC, IsActivated(), null, E_INVALID_STATE, "[E_INVALID_STATE] NFC is not activated."); + SysTryReturn(NID_NET_NFC, (IsTagConnected() && __pCurrentTagImpl), null, E_CONNECTION_FAILED, + "[E_CONNECTION_FAILED] Connection to the tag is lost."); + + pCurrentConnection = _TagConnectionImpl::GetTagConnectionN(*__pCurrentTagImpl); + SysTryReturn(NID_NET_NFC, pCurrentConnection != null, null, E_SYSTEM, "[E_SYSTEM] System error occurred."); + + return pCurrentConnection; +} + +result +_NfcManagerImpl::AddTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type) +{ + result r = E_SUCCESS; + _NfcTagEventMap* pEventMap = null; + + pEventMap = dynamic_cast <_NfcTagEventMap*> (__pTagConditionMap->GetValue(Integer(type))); + + if (pEventMap == null) + { + // this condition - the specified tag type - is registered first time, + // therefore, create a new event map which is related with the specified tag type. + unique_ptr<_NfcTagEventMap> pNewEventMap(new (std::nothrow) _NfcTagEventMap()); + SysTryReturnResult(NID_NET_NFC, pNewEventMap != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pNewEventMap->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construct of an event map instance failed."); + + unique_ptr pKey(new (std::nothrow) Integer(type)); + SysTryReturnResult(NID_NET_NFC, pKey != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pTagConditionMap->Add(*pKey, *pNewEventMap); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Internal map error. Adding a new event map has failed."); + + pKey.release(); + pEventMap = pNewEventMap.release(); + } + else + { + // if the event instance with the specified listener already exists, the adding operation fails + // because only one listener can be added in the event. + _NfcTagDiscoveryEvent* pEvent = null; + r = pEventMap->GetValue(&listener, pEvent); + SysTryReturnResult(NID_NET_NFC, pEvent == null, E_OBJ_ALREADY_EXIST, + "The listener with the specified type was already added."); + } + + unique_ptr<_NfcTagDiscoveryEvent> pNewEvent(new (std::nothrow) _NfcTagDiscoveryEvent()); + SysTryReturnResult(NID_NET_NFC, pNewEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pNewEvent->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construct of an event instance failed."); + + // add a new event to the event map. + // this event must include only the specified listener. + r = pNewEvent->AddListener(listener, true); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Adding a new listener has failed."); + + r = pEventMap->Add(&listener, pNewEvent.get()); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Internal map error. Adding a new listener has failed."); + + pNewEvent.release(); + + return E_SUCCESS; +} + +result +_NfcManagerImpl::RemoveTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type) +{ + result r = E_SUCCESS; + _NfcTagEventMap* pEventMap = null; + _NfcTagDiscoveryEvent* pEvent = null; + + // find the event map which is related with the specified tag type. + pEventMap = dynamic_cast <_NfcTagEventMap*> (__pTagConditionMap->GetValue(Integer(type))); + SysTryReturnResult(NID_NET_NFC, pEventMap != null, E_OBJ_NOT_FOUND, "The listener with the specified type was not found."); + + // find the event which is related with the specified listener. + r = pEventMap->GetValue(&listener, pEvent); + SysTryReturnResult(NID_NET_NFC, r != E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "The listener with the specified type was not found."); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Removing the listener has failed."); + + // remove the event from the event map. + r = pEventMap->Remove(&listener); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Removing the listener has failed."); + + delete pEvent; + + // if the event map has no event, delete it from the condition map. + if (pEventMap->GetCount() == 0) + { + (void) __pTagConditionMap->Remove(Integer(type)); // ignore the result of removal + } + + return E_SUCCESS; +} + +result +_NfcManagerImpl::AddNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, + const NdefRecordType& recordType) +{ + result r = E_SUCCESS; + _NdefMsgEventMap* pEventMap = null; + + NdefRecordTypeNameFormat tnf = recordType.GetNameFormat(); + if ((tnf == NDEF_TNF_WELL_KNOWN) || (tnf == NDEF_TNF_MIME_MEDIA) || + (tnf == NDEF_TNF_ABSOLUTE_URI) || (tnf == NDEF_TNF_EXTERNAL)) + { + SysTryReturnResult(NID_NET_NFC, recordType.GetName().IsEmpty() == false, E_INVALID_ARG, + "The empty string as a record type name is not allowed."); + } + + pEventMap = dynamic_cast <_NdefMsgEventMap*> (__pNdefConditionMap->GetValue(recordType)); + + if (pEventMap == null) + { + // this condition - the specified record type - is registered first time, + // therefore, create a new event map which is related with the specified record type. + unique_ptr<_NdefMsgEventMap> pNewEventMap(new (std::nothrow) _NdefMsgEventMap()); + SysTryReturnResult(NID_NET_NFC, pNewEventMap != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pNewEventMap->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construct of an event map instance failed."); + + unique_ptr pKey(new (std::nothrow) NdefRecordType(recordType)); + SysTryReturnResult(NID_NET_NFC, pKey != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pNdefConditionMap->Add(*pKey, *pNewEventMap); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Internal map error. Adding a new event map has failed."); + + pKey.release(); + pEventMap = pNewEventMap.release(); + } + else + { + // if the event instance with the specified listner already exists, the adding operation fails + // because only one listener can be added in the event. + _NdefMessageDiscoveryEvent* pEvent = null; + r = pEventMap->GetValue(&listener, pEvent); + SysTryReturnResult(NID_NET_NFC, pEvent == null, E_OBJ_ALREADY_EXIST, + "The listener with the specified type was already added."); + } + + unique_ptr<_NdefMessageDiscoveryEvent> pNewEvent(new (std::nothrow) _NdefMessageDiscoveryEvent()); + SysTryReturnResult(NID_NET_NFC, pNewEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = pNewEvent->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construct of an event instance failed."); + + // add a new event to the event map. + // this event must include only the specified listener. + r = pNewEvent->AddListener(listener, true); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Adding a new listener has failed."); + + r = pEventMap->Add(&listener, pNewEvent.get()); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Internal map error. Adding a new listener has failed."); + + pNewEvent.release(); + + return E_SUCCESS; +} + +result +_NfcManagerImpl::RemoveNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, + const NdefRecordType& recordType) +{ + result r = E_SUCCESS; + _NdefMsgEventMap* pEventMap = null; + _NdefMessageDiscoveryEvent* pEvent = null; + + NdefRecordTypeNameFormat tnf = recordType.GetNameFormat(); + if ((tnf == NDEF_TNF_WELL_KNOWN) || (tnf == NDEF_TNF_MIME_MEDIA) || + (tnf == NDEF_TNF_ABSOLUTE_URI) || (tnf == NDEF_TNF_EXTERNAL)) + { + SysTryReturnResult(NID_NET_NFC, recordType.GetName().IsEmpty() == false, E_INVALID_ARG, + "The empty string as a record type name is not allowed."); + } + + // find the event map which is related with the specified record type. + pEventMap = dynamic_cast <_NdefMsgEventMap*> (__pNdefConditionMap->GetValue(recordType)); + SysTryReturnResult(NID_NET_NFC, pEventMap != null, E_OBJ_NOT_FOUND, "The listener with the specified type was not found."); + + // find the event which is related with the specified listener. + r = pEventMap->GetValue(&listener, pEvent); + SysTryReturnResult(NID_NET_NFC, r != E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "The listener with the specified type was not found."); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Removing the listener has failed."); + + // remove the event from the event map. + r = pEventMap->Remove(&listener); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Removing the listener has failed."); + + delete pEvent; + + // if the event map has no event, delete it from the condition map. + if (pEventMap->GetCount() == 0) + { + (void) __pNdefConditionMap->Remove(recordType); // ignore the result of removal + } + + return E_SUCCESS; +} + +result +_NfcManagerImpl::AddDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener) +{ + result r = E_SUCCESS; + + r = __pDeviceDiscoveryEvent->AddListener(listener, true); + SysTryReturnResult(NID_NET_NFC, r != E_OBJ_ALREADY_EXIST, r, "The listener was already added."); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Adding a new listener has failed."); + + return E_SUCCESS; +} + +result +_NfcManagerImpl::RemoveDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener) +{ + result r = E_SUCCESS; + + r = __pDeviceDiscoveryEvent->RemoveListener(listener); + SysTryReturnResult(NID_NET_NFC, r != E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "The listener was not found."); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Removing the listener has failed."); + + return E_SUCCESS; +} + +void +_NfcManagerImpl::OnNfcActivated(result r) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + bool isFired = false; + + __stateMutex.Acquire(); + + switch (__currentState) + { + case _NFC_MANAGER_STATE_DISABLED: + if (r == E_SUCCESS) + { + __currentState = _NFC_MANAGER_STATE_IDLE; + isFired = true; + } + break; + + case _NFC_MANAGER_STATE_ACTIVATING: + if (r == E_SUCCESS) + { + __currentState = _NFC_MANAGER_STATE_IDLE; + } + else + { + __currentState = _NFC_MANAGER_STATE_DISABLED; + } + isFired = true; + break; + + default: + break; + } + + __stateMutex.Release(); + + if (isFired) + { + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred during activating NFC.", GetErrorMessage(r)); + } + + _NfcManagerEventArg* pArg = new (std::nothrow) _NfcManagerEventArg(_NFC_MGR_EVENT_TYPE_ACTIVATED, r); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->Fire(*pArg); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [ACTIVATED_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_NfcManagerImpl::OnNfcDeactivated(result r) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + bool isFired = false; + + __stateMutex.Acquire(); + + switch (__currentState) + { + case _NFC_MANAGER_STATE_IDLE: + case _NFC_MANAGER_STATE_CONNECTED: + if (r == E_SUCCESS) + { + __currentState = _NFC_MANAGER_STATE_DISABLED; + isFired = true; + } + break; + + case _NFC_MANAGER_STATE_DEACTIVATING: + if (r == E_SUCCESS) + { + __currentState = _NFC_MANAGER_STATE_DISABLED; + } + else + { + __currentState = _NFC_MANAGER_STATE_IDLE; + } + isFired = true; + break; + + default: + break; + } + + __stateMutex.Release(); + + if (isFired) + { + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred during deactivating NFC.", GetErrorMessage(r)); + } + + _NfcManagerEventArg* pArg = new (std::nothrow) _NfcManagerEventArg(_NFC_MGR_EVENT_TYPE_DEACTIVATED, r); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + __pMgrEvent->Fire(*pArg); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [DEACTIVATED_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_NfcManagerImpl::OnNfcTagDetectedN(Tizen::Net::Nfc::_NfcTagImpl* pTagImpl) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + bool isFired = false; + + // changes the current state and state information. + __stateMutex.Acquire(); + + if (__currentState == _NFC_MANAGER_STATE_IDLE) + { + __currentState = _NFC_MANAGER_STATE_CONNECTED; + __pCurrentTagImpl = pTagImpl; + isFired = true; + } + // ignore the event in other states + + __stateMutex.Release(); + + if (isFired) + { + // display the information of the connected tag + PrintTag(*pTagImpl); + // send events to listeners + isFired = SendTagDiscoveryEvent(pTagImpl, true); + } + else + { + delete pTagImpl; + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [TAG_DETECTED_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_NfcManagerImpl::OnNfcTagLost(void) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + bool isFired = false; + _NfcTagImpl* pTagImpl = null; + + __stateMutex.Acquire(); + + if (__currentState == _NFC_MANAGER_STATE_CONNECTED) + { + __currentState = _NFC_MANAGER_STATE_IDLE; + pTagImpl = __pCurrentTagImpl; + __pCurrentTagImpl = null; + } + else if (__currentState == _NFC_MANAGER_STATE_DEACTIVATING) + { + pTagImpl = __pCurrentTagImpl; + __pCurrentTagImpl = null; + } + // ignore the event in other states + + __stateMutex.Release(); + + if (pTagImpl != null) + { + // send events to listeners + isFired = SendTagDiscoveryEvent(pTagImpl, false); + delete pTagImpl; + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [TAG_LOST_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_NfcManagerImpl::OnNdefMessageDetectedN(NdefMessage* pMessage) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + bool isFired = false; + + if ((__currentState == _NFC_MANAGER_STATE_DEACTIVATING) + || (__currentState == _NFC_MANAGER_STATE_IDLE) + || (__currentState == _NFC_MANAGER_STATE_CONNECTED)) + { + isFired = SendNdefMessageDetectedEvent(*pMessage); + } + + delete pMessage; + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [MSG_DETECTED_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_NfcManagerImpl::OnNfcDeviceDetected(void) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + bool isFired = false; + + __stateMutex.Acquire(); + + if (__currentState == _NFC_MANAGER_STATE_IDLE) + { + __currentState = _NFC_MANAGER_STATE_CONNECTED; + isFired = true; + } + // ignore the event in other states + + __stateMutex.Release(); + + if (isFired) + { + _NfcDeviceDiscoveryEventArg* pArg = new (std::nothrow) + _NfcDeviceDiscoveryEventArg(_NFC_DEVICE_DISCOVERY_EVENT_TYPE_DETECTED); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + __pDeviceDiscoveryEvent->Fire(*pArg); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [DEV_DETECTED_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_NfcManagerImpl::OnNfcDeviceLost(void) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + bool isFired = false; + + __stateMutex.Acquire(); + + if (__currentState == _NFC_MANAGER_STATE_CONNECTED) + { + __currentState = _NFC_MANAGER_STATE_IDLE; + isFired = true; + } + // ignore the event in other states + + __stateMutex.Release(); + + if (isFired) + { + _NfcDeviceDiscoveryEventArg* pArg = new (std::nothrow) _NfcDeviceDiscoveryEventArg(_NFC_DEVICE_DISCOVERY_EVENT_TYPE_LOST); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + __pDeviceDiscoveryEvent->Fire(*pArg); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [DEV_LOST_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +NdefMessage* +_NfcManagerImpl::GetCachedNdefMessageN(void) +{ + // TODO: access control + return _NfcSystemAdapter::GetCachedNdefMessageN(); +} + +result +_NfcManagerImpl::SetLaunchPopupEnabled(bool enable) +{ + result r = E_SYSTEM; + _NfcAuthorityController* pController = null; + + pController = _NfcAuthorityController::GetInstance(); + + if (pController) + { + r = pController->SetLaunchPopupEnabled(enable); + } + + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, r, r, "[%s] error occurred on %s the launch popup.", + GetErrorMessage(r), enable ? "enabling" : "disabling"); + + return E_SUCCESS; +} + +bool +_NfcManagerImpl::SendTagDiscoveryEvent(_NfcTagImpl* pTagImpl, bool isDetected) +{ + result r = E_SUCCESS; + bool isFired = false; + _NfcTagEventMap* pEventMap = null; + ArrayListT conditionList; + LinkedListT firedList; + + // make the list which includes all conditions related to this tag. + r = conditionList.Construct(*(pTagImpl->GetTagTypeList())); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Internal list error."); + + if (pTagImpl->IsNdefSupported()) + { + conditionList.Add(NFC_TAG_TYPE_ALL_NDEF_COMPATIBLE); + } + conditionList.Add(NFC_TAG_TYPE_ALL); + + unique_ptr< IEnumeratorT > pConditionEnum(conditionList.GetEnumeratorN()); + // interate all related tag types and notify events for each tag type + while (pConditionEnum->MoveNext() == E_SUCCESS) + { + NfcTagType type; + pConditionEnum->GetCurrent(type); + + pEventMap = dynamic_cast <_NfcTagEventMap*> (__pTagConditionMap->GetValue(Integer(type))); + if (pEventMap != null) + { + unique_ptr<_NfcTagEventMapEnumerator> pEventMapEnum(pEventMap->GetMapEnumeratorN()); + while (pEventMapEnum->MoveNext() == E_SUCCESS) + { + INfcTagDiscoveryEventListener* pListener = null; + pEventMapEnum->GetKey(pListener); + + if (firedList.Contains(pListener) == false) + { + _NfcTagDiscoveryEvent* pEvent = null; + pEventMapEnum->GetValue(pEvent); + + // make the event arg instance + _NfcTagDiscoveryEventArg* pArg = null; + if (isDetected) + { + pArg = new (std::nothrow) _NfcTagDiscoveryEventArg(*pTagImpl); // for the detected event + } + else + { + pArg = new (std::nothrow) _NfcTagDiscoveryEventArg(); // for the lost event + } + SysTryReturn(NID_NET_NFC, pArg != null, false, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Memory allocation failed."); + + // fire the event if the listener is found in at first time + pEvent->Fire(*pArg); + firedList.Add(pListener); + } + } + + isFired = true; + } + } + + return isFired; +} + +bool +_NfcManagerImpl::SendNdefMessageDetectedEvent(NdefMessage& message) +{ + bool isFired = false; + _NdefMsgEventMap* pEventMap = null; + LinkedList conditionList(SingleObjectDeleter); + LinkedListT firedList; + + // make the list which includes all conditions related to this tag. + int recordCount = message.GetRecordsCount(); + + for (int i = 0; i < recordCount; i++) + { + const NdefRecord* pRecord = message.GetRecordAt(i); + NdefRecordType recordType = pRecord->GetRecordType(); + + // get all equivalent record type which are the same condition as this record type. + IList* pKeyList = _NdefMessageUtil::GetEquivalentRecordTypesN(recordType); + SysTryReturn(NID_NET_NFC, pKeyList != null, false, E_SYSTEM, "[E_SYSTEM] Getting equivalent record types failed."); + + (void) conditionList.AddItems(*pKeyList); // shallow copy, ignore the result. + delete pKeyList; + } + + NdefRecordType* pAllRecordType = new NdefRecordType(NDEF_TNF_ALL); + SysTryReturn(NID_NET_NFC, pAllRecordType != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + conditionList.Add(*pAllRecordType); + + unique_ptr pConditionEnum(conditionList.GetEnumeratorN()); + // interate all related tag types and notify events for each tag type + while (pConditionEnum->MoveNext() == E_SUCCESS) + { + NdefRecordType* pType = dynamic_cast (pConditionEnum->GetCurrent()); + SysTryReturn(NID_NET_NFC, pType != null, false, E_SYSTEM, "[E_SYSTEM] Internal list error."); + + pEventMap = dynamic_cast <_NdefMsgEventMap*> (__pNdefConditionMap->GetValue(*pType)); + if (pEventMap != null) + { + unique_ptr<_NdefMsgEventMapEnumerator> pEventMapEnum(pEventMap->GetMapEnumeratorN()); + while (pEventMapEnum->MoveNext() == E_SUCCESS) + { + INdefMessageDiscoveryEventListener* pListener = null; + pEventMapEnum->GetKey(pListener); + + if (firedList.Contains(pListener) == false) + { + _NdefMessageDiscoveryEvent* pEvent = null; + pEventMapEnum->GetValue(pEvent); + + // make the event arg instance + _NdefMessageDiscoveryEventArg* pArg = null; + pArg = new (std::nothrow) _NdefMessageDiscoveryEventArg(message); + SysTryReturn(NID_NET_NFC, pArg != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + // fire the event if the listener is found in at first time + pEvent->Fire(*pArg); + firedList.Add(pListener); + } + } + + isFired = true; + } + } + + return isFired; +} + +const char* +_NfcManagerImpl::GetStringOfCurrentState(void) const +{ + const char* pStateString = null; + + switch (__currentState) + { + case _NFC_MANAGER_STATE_DISABLED: + pStateString = "DISABLED"; + break; + + case _NFC_MANAGER_STATE_ACTIVATING: + pStateString = "ACTIVATING"; + break; + + case _NFC_MANAGER_STATE_DEACTIVATING: + pStateString = "DEACTIVATING"; + break; + + case _NFC_MANAGER_STATE_IDLE: + pStateString = "IDLE"; + break; + + case _NFC_MANAGER_STATE_CONNECTED: + pStateString = "CONNECTED"; + break; + + default: + pStateString = ""; + break; + } + + return pStateString; +} + +const char* +_NfcManagerImpl::GetStringOfTagType(NfcTagType tagType) const +{ + const char* pTypeString = null; + + switch (tagType) + { + case NFC_TAG_TYPE_UNKNOWN: + pTypeString = "Unknown"; + break; + + case NFC_TAG_TYPE_ISO14443_3A: + pTypeString = "ISO14443-3A"; + break; + + case NFC_TAG_TYPE_ISO14443_3B: + pTypeString = "ISO14443-3B"; + break; + + case NFC_TAG_TYPE_FELICA: + pTypeString = "FeliCa"; + break; + + case NFC_TAG_TYPE_ISO15693: + pTypeString = "ISO15693"; + break; + + case NFC_TAG_TYPE_TOPAZ_JEWEL: + pTypeString = "Topaz/Jewel"; + break; + + case NFC_TAG_TYPE_MIFARE_UL: + pTypeString = "Mifare Ultralight"; + break; + + case NFC_TAG_TYPE_MIFARE_CLASSIC: + pTypeString = "Mifare Classic"; + break; + + case NFC_TAG_TYPE_ISO14443_4: + pTypeString = "ISO14443-4"; + break; + + case NFC_TAG_TYPE_FORUM_TYPE_1: + pTypeString = "Forum Type 1"; + break; + + case NFC_TAG_TYPE_FORUM_TYPE_2: + pTypeString = "Forum Type 2"; + break; + + case NFC_TAG_TYPE_FORUM_TYPE_3: + pTypeString = "Forum Type 3"; + break; + + case NFC_TAG_TYPE_FORUM_TYPE_4: + pTypeString = "Forum Type 4"; + break; + + case NFC_TAG_TYPE_ALL_NDEF_COMPATIBLE: + pTypeString = "All NDEF compatible types"; + break; + + case NFC_TAG_TYPE_ALL: + pTypeString = "All types"; + break; + + default: + pTypeString = ""; + break; + } + + return pTypeString; +} + +void +_NfcManagerImpl::ConvertByteToString(const Tizen::Base::ByteBuffer* pSrcBytes, Tizen::Base::String& hexString) const +{ + String tempHex; + byte b = 0x00; + int count = 0; + + hexString.Clear(); + count = pSrcBytes->GetRemaining(); + + for (int i = pSrcBytes->GetPosition(); i < count; i++) + { + pSrcBytes->GetByte(i, b); + tempHex.Format(3, L"%02X", b); + hexString.Append(tempHex); + hexString.Append(L" "); + } +} + +void +_NfcManagerImpl::PrintTag(const _NfcTagImpl& _tagImpl) const +{ + const ByteBuffer* pTagIdByte = null; + String tagIdStr(L"null"); + const IListT * pTagTypeList = null; + int count = 0; + NfcTagType tagType = NFC_TAG_TYPE_UNKNOWN; + + pTagIdByte = _tagImpl.GetId(); + if (pTagIdByte) + { + ConvertByteToString(pTagIdByte, tagIdStr); + } + SysLog(NID_NET_NFC, "[Tag] ID : %ls", tagIdStr.GetPointer()); + + pTagTypeList = _tagImpl.GetTagTypeList(); + count = pTagTypeList->GetCount(); + + for (int i = 0; i < count; i++) + { + pTagTypeList->GetAt(i, tagType); + SysLog(NID_NET_NFC, "[Tag] Type : %s", GetStringOfTagType(tagType)); + } + + SysLog(NID_NET_NFC, "[Tag] %s format", _tagImpl.IsNdefSupported() ? "NDEF" : "No NDEF"); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcSystemAdapter.cpp b/src/FNetNfc_NfcSystemAdapter.cpp new file mode 100644 index 0000000..7fb9b19 --- /dev/null +++ b/src/FNetNfc_NfcSystemAdapter.cpp @@ -0,0 +1,1002 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfc_NfcSystemAdapter.cpp +// @brief This is the implementation file for _NfcSystemAdapter class. +// +// This file contains the implementation of _NfcSystemAdapter class. +// + +#include +#include +#include +#include +#include +#include "FNetNfc_NfcSystemAdapter.h" +#include "FNetNfc_NfcManagerEvent.h" +#include "FNetNfc_NfcManagerEventArg.h" +#include "FNetNfc_TagConnectionEvent.h" +#include "FNetNfc_TagConnectionEventArg.h" +#include "FNetNfc_ITagConnectionListener.h" +#include "FNetNfc_NfcTagImpl.h" +#include "FNetNfc_NdefMessageUtil.h" +#include "FNetNfc_NfcManagerImpl.h" +#include "FNetNfc_NdefPushManagerImpl.h" + +#ifdef _NfcConvertErrorResult +#undef _NfcConvertErrorResult +#endif +#define _NfcConvertErrorResult(condition, r, value) \ + do \ + { \ + if (condition) { \ + r = value; \ + } \ + } while (0); + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Net::Nfc; + +_NfcSystemAdapter* _NfcSystemAdapter::__pSingleton = null; + +static const char* KEY_TAG_ID_ISO14443_3A = "UID"; +static const char* KEY_TAG_ID_ISO14443_3B = "UID"; +static const char* KEY_TAG_ID_FELICA = "IDm"; +static const char* KEY_TAG_ID_ISO15693 = "UID"; + +const bool _NFC_ACTIVATE = true; +const bool _NFC_DEACTIVATE = false; + + +namespace Tizen { namespace Net { namespace Nfc +{ +_NfcSystemAdapter::_NfcSystemAdapter(void) + : __pConnectionEvent(null) + , __pNfcManagerImplList(null) + , __pNdefPushManagerImplList(null) + , __tagHandle(null) + , __p2pTargetHandle(null) + , __pNfcTagImpl(null) + , __pTagValue(null) + , __valueSize(0) + , __isConnected(false) +{ +} + +_NfcSystemAdapter::~_NfcSystemAdapter(void) +{ + int res = NFC_ERROR_NONE; + + // unset callback + nfc_manager_unset_activation_changed_cb(); + nfc_manager_unset_tag_discovered_cb(); + nfc_manager_unset_ndef_discovered_cb(); + nfc_manager_unset_p2p_target_discovered_cb(); + + // deinitialize + res = nfc_manager_deinitialize(); + if (res != NFC_ERROR_NONE) + { + SysLogException(NID_NET_NFC, E_SYSTEM, "[E_SYSTEM] Failed to de-initialize the nfc manager [0x%08X]", res); + } + + __pSingleton = null; +} + +result +_NfcSystemAdapter::Construct(void) // private +{ + result r = E_SUCCESS; + int res = NFC_ERROR_NONE; + + unique_ptr<_TagConnectionEvent> pConnectionEvent(new (std::nothrow) _TagConnectionEvent()); + SysTryReturnResult(NID_NET_NFC, pConnectionEvent != null, E_OUT_OF_MEMORY, "Failure to create _Event instance."); + + r = pConnectionEvent->Construct(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Failure to create _Event instance."); + + unique_ptr pNfcManagerImplList(new (std::nothrow) LinkedList()); + SysTryReturnResult(NID_NET_NFC, pNfcManagerImplList != null, E_OUT_OF_MEMORY, "Failure to create LinkedList instance."); + + unique_ptr pNdefPushManagerImplList(new (std::nothrow) LinkedList()); + SysTryReturnResult(NID_NET_NFC, pNdefPushManagerImplList != null, E_OUT_OF_MEMORY, "Failure to create LinkedList instance."); + + // initialize the underlying system + res = nfc_manager_initialize(null, null); + SysTryReturnResult(NID_NET_NFC, res == NFC_ERROR_NONE, E_SYSTEM, "Failed to initialize the NFC from the result."); + + SysLog(NID_NET_NFC, "nfc_manager_initialize() is invoked successfully."); + + // set the response callback + nfc_manager_set_activation_changed_cb(&OnNfcActivationChanged, this); + nfc_manager_set_tag_discovered_cb(&OnNfcTagDiscovered, this); + nfc_manager_set_ndef_discovered_cb (&OnNdefMessageDiscovered, this); + nfc_manager_set_p2p_target_discovered_cb (&OnNfcTargetDiscovered, this); + + __pConnectionEvent = move(pConnectionEvent); + __pNfcManagerImplList = move(pNfcManagerImplList); + __pNdefPushManagerImplList = move(pNdefPushManagerImplList); + + return r; +} + +void +_NfcSystemAdapter::InitSingleton(void) +{ + unique_ptr<_NfcSystemAdapter> pInst(new (std::nothrow) _NfcSystemAdapter()); + SysTryReturnVoidResult(NID_NET_NFC, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + result r = pInst->Construct(); + SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r)); + + __pSingleton = pInst.release(); + std::atexit(DestroySingleton); +} + +void +_NfcSystemAdapter::DestroySingleton(void) +{ + delete __pSingleton; +} + +_NfcSystemAdapter* +_NfcSystemAdapter::GetInstance(void) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + + if (!__pSingleton) + { + ClearLastResult(); + pthread_once(&onceBlock, InitSingleton); + result r = GetLastResult(); + if (IsFailed(r)) + { + onceBlock = PTHREAD_ONCE_INIT; + } + } + + return __pSingleton; +} + +result +_NfcSystemAdapter::Activate(void) +{ + int res = NFC_ERROR_NONE; + + // turn on the NFC + res = nfc_manager_set_activation(_NFC_ACTIVATE, &OnNfcActivationCompleted, (void*)&_NFC_ACTIVATE); + SysTryReturnResult(NID_NET_NFC, res == NFC_ERROR_NONE, E_SYSTEM, "Failed to turn on the NFC [0x%08X]", res); + + SysLog(NID_NET_NFC, "nfc_manager_set_activation(true) is successful."); + + return E_SUCCESS; +} + +result +_NfcSystemAdapter::Deactivate(void) +{ + int res = NFC_ERROR_NONE; + + // turn off the NFC + res = nfc_manager_set_activation(_NFC_DEACTIVATE, &OnNfcActivationCompleted, (void*)&_NFC_DEACTIVATE); + SysTryReturnResult(NID_NET_NFC, res == NFC_ERROR_NONE, E_SYSTEM, "Failed to turn off the NFC [0x%08X]", res); + + SysLog(NID_NET_NFC, "nfc_manager_set_activation(false) is successful."); + + return E_SUCCESS; +} + +bool +_NfcSystemAdapter::IsActivated(void) const +{ + bool result = false; + + // get nfc state + result = nfc_manager_is_activated(); + + SysLog(NID_NET_NFC, "the result of nfc_manager_is_activated() is [%s].", result ? "true" : "false"); + + return result; +} + +bool +_NfcSystemAdapter::IsTagConnected(void) +{ + if (nfc_manager_get_connected_tag(&__tagHandle) != NFC_ERROR_NONE) + { + return false; + } + + return true; +} + +_NfcTagImpl* +_NfcSystemAdapter::GetCurrentTagImplN(void) +{ + int res = NFC_ERROR_NONE; + nfc_tag_h currentTag = null; + + res = nfc_manager_get_connected_tag(¤tTag); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Failed to get the connected Tag [0x%08X].", res); + + return new _NfcTagImpl(*(GetCurrentTag(currentTag))); +} + +result +_NfcSystemAdapter::RegisterTagConnectionListener(const _ITagConnectionListener& listener) +{ + result r = E_SUCCESS; + + SysTryReturnResult(NID_NET_NFC, __pConnectionEvent != null, E_SYSTEM, + "Failed to register _TagConnectionEvent. Check the Construct() was called or not."); + + r = __pConnectionEvent->AddListener(listener); + if (IsFailed(r)) + { + SysLogException(NID_NET_NFC, r, "[%s] Failed to register NFC tag connection listener.", GetErrorMessage(r)); + SysLog(NID_NET_NFC, "[%s] is converted to [E_SYSTEM]", GetErrorMessage(r)); + r = E_SYSTEM; + } + + return r; +} + +result +_NfcSystemAdapter::UnregisterTagConnectionListener(const _ITagConnectionListener& listener) +{ + result r = E_SUCCESS; + + SysTryReturnResult(NID_NET_NFC, __pConnectionEvent != null, E_OBJ_NOT_FOUND, "Failed to unregister _TagConnectionEvent."); + + r = __pConnectionEvent->RemoveListener(listener); + if (IsFailed(r)) + { + SysLogException(NID_NET_NFC, r, "[%s] Failed to remove NFC manager listener.", GetErrorMessage(r)); + } + + return r; +} + +result +_NfcSystemAdapter::AddNfcManagerImpl(const _NfcManagerImpl& nfcManagerImpl) +{ + result r = E_SUCCESS; + bool isContained = false; + + isContained = __pNfcManagerImplList->Contains(nfcManagerImpl); + SysTryReturnResult(NID_NET_NFC, isContained == false, E_OBJ_ALREADY_EXIST, "the _NfcManagerImpl instance is already added."); + + r = __pNfcManagerImplList->Add(nfcManagerImpl); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Propagating."); + + return r; +} + +result +_NfcSystemAdapter::RemoveNfcManagerImpl(const _NfcManagerImpl& nfcManagerImpl) +{ + result r = E_SUCCESS; + + r = __pNfcManagerImplList->Remove(nfcManagerImpl); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Propagating."); + + return r; +} + +result +_NfcSystemAdapter::AddNdefPushManagerImpl(const _NdefPushManagerImpl& ndefPushManagerImpl) +{ + result r = E_SUCCESS; + bool isContained = false; + + isContained = __pNdefPushManagerImplList->Contains(ndefPushManagerImpl); + SysTryReturnResult(NID_NET_NFC, isContained == false, E_OBJ_ALREADY_EXIST, + "the _NdefPushManagerImpl instance is already added."); + + r = __pNdefPushManagerImplList->Add(ndefPushManagerImpl); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Propagating."); + + return r; +} + +result +_NfcSystemAdapter::RemoveNdefPushManagerImpl(const _NdefPushManagerImpl& ndefPushManagerImpl) +{ + result r = E_SUCCESS; + + r = __pNdefPushManagerImplList->Remove(ndefPushManagerImpl); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Propagating."); + + return r; +} + +result +_NfcSystemAdapter::SendCommand(const Tizen::Base::ByteBuffer& command) +{ + // TODO: temporarily _NfcConnectionType will be ignored + result r = E_SYSTEM; + int res = NFC_ERROR_NONE; + int length = 0; + byte* pBuffer = null; + + length = command.GetRemaining(); + pBuffer = (byte*)(command.GetPointer()) + command.GetPosition(); + + // transceive a low level command + res = nfc_tag_transceive(__tagHandle, pBuffer, length, &OnNfcResponseReceived, null); + _NfcConvertErrorResult(res == NFC_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY, r, E_CONNECTION_BUSY); + _NfcConvertErrorResult(res == NFC_ERROR_TIMED_OUT, r, E_CONNECTION_FAILED); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Failed to transceive data. [0x%08X]", res); + + return E_SUCCESS; +} + +result +_NfcSystemAdapter::Read(void) +{ + result r = E_SYSTEM; + int res = NFC_ERROR_NONE; + + // read the tag + res = nfc_tag_read_ndef(__tagHandle, &OnNdefReadCompleted, null); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY, r, E_CONNECTION_BUSY); + _NfcConvertErrorResult(res == NFC_ERROR_TIMED_OUT, r, E_CONNECTION_FAILED); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Failed to read NDEF message. [0x%08X]", res); + + return E_SUCCESS; +} + +result +_NfcSystemAdapter::Write(const NdefMessage& message) +{ + result r = E_SYSTEM; + int res = NFC_ERROR_NONE; + nfc_ndef_message_h ndefMessageH = NULL; + int length = 0; + + // convert NdefMessage to ByteBuffer + unique_ptr pByteBuffer(message.ToByteBufferN()); + SysTryReturnResult(NID_NET_NFC, pByteBuffer != null, E_SYSTEM, "Failed to convert NdefMessage to ByteBuffer."); + + length = pByteBuffer->GetCapacity(); + + // convert the NDEF message to byte array type + res = nfc_ndef_message_create_from_rawdata(&ndefMessageH, pByteBuffer->GetPointer(), length); + _NfcConvertErrorResult(res == NFC_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Failed to convert to NDEF raw data. [0x%08X]", res); + + res = nfc_tag_write_ndef(__tagHandle, ndefMessageH, &OnNdefWriteCompleted, null); + nfc_ndef_message_destroy(ndefMessageH); // free the resources. (the result is ignored) + r = E_SYSTEM; + _NfcConvertErrorResult(res == NFC_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY, r, E_CONNECTION_BUSY); + _NfcConvertErrorResult(res == NFC_ERROR_TIMED_OUT, r, E_CONNECTION_FAILED); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Failed to write NDEF data. [0x%08X]", res); + + return E_SUCCESS; +} + +bool +_NfcSystemAdapter::IsDeviceDetected(void) +{ + nfc_p2p_target_h pDevice = null; + + if (nfc_manager_get_connected_target(&pDevice) != NFC_ERROR_NONE) + { + return false; + } + + return true; +} + +result +_NfcSystemAdapter::Push(const NdefMessage& message) +{ + SysTryReturnResult(NID_NET_NFC, __p2pTargetHandle != null, E_INVALID_STATE, + "[E_INVALID_STATE] The NFC feature is not activated or a peer device is not attached."); + + int res = NFC_ERROR_NONE; + result r = E_OPERATION_FAILED; + nfc_ndef_message_h ndefMessageH = NULL; + int length = 0; + + // convert NdefMessage to ByteBuffer + unique_ptr pByteBuffer(message.ToByteBufferN()); + SysTryReturnResult(NID_NET_NFC, pByteBuffer != null, E_OPERATION_FAILED, + "[E_OPERATION_FAILED] Failed to convert NdefMessage to ByteBuffer."); + + length = pByteBuffer->GetCapacity(); + + // convert the NDEF message to byte array type + res = nfc_ndef_message_create_from_rawdata(&ndefMessageH, pByteBuffer->GetPointer(), length); + _NfcConvertErrorResult(res == NFC_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Failed to convert to NDEF raw data. [0x%08X]", res); + + res = nfc_p2p_send(__p2pTargetHandle, ndefMessageH, &OnNdefMessageSent, this); + nfc_ndef_message_destroy(ndefMessageH); // free the resources. (the result is ignored) + r = E_OPERATION_FAILED; + _NfcConvertErrorResult(res == NFC_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG); + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY, r, E_DEVICE_BUSY); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Failed to send NDEF data. [0x%08X]", res); + + return E_SUCCESS; +} + +void +_NfcSystemAdapter::OnNfcActivationCompleted(nfc_error_e error, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = _NfcSystemAdapter::GetInstance(); + bool activated = *((bool*)pUserData); + + SysLog(NID_NET_NFC, "NFC Activation Completed CB is invoked."); + + // notify the event only in error cases + if (error != NFC_ERROR_NONE) + { + unique_ptr pEnum(pAdapter->__pNfcManagerImplList->GetEnumeratorN()); + while (pEnum->MoveNext() == E_SUCCESS) + { + _NfcManagerImpl* pImpl = dynamic_cast< _NfcManagerImpl* >(pEnum->GetCurrent()); + SysTryReturnVoidResult(NID_NET_NFC, pImpl != null, E_SYSTEM, + "[E_SYSTEM] Failed to get the _NfcManagerImpl instance."); + + if (activated == true) + { + pImpl->OnNfcActivated(E_SYSTEM); + } + else + { + pImpl->OnNfcDeactivated(E_SYSTEM); + } + } + } +} + +void +_NfcSystemAdapter::OnNfcActivationChanged(bool activated, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = static_cast< _NfcSystemAdapter* >(pUserData); + + SysLog(NID_NET_NFC, "NFC Activation Status Changed CB is invoked."); + + unique_ptr pEnum(pAdapter->__pNfcManagerImplList->GetEnumeratorN()); + while (pEnum->MoveNext() == E_SUCCESS) + { + _NfcManagerImpl* pImpl = dynamic_cast< _NfcManagerImpl* >(pEnum->GetCurrent()); + SysTryReturnVoidResult(NID_NET_NFC, pImpl != null, E_SYSTEM, "[E_SYSTEM] Failed to get the _NfcManagerImpl instance."); + + if (activated == true) + { + pImpl->OnNfcActivated(E_SUCCESS); + } + else + { + // send the tag lost event if the tag connection has been established + if (pAdapter->__isConnected == true) + { + pAdapter->__isConnected = false; + pAdapter->__tagHandle = NULL; + pImpl->OnNfcTagLost(); + } + + pImpl->OnNfcDeactivated(E_SUCCESS); + } + } +} + +void +_NfcSystemAdapter::OnNfcResponseReceived(nfc_error_e res, byte* pReadData, int length, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = _NfcSystemAdapter::GetInstance(); + + SysLog(NID_NET_NFC, "NFC Command Response CB is invoked."); + + result r = E_SYSTEM; + _TagConnectionEventArg* pArg = null; + unique_ptr pResponse; + + // convert the error code + _NfcConvertErrorResult(res == NFC_ERROR_SECURITY_RESTRICTED, r, E_ILLEGAL_ACCESS); + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY || res == NFC_ERROR_TIMED_OUT, r, E_NOT_RESPONDING); + _NfcConvertErrorResult(pReadData != NULL && res == NFC_ERROR_NONE, r, E_SUCCESS); + + if (pReadData != NULL) + { + pResponse.reset(new (std::nothrow) ByteBuffer()); + SysTryReturnVoidResult(NID_NET_NFC, pResponse != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + pResponse->Construct(length); + pResponse->SetArray(pReadData, 0, length); + pResponse->SetPosition(0); + } + + pArg = new (std::nothrow) _TagConnectionEventArg(pResponse.get(), r); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + pAdapter->__pConnectionEvent->Fire(*pArg); +} + +void +_NfcSystemAdapter::OnNdefReadCompleted(nfc_error_e res, nfc_ndef_message_h message, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = _NfcSystemAdapter::GetInstance(); + + SysLog(NID_NET_NFC, "NFC NDEF Read Completed CB is invoked."); + + result r = E_SYSTEM; + unique_ptr pNdefMessage; + _TagConnectionEventArg* pArg = null; + + // convert the error code + _NfcConvertErrorResult(res == NFC_ERROR_NO_NDEF_MESSAGE, r, E_DATA_NOT_FOUND); + _NfcConvertErrorResult(res == NFC_ERROR_NOT_NDEF_FORMAT, r, E_INVALID_FORMAT); + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY || res == NFC_ERROR_TIMED_OUT, r, E_NOT_RESPONDING); + _NfcConvertErrorResult(message != NULL && res == NFC_ERROR_NONE, r, E_SUCCESS); + + if (r == E_SUCCESS) + { + pNdefMessage.reset(pAdapter->GetNdefMessageN(message)); + r = GetLastResult(); + } + + pArg = new (std::nothrow) _TagConnectionEventArg(pNdefMessage.get(), r); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + // fire a read completed event + pAdapter->__pConnectionEvent->Fire(*pArg); +} + +void +_NfcSystemAdapter::OnNdefWriteCompleted(nfc_error_e res, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = _NfcSystemAdapter::GetInstance(); + + SysLog(NID_NET_NFC, "NFC NDEF Write Completed CB is invoked."); + + result r = E_SYSTEM; + _TagConnectionEventArg* pArg = null; + + // convert the error code + _NfcConvertErrorResult(res == NFC_ERROR_NO_SPACE_ON_NDEF, r, E_STORAGE_FULL); + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY || res == NFC_ERROR_TIMED_OUT, r, E_NOT_RESPONDING); + _NfcConvertErrorResult(res == NFC_ERROR_READ_ONLY_NDEF || res == NFC_ERROR_SECURITY_RESTRICTED, r, E_ILLEGAL_ACCESS); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + + pArg = new (std::nothrow) _TagConnectionEventArg(r); + SysTryReturnVoidResult(NID_NET_NFC, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + pAdapter->__pConnectionEvent->Fire(*pArg); +} + +void +_NfcSystemAdapter::OnNfcTagDiscovered(nfc_discovered_type_e type, nfc_tag_h tag, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = static_cast< _NfcSystemAdapter* >(pUserData); + + if (type == NFC_DISCOVERED_TYPE_ATTACHED) + { + SysLog(NID_NET_NFC, "NFC Tag Discovered CB is invoked. (Detected)"); + SysTryReturnVoidResult(NID_NET_NFC, pAdapter->__isConnected == false, E_SYSTEM, + "[E_SYSTEM] Invalid status. The tag detected CB is invoked duplicately."); + + bool isNdefSupport = false; + int res = nfc_tag_is_support_ndef(tag, &isNdefSupport); + SysTryReturnVoidResult(NID_NET_NFC, res == NFC_ERROR_NONE, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_ndef_support() is failed. [0x%08X]", res); + + pAdapter->__isConnected = true; + pAdapter->__tagHandle = tag; + } + else if (type == NFC_DISCOVERED_TYPE_DETACHED) + { + SysLog(NID_NET_NFC, "NFC Tag Discovered CB is invoked. (Lost)"); + SysTryReturnVoidResult(NID_NET_NFC, pAdapter->__isConnected == true, E_SYSTEM, + "[E_SYSTEM] Invalid status. The tag lost CB is invoked duplicately."); + + pAdapter->__isConnected = false; + pAdapter->__tagHandle = NULL; + + if (pAdapter->__pTagValue != null) + { + free(pAdapter->__pTagValue); + pAdapter->__pTagValue = null; + pAdapter->__valueSize = 0; + } + } + + unique_ptr pEnum(pAdapter->__pNfcManagerImplList->GetEnumeratorN()); + while (pEnum->MoveNext() == E_SUCCESS) + { + _NfcManagerImpl* pImpl = dynamic_cast< _NfcManagerImpl* >(pEnum->GetCurrent()); + SysTryReturnVoidResult(NID_NET_NFC, pImpl != null, E_SYSTEM, "[E_SYSTEM] Failed to get the _NfcManagerImpl instance."); + + if (type == NFC_DISCOVERED_TYPE_ATTACHED) + { + _NfcTagImpl* pTagImpl = pAdapter->GetCurrentTag(tag); + SysTryReturnVoidResult(NID_NET_NFC, pTagImpl != null, E_SYSTEM, + "[E_SYSTEM] Failed to create _NfcTagImpl instance for the detected tag."); + + pImpl->OnNfcTagDetectedN(pTagImpl); + } + else if (type == NFC_DISCOVERED_TYPE_DETACHED) + { + pImpl->OnNfcTagLost(); + } + } +} + +void +_NfcSystemAdapter::OnNfcTargetDiscovered(nfc_discovered_type_e type, nfc_p2p_target_h target, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = static_cast< _NfcSystemAdapter* >(pUserData); + + if (type == NFC_DISCOVERED_TYPE_ATTACHED) + { + SysLog(NID_NET_NFC, "NFC Target Discovered CB is invoked. (Detected)"); + // set the callback to receive NDEF message from the peer device + nfc_p2p_set_data_received_cb(target, &OnNdefMessageReceived, pAdapter); + // set the P2P target handle + pAdapter->__p2pTargetHandle = target; + } + else if (type == NFC_DISCOVERED_TYPE_DETACHED) + { + SysLog(NID_NET_NFC, "NFC Target Discovered CB is invoked. (Lost)"); + // unset the callback to receive NDEF message + nfc_p2p_unset_data_received_cb(pAdapter->__p2pTargetHandle); + // initialize(nullify) the P2P target handle + pAdapter->__p2pTargetHandle = null; + } + // ignore other cases + + unique_ptr pEnum(pAdapter->__pNfcManagerImplList->GetEnumeratorN()); + while (pEnum->MoveNext() == E_SUCCESS) + { + _NfcManagerImpl* pImpl = dynamic_cast< _NfcManagerImpl* >(pEnum->GetCurrent()); + SysTryReturnVoidResult(NID_NET_NFC, pImpl != null, E_SYSTEM, "[E_SYSTEM] Failed to get the _NfcManagerImpl instance."); + + if (type == NFC_DISCOVERED_TYPE_ATTACHED) + { + pImpl->OnNfcDeviceDetected(); + } + else if (type == NFC_DISCOVERED_TYPE_DETACHED) + { + pImpl->OnNfcDeviceLost(); + } + } +} + +bool +_NfcSystemAdapter::OnNfcKeyRetrieved(const char* pKey, const unsigned char* pValue, int valueSize, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = _NfcSystemAdapter::GetInstance(); + const char *pKeyTagId = static_cast(pUserData); + + if (strcmp(pKey, pKeyTagId) == 0) + { + pAdapter->__pTagValue = (byte*)malloc(sizeof(byte) * valueSize); + SysTryReturn(NID_NET_NFC, pAdapter->__pTagValue != null, false, E_OUT_OF_MEMORY, + "[E_OUT_OF_MEMORY] Failed to allocate memory to __pTagValue."); + memcpy(pAdapter->__pTagValue, (byte*) pValue, valueSize); + pAdapter->__valueSize = valueSize; + + return false; + } + + return true; +} + +void +_NfcSystemAdapter::OnNdefMessageDiscovered(nfc_ndef_message_h message, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = static_cast< _NfcSystemAdapter* >(pUserData); + + SysLog(NID_NET_NFC, "The NDEF message discovered CB is called."); + + unique_ptr pEnum(pAdapter->__pNfcManagerImplList->GetEnumeratorN()); + while (pEnum->MoveNext() == E_SUCCESS) + { + _NfcManagerImpl* pImpl = dynamic_cast< _NfcManagerImpl* >(pEnum->GetCurrent()); + SysTryReturnVoidResult(NID_NET_NFC, pImpl != null, E_SYSTEM, "[E_SYSTEM] Failed to get the _NfcManagerImpl instance."); + + NdefMessage* pDetectedMessage = pAdapter->GetNdefMessageN(message); + SysTryReturnVoidResult(NID_NET_NFC, pDetectedMessage != null, GetLastResult(), + "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + pImpl->OnNdefMessageDetectedN(pDetectedMessage); + } +} + +void +_NfcSystemAdapter::OnNdefMessageReceived(nfc_p2p_target_h target, nfc_ndef_message_h message, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = static_cast< _NfcSystemAdapter* >(pUserData); + pAdapter->OnNdefMessageDiscovered(message, pAdapter); +} + +void +_NfcSystemAdapter::OnNdefMessageSent(nfc_error_e res, void* pUserData) +{ + _NfcSystemAdapter* pAdapter = static_cast< _NfcSystemAdapter* >(pUserData); + result r = E_OPERATION_FAILED; + + SysLog(NID_NET_NFC, "The NDEF message sent CB is called."); + + // convert the error code + _NfcConvertErrorResult(res == NFC_ERROR_DEVICE_BUSY || res == NFC_ERROR_TIMED_OUT, r, E_NOT_RESPONDING); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + + unique_ptr pEnum(pAdapter->__pNdefPushManagerImplList->GetEnumeratorN()); + while (pEnum->MoveNext() == E_SUCCESS) + { + _NdefPushManagerImpl* pImpl = dynamic_cast< _NdefPushManagerImpl* >(pEnum->GetCurrent()); + SysTryReturnVoidResult(NID_NET_NFC, pImpl != null, E_SYSTEM, + "[E_SYSTEM] Failed to get the _NdefPushManagerImpl instance."); + + pImpl->OnNdefPushMessageSent(r); + } +} + +NdefMessage* +_NfcSystemAdapter::GetCachedNdefMessageN(void) +{ + int res = NFC_ERROR_NONE; + result r = E_SYSTEM; + nfc_ndef_message_h msgHandle = null; + NdefMessage* pCachedMessage = null; + + res = nfc_manager_get_cached_message(&msgHandle); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(res == NFC_ERROR_INVALID_NDEF_MESSAGE, r, E_INVALID_FORMAT); + _NfcConvertErrorResult(res == NFC_ERROR_NONE, r, E_SUCCESS); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, null, r, + "[%s] Failed to get the cached NDEF message. [0x%08X]", GetErrorMessage(r), res); + + pCachedMessage = GetNdefMessageN(msgHandle); + r = GetLastResult(); + nfc_ndef_message_destroy(msgHandle); + + return pCachedMessage; +} + +NdefMessage* +_NfcSystemAdapter::GetNdefMessageN(const nfc_ndef_message_h& messageHandle) +{ + int res = NFC_ERROR_NONE; + result r = E_SYSTEM; + byte* pTempBuffer = null; + unique_ptr pBuffer; + int bufSize = 0; + ByteBuffer byteMessage; + NdefMessage* pNdefMessage = null; + + ClearLastResult(); + + // get the handle of the raw data of NDEF message + res = nfc_ndef_message_get_rawdata (messageHandle, &pTempBuffer, &bufSize); + _NfcConvertErrorResult(res == NFC_ERROR_INVALID_NDEF_MESSAGE, r, E_INVALID_FORMAT); + _NfcConvertErrorResult(res == NFC_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY); + _NfcConvertErrorResult(pTempBuffer != NULL && res == NFC_ERROR_NONE, r, E_SUCCESS); + pBuffer.reset(pTempBuffer); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, null, r, + "[%s] Failed to get the raw data of the NDEF message. [0x%08X]", GetErrorMessage(r), res); + + // TODO: shallow copy + byteMessage.Construct(bufSize); + byteMessage.SetArray(pBuffer.get(), 0, bufSize); + byteMessage.SetPosition(0); + + // convert byte buffer to NdefMessage + pNdefMessage = _NdefMessageUtil::ToNdefMessageN(byteMessage); + + return pNdefMessage; +} + +_NfcTagImpl* +_NfcSystemAdapter::GetCurrentTag(nfc_tag_h targetInfoHandle) +{ + //////////////////////////////////////////////////////////////////////////////// + // in the /usr/include/nfc-common-lib/net_nfc_typedef_private.h file directory + // net_nfc_sIso14443AInfo_t::Uid + // net_nfc_sIso14443BInfo_t::AtqB::AtqResInfo::Pupi + // net_nfc_sFelicaInfo_t::IDm + // net_nfc_sIso15693Info_t::Uid + //////////////////////////////////////////////////////////////////////////////// + int res = NFC_ERROR_NONE; + nfc_tag_type_e type; + Tizen::Base::ByteBuffer tagId; + Tizen::Base::Collection::ArrayListT tagTypes; + bool isNdefSupport = false; + bool isUnknownTagType = false; + + // check if the tag supports NDEF format + res = nfc_tag_is_support_ndef(targetInfoHandle, &isNdefSupport); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_ndef_support() is failed. [0x%08X]", res); + // get tag type + nfc_tag_get_type(targetInfoHandle, &type); + + // construct the list + tagTypes.Construct(); + + switch (type) + { + case NFC_ISO14443_4A_PICC: + case NFC_ISO14443_A_PICC: + SysLog(NID_NET_NFC, "[NET_NFC_ISO14443_4A_PICC] or [NET_NFC_ISO14443_A_PICC] type"); + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO14443_3A); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_ISO14443_3A); + tagTypes.Add(NFC_TAG_TYPE_ISO14443_4); + if (isNdefSupport) + { + tagTypes.Add(NFC_TAG_TYPE_FORUM_TYPE_4); + } + break; + case NFC_ISO14443_4B_PICC: + case NFC_ISO14443_B_PICC: + // TODO: should check this case means the ISO14443-3B or not + SysLog(NID_NET_NFC, "[NET_NFC_ISO14443_B_PICC | NET_NFC_ISO14443_4B_PICC type"); + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO14443_3B); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_ISO14443_3B); + tagTypes.Add(NFC_TAG_TYPE_ISO14443_4); + if (isNdefSupport) + { + tagTypes.Add(NFC_TAG_TYPE_FORUM_TYPE_4); + } + break; + case NFC_ISO14443_3A_PICC: // ISO14443-3A type + SysLog(NID_NET_NFC, "NET_NFC_ISO14443_3A_PICC type"); + // tag id + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO14443_3A); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_ISO14443_3A); + break; + case NFC_ISO15693_PICC: // 15693 + SysLog(NID_NET_NFC, "NET_NFC_ISO15693_PICC type"); + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO15693); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add type + tagTypes.Add(NFC_TAG_TYPE_ISO15693); + break; + case NFC_MIFARE_ULTRA_PICC: // Mifare Ultralight + SysLog(NID_NET_NFC, "NET_NFC_MIFARE_ULTRA_PICC type"); + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO14443_3A); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM]net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_ISO14443_3A); + tagTypes.Add(NFC_TAG_TYPE_MIFARE_UL); + if (isNdefSupport) + { + tagTypes.Add(NFC_TAG_TYPE_FORUM_TYPE_2); + } + break; + case NFC_MIFARE_MINI_PICC: // Mifare classic + // fall through + case NFC_MIFARE_1K_PICC: // Mifare classic + // fall through + case NFC_MIFARE_4K_PICC: // Mifare classic + SysLog(NID_NET_NFC, "[NET_NFC_MIFARE_MINI_PICC|NET_NFC_MIFARE_1K_PICC|NET_NFC_MIFARE_4K_PICC] Mifare classic type"); + // tag id + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO14443_3A); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_ISO14443_3A); + tagTypes.Add(NFC_TAG_TYPE_MIFARE_CLASSIC); + break; + case NFC_FELICA_PICC: // Felica + SysLog(NID_NET_NFC, "NET_NFC_FELICA_PICC type"); + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_FELICA); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_FELICA); + if (isNdefSupport) + { + tagTypes.Add(NFC_TAG_TYPE_FORUM_TYPE_3); + } + + break; + case NFC_JEWEL_PICC: + SysLog(NID_NET_NFC, "NET_NFC_JEWEL_PICC type"); + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO14443_3A); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_ISO14443_3A); + tagTypes.Add(NFC_TAG_TYPE_TOPAZ_JEWEL); + if (isNdefSupport) + { + tagTypes.Add(NFC_TAG_TYPE_FORUM_TYPE_1); + } + break; + case NFC_MIFARE_DESFIRE_PICC: // unknown + SysLog(NID_NET_NFC, "NET_NFC_MIFARE_DESFIRE_PICC type"); + res = nfc_tag_foreach_information (targetInfoHandle, &OnNfcKeyRetrieved, (void*)KEY_TAG_ID_ISO14443_3A); + SysTryReturn(NID_NET_NFC, res == NFC_ERROR_NONE, null, E_SYSTEM, + "[E_SYSTEM] net_nfc_get_tag_info_value() is failed. [0x%08X]", res); + + // add types + tagTypes.Add(NFC_TAG_TYPE_ISO14443_3A); + tagTypes.Add(NFC_TAG_TYPE_ISO14443_4); + if (isNdefSupport) + { + tagTypes.Add(NFC_TAG_TYPE_FORUM_TYPE_4); + } + break; + case NFC_ISO14443_BPRIME_PICC: + case NFC_GENERIC_PICC: + // TODO: find the way how to get the ID of B Prime tag + SysLog(NID_NET_NFC, "[NET_NFC_GENERIC_PICC | NET_NFC_ISO14443_A_PICC] type. Map these types to UNKNOWN tag type"); + tagTypes.Add(NFC_TAG_TYPE_UNKNOWN); + isUnknownTagType = true; + break; + case NFC_NFCIP1_TARGET: // p2p type + case NFC_NFCIP1_INITIATOR: // p2p type + default: + SysLog(NID_NET_NFC, "[NET_NFC_NFCIP1_TARGET | NET_NFC_NFCIP1_INITIATOR] NOT a Tag Type - p2p type (%d)", type); + return null; + } + + if (isUnknownTagType != true) + { + tagId.Construct(__valueSize); + tagId.SetArray(__pTagValue, 0, __valueSize); + tagId.SetPosition(0); + + // _NfcTagImpl instance + return new _NfcTagImpl(&tagId, tagTypes, isNdefSupport); + } + else // UNKNOWN TAG TYPE + { + // _NfcTagImpl instance + return new _NfcTagImpl(null, tagTypes, isNdefSupport); + } +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcSystemAdapter.h b/src/FNetNfc_NfcSystemAdapter.h new file mode 100644 index 0000000..974fd61 --- /dev/null +++ b/src/FNetNfc_NfcSystemAdapter.h @@ -0,0 +1,350 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNet_NfcSystemAdapter.h + * @brief This is the header file for _NfcSystemAdapter class. + */ +#ifndef _FNET_NFC_INTERNAL_NFC_SYSTEM_ADAPTER_H_ +#define _FNET_NFC_INTERNAL_NFC_SYSTEM_ADAPTER_H_ + +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NdefMessageUtil.h" + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +namespace Collection +{ +template class IListT; +class LinkedList; +} +} } + +namespace Tizen { namespace Net { namespace Nfc +{ +// Forward declaration +class NdefMessage; +class _INfcManagerEventListener; +class _ITagConnectionListener; +class _NfcTagImpl; +class _NfcManagerEvent; +class _TagConnectionEvent; +class _NfcManagerImpl; +class _NdefPushManagerImpl; + +struct _RawDataDeleter +{ + void operator()(byte* pBuffer) + { + free(pBuffer); + } +}; +/** + * @class _NfcSystemAdapter + * @brief This class provides functions related to deliver the system events to the listeners such as _NfcManagerImpl. + * This class is a type of singleton, therefore only one instance should be allowed. + */ +class _NfcSystemAdapter + : public Tizen::Base::Object +{ + +public: + /** + * Creates an instance of this class if there is no instance in this application context. + * Gets the exist instance because this class is a singleton, otherwise. + * + * @return the instance of this class + */ + static _NfcSystemAdapter* GetInstance(void); + + /** + * Register an instance of _ITagConnectionListener class. + * Multiple instances can be registered. + * + * @return An error code + * @param[in] impl The instance of _ITagConnectionListener to be registered + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error has occurred. + */ + result RegisterTagConnectionListener(const _ITagConnectionListener& listener); + + /** + * Unregister an instance of _ITagConnectionListener class from the internal list. + * + * @return An error code + * @param[in] impl The instance of _ITagConnectionListener to be unregistered + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_NOT_FOUND The input instance is not registered. + */ + result UnregisterTagConnectionListener(const _ITagConnectionListener& listener); + + /** + * Adds the specified %_NfcManagerImpl instance for the device discovery events. + * + * @return An error code + * @param[in] nfcManagerImpl The %_NfcManagerImpl instance to be added + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_ALREADY_EXIST The listener was already added. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + */ + result AddNfcManagerImpl(const _NfcManagerImpl& nfcManagerImpl); + + /** + * Removes the specified %_NfcManagerImpl instance. + * + * @return An error code + * @param[in] nfcManagerImpl The %_NfcManagerImpl instance to be removed + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + */ + result RemoveNfcManagerImpl(const _NfcManagerImpl& nfcManagerImpl); + + /** + * Adds the specified %_NfcManagerImpl instance for the device discovery events. + * + * @return An error code + * @param[in] ndefPushManagerImpl The %_NdefPushManagerImpl instance to be added + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_ALREADY_EXIST The listener was already added. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + */ + result AddNdefPushManagerImpl(const _NdefPushManagerImpl& ndefPushManagerImpl); + + /** + * Removes the specified %_NfcManagerImpl instance. + * + * @return An error code + * @param[in] ndefPushManagerImpl The %_NdefPushManagerImpl instance to be removed + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + */ + result RemoveNdefPushManagerImpl(const _NdefPushManagerImpl& ndefPushManagerImpl); + + /** + * Activate NFC feature. + * + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + */ + result Activate(void); + + /** + * Deactivate NFC feature. + * + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + */ + result Deactivate(void); + + /** + * Checks whether the NFC feature is activated. + * + * @return @c true, if the NFC feature is activated @n + * @c false, otherwise + */ + bool IsActivated(void) const; + + /** + * Checks whether an NFC tag is currently connected with the device. + * + * @return @c true, if an NFC tag is currently connected @n + * @c false, otherwise + */ + bool IsTagConnected(void); + + /** + * Checks whether an NFC peer device is currently connected with this device. + * + * @return @c true, if an NFC peer device is currently connected @n + * @c false, otherwise + */ + bool IsDeviceDetected(void); + + /** + * Gets the Impl instance of the current detected tag. + * + * @return the Impl instance of the current detected tag, @n + * @c null if the getting fails + */ + _NfcTagImpl* GetCurrentTagImplN(void); + + /** + * Sends the raw data to the current detected tag. + * + * @return An error code + * @param[in] command Command to be sent to the tag + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The input @c command is invalid. + * @exception E_CONNECTION_BUSY The connection is busy, so cannot process the send request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or fails. + * @exception E_SYSTEM A system error occurred. + * @see INfcConnectionInternalEventListener::OnNfcResponseReceivedN() + */ + result SendCommand(const Tizen::Base::ByteBuffer& command); + + /** + * Reads NDEF data from an NDEF tag. + * + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_CONNECTION_BUSY The connection is busy, so cannot process the read request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or fails. + * @exception E_SYSTEM A system error occurred. + * @see INfcConnectionInternalEventListener::OnNdefReadCompletedN() + */ + result Read(void); + + /** + * Writes NDEF data to an NDEF tag. + * + * @return An error code + * @param[in] message NDEF message to be written to the target + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The input @c message is invalid. + * @exception E_CONNECTION_BUSY The connection is busy, so cannot process the write request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or fails. + * @exception E_SYSTEM A system error occurred. + * @see INfcConnectionInternalEventListener::OnNdefWriteCompleted() + */ + result Write(const NdefMessage& message); + + /** + * Pushes the NDEF message. + * + * @return An error code + * @param[in] message The NDEF message to be sent + * @exception E_SUCCESS The method is successful. + * @exception E_DEVICE_BUSY The device is processing preceding job. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_STATE This instance is in an invalid state. @n + * For example, the NFC feature is not activated @n + * or a peer device is not attached. + * @exception E_OPERATION_FAILED The operation has failed. + */ + result Push(const NdefMessage& message); + + + // Callback methods + + /** + * Callback to notify that the NFC activation or deactivation is completed. + */ + static void OnNfcActivationCompleted(nfc_error_e error, void* pUserData); + + /** + * Callback to notify that the NFC activation status is changed. + */ + static void OnNfcActivationChanged(bool activated, void* pUserData); + + /** + * Callback to notify the peer device is detected or lost. + */ + static void OnNfcTargetDiscovered(nfc_discovered_type_e type, nfc_p2p_target_h target, void* pUserData); + + /** + * Callback to notify that Nfc activation is changed. + */ + static void OnNfcResponseReceived(nfc_error_e res, byte* pReadData, int length, void* pUserData); + + /** + * Callback to notify that ndef read is completed. + */ + static void OnNdefReadCompleted(nfc_error_e res, nfc_ndef_message_h message, void* pUserData); + + /** + * Callback to notify that ndef write is completed. + */ + static void OnNdefWriteCompleted(nfc_error_e res, void* pUserData); + + /** + * Callback to notify that nfc tag is detected or lost. + */ + static void OnNfcTagDiscovered(nfc_discovered_type_e type, nfc_tag_h tag, void* pUserData); + + /** + * Callback to notify that nfc tag key is retrieved. + */ + static bool OnNfcKeyRetrieved(const char* pKey, const unsigned char* pValue, int valueSize, void* pUserData); + + /** + * Callback to notify that ndef message is discovered. + */ + static void OnNdefMessageDiscovered(nfc_ndef_message_h message, void* pUserData); + + /** + * Callback to notify that ndef message is received from a peer device. + */ + static void OnNdefMessageReceived(nfc_p2p_target_h target, nfc_ndef_message_h message, void* pUserData); + + /** + * Callback to notify that NDEF push is completed. + */ + static void OnNdefMessageSent(nfc_error_e res, void* pUserData); + + /** + * Gets the NDEF message cached when the tag is detected. + * + * @return The cached %NdefMessage instance, @n + * else @c null if the method is not successful + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS This operation is not allowed because the application is not launched by + * Conditional %App Launch. + * @exception E_INVALID_FORMAT The cached data cannot be converted to the NDEF message. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + static NdefMessage* GetCachedNdefMessageN(void); + +private: + _NfcSystemAdapter(void); + _NfcSystemAdapter(const _NfcSystemAdapter& value); + ~_NfcSystemAdapter(void); + + _NfcSystemAdapter& operator =(const _NfcSystemAdapter& value); + result Construct(void); + + static NdefMessage* GetNdefMessageN(const nfc_ndef_message_h& messageHandle); + _NfcTagImpl* GetCurrentTag(nfc_tag_h targetInfoHandle); + static void InitSingleton(void); + static void DestroySingleton(void); + +private: + std::unique_ptr __pConnectionEvent; + std::unique_ptr __pNfcManagerImplList; + std::unique_ptr __pNdefPushManagerImplList; + nfc_tag_h __tagHandle; + nfc_p2p_target_h __p2pTargetHandle; + _NfcTagImpl* __pNfcTagImpl; // temporary defined due to get the current tag info (6/22) + byte* __pTagValue; + int __valueSize; + bool __isConnected; // temporary defined due to get the current tag connection state. + static _NfcSystemAdapter* __pSingleton; + +friend class std::default_delete< _NfcSystemAdapter >; +}; // _NfcSystemAdapter + +} } } +#endif // _FNET_NFC_INTERNAL_NFC_SYSTEM_ADAPTER_H_ diff --git a/src/FNetNfc_NfcTagDiscoveryEvent.cpp b/src/FNetNfc_NfcTagDiscoveryEvent.cpp new file mode 100644 index 0000000..52c67e7 --- /dev/null +++ b/src/FNetNfc_NfcTagDiscoveryEvent.cpp @@ -0,0 +1,93 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcTagDiscoveryEvent.cpp +// @brief This is the implementation file for _NfcTagDiscoveryEvent class. +// +// This file contains the implementation of _NfcTagDiscoveryEvent class. +// + +#include +#include +#include +#include +#include "FNetNfc_NfcTagDiscoveryEvent.h" +#include "FNetNfc_NfcTagDiscoveryEventArg.h" +#include "FNetNfc_NfcTagImpl.h" +#include "FNetNfc_TagConnectionImpl.h" + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NfcTagDiscoveryEvent::_NfcTagDiscoveryEvent(void) +{ +} + +_NfcTagDiscoveryEvent::~_NfcTagDiscoveryEvent(void) +{ +} + +result +_NfcTagDiscoveryEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_NfcTagDiscoveryEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + result r = E_SUCCESS; + + INfcTagDiscoveryEventListener* pEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_NET_NFC, pEventListener != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + + const _NfcTagDiscoveryEventArg* pEventArg = dynamic_cast (&arg); + SysTryReturnVoidResult(NID_NET_NFC, pEventArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + const _NfcTagImpl* pTagImpl = null; + TagConnection* pConnection = null; + + _NfcTagDiscoveryEventType eventType = pEventArg->GetEventType(); + + switch (eventType) + { + case _NFC_TAG_DISCOVERY_EVENT_TYPE_DETECTED: + pTagImpl = pEventArg->GetTagImpl(); + pConnection = _TagConnectionImpl::GetTagConnectionN(*pTagImpl); + + if (pConnection) + { + pEventListener->OnNfcTagDetectedN(pConnection); + } + else + { + r = E_SYSTEM; + SysLog(NID_NET_NFC, "[E_SYSTEM] A system error has been occurred."); + } + + break; + + case _NFC_TAG_DISCOVERY_EVENT_TYPE_LOST: + pEventListener->OnNfcTagLost(); + break; + + default: + break; + } +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcTagDiscoveryEvent.h b/src/FNetNfc_NfcTagDiscoveryEvent.h new file mode 100644 index 0000000..e722cd0 --- /dev/null +++ b/src/FNetNfc_NfcTagDiscoveryEvent.h @@ -0,0 +1,84 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcTagDiscoveryEvent.h + * @brief This is the header file for the _NfcTagDiscoveryEvent class. + * + * This header file contains declaration of the _NfcTagDiscoveryEvent class. + * The _NfcTagDiscoveryEvent class can call methods of a INfcTagDiscoveryEventListener class. + */ +#ifndef _FNET_NFC_INTERNAL_NFC_TAG_DISCOVERY_EVENT_H_ +#define _FNET_NFC_INTERNAL_NFC_TAG_DISCOVERY_EVENT_H_ + +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base { namespace Runtime +{ +class IEventArg; +class IEventListener; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @class _NfcTagDiscoveryEvent + * @brief This class handles the events related to the discovery of NFC tag. + * + * When an NFC tag is discovered, the _NfcTagDiscoveryEvent object finds a INfcTagDiscoveryEventListener object and + * calls an appropriate method of the listener. + */ +class _NfcTagDiscoveryEvent + : public Tizen::Base::Runtime::_Event +{ +public: + /** + * This is the default constructor. + */ + _NfcTagDiscoveryEvent(); + + /** + * This is the class destructor. + */ + virtual ~_NfcTagDiscoveryEvent(void); + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + +protected: + /** + * Calls the specified listener's method with the specified argument when event is generated. + * + * @param[in] listener The event listener which will be received the event + * @param[in] arg The event argument to be passed by + */ + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _NfcTagDiscoveryEvent(const _NfcTagDiscoveryEvent& value); + _NfcTagDiscoveryEvent& operator =(const _NfcTagDiscoveryEvent& value); + +}; // _NfcTagDiscoveryEvent + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NFC_TAG_DISCOVERY_EVENT_H_ diff --git a/src/FNetNfc_NfcTagDiscoveryEventArg.cpp b/src/FNetNfc_NfcTagDiscoveryEventArg.cpp new file mode 100644 index 0000000..63628e8 --- /dev/null +++ b/src/FNetNfc_NfcTagDiscoveryEventArg.cpp @@ -0,0 +1,63 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcTagDiscoveryEventArg.cpp +// @brief This is the implementation file for _NfcTagDiscoveryEventArg class. +// +// This file contains the implementation of _NfcTagDiscoveryEventArg class. +// + +#include +#include "FNetNfc_NfcTagDiscoveryEventArg.h" +#include "FNetNfc_NfcTagImpl.h" + +using namespace std; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NfcTagDiscoveryEventArg::_NfcTagDiscoveryEventArg(void) + : __eventType(_NFC_TAG_DISCOVERY_EVENT_TYPE_LOST) + , __pTagImpl(null) +{ +} + +_NfcTagDiscoveryEventArg::_NfcTagDiscoveryEventArg(const _NfcTagImpl& tagImpl) + : __eventType(_NFC_TAG_DISCOVERY_EVENT_TYPE_DETECTED) + , __pTagImpl(null) +{ + __pTagImpl = new (std::nothrow) _NfcTagImpl(tagImpl); + SysTryReturnVoidResult(NID_NET_NFC, __pTagImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); +} + +_NfcTagDiscoveryEventArg::~_NfcTagDiscoveryEventArg(void) +{ + delete __pTagImpl; +} + +_NfcTagDiscoveryEventType +_NfcTagDiscoveryEventArg::GetEventType(void) const +{ + return __eventType; +} + +const _NfcTagImpl* +_NfcTagDiscoveryEventArg::GetTagImpl(void) const +{ + return __pTagImpl; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_NfcTagDiscoveryEventArg.h b/src/FNetNfc_NfcTagDiscoveryEventArg.h new file mode 100644 index 0000000..4dbbdf3 --- /dev/null +++ b/src/FNetNfc_NfcTagDiscoveryEventArg.h @@ -0,0 +1,102 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcTagDiscoveryEventArg.h + * @brief This is the header file for the _NfcTagDiscoveryEventArg class. + * + * This header file contains declaration of the _NfcTagDiscoveryEventArg class. + */ +#ifndef _FNET_NFC_INTERNAL_NFC_TAG_DISCOVERY_EVENT_ARG_H_ +#define _FNET_NFC_INTERNAL_NFC_TAG_DISCOVERY_EVENT_ARG_H_ + +#include +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NfcTagImpl; + +/** + * @enum _NfcTagDiscoveryEventType + * + * Defines the type of the tag discovery event. + */ +enum _NfcTagDiscoveryEventType +{ + _NFC_TAG_DISCOVERY_EVENT_TYPE_DETECTED, + _NFC_TAG_DISCOVERY_EVENT_TYPE_LOST +}; + +/** + * @class _NfcTagDiscoveryEventArg + * @brief This class is used as an argument of methods of the _NfcTagDiscoveryEvent class. + * + * When an NFC tag is discovered, the INfcTagDiscoveryEventListener objects registered to the event are called + * with this argument class. + */ +class _NfcTagDiscoveryEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ +public: + /** + * This is the default constructor for the detached event. + */ + _NfcTagDiscoveryEventArg(void); + + /** + * This is the constructor for the detected event. + * + * @param[in] tagImpl The impl instance of the detected tag + */ + _NfcTagDiscoveryEventArg(const _NfcTagImpl& tagImpl); + + /** + * This is the class destructor. + */ + ~_NfcTagDiscoveryEventArg(void); + + /** + * Gets the type of this event. + * + * @return The type of the event + */ + _NfcTagDiscoveryEventType GetEventType(void) const; + + /** + * Gets the Impl instance of the detected tag. + * + * @return The Impl instance of the detected tag + */ + const _NfcTagImpl* GetTagImpl(void) const; + +private: + _NfcTagDiscoveryEventArg(const _NfcTagDiscoveryEventArg& value); + _NfcTagDiscoveryEventArg& operator =(const _NfcTagDiscoveryEventArg& value); + +private: + _NfcTagDiscoveryEventType __eventType; + _NfcTagImpl* __pTagImpl; + +}; // _NfcTagDiscoveryEventArg + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NFC_TAG_DISCOVERY_EVENT_ARG_H_ diff --git a/src/FNetNfc_NfcTagImpl.cpp b/src/FNetNfc_NfcTagImpl.cpp new file mode 100644 index 0000000..4f3f62d --- /dev/null +++ b/src/FNetNfc_NfcTagImpl.cpp @@ -0,0 +1,108 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcNfcTagImpl.cpp +// @brief This is the implementation file for _NfcTagImpl class. +// +// This file contains the implementation of _NfcTagImpl class. +// + +#include +#include +#include +#include +#include "FNetNfc_NfcTagImpl.h" + +using namespace std; +using namespace Tizen::Base; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_NfcTagImpl::_NfcTagImpl(const Tizen::Base::ByteBuffer* pId, const Tizen::Base::Collection::IListT & types, bool isNdefSupported) + : __pTagId(null) + , __tagTypeList() + , __isNdefSupported(isNdefSupported) +{ + if (pId) + { + __pTagId = new (std::nothrow) ByteBuffer; + SysTryReturnVoidResult(NID_NET_NFC, __pTagId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + __pTagId->Construct(*pId); + } + + __tagTypeList.Construct(types); +} + +_NfcTagImpl::_NfcTagImpl(const _NfcTagImpl& value) + : __pTagId(null) + , __tagTypeList() + , __isNdefSupported(value.__isNdefSupported) +{ + if (value.__pTagId) + { + __pTagId = new (std::nothrow) ByteBuffer; + SysTryReturnVoidResult(NID_NET_NFC, __pTagId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + __pTagId->Construct(*(value.__pTagId)); + } + + __tagTypeList.Construct(value.__tagTypeList); +} + +_NfcTagImpl::~_NfcTagImpl(void) +{ + delete __pTagId; +} + +bool +_NfcTagImpl::HasTagType(NfcTagType type) const +{ + return __tagTypeList.Contains(type); +} + +const Tizen::Base::Collection::IListT * +_NfcTagImpl::GetTagTypeList(void) const +{ + return &__tagTypeList; +} + +const Tizen::Base::ByteBuffer* +_NfcTagImpl::GetId(void) const +{ + return __pTagId; +} + +bool +_NfcTagImpl::IsNdefSupported(void) const +{ + return __isNdefSupported; +} + +NfcTag* +_NfcTagImpl::GetNfcTagN(const _NfcTagImpl& impl) +{ + unique_ptr pTag(new (std::nothrow) NfcTag()); + SysTryReturn(NID_NET_NFC, pTag != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + unique_ptr<_NfcTagImpl> pImpl(new (std::nothrow) _NfcTagImpl(impl)); + SysTryReturn(NID_NET_NFC, pImpl != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + pTag->__pImpl = pImpl.release(); + + return pTag.release(); +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_TagConnectionEvent.cpp b/src/FNetNfc_TagConnectionEvent.cpp new file mode 100644 index 0000000..c8d6e03 --- /dev/null +++ b/src/FNetNfc_TagConnectionEvent.cpp @@ -0,0 +1,160 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcTagConnectionEvent.cpp + * @brief This is the implementation file for _TagConnectionEvent class. + * + * This file contains the implementation of _TagConnectionEvent class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_TagConnectionEvent.h" +#include "FNetNfc_TagConnectionEventArg.h" +#include "FNetNfc_ITagConnectionListener.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_TagConnectionEvent::_TagConnectionEvent(void) +{ +} + +_TagConnectionEvent::~_TagConnectionEvent(void) +{ +} + +result +_TagConnectionEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_TagConnectionEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + result r = E_SUCCESS; + NdefMessage* pMessage = null; + NdefMessage* pCopiedMessage = null; + NdefRecord* pNdefRecord = null; + ByteBuffer* pResponse = null; + _ITagConnectionListener* pTagConnectionListener = null; + _TagConnectionEventType type; + int recordCount = 0; + + const _TagConnectionEventArg* pEventArg = dynamic_cast (&arg); + SysTryReturnVoidResult(NID_NET_NFC, pEventArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + type = pEventArg->GetEventType(); + + switch (type) + { + case _TAG_CON_EVENT_TYPE_READ_COMPLETED: + SysLog(NID_NET_NFC, "_TAG_CON_EVENT_TYPE_READ_COMPLETED"); + pTagConnectionListener = dynamic_cast <_ITagConnectionListener*>(&listener); + if (pTagConnectionListener != null) + { + pMessage = pEventArg->GetNdefMessage(); + if (pMessage != null) + { + // shallow copy + recordCount = pMessage->GetRecordsCount(); + + // do shallow copy + pCopiedMessage = new (std::nothrow) NdefMessage(); + SysTryReturnVoidResult(NID_NET_NFC, pCopiedMessage != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + for (int i = 0; i < recordCount; i++) + { + pNdefRecord = new (std::nothrow) NdefRecord(pMessage->GetRecordAt(i)->GetRecordType()); + TryCatch(pNdefRecord != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pNdefRecord->SetPayloadId(pMessage->GetRecordAt(i)->GetPayloadId()); + const ByteBuffer* pPayload = pMessage->GetRecordAt(i)->GetPayload(); + if (pPayload) + { + ByteBuffer* pNewPayload = new (std::nothrow) ByteBuffer(); + TryCatch(pNewPayload != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pNewPayload->Construct(*pPayload); + pNdefRecord->SetPayload(*pNewPayload); + delete pNewPayload; + pNewPayload = null; + } + + r = pCopiedMessage->AppendRecord(*pNdefRecord); + TryCatch(r == E_SUCCESS, r = E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + } + } + + pTagConnectionListener->OnNdefReadCompletedN(pCopiedMessage, pEventArg->GetResult()); + } + break; + + case _TAG_CON_EVENT_TYPE_WRITE_COMPLETED: + SysLog(NID_NET_NFC, "_TAG_CON_EVENT_TYPE_WRITE_COMPLETED"); + pTagConnectionListener = dynamic_cast <_ITagConnectionListener*>(&listener); + if (pTagConnectionListener != null) + { + pTagConnectionListener->OnNdefWriteCompleted(pEventArg->GetResult()); + } + break; + + case _TAG_CON_EVENT_TYPE_RESPONSE_RECEIVED: + SysLog(NID_NET_NFC, "_TAG_CON_EVENT_TYPE_RESPONSE_RECEIVED"); + pTagConnectionListener = dynamic_cast <_ITagConnectionListener*>(&listener); + if (pTagConnectionListener != null) + { + if (pEventArg->GetResponse() != null) + { + // shallow copy + pResponse = new (std::nothrow) ByteBuffer; + SysTryReturnVoidResult(NID_NET_NFC, pResponse != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + pResponse->Construct(*(pEventArg->GetResponse())); + } + pTagConnectionListener->OnNfcResponseReceivedN(pResponse, pEventArg->GetResult()); + } + break; + + default: + SysLog(NID_NET_NFC, "A failure occurred from the underlying system."); + r = E_SYSTEM; + break; + } + + return; + +CATCH: + if (pCopiedMessage) + { + pCopiedMessage->RemoveAllRecords(true); + delete pCopiedMessage; + pCopiedMessage = null; + } + if (pNdefRecord) + { + delete pNdefRecord; + pNdefRecord = null; + } +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_TagConnectionEvent.h b/src/FNetNfc_TagConnectionEvent.h new file mode 100644 index 0000000..2046411 --- /dev/null +++ b/src/FNetNfc_TagConnectionEvent.h @@ -0,0 +1,84 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcTagConnectionEvent.h + * @brief This is the header file for the _TagConnectionEvent class. + * + * This header file contains declaration of the _TagConnectionEvent class. + * The _TagConnectionEvent class can call methods of a INfcTagConnectionEventListener class. + */ +#ifndef _FNET_NFC_INTERNAL_TAG_CONNECTION_EVENT_H_ +#define _FNET_NFC_INTERNAL_TAG_CONNECTION_EVENT_H_ + +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base { namespace Runtime +{ +class IEventArg; +class IEventListener; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +/** + * @class _TagConnectionEvent + * @brief This class handles the events related to the connection with NFC tag. + * + * When the connection with the detected NFC tag is established and the events are detected from it, the + * _TagConnectionEvent object finds a ITagConnectionEventListner object and calls an appropriate method of the listener. + */ +class _TagConnectionEvent + : public Tizen::Base::Runtime::_Event +{ +public: + /** + * This is the default constructor. + */ + _TagConnectionEvent(); + + /** + * This is the class destructor. + */ + virtual ~_TagConnectionEvent(void); + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + +protected: + /** + * Calls the specified listener's method with the specified argument when event is generated. + * + * @param[in] listener The event listener which will be received the event + * @param[in] arg The event argument to be passed by + */ + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _TagConnectionEvent(const _TagConnectionEvent& value); + _TagConnectionEvent& operator =(const _TagConnectionEvent& value); + +}; // _TagConnectionEvent + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_TAG_CONNECTION_EVENT_H_ diff --git a/src/FNetNfc_TagConnectionEventArg.cpp b/src/FNetNfc_TagConnectionEventArg.cpp new file mode 100644 index 0000000..f3cff4c --- /dev/null +++ b/src/FNetNfc_TagConnectionEventArg.cpp @@ -0,0 +1,136 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcTagConnectionEventArg.cpp +// @brief This is the implementation file for _TagConnectionEventArg class. +// +// This file contains the implementation of _TagConnectionEventArg class. +// + +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_TagConnectionEventArg.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_TagConnectionEventArg::_TagConnectionEventArg(NdefMessage* pMessage, result r) + : __eventType(_TAG_CON_EVENT_TYPE_READ_COMPLETED) + , __pRecievedMessage(null) + , __pResponseData(null) + , __result(r) +{ + NdefRecord* pNdefRecord = null; + ByteBuffer* pNewPayload = null; + int recordCount = 0; + + if (pMessage != null) + { + // shallow copy + recordCount = pMessage->GetRecordsCount(); + + // do shallow copy + __pRecievedMessage = new (std::nothrow) NdefMessage(); + SysTryReturnVoidResult(NID_NET_NFC, __pRecievedMessage != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + for (int i = 0; i < recordCount; i++) + { + pNdefRecord = new (std::nothrow) NdefRecord(pMessage->GetRecordAt(i)->GetRecordType()); + SysTryReturnVoidResult(NID_NET_NFC, pNdefRecord != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pNdefRecord->SetPayloadId(pMessage->GetRecordAt(i)->GetPayloadId()); + const ByteBuffer* pPayload = pMessage->GetRecordAt(i)->GetPayload(); + if (pPayload) + { + pNewPayload = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_NET_NFC, pNewPayload != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + pNewPayload->Construct(*pPayload); + pNdefRecord->SetPayload(*pNewPayload); + delete pNewPayload; + pNewPayload = null; + } + r = __pRecievedMessage->AppendRecord(*pNdefRecord); + } + } +} + +_TagConnectionEventArg::_TagConnectionEventArg(result r) + : __eventType(_TAG_CON_EVENT_TYPE_WRITE_COMPLETED) + , __pRecievedMessage(null) + , __pResponseData(null) + , __result(r) +{ +} + +_TagConnectionEventArg::_TagConnectionEventArg(Tizen::Base::ByteBuffer* pResponse, result r) + : __eventType(_TAG_CON_EVENT_TYPE_RESPONSE_RECEIVED) + , __pRecievedMessage(null) + , __pResponseData(null) + , __result(r) +{ + if (pResponse != null) + { + // shallow copy + __pResponseData = new (std::nothrow) ByteBuffer; + SysTryReturnVoidResult(NID_NET_NFC, __pResponseData != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + __pResponseData->Construct(*pResponse); + } +} + +_TagConnectionEventArg::~_TagConnectionEventArg(void) +{ + if (__pRecievedMessage) + { + __pRecievedMessage->RemoveAllRecords(true); + delete __pRecievedMessage; + } + + if (__pResponseData) + { + delete __pResponseData; + } +} + +_TagConnectionEventType +_TagConnectionEventArg::GetEventType(void) const +{ + return __eventType; +} + +NdefMessage* +_TagConnectionEventArg::GetNdefMessage(void) const +{ + return __pRecievedMessage; +} + +Tizen::Base::ByteBuffer* +_TagConnectionEventArg::GetResponse(void) const +{ + return __pResponseData; +} + +result +_TagConnectionEventArg::GetResult(void) const +{ + return __result; +} + +} } } // Tizen::Net::Nfc diff --git a/src/FNetNfc_TagConnectionEventArg.h b/src/FNetNfc_TagConnectionEventArg.h new file mode 100644 index 0000000..e6e733c --- /dev/null +++ b/src/FNetNfc_TagConnectionEventArg.h @@ -0,0 +1,129 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcTagConnectionEventArg.h + * @brief This is the header file for the _TagConectionEventArg Class. + * + * This header file contains declaration of the _TagConectionEventArg Class. + */ +#ifndef _FNET_NFC_INTERNAL_TAG_CONNECTION_EVENT_ARG_H_ +#define _FNET_NFC_INTERNAL_TAG_CONNECTION_EVENT_ARG_H_ + +#include +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base { namespace Runtime +{ +class ByteBuffer; +class IEventListener; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NdefMessage; + +/** + * @enum _TagConnectionEventType + * + * Defines the type of the tag connection event. + */ +enum _TagConnectionEventType +{ + _TAG_CON_EVENT_TYPE_READ_COMPLETED, + _TAG_CON_EVENT_TYPE_WRITE_COMPLETED, + _TAG_CON_EVENT_TYPE_RESPONSE_RECEIVED +}; + +/** + * @class _TagConnectionEvent + * @brief This class is used as an argument of methods of the _TagConnectionEvent class. + * + * When the connection with the detected NFC tag is established and the events are detected from it, the + * ITagConnectionEventListner objects registered to the event are called with this argument class. + */ +class _TagConnectionEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ +public: + /** + * This is the constructor for _TAG_CON_EVENT_TYPE_READ_COMPLETED. + */ + _TagConnectionEventArg(NdefMessage* pMessage, result r); + + /** + * This is the constructor for _TAG_CON_EVENT_TYPE_WRITE_COMPLETED. + */ + _TagConnectionEventArg(result r); + + /** + * This is the constructor for _TAG_CON_EVENT_TYPE_RESPONSE_RECEIVED. + */ + _TagConnectionEventArg(Tizen::Base::ByteBuffer* pResponse, result r); + + /** + * This is the class destructor. + */ + ~_TagConnectionEventArg(void); + + /** + * Gets the tag event type. + * + * @return The type of the event + */ + _TagConnectionEventType GetEventType(void) const; + + /** + * Gets the NDEF Message. + * + * @return The detected NDEF message + */ + NdefMessage* GetNdefMessage(void) const; + + /** + * Gets the response data. + * + * @return The response data + */ + Tizen::Base::ByteBuffer* GetResponse(void) const; + + /** + * Gets the action result. + * + * @return The error code + */ + result GetResult(void) const; + +private: + _TagConnectionEventArg(const _TagConnectionEventArg& value); + _TagConnectionEventArg& operator =(const _TagConnectionEventArg& value); + +private: + _TagConnectionEventType __eventType; + NdefMessage* __pRecievedMessage; + Tizen::Base::ByteBuffer* __pResponseData; + result __result; + +}; // _TagConnectionEventArg + +} } } //Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_TAG_CONNECTION_EVENT_ARG_H_ diff --git a/src/FNetNfc_TagConnectionImpl.cpp b/src/FNetNfc_TagConnectionImpl.cpp new file mode 100644 index 0000000..edfbf36 --- /dev/null +++ b/src/FNetNfc_TagConnectionImpl.cpp @@ -0,0 +1,509 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// @file FNetNfcTagConnectionImpl.cpp +// @brief This is the implementation file for _TagConnectionImpl class. +// +// This file contains the implementation of _TagConnectionImpl class. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "FNetNfc_NfcTagImpl.h" +#include "FNetNfc_TagConnectionImpl.h" +#include "FNetNfc_NfcSystemAdapter.h" +#include + +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Net { namespace Nfc +{ + +_TagConnectionImpl::_TagConnectionImpl(void) + : __pTargetTag(null) + , __pSystemAdapter(null) + , __pConnectionListener(null) + , __pNdefTagListener(null) + , __stateMutex() + , __currentState(_TAG_CONNECTION_STATE_CONNECTED) +{ +} + +_TagConnectionImpl::~_TagConnectionImpl(void) +{ + if (__pSystemAdapter) + { + __pSystemAdapter->UnregisterTagConnectionListener(*this); + } + + delete __pTargetTag; +} + +result +_TagConnectionImpl::Construct(const _NfcTagImpl& tagImpl) +{ + result r = E_SUCCESS; + + r = __stateMutex.Create(); + SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Internal error occurred on initializing the tag connection."); + + __pSystemAdapter = _NfcSystemAdapter::GetInstance(); + SysTryReturnResult(NID_NET_NFC, __pSystemAdapter != null, E_SYSTEM, + "Internal error occurred on initializing the tag connection."); + + __pTargetTag = _NfcTagImpl::GetNfcTagN(tagImpl); + SysTryReturnResult(NID_NET_NFC, __pTargetTag != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + return E_SUCCESS; +} + +const NfcTag* +_TagConnectionImpl::GetTargetTag(void) const +{ + return __pTargetTag; +} + +result +_TagConnectionImpl::SetTagConnectionListener(ITagConnectionListener* pListener) +{ + result r = E_SUCCESS; + + if ((__pNdefTagListener == null) && (__pConnectionListener == null) && (pListener != null)) + { + // Register the connection event listener to _NfcSystemAdapter + r = __pSystemAdapter->RegisterTagConnectionListener(*this); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, + "[E_SYSTEM] Internal error occurred on registering the event listener."); + } + + if ((__pNdefTagListener == null) && (__pConnectionListener != null) && (pListener == null)) + { + // Unregister the connection event listener to _NfcSystemAdapter + r = __pSystemAdapter->UnregisterTagConnectionListener(*this); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, + "[E_SYSTEM] Internal error occurred on registering the event listener."); + } + + __pConnectionListener = pListener; + + return E_SUCCESS; +} + +result +_TagConnectionImpl::SetNdefTagConnectionListener(INdefTagConnectionListener* pListener) +{ + result r = E_SUCCESS; + + if ((__pConnectionListener == null) && (__pNdefTagListener == null) && (pListener != null)) + { + // Register the connection event listener to _NfcSystemAdapter + r = __pSystemAdapter->RegisterTagConnectionListener(*this); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, + "[E_SYSTEM] Internal error occurred on registering the event listener."); + } + + if ((__pConnectionListener == null) && (__pNdefTagListener != null) && (pListener == null)) + { + // Unregister the connection event listener to _NfcSystemAdapter + r = __pSystemAdapter->UnregisterTagConnectionListener(*this); + SysTryReturn(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, + "[E_SYSTEM] Internal error occurred on registering the event listener."); + } + + __pNdefTagListener = pListener; + + return E_SUCCESS; +} + +result +_TagConnectionImpl::SendCommand(const Tizen::Base::ByteBuffer& command) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + result r = E_SUCCESS; + + SysTryReturn(NID_NET_NFC, command.GetRemaining() != 0, E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Invalid argument is used. command is empty"); + + MutexGuard locked(__stateMutex); + + switch (__currentState) + { + case _TAG_CONNECTION_STATE_DISABLED: + r = E_CONNECTION_FAILED; + break; + + case _TAG_CONNECTION_STATE_CONNECTED: + r = __pSystemAdapter->SendCommand(command); + + if (r == E_SUCCESS) + { + __currentState = _TAG_CONNECTION_STATE_SEND_REQUESTED; + } + break; + + case _TAG_CONNECTION_STATE_SEND_REQUESTED: + r = E_IN_PROGRESS; + break; + + case _TAG_CONNECTION_STATE_READ_REQUESTED: + case _TAG_CONNECTION_STATE_WRITE_REQUESTED: + r = E_CONNECTION_BUSY; + break; + + default: + r = E_SYSTEM; + break; + } + + locked.Unlock(); + + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred on sending a command to the target tag.", GetErrorMessage(r)); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + return r; +} + +result +_TagConnectionImpl::Read(void) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + result r = E_SUCCESS; + + MutexGuard locked(__stateMutex); + + switch (__currentState) + { + case _TAG_CONNECTION_STATE_DISABLED: + r = E_CONNECTION_FAILED; + break; + + case _TAG_CONNECTION_STATE_CONNECTED: + r = __pSystemAdapter->Read(); + if (r == E_SUCCESS) + { + __currentState = _TAG_CONNECTION_STATE_READ_REQUESTED; + } + break; + + case _TAG_CONNECTION_STATE_READ_REQUESTED: + r = E_IN_PROGRESS; + break; + + case _TAG_CONNECTION_STATE_SEND_REQUESTED: + case _TAG_CONNECTION_STATE_WRITE_REQUESTED: + r = E_CONNECTION_BUSY; + break; + + default: + r = E_SYSTEM; + break; + } + + locked.Unlock(); + + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred on reading the NDEF message from the target tag.", GetErrorMessage(r)); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + return r; +} + +result +_TagConnectionImpl::Write(const NdefMessage& message) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + result r = E_SUCCESS; + + SysTryReturn(NID_NET_NFC, message.GetRecordsCount() != 0, E_INVALID_ARG, E_INVALID_ARG, + "Invalid argument is used. NDEF message does not contain any NDEF records"); + + MutexGuard locked(__stateMutex); + + switch (__currentState) + { + case _TAG_CONNECTION_STATE_DISABLED: + r = E_CONNECTION_FAILED; + break; + + case _TAG_CONNECTION_STATE_CONNECTED: + r = __pSystemAdapter->Write(message); + if (r == E_SUCCESS) + { + __currentState = _TAG_CONNECTION_STATE_WRITE_REQUESTED; + } + break; + + case _TAG_CONNECTION_STATE_WRITE_REQUESTED: + r = E_IN_PROGRESS; + break; + + case _TAG_CONNECTION_STATE_SEND_REQUESTED: + case _TAG_CONNECTION_STATE_READ_REQUESTED: + r = E_CONNECTION_BUSY; + break; + + default: + r = E_SYSTEM; + break; + } + + locked.Unlock(); + + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred on writing an NDEF message from the target tag.", GetErrorMessage(r)); + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + return r; +} + +TagConnection* +_TagConnectionImpl::GetTagConnectionN(const _NfcTagImpl& tagImpl) +{ + result r = E_SUCCESS; + TagConnection* pConnection = null; + _TagConnectionImpl* pConnectionImpl = null; + + if (tagImpl.IsNdefSupported()) + { + pConnection = new (std::nothrow) NdefTagConnection(); + } + else + { + pConnection = new (std::nothrow) TagConnection(); + } + + if (pConnection != null) + { + pConnectionImpl = new (std::nothrow) _TagConnectionImpl(); + + if (pConnectionImpl) + { + // Invokes the construct method of TagConnection because TagConnection and NdefTagConnection use the common impl class. + r = pConnectionImpl->Construct(tagImpl); + + if (r == E_SUCCESS) + { + pConnection->_pImpl = pConnectionImpl; + } + else + { + delete pConnectionImpl; + delete pConnection; + pConnection = null; + } + } + else + { + delete pConnection; + pConnection = null; + } + } + + return pConnection; +} + +void +_TagConnectionImpl::OnNdefReadCompletedN(NdefMessage* pMessage, result r) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + bool isFired = false; + + MutexGuard locked(__stateMutex); + + if (__currentState == _TAG_CONNECTION_STATE_READ_REQUESTED) + { + __currentState = _TAG_CONNECTION_STATE_CONNECTED; + isFired = true; + } + + locked.Unlock(); + + if (isFired) + { + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred during the NDEF read operation.", GetErrorMessage(r)); + } + + if (__pNdefTagListener != null) + { + __pNdefTagListener->OnNdefReadCompletedN(pMessage, r); + } + } + + // delete the input parameter if it was not passed to the listener which is responsible for deleting it + if ((isFired == false) || (__pNdefTagListener == null)) + { + if (pMessage) + { + pMessage->RemoveAllRecords(true); + delete pMessage; + } + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [READ_COMPLETED_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_TagConnectionImpl::OnNdefWriteCompleted(result r) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + bool isFired = false; + + MutexGuard locked(__stateMutex); + + if (__currentState == _TAG_CONNECTION_STATE_WRITE_REQUESTED) + { + __currentState = _TAG_CONNECTION_STATE_CONNECTED; + isFired = true; + } + + locked.Unlock(); + + if (isFired) + { + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred during the NDEF write operation.", GetErrorMessage(r)); + } + + if (__pNdefTagListener != null) + { + __pNdefTagListener->OnNdefWriteCompleted(r); + } + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [WRITE_COMPLETED_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_TagConnectionImpl::OnNfcResponseReceivedN(Tizen::Base::ByteBuffer* pResponse, result r) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r)); + + bool isFired = false; + + MutexGuard locked(__stateMutex); + + if (__currentState == _TAG_CONNECTION_STATE_SEND_REQUESTED) + { + __currentState = _TAG_CONNECTION_STATE_CONNECTED; + isFired = true; + } + + locked.Unlock(); + + if (isFired) + { + if (r != E_SUCCESS) + { + SysLogException(NID_NET_NFC, r, "[%s] exception occurred during the send operation.", GetErrorMessage(r)); + } + + if (__pConnectionListener != null) + { + __pConnectionListener->OnNfcResponseReceivedN(pResponse, r); + } + } + + // delete the input parameter if it was not passed to the listener which is responsible for deleting it + if ((isFired == false) || (__pConnectionListener == null)) + { + delete pResponse; + } + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s], [RESPONSE_RECV_Event:%s]", + GetStringOfCurrentState(), isFired ? "Fired" : "NotFired"); +} + +void +_TagConnectionImpl::OnNfcConnectionClosed(void) +{ + SysLog(NID_NET_NFC, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState()); + + MutexGuard locked(__stateMutex); + + if (__currentState != _TAG_CONNECTION_STATE_DISABLED) + { + __currentState = _TAG_CONNECTION_STATE_DISABLED; + } + + locked.Unlock(); + + __pSystemAdapter->UnregisterTagConnectionListener(*this); + + SysLog(NID_NET_NFC, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState()); +} + +const char* +_TagConnectionImpl::GetStringOfCurrentState(void) const +{ + const char* pStateString = null; + + switch (__currentState) + { + case _TAG_CONNECTION_STATE_DISABLED: + pStateString = "DISABLED"; + break; + + case _TAG_CONNECTION_STATE_CONNECTED: + pStateString = "CONNECTED"; + break; + + case _TAG_CONNECTION_STATE_SEND_REQUESTED: + pStateString = "SEND_REQUESTED"; + break; + + case _TAG_CONNECTION_STATE_READ_REQUESTED: + pStateString = "READ_REQUESTED"; + break; + + case _TAG_CONNECTION_STATE_WRITE_REQUESTED: + pStateString = "WRITE_REQUESTED"; + break; + + default: + pStateString = ""; + break; + } + + return pStateString; +} + +} } } // Tizen::Net::Nfc diff --git a/src/inc/FNetNfc_ConnectivityIpcMessages.h b/src/inc/FNetNfc_ConnectivityIpcMessages.h new file mode 100644 index 0000000..466c200 --- /dev/null +++ b/src/inc/FNetNfc_ConnectivityIpcMessages.h @@ -0,0 +1,38 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_ConnectivityIpcMessages.h + * @brief This is the header file for the Connectivity service daemon's IPC messages. + * + * This header file contains the declarations of the IPC messages for the Connectivity service daemon. + */ + +#include +#include +#include + +#ifndef NFC_CONNECTIVITY_IPC_SERVER_NAME +#define NFC_CONNECTIVITY_IPC_SERVER_NAME "osp.net.nfc.ipcserver.connectivity" +#endif + +#define IPC_MESSAGE_START ConnectivityNfcServiceMsgStart + +// Client -> Server (sync) +IPC_SYNC_MESSAGE_CONTROL0_1(ConnectivityNfcServiceMsg_initialize, unsigned long /* result */) +IPC_SYNC_MESSAGE_CONTROL1_1(ConnectivityNfcServiceMsg_setLaunchPopupEnabled, bool /* enable */, unsigned long /* result */) +IPC_SYNC_MESSAGE_CONTROL2_1(ConnectivityNfcServiceMsg_registerPushMessage, Tizen::Base::ByteBuffer /* message */, Tizen::Base::String /* description */, unsigned long /* result */) +IPC_SYNC_MESSAGE_CONTROL0_1(ConnectivityNfcServiceMsg_unregisterPushMessage, unsigned long /* result */) diff --git a/src/inc/FNetNfc_ITagConnectionListener.h b/src/inc/FNetNfc_ITagConnectionListener.h new file mode 100644 index 0000000..17e276d --- /dev/null +++ b/src/inc/FNetNfc_ITagConnectionListener.h @@ -0,0 +1,103 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_ITagConnectionListener.h + * @brief This is the header file for the _ITagConnectionListener interface. + * + * This header file contains the declaration of the _ITagConnectionListener interface. + * + */ +#ifndef _FNET_NFC_INTERNAL_ITAG_CONNECTION_LISTENER_H_ +#define _FNET_NFC_INTERNAL_ITAG_CONNECTION_LISTENER_H_ + +#include +#include + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NdefMessage; + +/** + * @interface _ITagConnectionListener + * @brief This interface provides a listener for the events related to the NFC tag connection. + * + * The _ITagConnectionListener interface specifies the event listener methods invoked by _NfcSystemAdapter for + * notifying NFC connection events. + */ + +class _OSP_EXPORT_ _ITagConnectionListener + : public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This is the virtual destructor for this class. + */ + virtual ~_ITagConnectionListener(void) {} + + /** + * Notify when the read from the remote tag is completed. + * + * @param[in] pMessage The read NdefMessageobject, @c null if the method was not successful + * @param[in] r An error code + * @exception E_SUCCESS The method was successful. + * @exception E_DATA_NOT_FOUND The target tag has no NDEF record. + * @exception E_INVALID_FORMAT The read data cannot be formulated to NDEF message. + * @exception E_SYSTEM A system error occurred. + */ + virtual void OnNdefReadCompletedN(NdefMessage* pMessage, result r) = 0; + + /** + * Notify when the write to the remote tag is completed. + * + * @param[in] r An error code + * @exception E_SUCCESS The method was successful. + * @exception E_ILLEGAL_ACCESS Permission to write was denied. + * @exception E_STORAGE_FULL The storage of target tag is full. + * @exception E_SYSTEM A system error occurred. + */ + virtual void OnNdefWriteCompleted(result r) = 0; + + /** + * Notify when the response is received from remote tag. + * + * @param[in] pResponse The response of the command as ByteBuffer object, @c null if the method was not successful + * @param[in] r An error code + * @exception E_SUCCESS The method was successful. + * @exception E_ILLEGAL_ACCESS Permission to process the command was denied. + * @exception E_STORAGE_FULL The storage of target tag is full. + * @exception E_SYSTEM A system error occurred. + */ + virtual void OnNfcResponseReceivedN(Tizen::Base::ByteBuffer* pResponse, result r) = 0; + + /** + * Notify when the tag connection is closed + */ + virtual void OnNfcConnectionClosed(void) = 0; + +}; // _ITagConnectionListener + +} } } + +#endif // _FNET_NFC_INTERNAL_ITAG_CONNECTION_LISTENER_H_ diff --git a/src/inc/FNetNfc_NdefMessageImpl.h b/src/inc/FNetNfc_NdefMessageImpl.h new file mode 100644 index 0000000..b874458 --- /dev/null +++ b/src/inc/FNetNfc_NdefMessageImpl.h @@ -0,0 +1,233 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefMessageImpl.h + * @brief This is the header file for the _NdefMessageImpl class. + * + * This header file contains the declarations of the _NdefMessageImpl class. + */ + +#ifndef _FNET_NFC_INTERNAL_NDEF_MESSAGE_IMPL_H_ +#define _FNET_NFC_INTERNAL_NDEF_MESSAGE_IMPL_H_ + +#include +#include +#include +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +class String; +namespace Collection +{ +class LinkedList; +} +} } + +namespace Tizen { namespace Net { namespace Nfc +{ +// Forward declaration +class NdefRecordType; +class NdefRecord; + +/** + * @class _NdefMessageImpl + * @brief This class provides information and performs operations on a NDEF Message + */ +class _OSP_EXPORT_ _NdefMessageImpl + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + */ + _NdefMessageImpl(void); + + /** + * This is copy constructor for this class. + * + * @param[in] value An instance of _NdefMessageImpl + * @remarks It performs a deep copy. + */ + _NdefMessageImpl(const _NdefMessageImpl& value); + + /** + * This is the destructor for this class. + */ + ~_NdefMessageImpl(void); + + /** + * Compares the calling instance with the specified instance. + * + * @return @c true if the specified instance of %Object is equal to the calling %_NdefMessageImpl instance, @n + * else @c false + * @param[in] obj The object to compare + * @remark Two %_NdefMessageImpl instances are equal only if they contain the same %NdefRecord instances in + * the same order. + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Gets the number of NDEF records in the NDEF message. + * + * @return The number of NDEF records + */ + int GetRecordsCount() const; + + /** + * Searches for an NdefRecord instance in the NDEF message. @n + * Gets the index of the NdefRecord instance if found. + * + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_NOT_FOUND The specified @c record was not found. + * @remarks This method checks the equality of the pointers. + */ + result IndexOf(const NdefRecord& record, int& index) const; + + /** + * Gets the NdefRecord object at the specified location. + * + * @return The requested NdefRecord object, @c null if the index is not valid + * @param[in] index The index of the NDEF record to get + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index is either equal to or greater than the number of + * elements or less than zero. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + NdefRecord* GetRecordAt(int index) const; + + /** + * Gets the NdefRecord object with the specified payload identifier. + * + * @return The requested NdefRecord object, @c null if no record is matched. + * @param[in] payloadId The payload identifier of the NDEF record to get + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_NOT_FOUND The @id was not found in any NDEF records. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + NdefRecord* GetRecord(const Tizen::Base::String& payloadId) const; + + /** + * Appends the specified NDEF record after the last NDEF record in the NDEF message. + * + * @return An error code + * @param[in] record The NDEF record to add + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The specified NDEF record has the same payload identifier as other records in + * this NDEF message. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @remarks This method performs a shallow copy. It adds just the pointer; not the NdefRecord instance itself. + */ + result AppendRecord(const NdefRecord& record); + + /** + * Inserts the specified NDEF record into the NDEF message at the specified location. + * + * @return An error code + * @param[in] record An NDEF record to insert + * @param[in] index The index at which the NDEF record should be inserted + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index is either equal to or greater than the number of + * elements or less than zero. + * @exception E_INVALID_ARG The specified NDEF record has the same payload identifier as other records in + * this NDEF message. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @remarks The NDEF records that follow the insertion point move down to accommodate the inserted NDEF + * record. @n + * This method performs a shallow copy. It adds just the pointer; not the NdefRecord instance itself. + */ + result InsertRecordAt(const NdefRecord& record, int index); + + /** + * Removes the NDEF record at the specified location. + * + * @return An error code + * @param[in] index The index at which the NDEF record should be removed + * @param[in] deallocate Set to @c true to deallocate the record @c false, otherwise + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index is either equal to or greater than the number of + * elements or less than zero. + * @remarks The NDEF records that follow the deletion point move up to occupy the vacated spot. + */ + result RemoveRecordAt(int index, bool deallocate); + + /** + * Replaces the NDEF record at the specified location with the specified NDEF record. + * + * @return An error code + * @param[in] record An NDEF record to set + * @param[in] index The index at which the NDEF record should be set + * @param[in] deallocate Set to @c true to deallocate the replaced record @c false, otherwise + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the record list. @n + * The specified @c index is either equal to or greater than the number of + * elements or less than zero. + * @exception E_INVALID_ARG The specified NDEF record has the same payload identifier as other records in + * this NDEF message. + * @remarks This method performs a shallow copy. It adds just the pointer; not the NdefRecord instance itself. + */ + result SetRecordAt(const NdefRecord& record, int index, bool deallocate); + + /** + * Remove all records in the NDEF message. + * If the specified @c deallocate is set to @c true, it deallocates all the NdefRecord instance in the message. + * + * @param[in] deallocate Set to @c true to deallocate the record @c false, otherwise + */ + void RemoveAllRecords(bool deallocate); + + /** + * Gets the whole NDEF message with all the NDEF records as a ByteBuffer. + * + * @return The NDEF message as a ByteBuffer, @c null if the getting fails. + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_DATA The NDEF message does not contain any NDEF records. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_SYSTEM A system error occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* ToByteBufferN(const NdefMessage& message) const; + + /** + * This assignment operator copies the values from the specified instance of %_NdefMessageImpl to the calling + * instance of %_NdefMessageImpl. + * + * @return A reference to the %_NdefMessageImpl instance + * @param[in] rhs A reference to the %_NdefMessageImpl instance to copy + */ + _NdefMessageImpl& operator =(const _NdefMessageImpl& value); + +private: + std::unique_ptr __pRecordList; +}; // _NdefMessageImpl + +} } } // Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NDEF_MESSAGE_IMPL_H_ diff --git a/src/inc/FNetNfc_NdefMessageUtil.h b/src/inc/FNetNfc_NdefMessageUtil.h new file mode 100644 index 0000000..c07da57 --- /dev/null +++ b/src/inc/FNetNfc_NdefMessageUtil.h @@ -0,0 +1,115 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcINdefMessageUtil.h + * @brief This is the header file for _NdefMessageUtil. + * + * This header file contains the declarations of the _NdefMessageUtil class. + */ +#ifndef _FNET_NFC_INTERNAL_NDEF_MESSAGE_UTIL_H_ +#define _FNET_NFC_INTERNAL_NDEF_MESSAGE_UTIL_H_ + +#include +#include + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +class String; +namespace Collection +{ +class IList; +} +} } + +namespace Tizen { namespace Net { namespace Nfc +{ +// Forward declaration +class NdefRecordType; + +struct _NdefMessageDeleter +{ + void operator()(NdefMessage* pNdefMessage) + { + pNdefMessage->RemoveAllRecords(true); + delete pNdefMessage; + } +}; +/** + * @class _NdefMessageUtil + * @brief Utility class of the NDEF Message. + */ +class _OSP_EXPORT_ _NdefMessageUtil +{ +public: + /** + * Converts the whole NDEF message with all the NDEF records to a ByteBuffer + * + * @return NDEF message as a ByteBuffer + * @param[in] message NDEF message to be converted + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory + * @exception E_SYSTEM A failure occurred from the underlying system. + */ + static Tizen::Base::ByteBuffer* ToByteBufferN(const NdefMessage& ndefMessage); + + /** + * Generates the NDEF message from ByteBuffer + * + * @return An NDEF message as a NdefMessage instance + * @param[in] buffer NDEF message as a ByteBuffer to be converted + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_FORMAT The record payload can not be formulated to NDEF message. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_SYSTEM A system error occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + static NdefMessage* ToNdefMessageN(const Tizen::Base::ByteBuffer& buffer); + + + /** + * Checks whether Record type name is valid with specified record type name format + * + * @return @c true, if the name is valid @n + * @c false, otherwise + * @param[in] type NdefRecordTypeNameFormat + * @param[in] name Record type name to be checked + */ + static bool IsValidRecordType(NdefRecordTypeNameFormat type, const Tizen::Base::String& name); + + /** + * Gets the equivalent record type list + * + * @return list of record types equivalent to specified record type + * @param[in] recordType NdefRecordType + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory + * @exception E_SYSTEM A failure occurred from the underlying system. + */ + static Tizen::Base::Collection::IList* GetEquivalentRecordTypesN(const NdefRecordType& recordType); + +private: + _NdefMessageUtil(void); + ~_NdefMessageUtil(void); + _NdefMessageUtil(const _NdefMessageUtil& value); + _NdefMessageUtil& operator =(const _NdefMessageUtil& value); + +}; // _NdefMessageUtil + +} } } +#endif // _FNET_NFC_INTERNAL_NDEF_MESSAGE_UTIL_H_ diff --git a/src/inc/FNetNfc_NdefPushManagerImpl.h b/src/inc/FNetNfc_NdefPushManagerImpl.h new file mode 100644 index 0000000..35a23b9 --- /dev/null +++ b/src/inc/FNetNfc_NdefPushManagerImpl.h @@ -0,0 +1,126 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NdefPushManagerImpl.h + * @brief This is the header file for the _NdefPushManagerImpl Class. + * + * This header file contains the declarations of the _NdefPushManagerImpl Class. + */ +#ifndef _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_IMPL_H_ +#define _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_IMPL_H_ + +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class _NfcSystemAdapter; +class NdefMessage; +class INdefPushManagerListener; +class _NdefPushManagerEvent; + +/** + * @class _NdefPushManagerImpl + * @brief This class provides information and performs operations of a _NdefPushManagerImpl. + */ +class _OSP_EXPORT_ _NdefPushManagerImpl + : public Tizen::Base::Object +{ + +public: + /** + * This is the default constructor for this class. + */ + _NdefPushManagerImpl(void); + + /** + * This is the destructor for this class. + */ + ~_NdefPushManagerImpl(void); + + /** + * Sets a listener for receiving the result of pushing an NDEF message. + * + * @return An error code + * @param[in] pListener The %INdefPushManagerListener instance to be added + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OPERATION_FAILED The operation has failed. + */ + result SetNdefPushManagerListener(INdefPushManagerListener* pListener); + + /** + * Pushes the NDEF message. + * + * @return An error code + * @param[in] message The NDEF message to be sent + * @exception E_SUCCESS The method is successful. + * @exception E_DEVICE_BUSY The device is processing preceding job. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_STATE This instance is in an invalid state. @n + * For example, the NFC feature is not activated @n + * or a peer device is not attached. + * @exception E_OPERATION_FAILED The operation has failed. + */ + result Push(const NdefMessage& message); + + /** + * Callback method which implements _INdefPushManagerListener + */ + void OnNdefPushMessageSent(result r); + + /** + * Registers an NDEF message to be pushed if the home screen or the main menu is on top of the screen in the local + * device when a peer device is detected. + * + * @return An error code + * @param[in] message The NDEF message to be registered + * @param[in] description The description for the NDEF message to be registered + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The input @c message is invalid. @n + * For example, it does not contain any NDEF records. + * @exception E_SYSTEM A system error has occurred. + * @remarks An application can register only one NDEF message. So the previously registered message will be + * replaced by the new one. + */ + static result RegisterNdefPushMessage(const NdefMessage& message, const Tizen::Base::String& description); + + /** + * Unregisters an NDEF message if the NDEF message to be pushed is registered. + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + */ + static result UnregisterNdefPushMessage(void); + +private: + _NdefPushManagerImpl(const _NdefPushManagerImpl& rhs); + _NdefPushManagerImpl& operator =(const _NdefPushManagerImpl& rhs); + +private: + nfc_p2p_target_h __p2pTargetHandle; + _NfcSystemAdapter* __pSystemAdapter; + std::unique_ptr<_NdefPushManagerEvent> __pNdefPushManagerEvent; + INdefPushManagerListener* __pPreviousListener; +}; // _NdefPushManagerImpl + +} } } +#endif // _FNET_NFC_INTERNAL_NDEF_PUSH_MANAGER_IMPL_H_ diff --git a/src/inc/FNetNfc_NdefRecordImpl.h b/src/inc/FNetNfc_NdefRecordImpl.h new file mode 100644 index 0000000..85b9915 --- /dev/null +++ b/src/inc/FNetNfc_NdefRecordImpl.h @@ -0,0 +1,181 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefRecordImpl.h + * @brief This is the header file for the NdefRecordImpl class. + * + * This header file contains the declarations of the NdefRecordImpl class. + */ + +#ifndef _FNET_NFC_INTERNAL_NDEF_RECORD_IMPL_H_ +#define _FNET_NFC_INTERNAL_NDEF_RECORD_IMPL_H_ + +#include +#include +#include +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NdefMessage; +class NdefRecord; +class _NdefMessageImpl; + +/** + * @class _NdefRecordImpl + * @brief This class provides information and performs operations on a NDEF Record + */ +class _OSP_EXPORT_ _NdefRecordImpl + : public Tizen::Base::Object +{ +public: + /** + * This constructor initializes this instance of _NdefRecordImpl with the specified record type. + * + * @param[in] recordType A specified NDEF record type + */ + _NdefRecordImpl(const NdefRecordType& recordType); + + /** + * This is a copy constructor for this class. + * + * @param[in] value An instance of _NdefRecordImpl + * @remarks It performs a deep copy. + */ + _NdefRecordImpl(const _NdefRecordImpl& value); + + /** + * This is the destructor for this class. + */ + ~_NdefRecordImpl(void); + + /** + * Compares the calling instance with the specified instance. + * + * @return @c true if the specified instance of %Object is equal to the calling %_NdefRecordImpl instance, @n + * else @c false + * @param[in] obj The object to compare + * @remark Two %_NdefRecordImpl instances are equal only if they contain the same record type, payload ID, and payload. + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Gets the identifier for the record payload. + * + * @return The identifier of the payload @n + * An empty string if the identifier does not exist in the NDEF record. + */ + Tizen::Base::String GetPayloadId(void) const; + + /** + * Gets the payload in the NDEF record as ByteBuffer. + * + * @return The payload, @c null if the NDEF record does not have it + */ + Tizen::Base::ByteBuffer* GetPayload(void) const; + + /** + * Gets the record type of this NDEF record + * + * @return NdefRecordType + */ + NdefRecordType GetRecordType(void) const; + + /** + * Sets the record type of this NDEF record. + * + * @return An error code + * @param[in] type The record type to set + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG Setting the record type with NDEF_TNF_EMPTY is not allowed + * if the ID is not an empty string or the payload is not null. + */ + result SetRecordType(NdefRecordType& type); + + /** + * Sets the identifier for the payload. + * + * @return An error code + * @param[in] id The identifier of the payload + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION Setting the payload identifier is not allowed if the name format of the record type is + * NDEF_TNF_EMPTY. + * @exception E_INVALID_ARG The specified identifier is the same as other records in this NDEF message. + * @exception E_MAX_EXCEEDED The length of the id exceeds 256 bytes. + */ + result SetPayloadId(const Tizen::Base::String& id); + + /** + * Sets the given data into the payload of this class. + * + * @return An error code + * @param[in] payload The payload data + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION Setting the payload is not allowed if the name format of the record type is + * NDEF_TNF_EMPTY. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_INVALID_ARG A specified input parameter is invalid. @n + * The source payload is not constructed. + */ + result SetPayload(const Tizen::Base::ByteBuffer& payload); + + static void SetMessageImpl(const NdefRecord& record, const _NdefMessageImpl* pNdefMessageImpl); + + /** + * This assignment operator copies the values from the specified instance of %_NdefRecordImpl to the calling instance of + * %_NdefRecordImpl. + * + * @return A reference to the %_NdefRecordImpl instance + * @param[in] rhs A reference to the %_NdefRecordImpl instance to copy + */ + _NdefRecordImpl& operator =(const _NdefRecordImpl& value); + +private: + // + // This is the default constructor for this class. + // + _NdefRecordImpl(void); + + result CopyPayloadFrom(const Tizen::Base::ByteBuffer* pPayload); + +private: + NdefRecordType __type; + Tizen::Base::String __id; + std::unique_ptr __pPayload; + _NdefMessageImpl* __pMessageImpl; + +}; // _NdefRecordImpl + +} } } // Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NDEF_RECORD_IMPL_H_ diff --git a/src/inc/FNetNfc_NdefRecordTypeImpl.h b/src/inc/FNetNfc_NdefRecordTypeImpl.h new file mode 100644 index 0000000..9d37f92 --- /dev/null +++ b/src/inc/FNetNfc_NdefRecordTypeImpl.h @@ -0,0 +1,168 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNdefRecordTypeImpl.h + * @brief This is the header file for the _NdefRecordTypeImpl class. + * + * This header file contains the declarations of the _NdefRecordTypeImpl class. + */ + +#ifndef _FNET_NFC_INTERNAL_NDEF_RECORD_TYPE_IMPL_H_ +#define _FNET_NFC_INTERNAL_NDEF_RECORD_TYPE_IMPL_H_ + +#include +#include +#include +#include + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NdefRecordType; + +/** + * @class _NdefRecordTypeImpl + * @brief This class encapsulates the type of an NDEF record + */ +class _OSP_EXPORT_ _NdefRecordTypeImpl + : public Tizen::Base::Object +{ +public: + /** + * This is a constructor for this class. + * This constructor initializes the name format with the specified parameter. + * + * @param[in] format NDEF record type name format + */ + _NdefRecordTypeImpl(NdefRecordTypeNameFormat format); + + /** + * This is a copy constructor for this class. + * + * @param[in] value An instance of %_NdefRecordTypeImpl + */ + _NdefRecordTypeImpl(const _NdefRecordTypeImpl& value); + + /** + * This is the destructor for this class. + */ + ~_NdefRecordTypeImpl(void); + + /** + * Compares two record types + * + * @return @c true, if record types are equal,@n + * @c false, otherwise + * @param[in] obj record type that this record type is compared to + * + * @remarks + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Record type format nameComparison rule for record type name
NDEF_TNF_WELL_KNOWNcharacter-by-character in case-sensitive manner.
NDEF_TNF_MIME_MEDIA character-by-character in case-insensitive manner up to the first ";"
NDEF_TNF_ABSOLUTE_URI Reserved characters must be percent-encoded and the hexadecimal digits in those normalized to upper-case + * letters. URI The scheme and host parts of the URI must be normalized to lower-case. After this the URIs are + * compared in the character-by-character in case-sensitive manner
NDEF_TNF_EXTERNAL character-by-character in case-insensitive manner
NDEF_TNF_EMPTY | NDEF_TNF_UNKNOWN Both record type names must be null
+ */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @return An integer value indicating the hash value of the current instance + * @remarks Two Equal instances should return the same hash value. + */ + virtual int GetHashCode(void) const; + + /** + * Gets the name format of this record type. + * + * @return The name format of this record type + */ + NdefRecordTypeNameFormat GetNameFormat(void) const; + + /** + * Gets the name of this record type. + * + * @return The name of this record type, An empty string if the name format is NDEF_TNF_EMPTY or + * NDEF_TNF_UNKNOWN + * @remarks The returned name does not have any prefix defined in the NFC Forum. @n + * If the name format of this record type is NDEF_TNF_ABSOLUTE_URI, this method returns the name in + * the same format as it was given in the constructor (with or without percent-encoding). The name + * consists of characters encoded using US_ASCII character set. + */ + Tizen::Base::String GetName(void) const; + + /** + * Sets the name of this record type. + * + * @return An error code + * @param[in] name The name of this record type + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is not allowed if the name format is NDEF_TNF_EMPTY, + * NDEF_TNF_UNKNOWN, or NDEF_TNF_ALL. + * @exception E_INVALID_ENCODING_RANGE The specified input string contains code points that are outside the + * bounds specified by the US_ASCII encoding scheme. + * @exception E_INVALID_FORMAT The format of the specified name is invalid according to the + * specification of each type name format. + * @exception E_MAX_EXCEEDED The length of the name exceeds 256 characters. + * @remarks The input name must not have the prefix defined by the NFC forum such as @c "urn:nfc:wkt:" and + * @c "urn:nfc:ext:". + */ + result SetName(const Tizen::Base::String& name); + + /** + * This assignment operator copies the values from the specified instance of %_NdefRecordTypeImpl to the calling instance of + * %_NdefRecordTypeImpl. + * + * @return A reference to the %_NdefRecordTypeImpl instance + * @param[in] rhs A reference to the %_NdefRecordTypeImpl instance to copy + */ + _NdefRecordTypeImpl& operator =(const _NdefRecordTypeImpl& value); + +private: + _NdefRecordTypeImpl(void); + +private: + NdefRecordTypeNameFormat __format; + Tizen::Base::String __name; +}; // _NdefRecordTypeImpl + +} } } // Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NDEF_RECORD_TYPE_IMPL_H_ diff --git a/src/inc/FNetNfc_NfcManagerImpl.h b/src/inc/FNetNfc_NfcManagerImpl.h new file mode 100644 index 0000000..0944494 --- /dev/null +++ b/src/inc/FNetNfc_NfcManagerImpl.h @@ -0,0 +1,317 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfc_NfcManagerImpl.h + * @brief This is the header file for the _NfcManagerImpl Class. + * + * This header file contains the declarations of the _NfcManagerImpl Class. + */ +#ifndef FNET_NFC_INTERNAL_NFC_MANAGER_IMPL_H +#define FNET_NFC_INTERNAL_NFC_MANAGER_IMPL_H + +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +class Integer; +} } + +namespace Tizen { namespace Base { namespace Collection +{ +class HashMap; +template class IListT; +} } } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class INfcManagerEventListener; +class INfcTagDiscoveryEventListener; +class INfcDeviceDiscoveryEventListener; +class INdefMessageDiscoveryEventListener; +class NdefRecordType; +class TagConnection; +class _NfcTagImpl; +class _NfcSystemAdapter; +class _NfcManagerEvent; +class _NfcDeviceDiscoveryEvent; + +/** + * @class _NfcManagerImpl + * @brief This class provides information and performs operations of a _NfcManagerImpl. + */ +class _OSP_EXPORT_ _NfcManagerImpl + : public Tizen::Base::Object +{ + // + // @enum _NfcManagerStateType + // + // Defines the states of the NfcManager. + // + enum _NfcManagerStateType + { + _NFC_MANAGER_STATE_DISABLED, + _NFC_MANAGER_STATE_ACTIVATING, + _NFC_MANAGER_STATE_DEACTIVATING, + _NFC_MANAGER_STATE_IDLE, + _NFC_MANAGER_STATE_CONNECTED + }; + +public: + /** + * This is the default constructor for this class. + */ + _NfcManagerImpl(void); + + /** + * This is the destructor for this class. + */ + ~_NfcManagerImpl(void); + + /** + * Initializes this instance of _NfcManagerImpl. + * + * @return An error code + * @param[in] listener The listener to be added + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_SYSTEM A system error occurred. + */ + result Construct(INfcManagerEventListener& listener); + + /** + * Activates NFC feature. + * + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE This instance is in an invalid state. + * @exception E_IN_PROGRESS The activation process is in progress. + * @exception E_SYSTEM A system error occurred. + */ + result Activate(void); + + + /** + * Deactivates NFC feature. + * + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE This instance is in an invalid state. + * @exception E_IN_PROGRESS The deactivation process is in progress. + * @exception E_SYSTEM A system error occurred. + */ + result Deactivate(void); + + /** + * Checks whether the NFC feature is activated. + * + * @return @c true, if the NFC feature is activated @n + * @c false, otherwise + */ + bool IsActivated(void) const; + + /** + * Checks whether an NFC tag is currently connected with the device. + * + * @return @c true, if an NFC tag is currently connected @n + * @c false, otherwise + */ + bool IsTagConnected(void) const; + + /** + * Checks whether peer device has been detected. + * + * @return @c true if peer device has been detected, @n + * else @c false + */ + bool IsDeviceDetected(void) const; + + /** + * Gets the tag connection with the currently detected tag. + * + * @return The tag connection with the currently detected tag @n + * @c null if no tag is connected or the getting fails + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_STATE This instance is in an invalid state. + * @exception E_CONNECTION_FAILED The connection with the tag is closed or fails. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_SYSTEM A system error occurred. + */ + TagConnection* GetCurrentTagConnectionN(void) const; + + /** + * Adds a listener instance for tag events with the specified tag type. + * + * @return An error code + * @param[in] listener The listener to be added + * @param[in] type The connection type the application is interested in + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + */ + result AddTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type); + + /** + * Removes the specified listener instance. + * + * @return An error code + * @param[in] listener The listener to be removed + * @param[in] type The tag type the application is not interested in any more + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + * @exception E_SYSTEM A system error occurred. + */ + result RemoveTagDiscoveryEventListener(INfcTagDiscoveryEventListener& listener, NfcTagType type); + + /** + * Adds a listener instance for events about an NDEF message + * which includes the NDEF record with the specified type. + * + * @return An error code + * @param[in] listener The listener to be added + * @param[in] type The type of the NDEF record which the application is interested in + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + */ + result AddNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, const NdefRecordType& type); + + /** + * Removes message listener from the specified NDEF record type + * + * @return An error code + * @param[in] listener The listener to be removed + * @param[in] type The type of the NDEF record which the application is not interested in any more + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + * @exception E_SYSTEM A system error occurred. + */ + result RemoveNdefMessageDiscoveryEventListener(INdefMessageDiscoveryEventListener& listener, const NdefRecordType& type); + + /** + * Adds the specified %INfcDeviceDiscoveryEventListener instance for the device discovery events. + * + * @return An error code + * @param[in] listener The listener to be added + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_ALREADY_EXIST The listener was already added. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + result AddDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener); + + /** + * Removes the specified %INfcDeviceDiscoveryEventListener instance. @n + * The removed listener cannot listen to the events that are fired. + * + * @return An error code + * @param[in] listener The listener to be removed + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + * @exception E_SYSTEM A system error has occurred. + */ + result RemoveDeviceDiscoveryEventListener(INfcDeviceDiscoveryEventListener& listener); + + /** + * Callback method to notify that the target device is detected. + */ + void OnNfcDeviceDetected(void); + + /** + * Callback method to notify that the target device is lost. + */ + void OnNfcDeviceLost(void); + + /** + * Callback method to notify that the NFC is activated. + */ + void OnNfcActivated(result r); + + /** + * Callback method to notify that the NFC is deactivated. + */ + void OnNfcDeactivated(result r); + + /** + * Callback method to notify that the target tag is detected. + */ + void OnNfcTagDetectedN(_NfcTagImpl* pTagImpl); + + /** + * Callback method to notify that the target tag is lost. + */ + void OnNfcTagLost(void); + + /** + * Callback method which implements _INfcManagerEventListener + */ + void OnNdefMessageDetectedN(NdefMessage* pMessage); + + /** + * Gets the NDEF message cached when the tag is detected. + * + * @return The cached %NdefMessage instance, @n + * else @c null if the method is not successful + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS This operation is not allowed because the application is not launched by + * Conditional %App Launch. + * @exception E_INVALID_FORMAT The cached data cannot be converted to the NDEF message. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + static NdefMessage* GetCachedNdefMessageN(void); + + /** + * Enables or disables the Conditional NFC %App Launch pop-up. @n + * The pop-up includes all kinds of UI components that the system raises about NFC as well as a pop-up for + * selecting the launching application when a tag is detected. + * + * @return An error code + * @param[in] enable Set to @c true to enable the Conditional NFC %App Launch pop-up, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + */ + static result SetLaunchPopupEnabled(bool enable); + +private: + _NfcManagerImpl(const _NfcManagerImpl& value); + _NfcManagerImpl& operator =(const _NfcManagerImpl& value); + + bool SendTagDiscoveryEvent(_NfcTagImpl* pTagImpl, bool isDetected); + bool SendNdefMessageDetectedEvent(NdefMessage& message); + const char* GetStringOfCurrentState(void) const; + const char* GetStringOfTagType(NfcTagType tagType) const; + void ConvertByteToString(const Tizen::Base::ByteBuffer* pSrcBytes, Tizen::Base::String& hexString) const; + void PrintTag(const _NfcTagImpl& _tagImpl) const; + +private: + _NfcSystemAdapter* __pSystemAdapter; + _NfcTagImpl* __pCurrentTagImpl; + _NfcManagerEvent* __pMgrEvent; + Tizen::Base::Collection::HashMap* __pTagConditionMap; // key: NfcTagType, value: event map + Tizen::Base::Collection::HashMap* __pNdefConditionMap; // key: NdefRecordType, value: event map + _NfcDeviceDiscoveryEvent* __pDeviceDiscoveryEvent; + Tizen::Base::Runtime::Mutex __stateMutex; + _NfcManagerStateType __currentState; +}; // _NfcManagerImpl + +} } } +#endif // FNET_NFC_INTERNAL_NFC_MANAGER_IMPL_H diff --git a/src/inc/FNetNfc_NfcTagImpl.h b/src/inc/FNetNfc_NfcTagImpl.h new file mode 100644 index 0000000..ea11a4d --- /dev/null +++ b/src/inc/FNetNfc_NfcTagImpl.h @@ -0,0 +1,124 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcNfcTagImpl.h + * @brief This is the header file for the _NfcTagImpl class. + * + * This header file contains the declarations of the _NfcTagImpl class. + */ + +#ifndef _FNET_NFC_INTERNAL_NFC_TAG_IMPL_H_ +#define _FNET_NFC_INTERNAL_NFC_TAG_IMPL_H_ + +#include +#include +#include +#include +#include + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NfcTag; + +/** + * @class _NfcTagImpl + * @brief This class provides information about the target tag. + */ +class _OSP_EXPORT_ _NfcTagImpl + : public Tizen::Base::Object +{ +public: + /** + * This is a constructor for this class. + * + * @param[in] pId The ID of the tag + * @param[in] types The types of the tag + * @param[in] isNdefSupported Set to @c true if the tag supports the NDEF message operations, @n + * else @c false + */ + _NfcTagImpl(const Tizen::Base::ByteBuffer* pId, const Tizen::Base::Collection::IListT & types, bool isNdefSupported); + + /** + * This is a copy constructor for this class. + * + * @param[in] value An instance of _NfcTagImpl + */ + _NfcTagImpl(const _NfcTagImpl& value); + + /** + * This is the destructor for this class. + */ + ~_NfcTagImpl(void); + + /** + * Gets the list of the tag types. + * + * @return The list of tag types + */ + const Tizen::Base::Collection::IListT * GetTagTypeList(void) const; + + /** + * Checks whether the tag has the specified type. + * + * @return @c true if the target has the specified type, @n + * @c false otherwise + * @param[in] type The tag type to be checked + */ + bool HasTagType(NfcTagType type) const; + + /** + * Gets the ID of the tag. + * + * @return The ID of the tag + * @c null if the tag has no ID + */ + const Tizen::Base::ByteBuffer* GetId(void) const; + + /** + * Checks whether the tag supports the NDEF message operations. + */ + bool IsNdefSupported(void) const; + + /** + * This is the factory method for NfcTag class. + * + * @return The NfcTag object according to the specified _NfcTagImpl instance, + * @c null if the getting fails due to the insufficient memory + * @param[in] tagImpl The impl instance of the detected tag + */ + static NfcTag* GetNfcTagN(const _NfcTagImpl& tagImpl); + +private: + _NfcTagImpl(void); + _NfcTagImpl& operator =(const _NfcTagImpl& value); + +private: + Tizen::Base::ByteBuffer* __pTagId; + Tizen::Base::Collection::ArrayListT __tagTypeList; + bool __isNdefSupported; +}; // _NfcTagImpl + +} } } // Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_NFC_TAG_IMPL_H_ diff --git a/src/inc/FNetNfc_TagConnectionImpl.h b/src/inc/FNetNfc_TagConnectionImpl.h new file mode 100644 index 0000000..e62ae27 --- /dev/null +++ b/src/inc/FNetNfc_TagConnectionImpl.h @@ -0,0 +1,216 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FNetNfcTagConnectionImpl.h + * @brief This is the header file for the _TagConnectionImpl class. + * + * This header file contains the declarations of the _TagConnectionImpl class. + */ + +#ifndef _FNET_NFC_INTERNAL_TAG_CONNECTION_IMPL_H_ +#define _FNET_NFC_INTERNAL_TAG_CONNECTION_IMPL_H_ + +#include +#include +#include +#include "FNetNfc_ITagConnectionListener.h" + +// Forward declaration +namespace Tizen { namespace Base +{ +class ByteBuffer; +} } + +namespace Tizen { namespace Net { namespace Nfc +{ + +// Forward declaration +class NfcTag; +class _NfcTagImpl; +class NdefMessage; +class TagConnection; +class ITagConnectionListener; +class INdefTagConnectionListener; +class _NfcSystemAdapter; + +/** + * @enum _TagConnectionStateType + * + * Defines the states of the NfcManager. + */ +enum _TagConnectionStateType +{ + _TAG_CONNECTION_STATE_DISABLED, + _TAG_CONNECTION_STATE_CONNECTED, + _TAG_CONNECTION_STATE_SEND_REQUESTED, + _TAG_CONNECTION_STATE_READ_REQUESTED, + _TAG_CONNECTION_STATE_WRITE_REQUESTED, +}; + +/** + * @class _TagConnectionImpl + * @brief This class provides information about tag connection and performs operations for Non-NDEF tag such as + * ISO14443-4 compliant tag and general RFID tag. + */ +class _OSP_EXPORT_ _TagConnectionImpl + : public Tizen::Base::Object + , public _ITagConnectionListener +{ +public: + /** + * This is the destructor for this class. + */ + ~_TagConnectionImpl(void); + + /** + * Gets the target tag object. + * + * @return The target tag object + */ + const NfcTag* GetTargetTag(void) const; + + /** + * Sets a listener for event about the result of sending command on tag connection. + * + * @return An error code + * @param[in] pListener The listener to be added + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + * @remarks Only one event listener is able to be set. + * If the input parameter is @c null, the listener already set is unregistered. + */ + result SetTagConnectionListener(ITagConnectionListener* pListener); + + /** + * Sets a listener for event about the result of reading or writing on NDEF tag connection. + * + * @return An error code + * @param[in] pListener The listener to be added + * @exception E_SUCCESS The method was successful. + * @exception E_SYSTEM A system error occurred. + * @remarks Only one event listener is able to be set. + * If the input parameter is @c null, the listener already set is unregistered. + */ + result SetNdefTagConnectionListener(INdefTagConnectionListener* pListener); + + /** + * Sends the specified command to the target tag. + * + * @return An error code + * @param[in] command The command to be sent + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The input @c command is invalid. + * @exception E_IN_PROGRESS The previous send request is in progress. + * @exception E_CONNECTION_BUSY The connection is busy, so cannot process the send request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or fails. + * @exception E_SYSTEM A system error occurred. + */ + result SendCommand(const Tizen::Base::ByteBuffer& command); + + /** + * Reads NDEF data from the NDEF tag. + * + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_IN_PROGRESS The read process is in progress. + * @exception E_CONNECTION_BUSY The connection is busy, so cannot process the read request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or fails. + * @exception E_SYSTEM A system error occurred. + */ + result Read(void); + + /** + * Writes NDEF data to the NDEF tag. + * + * @return An error code + * @param[in] message NDEF message to be written to the target + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The input @c message is invalid. + * For example, it does not contain any NDEF records. + * @exception E_IN_PROGRESS The write process is in progress. + * @exception E_CONNECTION_BUSY The connection is busy, so cannot process the write request. + * @exception E_CONNECTION_FAILED The connection to the tag is closed or fails. + * @exception E_SYSTEM A system error occurred. + */ + result Write(const NdefMessage& message); + + /** + * This is the factory method for TagConnection class. + * + * @return The TagConnection object according to the specified target tag and connection type, + * @c null if the getting fails due to the insufficient memory + * @param[in] tagImpl The impl instance of the target tag + */ + static TagConnection* GetTagConnectionN(const _NfcTagImpl& tagImpl); + + /** + * Callback method which implements _INfcConnectionListener + */ + virtual void OnNdefReadCompletedN(NdefMessage* pMessage, result r); + + /** + * Callback method which implements _INfcConnectionListener + */ + virtual void OnNdefWriteCompleted(result r); + + /** + * Callback method which implements _INfcConnectionListener + */ + virtual void OnNfcResponseReceivedN(Tizen::Base::ByteBuffer* pResponse, result r); + + /** + * Callback method which implements _INfcConnectionListener + */ + virtual void OnNfcConnectionClosed(void); + +private: + /** + * This is the default constructor for this class. + * + * @remark After creating an instance of the _TagConnectionImpl class, Construct() methods must be called explicitly to initialize this instance. + * @see Construct() + */ + _TagConnectionImpl(void); + + _TagConnectionImpl(const _TagConnectionImpl& value); + _TagConnectionImpl& operator =(const _TagConnectionImpl& value); + + /** + * Initializes this instance of NdefTagConnection. + * + * @return An error code + * @param[in] tagImpl The impl instance of the target tag + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_SYSTEM Internal initialization procedure failed. + */ + result Construct(const _NfcTagImpl& tagImpl); + + const char* GetStringOfCurrentState(void) const; + +private: + NfcTag* __pTargetTag; + _NfcSystemAdapter* __pSystemAdapter; + ITagConnectionListener* __pConnectionListener; + INdefTagConnectionListener* __pNdefTagListener; + Tizen::Base::Runtime::Mutex __stateMutex; + _TagConnectionStateType __currentState; + +}; // _TagConnectionImpl + +} } } // Tizen::Net::Nfc +#endif // _FNET_NFC_INTERNAL_TAG_CONNECTION_IMPL_H_ -- 2.7.4