Tizen 2.0 Release 2.0_release
authorHyungKyu Song <hk76.song@samsung.com>
Fri, 15 Feb 2013 06:09:14 +0000 (15:09 +0900)
committerHyungKyu Song <hk76.song@samsung.com>
Fri, 15 Feb 2013 06:09:14 +0000 (15:09 +0900)
93 files changed:
CMakeLists.txt [new file with mode: 0755]
LICENSE.APLv2.0 [new file with mode: 0755]
NOTICE [new file with mode: 0755]
inc/FNetBluetooth.h [new file with mode: 0755]
inc/FNetBtBluetoothDevice.h [new file with mode: 0755]
inc/FNetBtBluetoothHealth.h [new file with mode: 0755]
inc/FNetBtBluetoothManager.h [new file with mode: 0755]
inc/FNetBtBluetoothOppClient.h [new file with mode: 0755]
inc/FNetBtBluetoothOppServer.h [new file with mode: 0755]
inc/FNetBtBluetoothSppAcceptor.h [new file with mode: 0755]
inc/FNetBtBluetoothSppInitiator.h [new file with mode: 0755]
inc/FNetBtBluetoothTypes.h [new file with mode: 0755]
inc/FNetBtIBluetoothDeviceEventListener.h [new file with mode: 0755]
inc/FNetBtIBluetoothHealthEventListener.h [new file with mode: 0755]
inc/FNetBtIBluetoothManagerEventListener.h [new file with mode: 0755]
inc/FNetBtIBluetoothOppClientEventListener.h [new file with mode: 0755]
inc/FNetBtIBluetoothOppServerEventListener.h [new file with mode: 0755]
inc/FNetBtIBluetoothSppAcceptorEventListener.h [new file with mode: 0755]
inc/FNetBtIBluetoothSppInitiatorEventListener.h [new file with mode: 0755]
osp-bluetooth.manifest [new file with mode: 0644]
osp-bluetooth.pc.in [new file with mode: 0755]
packaging/osp-bluetooth.spec [new file with mode: 0755]
src/FNetBtBluetoothDevice.cpp [new file with mode: 0755]
src/FNetBtBluetoothHealth.cpp [new file with mode: 0644]
src/FNetBtBluetoothManager.cpp [new file with mode: 0644]
src/FNetBtBluetoothOppClient.cpp [new file with mode: 0644]
src/FNetBtBluetoothOppServer.cpp [new file with mode: 0644]
src/FNetBtBluetoothSppAcceptor.cpp [new file with mode: 0644]
src/FNetBtBluetoothSppInitiator.cpp [new file with mode: 0644]
src/FNetBt_BluetoothAdapterUtility.cpp [new file with mode: 0755]
src/FNetBt_BluetoothConnectionEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothConnectionEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothConnectionEventArg.cpp [new file with mode: 0644]
src/FNetBt_BluetoothConnectionEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothDeviceEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothDeviceEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothDeviceEventArg.cpp [new file with mode: 0755]
src/FNetBt_BluetoothDeviceEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothDeviceImpl.cpp [new file with mode: 0755]
src/FNetBt_BluetoothGapSystemAdapter.cpp [new file with mode: 0755]
src/FNetBt_BluetoothGapSystemAdapter.h [new file with mode: 0644]
src/FNetBt_BluetoothHdpSystemAdapter.cpp [new file with mode: 0755]
src/FNetBt_BluetoothHdpSystemAdapter.h [new file with mode: 0644]
src/FNetBt_BluetoothHealthEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothHealthEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothHealthEventArg.cpp [new file with mode: 0755]
src/FNetBt_BluetoothHealthEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothHealthImpl.cpp [new file with mode: 0755]
src/FNetBt_BluetoothIpcMessages.cpp [new file with mode: 0644]
src/FNetBt_BluetoothIpcProxy.cpp [new file with mode: 0755]
src/FNetBt_BluetoothIpcProxy.h [new file with mode: 0644]
src/FNetBt_BluetoothManagerEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothManagerEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothManagerEventArg.cpp [new file with mode: 0644]
src/FNetBt_BluetoothManagerEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothManagerImpl.cpp [new file with mode: 0755]
src/FNetBt_BluetoothOppClientEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothOppClientEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothOppClientEventArg.cpp [new file with mode: 0644]
src/FNetBt_BluetoothOppClientEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothOppClientImpl.cpp [new file with mode: 0755]
src/FNetBt_BluetoothOppServerEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothOppServerEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothOppServerEventArg.cpp [new file with mode: 0755]
src/FNetBt_BluetoothOppServerEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothOppServerImpl.cpp [new file with mode: 0755]
src/FNetBt_BluetoothOppSystemAdapter.cpp [new file with mode: 0755]
src/FNetBt_BluetoothOppSystemAdapter.h [new file with mode: 0644]
src/FNetBt_BluetoothSppAcceptorEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothSppAcceptorEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothSppAcceptorEventArg.cpp [new file with mode: 0755]
src/FNetBt_BluetoothSppAcceptorEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothSppAcceptorImpl.cpp [new file with mode: 0755]
src/FNetBt_BluetoothSppInitiatorEvent.cpp [new file with mode: 0644]
src/FNetBt_BluetoothSppInitiatorEvent.h [new file with mode: 0644]
src/FNetBt_BluetoothSppInitiatorEventArg.cpp [new file with mode: 0755]
src/FNetBt_BluetoothSppInitiatorEventArg.h [new file with mode: 0644]
src/FNetBt_BluetoothSppInitiatorImpl.cpp [new file with mode: 0755]
src/FNetBt_BluetoothSppSystemAdapter.cpp [new file with mode: 0755]
src/FNetBt_BluetoothSppSystemAdapter.h [new file with mode: 0644]
src/inc/FNetBt_BluetoothAdapterUtility.h [new file with mode: 0644]
src/inc/FNetBt_BluetoothDeviceImpl.h [new file with mode: 0755]
src/inc/FNetBt_BluetoothHealthImpl.h [new file with mode: 0644]
src/inc/FNetBt_BluetoothManagerImpl.h [new file with mode: 0755]
src/inc/FNetBt_BluetoothOppClientImpl.h [new file with mode: 0644]
src/inc/FNetBt_BluetoothOppServerImpl.h [new file with mode: 0644]
src/inc/FNetBt_BluetoothSppAcceptorImpl.h [new file with mode: 0644]
src/inc/FNetBt_BluetoothSppInitiatorImpl.h [new file with mode: 0644]
src/inc/FNetBt_ConnectivityIpcMessages.h [new file with mode: 0644]
src/inc/FNetBt_IBluetoothConnectionEventListener.h [new file with mode: 0644]
src/inc/FNetBt_IBluetoothDeviceEventListener.h [new file with mode: 0644]
src/inc/FNetBt_IBluetoothManagerEventListener.h [new file with mode: 0644]
src/inc/FNetBt_IBluetoothSocketListener.h [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..6818a4d
--- /dev/null
@@ -0,0 +1,117 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET (this_target osp-bluetooth)
+
+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/FNetBtBluetoothDevice.cpp
+    src/FNetBtBluetoothManager.cpp
+    src/FNetBtBluetoothOppClient.cpp
+    src/FNetBtBluetoothOppServer.cpp
+    src/FNetBtBluetoothSppInitiator.cpp
+    src/FNetBtBluetoothSppAcceptor.cpp
+    src/FNetBtBluetoothSppInitiator.cpp
+    src/FNetBtBluetoothHealth.cpp
+    src/FNetBt_BluetoothAdapterUtility.cpp
+    src/FNetBt_BluetoothConnectionEvent.cpp
+    src/FNetBt_BluetoothConnectionEventArg.cpp
+    src/FNetBt_BluetoothDeviceEvent.cpp
+    src/FNetBt_BluetoothDeviceEventArg.cpp
+    src/FNetBt_BluetoothDeviceImpl.cpp
+    src/FNetBt_BluetoothGapSystemAdapter.cpp
+    src/FNetBt_BluetoothHealthEvent.cpp
+    src/FNetBt_BluetoothHealthEventArg.cpp
+    src/FNetBt_BluetoothHealthImpl.cpp
+    src/FNetBt_BluetoothHdpSystemAdapter.cpp
+    src/FNetBt_BluetoothIpcMessages.cpp
+    src/FNetBt_BluetoothIpcProxy.cpp
+    src/FNetBt_BluetoothManagerEvent.cpp
+    src/FNetBt_BluetoothManagerEventArg.cpp
+    src/FNetBt_BluetoothManagerImpl.cpp
+    src/FNetBt_BluetoothOppClientEvent.cpp
+    src/FNetBt_BluetoothOppClientEventArg.cpp
+    src/FNetBt_BluetoothOppClientImpl.cpp
+    src/FNetBt_BluetoothOppServerEvent.cpp
+    src/FNetBt_BluetoothOppServerEventArg.cpp
+    src/FNetBt_BluetoothOppServerImpl.cpp
+    src/FNetBt_BluetoothOppSystemAdapter.cpp
+    src/FNetBt_BluetoothSppAcceptorEvent.cpp
+    src/FNetBt_BluetoothSppAcceptorEventArg.cpp
+    src/FNetBt_BluetoothSppAcceptorImpl.cpp
+    src/FNetBt_BluetoothSppInitiatorEvent.cpp
+    src/FNetBt_BluetoothSppInitiatorEventArg.cpp
+    src/FNetBt_BluetoothSppInitiatorImpl.cpp
+    src/FNetBt_BluetoothSppSystemAdapter.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} "-lpthread" )
+TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw -losp-net" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-network-bluetooth" )
+
+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)
\ No newline at end of file
diff --git a/LICENSE.APLv2.0 b/LICENSE.APLv2.0
new file mode 100755 (executable)
index 0000000..d645695
--- /dev/null
@@ -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/NOTICE b/NOTICE
new file mode 100755 (executable)
index 0000000..4443889
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+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.
+
+
diff --git a/inc/FNetBluetooth.h b/inc/FNetBluetooth.h
new file mode 100755 (executable)
index 0000000..afaf686
--- /dev/null
@@ -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        FNetBluetooth.h
+ * @brief       This is the header file for the %Bluetooth namespace.
+ *
+ * This header file contains the declarations and descriptions of the %Tizen::Net::Bluetooth namespace.
+ */
+#ifndef _FNET_BLUETOOTH_H_
+#define _FNET_BLUETOOTH_H_
+
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtBluetoothManager.h>
+#include <FNetBtIBluetoothDeviceEventListener.h>
+#include <FNetBtIBluetoothManagerEventListener.h>
+#include <FNetBtBluetoothOppServer.h>
+#include <FNetBtIBluetoothOppServerEventListener.h>
+#include <FNetBtBluetoothOppClient.h>
+#include <FNetBtIBluetoothOppClientEventListener.h>
+#include <FNetBtBluetoothSppAcceptor.h>
+#include <FNetBtIBluetoothSppAcceptorEventListener.h>
+#include <FNetBtBluetoothSppInitiator.h>
+#include <FNetBtIBluetoothSppInitiatorEventListener.h>
+#include <FNetBtBluetoothHealth.h>
+#include <FNetBtIBluetoothHealthEventListener.h>
+
+namespace Tizen { namespace Net
+{
+/**
+ * @namespace   Tizen::Net::Bluetooth
+ * @brief       This namespace contains the classes and interfaces for %Bluetooth services.
+ * @since       2.0
+ *
+ * @remarks     @b Header @b %file: @b \#include @b <FNet.h> @n
+ *              @b Library : @b osp-bluetooth @n
+ *
+ * The %Bluetooth namespace contains the classes and interfaces for %Bluetooth services that provide the mechanisms for
+ * peer-to-peer communication involving connecting, sending, and receiving data over a %Bluetooth connection. It
+ * consists of the submodules that support different profiles such as GAP, OPP, and SPP.
+ * @n
+ * For more information on the %Bluetooth namespace features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ *
+ * The following diagram illustrates the relationships between the classes within the %Bluetooth namespace.
+ * @image html net_bluetooth_using_the_apis_classdiagram.png
+ *
+ */
+namespace Bluetooth
+{
+} } } // Tizen::Net::Bluetooth
+#endif // _FNET_BLUETOOTH_H_
diff --git a/inc/FNetBtBluetoothDevice.h b/inc/FNetBtBluetoothDevice.h
new file mode 100755 (executable)
index 0000000..5448190
--- /dev/null
@@ -0,0 +1,269 @@
+//
+// 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        FNetBtBluetoothDevice.h
+ * @brief       This is the header file for the %BluetoothDevice class.
+ *
+ * This header file contains the declarations of the %BluetoothDevice class.
+ */
+#ifndef _FNET_BT_BLUETOOTH_DEVICE_H_
+#define _FNET_BT_BLUETOOTH_DEVICE_H_
+
+#include <FNetBtBluetoothTypes.h>
+#include <FBaseResult.h>
+#include <FBaseObject.h>
+
+// forward declarations
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+class String;
+namespace Collection
+{
+class IList;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class _BluetoothDeviceImpl;
+
+/**
+ * @class   BluetoothDevice
+ * @brief   This class provides information about a remote %Bluetooth device.
+ * @since   2.0
+ *
+ * The %BluetoothDevice class provides information about a remote %Bluetooth device.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ BluetoothDevice
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @since       2.0
+        */
+       BluetoothDevice(void);
+
+       /**
+        * @if OSPDEPREC
+        * Initializes an instance of %BluetoothDevice with the specified parameters.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  This constructor is deprecated because most of the information is generated internally.
+        *              Therefore, creating a %BluetoothDevice instance directly by the application is not recommended.
+        *              Instead of using this method for copying an instance, the copy constructor is recommended.
+        * @since       2.0
+        *
+        * @param[in]   address                 The %Bluetooth device address
+        * @param[in]   deviceName              The name of the device
+        * @param[in]   majorClassType          The major class type of a %Bluetooth device
+        * @param[in]   minorClassType          The minor class type of a %Bluetooth device
+        * @param[in]   serviceClassList        The service class type list
+        * @param[in]   serviceList             The service type list
+        * @remarks     The @c serviceClassList parameter consists of Bluetooth::BluetoothServiceClassType values, which are
+        *              joined by the logical OR operator. @n
+        *              The @c serviceList parameter consists of Bluetooth::BluetoothServiceType values which are joined by the
+        *              logical OR operator.
+        * @endif
+        */
+       BluetoothDevice(const Tizen::Base::ByteBuffer& address, const Tizen::Base::String& deviceName, BluetoothMajorDeviceClassType majorClassType, BluetoothMinorDeviceClassType minorClassType, unsigned long serviceClassList, unsigned long serviceList);
+
+       /**
+        * Copying of objects using this copy constructor is allowed.
+        *
+        * @since 2.0
+        *
+        * @param[in]   value                   An instance of %BluetoothDevice
+        */
+       BluetoothDevice(const BluetoothDevice& value);
+
+       /**
+        * This destructor overrides Tizen::Base::Object::~Object().
+        *
+        * @since       2.0
+        */
+       virtual ~BluetoothDevice(void);
+
+       /**
+        * Gets the address of a %Bluetooth device which consists of 6 bytes.
+        *
+        * @since       2.0
+        *
+        * @return      The address of a %Bluetooth device
+        */
+       const Tizen::Base::ByteBuffer* GetAddress(void) const;
+
+       /**
+        * Sets the address of a %Bluetooth device.
+        *
+        * @since 2.0
+        *
+        * @return      An error code
+        * @param[in]   address                 An address of the %Bluetooth device
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_ARG           The specified address is invalid @n
+        *                                      The size of the address should be 6 bytes.
+        * @remarks     @c address must have 6 byte data (remaining elements). @n
+        *              Setting the address of the %BluetoothDevice instance which is obtained from the paired list does not
+        *              affect the information of the paired list in the system.
+        */
+       result SetAddress(const Tizen::Base::ByteBuffer& address);
+
+       /**
+        * Gets the %Bluetooth device name.
+        *
+        * @since       2.0
+        *
+        * @return      The %Bluetooth device name
+        */
+       Tizen::Base::String GetName(void) const;
+
+       /**
+        * Checks whether this device is paired with the local device.
+        *
+        * @since 2.0
+        *
+        * @return      @c true if this device is paired with the local device, @n
+        *              else @c false
+        */
+       bool IsPaired(void) const;
+
+       /**
+        * Gets the Received Signal Strength Indication (RSSI) value of a device at the time of device discovery (scan).
+        *
+        * @since 2.0
+        *
+        * @return      The RSSI value in dBm
+        */
+       int GetRssi(void) const;
+
+       /**
+        * Gets the major device class.
+        *
+        * @since       2.0
+        *
+        * @return      The major device class
+        */
+       BluetoothMajorDeviceClassType GetMajorDeviceClassType(void) const;
+
+       /**
+        * Gets the minor device class.
+        *
+        * @since       2.0
+        *
+        * @return      The minor device class
+        */
+       BluetoothMinorDeviceClassType GetMinorDeviceClassType(void) const;
+
+       /**
+        * Gets the service class of the %Bluetooth device. @n
+        * This service class list consists of Bluetooth::BluetoothServiceClassType values, which are joined by the logical OR
+        * operator.
+        *
+        * @since       2.0
+        *
+        * @return      The service class of the device
+        * @remarks     This operation is not supported in the local device acquired by BluetoothManager::GetLocalDevice().
+        */
+       unsigned long GetServiceClassList(void) const;
+
+       /**
+        * Gets the %Bluetooth device service list. @n
+        * This service list consists of Bluetooth::BluetoothServiceType values, which are joined by the logical OR operator.
+        *
+        * @since       2.0
+        *
+        * @return      The %Bluetooth device service list
+        * @remarks     This operation is not supported in the local device acquired by BluetoothManager::GetLocalDevice().
+        */
+       unsigned long GetServiceList(void) const;
+
+       /**
+        * Gets the %Bluetooth device service UUID list. @n
+        * This service list consists of Tizen::Base::UuId instances that represent service UUIDs that the device supports.
+        *
+        * @since 2.0
+        *
+        * @return      The %Bluetooth device service UUID list
+        * @remarks     This operation returns @c null, if it is called in the local device acquired by
+        *              BluetoothManager::GetLocalDevice().
+        */
+       const Tizen::Base::Collection::IList* GetServiceUuidList(void) const;
+
+       /**
+        * Compares the calling instance with the specified instance.
+        *
+        * @since       2.0
+        * @return      @c true if both the instances are equal, @n
+        *              else @c false
+        * @param[in]   obj                    The object to compare
+        */
+       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 a new instance of %BluetoothDevice generated using the result of the %Bluetooth AppControl.
+        *
+        * @since       2.0
+        * @return      The %Bluetooth device containing the specified information extracted from the input data if successful,
+        * @n
+        *              else @c null
+        * @param[in]   appControlResult        The data list, which is the result of the %Bluetooth AppControl
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_ARG           The specified @c appControlResult contains an invalid value. @n
+        *                                      The result of %Bluetooth AppControl is only permitted to be used as an input
+        *                                      argument.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       static BluetoothDevice* GetInstanceFromAppControlResultN(const Tizen::Base::Collection::IList& appControlResult);
+
+       /**
+        * Copying of objects using this copy assignment operator is allowed.
+        *
+        * @since 2.0
+        *
+        * @return      A reference to the %BluetoothDevice instance
+        * @param[in]   rhs                     A reference to the %BluetoothDevice instance to copy
+        */
+       BluetoothDevice& operator =(const BluetoothDevice& rhs);
+
+private:
+       _BluetoothDeviceImpl* __pImpl;
+
+       friend class _BluetoothDeviceImpl;
+
+}; // BluetoothDevice
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_DEVICE_H_
diff --git a/inc/FNetBtBluetoothHealth.h b/inc/FNetBtBluetoothHealth.h
new file mode 100755 (executable)
index 0000000..36762cf
--- /dev/null
@@ -0,0 +1,226 @@
+//
+// 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    FNetBtBluetoothHealth.h
+ * @brief   This is the header file for the %BluetoothHealth class.
+ *
+ * This header file contains the declarations of the %BluetoothHealth class.
+ */
+#ifndef _FNET_BT_BLUETOOTH_HEALTH_H_
+#define _FNET_BT_BLUETOOTH_HEALTH_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+class BluetoothDevice;
+class IBluetoothHealthEventListener;
+class _BluetoothHealthImpl;
+
+/**
+ * @class   BluetoothHealth
+ * @brief   This class provides the methods to handle the %Bluetooth Health Device Profile (HDP), such as the
+ *          establishing a connection and exchanging data through the data channel.
+ * @since 2.0
+ *
+ * @final   This class is not intended for extension.
+ *
+ * This %BluetoothHealth class provides the methods to handle the %Bluetooth Health Device Profile (HDP), which is a
+ * profile that defines the requirements for qualified %Bluetooth healthcare and fitness (referred to as 'health')
+ * device implementations. @n
+ * This class allows Sink device such as mobile phone to establish a connection and exchange data to Source devices
+ * such as blood pressure monitors, weight scales, glucose meters, thermometers, and pulse oximeters.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ BluetoothHealth
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * The object is not fully constructed after this constructor is called. For full construction, the Construct()
+        * method must be called right after calling this constructor.
+        *
+        * @since 2.0
+        */
+       BluetoothHealth(void);
+
+       /**
+        * This destructor overrides Tizen::Base::Object::~Object().
+        *
+        * @since 2.0
+        */
+       virtual ~BluetoothHealth(void);
+
+       /**
+        * Constructs an instance of %BluetoothHealth with the specified listener.
+        *
+        * @since 2.0
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for the %BluetoothHealth. @n
+        *                                      Listener must be allocated at heap, not stack.
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        * @exception   E_UNSUPPORTED_OPERATION The device does not support the %Bluetooth feature.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result Construct(IBluetoothHealthEventListener& listener);
+
+       /**
+        * Starts %Bluetooth health as a role of sink with the specified data type.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.health
+        *
+        * @return      An error code
+        * @param[in]   dataType                The type of data used in communication which is defined in ISO/IEEE
+        *                                      11073-20601 and represents type of health device such as thermometer,
+        *                                      heart rate monitor, weight scale, and so on
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_IN_PROGRESS           The sink role with the specified data type has already started.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the sink role already started with another data type.
+        * @exception   E_SERVICE_UNAVAILABLE   The sink role with the specified data type is currently busy with another
+        *                                      instance or application.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        * @remarks     One %BluetoothHealth instance supports only a sink role with the specific data type at one time and
+        *              only one sink role for the specific data type can be enabled system-widely. For providing sink
+        *              roles with various data types, make multiple %BluetoothHealth instances with different data types.
+        */
+       result StartAsSink(int dataType);
+
+       /**
+        * Stops %Bluetooth health as a role of sink. @n
+        * This method disconnects all established channels before stop.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.health
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the sink role is not started yet.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result Stop(void);
+
+       /**
+        * Connects to a new channel with a remote health device which has source role. @n
+        * This method establishes a channel after the source device accepts the request.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.health
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice            The remote device to connect
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the sink role is not started yet.
+        * @exception   E_DEVICE_BUSY           The pairing and connection process is in progress.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        * @see         IBluetoothHealthEventListener::OnHealthConnected()
+        * @remarks     If the local device is not paired with the specified target device, the pairing process starts
+        *              internally before the connect request is sent.
+        */
+       result ConnectToSource(const BluetoothDevice& remoteDevice);
+
+       /**
+        * Disconnects the connection which has the specified channel ID. @n
+        * After calling this method, the IBluetoothHealthEventListener::OnHealthDisconnected() is called regardless of
+        * whether this method is called during connection or before connection is established.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.health
+        *
+        * @return      An error code
+        * @param[in]   channelId               The ID of the specified channel to disconnect
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, there is no connection with the specified channel ID.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        * @see         IBluetoothHealthEventListener::OnHealthDisconnected()
+        * @remarks     @c channelId value can be obtained by IBluetoothHealthEventListener::OnHealthConnected() after the
+        *              specific channel is established.
+        */
+       result Disconnect(int channelId);
+
+       /**
+        * Sends the specified data on the specified channel.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.health
+        *
+        * @return      An error code
+        * @param[in]   channelId               The ID of the specified channel on which the data is sent
+        * @param[in]   buffer                  The data to send
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, there is no connection with the specified channel ID.
+        * @exception   E_INVALID_ARG           The input buffer has no data.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_OPERATION_FAILED      The operation has failed.
+        * @see         IBluetoothHealthEventListener::OnHealthDataReceived()
+        * @remarks     @c channelId value can be obtained by IBluetoothHealthEventListener::OnHealthConnected() after the
+        *              specific channel is established.
+        */
+       result SendData(int channelId, const Tizen::Base::ByteBuffer& buffer);
+
+private:
+       //
+       // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying
+       // of objects.
+       //
+       BluetoothHealth(const BluetoothHealth& value);
+
+       //
+       // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit
+       // copying of objects.
+       //
+       BluetoothHealth& operator =(const BluetoothHealth& rhs);
+
+private:
+       _BluetoothHealthImpl* __pImpl;
+
+}; // BluetoothHealth
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_HEALTH_H_
diff --git a/inc/FNetBtBluetoothManager.h b/inc/FNetBtBluetoothManager.h
new file mode 100755 (executable)
index 0000000..f1dc6c3
--- /dev/null
@@ -0,0 +1,594 @@
+//
+// 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    FNetBtBluetoothManager.h
+ * @brief   This is the header file for the %BluetoothManager class.
+ *
+ * This header file contains the declarations of the %BluetoothManager class.
+ */
+#ifndef _FNET_BT_BLUETOOTH_MANAGER_H_
+#define _FNET_BT_BLUETOOTH_MANAGER_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Base
+{
+class String;
+class ByteBuffer;
+namespace Collection
+{
+class IList;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class IBluetoothManagerEventListener;
+class IBluetoothDeviceEventListener;
+class _BluetoothManagerImpl;
+
+/**
+ * @class   BluetoothManager
+ * @brief   This class is used to obtain information about the local device or the paired devices, and to configure
+ *          the %Bluetooth stack.
+ * @since   2.0
+ *
+ * The %BluetoothManager class is used to obtain information about the local device or the paired devices and to configure the
+ * %Bluetooth stack.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ BluetoothManager
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * The object is not fully constructed after this constructor is called. For full construction, the Construct()
+        * method must be called right after calling this constructor.
+        *
+        * @since       2.0
+        */
+       BluetoothManager(void);
+
+       /**
+        * This destructor overrides Tizen::Base::Object::~Object().
+        *
+        * @since       2.0
+        */
+       virtual ~BluetoothManager(void);
+
+       /**
+        * Constructs and initializes an instance of the %BluetoothManager class with the specified listener.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   listener                    The listener to handle the %BluetoothManager event
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
+        * @exception   E_UNSUPPORTED_OPERATION         This operation is not supported.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        */
+       result Construct(IBluetoothManagerEventListener& listener);
+
+       /**
+        * Activates %Bluetooth on a device.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.admin
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The %Bluetooth 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, %Bluetooth is already activated.
+        * @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.
+        * @see         IBluetoothManagerEventListener::OnBluetoothActivated()
+        */
+       result Activate(void);
+
+       /**
+        * Deactivates %Bluetooth on a device.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.admin
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The %Bluetooth 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 %Bluetooth is already deactivated.
+        * @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.
+        * @see         IBluetoothManagerEventListener::OnBluetoothDeactivated()
+        */
+       result Deactivate(void);
+
+       /**
+        * @if OSPDEPREC
+        * Checks whether a %Bluetooth-specific profile is available.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  This method is deprecated because multiple clients as well as multiple SPP servers with unique
+        *              service UUIDs are supported. In case of OPP server, invoke
+        *              BluetoothOppServer::StartService() directly without checking OPP server's availability.
+        *              If a new OPP server is not available, the method returns the E_SERVICE_UNAVAILABLE exception.
+        * @since       2.0
+        *
+        * @return      @c true if the specified type of connection is available, @n
+        *              else @c false
+        * @param[in]   type                        The connection type
+        *
+        * @endif
+        */
+       bool IsAvailable(BluetoothConnectionType type) const;
+
+       /**
+        * @if OSPDEPREC
+        * Gets the local device information.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  This method is deprecated because the return value of this method is a dangling pointer if this
+        *              instance of %BluetoothManager is deleted. In addition to this, the %BluetoothDevice class
+        *              represents only remote devices since 2.0. Instead of using this method, the GetLocalDeviceAddress()
+        *              and GetLocalDeviceName() methods are recommended.
+        * @since       2.0
+        *
+        * @return      The local device information
+        * @exception   E_SUCCESS                   The method is successful.
+        * @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.
+        * @endif
+        */
+       const BluetoothDevice* GetLocalDevice(void) const;
+
+       /**
+        * Gets the local %Bluetooth device address.
+        *
+        * @since       2.0
+        *
+        * @return      The local %Bluetooth device address
+        * @remarks     The address is expressed as a @c 6 byte hexadecimal value delimited by colons. @n
+        *              For example, "00:3D:47:EF:8A:03".
+        */
+       Tizen::Base::String GetLocalDeviceAddress(void) const;
+
+       /**
+        * Gets the local %Bluetooth device name.
+        *
+        * @since       2.0
+        *
+        * @return      The local %Bluetooth device name
+        */
+       Tizen::Base::String GetLocalDeviceName(void) const;
+
+       /**
+        * @if OSPDEPREC
+        * Gets the operational mode of the %Bluetooth unit.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  %BluetoothDeviceStateType is deprecated. Therefore, this method is also deprecated, because the
+        *              return value of this method is of type %BluetoothDeviceStateType. Instead of using this method, the
+        *              IsActivated() and GetDiscoverableMode() methods are recommended.
+        *
+        * @since       2.0
+        *
+        * @return      The operational mode
+        * @endif
+        */
+       BluetoothDeviceStateType GetLocalDeviceState(void) const;
+
+       /**
+        * Checks whether the local %Bluetooth is activated.
+        *
+        * @since       2.0
+        *
+        * @return      @c true if the local %Bluetooth is activated, @n
+        *              else @c false
+        */
+       bool IsActivated(void) const;
+
+       /**
+        * Gets the discoverable mode of the local device.
+        *
+        * @if OSPCOMPAT
+        * @brief <i> [Compatibility]  </i>
+        * @endif
+        * @since       2.0
+        * @if OSPCOMPAT
+        * @compatibility   This method has compatibility issues@n
+        *                  For more information, see @ref BluetoothManagerGetDiscoverableModePage "here".
+        *
+        * @endif
+        * @return      The discoverable mode of the local device
+        */
+       BluetoothDiscoverableMode GetDiscoverableMode(void) const;
+
+       /**
+        * @if OSPCOMPAT
+        * @page        BluetoothManagerGetDiscoverableModePage Compatibility for GetDiscoverableMode()
+        *
+        * @section     BluetoothManagerGetDiscoverableModePageIssueSection Issues
+        *              Implementation of this method in API versions prior to 2.0 has the following issue: @n
+        *
+        *              -# The always discoverable mode and the discoverable mode with a certain amount of time cannot be
+        *              differentiated. BT_DISC_MODE_DISCOVERABLE of BluetoothDiscoverableMode means both.
+        *
+        * @section     BluetoothManagerGetDiscoverableModePageSolutionSection Resolutions
+        *              The issue mentioned above is resolved in API version 2.0, and it is recommended to use API version
+        *              3.0 or above. @n
+        *
+        *              -# The new element, BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE, is added into BluetoothDiscoverableMode
+        *              in API version 2.0, Therefore, BT_DISC_MODE_DISCOVERABLE means the always discoverable mode and
+        *              BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE means the discoverable mode with a certain amount of time.
+        * @endif
+        */
+
+       /**
+        * Gets the remaining time, in seconds, until the discoverable mode is changed from
+        * @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE to be @c BT_DISC_MODE_NOT_DISCOVERABLE. @n
+        * This method is valid only if the current discoverable mode is @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        *
+        * @since 2.0
+        *
+        * @return      The remaining time, in seconds, until the local device to be not discoverable.
+        * @remarks     0 will be returned if the current discoverable mode is not @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        */
+       int GetRemainingTimeAsDiscoverable(void) const;
+
+       /**
+        * Checks whether the device discovery is in progress.
+        *
+        * @since       2.0
+        *
+        * @return      @c true if the device discovery is in progress, @n
+        *              else @c false
+        */
+       bool IsDiscoveryInProgress(void) const;
+
+       /**
+        * Sets the name of the local device.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.admin
+        *
+        * @return      An error code
+        * @param[in]   deviceName                  The new device name
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_ARG               The specified device name is an empty string.
+        * @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 does not affect the system settings. The device name is only valid while an application
+        *              is active. The searching device detects the local devices in close proximity based on the specified
+        *              device name. The specified device name is automatically truncated if its size is greater than @c 64
+        *              bytes.
+        */
+       result SetLocalDeviceName(const Tizen::Base::String& deviceName);
+
+       /**
+        * @if VISPARTNER-MANUFACTURER
+        * Sets the discoverable mode of the local device.
+        *
+        * @since 2.0
+        * @visibility  partner-manufacturer
+        * @privilege   http://tizen.org/privilege/bluetoothmanager
+        *
+        * @return      An error code
+        * @param[in]   mode                        The new discoverable mode
+        * @param[in]   seconds                     The duration in seconds for which the local device is discoverable
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_ARG               The specified @c seconds should be greater than 0 if the specified
+        *                                          @c mode is @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        * @exception   E_INVALID_OPERATION         %Bluetooth is not 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         IBluetoothManagerEventListener::OnBluetoothDiscoverableModeChanged()
+        * @remarks     @c seconds is adopted only if the specified @c mode is @c BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        * @endif
+        */
+       result SetDiscoverableMode(BluetoothDiscoverableMode mode, int seconds = 0);
+
+       /**
+        * @if OSPDEPREC
+        * Refreshes the paired device list.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  This method is deprecated because the paired device list of this instance of %BluetoothManager is
+        *              refreshed automatically. An application should not call this method to refresh the list.
+        * @since       2.0
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        * @endif
+        */
+       result RefreshPairedDeviceList(void);
+
+       /**
+        * @if OSPDEPREC
+        * Searches for an element that matches a %Bluetooth address.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  This method is deprecated because the return value of this method is a dangling pointer, if this
+        *              instance of %BluetoothManager is deleted. In addition to this, it is also an invalid pointer if the
+        *              paired device list is updated internally. Instead of using this method, GetPairedDeviceByAddressN()
+        *              is recommended.
+        * @since       2.0
+        *
+        * @return      The instance of %BluetoothDevice containing the specified address, @n
+        *              else @c null if the search is not successful
+        * @param[in]   deviceAddress               The address to locate
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified device is not found in the paired device list.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        * @endif
+        */
+       const BluetoothDevice* GetPairedDeviceByAddress(const Tizen::Base::ByteBuffer& deviceAddress) const;
+
+       /**
+        * Gets an element that matches a %Bluetooth address.
+        *
+        * @since       2.0
+        *
+        * @return      The instance of %BluetoothDevice containing the specified address, @n
+        *              else @c null if the search is not successful
+        * @param[in]   deviceAddress               The address to locate
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified device is not found in the paired device list.
+        * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       BluetoothDevice* GetPairedDeviceByAddressN(const Tizen::Base::ByteBuffer& deviceAddress) const;
+
+       /**
+        * Gets the elements matching a device name in the paired device list.
+        *
+        * @since       2.0
+        *
+        * @return      A list containing the matching devices, @n
+        *              else @c null if the search is not successful
+        * @param[in]   deviceName                  The name of the device to locate
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified device is not found in the paired device list.
+        * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       Tizen::Base::Collection::IList* GetPairedDeviceByNameN(const Tizen::Base::String& deviceName) const;
+
+       /**
+        * @if OSPDEPREC
+        * Gets the element at the specified index.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  This method is deprecated because the return value of this method is a dangling pointer, if this
+        *              instance of %BluetoothManager is deleted. In addition to this, it is also an invalid pointer if the
+        *              paired device list is updated internally. Instead of using this method, GetPairedDeviceListN() and
+        *              Tizen::Base::Collection::IList::GetAt() are recommended.
+        * @since       2.0
+        *
+        * @return      The instance of %BluetoothDevice at the specified index, @n
+        *              else @c null if there is no element
+        * @param[in]   index                       The index in the list
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified index is not found in the paired device list.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        * @endif
+        */
+       const BluetoothDevice* GetPairedDeviceAt(int index) const;
+
+       /**
+        * @if OSPDEPREC
+        * Gets the paired device list.
+        *
+        * @brief <i> [Deprecated]  </i>
+        * @deprecated  This method is deprecated because the return value of this method is a dangling pointer, if this
+        *              instance of %BluetoothManager is deleted. In addition to this, some elements of the list may also
+        *              be invalid pointers if the paired device list is updated internally. Instead of using this method,
+        *              GetPairedDeviceListN() is recommended.
+        * @since       2.0
+        *
+        * @return      A pointer to the paired device list on success, @n
+        *              else @c null
+        * @exception   E_SUCCESS                   The method is successful.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        * @endif
+        */
+       const Tizen::Base::Collection::IList* GetPairedDeviceList(void) const;
+
+       /**
+        * Gets the paired device list.
+        *
+        * @since       2.0
+        *
+        * @return      A pointer to the paired device list on success, @n
+        *              else @c null
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       Tizen::Base::Collection::IList* GetPairedDeviceListN(void) const;
+
+       /**
+        * Sets a remote device event listener for searching devices and services.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   pListener                   The device event listener to add
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        * @remarks     Only one event listener can be set. If the input parameter is @c null, the listener currently set
+        *              is unregistered.
+        */
+       result SetBluetoothDeviceListener(IBluetoothDeviceEventListener* pListener);
+
+       /**
+        * Starts the device discovery process.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.gap
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The device discovery process is in progress.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation.
+        * @exception   E_PRIVILEGE_DENIED          The application does not have the privilege to call this method.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        * @see         IBluetoothDeviceEventListener::OnBluetoothDiscoveryStarted()
+        * @see         IBluetoothDeviceEventListener::OnBluetoothRemoteDeviceFoundN()
+        * @see         IBluetoothDeviceEventListener::OnBluetoothDiscoveryDone()
+        */
+       result StartDiscovery(void);
+
+       /**
+        * Cancels the device discovery process.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.gap
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The termination of the device discovery process is in progress.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the discovery has not started as yet.
+        * @exception   E_PRIVILEGE_DENIED          The application does not have the privilege to call this method.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        * @see         IBluetoothDeviceEventListener::OnBluetoothDiscoveryDone()
+        */
+       result CancelDiscovery(void);
+
+       /**
+        * Retrieves the service list from a remote device.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.gap
+        *
+        * @return      An error code
+        * @param[in]   pairedDevice                A remote device that is already paired with the local device
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The retrieving is in progress.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the discovery is in progress.
+        * @exception   E_NOT_PAIRED                The input device is not found in the paired device list.
+        * @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 target remote device should be a paired device.
+        * @see         IBluetoothDeviceEventListener::OnBluetoothServiceListReceived()
+        */
+       result RetrieveServiceList(const BluetoothDevice& pairedDevice);
+
+       /**
+        * Pairs with the specified remote device.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.gap
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice                The remote %Bluetooth device to pair with
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the %Bluetooth is not activated.
+        * @exception   E_DEVICE_BUSY               The device cannot be approached because other operation is in progress.
+        * @exception   E_PRIVILEGE_DENIED          The application does not have the privilege to call this method.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        * @remarks     IBluetoothDeviceEventListener::OnBluetoothPaired() is called if the pairing is successful, @n
+        *              IBluetoothDeviceEventListener::OnBluetoothPairingFailed() if the pairing has failed.
+        */
+       result Pair(const BluetoothDevice& remoteDevice);
+
+       /**
+        * Stops the pairing process.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.gap
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the pairing process is not in progress.
+        * @exception   E_IN_PROGRESS               The termination of the pairing process is in progress.
+        * @exception   E_PRIVILEGE_DENIED          The application does not have the privilege to call this method.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        * @remarks     If the canceling of the pairing process is successful,
+        *              IBluetoothDeviceEventListener::OnBluetoothPairingFailed() is called with E_OPERATION_CANCELED.
+        */
+       result CancelPair(void);
+
+       /**
+        * Unpairs with the paired device.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.gap
+        *
+        * @return      An error code
+        * @param[in]   pairedDevice                The paired device to unpair
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the %Bluetooth is not activated, or retrieving the service
+        *                                          list is in progress.
+        * @exception   E_NOT_PAIRED                The input device is not found in the paired device list.
+        * @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 process of unpairing is to remove the specified device from the paired device list. No
+        *              notification is transmitted to the remote device. @n
+        *              This method is synchronous. Only when the result of this method is E_SUCCESS, the unpaired event is
+        *              fired.
+        * @see         IBluetoothDeviceEventListener::OnBluetoothUnpaired()
+        */
+       result Unpair(const BluetoothDevice& pairedDevice);
+
+private:
+       //
+       // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying
+       // of objects.
+       //
+       BluetoothManager(const BluetoothManager& value);
+       //
+       // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit
+       // copying of objects.
+       //
+       BluetoothManager& operator =(const BluetoothManager& value);
+
+private:
+       _BluetoothManagerImpl* __pImpl;
+
+       friend class _BluetoothManagerImpl;
+
+}; // BluetoothManager
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_MANAGER_H_
diff --git a/inc/FNetBtBluetoothOppClient.h b/inc/FNetBtBluetoothOppClient.h
new file mode 100755 (executable)
index 0000000..a0d5312
--- /dev/null
@@ -0,0 +1,179 @@
+//
+// 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    FNetBtBluetoothOppClient.h
+ * @brief   This is the header file for the %BluetoothOppClient class.
+ *
+ * This header file contains the declarations of the %BluetoothOppClient class.
+ */
+#ifndef _FNET_BT_BLUETOOTH_OPP_CLIENT_H_
+#define _FNET_BT_BLUETOOTH_OPP_CLIENT_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+
+namespace Tizen { namespace Base
+{
+class String;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class IBluetoothOppClientEventListener;
+class _BluetoothOppClientImpl;
+
+/**
+ * @class   BluetoothOppClient
+ * @brief   This class provides methods to handle the %Bluetooth Object Push Profile (OPP) client, such as the
+ *          outgoing connection requests.
+ *
+ * @since   2.0
+ *
+ * The %BluetoothOppClient class provides methods to handle the %Bluetooth Object Push Profile (OPP) client, such as the outgoing
+ * connection requests.
+ * @n
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ BluetoothOppClient
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * The object is not fully constructed after this constructor is called. For full construction, the Construct() method
+        * must be called right after calling this constructor.
+        *
+        * @since       2.0
+        */
+       BluetoothOppClient(void);
+
+       /**
+        * This destructor overrides Tizen::Base::Object::~Object().
+        *
+        * @since       2.0
+        */
+       virtual ~BluetoothOppClient(void);
+
+       /**
+        * Constructs and initializes this instance of %BluetoothOppClient with the specified listener.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for the OPP client
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        * @exception   E_UNSUPPORTED_OPERATION This operation is not supported.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result Construct(IBluetoothOppClientEventListener& listener);
+
+       /**
+        * Pushes a file to a remote OPP server. @n
+        * The file transfer starts when the OPP server accepts the request.
+        *
+        * @if OSPCOMPAT
+        * @brief <i> [Compatibility] </i>
+        * @endif
+        * @since       2.0
+        * @if OSPCOMPAT
+        * @compatibility       This method has compatibility issues@n
+        *                                      For more information, see @ref CompIoPathPage "here".
+        * @endif
+        * @privilege   http://tizen.org/privilege/bluetooth.opp
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice                The remote OPP server
+        * @param[in]   filePath                    The path of the source file
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_STATE             This instance is in an invalid state. @n
+        *                                          For example, %Bluetooth is not activated.
+        * @exception   E_IN_PROGRESS               The push process is in progress.
+        * @exception   E_PRIVILEGE_DENIED          The application does not have the privilege to call this method.
+        * @exception   E_SERVICE_UNAVAILABLE       The OPP service is unavailable.
+        * @exception   E_INACCESSIBLE_PATH         The specified @c filePath is inaccessible.
+        * @exception   E_REMOTE_DEVICE_NOT_FOUND   The input device is not found. @n
+        *                                          This exception is currently not in use.
+        * @exception   E_FAILURE                   The method has failed.
+        * @see         IBluetoothOppServerEventListener::OnOppPushRequested()
+        * @remarks     If the local device is not paired with the specified target device, the pairing process starts
+        *              internally before the push request is sent.
+        */
+       result PushFile(const BluetoothDevice& remoteDevice, const Tizen::Base::String& filePath);
+
+       /**
+        * Cancels the file push request in progress. @n
+        * If this method is called before the OPP server accepts the push request, the
+        * IBluetoothOppClientEventListener::OnOppPushResponded() method is called and the exception E_SYSTEM is thrown. @n
+        * If this method is called during the file transfer, the IBluetoothOppClientEventListener::OnOppTransferDone()
+        * method is called with @c isCompleted as @c false.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.opp
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         This instance is in an invalid state. @n
+        *                                      For example, %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the push request is not sent or accepted by a remote device.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @see         IBluetoothOppClientEventListener::OnOppPushResponded()
+        * @see         IBluetoothOppClientEventListener::OnOppTransferDone()
+        */
+       result CancelPush(void);
+
+       /**
+        * Sets the minimum interval of invocation of IBluetoothOppClientEventListener::OnOppTransferInProgress() in
+        * percentage. @n
+        * The default value is @c 5.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   percent                 The minimum period of progress interval as a percentage value
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_RANGE          The value of an argument is outside the valid range defined by the method.
+        * @see         IBluetoothOppClientEventListener::OnOppTransferInProgress()
+        */
+       result SetMinProgressInterval(int percent);
+
+private:
+       //
+       // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying
+       // of objects.
+       //
+       BluetoothOppClient(const BluetoothOppClient& value);
+       //
+       // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit
+       // copying of objects.
+       //
+       BluetoothOppClient& operator =(const BluetoothOppClient& value);
+
+private:
+       _BluetoothOppClientImpl* __pImpl;
+
+}; // BluetoothOppClient
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_OPP_CLIENT_H_
diff --git a/inc/FNetBtBluetoothOppServer.h b/inc/FNetBtBluetoothOppServer.h
new file mode 100755 (executable)
index 0000000..d0ed262
--- /dev/null
@@ -0,0 +1,257 @@
+//
+// 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        FNetBtBluetoothOppServer.h
+ * @brief       This is the header file for the %BluetoothOppServer class.
+ *
+ * This header file contains the declarations of the %BluetoothOppServer class.
+ */
+#ifndef _FNET_BT_BLUETOOTH_OPP_SERVER_H_
+#define _FNET_BT_BLUETOOTH_OPP_SERVER_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+
+namespace Tizen { namespace Base
+{
+class String;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class IBluetoothOppServerEventListener;
+class _BluetoothOppServerImpl;
+
+/**
+ * @class    BluetoothOppServer
+ * @brief    This class provides methods to handle the %Bluetooth Object Push Profile (OPP) server, such as the
+ *           incoming connection requests.
+ *
+ * @since    2.0
+ *
+ * The %BluetoothOppServer class provides methods to handle the %Bluetooth Object Push Profile (OPP) server, such as the incoming
+ * connection requests.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ BluetoothOppServer
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * The object is not fully constructed after this constructor is called. For full construction, the Construct()
+        * method must be called right after calling this constructor.
+        *
+        * @since       2.0
+        */
+       BluetoothOppServer(void);
+
+       /**
+        * This destructor overrides Tizen::Base::Object::~Object().
+        *
+        * @since       2.0
+        */
+       virtual ~BluetoothOppServer(void);
+
+       /**
+        * Constructs and initializes this instance of %BluetoothOppServer with the specified listener.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for the OPP server
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        * @exception   E_UNSUPPORTED_OPERATION This operation is not supported.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result Construct(IBluetoothOppServerEventListener& listener);
+
+       /**
+        * Accepts a push request from a remote OPP client. @n
+        * This method starts the file transfer.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.opp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a push request is not
+        *                                      received from a remote device.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @see         IBluetoothOppClientEventListener::OnOppPushResponded()
+        */
+       result AcceptPush(void);
+
+       /**
+        * Rejects a push request from a remote OPP client.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.opp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a push request is not
+        *                                      received from a remote device.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @see         IBluetoothOppClientEventListener::OnOppPushResponded()
+        */
+       result RejectPush(void);
+
+       /**
+        * Sets the destination path of the file to be received.
+        *
+        * @if OSPCOMPAT
+        * @brief <i> [Compatibility] </i>
+        * @endif
+        * @since       2.0
+        * @if OSPCOMPAT
+        * @compatibility       This method has compatibility issues. @n
+        *                                      For more information, see @ref CompIoPathPage "here".
+        *
+        * @endif
+        * @return      An error code
+        * @param[in]   dstPath                 The new destination file path
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, trying to change the path on Push transition is prohibited.
+        * @exception   E_INACCESSIBLE_PATH     The specified @c dstPath is inaccessible.
+        * @exception   E_FAILURE               The method has failed.
+        */
+       result SetDestinationPath(const Tizen::Base::String& dstPath);
+
+       /**
+        * Starts the OPP service and associates a listener with it.
+        *
+        * @if OSPCOMPAT
+        * @brief <i> [Compatibility] </i>
+        * @endif
+        * @since       2.0
+        * @if OSPCOMPAT
+        * @compatibility       This method has compatibility issues. @n
+        *                                      For more information, see @ref CompIoPathPage "here".
+        * @endif
+        * @privilege   http://tizen.org/privilege/bluetooth.opp
+        *
+        * @return      An error code
+        * @param[in]   dstPath                 The new destination file path
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         This instance is in an invalid state. @n
+        *                                      For example, %Bluetooth is not activated.
+        * @exception   E_IN_PROGRESS           The service has already started.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_SERVICE_UNAVAILABLE   The OPP service is unavailable.
+        * @exception   E_INACCESSIBLE_PATH     The specified @c dstPath is inaccessible.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, The stop process is in progress.
+        * @exception   E_FAILURE               The method has failed.
+        */
+       result StartService(const Tizen::Base::String& dstPath);
+
+       /**
+        * Stops the OPP service. @n
+        * This method cancels the file transfer before stopping the service.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.opp
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         This instance is in an invalid state. @n
+        *                                      For example, %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started as yet.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_IN_PROGRESS           The stop process is in progress.
+        * @exception   E_FAILURE               The method has failed.
+        */
+       result StopService(void);
+
+       /**
+        * Stops the file transfer in progress which was started by the client. @n
+        * If this method is called during the file transfer, the IBluetoothOppServerEventListener::OnOppTransferDone()
+        * method is called with @c isCompleted as @c false.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.opp
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         This instance is in an invalid state. @n
+        *                                      For example, %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the file transfer is not in progress.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_OPERATION_FAILED      The operation has failed.
+        * @see         IBluetoothOppServerEventListener::OnOppTransferDone()
+        */
+       result StopTransfer(void);
+
+       /**
+        * Sets the minimum interval of invocation of IBluetoothOppServerEventListener::OnOppTransferInProgress() in
+        * percentage. @n
+        * The default value is @c 5.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   percent                 The minimum period of progress interval as a percentage value
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_RANGE          The value of the argument is outside the valid range defined by the method.
+        * @see         IBluetoothOppServerEventListener::OnOppTransferInProgress()
+        */
+       result SetMinProgressInterval(int percent);
+
+private:
+       //
+       // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying
+       // of objects.
+       //
+       BluetoothOppServer(const BluetoothOppServer& value);
+       //
+       // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit
+       // copying of objects.
+       //
+       BluetoothOppServer& operator =(const BluetoothOppServer& value);
+
+private:
+       _BluetoothOppServerImpl* __pImpl;
+
+}; // BluetoothOppServer
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_OPP_SERVER_H_
diff --git a/inc/FNetBtBluetoothSppAcceptor.h b/inc/FNetBtBluetoothSppAcceptor.h
new file mode 100755 (executable)
index 0000000..0983502
--- /dev/null
@@ -0,0 +1,257 @@
+//
+// 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        FNetBtBluetoothSppAcceptor.h
+ * @brief       This is the header file for the %BluetoothSppAcceptor class.
+ *
+ * This header file contains the declarations of the %BluetoothSppAcceptor class.
+ */
+#ifndef _FNET_BT_BLUETOOTH_SPP_ACCEPTOR_H_
+#define _FNET_BT_BLUETOOTH_SPP_ACCEPTOR_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseUuId.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class IBluetoothSppAcceptorEventListener;
+class _BluetoothSppAcceptorImpl;
+
+/**
+ * @class   BluetoothSppAcceptor
+ * @brief   This class provides the methods to handle the %Bluetooth Serial Port Profile (SPP) acceptor, such as an
+ *          incoming connection request.
+ * @since   2.0
+ *
+ * The %BluetoothSppAcceptor class provides the methods to handle the %Bluetooth Serial Port Profile (SPP) acceptor, such as an
+ * incoming connection request.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ BluetoothSppAcceptor
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * The object is not fully constructed after this constructor is called. For full construction, the Construct()
+        * method must be called right after calling this constructor.
+        *
+        * @since       2.0
+        */
+       BluetoothSppAcceptor(void);
+
+       /**
+        * This destructor overrides Tizen::Base::Object::~Object().
+        *
+        * @since       2.0
+        */
+       virtual ~BluetoothSppAcceptor(void);
+
+       /**
+        * Initializes this instance of %BluetoothSppAcceptor with the specified listener.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for SPP acceptor
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        * @exception   E_UNSUPPORTED_OPERATION This operation is not supported.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result Construct(IBluetoothSppAcceptorEventListener& listener);
+
+       /**
+        * Accepts a connection request from a remote SPP initiator. @n
+        * This method establishes a connection.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or the connection request is
+        *                                      not yet received from a remote device.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @see         IBluetoothSppInitiatorEventListener::OnSppConnectionResponded()
+        */
+       result AcceptConnection(void);
+
+       /**
+        * Rejects a connection request from a remote SPP initiator.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or the connection request is
+        *                                      not yet received from a remote device.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @see         IBluetoothSppInitiatorEventListener::OnSppConnectionResponded()
+        */
+       result RejectConnection(void);
+
+       /**
+        * Starts the SPP service with the default service UUID - BT_SVC_UUID_SPP.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_IN_PROGRESS           The service has already started.
+        * @exception   E_ALREADY_CONNECTED     The connection with an SPP initiator has already been established.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_SERVICE_UNAVAILABLE   The SPP service with the specified UUId is unavailable.
+        * @exception   E_FAILURE               The method has failed.
+        */
+       result StartService(void);
+
+       /**
+        * Starts the SPP service with the specified service UUID.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @param[in]   serviceUuid             The UUID of SPP service
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_ARG           The specified input parameter is invalid.
+        * @exception   E_IN_PROGRESS           The service has already started.
+        * @exception   E_ALREADY_CONNECTED     The connection with an SPP initiator has already been established.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_SERVICE_UNAVAILABLE   The SPP service with the specified UUId is unavailable.
+        * @exception   E_FAILURE               The method has failed.
+        */
+       result StartService(const Tizen::Base::UuId& serviceUuid);
+
+       /**
+        * Stops the SPP service. @n
+        * This method disconnects the current connection before stopping the service.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        */
+       result StopService(void);
+
+       /**
+        * Disconnects the current connection.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a connection with a remote
+        *                                      device is not established.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @see         IBluetoothSppAcceptorEventListener::OnSppDisconnected()
+        * @see         IBluetoothSppInitiatorEventListener::OnSppDisconnected()
+        */
+       result Disconnect(void);
+
+       /**
+        * Sends the data.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @param[in]   buffer                  The data to send
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a connection with a remote
+        *                                      device is not established.
+        * @exception   E_INVALID_ARG           The specified @c buffer is empty.
+        * @exception   E_SYSTEM                A system error has occurred.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @remarks     The size of the buffer should not exceed @c 1000 bytes.
+        * @see         IBluetoothSppInitiatorEventListener::OnSppDataReceived()
+        */
+       result SendData(const Tizen::Base::ByteBuffer& buffer);
+
+private:
+       //
+       // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying
+       // of objects.
+       //
+       BluetoothSppAcceptor(const BluetoothSppAcceptor& value);
+       //
+       // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit
+       // copying of objects.
+       //
+       BluetoothSppAcceptor& operator =(const BluetoothSppAcceptor& value);
+
+private:
+       _BluetoothSppAcceptorImpl* __pImpl;
+
+}; // BluetoothSppAcceptor
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_SPP_ACCEPTOR_H_
diff --git a/inc/FNetBtBluetoothSppInitiator.h b/inc/FNetBtBluetoothSppInitiator.h
new file mode 100755 (executable)
index 0000000..da159e0
--- /dev/null
@@ -0,0 +1,214 @@
+//
+// 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    FNetBtBluetoothSppInitiator.h
+ * @brief   This is the header file for the %BluetoothSppInitiator class.
+ *
+ * This header file contains the declarations of the %BluetoothSppInitiator class.
+ */
+#ifndef _FNET_BT_BLUETOOTH_SPP_INITIATOR_H_
+#define _FNET_BT_BLUETOOTH_SPP_INITIATOR_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseUuId.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class IBluetoothSppInitiatorEventListener;
+class _BluetoothSppInitiatorImpl;
+
+/**
+ * @class   BluetoothSppInitiator
+ * @brief   This class provides the methods to handle the %Bluetooth Serial Port Profile (SPP) initiator, such as the
+ *          outgoing connection requests.
+ * @since   2.0
+ *
+ * The %BluetoothSppInitiator class provides the methods to handle the %Bluetooth Serial Port Profile (SPP) initiator, such as
+ * the outgoing connection requests.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ BluetoothSppInitiator
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * The object is not fully constructed after this constructor is called. For full construction, the Construct()
+        * method must be called right after calling this constructor.
+        *
+        * @since       2.0
+        */
+       BluetoothSppInitiator(void);
+
+       /**
+        * This destructor overrides Tizen::Base::Object::~Object().
+        *
+        * @since       2.0
+        */
+       virtual ~BluetoothSppInitiator(void);
+
+       /**
+        * Constructs and initializes this instance of %BluetoothSppInitiator with the specified listener.
+        *
+        * @since       2.0
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for the SPP initiator
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        * @exception   E_UNSUPPORTED_OPERATION This operation is not supported.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result Construct(IBluetoothSppInitiatorEventListener& listener);
+
+       /**
+        * Connects to a remote SPP acceptor with the default service UUID - BT_SVC_UUID_SPP. @n
+        * This method establishes a connection after the SPP acceptor accepts the request.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice                The remote device to connect
+        * @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
+        *                                          %Bluetooth is not activated.
+        * @exception   E_IN_PROGRESS               The connection process is in progress.
+        * @exception   E_ALREADY_CONNECTED         The connection with an SPP acceptor has already been established.
+        * @exception   E_PRIVILEGE_DENIED          The application does not have the privilege to call this method.
+        * @exception   E_SERVICE_UNAVAILABLE       The SPP connection is unavailable.
+        * @exception   E_REMOTE_DEVICE_NOT_FOUND   The input device is not found. @n
+        *                                          This exception is currently not in use.
+        * @exception   E_FAILURE                   The method has failed.
+        * @see         IBluetoothSppAcceptorEventListener::OnSppConnectionRequested()
+        * @remarks     If the local device is not paired with the specified target device, the pairing process starts
+        *              internally before the connect request is sent.
+        */
+       result Connect(const BluetoothDevice& remoteDevice);
+
+       /**
+        * Connects to a remote SPP acceptor with the specified service UUID. @n
+        * This method establishes a connection after the SPP acceptor accepts the request.
+        *
+        * @since 2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice                The remote device to connect
+        * @param[in]   serviceUuid                 The UUID of SPP service to connect
+        * @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
+        *                                          %Bluetooth is not activated.
+        * @exception   E_INVALID_ARG               A specified input parameter is invalid.
+        * @exception   E_IN_PROGRESS               The connection process is in progress.
+        * @exception   E_ALREADY_CONNECTED         The connection with an SPP acceptor has already been established.
+        * @exception   E_PRIVILEGE_DENIED          The application does not have the privilege to call this method.
+        * @exception   E_SERVICE_UNAVAILABLE       The SPP connection is unavailable.
+        * @exception   E_REMOTE_DEVICE_NOT_FOUND   The input device is not found. @n
+        *                                          This exception is currently not in use.
+        * @exception   E_FAILURE                   The method has failed.
+        * @see         IBluetoothSppAcceptorEventListener::OnSppConnectionRequested()
+        * @remarks     If the local device is not paired with the specified target device, the pairing process starts
+        *              internally before the connect request is sent.
+        */
+       result Connect(const BluetoothDevice& remoteDevice, const Tizen::Base::UuId& serviceUuid);
+
+       /**
+        * Disconnects the current connection. @n
+        * If this method is called before the SPP acceptor accepts the connection request, the
+        * IBluetoothSppInitiatorEventListener::OnSppConnectionResponded() and E_SYSTEM is thrown. @n
+        * If this method is called on connection, the IBluetoothSppInitiatorEventListener::OnSppDisconnected() and
+        * E_SUCCESS is thrown.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the connection request is not sent or a connection with a
+        *                                      remote device is not established yet.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @see         IBluetoothSppInitiatorEventListener::OnSppConnectionResponded()
+        * @see         IBluetoothSppInitiatorEventListener::OnSppDisconnected()
+        * @see         IBluetoothSppAcceptorEventListener::OnSppDisconnected()
+        */
+       result Disconnect(void);
+
+       /**
+        * Sends the specified data.
+        *
+        * @since       2.0
+        * @privilege   http://tizen.org/privilege/bluetooth.spp
+        *
+        * @return      An error code
+        * @param[in]   buffer                  The data to send
+        * @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 %Bluetooth is
+        *                                      not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the connection request is not sent or a connection with a
+        *                                      remote device is not established yet.
+        * @exception   E_INVALID_ARG           The argument has no data.
+        * @exception   E_SYSTEM                A system error has occurred.
+        * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
+        * @exception   E_FAILURE               The method has failed.
+        * @remarks     The size of the buffer should not exceed @c 1000 bytes.
+        * @see         IBluetoothSppAcceptorEventListener::OnSppDataReceived()
+        */
+       result SendData(const Tizen::Base::ByteBuffer& buffer);
+
+private:
+       //
+       // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying
+       // of objects.
+       //
+       BluetoothSppInitiator(const BluetoothSppInitiator& value);
+       //
+       // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit
+       // copying of objects.
+       //
+       BluetoothSppInitiator& operator =(const BluetoothSppInitiator& value);
+
+private:
+       _BluetoothSppInitiatorImpl* __pImpl;
+
+}; // BluetoothSppInitiator
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_SPP_INITIATOR_H_
diff --git a/inc/FNetBtBluetoothTypes.h b/inc/FNetBtBluetoothTypes.h
new file mode 100755 (executable)
index 0000000..b3e2fda
--- /dev/null
@@ -0,0 +1,630 @@
+//
+// 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    FNetBtBluetoothTypes.h
+ * @brief   This is the header file for the enumerations in the Bluetooth namespace.
+ *
+ * This header file contains the declarations and descriptions of the enumerations in the Bluetooth namespace.
+ */
+#ifndef _FNET_BT_BLUETOOTH_TYPES_H_
+#define _FNET_BT_BLUETOOTH_TYPES_H_
+
+#include <FBaseTypes.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+ * @if OSPDEPREC
+ * @enum        BluetoothDeviceStateType
+ * Defines the states of the local %Bluetooth device.
+ *
+ * @brief <i> [Deprecated]  </i>
+ * @deprecated  This enum type is deprecated because the on/off states and the discoverable mode are not orthogonal.
+ *              All the methods that use this enum type are also deprecated. Instead of using this enum type, it is
+ *              recommended to use BluetoothManager::IsActivated() and the enum
+ *              Bluetooth::BluetoothDiscoverableMode.
+ * @since       2.0
+ * @endif
+ */
+enum BluetoothDeviceStateType
+{
+       BT_DEVICE_STATE_OFF,                /**< The OFF state             */
+       BT_DEVICE_STATE_DISCOVERABLE,       /**< The DISCOVERABLE state    */
+       BT_DEVICE_STATE_NOT_DISCOVERABLE    /**< The NOT DISCOVERABLE state*/
+};
+
+/**
+ * @enum        BluetoothDiscoverableMode
+ * Defines the discoverable mode of the local %Bluetooth device.
+ *
+ * @since       2.0
+ */
+enum BluetoothDiscoverableMode
+{
+       BT_DISC_MODE_NOT_DISCOVERABLE,          /**< The mode NOT DISCOVERABLE by other devices */
+       BT_DISC_MODE_DISCOVERABLE,              /**< The mode DISCOVERABLE by other devices     */
+       BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE  /**< The mode DISCOVERABLE by other devices during a certain amount of time
+                                                *   @b Since: @b 2.0
+                                                */
+};
+
+/**
+ * @enum        BluetoothConnectionType
+ * Defines the %Bluetooth connection types.
+ *
+ * @since       2.0
+ */
+enum BluetoothConnectionType
+{
+       BT_CONNECTION_GENERIC,              /**< The GENERIC CONNECTION
+                                                        *   @if OSPDEPREC
+                                                        *   @deprecated    This enumeration field is deprecated. @n
+                                                        *   @endif
+                                                        */
+       BT_CONNECTION_SPP_ACCEPTOR,         /**< The SPP ACCEPTOR CONNECTION  */
+       BT_CONNECTION_SPP_INITIATOR,        /**< The SPP INITIATOR CONNECTION */
+       BT_CONNECTION_OPP_SERVER,           /**< The OPP SERVER CONNECTION    */
+       BT_CONNECTION_OPP_CLIENT,           /**< The OPP CLIENT CONNECTION    */
+       BT_CONNECTION_MAX
+};
+
+/**
+ * @enum        BluetoothHealthDataChannelType
+ * Defines the transmission type of %BluetoothHealth data channel.
+ *
+ * @since 2.0
+ */
+enum BluetoothHealthDataChannelType
+{
+       BT_HEALTH_DATA_CHANNEL_NONE,         /**< The any type of data channel */
+       BT_HEALTH_DATA_CHANNEL_RELIABLE,    /**< The data channel type for transmitting data with the reliable manner of
+                                            *   which the confidence in the exchange is at its highest (e.g. measurement
+                                            *   and alert information)
+                                            */
+       BT_HEALTH_DATA_CHANNEL_STREAMING    /**< The data channel type for transmitting data when the timeliness of the
+                                            *   delivery of each frame is more important than the reliable delivery of
+                                            *   every frame (e.g. an ECG waveform, where low latency is critical)
+                                            */
+};
+
+/**
+ * @enum        BluetoothServiceClassType
+ * Defines the service class type (part of the class of the device), returned from the device discovery.
+ *
+ * @since        2.0
+ */
+enum BluetoothServiceClassType
+{
+       BT_COD_SVC_LIMITED_DISCOVERABLE_MODE = 0x0020,      /**< The LIMITED DISCOVERABLE MODE          */
+       BT_COD_SVC_POSITIONING = 0x0100,                    /**< The POSITIONING service class type     */
+       BT_COD_SVC_NETWORKING = 0x0200,                     /**< The NETWORKING service class type      */
+       BT_COD_SVC_RENDERING = 0x0400,                      /**< The RENDERING service class type       */
+       BT_COD_SVC_CAPTURING = 0x0800,                      /**< The CAPTURING service class type       */
+       BT_COD_SVC_OBJECT_TRANSFER = 0x1000,                /**< The OBJECT TRANSFER service class type */
+       BT_COD_SVC_AUDIO = 0x2000,                          /**< The AUDIO service class type           */
+       BT_COD_SVC_TELEPHONY = 0x4000,                      /**< The TELEPHONY service class type       */
+       BT_COD_SVC_INFORMATION = 0x8000,                    /**< The INFORMATION service class type     */
+       BT_COD_SVC_ALL = 0x01FF,                            /**< The ALL services class type            */
+       BT_COD_SVC_UNKNOWN = 0x0000                         /**< The UNKNOWN service class type         */
+};
+
+/**
+ * @enum        BluetoothMajorDeviceClassType
+ * Defines the major device class (part of the class of the device).
+ *
+ * @since        2.0
+ */
+enum BluetoothMajorDeviceClassType
+{
+       BT_COD_MAJ_DEV_CLS_MISC = 0x00,                     /**< The MISC major device class type             */
+       BT_COD_MAJ_DEV_CLS_COMPUTER = 0x01,                 /**< The COMPUTER major device class type         */
+       BT_COD_MAJ_DEV_CLS_PHONE = 0x02,                    /**< The PHONE major device class type            */
+       BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT = 0x03,         /**< The LAN ACCESS POINT major device class type */
+       BT_COD_MAJ_DEV_CLS_AUDIO = 0x04,                    /**< The AUDIO major device class type            */
+       BT_COD_MAJ_DEV_CLS_PERIPHERAL = 0x05,               /**< The PERIPHERAL major device class type       */
+       BT_COD_MAJ_DEV_CLS_IMAGING = 0x06,                  /**< The IMAGING major device class type          */
+       BT_COD_MAJ_DEV_CLS_UNCLASSIFIED = 0x1F              /**< The UNCLASSIFIED major device class type     */
+};
+
+/**
+ * @enum        BluetoothMinorDeviceClassType
+ * Defines the minor device class (part of the class of the device).
+ *
+ * @since        2.0
+ */
+enum BluetoothMinorDeviceClassType
+{
+       BT_COD_MIN_DEV_CLS_UNCLASSIFIED = 0x00,                 /**< The UNCLASSIFIED minor device class type          */
+
+       BT_COD_MIN_DEV_CLS_DESKTOP_WORKSTATION = 0x04,          /**< The DESKTOP WORKSTATION minor device class type   */
+       BT_COD_MIN_DEV_CLS_SERVER_CLASS_COMPUTER = 0x08,        /**< The SERVER CLASS COMPUTER minor device class type */
+       BT_COD_MIN_DEV_CLS_LAPTOP = 0x0C,                       /**< The LAPTOP minor device class type                */
+       BT_COD_MIN_DEV_CLS_HANDHELD_PC_OR_PDA = 0x10,           /**< The HANDHELD PC OR PDA minor device class type    */
+       BT_COD_MIN_DEV_CLS_PALM_SIZED_PC_OR_PDA = 0x14,         /**< The PALM SIZED PC OR PDA minor device class type  */
+       BT_COD_MIN_DEV_CLS_WEARABLE_COMPUTER = 0x18,            /**< The WEARABLE COMPUTER minor device class type     */
+
+       BT_COD_MIN_DEV_CLS_CELLULAR = 0x04,                     /**< The CELLULAR minor device class type                     */
+       BT_COD_MIN_DEV_CLS_CORDLESS = 0x08,                     /**< The CORDLESS minor device class type                     */
+       BT_COD_MIN_DEV_CLS_SMART_PHONE = 0x0C,                  /**< The SMART PHONE minor device class type                  */
+       BT_COD_MIN_DEV_CLS_WIRED_MODEM_OR_VOICE_GATEWAY = 0x10, /**< The WIRED MODEM OR VOICE GATEWAY minor device class type */
+       BT_COD_MIN_DEV_CLS_COMMON_ISDN_ACCESS = 0x14,           /**< The COMMON ISDN ACCESS minor device class type           */
+
+       BT_COD_MIN_DEV_CLS_FULLY_AVAILABLE = 0x04,              /**< The FULLY AVAILABLE minor device class type           */
+       BT_COD_MIN_DEV_CLS_1_TO_17_PERCENT_UTILIZED = 0x20,     /**< The 1_TO_17_PERCENT_UTILIZED minor device class type  */
+       BT_COD_MIN_DEV_CLS_17_TO_33_PERCENT_UTILIZED = 0x40,    /**< The 17_TO_33_PERCENT_UTILIZED minor device class type */
+       BT_COD_MIN_DEV_CLS_33_TO_50_PERCENT_UTILIZED = 0x60,    /**< The 33_TO_50_PERCENT_UTILIZED minor device class type */
+       BT_COD_MIN_DEV_CLS_50_to_67_PERCENT_UTILIZED = 0x80,    /**< The 50_to_67_PERCENT_UTILIZED minor device class type */
+       BT_COD_MIN_DEV_CLS_67_TO_83_PERCENT_UTILIZED = 0xA0,    /**< The 67_TO_83_PERCENT_UTILIZED minor device class type */
+       BT_COD_MIN_DEV_CLS_83_TO_99_PERCENT_UTILIZED = 0xC0,    /**< The 83_TO_99_PERCENT_UTILIZED minor device class type */
+       BT_COD_MIN_DEV_CLS_NO_SERVICE_AVAILABLE = 0xE0,         /**< The NO SERVICE AVAILABLE minor device class type      */
+
+       BT_COD_MIN_DEV_CLS_HEADSET_PROFILE = 0x04,              /**< The HEADSET PROFILE minor device class type       */
+       BT_COD_MIN_DEV_CLS_HANDSFREE = 0x08,                    /**< The HANDSFREE minor device class type             */
+       BT_COD_MIN_DEV_CLS_SIM_CARD_READER = 0x18,              /**< The SIM CARD READER minor device class type       */
+
+};
+
+/**
+ * @enum        BluetoothServiceType
+ * Defines the %Bluetooth service type.
+ *
+ * @since       2.0
+ */
+enum BluetoothServiceType
+{
+       BT_SVC_RES_SERVICE = 0x00000001,           /**< The Reserved service type                           */
+       BT_SVC_SPP_SERVICE = 0x00000002,           /**< The Serial port profile service type                */
+       BT_SVC_DUN_SERVICE = 0x00000004,           /**< The Dial-up networking profile service type         */
+       BT_SVC_FAX_SERVICE = 0x00000008,           /**< The Fax profile service type                        */
+       BT_SVC_LAP_SERVICE = 0x00000010,           /**< The LAN access profile service type                 */
+       BT_SVC_HSP_SERVICE = 0x00000020,           /**< The Headset profile service type                    */
+       BT_SVC_HFP_SERVICE = 0x00000040,           /**< The Hands-free profile service type                 */
+       BT_SVC_OPP_SERVICE = 0x00000080,           /**< The Object push service type                        */
+       BT_SVC_FTP_SERVICE = 0x00000100,           /**< The File transfer service type                      */
+       BT_SVC_CTP_SERVICE = 0x00000200,           /**< The Cordless Terminal service type                  */
+       BT_SVC_ICP_SERVICE = 0x00000400,           /**< The Intercom Terminal service type                  */
+       BT_SVC_SYNC_SERVICE = 0x00000800,          /**< The Synchronization service type                    */
+       BT_SVC_BPP_SERVICE = 0x00001000,           /**< The Print server service type                       */
+       BT_SVC_BIP_SERVICE = 0x00002000,           /**< The Basic Imaging service type                      */
+       BT_SVC_PANU_SERVICE = 0x00004000,          /**< The PAN User service type                           */
+       BT_SVC_NAP_SERVICE = 0x00008000,           /**< The PAN Network access point service type           */
+       BT_SVC_GN_SERVICE = 0x00010000,            /**< The PAN Group Ad-hoc networks service type          */
+       BT_SVC_SAP_SERVICE = 0x00020000,           /**< The SIM Access Profile service type                 */
+       BT_SVC_A2DP_SERVICE = 0x00040000,          /**< An advanced audio distribution service type         */
+       BT_SVC_AVRCP_SERVICE = 0x00080000,         /**< An A/V remote control service type                  */
+       BT_SVC_HID_SERVICE = 0x00100000,           /**< The HID profile service type                        */
+       BT_SVC_VDP_SERVICE = 0x00200000,           /**< The VDP profile service type                        */
+       BT_SVC_PBAP_SERVICE = 0x00400000,          /**< The PhoneBook Access service type                   */
+       BT_SVC_HSP_HS_SERVICE = 0x00800000,        /**< The Headset service type                            */
+       BT_SVC_HFP_HS_SERVICE = 0x01000000,        /**< The Hands-free Headset service type                 */
+       BT_SVC_HCRP_SERVICE = 0x02000000,          /**< The Hardcopy cable replacement profile service type
+                                                *   @b Since: @b 2.0
+                                                */
+       BT_SVC_DID_SERVICE = 0x04000000,           /**< The device identification profile service type
+                                                *   @b Since: @b 2.0
+                                                */
+       BT_SVC_HDP_SERVICE = 0x08000000,           /**< The health device profile service type
+                                                *   @b Since: @b 2.0
+                                                */
+       BT_SVC_MAP_SERVICE = 0x10000000,           /**< The message access profile service type
+                                                *   @b Since: @b 2.0
+                                                */
+       BT_SVC_ALL_SERVICE = 0x01FFFFFF,           /**< The All-services-supported-by-BTA service type
+                                                               *   @if OSPDEPREC
+                                                               *   @deprecated    This enumeration field is deprecated.
+                                                               *   @endif
+
+                                                */
+       BT_SVC_NONE = 0                            /**< The No service or unknown service type              */
+};
+
+/**
+ * The serial port profile UUID (00001101-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_SPP[];
+
+/**
+ * The LAN access profile UUID (00001102-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_LAP[];
+
+/**
+ * The dial-up networking profile UUID (00001103-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_DUN[];
+
+/**
+ * The synchronization profile UUID (00001104-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_SYNC[];
+
+/**
+ * The object push profile UUID (00001105-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_OPP[];
+
+/**
+ * The file transfer profile UUID (00001106-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_FTP[];
+
+/**
+ * The synchronization profile UUID (00001107-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_SYNC_COMMAND[];
+
+/**
+ * The headset profile UUID (00001108-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HSP[];
+
+/**
+ * The cordless telephony profile UUID (00001109-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_CTP[];
+
+/**
+ * The advanced audio distribution profile source UUID (0000110A-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_A2DP_SOURCE[];
+
+/**
+ * The advanced audio distribution profile - sink UUID (0000110B-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_A2DP_SINK[];
+
+/**
+ * The audio/video remote control profile - target UUID (0000110C-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_AVRCP_TARGET[];
+
+/**
+ * The advanced audio distribution profile UUID (0000110D-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_A2DP[];
+
+/**
+ * The audio/video remote control profile UUID (0000110E-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_AVRCP[];
+
+/**
+ * The audio/video remote control profile - controller UUID (0000110F-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_AVRCP_CONTROLLER[];
+
+/**
+ * The intercom profile UUID (00001110-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_ICP[];
+
+/**
+ * The fax profile UUID (00001111-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_FAX[];
+
+/**
+ * The headset profile audio gateway UUID (00001112-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HSP_AG[];
+
+/**
+ * The personal area networking profile - user UUID (00001115-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_PAN_PANU[];
+
+/**
+ * The personal area networking profile - network access point UUID (00001116-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_PAN_NAP[];
+
+/**
+ * The personal area networking profile - group ad-hoc networks UUID (00001117-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_PAN_GN[];
+
+/**
+ * The basic printing profile - direct printing UUID (00001118-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BPP_DIRECT_PRINTING[];
+
+/**
+ * The basic printing profile - reference printing UUID (00001119-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BPP_REFERENCE_PRINTING[];
+
+/**
+ * The basic imaging profile UUID (0000111A-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BIP[];
+
+/**
+ * The basic imaging profile - imaging responder UUID (0000111B-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BIP_RESPONDER[];
+
+/**
+ * The basic imaging profile - imaging automatic archive UUID (0000111C-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BIP_AUTOMATIC_ARCHIVE[];
+
+/**
+ * The basic imaging profile - imaging referenced objects UUID (0000111D-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BIP_REFERENCED_OBJECTS[];
+
+/**
+ * The hands-free profile UUID (0000111E-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HFP[];
+
+/**
+ * The hands-free profile - audio gateway UUID (0000111F-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HFP_AG[];
+
+/**
+ * The basic printing profile - direct printing referenced objects UUID (00001120-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BPP_DIRECT_PRINTING_RO[];
+
+/**
+ * The basic printing profile - reflected UI UUID (00001121-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BPP_REFLECTED_UI[];
+
+/**
+ * The basic printing profile - basic printing UUID (00001122-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BPP_BASIC_PRINTING[];
+
+/**
+ * The basic printing profile - printing status UUID (00001123-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_BPP_PRINTING_STATUS[];
+
+/**
+ * The human interface device profile UUID (00001124-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HID[];
+
+/**
+ * The hardcopy cable replacement profile UUID (00001125-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HCRP[];
+
+/**
+ * The hardcopy cable replacement profile - print UUID (00001126-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HCRP_PRINT[];
+
+/**
+ * The hardcopy cable replacement profile - scan UUID (00001127-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HCRP_SCAN[];
+
+/**
+ * The SIM access profile UUID (0000112D-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_SAP[];
+
+/**
+ * The phone book access - client equipment UUID (0000112E-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_PBAP_PCE[];
+
+/**
+ * The phone book access - server equipment UUID (0000112F-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_PBAP_PSE[];
+
+/**
+ * The phone book access UUID (00001130-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_PBAP[];
+
+/**
+ * The headset profile - headset UUID (00001131-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HSP_HS[];
+
+/**
+ * The message access profile - message access server UUID (00001132-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_MAP_ACCESS_SERVER[];
+
+/**
+ * The message access profile - message notification server UUID (00001133-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_MAP_NOTIFICATION_SERVER[];
+
+/**
+ * The message access profile - message access profile UUID (00001134-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_MAP_ACCESS_PROFILE[];
+
+/**
+ * The device identification profile - PNP information UUID (00001200-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_DID_PNP_INFORMATION[];
+
+/**
+ * The generic networking UUID (00001201-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_GENERIC_NETWORKING[];
+
+/**
+ * The generic file transfer UUID (00001202-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_GENERIC_FILE_TRANSFER[];
+
+/**
+ * The generic audio UUID (00001203-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_GENERIC_AUDIO[];
+
+/**
+ * The generic telephony UUID. (00001204-0000-1000-8000-00805F9B34FB)
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_GENERIC_TELEPHONY[];
+
+/**
+ * The video distribution profile - source UUID (00001303-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_VDP_SOURCE[];
+
+/**
+ * The video distribution profile - sink UUID (00001304-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_VDP_SINK[];
+
+/**
+ * The video distribution profile - distribution UUID (00001305-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_VDP_DISTRIBUTION[];
+
+/**
+ * The health device profile UUID (00001400-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HDP[];
+
+/**
+ * The health device profile - source UUID (00001401-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HDP_SOURCE[];
+
+/**
+ * The health device profile - sink UUID (00001402-0000-1000-8000-00805F9B34FB).
+ *
+ * @since 2.0
+ */
+_OSP_EXPORT_ extern const byte BT_SVC_UUID_HDP_SINK[];
+
+} } }
+#endif // _FNET_BT_BLUETOOTH_TYPES_H_
diff --git a/inc/FNetBtIBluetoothDeviceEventListener.h b/inc/FNetBtIBluetoothDeviceEventListener.h
new file mode 100755 (executable)
index 0000000..23f0eb8
--- /dev/null
@@ -0,0 +1,206 @@
+//
+// 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    FNetBtIBluetoothDeviceEventListener.h
+ * @brief   This is the header file for the %IBluetoothDeviceEventListener interface.
+ *
+ * This header file contains the declarations of the %IBluetoothDeviceEventListener interface.
+ */
+#ifndef _FNET_BT_IBLUETOOTH_DEVICE_EVENT_LISTENER_H_
+#define _FNET_BT_IBLUETOOTH_DEVICE_EVENT_LISTENER_H_
+
+#include <FBaseResult.h>
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declaration
+class BluetoothDevice;
+
+/**
+ * @interface   IBluetoothDeviceEventListener
+ * @brief       This interface implements the listener for %Bluetooth remote device events.
+ *
+ * @since       2.0
+ *
+ * The %IBluetoothDeviceEventListener interface specifies the methods used to create notifications for the different
+ * kinds of %Bluetooth remote device events, including device discovery, service discovery, and pairing of the devices.
+ * When a %Bluetooth device event is generated, one of these methods is called.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ IBluetoothDeviceEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes
+        * are called when the destructor of this interface is called.
+        *
+        * @since       2.0
+        */
+       virtual ~IBluetoothDeviceEventListener(void) {}
+
+       /**
+        * Called when the device discovery process for finding the nearby %Bluetooth devices has started.
+        *
+        * @since       2.0
+        *
+        * @param[in]   r                   The start status
+        * @exception   E_SUCCESS           The device discovery process is launched successfully.
+        * @exception   E_SYSTEM            A system error has occurred.
+        * @see         BluetoothManager::StartDiscovery()
+        */
+       virtual void OnBluetoothDiscoveryStarted(result r) = 0;
+
+       /**
+        * Called when a remote device is found during the device discovery process.
+        *
+        * @since       2.0
+        *
+        * @param[in]   pFoundDevice        The remote device that is found
+        * @remarks     This event may be issued only if the device discovery process has started successfully.
+        * @see         BluetoothManager::StartDiscovery()
+        */
+       virtual void OnBluetoothRemoteDeviceFoundN(BluetoothDevice* pFoundDevice) = 0;
+
+       /**
+        * Called when the device discovery process for finding the nearby %Bluetooth devices has completed.
+        *
+        * @since       2.0
+        *
+        * @param[in]   isCompleted         Set to @c true if the device discovery process is successfully completed, @n
+        *                                  else @c false @n
+        *                                  For example, the discovery is canceled.
+        * @remarks     This event must be issued only if the discovery starts successfully.
+        * @see         BluetoothManager::CancelDiscovery()
+        */
+       virtual void OnBluetoothDiscoveryDone(bool isCompleted) = 0;
+
+       /**
+        * Called when a service list is received from a remote device using the service discovery process.
+        *
+        * @since       2.0
+        *
+        * @param[in]   targetDevice                The remote device that sends its service list
+        * @param[in]   serviceList                 The service list that is received
+        * @param[in]   r                           The result of receiving the service list
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_REMOTE_SERVICE_NOT_FOUND  The service list of the remote device is not found.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        * @remarks     @c serviceList consists of Bluetooth::BluetoothServiceType values which are joined by OR
+        *              operator.
+        */
+       virtual void OnBluetoothServiceListReceived(const BluetoothDevice& targetDevice, unsigned long serviceList, result r) = 0;
+
+       /**
+        * Called when a new remote device is paired with this local device.
+        *
+        * @since       2.0
+        *
+        * @param[in]   pairedDevice      The device to pair with the local device
+        * @remarks     This method is able to be called even though the specified device already exists in the paired
+        *              device list. Because the authorized key with the remote device is no more valid. @n
+        *              @c pairedDevice may have no service list value and elements in the service UUID list because the
+        *              retrieving the service list from the remote device fails. In that case, call
+        *              BluetoothManager::RetrieveServiceList() to get the service list from the paired device. @n
+        *              If the pairing is explicitly requested by BluetoothManager::Pair() and the request fails,
+        *              IBluetoothDeviceEventListener::OnBluetoothPairingFailed() is called instead of this method.
+        * @see         BluetoothManager::Pair()
+        * @see         OnBluetoothPairingFailed()
+        */
+       virtual void OnBluetoothPaired(const BluetoothDevice& pairedDevice) = 0;
+
+       /**
+        * Called when the already paired device is unpaired with this local device.
+        *
+        * @since       2.0
+        *
+        * @param[in]   unpairedDevice      The device to unpair with the local device
+        */
+       virtual void OnBluetoothUnpaired(const BluetoothDevice& unpairedDevice) = 0;
+
+       /**
+        * Called when the pairing request with the specific remote device fails.
+        *
+        * @since 2.0
+        *
+        * @param[in]   r                           The error result of the pairing request. @n
+        *                                          One of the following exception is thrown.
+        * @exception   E_OPERATION_CANCELED        The pairing operation is canceled explicitly.
+        * @exception   E_TIMEOUT                   The pairing request has timed out because the remote device does not
+        *                                          respond within 60 seconds.
+        * @exception   E_OPERATION_FAILED          The operation has failed.
+        * @see         BluetoothManager::Pair()
+        * @see         BluetoothManager::CancelPair()
+        * @see         OnBluetoothPaired()
+        */
+       virtual void OnBluetoothPairingFailed(result r) {}
+
+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 IBluetoothDeviceEventListener_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 IBluetoothDeviceEventListener_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 IBluetoothDeviceEventListener_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 IBluetoothDeviceEventListener_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 IBluetoothDeviceEventListener_Reserved5(void) {}
+}; // IBluetoothDeviceEventListener
+
+} } }
+#endif // _FNET_BT_IBLUETOOTH_DEVICE_EVENT_LISTENER_H_
diff --git a/inc/FNetBtIBluetoothHealthEventListener.h b/inc/FNetBtIBluetoothHealthEventListener.h
new file mode 100755 (executable)
index 0000000..90ab3ec
--- /dev/null
@@ -0,0 +1,139 @@
+//
+// 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    FNetBtIBluetoothHealthEventListener.h
+ * @brief   This is the header file for the %IBluetoothHealthEventListener interface.
+ *
+ * This header file contains the declarations of the %IBluetoothHealthEventListener interface.
+ */
+#ifndef _FNET_BT_IBLUETOOTH_HEALTH_EVENT_LISTENER_H_
+#define _FNET_BT_IBLUETOOTH_HEALTH_EVENT_LISTENER_H_
+
+#include <FBaseResult.h>
+#include <FBaseRtIEventListener.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+class BluetoothDevice;
+
+/**
+ * @interface   IBluetoothHealthEventListener
+ * @brief       This interface provides a listener for the %BluetoothHealth events.
+ * @since 2.0
+ *
+ * The %IBluetoothHealthEventListener interface specifies the methods used for creating notifications about the
+ * different kinds of BluetoothHealth events. When a %BluetoothHealth event is generated, one of these methods is called.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ IBluetoothHealthEventListener
+       : virtual public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes
+        * are called when the destructor of this interface is called.
+        *
+        * @since 2.0
+        */
+       virtual ~IBluetoothHealthEventListener(void) {}
+
+       /**
+        * Called to notify when a connection with a health device is established.
+        *
+        * @since 2.0
+        * @param[in]   channelId           The channel ID of the established connection, @n
+        *                                  else an invalid ID (-1) if the method is not successful
+        * @param[in]   dataType            The type of data used in the established connection which is defined in
+        *                                  ISO/IEEE 11073-20601 and represents type of health device such as thermometer,
+        *                                  heart rate monitor, weight scale, and so on
+        * @param[in]   channelType         The data channel type of the established connection
+        * @param[in]   pRemoteDevice       The remote health device to connect with the local device, @n
+        *                                  else @c null if the method is not successful
+        * @param[in]   r                   The result of the connection request. @n
+        *                                  One of the following exception is thrown.
+        * @exception   E_SUCCESS           The connection is established successfully.
+        * @exception   E_OPERATION_FAILED  The connection request has failed.
+        */
+       virtual void OnHealthConnected(int channelId, int dataType, BluetoothHealthDataChannelType channelType,
+                       const BluetoothDevice* pRemoteDevice, result r) = 0;
+
+       /**
+        * Called to notify that the connection with the specified channel ID is disconnected.
+        *
+        * @since 2.0
+        *
+        * @param[in]   channelId           The channel ID of the terminated connection
+        * @param[in]   r                   The disconnection status. @n
+        *                                  One of the following exception is thrown.
+        * @exception   E_SUCCESS           The specified connection (channel) is terminated successfully.
+        * @exception   E_OPERATION_FAILED  The method has failed to disconnect.
+        */
+       virtual void OnHealthDisconnected(int channelId, result r) = 0;
+
+       /**
+        * Called to notify when the data has been received on the specified channel.
+        *
+        * @since 2.0
+        *
+        * @param[in]   channelId           The channel ID of the connection to receive data
+        * @param[in]   buffer              The data to receive
+        */
+       virtual void OnHealthDataReceived(int channelId, Tizen::Base::ByteBuffer& buffer) = 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 IBluetoothHealthEventListener_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 IBluetoothHealthEventListener_Reserved2(void) {};
+
+       //
+       //
+       // This method is for internal use only. Using this method can cause behavioral, security-related, and
+       // consistency-relatedissues in the application.
+       // This method is reserved and may change its name at any time without prior notice.
+       //
+       // @since 2.0
+       //
+       virtual void IBluetoothHealthEventListener_Reserved3(void) {};
+
+}; // IBluetoothHealthEventListener
+
+} } }
+#endif // _FNET_BT_IBLUETOOTH_HEALTH_EVENT_LISTENER_H_
diff --git a/inc/FNetBtIBluetoothManagerEventListener.h b/inc/FNetBtIBluetoothManagerEventListener.h
new file mode 100755 (executable)
index 0000000..0b56853
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// 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    FNetBtIBluetoothManagerEventListener.h
+ * @brief   This is the header file for the %IBluetoothManagerEventListener interface.
+ *
+ * This header file contains the declarations of the %IBluetoothManagerEventListener interface.
+ */
+#ifndef _FNET_BT_IBLUETOOTH_MANAGER_EVENT_LISTENER_H_
+#define _FNET_BT_IBLUETOOTH_MANAGER_EVENT_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+ * @interface   IBluetoothManagerEventListener
+ * @brief       This interface implements the listener for the %BluetoothManager events.
+ *
+ * @since       2.0
+ *
+ * The %IBluetoothManagerEventListener interface specifies the methods used for creating notifications about the
+ * different kinds of BluetoothManager events. When a BluetoothManager event is generated, one of these methods is
+ * called.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ IBluetoothManagerEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes
+        * are called when the destructor of this interface is called.
+        *
+        * @since       2.0
+        */
+       virtual ~IBluetoothManagerEventListener(void) {}
+
+       /**
+        * Called when %Bluetooth 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 OnBluetoothActivated(result r) = 0;
+
+       /**
+        * Called when %Bluetooth 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 OnBluetoothDeactivated(result r) = 0;
+
+       /**
+        * Called when the discoverable mode is changed on the device.
+        *
+        * @since 2.0
+        *
+        * @param[in]   mode            The new discoverable mode to change
+        */
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode) {}
+
+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 IBluetoothManagerEventListener_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 IBluetoothManagerEventListener_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 IBluetoothManagerEventListener_Reserved3(void) {};
+}; // IBluetoothManagerEventListener
+
+} } }
+#endif // _FNET_BT_IBLUETOOTH_MANAGER_EVENT_LISTENER_H_
diff --git a/inc/FNetBtIBluetoothOppClientEventListener.h b/inc/FNetBtIBluetoothOppClientEventListener.h
new file mode 100755 (executable)
index 0000000..0835e26
--- /dev/null
@@ -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    FNetBtIBluetoothOppClientEventListener.h
+ * @brief   This is the header file for the %IBluetoothOppClientEventListener interface.
+ *
+ * This header file contains the declarations of the %IBluetoothOppClientEventListener interface.
+ */
+#ifndef _FNET_BT_IBLUETOOTH_OPP_CLIENT_EVENT_LISTENER_H_
+#define _FNET_BT_IBLUETOOTH_OPP_CLIENT_EVENT_LISTENER_H_
+
+#include <FBaseString.h>
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+ * @interface   IBluetoothOppClientEventListener
+ * @brief       This interface provides a listener for the %BluetoothOppClient events.
+ *
+ * @since       2.0
+ *
+ * The %IBluetoothOppClientEventListener interface specifies the methods used for creating notifications about the
+ * different kinds of BluetoothOppClient events. When a BluetoothOppClient event is generated, one of these methods
+ * is called.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ IBluetoothOppClientEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes
+        * are called when the destructor of this interface is called.
+        *
+        * @since       2.0
+        */
+       virtual ~IBluetoothOppClientEventListener(void) {}
+
+       /**
+        * Called when the OPP server responded to the push request.
+        *
+        * @since       2.0
+        *
+        * @param[in]   r                   The response status
+        * @exception   E_SUCCESS           The push request is accepted by the OPP server and the file transfer has begun.
+        * @exception   E_REJECTED          The push request is rejected by the OPP server. @n
+        *                                  This exception is currently not in use.
+        * @exception   E_TIMEOUT           The push request is out of time.
+        * @exception   E_SYSTEM            A failure has occurred from the underlying system. @n
+        *                                  This failure includes the rejection by the OPP server.
+        */
+       virtual void OnOppPushResponded(result r) = 0;
+
+       /**
+        * Called when the file is being transferred. @n
+        * Gets the progress information of the file transfer.
+        *
+        * @since       2.0
+        *
+        * @param[in]   percent             The progress in percentage ranging from @c 1 to @c 100 percent
+        * @see         BluetoothOppClient::SetMinProgressInterval()
+        */
+       virtual void OnOppTransferInProgress(int percent) = 0;
+
+       /**
+        * Called when the file transfer has finished.
+        *
+        * @if OSPCOMPAT
+        * @brief <i> [Compatibility] </i>
+        * @endif
+        * @since       2.0
+        * @if OSPCOMPAT
+        * @compatibility       This method has compatibility issues. @n
+        *                                      For more information, see @ref CompIoPathPage "here".
+        *
+        * @endif
+        * @param[in]   filePath            The path of the file (including the file name) to transfer
+        * @param[in]   fileSize            The size of the file to transfer
+        * @param[in]   isCompleted         Set to @c true if the transfer is successfully completed, @n
+        *                                  else @c false
+        */
+       virtual void OnOppTransferDone(const Tizen::Base::String& filePath, int fileSize, bool isCompleted) = 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 IBluetoothOppClientEventListener_Reserved1(void) {};
+}; // IBluetoothOppClientEventListener
+
+} } }
+#endif // _FNET_BT_IBLUETOOTH_OPP_CLIENT_EVENT_LISTENER_H_
diff --git a/inc/FNetBtIBluetoothOppServerEventListener.h b/inc/FNetBtIBluetoothOppServerEventListener.h
new file mode 100755 (executable)
index 0000000..2f5bf70
--- /dev/null
@@ -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    FNetBtIBluetoothOppServerEventListener.h
+ * @brief   This is the header file for the %IBluetoothOppServerEventListener interface.
+ *
+ * This header file contains the declarations of the %IBluetoothOppServerEventListener interface.
+ */
+#ifndef _FNET_BT_IBLUETOOTH_OPP_SERVER_EVENT_LISTENER_H_
+#define _FNET_BT_IBLUETOOTH_OPP_SERVER_EVENT_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declaration
+class BluetoothOppServer;
+class BluetoothDevice;
+/**
+ * @interface    IBluetoothOppServerEventListener
+ * @brief        This interface provides a listener for the %BluetoothOppServer events.
+ *
+ * @since        2.0
+ *
+ * The %IBluetoothOppServerEventListener interface specifies the methods used for creating notifications about the
+ * different kinds of BluetoothOppServer events. When a BluetoothOppServer event is generated, one of these methods
+ * is called.
+ * @n
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ IBluetoothOppServerEventListener
+       : public Tizen::Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes
+        * are called when the destructor of this interface is called.
+        *
+        * @since       2.0
+        */
+       virtual ~IBluetoothOppServerEventListener(void) {}
+
+       /**
+        * Called when an incoming push request is received from a remote OPP client.
+        *
+        * @since       2.0
+        *
+        * @param[in]   device          The remote device to request the connection
+        */
+       virtual void OnOppPushRequested(const BluetoothDevice& device) = 0;
+
+       /**
+        * Called when the file is being transferred. @n
+        * Gets the progress information of the file transfer.
+        *
+        * @since       2.0
+        *
+        * @param[in]   percent         The progress in percentage ranging from @c 1 to @c 100 percent
+        * @see         BluetoothOppServer::SetMinProgressInterval()
+        */
+       virtual void OnOppTransferInProgress(int percent) = 0;
+
+       /**
+        * Called when the file transfer has finished.
+        *
+        * @since           2.0
+        *
+        * @param[in]       fileName        The name of the file to transfer
+        * @param[in]       fileSize        The size of the file to transfer
+        * @param[in]       isCompleted     Set to @c true if the transfer is successfully completed, @n
+        *                                  else @c false
+        * @remarks         If the name of the received file already exists in the destination path, the received file is renamed
+        *                  automatically and @c isCompleted is set to @c true. For renaming, the specified postfix is appended to
+        *                  the original file name. The postfix consists of an underscore and three digit sequence numbers starting
+        *                  from 001. For example, "MySong.mp3" may be changed to "MySong_001.mp3".
+        */
+       virtual void OnOppTransferDone(const Tizen::Base::String& fileName, int fileSize, bool isCompleted) = 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 IBluetoothOppServerEventListener_Reserved1(void) {};
+}; // IBluetoothOppServerEventListener
+
+} } }
+#endif // _FNET_BT_IBLUETOOTH_OPP_SERVER_EVENT_LISTENER_H_
diff --git a/inc/FNetBtIBluetoothSppAcceptorEventListener.h b/inc/FNetBtIBluetoothSppAcceptorEventListener.h
new file mode 100755 (executable)
index 0000000..7298a41
--- /dev/null
@@ -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    FNetBtIBluetoothSppAcceptorEventListener.h
+ * @brief   This is the header file for the %IBluetoothSppAcceptorEventListener interface.
+ *
+ * This header file contains the declarations of the %IBluetoothSppAcceptorEventListener interface.
+ */
+#ifndef _FNET_BT_IBLUETOOTH_SPP_ACCEPTOR_EVENT_LISTENER_H_
+#define _FNET_BT_IBLUETOOTH_SPP_ACCEPTOR_EVENT_LISTENER_H_
+
+#include <FBaseByteBuffer.h>
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declaration
+class BluetoothSppAcceptor;
+class BluetoothDevice;
+
+/**
+ * @interface   IBluetoothSppAcceptorEventListener
+ * @brief       This interface provides a listener for the %BluetoothSppAcceptor events.
+ *
+ * @since       2.0
+ *
+ * The %IBluetoothSppAcceptorEventListener interface specifies the methods used for creating notifications about the
+ * different kinds of BluetoothSppAcceptor events. When a BluetoothSppAcceptor event is generated, one of these methods
+ * is called.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ IBluetoothSppAcceptorEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes
+        * are called when the destructor of this interface is called.
+        *
+        * @since       2.0
+        */
+       virtual ~IBluetoothSppAcceptorEventListener(void) {}
+
+       /**
+        * Called to notify an incoming connection request from a remote SPP initiator.
+        *
+        * @since       2.0
+        *
+        * @param[in]   device          The remote device to request the connection
+        * @remarks     If BluetoothSppAcceptor::SendData() is invoked in this callback, it does not work as expected.
+        *              Therefore, it must be invoked outside this callback thread.
+        */
+       virtual void OnSppConnectionRequested(const BluetoothDevice& device) = 0;
+
+       /**
+        * Called to notify that the connection is disconnected.
+        *
+        * @since       2.0
+        *
+        * @param[in]   r               The disconnection status
+        * @exception   E_SUCCESS       The connection is terminated successfully.
+        * @exception   E_SYSTEM        The method has failed to disconnect.
+        */
+       virtual void OnSppDisconnected(result r) = 0;
+
+       /**
+        * Called to notify when the data is received.
+        *
+        * @since       2.0
+        *
+        * @param[in]   buffer          The data to receive as a Tizen::Base::ByteBuffer
+        */
+       virtual void OnSppDataReceived(Tizen::Base::ByteBuffer& buffer) = 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 IBluetoothSppAcceptorEventListener_Reserved1(void) {};
+}; // IBluetoothSppAcceptorEventListener
+
+} } }
+#endif // _FNET_BT_IBLUETOOTH_SPP_ACCEPTOR_EVENT_LISTENER_H_
diff --git a/inc/FNetBtIBluetoothSppInitiatorEventListener.h b/inc/FNetBtIBluetoothSppInitiatorEventListener.h
new file mode 100755 (executable)
index 0000000..f78ce6e
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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    FNetBtIBluetoothSppInitiatorEventListener.h
+ * @brief   This is the header file for the %IBluetoothSppInitiatorEventListener interface.
+ *
+ * This header file contains the declarations of the %IBluetoothSppInitiatorEventListener interface.
+ */
+#ifndef _FNET_BT_IBLUETOOTH_SPP_INITIATOR_EVENT_LISTENER_H_
+#define _FNET_BT_IBLUETOOTH_SPP_INITIATOR_EVENT_LISTENER_H_
+
+#include <FBaseByteBuffer.h>
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+ * @interface   IBluetoothSppInitiatorEventListener
+ * @brief       This interface provides a listener for the %BluetoothSppInitiator events.
+ *
+ * @since       2.0
+ *
+ * The %IBluetoothSppInitiatorEventListener interface specifies the methods used for creating notifications about the
+ * different kinds of BluetoothSppInitiator events. When a BluetoothSppInitiator event is generated, one of these
+ * methods is called.
+ *
+ * For more information on the class features, see
+ * <a href="../org.tizen.native.appprogramming/html/guide/net/bluetooth_namespace.htm">Bluetooth Guide</a>.
+ */
+class _OSP_EXPORT_ IBluetoothSppInitiatorEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes
+        * are called when the destructor of this interface is called.
+        *
+        * @since       2.0
+        */
+       virtual ~IBluetoothSppInitiatorEventListener(void) {}
+
+       /**
+        * Called to notify when an SPP acceptor responds to the connection request.
+        *
+        * @since       2.0
+        *
+        * @param[in]   r               The status of the connection response
+        * @exception   E_SUCCESS       The connection request is accepted by the SPP acceptor and the file transfer has
+        *                              begun.
+        * @exception   E_REJECTED      The connection request is rejected by the SPP acceptor. @n
+        *                              This exception is currently not in use.
+        * @exception   E_TIMEOUT       The connection request has timed out.
+        * @exception   E_SYSTEM        A failure has occurred from the underlying system. @n
+        *                              This failure includes the rejection by the SPP acceptor.
+        */
+       virtual void OnSppConnectionResponded(result r) = 0;
+
+       /**
+        * Called to notify that the connection is disconnected.
+        *
+        * @since       2.0
+        *
+        * @param[in]   r               The disconnection status
+        * @exception   E_SUCCESS       The connection is terminated successfully.
+        * @exception   E_SYSTEM        The method has failed to disconnect.
+        */
+       virtual void OnSppDisconnected(result r) = 0;
+
+       /**
+        * Called to notify when the data has been received.
+        *
+        * @since       2.0
+        *
+        * @param[in]   buffer          The data to receive
+        */
+       virtual void OnSppDataReceived(Tizen::Base::ByteBuffer& buffer) = 0;
+}; // IBluetoothSppInitiatorEventListener
+
+} } }
+#endif // _FNET_BT_IBLUETOOTH_SPP_INITIATOR_EVENT_LISTENER_H_
diff --git a/osp-bluetooth.manifest b/osp-bluetooth.manifest
new file mode 100644 (file)
index 0000000..ae3e6f7
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_"/>
+       </request>
+</manifest>
\ No newline at end of file
diff --git a/osp-bluetooth.pc.in b/osp-bluetooth.pc.in
new file mode 100755 (executable)
index 0000000..eb6c3b7
--- /dev/null
@@ -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-bluetooth.spec b/packaging/osp-bluetooth.spec
new file mode 100755 (executable)
index 0000000..4576329
--- /dev/null
@@ -0,0 +1,91 @@
+%define debug_package %{nil}
+%define __strip /bin/true
+
+Name:          osp-bluetooth
+Summary:       osp bluetooth library
+Version:       1.2.1.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-bluetooth)
+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 bluetooth library
+
+%package devel
+Summary:    osp bluetooth library (Development)
+Group:      TO_BE/FILLED_IN
+Requires:   %{name} = %{version}-%{release}
+
+%description devel
+osp bluetooth library (DEV)
+
+%package internal-devel
+Summary:    osp bluetooth library (Internal)
+Group:      TO_BE/FILLED_IN
+Requires:   %{name} = %{version}-%{release}
+
+%description internal-devel
+osp bluetooth library (Internal-DEV)
+
+%package debug
+Summary:    osp bluetooth library (Development)
+Group:      TO_BE/FILLED_IN
+Requires:   %{name} = %{version}-%{release}
+
+%description debug
+osp bluetooth 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.APLv2.0  %{buildroot}/usr/share/license/%{name}
+
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest osp-bluetooth.manifest
+/usr/share/license/%{name}
+%{_libdir}/osp/*.so*
+
+%files devel
+%{_includedir}/osp/*.h
+%{_libdir}/pkgconfig/osp-bluetooth.pc
+
+%files internal-devel
+%{_includedir}/osp/net/*.h
+
+%files debug
+%{_libdir}/osp/debug/*.so*
diff --git a/src/FNetBtBluetoothDevice.cpp b/src/FNetBtBluetoothDevice.cpp
new file mode 100755 (executable)
index 0000000..3221c7b
--- /dev/null
@@ -0,0 +1,469 @@
+//
+// 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    FNetBtBluetoothDevice.cpp
+// @brief   This is the implementation file for the BluetoothDevice class.
+//
+
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FAppAppControl.h>
+#include <FBaseColIList.h>
+#include <FBaseLong.h>
+#include <FBaseShort.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothDeviceImpl.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// The serial port profile UUID. (00001101-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_SPP[] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The LAN access profile UUID. (00001102-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_LAP[] = {0x00, 0x00, 0x11, 0x02, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The dial-up networking profile UUID. (00001103-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_DUN[] = {0x00, 0x00, 0x11, 0x03, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The synchronization profile UUID. (00001104-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_SYNC[] = {0x00, 0x00, 0x11, 0x04, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The object push profile UUID. (00001105-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_OPP[] = {0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The file transfer profile UUID. (00001106-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_FTP[] = {0x00, 0x00, 0x11, 0x06, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The synchronization profile UUID. (00001107-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_SYNC_COMMAND[] = {0x00, 0x00, 0x11, 0x07, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The headset profile UUID. (00001108-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HSP[] = {0x00, 0x00, 0x11, 0x08, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The cordless telephony profile UUID. (00001109-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_CTP[] = {0x00, 0x00, 0x11, 0x09, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The advanced audio distribution profile - source UUID. (0000110A-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_A2DP_SOURCE[] = {0x00, 0x00, 0x11, 0x0A, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The advanced audio distribution profile - sink UUID. (0000110B-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_A2DP_SINK[] = {0x00, 0x00, 0x11, 0x0B, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The audio/video remote control profile - target UUID. (0000110C-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_AVRCP_TARGET[] = {0x00, 0x00, 0x11, 0x0C, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The advanced audio distribution profile UUID. (0000110D-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_A2DP[] = {0x00, 0x00, 0x11, 0x0D, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The audio/video remote control profile UUID. (0000110E-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_AVRCP[] = {0x00, 0x00, 0x11, 0x0E, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The audio/video remote control profile - controller UUID. (0000110F-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_AVRCP_CONTROLLER[] = {0x00, 0x00, 0x11, 0x0F, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The intercom profile UUID. (00001110-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_ICP[] = {0x00, 0x00, 0x11, 0x10, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The fax profile UUID. (00001111-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_FAX[] = {0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The headset profile - audio gateway UUID. (00001112-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HSP_AG[] = {0x00, 0x00, 0x11, 0x12, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The personal area networking profile - user UUID. (00001115-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_PAN_PANU[] = {0x00, 0x00, 0x11, 0x15, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The personal area networking profile - network access point UUID. (00001116-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_PAN_NAP[] = {0x00, 0x00, 0x11, 0x16, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The personal area networking profile - group ad-hoc networks UUID. (00001117-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_PAN_GN[] = {0x00, 0x00, 0x11, 0x17, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic printing profile - direct printing UUID. (00001118-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BPP_DIRECT_PRINTING[] = {0x00, 0x00, 0x11, 0x18, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic printing profile - reference printing UUID. (00001119-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BPP_REFERENCE_PRINTING[] = {0x00, 0x00, 0x11, 0x19, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic imaging profile UUID. (0000111A-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BIP[] = {0x00, 0x00, 0x11, 0x1A, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic imaging profile - imaging responder UUID. (0000111B-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BIP_RESPONDER[] = {0x00, 0x00, 0x11, 0x1B, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic imaging profile - imaging automatic archive UUID. (0000111C-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BIP_AUTOMATIC_ARCHIVE[] = {0x00, 0x00, 0x11, 0x1C, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic imaging profile - imaging referenced objects UUID. (0000111D-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BIP_REFERENCED_OBJECTS[] = {0x00, 0x00, 0x11, 0x1D, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The hands-free profile UUID. (0000111E-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HFP[] = {0x00, 0x00, 0x11, 0x1E, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The hands-free profile - audio gateway UUID. (0000111F-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HFP_AG[] = {0x00, 0x00, 0x11, 0x1F, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic printing profile - direct printing referenced objects UUID. (00001120-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BPP_DIRECT_PRINTING_RO[] = {0x00, 0x00, 0x11, 0x20, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic printing profile - reflected UI UUID. (00001121-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BPP_REFLECTED_UI[] = {0x00, 0x00, 0x11, 0x21, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic printing profile - basic printing UUID. (00001122-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BPP_BASIC_PRINTING[] = {0x00, 0x00, 0x11, 0x22, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The basic printing profile - printing status UUID. (00001123-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_BPP_PRINTING_STATUS[] = {0x00, 0x00, 0x11, 0x23, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The human interface device profile UUID. (00001124-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HID[] = {0x00, 0x00, 0x11, 0x24, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The hardcopy cable replacement profile UUID. (00001125-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HCRP[] = {0x00, 0x00, 0x11, 0x25, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The hardcopy cable replacement profile - print UUID. (00001126-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HCRP_PRINT[] = {0x00, 0x00, 0x11, 0x26, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The hardcopy cable replacement profile - scan UUID. (00001127-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HCRP_SCAN[] = {0x00, 0x00, 0x11, 0x27, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The SIM access profile UUID. (0000112D-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_SAP[] = {0x00, 0x00, 0x11, 0x2D, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The phone book access - client equipment UUID. (0000112E-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_PBAP_PCE[] = {0x00, 0x00, 0x11, 0x2E, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The phone book access - server equipment UUID. (0000112F-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_PBAP_PSE[] = {0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The phone book access UUID. (00001130-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_PBAP[] = {0x00, 0x00, 0x11, 0x30, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The headset profile - headset UUID. (00001131-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HSP_HS[] = {0x00, 0x00, 0x11, 0x31, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The message access profile - message access server UUID. (00001132-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_MAP_ACCESS_SERVER[] = {0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The message access profile - message notification server UUID. (00001133-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_MAP_NOTIFICATION_SERVER[] = {0x00, 0x00, 0x11, 0x33, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The message access profile - message access profile UUID. (00001134-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_MAP_ACCESS_PROFILE[] = {0x00, 0x00, 0x11, 0x34, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The device identification profile - PNP information UUID. (00001200-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_DID_PNP_INFORMATION[] = {0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The generic networking UUID. (00001201-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_GENERIC_NETWORKING[] = {0x00, 0x00, 0x12, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The generic file transfer UUID. (00001202-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_GENERIC_FILE_TRANSFER[] = {0x00, 0x00, 0x12, 0x02, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The generic audio UUID. (00001203-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_GENERIC_AUDIO[] = {0x00, 0x00, 0x12, 0x03, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The generic telephony UUID. (00001204-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_GENERIC_TELEPHONY[] = {0x00, 0x00, 0x12, 0x04, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The video distribution profile - source UUID. (00001303-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_VDP_SOURCE[] = {0x00, 0x00, 0x13, 0x03, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The video distribution profile - sink UUID. (00001304-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_VDP_SINK[] = {0x00, 0x00, 0x13, 0x04, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The video distribution profile - distribution UUID. (00001305-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_VDP_DISTRIBUTION[] = {0x00, 0x00, 0x13, 0x05, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The health device profile UUID. (00001400-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HDP[] = {0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The health device profile - source UUID. (00001401-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HDP_SOURCE[] = {0x00, 0x00, 0x14, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+// The health device profile - sink UUID. (00001402-0000-1000-8000-00805F9B34FB)
+const byte BT_SVC_UUID_HDP_SINK[] = {0x00, 0x00, 0x14, 0x02, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
+
+
+BluetoothDevice::BluetoothDevice(void)
+       : __pImpl(null)
+{
+       __pImpl = new (std::nothrow) _BluetoothDeviceImpl();
+       SysTryReturnVoidResult(NID_NET_BT, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+}
+
+BluetoothDevice::BluetoothDevice(const Tizen::Base::ByteBuffer& address, const Base::String& deviceName, BluetoothMajorDeviceClassType majorClassType, BluetoothMinorDeviceClassType minorClassType, unsigned long serviceClassList, unsigned long serviceList)
+       : __pImpl(null)
+{
+       __pImpl = new (std::nothrow) _BluetoothDeviceImpl(address, deviceName, majorClassType, minorClassType, serviceClassList, serviceList);
+       SysTryReturnVoidResult(NID_NET_BT, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+}
+
+BluetoothDevice::BluetoothDevice(const BluetoothDevice& value)
+       : __pImpl(null)
+{
+       __pImpl = new (std::nothrow) _BluetoothDeviceImpl(*value.__pImpl);
+       SysTryReturnVoidResult(NID_NET_BT, __pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+}
+
+BluetoothDevice::~BluetoothDevice(void)
+{
+       delete __pImpl;
+}
+
+BluetoothDevice&
+BluetoothDevice::operator =(const BluetoothDevice& rhs)
+{
+    if (this != &rhs)
+    {
+       *__pImpl = *rhs.__pImpl;
+    }
+
+       return *this;
+}
+
+const Tizen::Base::ByteBuffer*
+BluetoothDevice::GetAddress(void) const
+{
+       return __pImpl->GetAddress();
+}
+
+result
+BluetoothDevice::SetAddress(const Tizen::Base::ByteBuffer& address)
+{
+       return __pImpl->SetAddress(address);
+}
+
+String
+BluetoothDevice::GetName(void) const
+{
+       return __pImpl->GetName();
+}
+
+bool
+BluetoothDevice::IsPaired(void) const
+{
+       return __pImpl->IsPaired();
+}
+
+int
+BluetoothDevice::GetRssi(void) const
+{
+       return __pImpl->GetRssi();
+}
+
+BluetoothMajorDeviceClassType
+BluetoothDevice::GetMajorDeviceClassType(void) const
+{
+       return __pImpl->GetMajorDeviceClassType();
+}
+
+BluetoothMinorDeviceClassType
+BluetoothDevice::GetMinorDeviceClassType(void) const
+{
+       return __pImpl->GetMinorDeviceClassType();
+}
+
+unsigned long
+BluetoothDevice::GetServiceClassList(void) const
+{
+       return __pImpl->GetServiceClassList();
+}
+
+unsigned long
+BluetoothDevice::GetServiceList(void) const
+{
+       return __pImpl->GetServiceList();
+}
+
+const Tizen::Base::Collection::IList*
+BluetoothDevice::GetServiceUuidList(void) const
+{
+       return __pImpl->GetServiceUuidList();
+}
+
+bool
+BluetoothDevice::Equals(const Tizen::Base::Object& obj) const
+{
+       const BluetoothDevice* pOther = dynamic_cast <const BluetoothDevice*>(&obj);
+
+       if (pOther == null)
+       {
+               return false;
+       }
+
+       if (pOther == this)
+       {
+               return true;
+       }
+
+       return(__pImpl->Equals(*(pOther->__pImpl)));
+}
+
+int
+BluetoothDevice::GetHashCode(void) const
+{
+       return __pImpl->GetHashCode();
+}
+
+BluetoothDevice*
+BluetoothDevice::GetInstanceFromAppControlResultN(const Tizen::Base::Collection::IList& appControlResult)
+{
+       BluetoothDevice* pNewBtDevice = null;
+       String* pResultStrPtr = null;
+       String keywordStr;
+       String dataStr;
+       ByteBuffer btAddrBytes;
+       String deviceName;
+       long majClassType = 0;
+       long minClassType = 0;
+       long svcClassType = 0;
+       long svcType = 0;
+
+       ClearLastResult();
+
+       if (appControlResult.GetCount() != 7)
+       {
+               goto CATCH;
+       }
+
+       pResultStrPtr = (String*) appControlResult.GetAt(0);
+       if (pResultStrPtr->Equals(String(Tizen::App::APPCONTROL_RESULT_SUCCEEDED)) == false)
+       {
+               goto CATCH;
+       }
+
+       // Gets the address from index 1 as a String. E.g. 00-1E-2B-72-08-DB
+       pResultStrPtr = (String*) appControlResult.GetAt(1);
+       if ((pResultStrPtr->SubString(0, 9, keywordStr) != E_SUCCESS) ||
+               (keywordStr.Equals(String("addr_val:")) == false) ||
+               (pResultStrPtr->SubString(9, dataStr) != E_SUCCESS))
+       {
+               goto CATCH;
+       }
+
+       // Convert the type of the address to ByteBuffer
+       btAddrBytes.Construct(6);
+       if (_BluetoothDeviceImpl::GetAddressByteBuffer(dataStr, L"-", btAddrBytes) != E_SUCCESS)
+       {
+               goto CATCH;
+       }
+
+       keywordStr.Clear();
+       dataStr.Clear();
+
+       // Gets the name from index 2
+       pResultStrPtr = (String*) appControlResult.GetAt(2);
+       if ((pResultStrPtr->SubString(0, 9, keywordStr) != E_SUCCESS) ||
+               (keywordStr.Equals(String("dev_name:")) == false) ||
+               (pResultStrPtr->SubString(9, deviceName) != E_SUCCESS))
+       {
+               goto CATCH;
+       }
+
+       keywordStr.Clear();
+
+       // Gets the major device class from index 3
+       pResultStrPtr = (String*) appControlResult.GetAt(3);
+       if ((pResultStrPtr->SubString(0, 13, keywordStr) != E_SUCCESS) ||
+               (keywordStr.Equals(String("maj_cls_type:")) == false) ||
+               (pResultStrPtr->SubString(13, dataStr) != E_SUCCESS))
+       {
+               goto CATCH;
+       }
+
+       if (Long::Decode(dataStr, majClassType) != E_SUCCESS)
+       {
+               goto CATCH;
+       }
+
+       keywordStr.Clear();
+       dataStr.Clear();
+
+       // Gets the minor device class from index 4
+       pResultStrPtr = (String*) appControlResult.GetAt(4);
+       if ((pResultStrPtr->SubString(0, 13, keywordStr) != E_SUCCESS) ||
+               (keywordStr.Equals(String("min_cls_type:")) == false) ||
+               (pResultStrPtr->SubString(13, dataStr) != E_SUCCESS))
+       {
+               goto CATCH;
+       }
+
+       if (Long::Decode(dataStr, minClassType) != E_SUCCESS)
+       {
+               goto CATCH;
+       }
+
+       keywordStr.Clear();
+       dataStr.Clear();
+
+       // Gets the service classes as a bit-mask from index 5
+       pResultStrPtr = (String*) appControlResult.GetAt(5);
+       if ((pResultStrPtr->SubString(0, 13, keywordStr) != E_SUCCESS) ||
+               (keywordStr.Equals(String("svc_cls_type:")) == false) ||
+               (pResultStrPtr->SubString(13, dataStr) != E_SUCCESS))
+       {
+               goto CATCH;
+       }
+
+       if (Long::Decode(dataStr, svcClassType) != E_SUCCESS)
+       {
+               goto CATCH;
+       }
+
+       keywordStr.Clear();
+       dataStr.Clear();
+
+       // Gets the service types as a bit-mask from index 6
+       pResultStrPtr = (String*) appControlResult.GetAt(6);
+       if ((pResultStrPtr->SubString(0, 9, keywordStr) != E_SUCCESS) ||
+               (keywordStr.Equals(String("svc_type:")) == false) ||
+               (pResultStrPtr->SubString(9, dataStr) != E_SUCCESS))
+       {
+               goto CATCH;
+       }
+
+       if (Long::Decode(dataStr, svcType) != E_SUCCESS)
+       {
+               goto CATCH;
+       }
+
+       // Create an instance of BluetoothDevice.
+       pNewBtDevice =
+               new (std::nothrow) BluetoothDevice(btAddrBytes, deviceName, (BluetoothMajorDeviceClassType) majClassType,
+                                                       (BluetoothMinorDeviceClassType) minClassType, svcClassType,
+                                                       svcType);
+       if (pNewBtDevice == null)
+       {
+               SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] exception occurred on creating BluetoothDevice.");
+               SetLastResult(E_OUT_OF_MEMORY);
+       }
+
+       return pNewBtDevice;
+
+CATCH:
+
+       SysLogException(NID_NET_BT, E_INVALID_ARG, "[E_INVALID_ARG] exception occurred on parsing input data.");
+       SetLastResult(E_INVALID_ARG);
+
+       return null;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBtBluetoothHealth.cpp b/src/FNetBtBluetoothHealth.cpp
new file mode 100644 (file)
index 0000000..24fa8e8
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// 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    FNetBtBluetoothHealth.cpp
+// @brief   This is the implementation file for the BluetoothHealth class.
+//
+
+#include <FNetBtBluetoothHealth.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothHealthEventListener.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseSysLog.h>
+#include <FSec_AccessController.h>
+#include <FSys_SystemInfoImpl.h>
+#include "FNetBt_BluetoothHealthImpl.h"
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+BluetoothHealth::BluetoothHealth(void)
+       : __pImpl(null)
+{
+}
+
+BluetoothHealth::~BluetoothHealth(void)
+{
+       delete __pImpl;
+}
+
+result
+BluetoothHealth::Construct(IBluetoothHealthEventListener& listener)
+{
+       result r = E_SUCCESS;
+       bool isBtSupported = false;
+
+       Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
+       SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth 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) _BluetoothHealthImpl;
+       SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a _BluetoothHealthImpl instance failed.");
+
+       r = __pImpl->Construct(listener);
+
+       if (r != E_SUCCESS)
+       {
+               delete __pImpl;
+               __pImpl = null;
+       }
+
+       return r;
+}
+
+result
+BluetoothHealth::StartAsSink(int dataType)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_HEALTH);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->StartAsSink(dataType);
+}
+
+result
+BluetoothHealth::Stop(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_HEALTH);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->Stop();
+}
+
+result
+BluetoothHealth::ConnectToSource(const BluetoothDevice& remoteDevice)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_HEALTH);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->ConnectToSource(remoteDevice);
+}
+
+result
+BluetoothHealth::Disconnect(int channelId)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_HEALTH);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->Disconnect(channelId);
+}
+
+result
+BluetoothHealth::SendData(int channelId, const Tizen::Base::ByteBuffer& buffer)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_HEALTH);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->SendData(channelId, buffer);
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBtBluetoothManager.cpp b/src/FNetBtBluetoothManager.cpp
new file mode 100644 (file)
index 0000000..e0bffbd
--- /dev/null
@@ -0,0 +1,371 @@
+//
+// 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    FNetBtBluetoothManager.cpp
+// @brief   This is the implementation file for the BluetoothManager class.
+//
+
+#include <FNetBtBluetoothManager.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothManagerEventListener.h>
+#include <FNetBtIBluetoothDeviceEventListener.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseColIList.h>
+#include <FBaseSysLog.h>
+#include <FSec_AccessController.h>
+#include <FSys_SystemInfoImpl.h>
+#include "FNetBt_BluetoothManagerImpl.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+BluetoothManager::BluetoothManager(void)
+       : __pImpl(null)
+{
+}
+
+BluetoothManager::~BluetoothManager(void)
+{
+       delete __pImpl;
+}
+
+result
+BluetoothManager::Construct(IBluetoothManagerEventListener& listener)
+{
+       result r = E_SUCCESS;
+       bool isBtSupported = false;
+
+       r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
+       SysTryReturnResult(NID_NET_BT, (r == E_SUCCESS) && (isBtSupported == true), E_UNSUPPORTED_OPERATION,
+                       "Bluetooth 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) _BluetoothManagerImpl;
+
+       SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a __pImpl instance failed.");
+
+       r = __pImpl->Construct(listener);
+
+       if (r != E_SUCCESS)
+       {
+               delete __pImpl;
+               __pImpl = null;
+       }
+
+       return r;
+}
+
+result
+BluetoothManager::Activate(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_ADMIN);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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
+BluetoothManager::Deactivate(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_ADMIN);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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
+BluetoothManager::IsAvailable(BluetoothConnectionType type) const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->IsAvailable(type);
+}
+
+const BluetoothDevice*
+BluetoothManager::GetLocalDevice(void) const
+{
+       ClearLastResult();
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetLocalDevice();
+}
+
+Tizen::Base::String
+BluetoothManager::GetLocalDeviceAddress(void) const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetLocalDeviceAddress();
+}
+
+Tizen::Base::String
+BluetoothManager::GetLocalDeviceName(void) const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetLocalDeviceName();
+}
+
+BluetoothDeviceStateType
+BluetoothManager::GetLocalDeviceState() const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetLocalDeviceState();
+}
+
+bool
+BluetoothManager::IsActivated(void) const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->IsActivated();
+}
+
+BluetoothDiscoverableMode
+BluetoothManager::GetDiscoverableMode(void) const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetDiscoverableMode();
+}
+
+int
+BluetoothManager::GetRemainingTimeAsDiscoverable(void) const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetRemainingTimeAsDiscoverable();
+}
+
+bool
+BluetoothManager::IsDiscoveryInProgress(void) const
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->IsDiscoveryInProgress();
+}
+
+result
+BluetoothManager::SetLocalDeviceName(const Tizen::Base::String& deviceName)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_ADMIN);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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->SetLocalDeviceName(deviceName);
+}
+
+result
+BluetoothManager::SetDiscoverableMode(BluetoothDiscoverableMode mode, int seconds)
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       // Privilege check will be done by Impl class
+       return __pImpl->SetDiscoverableMode(mode, seconds);
+}
+
+result
+BluetoothManager::RefreshPairedDeviceList(void)
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->RefreshPairedDeviceList();
+}
+
+const BluetoothDevice*
+BluetoothManager::GetPairedDeviceByAddress(const Tizen::Base::ByteBuffer& deviceAddress) const
+{
+       ClearLastResult();
+
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetPairedDeviceByAddress(deviceAddress);
+}
+
+BluetoothDevice*
+BluetoothManager::GetPairedDeviceByAddressN(const Tizen::Base::ByteBuffer& deviceAddress) const
+{
+       ClearLastResult();
+
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetPairedDeviceByAddressN(deviceAddress);
+}
+
+Tizen::Base::Collection::IList*
+BluetoothManager::GetPairedDeviceByNameN(const Base::String& deviceName) const
+{
+       ClearLastResult();
+
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetPairedDeviceByNameN(deviceName);
+}
+
+const BluetoothDevice*
+BluetoothManager::GetPairedDeviceAt(int index) const
+{
+       ClearLastResult();
+
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetPairedDeviceAt(index);
+}
+
+const Tizen::Base::Collection::IList*
+BluetoothManager::GetPairedDeviceList(void) const
+{
+       ClearLastResult();
+
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetPairedDeviceList();
+}
+
+Tizen::Base::Collection::IList*
+BluetoothManager::GetPairedDeviceListN(void) const
+{
+       ClearLastResult();
+
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->GetPairedDeviceListN();
+}
+
+result
+BluetoothManager::SetBluetoothDeviceListener(IBluetoothDeviceEventListener* pListener)
+{
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->SetBluetoothDeviceListener(pListener);
+}
+
+result
+BluetoothManager::StartDiscovery(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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->StartDiscovery();
+}
+
+result
+BluetoothManager::CancelDiscovery(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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->CancelDiscovery();
+}
+
+result
+BluetoothManager::RetrieveServiceList(const BluetoothDevice& pairedDevice)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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->RetrieveServiceList(pairedDevice);
+}
+
+result
+BluetoothManager::Pair(const BluetoothDevice& remoteDevice)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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->Pair(remoteDevice);
+}
+
+result
+BluetoothManager::CancelPair(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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->CancelPair();
+}
+
+result
+BluetoothManager::Unpair(const BluetoothDevice& pairedDevice)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "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->Unpair(pairedDevice);
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBtBluetoothOppClient.cpp b/src/FNetBtBluetoothOppClient.cpp
new file mode 100644 (file)
index 0000000..bd33dc0
--- /dev/null
@@ -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    FNetBtBluetoothOppClient.cpp
+// @brief   This is the implementation file for the BluetoothOppClient class.
+//
+
+#include <FNetBtBluetoothOppClient.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothOppClientEventListener.h>
+#include <FBaseString.h>
+#include <FBaseSysLog.h>
+#include <FSec_AccessController.h>
+#include <FSys_SystemInfoImpl.h>
+#include "FNetBt_BluetoothOppClientImpl.h"
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+BluetoothOppClient::BluetoothOppClient(void)
+       : __pImpl(null)
+{
+}
+
+BluetoothOppClient::~BluetoothOppClient(void)
+{
+       delete __pImpl;
+}
+
+result
+BluetoothOppClient::Construct(IBluetoothOppClientEventListener& listener)
+{
+       result r = E_SUCCESS;
+       bool isBtSupported = false;
+
+       Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
+       SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth 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) _BluetoothOppClientImpl;
+
+       SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a _BluetoothOppClientImpl instance failed.");
+
+       r = __pImpl->Construct(listener);
+
+       if (r != E_SUCCESS)
+       {
+               delete __pImpl;
+               __pImpl = null;
+       }
+
+       return r;
+}
+
+
+result
+BluetoothOppClient::PushFile(const BluetoothDevice& remoteDevice, const Base::String& filePath)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->PushFile(remoteDevice, filePath);
+}
+
+result
+BluetoothOppClient::CancelPush(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->CancelPush();
+}
+
+result
+BluetoothOppClient::SetMinProgressInterval(int percent)
+{
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->SetMinProgressInterval(percent);
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBtBluetoothOppServer.cpp b/src/FNetBtBluetoothOppServer.cpp
new file mode 100644 (file)
index 0000000..6408760
--- /dev/null
@@ -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    FNetBtBluetoothOppServer.cpp
+// @brief   This is the implementation file for the BluetoothOppServer class.
+//
+
+#include <FBaseString.h>
+#include <FNetBtBluetoothOppServer.h>
+#include <FNetBtIBluetoothOppServerEventListener.h>
+#include <FBaseSysLog.h>
+#include <FSec_AccessController.h>
+#include <FSys_SystemInfoImpl.h>
+#include "FNetBt_BluetoothOppServerImpl.h"
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+BluetoothOppServer::BluetoothOppServer(void)
+       : __pImpl(null)
+{
+}
+
+BluetoothOppServer::~BluetoothOppServer(void)
+{
+       delete __pImpl;
+}
+
+result
+BluetoothOppServer::Construct(IBluetoothOppServerEventListener& listener)
+{
+       result r = E_SUCCESS;
+       bool isBtSupported = false;
+
+       Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
+       SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth 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) _BluetoothOppServerImpl;
+       SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a _BluetoothOppServerImpl instance failed.");
+
+       r = __pImpl->Construct(listener);
+
+       if (r != E_SUCCESS)
+       {
+               delete __pImpl;
+               __pImpl = null;
+       }
+
+       return r;
+}
+
+result
+BluetoothOppServer::AcceptPush(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->AcceptPush();
+}
+
+result
+BluetoothOppServer::RejectPush(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->RejectPush();
+}
+
+result
+BluetoothOppServer::SetDestinationPath(const Tizen::Base::String& dstPath)
+{
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->SetDestinationPath(dstPath);
+}
+
+result
+BluetoothOppServer::SetMinProgressInterval(int percent)
+{
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->SetMinProgressInterval(percent);
+}
+
+result
+BluetoothOppServer::StartService(const Tizen::Base::String& dstPath)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->StartService(dstPath);
+}
+
+result
+BluetoothOppServer::StopService(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->StopService();
+}
+
+result
+BluetoothOppServer::StopTransfer(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
+                       "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->StopTransfer();
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBtBluetoothSppAcceptor.cpp b/src/FNetBtBluetoothSppAcceptor.cpp
new file mode 100644 (file)
index 0000000..658c6ca
--- /dev/null
@@ -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    FNetBtBluetoothSppAcceptor.cpp
+// @brief   This is the implementation file for the BluetoothSppAcceptor class.
+//
+
+#include <FNetBtBluetoothSppAcceptor.h>
+#include <FNetBtIBluetoothSppAcceptorEventListener.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseUuId.h>
+#include <FBaseSysLog.h>
+#include <FSec_AccessController.h>
+#include <FSys_SystemInfoImpl.h>
+#include "FNetBt_BluetoothSppAcceptorImpl.h"
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+BluetoothSppAcceptor::BluetoothSppAcceptor(void)
+       : __pImpl(null)
+{
+}
+
+BluetoothSppAcceptor::~BluetoothSppAcceptor(void)
+{
+       delete __pImpl;
+}
+
+result
+BluetoothSppAcceptor::Construct(IBluetoothSppAcceptorEventListener& listener)
+{
+       result r = E_SUCCESS;
+       bool isBtSupported = false;
+
+       Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
+       SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth 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) _BluetoothSppAcceptorImpl;
+       SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a _BluetoothSppAcceptorImpl instance failed.");
+
+       r = __pImpl->Construct(listener);
+
+       if (r != E_SUCCESS)
+       {
+               delete __pImpl;
+               __pImpl = null;
+       }
+
+       return r;
+}
+
+result
+BluetoothSppAcceptor::AcceptConnection(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->AcceptConnection();
+}
+
+result
+BluetoothSppAcceptor::RejectConnection()
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->RejectConnection();
+}
+
+result
+BluetoothSppAcceptor::StartService(void)
+{
+       // Actually, E_INVALID_ARG never occur because the fixed SPP UUID is used.
+       return StartService(Tizen::Base::UuId(BT_SVC_UUID_SPP));
+}
+
+result
+BluetoothSppAcceptor::StartService(const Tizen::Base::UuId& serviceUuid)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->StartService(serviceUuid);
+}
+
+result
+BluetoothSppAcceptor::StopService(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->StopService();
+}
+
+result
+BluetoothSppAcceptor::SendData(const Tizen::Base::ByteBuffer& buffer)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->SendData(buffer);
+}
+
+result
+BluetoothSppAcceptor::Disconnect(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->Disconnect();
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBtBluetoothSppInitiator.cpp b/src/FNetBtBluetoothSppInitiator.cpp
new file mode 100644 (file)
index 0000000..ecdf810
--- /dev/null
@@ -0,0 +1,125 @@
+//
+// 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    FNetBtBluetoothSppInitiator.cpp
+// @brief   This is the implementation file for the BluetoothSppInitiator class.
+//
+
+#include <FNetBtBluetoothSppInitiator.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothSppInitiatorEventListener.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseUuId.h>
+#include <FBaseSysLog.h>
+#include <FSec_AccessController.h>
+#include <FSys_SystemInfoImpl.h>
+#include "FNetBt_BluetoothSppInitiatorImpl.h"
+
+using namespace Tizen::Security;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+BluetoothSppInitiator::BluetoothSppInitiator(void)
+       : __pImpl(null)
+{
+}
+
+BluetoothSppInitiator::~BluetoothSppInitiator(void)
+{
+       delete __pImpl;
+}
+
+result
+BluetoothSppInitiator::Construct(IBluetoothSppInitiatorEventListener& listener)
+{
+       result r = E_SUCCESS;
+       bool isBtSupported = false;
+
+       Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
+       SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth 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) _BluetoothSppInitiatorImpl;
+       SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY,
+                       "Creation of a _BluetoothSppInitiatorImpl instance failed.");
+
+       r = __pImpl->Construct(listener);
+
+       if (r != E_SUCCESS)
+       {
+               delete __pImpl;
+               __pImpl = null;
+       }
+
+       return r;
+}
+
+result
+BluetoothSppInitiator::SendData(const Tizen::Base::ByteBuffer& buffer)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->SendData(buffer);
+}
+
+result
+BluetoothSppInitiator::Connect(const BluetoothDevice& remoteDevice)
+{
+       // Actually, E_INVALID_ARG never occur because the fixed SPP UUID is used.
+       return Connect(remoteDevice, Tizen::Base::UuId(BT_SVC_UUID_SPP));
+}
+
+result
+BluetoothSppInitiator::Connect(const BluetoothDevice& remoteDevice, const Tizen::Base::UuId& serviceUuid)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->Connect(remoteDevice, serviceUuid);
+}
+
+result
+BluetoothSppInitiator::Disconnect(void)
+{
+       result r = E_SUCCESS;
+
+       // Privilege check
+       r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_SPP);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       // Check Construct
+       SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
+
+       return __pImpl->Disconnect();
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothAdapterUtility.cpp b/src/FNetBt_BluetoothAdapterUtility.cpp
new file mode 100755 (executable)
index 0000000..6a0f958
--- /dev/null
@@ -0,0 +1,911 @@
+//
+// 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        FNetBt_BluetoothAdapterUtility.cpp
+// @brief       This is the implementation file for the _BluetoothAdapterUtility class.
+//
+
+#include <unique_ptr.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseUuId.h>
+#include <FBaseInteger.h>
+#include <FBaseSysLog.h>
+#include <FBaseLong.h>
+#include <FBaseColHashMap.h>
+#include <FBaseUtilStringUtil.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FBase_StringConverter.h>
+#include <FNetBt_BluetoothDeviceImpl.h>
+#include "FNetBt_BluetoothAdapterUtility.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+class _BluetoothUuidMap;
+
+static _BluetoothUuidMap* pMapSingleton = null;
+
+/*
+ * @class              _BluetoothUuidMap
+ * @brief              The _BluetoothUuidMap class provides the method which converts UUID string to the long type value of
+ *              BluetoothServiceType defined "FNetBtBluetoothTypes.h".
+ */
+class _BluetoothUuidMap
+       : public Tizen::Base::Object
+{
+public:
+       _BluetoothUuidMap(void) {}
+
+       virtual ~_BluetoothUuidMap(void)
+       {
+               //Clear all entries in the map
+               (void) __uuidMap.RemoveAll(true);
+       }
+
+       static _BluetoothUuidMap* GetInstance(void)
+       {
+               static _BluetoothUuidMap uuidMap;
+
+               // TODO: this singleton pattern to use a local static instance is not thread-safe.
+               if (!pMapSingleton)
+               {
+                       if (uuidMap.Initialise() == E_SUCCESS)
+                       {
+                               pMapSingleton = &uuidMap;
+                       }
+               }
+
+               return pMapSingleton;
+       }
+
+       long GetUuidLong(const Tizen::Base::String& uuidString) const
+       {
+               UuId uuid;
+               UuId::Parse(uuidString, uuid);
+               const Long* pUuidLongValue = null;
+
+               pUuidLongValue = dynamic_cast<const Long*> (__uuidMap.GetValue(uuid));
+               SysTryReturn(NID_NET_BT, pUuidLongValue != null, 0, E_SYSTEM,
+                               "Getting UUID(%ls) value from <UUID string, UUID enum type> map has failed.", uuidString.GetPointer());
+
+               return pUuidLongValue->ToLong();
+       }
+
+private:
+       _BluetoothUuidMap(const _BluetoothUuidMap& value);
+       _BluetoothUuidMap& operator =(const _BluetoothUuidMap& value);
+
+       result Initialise(void)
+       {
+               result r = E_SUCCESS;
+
+               r = __uuidMap.Construct();
+               SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Construction of <UUID string, UUID enum type> map has failed.");
+
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SPP)), *(new Long((long)(BT_SVC_SPP_SERVICE))));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_LAP)), *(new Long((long) BT_SVC_LAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_DUN)), *(new Long((long) BT_SVC_DUN_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SYNC)), *(new Long((long) BT_SVC_SYNC_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_OPP)), *(new Long((long) BT_SVC_OPP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_FTP)), *(new Long((long) BT_SVC_FTP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SYNC_COMMAND)), *(new Long((long) BT_SVC_SYNC_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HSP)), *(new Long((long) BT_SVC_HSP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_CTP)), *(new Long((long) BT_SVC_CTP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_A2DP_SOURCE)), *(new Long((long) BT_SVC_A2DP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_A2DP_SINK)), *(new Long((long) BT_SVC_A2DP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_AVRCP_TARGET)), *(new Long((long) BT_SVC_AVRCP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_A2DP)), *(new Long((long) BT_SVC_A2DP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_AVRCP)), *(new Long((long) BT_SVC_AVRCP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_AVRCP_CONTROLLER)), *(new Long((long) BT_SVC_AVRCP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_ICP)), *(new Long((long) BT_SVC_ICP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_FAX)), *(new Long((long) BT_SVC_FAX_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HSP_AG)), *(new Long((long) BT_SVC_HSP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PAN_PANU)), *(new Long((long) BT_SVC_PANU_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PAN_NAP)), *(new Long((long) BT_SVC_NAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PAN_GN)), *(new Long((long) BT_SVC_GN_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_DIRECT_PRINTING)), *(new Long((long) BT_SVC_BPP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_REFERENCE_PRINTING)), *(new Long((long) BT_SVC_BPP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP)), *(new Long((long) BT_SVC_BIP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP_RESPONDER)), *(new Long((long) BT_SVC_BIP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP_AUTOMATIC_ARCHIVE)), *(new Long((long) BT_SVC_BIP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP_REFERENCED_OBJECTS)), *(new Long((long) BT_SVC_BIP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HFP)), *(new Long((long) BT_SVC_HFP_HS_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HFP_AG)), *(new Long((long) BT_SVC_HFP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_DIRECT_PRINTING_RO)), *(new Long((long) BT_SVC_BPP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_REFLECTED_UI)), *(new Long((long) BT_SVC_BPP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_BASIC_PRINTING)), *(new Long((long) BT_SVC_BPP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_PRINTING_STATUS)), *(new Long((long) BT_SVC_BPP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HID)), *(new Long((long) BT_SVC_HID_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HCRP)), *(new Long((long) BT_SVC_HCRP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HCRP_PRINT)), *(new Long((long) BT_SVC_HCRP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HCRP_SCAN)), *(new Long((long) BT_SVC_HCRP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SAP)), *(new Long((long) BT_SVC_SAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PBAP_PCE)), *(new Long((long) BT_SVC_PBAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PBAP_PSE)), *(new Long((long) BT_SVC_PBAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PBAP)), *(new Long((long) BT_SVC_PBAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HSP_HS)), *(new Long((long) BT_SVC_HSP_HS_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_MAP_ACCESS_SERVER)), *(new Long((long) BT_SVC_MAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_MAP_NOTIFICATION_SERVER)), *(new Long((long) BT_SVC_MAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_MAP_ACCESS_PROFILE)), *(new Long((long) BT_SVC_MAP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_DID_PNP_INFORMATION)), *(new Long((long) BT_SVC_DID_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_NETWORKING)), *(new Long((long) BT_SVC_NONE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_FILE_TRANSFER)), *(new Long((long) BT_SVC_NONE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_AUDIO)), *(new Long((long) BT_SVC_NONE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_TELEPHONY)), *(new Long((long) BT_SVC_NONE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_VDP_SOURCE)), *(new Long((long) BT_SVC_VDP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_VDP_SINK)), *(new Long((long) BT_SVC_VDP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_VDP_DISTRIBUTION)), *(new Long((long) BT_SVC_VDP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HDP)), *(new Long((long) BT_SVC_HDP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HDP_SOURCE)), *(new Long((long) BT_SVC_HDP_SERVICE)));
+               __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HDP_SINK)), *(new Long((long) BT_SVC_HDP_SERVICE)));
+
+               return E_SUCCESS;
+       }
+
+private:
+       Tizen::Base::Collection::HashMap __uuidMap;
+
+};     //_BluetoothUuidMap
+
+// defines local methods
+void PrintMajorDeviceClass(BluetoothMajorDeviceClassType type);
+void PrintMinorDeviceClass(BluetoothMajorDeviceClassType majType, BluetoothMinorDeviceClassType minType);
+void PrintServiceClassList(unsigned long type);
+
+
+_BluetoothAdapterUtility::_BluetoothAdapterUtility(void)
+{
+}
+
+_BluetoothAdapterUtility::~_BluetoothAdapterUtility(void)
+{
+}
+
+
+BluetoothMajorDeviceClassType
+_BluetoothAdapterUtility::ConvertToMajorDeviceClassType(bt_major_device_class_e majorClass)
+{
+       BluetoothMajorDeviceClassType convertedType = BT_COD_MAJ_DEV_CLS_UNCLASSIFIED;
+
+       switch (majorClass)
+       {
+       case BT_MAJOR_DEVICE_CLASS_MISC:
+               convertedType = BT_COD_MAJ_DEV_CLS_MISC;
+               break;
+
+       case BT_MAJOR_DEVICE_CLASS_COMPUTER:
+               convertedType = BT_COD_MAJ_DEV_CLS_COMPUTER;
+               break;
+
+       case BT_MAJOR_DEVICE_CLASS_PHONE:
+               convertedType = BT_COD_MAJ_DEV_CLS_PHONE;
+               break;
+
+       case BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT:
+               convertedType = BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT;
+               break;
+
+       case BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO:
+               convertedType = BT_COD_MAJ_DEV_CLS_AUDIO;
+               break;
+
+       case BT_MAJOR_DEVICE_CLASS_PERIPHERAL:
+               convertedType = BT_COD_MAJ_DEV_CLS_PERIPHERAL;
+               break;
+
+       case BT_MAJOR_DEVICE_CLASS_IMAGING:
+               convertedType = BT_COD_MAJ_DEV_CLS_IMAGING;
+               break;
+
+       case BT_MAJOR_DEVICE_CLASS_WEARABLE:
+       case BT_MAJOR_DEVICE_CLASS_TOY:
+       case BT_MAJOR_DEVICE_CLASS_HEALTH:
+       case BT_MAJOR_DEVICE_CLASS_UNCATEGORIZED:
+       default:
+               convertedType = BT_COD_MAJ_DEV_CLS_UNCLASSIFIED;
+               break;
+       }
+
+       return convertedType;
+}
+
+BluetoothMinorDeviceClassType
+_BluetoothAdapterUtility::ConvertToMinorDeviceClassType(bt_major_device_class_e majorClass, bt_minor_device_class_e minorClass)
+{
+       BluetoothMinorDeviceClassType convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+
+       if (majorClass == BT_MAJOR_DEVICE_CLASS_COMPUTER)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_COMPUTER_DESKTOP_WORKSTATION:
+                       convertedType = BT_COD_MIN_DEV_CLS_DESKTOP_WORKSTATION;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_COMPUTER_SERVER_CLASS:
+                       convertedType = BT_COD_MIN_DEV_CLS_SERVER_CLASS_COMPUTER;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_COMPUTER_LAPTOP:
+                       convertedType = BT_COD_MIN_DEV_CLS_LAPTOP;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_COMPUTER_HANDHELD_PC_OR_PDA:
+                       convertedType = BT_COD_MIN_DEV_CLS_HANDHELD_PC_OR_PDA;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_COMPUTER_PALM_SIZED_PC_OR_PDA:
+                       convertedType = BT_COD_MIN_DEV_CLS_PALM_SIZED_PC_OR_PDA;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_COMPUTER_WEARABLE_COMPUTER:
+                       convertedType = BT_COD_MIN_DEV_CLS_WEARABLE_COMPUTER;
+                       break;
+
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_PHONE)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_PHONE_CELLULAR:
+                       convertedType = BT_COD_MIN_DEV_CLS_CELLULAR;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_PHONE_CORDLESS:
+                       convertedType = BT_COD_MIN_DEV_CLS_CORDLESS;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_PHONE_SMART_PHONE:
+                       convertedType = BT_COD_MIN_DEV_CLS_SMART_PHONE;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_PHONE_WIRED_MODEM_OR_VOICE_GATEWAY:
+                       convertedType = BT_COD_MIN_DEV_CLS_WIRED_MODEM_OR_VOICE_GATEWAY;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_PHONE_COMMON_ISDN_ACCESS:
+                       convertedType = BT_COD_MIN_DEV_CLS_COMMON_ISDN_ACCESS;
+                       break;
+
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_FULLY_AVAILABLE:
+                       convertedType = BT_COD_MIN_DEV_CLS_FULLY_AVAILABLE;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_1_TO_17_PERCENT_UTILIZED:
+                       convertedType = BT_COD_MIN_DEV_CLS_1_TO_17_PERCENT_UTILIZED;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_17_TO_33_PERCENT_UTILIZED:
+                       convertedType = BT_COD_MIN_DEV_CLS_17_TO_33_PERCENT_UTILIZED;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_33_TO_50_PERCENT_UTILIZED :
+                       convertedType = BT_COD_MIN_DEV_CLS_33_TO_50_PERCENT_UTILIZED;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_50_to_67_PERCENT_UTILIZED:
+                       convertedType = BT_COD_MIN_DEV_CLS_50_to_67_PERCENT_UTILIZED;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_67_TO_83_PERCENT_UTILIZED:
+                       convertedType = BT_COD_MIN_DEV_CLS_67_TO_83_PERCENT_UTILIZED;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_83_TO_99_PERCENT_UTILIZED:
+                       convertedType = BT_COD_MIN_DEV_CLS_83_TO_99_PERCENT_UTILIZED;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_NO_SERVICE_AVAILABLE :
+                       convertedType = BT_COD_MIN_DEV_CLS_NO_SERVICE_AVAILABLE;
+                       break;
+
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_WEARABLE_HEADSET:
+                       convertedType = BT_COD_MIN_DEV_CLS_HEADSET_PROFILE;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HANDS_FREE :
+                       convertedType = BT_COD_MIN_DEV_CLS_HANDSFREE;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_MICROPHONE:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_LOUDSPEAKER:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HEADPHONES:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_PORTABLE_AUDIO:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAR_AUDIO:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_SET_TOP_BOX:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HIFI_AUDIO_DEVICE:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VCR:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CAMERA:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAMCORDER :
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_MONITOR:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_DISPLAY_LOUDSPEAKER:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CONFERENCING:
+               case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_GAMING_TOY:
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_PERIPHERAL)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_KEY_BOARD:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_POINTING_DEVICE:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_COMBO_KEYBOARD_POINTING_DEVICE :
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_JOYSTICK:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_GAME_PAD:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_REMOTE_CONTROL:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_SENSING_DEVICE:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITIZER_TABLET:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_CARD_READER:
+                       convertedType = BT_COD_MIN_DEV_CLS_SIM_CARD_READER;
+                       break;
+
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITAL_PEN:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_SCANNER:
+               case BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_GESTURAL_INPUT_DEVICE :
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_IMAGING)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_IMAGING_DISPLAY:
+               case BT_MINOR_DEVICE_CLASS_IMAGING_CAMERA:
+               case BT_MINOR_DEVICE_CLASS_IMAGING_SCANNER:
+               case BT_MINOR_DEVICE_CLASS_IMAGING_PRINTER:
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_WEARABLE)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_WEARABLE_WRIST_WATCH:
+               case BT_MINOR_DEVICE_CLASS_WEARABLE_PAGER:
+               case BT_MINOR_DEVICE_CLASS_WEARABLE_JACKET:
+               case BT_MINOR_DEVICE_CLASS_WEARABLE_HELMET:
+               case BT_MINOR_DEVICE_CLASS_WEARABLE_GLASSES:
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_TOY)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_TOY_ROBOT:
+               case BT_MINOR_DEVICE_CLASS_TOY_VEHICLE:
+               case BT_MINOR_DEVICE_CLASS_TOY_DOLL_ACTION:
+               case BT_MINOR_DEVICE_CLASS_TOY_CONTROLLER:
+               case BT_MINOR_DEVICE_CLASS_TOY_GAME:
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else if (majorClass == BT_MAJOR_DEVICE_CLASS_HEALTH)
+       {
+               switch (minorClass)
+               {
+               case BT_MINOR_DEVICE_CLASS_HEATH_BLOOD_PRESSURE_MONITOR:
+               case BT_MINOR_DEVICE_CLASS_HEATH_THERMOMETER :
+               case BT_MINOR_DEVICE_CLASS_HEATH_WEIGHING_SCALE:
+               case BT_MINOR_DEVICE_CLASS_HEATH_GLUCOSE_METER:
+               case BT_MINOR_DEVICE_CLASS_HEATH_PULSE_OXIMETER:
+               case BT_MINOR_DEVICE_CLASS_HEATH_HEART_PULSE_RATE_MONITOR:
+               case BT_MINOR_DEVICE_CLASS_HEATH_DATA_DISPLAY:
+               case BT_MINOR_DEVICE_CLASS_HEATH_STEP_COUNTER:
+               case BT_MINOR_DEVICE_CLASS_HEATH_BODY_COMPOSITION_ANALYZER:
+               case BT_MINOR_DEVICE_CLASS_HEATH_PEAK_FLOW_MONITOR:
+               case BT_MINOR_DEVICE_CLASS_HEATH_MEDICATION_MONITOR :
+               case BT_MINOR_DEVICE_CLASS_HEATH_KNEE_PROSTHESIS:
+               case BT_MINOR_DEVICE_CLASS_HEATH_ANKLE_PROSTHESIS:
+               default:
+                       convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+                       break;
+               }
+       }
+       else
+       {
+               convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED;
+       }
+
+       return convertedType;
+}
+
+unsigned long
+_BluetoothAdapterUtility::ConvertToServiceClassList(int serviceClass)
+{
+       unsigned long serviceClassMask = 0;
+
+       bt_major_service_class_e origianlClassList[] =
+       {
+               BT_MAJOR_SERVICE_CLASS_INFORMATION,
+               BT_MAJOR_SERVICE_CLASS_TELEPHONY,
+               BT_MAJOR_SERVICE_CLASS_AUDIO,
+               BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER,
+               BT_MAJOR_SERVICE_CLASS_CAPTURING,
+               BT_MAJOR_SERVICE_CLASS_RENDERING,
+               BT_MAJOR_SERVICE_CLASS_NETWORKING,
+               BT_MAJOR_SERVICE_CLASS_POSITIONING,
+               BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE
+       };
+
+       BluetoothServiceClassType convertedClassList[] =
+       {
+               BT_COD_SVC_INFORMATION,
+               BT_COD_SVC_TELEPHONY,
+               BT_COD_SVC_AUDIO,
+               BT_COD_SVC_OBJECT_TRANSFER,
+               BT_COD_SVC_CAPTURING,
+               BT_COD_SVC_RENDERING,
+               BT_COD_SVC_NETWORKING,
+               BT_COD_SVC_POSITIONING,
+               BT_COD_SVC_LIMITED_DISCOVERABLE_MODE
+       };
+
+       for (int i = 0; i < 9; i++)
+       {
+               // checks the input value, 'serviceClass', has each value of the class list using bit masking
+               if (origianlClassList[i] == (serviceClass & origianlClassList[i]))
+               {
+                       serviceClassMask += convertedClassList[i];
+               }
+       }
+
+       return serviceClassMask;
+}
+
+unsigned long
+_BluetoothAdapterUtility::ConvertToServiceList(char** pServiceUuid, int& serviceUuidCount)
+{
+       unsigned long serviceListMask = 0;
+       _BluetoothUuidMap* pMap = null;
+
+       pMap = _BluetoothUuidMap::GetInstance();
+       SysTryReturn(NID_NET_BT, pMap != null, 0, E_SYSTEM, "Converting UUID strings to a masked BluetoothServiceType value faild.");
+
+       for (int i = 0; i < serviceUuidCount; i++)
+       {
+               String uuidString(pServiceUuid[i]);
+               long uuidLongValue = pMap->GetUuidLong(uuidString);
+
+               serviceListMask |= uuidLongValue;
+       }
+
+       return serviceListMask;
+}
+
+Tizen::Base::Collection::IList*
+_BluetoothAdapterUtility::ConvertServiceUuidListN(char** pServiceUuid, int& serviceUuidCount)
+{
+       unique_ptr<ArrayList, AllElementsDeleter> pList;
+       UuId* pUuid = null;
+
+       pList.reset(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_NET_BT, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       for (int i = 0; i < serviceUuidCount; i++)
+       {
+               String uuidString(pServiceUuid[i]);
+               pUuid = new (std::nothrow) UuId();
+               SysTryReturn(NID_NET_BT, pUuid != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+               uuidString.ToUpperCase();
+               UuId::Parse(uuidString, *pUuid);
+
+               pList->Add(*pUuid);
+       }
+
+       return pList.release();
+}
+
+void
+_BluetoothAdapterUtility::PrintDeviceInfo(const BluetoothDevice& device)
+{
+       SysLog(NID_NET_BT, "Bluetooth Device Information =============");
+       SysLog(NID_NET_BT, "+ Address: [%ls]", _BluetoothDeviceImpl::GetAddressString(*(device.GetAddress())).GetPointer());
+       SysLog(NID_NET_BT, "+ Name: %ls", device.GetName().GetPointer());
+       SysLog(NID_NET_BT, "+ %s", device.IsPaired() ? "Paired" : "Not Paired");
+       SysLog(NID_NET_BT, "+ RSSI: %d", device.GetRssi());
+       PrintMajorDeviceClass(device.GetMajorDeviceClassType());
+       PrintMinorDeviceClass(device.GetMajorDeviceClassType(), device.GetMinorDeviceClassType());
+       PrintServiceClassList(device.GetServiceClassList());
+       PrintServiceList(device.GetServiceList());
+       PrintServiceUuidList(device.GetServiceUuidList());
+}
+
+void
+_BluetoothAdapterUtility::PrintServiceList(unsigned long type)
+{
+       int index = 0;
+       unsigned long typeList[] =
+       {
+               BT_SVC_MAP_SERVICE,
+               BT_SVC_HDP_SERVICE,
+               BT_SVC_DID_SERVICE,
+               BT_SVC_HCRP_SERVICE,
+               BT_SVC_HFP_HS_SERVICE,
+               BT_SVC_HSP_HS_SERVICE,
+               BT_SVC_PBAP_SERVICE,
+               BT_SVC_VDP_SERVICE,
+               BT_SVC_HID_SERVICE,
+               BT_SVC_AVRCP_SERVICE,
+               BT_SVC_A2DP_SERVICE,
+               BT_SVC_SAP_SERVICE,
+               BT_SVC_GN_SERVICE,
+               BT_SVC_NAP_SERVICE,
+               BT_SVC_PANU_SERVICE,
+               BT_SVC_BIP_SERVICE,
+               BT_SVC_BPP_SERVICE,
+               BT_SVC_SYNC_SERVICE,
+               BT_SVC_ICP_SERVICE,
+               BT_SVC_CTP_SERVICE,
+               BT_SVC_FTP_SERVICE,
+               BT_SVC_OPP_SERVICE,
+               BT_SVC_HFP_SERVICE,
+               BT_SVC_HSP_SERVICE,
+               BT_SVC_LAP_SERVICE,
+               BT_SVC_FAX_SERVICE,
+               BT_SVC_DUN_SERVICE,
+               BT_SVC_SPP_SERVICE,
+               BT_SVC_RES_SERVICE
+       };
+       const char* typeStrList[] =
+       {
+               "BT_SVC_MAP_SERVICE",
+               "BT_SVC_HDP_SERVICE",
+               "BT_SVC_DID_SERVICE",
+               "BT_SVC_HCRP_SERVICE",
+               "BT_SVC_HFP_HS_SERVICE",
+               "BT_SVC_HSP_HS_SERVICE",
+               "BT_SVC_PBAP_SERVICE",
+               "BT_SVC_VDP_SERVICE",
+               "BT_SVC_HID_SERVICE",
+               "BT_SVC_AVRCP_SERVICE",
+               "BT_SVC_A2DP_SERVICE",
+               "BT_SVC_SAP_SERVICE",
+               "BT_SVC_GN_SERVICE",
+               "BT_SVC_NAP_SERVICE",
+               "BT_SVC_PANU_SERVICE",
+               "BT_SVC_BIP_SERVICE",
+               "BT_SVC_BPP_SERVICE",
+               "BT_SVC_SYNC_SERVICE",
+               "BT_SVC_ICP_SERVICE",
+               "BT_SVC_CTP_SERVICE",
+               "BT_SVC_FTP_SERVICE",
+               "BT_SVC_OPP_SERVICE",
+               "BT_SVC_HFP_SERVICE",
+               "BT_SVC_HSP_SERVICE",
+               "BT_SVC_LAP_SERVICE",
+               "BT_SVC_FAX_SERVICE",
+               "BT_SVC_DUN_SERVICE",
+               "BT_SVC_SPP_SERVICE",
+               "BT_SVC_RES_SERVICE"
+       };
+
+       for (int i = 0; i < 29; i++)
+       {
+               // checks the input value, 'type', has each value of the service list using bit masking
+               if (typeList[i] == (type & typeList[i]))
+               {
+                       SysLog(NID_NET_BT, "+ Service List[%d]: %s", index++, typeStrList[i]);
+               }
+       }
+}
+
+void
+_BluetoothAdapterUtility::PrintServiceUuidList(const Tizen::Base::Collection::IList* pList)
+{
+       int count = 0;
+       const UuId* pUuid = null;
+
+       if (pList == null)
+       {
+               SysLog(NID_NET_BT, "+ No Service UUID (with error)");
+       }
+       else
+       {
+               count = pList->GetCount();
+
+               if (count == 0)
+               {
+                       SysLog(NID_NET_BT, "+ No Service UUID");
+               }
+
+               for (int i = 0; i < count; i++)
+               {
+                       pUuid = dynamic_cast<const UuId*>(pList->GetAt(i));
+                       if (pUuid != null)
+                       {
+                               SysLog(NID_NET_BT, "+ Service UUID[%d]: %ls", i, pUuid->ToString().GetPointer());
+                       }
+               }
+       }
+}
+
+void PrintMajorDeviceClass(BluetoothMajorDeviceClassType type)
+{
+       const char* pTypeString = null;
+
+       switch (type)
+       {
+       case BT_COD_MAJ_DEV_CLS_MISC:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_MISC";
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_COMPUTER:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_COMPUTER";
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_PHONE:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_PHONE";
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT";
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_AUDIO:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_AUDIO";
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_PERIPHERAL:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_PERIPHERAL";
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_IMAGING:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_IMAGING";
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_UNCLASSIFIED:
+               pTypeString = "BT_COD_MAJ_DEV_CLS_UNCLASSIFIED";
+               break;
+
+       default:
+               pTypeString = "Unknown";
+               break;
+       }
+
+       SysLog(NID_NET_BT, "+ Major Device Type: %s", pTypeString);
+}
+
+void PrintMinorDeviceClass(BluetoothMajorDeviceClassType majType, BluetoothMinorDeviceClassType minType)
+{
+       const char* pTypeString = null;
+
+       switch (majType)
+       {
+       case BT_COD_MAJ_DEV_CLS_COMPUTER:
+               switch (minType)
+               {
+               case BT_COD_MIN_DEV_CLS_DESKTOP_WORKSTATION:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_DESKTOP_WORKSTATION";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_SERVER_CLASS_COMPUTER:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_SERVER_CLASS_COMPUTER";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_LAPTOP:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_LAPTOP";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_HANDHELD_PC_OR_PDA:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_HANDHELD_PC_OR_PDA";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_PALM_SIZED_PC_OR_PDA:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_PALM_SIZED_PC_OR_PDA";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_WEARABLE_COMPUTER:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_WEARABLE_COMPUTER";
+                       break;
+
+               default:
+                       pTypeString = "Unclassified";
+                       break;
+               }
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_PHONE:
+               switch (minType)
+               {
+               case BT_COD_MIN_DEV_CLS_CELLULAR:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_CELLULAR";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_CORDLESS:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_CORDLESS";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_SMART_PHONE:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_SMART_PHONE";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_WIRED_MODEM_OR_VOICE_GATEWAY:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_WIRED_MODEM_OR_VOICE_GATEWAY";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_COMMON_ISDN_ACCESS:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_COMMON_ISDN_ACCESS";
+                       break;
+
+               default:
+                       pTypeString = "Unclassified";
+                       break;
+               }
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT:
+               switch (minType)
+               {
+               case BT_COD_MIN_DEV_CLS_FULLY_AVAILABLE:
+                       pTypeString = "BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_1_TO_17_PERCENT_UTILIZED:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_1_TO_17_PERCENT_UTILIZED";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_17_TO_33_PERCENT_UTILIZED:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_17_TO_33_PERCENT_UTILIZED";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_33_TO_50_PERCENT_UTILIZED:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_33_TO_50_PERCENT_UTILIZED";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_50_to_67_PERCENT_UTILIZED:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_50_to_67_PERCENT_UTILIZED";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_67_TO_83_PERCENT_UTILIZED:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_67_TO_83_PERCENT_UTILIZED";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_83_TO_99_PERCENT_UTILIZED:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_83_TO_99_PERCENT_UTILIZED";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_NO_SERVICE_AVAILABLE:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_NO_SERVICE_AVAILABLE";
+                       break;
+
+               default:
+                       pTypeString = "Unclassified";
+                       break;
+               }
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_AUDIO:
+               switch (minType)
+               {
+               case BT_COD_MIN_DEV_CLS_HEADSET_PROFILE:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_HEADSET_PROFILE";
+                       break;
+
+               case BT_COD_MIN_DEV_CLS_HANDSFREE:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_HANDSFREE";
+                       break;
+
+               default:
+                       pTypeString = "Unclassified";
+                       break;
+               }
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_PERIPHERAL:
+               switch (minType)
+               {
+               case BT_COD_MIN_DEV_CLS_SIM_CARD_READER:
+                       pTypeString = "BT_COD_MIN_DEV_CLS_SIM_CARD_READER";
+                       break;
+
+               default:
+                       pTypeString = "Unclassified";
+                       break;
+               }
+               break;
+
+       case BT_COD_MAJ_DEV_CLS_IMAGING:
+       case BT_COD_MAJ_DEV_CLS_MISC:
+       case BT_COD_MAJ_DEV_CLS_UNCLASSIFIED:
+       default:
+               pTypeString = "Unclassified";
+               break;
+       }
+
+       SysLog(NID_NET_BT, "+ Minor Device Type: %s", pTypeString);
+}
+
+void PrintServiceClassList(unsigned long type)
+{
+       int index = 0;
+       unsigned long typeList[] =
+       {
+               BT_COD_SVC_INFORMATION,
+               BT_COD_SVC_TELEPHONY,
+               BT_COD_SVC_AUDIO,
+               BT_COD_SVC_OBJECT_TRANSFER,
+               BT_COD_SVC_CAPTURING,
+               BT_COD_SVC_RENDERING,
+               BT_COD_SVC_NETWORKING,
+               BT_COD_SVC_POSITIONING,
+               BT_COD_SVC_LIMITED_DISCOVERABLE_MODE
+       };
+       const char* typeStrList[] =
+       {
+               "BT_COD_SVC_INFORMATION",
+               "BT_COD_SVC_TELEPHONY",
+               "BT_COD_SVC_AUDIO",
+               "BT_COD_SVC_OBJECT_TRANSFER",
+               "BT_COD_SVC_CAPTURING",
+               "BT_COD_SVC_RENDERING",
+               "BT_COD_SVC_NETWORKING",
+               "BT_COD_SVC_POSITIONING",
+               "BT_COD_SVC_LIMITED_DISCOVERABLE_MODE"
+       };
+
+       for (int i = 0; i < 9; i++)
+       {
+               if (typeList[i] == (type & typeList[i]))
+               {
+                       // checks the input value, 'type', has each value of the service class list using bit masking
+                       SysLog(NID_NET_BT, "+ Service Class List[%d]: %s", index++, typeStrList[i]);
+               }
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothConnectionEvent.cpp b/src/FNetBt_BluetoothConnectionEvent.cpp
new file mode 100644 (file)
index 0000000..1bf160c
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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    FNetBt_BluetoothConnectionEvent.cpp
+// @brief   This is the implementation file for the _BluetoothDeviceEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
+#include "FNetBt_BluetoothConnectionEvent.h"
+#include "FNetBt_BluetoothConnectionEventArg.h"
+#include "FNetBt_IBluetoothConnectionEventListener.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothConnectionEvent::_BluetoothConnectionEvent(void)
+       : __listenerCount(0)
+{
+}
+
+_BluetoothConnectionEvent::~_BluetoothConnectionEvent(void)
+{
+}
+
+result
+_BluetoothConnectionEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothConnectionEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       _IBluetoothConnectionEventListener* pEventListener = dynamic_cast <_IBluetoothConnectionEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pEventListener != null, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothConnectionEventArg* pEventArg = dynamic_cast <const _BluetoothConnectionEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothConnectionEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case _BT_CONNECTION_EVENT_CONNECTED:
+               SysLog(NID_NET_BT, "Firing Bluetooth Connection state changed Event (Type: _BT_CONNECTION_EVENT_CONNECTED)");
+               pEventListener->OnBluetoothDeviceConnected(*pEventArg->GetRemoteAddress());
+               break;
+
+       case _BT_CONNECTION_EVENT_DISCONNECTED:
+               SysLog(NID_NET_BT, "Firing Bluetooth Connection state changed Event (Type: _BT_CONNECTION_EVENT_DISCONNECTED)");
+               pEventListener->OnBluetoothDeviceDisconnected(*pEventArg->GetRemoteAddress());
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothConnectionEvent.h b/src/FNetBt_BluetoothConnectionEvent.h
new file mode 100644 (file)
index 0000000..bbeb028
--- /dev/null
@@ -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    FNetBt_BluetoothConnectionEvent.h
+ * @brief   This is the header file for the _BluetoothConnectionEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothConnectionEvent class.
+ * The _BluetoothConnectionEvent class can call a method of a listener (IBluetoothConnectionEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_CONNECTION_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_CONNECTION_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+// Forward declaration
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// @class   _BluetoothConnectionEvent
+// @brief   This class handles Bluetooth connection events.
+//
+class _BluetoothConnectionEvent
+       : public Tizen::Base::Runtime::_Event
+{
+public:
+       /**
+        * This is the default constructor.
+        */
+       _BluetoothConnectionEvent(void);
+
+       /**
+        * This is the class destructor.
+        */
+       virtual ~_BluetoothConnectionEvent(void);
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate pListener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth device event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothConnectionEvent(const _BluetoothConnectionEvent& value);
+       _BluetoothConnectionEvent& operator =(const _BluetoothConnectionEvent& rhs);
+
+private:
+       int __listenerCount;
+
+}; // _BluetoothConnectionEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_CONNECTION_EVENT_H_
diff --git a/src/FNetBt_BluetoothConnectionEventArg.cpp b/src/FNetBt_BluetoothConnectionEventArg.cpp
new file mode 100644 (file)
index 0000000..5390071
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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    FNetBt_BluetoothConnectionEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothConnectionEventArg class.
+//
+
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothConnectionEventArg.h"
+
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// This is a class constructor for _BT_CONNECTION_EVENT_CONNECTED and _BT_CONNECTION_EVENT_DISCONNECTED event.
+//
+_BluetoothConnectionEventArg::_BluetoothConnectionEventArg(_BluetoothConnectionEventType type, const Tizen::Base::ByteBuffer& address)
+       : __evtType(type)
+       , __pRemoteAddress(null)
+{
+       __pRemoteAddress = new (std::nothrow) ByteBuffer();
+       __pRemoteAddress->Construct(address);
+}
+
+_BluetoothConnectionEventArg::~_BluetoothConnectionEventArg(void)
+{
+       delete __pRemoteAddress;
+}
+
+_BluetoothConnectionEventType
+_BluetoothConnectionEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
+
+const ByteBuffer*
+_BluetoothConnectionEventArg::GetRemoteAddress(void) const
+{
+       return __pRemoteAddress;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothConnectionEventArg.h b/src/FNetBt_BluetoothConnectionEventArg.h
new file mode 100644 (file)
index 0000000..154d88d
--- /dev/null
@@ -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    FNetBt_BluetoothConnectionEventArg.h
+ * @brief   This is the header file for the _BluetoothConnectionEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothConnectionEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_CONNECTION_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_CONNECTION_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+  * @enum    _BluetoothConnectionEventType
+  * Type for specifying the type of _BluetoothConnectionEvent
+  */
+enum _BluetoothConnectionEventType
+{
+       _BT_CONNECTION_EVENT_CONNECTED,        /**< For notifying that the device is connected */
+       _BT_CONNECTION_EVENT_DISCONNECTED,     /**< For notifying that the device is disconnected */
+};
+
+/**
+ * @class   _BluetoothConnectionEventArg
+ * @brief   This class is used as an argument for callback methods of the _IBluetoothConnectionEventListener class.
+ *
+ * When a _BluetoothConnectionEvent occurs, the _BluetoothConnectionEvent finds a _IBluetoothConnectionEventListener instance
+ * which is registered for the _BluetoothConnectionEvent and calls an appropriate method of the listener.
+ * @see     _IBluetoothConnectionEventListener
+ */
+class _BluetoothConnectionEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+
+       /**
+        * This is a class constructor for _BT_CONNECTION_EVENT_CONNECTED and _BT_CONNECTION_EVENT_DISCONNECTED event.
+        *
+        * @param[in]   address             the remote device address to be observed regarding connection
+        */
+       _BluetoothConnectionEventArg(_BluetoothConnectionEventType type, const Tizen::Base::ByteBuffer& address);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothConnectionEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothConnectionEventType GetEventType(void) const;
+
+       /**
+        * Gets the remote device address.
+        *
+        * @return      the pointer of the remote device address which is a connected or disconnected device
+        */
+       const Tizen::Base::ByteBuffer* GetRemoteAddress(void) const;
+
+private:
+       _BluetoothConnectionEventArg(void);
+       _BluetoothConnectionEventArg(const _BluetoothConnectionEventArg& eventArg);
+       _BluetoothConnectionEventArg& operator =(const _BluetoothConnectionEventArg& rValue);
+
+private:
+       _BluetoothConnectionEventType __evtType;
+       Tizen::Base::ByteBuffer* __pRemoteAddress;
+
+}; // _BluetoothConnectionEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_CONNECTION_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothDeviceEvent.cpp b/src/FNetBt_BluetoothDeviceEvent.cpp
new file mode 100644 (file)
index 0000000..8fcd982
--- /dev/null
@@ -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    FNetBt_BluetoothDeviceEvent.cpp
+// @brief   This is the implementation file for the _BluetoothDeviceEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
+#include <FNetBtBluetoothDevice.h>
+#include "FNetBt_BluetoothDeviceEvent.h"
+#include "FNetBt_BluetoothDeviceEventArg.h"
+#include "FNetBtIBluetoothDeviceEventListener.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothDeviceEvent::_BluetoothDeviceEvent(void)
+{
+}
+
+_BluetoothDeviceEvent::~_BluetoothDeviceEvent(void)
+{
+}
+
+result
+_BluetoothDeviceEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothDeviceEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       const BluetoothDevice* pDevice = null;
+
+       IBluetoothDeviceEventListener* pEventListener = dynamic_cast <IBluetoothDeviceEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pEventListener != null, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothDeviceEventArg* pEventArg = dynamic_cast <const _BluetoothDeviceEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothDeviceEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case _BT_DEVICE_EVENT_DISCOVERY_STARTED:
+               SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_DEVDISCOVERY_STARTED)");
+               pEventListener->OnBluetoothDiscoveryStarted(pEventArg->GetErrorResult());
+               break;
+
+       case _BT_DEVICE_EVENT_DEVICE_FOUND:
+               pDevice = pEventArg->GetRemoteDevice();
+               if (pDevice != null)
+               {
+                       BluetoothDevice* pFoundDevice = new (std::nothrow) BluetoothDevice(*pDevice);
+                       SysTryReturnVoidResult(NID_NET_BT, pFoundDevice != null, E_SYSTEM,
+                                       "[E_SYSTEM] Failed to copy the BluetoothDevice instance.");
+
+                       SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_DEVICE_FOUND)");
+                       pEventListener->OnBluetoothRemoteDeviceFoundN(pFoundDevice);
+               }
+               break;
+
+       case _BT_DEVICE_EVENT_DISCOVERY_DONE:
+               SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_DEVDISCOVERY_DONE)");
+               pEventListener->OnBluetoothDiscoveryDone(pEventArg->IsDiscoveryCompleted());
+               break;
+
+       case _BT_DEVICE_EVENT_SVCLIST_RECEIVED:
+               pDevice = pEventArg->GetRemoteDevice();
+               if (pDevice != null)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_SVCLIST_RECEIVED)");
+                       pEventListener->OnBluetoothServiceListReceived(*pDevice, pEventArg->GetServiceList(), pEventArg->GetErrorResult());
+               }
+               break;
+
+       case _BT_DEVICE_EVENT_PAIRED:
+               SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_PAIRED)");
+               pDevice = pEventArg->GetRemoteDevice();
+               if (pDevice != null)
+               {
+                       pEventListener->OnBluetoothPaired(*pDevice);
+               }
+               else
+               {
+                       pEventListener->OnBluetoothPairingFailed(pEventArg->GetErrorResult());
+               }
+               break;
+
+       case _BT_DEVICE_EVENT_UNPAIRED:
+               pDevice = pEventArg->GetRemoteDevice();
+               if (pDevice != null)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth Device Event (Type: _BT_DEVICE_EVENT_UNPAIRED)");
+                       pEventListener->OnBluetoothUnpaired(*pDevice);
+               }
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothDeviceEvent.h b/src/FNetBt_BluetoothDeviceEvent.h
new file mode 100644 (file)
index 0000000..d6d151c
--- /dev/null
@@ -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    FNetBt_BluetoothDeviceEvent.h
+ * @brief   This is the header file for the _BluetoothDeviceEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothDeviceEvent class.
+ * The _BluetoothDeviceEvent class can call a method of a listener (IBluetoothDeviceEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+// Forward declaration
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// @class   _BluetoothDeviceEvent
+// @brief   This class handles Bluetooth device events.
+//
+// When a Bluetooth device event occurs, the _BluetoothDeviceEvent object finds a IBluetoothDeviceEventListener object
+// and calls an appropriate method of the listener.
+//
+class _BluetoothDeviceEvent
+       : public Tizen::Base::Runtime::_Event
+{
+public:
+       /**
+        * This is the default constructor.
+        */
+       _BluetoothDeviceEvent(void);
+
+       /**
+        * This is the class destructor.
+        */
+       virtual ~_BluetoothDeviceEvent(void);
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate pListener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth device event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothDeviceEvent(const _BluetoothDeviceEvent& value);
+       _BluetoothDeviceEvent& operator =(const _BluetoothDeviceEvent& rhs);
+
+}; // _BluetoothDeviceEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_EVENT_H_
diff --git a/src/FNetBt_BluetoothDeviceEventArg.cpp b/src/FNetBt_BluetoothDeviceEventArg.cpp
new file mode 100755 (executable)
index 0000000..57c996c
--- /dev/null
@@ -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    FNetBt_BluetoothDeviceEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothDeviceEventArg class.
+//
+
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothDeviceEventArg.h"
+
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// This is a class constructor for _BT_DEVICE_EVENT_DISCOVERY_STARTED event.
+//
+_BluetoothDeviceEventArg::_BluetoothDeviceEventArg(result r)
+       : __evtType(_BT_DEVICE_EVENT_DISCOVERY_STARTED)
+       , __pRemoteDevice(null)
+       , __isCompleted(false)
+       , __serviceList(0)
+       , __result(r)
+{
+}
+
+//
+// This is a class constructor for _BT_DEVICE_EVENT_DISCOVERY_DONE event.
+//
+_BluetoothDeviceEventArg::_BluetoothDeviceEventArg(bool isCompleted)
+       : __evtType(_BT_DEVICE_EVENT_DISCOVERY_DONE)
+       , __pRemoteDevice(null)
+       , __isCompleted(isCompleted)
+       , __serviceList(0)
+       , __result(E_SUCCESS)
+{
+}
+
+//
+// This is a class constructor for _BT_DEVICE_EVENT_SVCLIST_RECEIVED event.
+//
+_BluetoothDeviceEventArg::_BluetoothDeviceEventArg(const BluetoothDevice& device, unsigned long serviceList, result r)
+       : __evtType(_BT_DEVICE_EVENT_SVCLIST_RECEIVED)
+       , __pRemoteDevice(null)
+       , __isCompleted(false)
+       , __serviceList(serviceList)
+       , __result(r)
+{
+       __pRemoteDevice = new (std::nothrow) BluetoothDevice(device);
+       SysTryReturnVoidResult(NID_NET_BT, __pRemoteDevice != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+}
+
+//
+// This is a class constructor for _BT_DEVICE_EVENT_DEVICE_FOUND and _BT_DEVICE_EVENT_UNPAIRED event.
+//
+_BluetoothDeviceEventArg::_BluetoothDeviceEventArg(_BluetoothDeviceEventType type, const BluetoothDevice& device)
+       : __evtType(type)
+       , __pRemoteDevice(null)
+       , __isCompleted(false)
+       , __serviceList(0)
+       , __result(E_SUCCESS)
+{
+       __pRemoteDevice = new (std::nothrow) BluetoothDevice(device);
+       SysTryReturnVoidResult(NID_NET_BT, __pRemoteDevice != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+}
+
+//
+// This is a class constructor for _BT_DEVICE_EVENT_PAIRED event.
+//
+_BluetoothDeviceEventArg::_BluetoothDeviceEventArg(const BluetoothDevice* pDevice, result r)
+       : __evtType(_BT_DEVICE_EVENT_PAIRED)
+       , __pRemoteDevice(null)
+       , __isCompleted(false)
+       , __serviceList(0)
+       , __result(r)
+{
+       if (pDevice != null)
+       {
+               __pRemoteDevice = new (std::nothrow) BluetoothDevice(*pDevice);
+               SysTryReturnVoidResult(NID_NET_BT, __pRemoteDevice != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       }
+}
+
+_BluetoothDeviceEventArg::~_BluetoothDeviceEventArg(void)
+{
+       delete __pRemoteDevice;
+}
+
+_BluetoothDeviceEventType
+_BluetoothDeviceEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
+
+const BluetoothDevice*
+_BluetoothDeviceEventArg::GetRemoteDevice(void) const
+{
+       return __pRemoteDevice;
+}
+
+bool
+_BluetoothDeviceEventArg::IsDiscoveryCompleted(void) const
+{
+       return __isCompleted;
+}
+
+unsigned long
+_BluetoothDeviceEventArg::GetServiceList(void) const
+{
+       return __serviceList;
+}
+
+result
+_BluetoothDeviceEventArg::GetErrorResult(void) const
+{
+       return __result;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothDeviceEventArg.h b/src/FNetBt_BluetoothDeviceEventArg.h
new file mode 100644 (file)
index 0000000..af93a97
--- /dev/null
@@ -0,0 +1,170 @@
+//
+// 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    FNetBt_BluetoothDeviceEventArg.h
+ * @brief   This is the header file for the _BluetoothDeviceEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothDeviceEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declaration
+class BluetoothDevice;
+
+/**
+  * @enum    _BluetoothDeviceEventType
+  * Type for specifying the type of _BluetoothDeviceEvent
+  */
+enum _BluetoothDeviceEventType
+{
+       _BT_DEVICE_EVENT_DISCOVERY_STARTED,     /**< For notifying that the device discovery process is started */
+       _BT_DEVICE_EVENT_DEVICE_FOUND,          /**< For notifying that a new remote device is found */
+       _BT_DEVICE_EVENT_DISCOVERY_DONE,        /**< For notifying that the device discovery process is done */
+       _BT_DEVICE_EVENT_SVCLIST_RECEIVED,      /**< For notifying that the service list is received from a remote device */
+       _BT_DEVICE_EVENT_PAIRED,                /**< For notifying that the local device is newly paired with a remote device */
+       _BT_DEVICE_EVENT_UNPAIRED,              /**< For notifying that the local device is unpaired with the paired device */
+};
+
+/**
+ * @class   _BluetoothDeviceEventArg
+ * @brief   This class is used as an argument for callback methods of the _IBluetoothDeviceEventListener class.
+ *
+ * When a _BluetoothDeviceEvent occurs, the _BluetoothDeviceEvent finds a _IBluetoothDeviceEventListener instance
+ * which is registered for the _BluetoothDeviceEvent and calls an appropriate method of the listener.
+ * @see     _IBluetoothDeviceEventListener
+ */
+class _BluetoothDeviceEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor for _BT_DEVICE_EVENT_DISCOVERY_STARTED 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.
+        */
+       _BluetoothDeviceEventArg(result r);
+
+       /**
+        * This is a class constructor for _BT_DEVICE_EVENT_DISCOVERY_DONE event.
+        *
+        * @param[in]   isCompleted         @c true, if the discovery is completely done @n
+        *                                  @c false, otherwise
+        */
+       _BluetoothDeviceEventArg(bool isCompleted);
+
+       /**
+        * This is a class constructor for _BT_DEVICE_EVENT_SVCLIST_RECEIVED event.
+        *
+        * @param[in]   device                      The target device which sent its service list
+        * @param[in]   serviceList                 The service list received from the remote device
+        * @param[in]   r                           The result of the event
+        * @exception   E_SUCCESS                   The action was successful.
+        * @exception   E_REMOTE_SERVICE_NOT_FOUND  The action failed because the service list of the remote device is not found.
+        * @exception   E_SYSTEM                    The action failed due to a system error.
+        */
+       _BluetoothDeviceEventArg(const BluetoothDevice& device, unsigned long serviceList, result r);
+
+       /**
+        * This is a class constructor for _BT_DEVICE_EVENT_DEVICE_FOUND and _BT_DEVICE_EVENT_UNPAIRED event.
+        *
+        * @param[in]   type                 The type of the event - only _BT_DEVICE_EVENT_DEVICE_FOUND and
+        *                                   _BT_DEVICE_EVENT_UNPAIRED are allowed
+        * @param[in]   device               The remote device
+        */
+       _BluetoothDeviceEventArg(_BluetoothDeviceEventType type, const BluetoothDevice& device);
+
+       /**
+        * This is a class constructor for _BT_DEVICE_EVENT_PAIRED.
+        *
+        * @param[in]   pDevice               The paired device
+        * @param[in]   r                    The result of pairing
+        * @exception   E_SUCCESS            The method is successful.
+        * @exception   E_SYSTEM             A system error occurred.
+        */
+       _BluetoothDeviceEventArg(const BluetoothDevice* pDevice, result r);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothDeviceEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothDeviceEventType GetEventType(void) const;
+
+       /**
+        * Gets the remote device.
+        *
+        * @return      The pointer of the remote device which is a found device, a paired, or an unpaired device
+        */
+       const BluetoothDevice* GetRemoteDevice(void) const;
+
+       /**
+        * Checks if the discovery is completely done.
+        *
+        * @return      @c true, if the discovery is completely done @n
+        *              @c false, otherwise
+        */
+       bool IsDiscoveryCompleted(void) const;
+
+       /**
+        * Gets the service list retrieved from a remote device.
+        *
+        * @return      the service list which consists of masked BluetoothServiceType values
+        */
+       unsigned long GetServiceList(void) const;
+
+       /**
+        * Gets the error result of this event.
+        *
+        * @return      The result of the event
+        */
+       result GetErrorResult(void) const;
+
+private:
+       _BluetoothDeviceEventArg(void);
+       _BluetoothDeviceEventArg(const _BluetoothDeviceEventArg& eventArg);
+       _BluetoothDeviceEventArg& operator =(const _BluetoothDeviceEventArg& rValue);
+
+private:
+       _BluetoothDeviceEventType __evtType;
+       BluetoothDevice* __pRemoteDevice;
+       bool __isCompleted;
+       unsigned long __serviceList;
+       result __result;
+
+}; // _BluetoothDeviceEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothDeviceImpl.cpp b/src/FNetBt_BluetoothDeviceImpl.cpp
new file mode 100755 (executable)
index 0000000..4b7af09
--- /dev/null
@@ -0,0 +1,345 @@
+//
+// 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    FNetBt_BluetoothDeviceImpl.cpp
+// @brief   This is the implementation file for the _BluetoothDeviceImpl class.
+//
+
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseUtilStringTokenizer.h>
+#include <FBaseColArrayList.h>
+#include <FBaseShort.h>
+#include <FBaseUuId.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothDeviceImpl.h"
+
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothDeviceImpl::_BluetoothDeviceImpl(void)
+       : __deviceAddress()
+       , __deviceName()
+       , __isPaired(false)
+       , __rssi(0)
+       , __majorClassType(BT_COD_MAJ_DEV_CLS_MISC)
+       , __minorClassType(BT_COD_MIN_DEV_CLS_UNCLASSIFIED)
+       , __serviceClassList(BT_COD_SVC_UNKNOWN)
+       , __serviceList(BT_SVC_NONE)
+       , __pServiceUuidList(null)
+{
+       (void) __deviceAddress.Construct(BT_ADDRESS_LENGTH);
+       (void) __deviceAddress.SetPosition(0);
+}
+
+_BluetoothDeviceImpl::_BluetoothDeviceImpl(const Tizen::Base::ByteBuffer& address, const Tizen::Base::String& deviceName, BluetoothMajorDeviceClassType majorClassType, BluetoothMinorDeviceClassType minorClassType, unsigned long serviceClassList, unsigned long serviceList)
+       : __deviceAddress()
+       , __deviceName(deviceName)
+       , __isPaired(false)
+       , __rssi(0)
+       , __majorClassType(majorClassType)
+       , __minorClassType(minorClassType)
+       , __serviceClassList(serviceClassList)
+       , __serviceList(serviceList)
+       , __pServiceUuidList(null)
+{
+       (void) __deviceAddress.Construct(address);
+       (void) __deviceAddress.SetPosition(0);
+}
+
+_BluetoothDeviceImpl::_BluetoothDeviceImpl(const _BluetoothDeviceImpl& value)
+       : __deviceAddress()
+       , __deviceName(value.__deviceName)
+       , __isPaired(value.__isPaired)
+       , __rssi(value.__rssi)
+       , __majorClassType(value.__majorClassType)
+       , __minorClassType(value.__minorClassType)
+       , __serviceClassList(value.__serviceClassList)
+       , __serviceList(value.__serviceList)
+       , __pServiceUuidList(null)
+{
+       (void) __deviceAddress.Construct(value.__deviceAddress);
+       (void) __deviceAddress.SetPosition(0);
+       (void) SetServiceUuidList(value.__pServiceUuidList.get(), true);
+}
+
+_BluetoothDeviceImpl::~_BluetoothDeviceImpl(void)
+{
+}
+
+const Tizen::Base::ByteBuffer*
+_BluetoothDeviceImpl::GetAddress(void) const
+{
+       return &__deviceAddress;
+}
+
+Tizen::Base::String
+_BluetoothDeviceImpl::GetName(void) const
+{
+       return __deviceName;
+}
+
+bool
+_BluetoothDeviceImpl::IsPaired(void) const
+{
+       return __isPaired;
+}
+
+int
+_BluetoothDeviceImpl::GetRssi(void) const
+{
+       return __rssi;
+}
+
+BluetoothMajorDeviceClassType
+_BluetoothDeviceImpl::GetMajorDeviceClassType(void) const
+{
+       return __majorClassType;
+}
+
+BluetoothMinorDeviceClassType
+_BluetoothDeviceImpl::GetMinorDeviceClassType(void) const
+{
+       return __minorClassType;
+}
+
+unsigned long
+_BluetoothDeviceImpl::GetServiceClassList(void) const
+{
+       return __serviceClassList;
+}
+
+unsigned long
+_BluetoothDeviceImpl::GetServiceList(void) const
+{
+       return __serviceList;
+}
+
+const Tizen::Base::Collection::IList*
+_BluetoothDeviceImpl::GetServiceUuidList(void) const
+{
+       return __pServiceUuidList.get();
+}
+
+bool
+_BluetoothDeviceImpl::Equals(const Tizen::Base::Object& obj) const
+{
+       const _BluetoothDeviceImpl* pOther = dynamic_cast <const _BluetoothDeviceImpl*>(&obj);
+
+       if (pOther == null)
+       {
+               return false;
+       }
+
+       if (pOther == this)
+       {
+               return true;
+       }
+
+       return __deviceAddress.Equals(pOther->__deviceAddress);
+}
+
+int
+_BluetoothDeviceImpl::GetHashCode(void) const
+{
+       return GetAddressString(__deviceAddress).GetHashCode();
+}
+
+_BluetoothDeviceImpl&
+_BluetoothDeviceImpl::operator =(const _BluetoothDeviceImpl& rhs)
+{
+    if (this != &rhs)
+    {
+               (void) __deviceAddress.SetArray(rhs.__deviceAddress.GetPointer(), 0, BT_ADDRESS_LENGTH);
+               (void) __deviceAddress.SetPosition(0);
+
+               __deviceName = rhs.__deviceName;
+               __majorClassType = rhs.__majorClassType;
+               __minorClassType = rhs.__minorClassType;
+               __serviceClassList = rhs.__serviceClassList;
+               __serviceList = rhs.__serviceList;
+               (void) SetServiceUuidList(rhs.__pServiceUuidList.get(), true);
+    }
+
+       return *this;
+}
+
+result
+_BluetoothDeviceImpl::SetAddress(const Tizen::Base::ByteBuffer& address)
+{
+       result r = E_SUCCESS;
+
+       if ((address.GetLimit() < BT_ADDRESS_LENGTH) || (__deviceAddress.GetCapacity() < BT_ADDRESS_LENGTH))
+       {
+               r = E_INVALID_ARG;
+       }
+       else
+       {
+               for (int i = 0; i < BT_ADDRESS_LENGTH; i++)
+               {
+                       byte value = 0x00;
+                       (void) address.GetByte(i, value);
+                       (void) __deviceAddress.SetByte(i, value);
+               }
+       }
+
+       return r;
+}
+
+void
+_BluetoothDeviceImpl::SetName(const Tizen::Base::String& name)
+{
+       __deviceName = name;
+}
+
+void
+_BluetoothDeviceImpl::SetMajorDeviceClassType(BluetoothMajorDeviceClassType type)
+{
+       __majorClassType = type;
+}
+
+void
+_BluetoothDeviceImpl::SetMinorDeviceClassType(BluetoothMinorDeviceClassType type)
+{
+       __minorClassType = type;
+}
+
+void
+_BluetoothDeviceImpl::SetServiceClassList(unsigned long listValue)
+{
+       __serviceClassList = listValue;
+}
+
+void
+_BluetoothDeviceImpl::SetServiceList(unsigned long serviceList)
+{
+       __serviceList = serviceList;
+}
+
+void
+_BluetoothDeviceImpl::SetPaired(bool isPaired)
+{
+       __isPaired = isPaired;
+}
+
+void
+_BluetoothDeviceImpl::SetRssi(int rssi)
+{
+       __rssi = rssi;
+}
+
+result
+_BluetoothDeviceImpl::SetServiceUuidList(const Tizen::Base::Collection::IList* pSrcUuidList, bool isDeepCopy)
+{
+       int count = 0;
+       unique_ptr<ArrayList, AllElementsDeleter> pTempList;
+
+       if (isDeepCopy == true)
+       {
+               if (pSrcUuidList != null)
+               {
+                       pTempList.reset(new (std::nothrow) ArrayList());
+                       SysTryReturnResult(NID_NET_BT, pTempList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+                       count = pSrcUuidList->GetCount();
+                       (void) pTempList->Construct(count);
+
+                       for (int i = 0; i < count; i++)
+                       {
+                               const UuId* pSrcUuid = dynamic_cast<const UuId*>(pSrcUuidList->GetAt(i));
+                               SysTryReturnResult(NID_NET_BT, pSrcUuid != null, E_SYSTEM, "A failure occurred when copying an internal variable.");
+
+                               unique_ptr<UuId> pNewUuid(new (std::nothrow) UuId(*pSrcUuid));
+                               SysTryReturnResult(NID_NET_BT, pNewUuid != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+                               pTempList->Add(*pNewUuid.release());
+                       }
+               }
+
+               __pServiceUuidList.reset(pTempList.release());
+       }
+       else
+       {
+               __pServiceUuidList.reset(const_cast<IList*>(pSrcUuidList));
+       }
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothDeviceImpl::GetAddressByteBuffer(const Tizen::Base::String& srcAddr, const Tizen::Base::String& delimiters, Tizen::Base::ByteBuffer& dstAddr)
+{
+       result r = E_SUCCESS;
+       StringTokenizer strTok(srcAddr, delimiters);
+       int tokCount = strTok.GetTokenCount();
+       String token;
+       short digit = 0;
+
+       SysTryReturnResult(NID_NET_BT, tokCount == BT_ADDRESS_LENGTH, E_SYSTEM, "The address format is invalid.");
+
+       for (int i = 0; i < BT_ADDRESS_LENGTH; i++)
+       {
+               (void) strTok.GetNextToken(token);
+               token.Insert(L"0X", 0);
+               r = Short::Decode(token, digit);
+               SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Parsing address has failed.");
+               r = dstAddr.SetByte(i, Short(digit).ToChar());
+               SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "The ByteBuffer argument is invalid.");
+       }
+
+       SysLog(NID_NET_BT, "Translated address is [%ls]", GetAddressString(dstAddr).GetPointer());
+
+       return E_SUCCESS;
+}
+
+Tizen::Base::String
+_BluetoothDeviceImpl::GetAddressString(const Tizen::Base::ByteBuffer& address)
+{
+       String addressString(BT_ADDRESS_LENGTH * 3);
+       String hex;
+       byte value = 0x00;
+
+       for (int i = 0; i < BT_ADDRESS_LENGTH; i++)
+       {
+               (void) address.GetByte(i, value);
+               (void) hex.Format(4, L"%02X:", value);
+               (void) addressString.Append(hex);
+       }
+
+       // Removes the last delimiter
+       (void) addressString.Remove(addressString.GetLength() - 1, 1);
+
+       return addressString;
+}
+
+_BluetoothDeviceImpl*
+_BluetoothDeviceImpl::GetInstance(BluetoothDevice& bluetoothDevice)
+{
+       return bluetoothDevice.__pImpl;
+}
+
+const _BluetoothDeviceImpl*
+_BluetoothDeviceImpl::GetInstance(const BluetoothDevice& bluetoothDevice)
+{
+       return bluetoothDevice.__pImpl;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothGapSystemAdapter.cpp b/src/FNetBt_BluetoothGapSystemAdapter.cpp
new file mode 100755 (executable)
index 0000000..fa49bc1
--- /dev/null
@@ -0,0 +1,973 @@
+//
+// 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        FNetBt_BluetoothGapSystemAdapter.cpp
+// @brief       This is the implementation file for the _BluetoothGapSystemAdapter class.
+//
+
+#include <unique_ptr.h>
+#include <pthread.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseUtilStringUtil.h>
+#include <FBaseUuId.h>
+#include <FIoFile.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include <FApp_AppInfo.h>
+#include <FBase_StringConverter.h>
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothDeviceImpl.h"
+#include "FNetBt_IBluetoothDeviceEventListener.h"
+#include "FNetBt_IBluetoothManagerEventListener.h"
+#include "FNetBt_BluetoothAdapterUtility.h"
+
+using namespace std;
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Io;
+
+static const Tizen::Base::String _BT_ADDRESS_FILE_PATH(L"/opt/etc/.bd_addr");
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+struct _DeviceInfoDeleter
+{
+       template<typename bt_device_info_s>
+       void operator()(bt_device_info_s* pDeviceInfo)
+       {
+               bt_adapter_free_device_info(pDeviceInfo);
+       }
+};
+
+_BluetoothGapSystemAdapter* _BluetoothGapSystemAdapter::__pInstance = null;
+
+_BluetoothGapSystemAdapter::_BluetoothGapSystemAdapter(void)
+       : __mgrEvtListenerList()
+       , __devEvtListenerList()
+{
+}
+
+_BluetoothGapSystemAdapter::~_BluetoothGapSystemAdapter(void)
+{
+       // unset all the system callback methods
+       bt_adapter_unset_state_changed_cb();
+       bt_adapter_unset_device_discovery_state_changed_cb();
+       bt_adapter_unset_visibility_mode_changed_cb();
+       bt_device_unset_bond_created_cb();
+       bt_device_unset_bond_destroyed_cb();
+       bt_device_unset_service_searched_cb();
+       bt_device_unset_connection_state_changed_cb();
+}
+
+void
+_BluetoothGapSystemAdapter::InitSingleton(void)
+{
+       bool isConstructed = false;
+       static _BluetoothGapSystemAdapter inst;
+
+       isConstructed = inst.Construct();
+       SysTryReturnVoidResult(NID_NET_BT, isConstructed == true, E_SYSTEM,
+                       "[E_SYSTEM] Construction of _BluetoothGapSystemAdpater fails.");
+
+       __pInstance = &inst;
+}
+
+_BluetoothGapSystemAdapter*
+_BluetoothGapSystemAdapter::GetInstance(void)
+{
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (__pInstance == null)
+       {
+               ClearLastResult();
+               pthread_once(&onceBlock, InitSingleton);
+               result r = GetLastResult();
+               if (IsFailed(r))
+               {
+                       onceBlock = PTHREAD_ONCE_INIT;
+               }
+       }
+
+       return __pInstance;
+}
+
+bool
+_BluetoothGapSystemAdapter::Construct(void)
+{
+       if (bt_initialize() == BT_ERROR_NONE)
+       {
+               //register all the call backs.
+               if ((bt_adapter_set_state_changed_cb(&OnAdapterStateChanged, NULL) == BT_ERROR_NONE) &&
+                       (bt_adapter_set_visibility_mode_changed_cb(&OnVisibilityModeChanged, NULL) == BT_ERROR_NONE) &&
+                       (bt_device_set_bond_created_cb(&OnPairingCompleted, NULL) == BT_ERROR_NONE) &&
+                       (bt_device_set_bond_destroyed_cb(&OnPairedDeviceRemoved, NULL) == BT_ERROR_NONE) &&
+                       (bt_adapter_set_device_discovery_state_changed_cb(&OnDeviceDiscoveryStateChanged, NULL) == BT_ERROR_NONE) &&
+                       (bt_device_set_service_searched_cb(&OnServiceDiscoveryCompleted, NULL) == BT_ERROR_NONE) &&
+                       (bt_device_set_connection_state_changed_cb(&OnConnectionStateChanged, NULL) == BT_ERROR_NONE))
+               {
+                       return true;
+               }
+       }
+       SysLog(NID_NET_BT, "Initialising the Bluetooth subsystem has failed");
+
+       return false;
+}
+
+result
+_BluetoothGapSystemAdapter::RegisterManagerEventListener(const _IBluetoothManagerEventListener& listener, bool isHighPriority)
+{
+       if (isHighPriority == true)
+       {
+               // insert the specified event listener at the begin of the list
+               return __mgrEvtListenerList.InsertAt(const_cast<_IBluetoothManagerEventListener*>(&listener), 0);
+       }
+       else
+       {
+               // insert the specified event listener at the end of the list
+               return __mgrEvtListenerList.Add(const_cast<_IBluetoothManagerEventListener*>(&listener));
+       }
+}
+
+result
+_BluetoothGapSystemAdapter::UnregisterManagerEventListener(const _IBluetoothManagerEventListener& listener)
+{
+
+       return __mgrEvtListenerList.Remove(const_cast<_IBluetoothManagerEventListener*>(&listener));
+}
+
+result
+_BluetoothGapSystemAdapter::RegisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener)
+{
+       return __devEvtListenerList.Add(const_cast<_IBluetoothDeviceEventListener*>(&listener));
+}
+
+result
+_BluetoothGapSystemAdapter::UnregisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener)
+{
+       return __devEvtListenerList.Remove(const_cast<_IBluetoothDeviceEventListener*>(&listener));
+}
+
+result
+_BluetoothGapSystemAdapter::Activate(void)
+{
+       if (bt_adapter_enable() == BT_ERROR_NONE)
+       {
+               return E_SUCCESS;
+       }
+       return E_SYSTEM;
+}
+
+result
+_BluetoothGapSystemAdapter::Deactivate(void)
+{
+       if (bt_adapter_disable() == BT_ERROR_NONE)
+       {
+               return E_SUCCESS;
+       }
+       return E_SYSTEM;
+}
+
+bool
+_BluetoothGapSystemAdapter::IsActivated(void) const
+{
+       bt_adapter_state_e btAdapterState = BT_ADAPTER_DISABLED;
+
+       if (bt_adapter_get_state(&btAdapterState) == BT_ERROR_NONE)
+       {
+               if (btAdapterState == BT_ADAPTER_ENABLED)
+               {
+                       return true;
+               }
+       }
+       return false;
+}
+
+bool
+_BluetoothGapSystemAdapter::IsAvailable(BluetoothConnectionType type) const
+{
+       bool isAvailable = false;
+       bool isUsed = true;
+       char* pUuidStr = null;
+
+       if (!IsActivated())
+       {
+               SysLog(NID_NET_BT, "All connection type is not available because Bluetooth is not activated.");
+               return false;
+       }
+
+       switch (type)
+       {
+       case BT_CONNECTION_GENERIC:
+               isAvailable = true;
+               break;
+
+       case BT_CONNECTION_SPP_ACCEPTOR:
+               pUuidStr = _StringConverter::CopyToCharArrayN(UuId(BT_SVC_UUID_SPP).ToString());
+               // TODO: meaning of bt_adapter_is_service_used() method is quite wrong
+               if ((pUuidStr != null) && (bt_adapter_is_service_used(pUuidStr, &isUsed) == BT_ERROR_NONE))
+               {
+                       SysLog(NID_NET_BT, "SPP(default UUID) server is %s.", isUsed ? "used" : "available");
+               }
+
+               isAvailable = isUsed ? false : true;
+
+               delete[] pUuidStr;
+               break;
+
+       case BT_CONNECTION_OPP_SERVER:
+               pUuidStr = _StringConverter::CopyToCharArrayN(UuId(BT_SVC_UUID_OPP).ToString());
+               // TODO: meaning of bt_adapter_is_service_used() method is quite wrong
+               if ((pUuidStr != null) && (bt_adapter_is_service_used(pUuidStr, &isUsed) == BT_ERROR_NONE))
+               {
+                       SysLog(NID_NET_BT, "OPP server is %s.", isUsed ? "used" : "available");
+               }
+
+               isAvailable = isUsed ? false : true;
+
+               delete[] pUuidStr;
+               break;
+
+       // This is always true, because multiple SPP initiators can be run simultaneously since 3.0
+       case BT_CONNECTION_SPP_INITIATOR:
+               isAvailable = true;
+               break;
+
+       // The only one OPP client can be run per process.
+       case BT_CONNECTION_OPP_CLIENT:
+               isAvailable = true;
+               break;
+
+       default:
+               break;
+       }
+
+       return isAvailable;
+}
+
+Tizen::Base::String
+_BluetoothGapSystemAdapter::GetLocalDeviceAddress(void) const
+{
+       result r = E_SUCCESS;
+       int ret = 0;
+       ByteBuffer addressBuffer;
+       String localAddrString(_BT_ADDRESS_LENGTH*3);
+       char* pLocalAddr = null;
+
+       ret = bt_adapter_get_address(&pLocalAddr);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               localAddrString = String(pLocalAddr);
+       }
+       else
+       {
+               File file;
+               int bufLimit;
+               byte curByte;
+
+               // Opens the local cache file and gets the local address from it.
+               r = file.Construct(_BT_ADDRESS_FILE_PATH, L"r");
+               SysTryReturn(NID_NET_BT, r == E_SUCCESS, localAddrString, E_SYSTEM, "Construction of the address info file has failed.");
+
+               (void) file.Seek(FILESEEKPOSITION_BEGIN, 0);
+
+               addressBuffer.Construct(_BT_ADDRESS_LENGTH*3);
+               r = file.Read(addressBuffer);
+               SysTryReturn(NID_NET_BT, r == E_SUCCESS, localAddrString, E_SYSTEM, "Read the address from the info file has failed.");
+
+               bufLimit = addressBuffer.GetLimit();
+
+               for (int i = 0, addressIndex = 0 ; i < bufLimit ; i++)
+               {
+                       addressBuffer.GetByte(i, curByte);
+                       if ((curByte >= '0' && curByte <= '9') ||
+                               (curByte >= 'a' && curByte <= 'f') ||
+                               (curByte >= 'A' && curByte <= 'F'))
+                       {
+                               localAddrString.Append((char)curByte);
+                               addressIndex++;
+                               if ((addressIndex % 3 == 2) && (addressIndex < (_BT_ADDRESS_LENGTH * 3 - 1 )))
+                               {
+                                       // append ":" int the localAddrString to form a correct BT address format[aa:bb:cc:dd:ee:ff]
+                                       localAddrString.Append(':'); 
+                                       addressIndex++;
+                               }
+                       }
+               }
+
+               localAddrString.ToUpperCase();
+       }
+
+       return localAddrString;
+}
+
+BluetoothDiscoverableMode
+_BluetoothGapSystemAdapter::GetDiscoverableMode(void) const
+{
+       bt_adapter_visibility_mode_e visMode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
+       BluetoothDiscoverableMode discMode = BT_DISC_MODE_NOT_DISCOVERABLE;
+
+       // CONNECTABLE is actually not exactly the same as NONE mode but dealt with as the same values herein.
+       // TODO: resolve the problem about failure when the BT adapter is disabled
+       if (bt_adapter_get_visibility(&visMode, null)== BT_ERROR_NONE)
+       {
+               if (visMode == BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE)
+               {
+                       discMode = BT_DISC_MODE_DISCOVERABLE;
+               }
+               else if (visMode == BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE)
+               {
+                       if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+                       {
+                               discMode = BT_DISC_MODE_DISCOVERABLE;
+                       }
+                       else
+                       {
+                               discMode = BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE;
+                       }
+               }
+               // BT_DISC_MODE_NOT_DISCOVERABLE, otherwise.
+       }
+
+       return discMode;
+}
+
+int
+_BluetoothGapSystemAdapter::GetRemainingTimeAsDiscoverable(void) const
+{
+       bt_adapter_visibility_mode_e visMode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
+       int duration = 0;
+       int ret = 0;
+
+       ret = bt_adapter_get_visibility(&visMode, &duration);
+
+       if ((ret != BT_ERROR_NONE) || (visMode != BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE))
+       {
+               SysLog(NID_NET_BT, "Not the time-limited discoverable mode! Remaining time is 0.");
+       }
+
+       return duration;
+}
+
+Tizen::Base::Collection::IList*
+_BluetoothGapSystemAdapter::GetAllPairedDeviceListN(void) const
+{
+       ArrayList* pPairedDeviceList = null;
+       SysLog(NID_NET_BT, "Getting all paired device list...");
+
+       pPairedDeviceList = new (std::nothrow) ArrayList();
+
+       bt_adapter_state_e btAdapterState;
+       if (bt_adapter_get_state(&btAdapterState) == BT_ERROR_NONE)
+       {
+               if (btAdapterState == BT_ADAPTER_ENABLED)
+               {
+                       if (bt_adapter_foreach_bonded_device(&OnPairedDeviceFound, pPairedDeviceList) != BT_ERROR_NONE)
+                       {
+                               pPairedDeviceList->RemoveAll(true);
+                               delete pPairedDeviceList;
+                               return null;
+                       }
+               }
+               else //BT_ADAPTER_DISABLED
+               {
+                       SysLog(NID_NET_BT, "Cannot get the paired device list because the Bluetooth apdater is disabled!!");
+               }
+       }
+
+       return pPairedDeviceList;
+}
+
+result
+_BluetoothGapSystemAdapter::Pair(const Tizen::Base::ByteBuffer& deviceAddress)
+{
+       result r = E_SYSTEM;
+       char* pPairDevAddr = null;
+
+       SysTryReturnResult(NID_NET_BT, deviceAddress.GetRemaining() == _BT_ADDRESS_LENGTH, E_SYSTEM,
+                                               "The address of the remote device is incorrect.");
+
+       pPairDevAddr = _StringConverter::CopyToCharArrayN(_BluetoothDeviceImpl::GetAddressString(deviceAddress));
+       SysTryReturnResult(NID_NET_BT, pPairDevAddr != null, E_SYSTEM, "Address converting fails.");
+
+       if (bt_device_create_bond(pPairDevAddr) == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       SysLog(NID_NET_BT, "Pairing with [%ls] %s.", _BluetoothDeviceImpl::GetAddressString(deviceAddress).GetPointer(),
+                       r == E_SUCCESS ? "is successful" : "fails");
+
+       delete[] pPairDevAddr;
+       return r;
+}
+
+result
+_BluetoothGapSystemAdapter::CancelPair(void)
+{
+       result r = E_SYSTEM;
+
+       if (bt_device_cancel_bonding() == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       SysLog(NID_NET_BT, "Cancel of bonding %s.", r == E_SUCCESS ? "is successful" : "fails");
+
+       return r;
+}
+
+result
+_BluetoothGapSystemAdapter::Unpair(const Tizen::Base::ByteBuffer& deviceAddress)
+{
+       result r = E_SYSTEM;
+       char* pUnpairDevAddr = null;
+
+       SysTryReturnResult(NID_NET_BT, deviceAddress.GetRemaining() == _BT_ADDRESS_LENGTH, E_SYSTEM,
+                                               "The address of the remote device is incorrect.");
+
+       pUnpairDevAddr = _StringConverter::CopyToCharArrayN(_BluetoothDeviceImpl::GetAddressString(deviceAddress));
+       SysTryReturnResult(NID_NET_BT, pUnpairDevAddr != null, E_SYSTEM, "Address converting fails.");
+
+       if (bt_device_destroy_bond(pUnpairDevAddr) == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       SysLog(NID_NET_BT, "Unpairing with [%ls] %s.", _BluetoothDeviceImpl::GetAddressString(deviceAddress).GetPointer(),
+                       r == E_SUCCESS ? "is successful" : "fails");
+
+       delete[] pUnpairDevAddr;
+       return r;
+}
+
+bool
+_BluetoothGapSystemAdapter::IsPaired(const Tizen::Base::ByteBuffer& deviceAddress) const
+{
+       bool isPaired = false;
+       
+       if (deviceAddress.GetRemaining() != _BT_ADDRESS_LENGTH)
+       {
+               SysLog(NID_NET_BT, "The address of the remote device is incorrect.");
+               return false;
+       }
+
+       char* pRemoteDevAddress = _StringConverter::CopyToCharArrayN(_BluetoothDeviceImpl::GetAddressString(deviceAddress));
+       bt_device_info_s* pDeviceInfo = null;
+       
+       if (bt_adapter_get_bonded_device_info(pRemoteDevAddress, &pDeviceInfo) == BT_ERROR_NONE)
+       {
+               if (pDeviceInfo)
+               {
+                       if (pDeviceInfo->is_bonded)
+                       {
+                               isPaired = true;
+                       }
+                       bt_adapter_free_device_info(pDeviceInfo);
+               }
+       }
+
+       delete[] pRemoteDevAddress;
+       return isPaired;
+}
+
+result
+_BluetoothGapSystemAdapter::StartDiscovery(void)
+{
+       result r = E_SYSTEM;
+
+       if (bt_adapter_start_device_discovery() == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       SysLog(NID_NET_BT, "Start of discovery %s.", r == E_SUCCESS ? "is successful" : "fails");
+
+       return r;
+}
+
+result
+_BluetoothGapSystemAdapter::CancelDiscovery(void)
+{
+       result r = E_SYSTEM;
+
+       if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       SysLog(NID_NET_BT, "Cancel of discovery %s.", r == E_SUCCESS ? "is successful" : "fails");
+
+       return r;
+}
+
+bool
+_BluetoothGapSystemAdapter::IsDiscoveryInProgress(void) const
+{
+       bool is_discovering = false;
+
+       (void) bt_adapter_is_discovering(&is_discovering);
+
+       return is_discovering;
+}
+
+result
+_BluetoothGapSystemAdapter::RetrieveServiceList(const Tizen::Base::ByteBuffer& deviceAddress)
+{
+       result r = E_SYSTEM;
+       char* pDevAddr = null;
+
+       SysTryReturnResult(NID_NET_BT, deviceAddress.GetRemaining() == _BT_ADDRESS_LENGTH, E_SYSTEM,
+                                               "The address of the remote device is incorrect.");
+
+       pDevAddr = _StringConverter::CopyToCharArrayN(_BluetoothDeviceImpl::GetAddressString(deviceAddress));
+       SysTryReturnResult(NID_NET_BT, pDevAddr != null, E_SYSTEM, "Address converting fails.");
+
+       if (bt_device_start_service_search(pDevAddr) == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       SysLog(NID_NET_BT, "Retrieving the service list from [%ls] %s.",
+                       _BluetoothDeviceImpl::GetAddressString(deviceAddress).GetPointer(), r == E_SUCCESS ? "is successful" : "fails");
+
+       delete[] pDevAddr;
+       return r;
+}
+
+result
+_BluetoothGapSystemAdapter::GetPairedDevice(const ByteBuffer& address, BluetoothDevice& pairedDevice)
+{
+       int err = BT_ERROR_NONE;
+       unique_ptr<char[]> pDevAddr;
+       bt_device_info_s* pDeviceInfo = null;
+       unique_ptr<bt_device_info_s, _DeviceInfoDeleter> pDeviceInfoPtr;
+       _BluetoothDeviceImpl* pDevImpl = null;
+       String convertedName;
+
+       pDevAddr.reset(_StringConverter::CopyToCharArrayN(_BluetoothDeviceImpl::GetAddressString(address)));
+       SysTryReturnResult(NID_NET_BT, pDevAddr != null, E_SYSTEM, "Address converting fails.");
+
+       err = bt_adapter_get_bonded_device_info(pDevAddr.get(), &pDeviceInfo);
+       SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_SYSTEM, "Getting paired device infomation has failed.");
+       pDeviceInfoPtr.reset(pDeviceInfo);
+
+       pDevImpl = _BluetoothDeviceImpl::GetInstance(pairedDevice);
+
+       // converts the UTF8 multibyte string to Unicode String
+       (void) StringUtil::Utf8ToString(pDeviceInfoPtr->remote_name, convertedName);
+
+       pDevImpl->SetAddress(address);
+       pDevImpl->SetName(convertedName);
+       pDevImpl->SetPaired(pDeviceInfoPtr->is_bonded);
+       pDevImpl->SetMajorDeviceClassType(_BluetoothAdapterUtility::ConvertToMajorDeviceClassType(
+                       pDeviceInfoPtr->bt_class.major_device_class));
+       pDevImpl->SetMinorDeviceClassType(_BluetoothAdapterUtility::ConvertToMinorDeviceClassType(
+                       pDeviceInfoPtr->bt_class.major_device_class, pDeviceInfoPtr->bt_class.minor_device_class));
+       pDevImpl->SetServiceClassList(_BluetoothAdapterUtility::ConvertToServiceClassList(
+                       pDeviceInfoPtr->bt_class.major_service_class_mask));
+       pDevImpl->SetServiceList(_BluetoothAdapterUtility::ConvertToServiceList(
+                       pDeviceInfoPtr->service_uuid, pDeviceInfoPtr->service_count));
+       pDevImpl->SetServiceUuidList(_BluetoothAdapterUtility::ConvertServiceUuidListN(
+                       pDeviceInfoPtr->service_uuid, pDeviceInfoPtr->service_count), false);
+
+       return E_SUCCESS;
+}
+
+void
+_BluetoothGapSystemAdapter::OnAdapterStateChanged(int status, bt_adapter_state_e adapterState, void* pUserdata)
+{
+       result r = E_SUCCESS;
+       _IBluetoothManagerEventListener* pMgrEvtListener = null;
+       IEnumeratorT<_IBluetoothManagerEventListener*>* pEnum = null;
+       _BluetoothGapSystemAdapter* pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+
+       if (status != BT_ERROR_NONE)
+       {
+               r = E_SYSTEM;
+       }
+
+       pEnum = pGapAdapter->__mgrEvtListenerList.GetEnumeratorN();
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pEnum->GetCurrent(pMgrEvtListener);
+               if(adapterState == BT_ADAPTER_ENABLED)
+               {
+                       pMgrEvtListener->OnBluetoothActivated(r);
+               }
+               else
+               {
+                       pMgrEvtListener->OnBluetoothDeactivated(r);
+               }
+       }
+
+       delete pEnum;
+}
+
+void
+_BluetoothGapSystemAdapter::OnVisibilityModeChanged(int result, bt_adapter_visibility_mode_e mode, void* pUserdata)
+{
+       _IBluetoothManagerEventListener* pMgrEvtListener = null;
+       IEnumeratorT<_IBluetoothManagerEventListener*>* pEnum = null;
+       _BluetoothGapSystemAdapter* pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       BluetoothDiscoverableMode changedMode = BT_DISC_MODE_NOT_DISCOVERABLE;
+
+       if (result == BT_ERROR_NONE)
+       {
+               switch (mode)
+               {
+               case BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE:
+                       changedMode = BT_DISC_MODE_NOT_DISCOVERABLE;
+                       break;
+
+               case BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE:
+                       changedMode = BT_DISC_MODE_DISCOVERABLE;
+                       break;
+
+               case BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE:
+                       changedMode = BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE;
+                       break;
+
+               default:
+                       return;
+               }
+
+               pEnum = pGapAdapter->__mgrEvtListenerList.GetEnumeratorN();
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetCurrent(pMgrEvtListener);
+                       pMgrEvtListener->OnBluetoothDiscoverableModeChanged(changedMode);
+               }
+
+               delete pEnum;
+       }
+}
+
+void
+_BluetoothGapSystemAdapter::OnDeviceDiscoveryStateChanged(int status, bt_adapter_device_discovery_state_e discoveryState,
+                                                               bt_adapter_device_discovery_info_s* pDiscoveryInfo, void* pUserData)
+{
+       result r = E_SUCCESS;
+       _IBluetoothDeviceEventListener* pDevEventListener = null;
+       IEnumeratorT<_IBluetoothDeviceEventListener*>* pEnum = null;
+       _BluetoothGapSystemAdapter* pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+
+       pEnum = pGapAdapter->__devEvtListenerList.GetEnumeratorN();
+
+       switch(discoveryState)
+       {
+       case BT_ADAPTER_DEVICE_DISCOVERY_STARTED:
+       {
+               if (status != BT_ERROR_NONE)
+               {
+                       r = E_SYSTEM;
+               }
+
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetCurrent(pDevEventListener);
+                       pDevEventListener->OnBluetoothDiscoveryStarted(r);
+               }
+       }
+               break;
+
+       case BT_ADAPTER_DEVICE_DISCOVERY_FOUND:
+       {
+               BluetoothDevice foundDevice;
+               ByteBuffer deviceAddress;
+               deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+               String convertedName;
+
+               String tempDevAddr(pDiscoveryInfo->remote_address);
+               _BluetoothDeviceImpl::GetAddressByteBuffer(tempDevAddr, L":", deviceAddress);
+
+               // converts the UTF8 multibyte string to Unicode String
+               (void) StringUtil::Utf8ToString(pDiscoveryInfo->remote_name, convertedName);
+
+               _BluetoothDeviceImpl* pDevImpl = _BluetoothDeviceImpl::GetInstance(foundDevice);
+
+               pDevImpl->SetAddress(deviceAddress);
+               pDevImpl->SetName(convertedName);
+               pDevImpl->SetPaired(pDiscoveryInfo->is_bonded);
+               pDevImpl->SetRssi(pDiscoveryInfo->rssi);
+               pDevImpl->SetMajorDeviceClassType(_BluetoothAdapterUtility::ConvertToMajorDeviceClassType(
+                               pDiscoveryInfo->bt_class.major_device_class));
+               pDevImpl->SetMinorDeviceClassType(_BluetoothAdapterUtility::ConvertToMinorDeviceClassType(
+                               pDiscoveryInfo->bt_class.major_device_class, pDiscoveryInfo->bt_class.minor_device_class));
+               pDevImpl->SetServiceClassList(_BluetoothAdapterUtility::ConvertToServiceClassList(
+                               pDiscoveryInfo->bt_class.major_service_class_mask));
+               pDevImpl->SetServiceList(_BluetoothAdapterUtility::ConvertToServiceList(
+                               pDiscoveryInfo->service_uuid, pDiscoveryInfo->service_count));
+               pDevImpl->SetServiceUuidList(_BluetoothAdapterUtility::ConvertServiceUuidListN(
+                               pDiscoveryInfo->service_uuid, pDiscoveryInfo->service_count), false);
+
+               _BluetoothAdapterUtility::PrintDeviceInfo(foundDevice);
+
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetCurrent(pDevEventListener);
+                       pDevEventListener->OnBluetoothRemoteDeviceFound(foundDevice);
+               }
+       }
+               break;
+
+       case BT_ADAPTER_DEVICE_DISCOVERY_FINISHED:
+       {
+               bool isCompleted = false;
+
+               if (status == BT_ERROR_NONE)
+               {
+                       isCompleted = true; // isCompleted is false in other cases including BT_ERROR_CANCEL
+               }
+
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetCurrent(pDevEventListener);
+                       pDevEventListener->OnBluetoothDiscoveryDone(isCompleted);
+               }
+       }
+               break;
+
+       default:
+               break;
+       }
+
+       delete pEnum;
+}
+
+void
+_BluetoothGapSystemAdapter::OnServiceDiscoveryCompleted(int status, bt_device_sdp_info_s* pSdpInfo, void* pUserData)
+{
+       result r = E_SUCCESS;
+       _IBluetoothDeviceEventListener* pDevEventListener = null;
+       IEnumeratorT<_IBluetoothDeviceEventListener*>* pEnum = null;
+       ByteBuffer deviceAddress;
+       deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+       unsigned long serviceList = 0;
+       Tizen::Base::Collection::IList* pServiceUuidList= null;
+       _BluetoothGapSystemAdapter* pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+
+       String tempDevAddr(pSdpInfo->remote_address);
+       r = _BluetoothDeviceImpl::GetAddressByteBuffer(tempDevAddr, L":", deviceAddress);
+
+       if (status != BT_ERROR_NONE)
+       {
+               r = E_SYSTEM;
+       }
+       else
+       {
+               pServiceUuidList = _BluetoothAdapterUtility::ConvertServiceUuidListN(
+                               pSdpInfo->service_uuid, pSdpInfo->service_count);
+               if (pServiceUuidList == null)
+               {
+                       r = E_SYSTEM;
+               }
+               else
+               {
+                       serviceList = _BluetoothAdapterUtility::ConvertToServiceList(pSdpInfo->service_uuid, pSdpInfo->service_count);
+                       SysLog(NID_NET_BT, "Searched Service List =================");
+                       _BluetoothAdapterUtility::PrintServiceList(serviceList);
+
+                       SysLog(NID_NET_BT, "Searched Service UUID List ============");
+                       _BluetoothAdapterUtility::PrintServiceUuidList(pServiceUuidList);
+               }
+       }
+
+       pEnum = pGapAdapter->__devEvtListenerList.GetEnumeratorN();
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pEnum->GetCurrent(pDevEventListener);
+               pDevEventListener->OnBluetoothServiceListReceived(deviceAddress, serviceList, pServiceUuidList, r);
+       }
+
+       delete pEnum;
+       // The ownership of UuId instances in the list is transferred to _BluetoothDeviceEventArg.
+       // Therefore, only the list except its elements is deleted here.
+       delete pServiceUuidList;
+}
+
+void
+_BluetoothGapSystemAdapter::OnPairingCompleted(int status, bt_device_info_s* pDeviceInfo, void* pUserdata)
+{
+       result r = E_SUCCESS;
+       _IBluetoothDeviceEventListener* pDevEventListener = null;
+       IEnumeratorT<_IBluetoothDeviceEventListener*>* pEnum = null;
+       BluetoothDevice pairingDevice;
+       _BluetoothGapSystemAdapter* pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       ByteBuffer deviceAddress;
+       deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+       String convertedName;
+
+       SysTryReturnVoidResult(NID_NET_BT, pDeviceInfo != null, E_SYSTEM,
+                       "[E_SYSTEM] the input param, DeviceInfo on callback is null.");
+
+       String tempDevAddr(pDeviceInfo->remote_address);
+       (void) _BluetoothDeviceImpl::GetAddressByteBuffer(tempDevAddr, L":", deviceAddress);
+
+       // converts the UTF8 multibyte string to Unicode String
+       (void) StringUtil::Utf8ToString(pDeviceInfo->remote_name, convertedName);
+
+       _BluetoothDeviceImpl* pDevImpl = _BluetoothDeviceImpl::GetInstance(pairingDevice);
+
+       pDevImpl->SetAddress(deviceAddress);
+       pDevImpl->SetName(convertedName);
+       pDevImpl->SetPaired(true);
+       pDevImpl->SetRssi(0);
+       pDevImpl->SetMajorDeviceClassType(_BluetoothAdapterUtility::ConvertToMajorDeviceClassType(
+                       pDeviceInfo->bt_class.major_device_class));
+       pDevImpl->SetMinorDeviceClassType(_BluetoothAdapterUtility::ConvertToMinorDeviceClassType(
+                       pDeviceInfo->bt_class.major_device_class, pDeviceInfo->bt_class.minor_device_class));
+       pDevImpl->SetServiceClassList(_BluetoothAdapterUtility::ConvertToServiceClassList(
+                       pDeviceInfo->bt_class.major_service_class_mask));
+       pDevImpl->SetServiceList(_BluetoothAdapterUtility::ConvertToServiceList(
+                       pDeviceInfo->service_uuid, pDeviceInfo->service_count));
+       pDevImpl->SetServiceUuidList(_BluetoothAdapterUtility::ConvertServiceUuidListN(
+                       pDeviceInfo->service_uuid, pDeviceInfo->service_count), false);
+
+       switch (status)
+       {
+       case BT_ERROR_NONE:
+               r = E_SUCCESS;
+               break;
+       case BT_ERROR_CANCELLED:
+               r = E_OPERATION_CANCELED;
+               break;
+       case BT_ERROR_TIMED_OUT:
+               r = E_TIMEOUT;
+               break;
+       default:
+               r = E_OPERATION_FAILED;
+               break;
+       }
+
+       pEnum = pGapAdapter->__devEvtListenerList.GetEnumeratorN();
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pEnum->GetCurrent(pDevEventListener);
+               pDevEventListener->OnBluetoothPaired(&pairingDevice, r);
+       }
+       delete pEnum;
+}
+
+void
+_BluetoothGapSystemAdapter::OnPairedDeviceRemoved(int status, char* pRemoteAddress, void* pUserData)
+{
+       _IBluetoothDeviceEventListener* pDevEventListener = null;
+       IEnumeratorT<_IBluetoothDeviceEventListener*>* pEnum = null;
+       _BluetoothGapSystemAdapter* pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       ByteBuffer deviceAddress;
+       deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+
+       if (status == BT_ERROR_NONE)
+       {
+               String tempDevAddr(pRemoteAddress);
+               _BluetoothDeviceImpl::GetAddressByteBuffer(tempDevAddr, L":", deviceAddress);
+
+               pEnum = pGapAdapter->__devEvtListenerList.GetEnumeratorN();
+
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetCurrent(pDevEventListener);
+                       pDevEventListener->OnBluetoothUnpaired(deviceAddress);
+               }
+
+               delete pEnum;
+       }
+       else
+       {
+               SysLog(NID_NET_BT, "Error in removing the Paired Device is %d", status);
+       }
+}
+
+bool
+_BluetoothGapSystemAdapter::OnPairedDeviceFound(bt_device_info_s* pDeviceInfo, void* pUserdata)
+{
+       ArrayList* pPairedDeviceList = static_cast<ArrayList*>(pUserdata);
+
+       ByteBuffer btAddress;
+       btAddress.Construct(_BT_ADDRESS_LENGTH);
+       BluetoothDevice* pPairedDevice = null;
+       String convertedName;
+
+       pPairedDevice = new (std::nothrow) BluetoothDevice();
+       SysTryReturn(NID_NET_BT, pPairedDevice != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       String tempDevAddr(pDeviceInfo->remote_address);
+       _BluetoothDeviceImpl::GetAddressByteBuffer(tempDevAddr, L":", btAddress);
+
+       // converts the UTF8 multibyte string to Unicode String
+       (void) StringUtil::Utf8ToString(pDeviceInfo->remote_name, convertedName);
+
+       SysLog(NID_NET_BT, "Paired Device - (name: %ls)", convertedName.GetPointer());
+
+       _BluetoothDeviceImpl* pDevImpl = _BluetoothDeviceImpl::GetInstance(*pPairedDevice);
+
+       pDevImpl->SetAddress(btAddress);
+       pDevImpl->SetName(convertedName);
+       pDevImpl->SetPaired(true);
+       pDevImpl->SetRssi(0);
+       pDevImpl->SetMajorDeviceClassType(_BluetoothAdapterUtility::ConvertToMajorDeviceClassType(
+                       pDeviceInfo->bt_class.major_device_class));
+       pDevImpl->SetMinorDeviceClassType(_BluetoothAdapterUtility::ConvertToMinorDeviceClassType(
+                       pDeviceInfo->bt_class.major_device_class, pDeviceInfo->bt_class.minor_device_class));
+       pDevImpl->SetServiceClassList(_BluetoothAdapterUtility::ConvertToServiceClassList(
+                       pDeviceInfo->bt_class.major_service_class_mask));
+       pDevImpl->SetServiceList(_BluetoothAdapterUtility::ConvertToServiceList(
+                       pDeviceInfo->service_uuid, pDeviceInfo->service_count));
+       pDevImpl->SetServiceUuidList(_BluetoothAdapterUtility::ConvertServiceUuidListN(
+                       pDeviceInfo->service_uuid, pDeviceInfo->service_count), false);
+
+       pPairedDeviceList->Add(*pPairedDevice);
+
+       return true;
+}
+
+void
+_BluetoothGapSystemAdapter::OnConnectionStateChanged(bool isConnected, const char* pRemoteAddress, void* pUserdata)
+{
+       _IBluetoothDeviceEventListener* pDevEventListener = null;
+       IEnumeratorT<_IBluetoothDeviceEventListener*>* pEnum = null;
+       _BluetoothGapSystemAdapter* pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       ByteBuffer deviceAddress;
+       deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+
+       String tempDevAddr(pRemoteAddress);
+       _BluetoothDeviceImpl::GetAddressByteBuffer(tempDevAddr, L":", deviceAddress);
+
+       pEnum = pGapAdapter->__devEvtListenerList.GetEnumeratorN();
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pEnum->GetCurrent(pDevEventListener);
+               if (isConnected)
+               {
+                       pDevEventListener->OnBluetoothDeviceConnected(deviceAddress);
+               }
+               else
+               {
+                       pDevEventListener->OnBluetoothDeviceDisconnected(deviceAddress);
+               }
+       }
+
+       delete pEnum;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothGapSystemAdapter.h b/src/FNetBt_BluetoothGapSystemAdapter.h
new file mode 100644 (file)
index 0000000..68d5798
--- /dev/null
@@ -0,0 +1,323 @@
+//
+// 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    FNetBt_BluetoothGapSystemAdapter.h
+ * @brief   This is the header file for the _BluetoothGapSystemAdapter class.
+ *
+ * This header file contains the declaration of the _BluetoothGapSystemAdapter class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_
+
+#include <bluetooth.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseColLinkedListT.h>
+#include <FNetBtBluetoothTypes.h>
+
+static const int _BT_ADDRESS_LENGTH = 6;
+
+// forward declarations
+namespace Tizen { namespace Base { namespace Collection
+{
+class IList;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class _IBluetoothDeviceEventListener;
+class _IBluetoothManagerEventListener;
+class _BluetoothIpcProxy;
+
+/**
+ * @class   _BluetoothGapSystemAdapter
+ * @brief   This class provides functions related to deliver the system events to the listeners such as
+ *          _BluetoothManagerImpl. This class is a type of singleton, therefore only one instance should be allowed.
+ */
+class _BluetoothGapSystemAdapter
+       : 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 _BluetoothGapSystemAdapter* GetInstance(void);
+
+
+       /**
+        * Register an instance of _IBluetoothManagerEventListener interface into the internal list.
+        *
+        * @return      An error code
+        * @param[in]   listener                The instance of _IBluetoothManagerEventListener to be registered
+        * @param[in]   isHighPriority          Set to @c true to register with the high priority, @n
+        *                                      else @c false
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        */
+       result RegisterManagerEventListener(const _IBluetoothManagerEventListener& listener, bool isHighPriority);
+
+       /**
+        * Unregister an instance of _IBluetoothManagerEventListener interface from the internal list.
+        *
+        * @return      An error code
+        * @param[in]   listener                The instance of _IBluetoothManagerEventListener to be unregistered
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OBJ_NOT_FOUND         The input instance is not registered.
+        */
+       result UnregisterManagerEventListener(const _IBluetoothManagerEventListener& listener);
+
+       /**
+        * Register an instance of _IBluetoothDeviceEventListener interface into the internal list.
+        *
+        * @return      An error code
+        * @param[in]   listener                The instance of _IBluetoothDeviceEventListener to be registered
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        */
+       result RegisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener);
+
+       /**
+        * Unregister an instance of _IBluetoothDeviceEventListener interface from the internal list.
+        *
+        * @return      An error code
+        * @param[in]   listener                The instance of _IBluetoothDeviceEventListener to be unregistered
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OBJ_NOT_FOUND         The input instance is not registered.
+        */
+       result UnregisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener);
+
+       /**
+        * Activates %Bluetooth module.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        */
+       result Activate(void);
+
+       /**
+        * Deactivates %Bluetooth module.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        */
+       result Deactivate(void);
+
+       /**
+        * Checks whether the %Bluetooth is activated or not.
+        *
+        * @return       @c true, if activated @n
+        *               @c false, otherwise
+        */
+       bool IsActivated(void) const;
+
+       /**
+        * Checks if the Bluetooth-specific profile is available.
+        *
+        * @return      @c true if connection is available @n
+        *              @c false, otherwise
+        * @param[in]   type                    The connection type to check availability
+        */
+       bool IsAvailable(BluetoothConnectionType type) const;
+
+       /**
+        * Gets the local %Bluetooth device address.
+        *
+        * @return      The local %Bluetooth device address
+        */
+       Tizen::Base::String GetLocalDeviceAddress(void) const;
+
+       /**
+        * Gets the discoverable mode of the local device.
+        *
+        * @return       The discoverable mode of the local device
+        */
+       BluetoothDiscoverableMode GetDiscoverableMode(void) const;
+
+       /**
+        * Gets the remaining time, in seconds, until the local device is not discoverable.
+        *
+        * @return      The remaining time, in seconds, until the local device to be not discoverable.
+        */
+       int GetRemainingTimeAsDiscoverable(void) const;
+
+       /**
+        * Gets all Paired Device list.
+        *
+        * @return       Pointer to the paired device list on success @n
+        *               @c null, otherwise.
+        * @remarks      It is caller's responsibility that deletes the result list.
+        */
+       Tizen::Base::Collection::IList* GetAllPairedDeviceListN(void) const;
+
+       /**
+        * Pairs(Bonds) with the specified remote device.
+        *
+        * @return      An error code
+        * @param[in]   deviceAddress           The address of a remote device to pair with
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       result Pair(const Tizen::Base::ByteBuffer& deviceAddress);
+
+       /**
+        * Cancels the pairing in progress.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       result CancelPair(void);
+
+       /**
+        * Unpairs(Unbonds) with the specified paired device.
+        *
+        * @return      An error code
+        * @param[in]   deviceAddress           The address of the paired device to unpair with
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       result Unpair(const Tizen::Base::ByteBuffer& deviceAddress);
+
+       /**
+        * Checks if this device is paired with the specified remote device.
+        *
+        * @return      @c true if the device is paired @n
+        *              @c false, otherwise
+        * @param[in]   deviceAddress           The address of a remote device to check
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       bool IsPaired(const Tizen::Base::ByteBuffer& deviceAddress) const;
+
+       /**
+        * Starts a device discovery process.
+        *
+        * @return       An error code
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_SYSTEM               A system error occurred.
+        */
+       result StartDiscovery(void);
+
+       /**
+        * Stops the discovery in progress.
+        *
+        * @return       An error code
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_SYSTEM               A system error occurred.
+        */
+       result CancelDiscovery(void);
+
+       /**
+        * Checks whether the device discovery is in progress or not.
+        *
+        * @return       @c true, if in progress @n
+        *               @c false, otherwise
+        */
+       bool IsDiscoveryInProgress(void) const;
+
+       /**
+        * Retrieves the service list from a remote device.
+        *
+        * @return       An error code
+        * @param[in]    deviceAddress          The address of a remote device which the service list is retrieved from
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_SYSTEM               A system error occurred.
+        */
+       result RetrieveServiceList(const Tizen::Base::ByteBuffer& deviceAddress);
+
+
+       /**
+        * Gets the information of the specified paired device.
+        *
+        * @return       An error code
+        * @param[in]    address                The address of a paired device
+        * @param[out]   pairedDevice           The remote device instance whose information to be filled in
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_SYSTEM               A system error occurred.
+        */
+       static result GetPairedDevice(const Tizen::Base::ByteBuffer& address, BluetoothDevice& pairedDevice);
+
+       /**
+        * Callback to notify the change in the state of Bluetooth adapter.
+        */
+       static void OnAdapterStateChanged(int status, bt_adapter_state_e adapterState, void* pUserdata);
+
+       /**
+        * Callback to notify the change in the visibility mode of Bluetooth adapter.
+        */
+       static void OnVisibilityModeChanged(int result, bt_adapter_visibility_mode_e mode, void* pUserdata);
+
+       /**
+        * Callback to notify when you get bonded devices repeatedly.
+        */
+       static bool OnPairedDeviceFound(bt_device_info_s* pDeviceInfo, void* pUserdata);
+
+       /**
+        * Callback to notify when the state of the device discovery changes.
+        */
+       static void OnDeviceDiscoveryStateChanged(int status, bt_adapter_device_discovery_state_e discoveryState,
+                                                               bt_adapter_device_discovery_info_s* pDiscoveryInfo, void* pUserdata);
+
+       /**
+        * Callback to notify when the process of service discovery is completed.
+        */
+       static void OnServiceDiscoveryCompleted(int status, bt_device_sdp_info_s* pSdpInfo, void* pUserdata);
+
+       /**
+        * Callback to notify that a new remote device is paired with this local device.
+        */
+       static void OnPairingCompleted(int status, bt_device_info_s* pDeviceInfo, void* pUserdata);
+
+       /**
+        * Callback to notify that the already paired device is unpaired with this local device.
+        */
+       static void OnPairedDeviceRemoved(int status, char* pRemoteAddress, void* pUserdata);
+
+       /**
+        * Callback to notify when the state of the device connection changes.
+        */
+       static void OnConnectionStateChanged(bool isConnected, const char* pRemoteAddress, void* pUserdata);
+
+
+private:
+       _BluetoothGapSystemAdapter(void);
+       ~_BluetoothGapSystemAdapter(void);
+
+       _BluetoothGapSystemAdapter(const _BluetoothGapSystemAdapter& value);
+       _BluetoothGapSystemAdapter& operator =(const _BluetoothGapSystemAdapter& value);
+
+       bool Construct(void);
+
+       static void InitSingleton(void);
+
+private:
+       Tizen::Base::Collection::LinkedListT<_IBluetoothManagerEventListener*> __mgrEvtListenerList;
+       Tizen::Base::Collection::LinkedListT<_IBluetoothDeviceEventListener*> __devEvtListenerList;
+       static _BluetoothGapSystemAdapter* __pInstance;
+
+}; // _BluetoothGapSystemAdapter
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_
diff --git a/src/FNetBt_BluetoothHdpSystemAdapter.cpp b/src/FNetBt_BluetoothHdpSystemAdapter.cpp
new file mode 100755 (executable)
index 0000000..0ea320a
--- /dev/null
@@ -0,0 +1,439 @@
+//
+// 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        FNetBt_BluetoothHdpSystemAdapter.cpp
+// @brief       This is the implementation file for the _BluetoothHdpSystemAdapter class.
+//
+
+#include <pthread.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseString.h>
+#include <FBaseColHashMapT.h>
+#include <FBaseColIComparerT.h>
+#include <FBaseColIHashCodeProviderT.h>
+#include <FBaseUtilStringUtil.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include "FNetBt_BluetoothHealthImpl.h"
+#include "FNetBt_BluetoothHdpSystemAdapter.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothDeviceImpl.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/*
+ * @class              _BluetoothAddressComparer
+ * @brief              The _BluetoothAddressComparer class provides the comparer about two specified String
+ *              which consists of Bluetooth address and service UUID.
+ */
+class _BluetoothAddressComparer
+       : public Tizen::Base::Collection::IComparerT <Tizen::Base::String>
+       , public Tizen::Base::Object
+{
+public:
+       _BluetoothAddressComparer(void) {}
+       virtual ~_BluetoothAddressComparer(void) {}
+
+       virtual result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
+       {
+               cmp = obj1.CompareTo(obj2);
+               return E_SUCCESS;
+       }
+
+private:
+       _BluetoothAddressComparer(const _BluetoothAddressComparer& value);
+       _BluetoothAddressComparer& operator =(const _BluetoothAddressComparer& value);
+
+};     //_BluetoothAddressComparer
+
+/*
+ * @class              _BluetoothAddressHashCodeProviderT
+ * @brief              The _BluetoothAddressHashCodeProviderT class provides the hash code of a specified String
+ *              which consists of Bluetooth address and service UUID.
+ */
+class _BluetoothAddressHashCodeProvider
+       : public Tizen::Base::Collection::IHashCodeProviderT <Tizen::Base::String>
+{
+public:
+       _BluetoothAddressHashCodeProvider(void) {}
+       virtual ~_BluetoothAddressHashCodeProvider(void) {}
+       virtual int GetHashCode(const Tizen::Base::String& obj) const
+       {
+               return obj.GetHashCode();
+       }
+
+private:
+       _BluetoothAddressHashCodeProvider(const _BluetoothAddressHashCodeProvider& value);
+       _BluetoothAddressHashCodeProvider& operator =(const _BluetoothAddressHashCodeProvider& value);
+
+};     //_BluetoothAddressHashCodeProvider
+
+
+static _BluetoothAddressComparer _btAddressComparer;
+static _BluetoothAddressHashCodeProvider _btAddressHashCodeProvider;
+
+_BluetoothHdpSystemAdapter* _BluetoothHdpSystemAdapter::__pInstance = null;
+
+_BluetoothHdpSystemAdapter::_BluetoothHdpSystemAdapter(void)
+       : __pAppHealthMap(null)
+       , __pChannelHealthMap(null)
+       , __pChannelAddressMap(null)
+{
+}
+
+_BluetoothHdpSystemAdapter::~_BluetoothHdpSystemAdapter(void)
+{
+       // unregister the callback methods from the underlying layer
+       int err = bt_hdp_unset_connection_state_changed_cb();
+       SysLog(NID_NET_BT, "[0x%x] error in unregistering the connection state change callback method", err);
+
+       err = bt_hdp_unset_data_received_cb();
+       SysLog(NID_NET_BT, "[0x%x] error in unregistering the data received state change callback method", err);
+}
+
+void
+_BluetoothHdpSystemAdapter::InitSingleton(void)
+{
+       bool r = false;
+       static _BluetoothHdpSystemAdapter inst;
+
+       r = inst.Construct();
+       SysTryReturnVoidResult(NID_NET_BT, r == true, E_SYSTEM, "[E_SYSTEM] Propagating.");
+
+       __pInstance = &inst;
+}
+
+_BluetoothHdpSystemAdapter*
+_BluetoothHdpSystemAdapter::GetInstance(void)
+{
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (__pInstance == null)
+       {
+               ClearLastResult();
+               pthread_once(&onceBlock, InitSingleton);
+               result r = GetLastResult();
+               if (IsFailed(r))
+               {
+                       onceBlock = PTHREAD_ONCE_INIT;
+               }
+       }
+
+       return __pInstance;
+}
+
+bool
+_BluetoothHdpSystemAdapter::Construct(void)
+{
+       int err = BT_ERROR_NONE;
+       result r = E_SUCCESS;
+       unique_ptr<Tizen::Base::Collection::HashMapT< Tizen::Base::String, _BluetoothHealthImpl*> > pAppHealthMap;
+       unique_ptr<Tizen::Base::Collection::HashMapT< int, _BluetoothHealthImpl*> > pChannelHealthMap;
+       unique_ptr<Tizen::Base::Collection::HashMapT< int, Tizen::Base::String> > pChannelAddressMap;
+
+       pAppHealthMap.reset(new (std::nothrow) HashMapT<String, _BluetoothHealthImpl*>);
+       SysTryReturn(NID_NET_BT, pAppHealthMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       //Constructing the hashmap template with the default capacity(16) and loadFactor(0.75f)
+       r = pAppHealthMap->Construct(16, 0.75f, _btAddressHashCodeProvider, _btAddressComparer);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       pChannelHealthMap.reset(new (std::nothrow) HashMapT<int, _BluetoothHealthImpl*>);
+       SysTryReturn(NID_NET_BT, pChannelHealthMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       r = pChannelHealthMap->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       pChannelAddressMap.reset(new (std::nothrow) HashMapT<int, String>);
+       SysTryReturn(NID_NET_BT, pChannelAddressMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       r = pChannelAddressMap->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       //register a call back to be invoked when connection state of the Sink device changes
+       err = bt_hdp_set_connection_state_changed_cb(&OnHdpConnected, &OnHdpDisconnected, null);
+       SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");
+
+       //register a callback to be invoked when any health data is received by the Sink device
+       err = bt_hdp_set_data_received_cb(&OnHdpDataReceived, null);
+       if (err != BT_ERROR_NONE)
+       {
+               int errUnset = bt_hdp_unset_connection_state_changed_cb();
+               SysLog(NID_NET_BT, "[0x%x] error in unregistering the connection state change callback method", errUnset);
+       }
+       SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");
+
+       __pAppHealthMap = move(pAppHealthMap);
+       __pChannelHealthMap = move(pChannelHealthMap);
+       __pChannelAddressMap = move(pChannelAddressMap);
+
+       return true;
+}
+
+result
+_BluetoothHdpSystemAdapter::StartSinkService(int dataType, _BluetoothHealthImpl& implListener, char** pAppId)
+{
+       result r = E_OPERATION_FAILED;
+       int err = BT_ERROR_NONE;
+
+       char* pUuidStr;
+       bool isUsed = false;
+
+       // check HDP service availability
+       pUuidStr = _StringConverter::CopyToCharArrayN(UuId(BT_SVC_UUID_HDP).ToString());
+       err = bt_adapter_is_service_used(pUuidStr, &isUsed);
+       delete[] pUuidStr;
+       SysTryReturnResult(NID_NET_BT, (err == BT_ERROR_NONE) && !isUsed, E_SERVICE_UNAVAILABLE,
+                       "[E_SERVICE_UNAVAILABLE] HDP sink service for the specified UUID is not available.");
+
+       err = bt_hdp_register_sink_app(dataType, pAppId);
+       SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Registering Sink role application for specified HDP data type is failed");
+       SysLog(NID_NET_BT, "Registering the HDP Sink role is successful [%d].", err);
+
+       String appIdString(*pAppId);
+
+       // Add the _BluetoothHealthImpl pointer to the event map using appIdString as the key.
+       r = __pAppHealthMap->Add(appIdString, &implListener);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Failed to add the _BluetoothHealthImpl instance to the map");
+       return E_SUCCESS;
+}
+
+result
+_BluetoothHdpSystemAdapter::StopService(const char* pAppId)
+{
+       int err = BT_ERROR_NONE;
+       result r = E_OPERATION_FAILED;
+
+       String appIdString(pAppId);
+
+       err = bt_hdp_unregister_sink_app(pAppId);
+       SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Failed to unregister the given Sink Role HDP application");
+       SysLog(NID_NET_BT, "The Sink role HDP app is successfully unregistered");
+
+       // remove the specified appIdString from the application event map.
+       r = __pAppHealthMap->Remove(appIdString);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] failed to remove the appId from the event map.");
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothHdpSystemAdapter::ConnectToSource(const Tizen::Base::ByteBuffer& sourceAddress, const char* pAppId)
+{
+       int err = BT_ERROR_NONE;
+       result r = E_OPERATION_FAILED;
+
+       char* pSourceAddress = null;
+
+       SysTryReturnResult(NID_NET_BT, sourceAddress.GetRemaining() == _BT_ADDRESS_LENGTH, E_OPERATION_FAILED,
+                                               "The address of the remote Source device is incorrect.");
+
+       pSourceAddress = _StringConverter::CopyToCharArrayN(_BluetoothDeviceImpl::GetAddressString(sourceAddress));
+       SysTryReturnResult(NID_NET_BT, pSourceAddress != null, E_OPERATION_FAILED, "Converting address to char* fails.");
+
+       err = bt_hdp_connect_to_source(pSourceAddress, pAppId);
+       SysLog(NID_NET_BT, "Connecting to the remote source device  [%s] %s.", pSourceAddress,
+                                               err == BT_ERROR_NONE ? "is successful" : "fails");
+       if (err == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       delete[] pSourceAddress;
+       return r;
+}
+
+result
+_BluetoothHdpSystemAdapter::Disconnect(int channelId)
+{
+       int err = BT_ERROR_NONE;
+       result r = E_OPERATION_FAILED;
+
+       String connectedAddress;
+       char* pSourceAddress = null;
+
+       r = __pChannelAddressMap->GetValue(channelId, connectedAddress);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "The channel ID is invalid.");
+
+       pSourceAddress = _StringConverter::CopyToCharArrayN(connectedAddress);
+       SysTryReturnResult(NID_NET_BT, pSourceAddress != null, E_OPERATION_FAILED, "Address converting fails.");
+
+       err = bt_hdp_disconnect(pSourceAddress, channelId);
+       SysLog(NID_NET_BT, "Disconnecting from the remote source device [%s] with channel id [%d] %s.", pSourceAddress, channelId,
+                                               err == BT_ERROR_NONE ? "is successful" : "fails");
+       if (err == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       delete[] pSourceAddress;
+       return r;
+}
+
+result
+_BluetoothHdpSystemAdapter::SendData(int channelId, const Tizen::Base::ByteBuffer& data)
+{
+       int err = BT_ERROR_NONE;
+       result r = E_OPERATION_FAILED;
+
+       const byte* pHealthData = null;
+       int healthDataLength = 0;
+
+       pHealthData = data.GetPointer();
+       pHealthData += data.GetPosition();
+       healthDataLength = data.GetRemaining();
+
+       err = bt_hdp_send_data(channelId, (char*)pHealthData, healthDataLength);
+       SysLog(NID_NET_BT, "Sending data to the remote source with channel id [%d] of length [%d] %s.", channelId, healthDataLength,
+                                               err == BT_ERROR_NONE ? "is successful" : "fails");
+       if (err == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       return r;
+}
+
+void
+_BluetoothHdpSystemAdapter::OnHdpConnected(int status, const char* pRemoteAddress, const char* pAppId,
+               bt_hdp_channel_type_e channelType, unsigned int channelId, void* pUserData)
+{
+       result r = E_OPERATION_FAILED;
+
+       BluetoothDevice btDevice;
+       ByteBuffer deviceAddress;
+       String remoteDeviceAddrStr(pRemoteAddress);
+       BluetoothHealthDataChannelType hdpchannelType = BT_HEALTH_DATA_CHANNEL_NONE;
+
+       _BluetoothHealthImpl* pHealthImpl = null;
+       String appIdString(pAppId);
+
+       _BluetoothHdpSystemAdapter* pHdpAdapter = _BluetoothHdpSystemAdapter::GetInstance();
+
+       // retrieve the _BluetoothHealthImpl instance from the __pAppHealthMap by using appIdString as key
+       r = pHdpAdapter->__pAppHealthMap->GetValue(appIdString, pHealthImpl);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] The application Id is unknown.");
+
+       r = deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Failed to construct the address buffer");
+
+       (void) _BluetoothDeviceImpl::GetAddressByteBuffer(remoteDeviceAddrStr, L":", deviceAddress);
+
+       r = _BluetoothGapSystemAdapter::GetPairedDevice(deviceAddress, btDevice);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Getting information of the source health device has failed.");
+
+       if (status == BT_ERROR_NONE)
+       {
+               // insert the pHealthImpl into __pChannelHealthMap by using the specified channelId as key
+               r = pHdpAdapter->__pChannelHealthMap->Add(channelId, pHealthImpl);
+               if (r != E_SUCCESS)
+               {
+                       SysLogException(NID_NET_BT, E_OPERATION_FAILED, "[%s] Propagating.", GetErrorMessage(r));
+                       r = E_OPERATION_FAILED;
+               }
+
+               // insert the pRemoteAddress into __pChannelAddressMap by using the specified channelId as key
+               r = pHdpAdapter->__pChannelAddressMap->Add(channelId, remoteDeviceAddrStr);
+               if (r != E_SUCCESS)
+               {
+                       SysLogException(NID_NET_BT, E_OPERATION_FAILED, "[%s] Propagating.", GetErrorMessage(r));
+                       r = E_OPERATION_FAILED;
+               }
+       }
+       else
+       {
+               SysLog(NID_NET_BT, "[E_OPERATION_FAILED] Connection request failure is reported by the underlying system.");
+               r = E_OPERATION_FAILED;
+       }
+
+       hdpchannelType = ((channelType == BT_HDP_CHANNEL_TYPE_RELIABLE)?
+                       BT_HEALTH_DATA_CHANNEL_RELIABLE : BT_HEALTH_DATA_CHANNEL_STREAMING);
+
+       // Fire the connect event using the _BluetoothHealthImpl handle
+       pHealthImpl->OnBluetoothHealthConnected(channelId, hdpchannelType, &btDevice, r);
+}
+
+void
+_BluetoothHdpSystemAdapter::OnHdpDisconnected(int status, const char* pRemoteAddress, unsigned int channelId, void* pUserData)
+{
+       result r = E_SYSTEM;
+
+       BluetoothDevice btDevice;
+       ByteBuffer deviceAddress;
+       String remoteDeviceAddrStr(pRemoteAddress);
+
+       _BluetoothHealthImpl* pHealthImpl = null;
+
+       _BluetoothHdpSystemAdapter* pHdpAdapter = _BluetoothHdpSystemAdapter::GetInstance();
+
+        // get the pointer of the _BluetoothHealthImpl from __pChannelHealthMap by using the specified channelId as a key
+       r = pHdpAdapter->__pChannelHealthMap->GetValue(channelId, pHealthImpl);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "[E_OPERATION_FAILED] The channel Id is unknown.");
+
+       if (status == BT_ERROR_NONE)
+       {
+               (void) pHdpAdapter->__pChannelHealthMap->Remove(channelId);
+               pHdpAdapter->__pChannelAddressMap->Remove(channelId);
+       }
+       else
+       {
+               SysLog(NID_NET_BT, "[E_OPERATION_FAILED] Disconnection request failure is reported by the underlying system [%d].", status);
+               r = E_OPERATION_FAILED;
+       }
+
+       // Fire the Disconnect event using the _BluetoothHealthImpl handle
+       pHealthImpl->OnBluetoothHealthDisconnected(channelId, r);
+}
+
+void
+_BluetoothHdpSystemAdapter::OnHdpDataReceived(unsigned int channelId, const char* pData, unsigned int dataSize, void* pUserData)
+{
+       result r = E_SUCCESS;
+       ByteBuffer dataBuffer;
+
+       _BluetoothHealthImpl* pHealthImpl = null;
+
+       _BluetoothHdpSystemAdapter* pHdpAdapter = _BluetoothHdpSystemAdapter::GetInstance();
+
+       // find the appropriate _BluetoothHealthImpl handle with the given channelId
+       r = pHdpAdapter->__pChannelHealthMap->GetValue(channelId, pHealthImpl);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "[E_OPERATION_FAILED] unknown channelId.");
+
+       dataBuffer.Construct(dataSize);
+       dataBuffer.SetArray((byte*) pData, 0, dataSize);
+       dataBuffer.SetPosition(0);
+
+       // Fire the data received event using the _BluetoothHealthImpl handle
+       pHealthImpl->OnBluetoothHealthDataReceived(channelId, dataBuffer);
+       SysLog(NID_NET_BT, " Received Health data of (%d bytes) through the channel (ID: %d) is received.",     dataSize, channelId);
+}
+
+} } }  // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothHdpSystemAdapter.h b/src/FNetBt_BluetoothHdpSystemAdapter.h
new file mode 100644 (file)
index 0000000..22a55ad
--- /dev/null
@@ -0,0 +1,164 @@
+//
+// 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    FNetBt_BluetoothHdpSystemAdapter.h
+ * @brief   This is the header file for the _BluetoothHdpSystemAdapter class.
+ *
+ * This header file contains the declaration of the _BluetoothHdpSystemAdapter class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_
+
+#include <unique_ptr.h>
+#include <bluetooth.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+
+// forward declarations
+namespace Tizen { namespace Base {
+class ByteBuffer;
+
+namespace Collection {
+template<class keyType, class valueType> class HashMapT;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declarations
+class BluetoothDevice;
+class _BluetoothHealthImpl;
+
+/**
+ * @class   _BluetoothHdpSystemAdapter
+ * @brief   This class provides functions related to HDP (Health Device Profile) and have a role of adaptation OSP classes and
+ *                     the underlying subsystem. This class is a type of singleton, therefore only one instance should be allowed.
+ */
+class _BluetoothHdpSystemAdapter
+       : 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 _BluetoothHdpSystemAdapter* GetInstance(void);
+
+       /**
+        * Create and initialize a sink service, and start to listen the health events. @n
+        * An instance of _BluetoothHealthImpl class is registered internally.
+        *
+        * @return      An error code
+        * @param[in]   dataType                The type of data used in communication, refer to ISO/IEEE 11073-20601 for data types
+        * @param[in]   implListener            The instance of _BluetoothHealthImpl to be registered in map
+        * @param[out]  pAppId                  The application ID
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SERVICE_UNAVAILABLE   The HDP service with the specified data type is unavailable.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result StartSinkService(int dataType, _BluetoothHealthImpl& implListener, char** pAppId);
+
+       /**
+        * Close the specified sink service. @n
+        *
+        * @return      An error code
+        * @param[in]   pAppId                          The application ID
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result StopService(const char* pAppId);
+
+       /**
+        * Sets up a new connection (channel) with a remote health device which has source role. @n
+        *
+        * @return      An error code
+        * @param[in]   sourceAddress           The address of the source device
+        * @param[in]   pAppId                          The application ID
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result ConnectToSource(const Tizen::Base::ByteBuffer& sourceAddress, const char* pAppId);
+
+       /**
+        * Close the connection with the remote HDP source device.
+        *
+        * @return      An error code
+        * @param[in]   channelId               The ID of the specified channel to be disconnected
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result Disconnect(int channelId);
+
+       /**
+        * Sends the specified data on the specified HDP channel.
+        *
+        * @return      An error code
+        * @param[in]   channelId               The ID of the specified channel to send data on
+        * @param[in]   data                    The health data to be sent over the connected channel
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result SendData(int channelId, const Tizen::Base::ByteBuffer& buffer);
+
+
+       //-----------------------------------------------------------------------------------------------------------------
+       // Callback methods for the HDP events
+       //-----------------------------------------------------------------------------------------------------------------
+
+       /**
+        * Callback called by the underlying system to notify that an HDP connection is established.
+        */
+       static void OnHdpConnected(int status, const char* pRemoteAddress, const char* appId, bt_hdp_channel_type_e channelType,
+                       unsigned int channelId, void* pUserData);
+
+       /**
+        * Callback called by the underlying system to notify that the specific HDP connection is disconnected.
+        */
+       static void OnHdpDisconnected(int status, const char* pRemoteAddress, unsigned int channelId, void* pUserData);
+
+       /**
+        * Callback used by the underlying system to notify that data is received on the established HDP connection.
+        */
+       static void OnHdpDataReceived(unsigned int channelId, const char* pData, unsigned int dataSize, void* pUserData);
+
+private:
+       _BluetoothHdpSystemAdapter(void);
+       ~_BluetoothHdpSystemAdapter(void);
+
+       _BluetoothHdpSystemAdapter(const _BluetoothHdpSystemAdapter& value);
+       _BluetoothHdpSystemAdapter& operator =(const _BluetoothHdpSystemAdapter& value);
+
+       bool Construct(void);
+
+       static void InitSingleton(void);
+
+private:
+       // hash map of HDP applications and the _BluetoothHealthImpl
+       std::unique_ptr<Tizen::Base::Collection::HashMapT< Tizen::Base::String, _BluetoothHealthImpl*> > __pAppHealthMap;
+       // hash map of HDP channel Ids and the _BluetoothHealthImpl
+       std::unique_ptr<Tizen::Base::Collection::HashMapT< int, _BluetoothHealthImpl*> > __pChannelHealthMap;
+       // hash map of HDP channel Ids and the connected device address
+       std::unique_ptr<Tizen::Base::Collection::HashMapT< int, Tizen::Base::String> > __pChannelAddressMap;
+       static _BluetoothHdpSystemAdapter* __pInstance;
+
+}; // _BluetoothHdpSystemAdapter
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_
diff --git a/src/FNetBt_BluetoothHealthEvent.cpp b/src/FNetBt_BluetoothHealthEvent.cpp
new file mode 100644 (file)
index 0000000..07f014c
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// 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    FNetBt_BluetoothHealthEvent.cpp
+// @brief   This is the implementation file for the _BluetoothHealthEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
+#include "FNetBt_BluetoothHealthEvent.h"
+#include "FNetBt_BluetoothHealthEventArg.h"
+#include "FNetBtIBluetoothHealthEventListener.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothHealthEvent::_BluetoothHealthEvent(void)
+{
+}
+
+_BluetoothHealthEvent::~_BluetoothHealthEvent(void)
+{
+}
+
+result
+_BluetoothHealthEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothHealthEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       const BluetoothDevice* pDevice = null;
+       ByteBuffer* pData = null;
+       int channelId = -1;
+       result r = E_SUCCESS;
+
+       IBluetoothHealthEventListener* pListener = dynamic_cast <IBluetoothHealthEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pListener != null, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothHealthEventArg* pEventArg = dynamic_cast <const _BluetoothHealthEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothHealthEventType eventType = pEventArg->GetEventType();
+       channelId = pEventArg->GetChannelId();
+       r = pEventArg->GetErrorResult();
+
+       switch (eventType)
+       {
+       case _BT_HEALTH_EVENT_CONNECTED:
+               pDevice = pEventArg->GetSourceDevice();
+               if (pDevice)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth Health Event (Type: _BT_HEALTH_EVENT_CONNECTED)");
+                       pListener->OnHealthConnected(channelId, pEventArg->GetDataType(), pEventArg->GetChannelType(), pDevice, r);
+               }
+               break;
+
+       case _BT_HEALTH_EVENT_DISCONNECTED:
+               SysLog(NID_NET_BT, "Firing Bluetooth Health Event (Type: _BT_HEALTH_EVENT_DISCONNECTED)");
+               pListener->OnHealthDisconnected(channelId, r);
+               break;
+
+       case _BT_HEALTH_EVENT_DATA_RECEIVED:
+               pData = pEventArg->GetReceivedData();
+               if (pData)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth socket Event (Type: _BT_HEALTH_EVENT_DATA_RECEIVED)");
+                       pListener->OnHealthDataReceived(channelId, *pData);
+               }
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothHealthEvent.h b/src/FNetBt_BluetoothHealthEvent.h
new file mode 100644 (file)
index 0000000..d2073e5
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// 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    FNetBt_BluetoothHealthEvent.h
+ * @brief   This is the header file for the _BluetoothHealthEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothHealthEvent class.
+ * The _BluetoothHealthEvent class can call a method of a listener (_IBluetoothHealthEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+// Forward declaration
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// @class   _BluetoothHealthEvent
+// @brief   This class handles Bluetooth Health events.
+//
+// When a Bluetooth device event occurs, the _BluetoothHealthEvent object finds a _IBluetoothHealthEventListener object
+// and calls an appropriate method of the listener.
+//
+class _BluetoothHealthEvent
+       : public Tizen::Base::Runtime::_Event
+{
+public:
+       /**
+        * This is the default constructor.
+        */
+       _BluetoothHealthEvent(void);
+
+       /**
+        * This is the class destructor.
+        */
+       virtual ~_BluetoothHealthEvent(void);
+
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate Listener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth health event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothHealthEvent(const _BluetoothHealthEvent& value);
+       _BluetoothHealthEvent& operator =(const _BluetoothHealthEvent& rhs);
+
+}; // _BluetoothHealthEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_EVENT_H_
diff --git a/src/FNetBt_BluetoothHealthEventArg.cpp b/src/FNetBt_BluetoothHealthEventArg.cpp
new file mode 100755 (executable)
index 0000000..990fcb7
--- /dev/null
@@ -0,0 +1,133 @@
+//
+// 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    FNetBt_BluetoothHealthEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothHealthEventArg class.
+//
+
+#include <FBaseByteBuffer.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothHealthEventArg.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// This is a class constructor for _BT_HEALTH_EVENT_CONNECTED event.
+//
+_BluetoothHealthEventArg::_BluetoothHealthEventArg(int channelId, int dataType, BluetoothHealthDataChannelType channelType,
+               const BluetoothDevice* pDevice, result r)
+       : __evtType(_BT_HEALTH_EVENT_CONNECTED)
+       , __pTargetDevice(null)
+       , __channelId(channelId)
+       , __dataType(dataType)
+       , __channelType(channelType)
+       , __result(r)
+       , __pData(null)
+{
+       if (pDevice != null)
+       {
+               __pTargetDevice = new (std::nothrow) BluetoothDevice(*pDevice);
+               SysTryReturnVoidResult(NID_NET_BT, __pTargetDevice != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       }
+}
+
+//
+// This is a class constructor for _BT_HEALTH_EVENT_DISCONNECTED event.
+//
+_BluetoothHealthEventArg::_BluetoothHealthEventArg(int channelId, result r)
+       : __evtType(_BT_HEALTH_EVENT_DISCONNECTED)
+       , __pTargetDevice(null)
+       , __channelId(channelId)
+       , __dataType(0)
+       , __channelType(BT_HEALTH_DATA_CHANNEL_NONE)
+       , __result(r)
+       , __pData(null)
+{
+}
+
+//
+// This is a class constructor for _BT_HEALTH_EVENT_DATA_RECEIVED event.
+//
+_BluetoothHealthEventArg::_BluetoothHealthEventArg(int channelId, const Tizen::Base::ByteBuffer& buffer)
+       : __evtType(_BT_HEALTH_EVENT_DATA_RECEIVED)
+       , __pTargetDevice(null)
+       , __channelId(channelId)
+       , __dataType(0)
+       , __channelType(BT_HEALTH_DATA_CHANNEL_NONE)
+       , __result(E_SUCCESS)
+       , __pData(null)
+{
+       __pData = new (std::nothrow) ByteBuffer();
+       SysTryReturnVoidResult(NID_NET_BT, __pData != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       __pData->Construct(buffer);
+       __pData->SetPosition(0);
+}
+
+_BluetoothHealthEventArg::~_BluetoothHealthEventArg(void)
+{
+       delete __pTargetDevice;
+       delete __pData;
+}
+
+_BluetoothHealthEventType
+_BluetoothHealthEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
+
+const BluetoothDevice*
+_BluetoothHealthEventArg::GetSourceDevice(void) const
+{
+       return __pTargetDevice;
+}
+
+int
+_BluetoothHealthEventArg::GetChannelId(void) const
+{
+       return __channelId;
+}
+
+int
+_BluetoothHealthEventArg::GetDataType(void) const
+{
+       return __dataType;
+}
+
+BluetoothHealthDataChannelType
+_BluetoothHealthEventArg::GetChannelType(void) const
+{
+       return __channelType;
+}
+
+result
+_BluetoothHealthEventArg::GetErrorResult(void) const
+{
+       return __result;
+}
+
+Tizen::Base::ByteBuffer*
+_BluetoothHealthEventArg::GetReceivedData(void) const
+{
+       return __pData;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothHealthEventArg.h b/src/FNetBt_BluetoothHealthEventArg.h
new file mode 100644 (file)
index 0000000..f9621c2
--- /dev/null
@@ -0,0 +1,175 @@
+//
+// 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    FNetBt_BluetoothHealthEventArg.h
+ * @brief   This is the header file for the _BluetoothHealthEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothHealthEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseRtIEventArg.h>
+#include <FNetBtBluetoothTypes.h>
+
+// Forward declaration
+namespace Tizen { namespace Base {
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declaration
+class BluetoothDevice;
+
+/**
+  * @enum    _BluetoothHealthEventType
+  * Type for specifying the type of _BluetoothHealthEvent
+  */
+enum _BluetoothHealthEventType
+{
+       _BT_HEALTH_EVENT_CONNECTED,         /**< For notifying that the connection is established */
+       _BT_HEALTH_EVENT_DISCONNECTED,      /**< For notifying that the connection is disconnected */
+       _BT_HEALTH_EVENT_DATA_RECEIVED,     /**< For notifying that the data has been received */
+};
+
+/**
+ * @class   _BluetoothHealthEventArg
+ * @brief   This class is used as an argument for callback methods of the IBluetoothHealthEventListener class.
+ *
+ * When a _BluetoothHealthEvent occurs, the _BluetoothHealthEvent finds a IBluetoothHealthEventListener instance
+ * which is registered for the _BluetoothHealthEvent and calls an appropriate method of the listener.
+ * @see     IBluetoothHealthEventListener
+ */
+class _BluetoothHealthEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor for _BT_HEALTH_EVENT_CONNECTED event.
+        *
+        * @param[in]   channelId           The channel ID of the established connection, @n
+        *                                  else an invalid ID (-1) if the method is not successful
+        * @param[in]   dataType                        dataType represents the type of health device (eg thermometer, BP device)
+        *                                                                      and is defined in ISO/IEEE 11073-20601 standard
+        * @param[in]   channelType         The data channel type of the established connection
+        * @param[in]   pRemoteDevice       The remote health device which the local device connects with, @n
+        *                                  else @c null if the method is not successful
+        * @param[in]   r                   The result of the connection request
+        * @exception   E_SUCCESS           The connection request is accepted by the target health device.
+        * @exception   E_REJECTED          The connection request is rejected by the target health device.
+        * @exception   E_TIMEOUT           The connection request has timed out.
+        * @exception   E_OPERATION_FAILED  The connection request has failed.
+        */
+       _BluetoothHealthEventArg(int channelId, int dataType, BluetoothHealthDataChannelType channelType,
+                               const BluetoothDevice* pDevice, result r);
+
+       /**
+        * This is a class constructor for _BT_HEALTH_EVENT_DISCONNECTED event.
+        *
+        * @param[in]   channelId           The channel ID of the terminated connection
+        * @param[in]   r                   The disconnection status
+        * @exception   E_SUCCESS           The specified connection (channel) is terminated successfully.
+        * @exception   E_OPERATION_FAILED  The method has failed to disconnect.
+        */
+       _BluetoothHealthEventArg(int channelId, result r);
+
+       /**
+        * This is a class constructor for _BT_HEALTH_EVENT_DATA_RECEIVED event.
+        *
+        * @param[in]   channelId           The channel ID of the conneciton which data is received on
+        * @param[in]   buffer              The received data
+        */
+       _BluetoothHealthEventArg(int channelId, const Tizen::Base::ByteBuffer& buffer);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothHealthEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothHealthEventType GetEventType(void) const;
+
+       /**
+        * Gets the socket client device.
+        *
+        * @return      The pointer of the source device which is connect with
+        */
+       const BluetoothDevice* GetSourceDevice(void) const;
+
+       /**
+        * Gets the channel ID.
+        *
+        * @return      The channel ID
+        */
+       int GetChannelId(void) const;
+
+       /**
+        * Gets the Data Type.
+        *
+        * @return      The Data Type
+        */
+       int GetDataType(void) const;
+
+       /**
+        * Gets the data channel type.
+        *
+        * @return      The data channel type
+        */
+       BluetoothHealthDataChannelType GetChannelType(void) const;
+
+       /**
+        * Gets the error result of this event.
+        *
+        * @return      The result of the event
+        */
+       result GetErrorResult(void) const;
+
+       /**
+        * Gets The received data.
+        *
+        * @return      The received data
+        */
+       Tizen::Base::ByteBuffer* GetReceivedData(void) const;
+
+private:
+       _BluetoothHealthEventArg(void);
+       _BluetoothHealthEventArg(const _BluetoothHealthEventArg& eventArg);
+       _BluetoothHealthEventArg& operator =(const _BluetoothHealthEventArg& rValue);
+
+private:
+       _BluetoothHealthEventType __evtType;
+       BluetoothDevice* __pTargetDevice;
+       int __channelId;
+       int __dataType;
+       BluetoothHealthDataChannelType __channelType;
+       result __result;
+       Tizen::Base::ByteBuffer* __pData;
+
+}; // _BluetoothHealthEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothHealthImpl.cpp b/src/FNetBt_BluetoothHealthImpl.cpp
new file mode 100755 (executable)
index 0000000..b6a17a6
--- /dev/null
@@ -0,0 +1,697 @@
+//
+// 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        FNetBt_BluetoothHealthImpl.cpp
+// @brief       This is the implementation file for the _BluetoothHealthImpl class.
+//
+
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothHealthEventListener.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothHealthEvent.h"
+#include "FNetBt_BluetoothHealthEventArg.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothHdpSystemAdapter.h"
+#include "FNetBt_BluetoothHealthImpl.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothHealthImpl::_BluetoothHealthImpl(void)
+       : __pGapAdapter(null)
+       , __pHdpAdapter(null)
+       , __pEvent(null)
+       , __stateMutex()
+       , __currentState(_BT_HEALTH_STATE_DISABLED)
+       , __channelIdList()
+       , __pairingTargetAddress()
+       , __pAppId(null)
+       , __dataType(_BT_INVALID_DATA_TYPE)
+{
+}
+
+_BluetoothHealthImpl::~_BluetoothHealthImpl(void)
+{
+       int count = 0;
+       int channelId = 0;
+
+       if (__pHdpAdapter != null)
+       {
+               count = __channelIdList.GetCount();
+               for (int i=0; i<count; i++)
+               {
+                       __channelIdList.GetAt(i, channelId);
+                       __pHdpAdapter->Disconnect(channelId);
+               }
+       }
+
+       if (__pGapAdapter != null)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+               __pGapAdapter->UnregisterDeviceEventListener(*this);
+       }
+}
+
+result
+_BluetoothHealthImpl::Construct(IBluetoothHealthEventListener& listener)
+{
+       result r = E_SUCCESS;
+       unique_ptr<_BluetoothHealthEvent> pEvent;
+
+       r = __stateMutex.Create();
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to create the state mutex.");
+
+       r = __pairingTargetAddress.Construct(_BT_ADDRESS_LENGTH);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to construct the address for pairing.");
+
+       __pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturnResult(NID_NET_BT, __pGapAdapter != null, E_OPERATION_FAILED,
+                       "Failed to invoke _BluetoothGapSystemAdapter::GetInstance().");
+
+       __pHdpAdapter = _BluetoothHdpSystemAdapter::GetInstance();
+       SysTryReturnResult(NID_NET_BT, __pHdpAdapter != null, E_OPERATION_FAILED,
+                       "Failed to invoke _BluetoothHdpSystemAdapter::GetInstance().");
+
+       pEvent.reset(new (std::nothrow) _BluetoothHealthEvent());
+       SysTryReturnResult(NID_NET_BT, pEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       r = pEvent->Construct();
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to construct the event.");
+       // add IBluetoothHealthEventListener instance to the newly created _BluetoothHealthEvent.
+       r = pEvent->AddListener(listener, true);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "Propagating. Failed to add the application listener for health device");
+
+       // registers this callback listener to the system adapter for activation/deactivation event
+       r = __pGapAdapter->RegisterManagerEventListener(*this, true);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to register the callback listener to _BluetoothGapSystemAdapter.");
+
+       // registers this callback listener to the system adapter for paired event
+       r = __pGapAdapter->RegisterDeviceEventListener(*this);
+       if (r != E_SUCCESS)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+       }
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to register the callback listener to _BluetoothGapSystemAdapter.");
+
+       // checks whether the Bluetooth is available
+       __stateMutex.Acquire();
+
+       if (__pGapAdapter->IsActivated() == true)
+       {
+               __currentState = _BT_HEALTH_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       __pEvent = move(pEvent);
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothHealthImpl::StartAsSink(int dataType)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+       char* pAppId = null;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_HEALTH_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_HEALTH_STATE_IDLE:
+               r = __pHdpAdapter->StartSinkService(dataType, *this, &pAppId);
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_HEALTH_STATE_ON_SERVICE;
+                       __dataType = dataType;
+                       __pAppId.reset(pAppId);
+               }
+               break;
+
+       case _BT_HEALTH_STATE_ON_SERVICE:
+       case _BT_HEALTH_STATE_BONDING:
+       case _BT_HEALTH_STATE_BOND_CANCELING:
+               if (__dataType == dataType)
+               {
+                       r = E_IN_PROGRESS;
+               }
+               else
+               {
+                       r = E_INVALID_OPERATION;
+               }
+               break;
+
+       default:
+               r = E_OPERATION_FAILED;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on starting Health sink role.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothHealthImpl::Stop(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_HEALTH_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_HEALTH_STATE_IDLE:
+       case _BT_HEALTH_STATE_BOND_CANCELING:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_HEALTH_STATE_ON_SERVICE:
+               r = __pHdpAdapter->StopService(__pAppId.get());
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_HEALTH_STATE_IDLE;
+                       __pAppId.reset(null);
+                       __dataType = _BT_INVALID_DATA_TYPE;
+               }
+               break;
+
+       case _BT_HEALTH_STATE_BONDING:
+               if (__pGapAdapter->CancelPair() == E_SUCCESS)
+               {
+                       r = E_SUCCESS;
+                       __currentState = _BT_HEALTH_STATE_BOND_CANCELING;
+               }
+               // It will be changed to IDLE after receiving the OnBluetoothPaired event.
+               break;
+
+       default:
+               r = E_OPERATION_FAILED;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on stopping Health sink role.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothHealthImpl::ConnectToSource(const BluetoothDevice& remoteDevice)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_OPERATION_FAILED;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_HEALTH_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_HEALTH_STATE_IDLE:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_HEALTH_STATE_ON_SERVICE:
+               if (__pGapAdapter->IsPaired(*(remoteDevice.GetAddress())) == true)
+               {
+                       r = __pHdpAdapter->ConnectToSource(*(remoteDevice.GetAddress()), __pAppId.get());
+               }
+               else
+               {
+                       // start the pairing process
+                       if (__pGapAdapter->Pair(*(remoteDevice.GetAddress())) == E_SUCCESS)
+                       {
+                               // copy the address of the pairing device to the local variable
+                               __pairingTargetAddress.SetArray(remoteDevice.GetAddress()->GetPointer(), 0, _BT_ADDRESS_LENGTH);
+                               __pairingTargetAddress.SetPosition(0);
+
+                               r = E_SUCCESS;
+                               __currentState = _BT_HEALTH_STATE_BONDING;
+                       }
+                       else
+                       {
+                               r = E_OPERATION_FAILED;
+                       }
+               }
+               break;
+
+       case _BT_HEALTH_STATE_BONDING:
+       case _BT_HEALTH_STATE_BOND_CANCELING:
+               r = E_DEVICE_BUSY;
+               break;
+
+       default:
+               r = E_OPERATION_FAILED;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on requesting a connection to the source device.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothHealthImpl::Disconnect(int channelId)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_OPERATION_FAILED;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_HEALTH_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_HEALTH_STATE_IDLE:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_HEALTH_STATE_ON_SERVICE:
+       case _BT_HEALTH_STATE_BONDING:
+       case _BT_HEALTH_STATE_BOND_CANCELING:
+               if (__channelIdList.Contains(channelId) == true)
+               {
+                       if (__pHdpAdapter->Disconnect(channelId) == E_SUCCESS)
+                       {
+                               r = E_SUCCESS;
+                       }
+                       else
+                       {
+                               r = E_OPERATION_FAILED;
+                       }
+               }
+               else
+               {
+                       r = E_INVALID_OPERATION;
+               }
+               break;
+
+       default:
+               r = E_OPERATION_FAILED;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on disconnecting the connection.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothHealthImpl::SendData(int channelId, const Tizen::Base::ByteBuffer& buffer)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_OPERATION_FAILED;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_HEALTH_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_HEALTH_STATE_IDLE:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_HEALTH_STATE_ON_SERVICE:
+       case _BT_HEALTH_STATE_BONDING:
+       case _BT_HEALTH_STATE_BOND_CANCELING:
+               if (__channelIdList.Contains(channelId) == true)
+               {
+                       if (buffer.GetRemaining() > 0)
+                       {
+                               r = __pHdpAdapter->SendData(channelId, buffer);
+                       }
+                       else
+                       {
+                               r = E_INVALID_ARG;
+                       }
+               }
+               else
+               {
+                       r = E_INVALID_OPERATION;
+               }
+               break;
+
+       default:
+               r = E_OPERATION_FAILED;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on sending data.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+void
+_BluetoothHealthImpl::OnBluetoothActivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_HEALTH_STATE_DISABLED) && (r == E_SUCCESS))
+       {
+               __currentState = _BT_HEALTH_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+}
+
+void
+_BluetoothHealthImpl::OnBluetoothDeactivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if (r == E_SUCCESS)
+       {
+               __currentState = _BT_HEALTH_STATE_DISABLED;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothHealthImpl::OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+       result responseResult = E_SYSTEM;
+
+       __stateMutex.Acquire();
+
+       if (pPairedDevice->GetAddress()->Equals(__pairingTargetAddress))
+       {
+               if (__currentState == _BT_HEALTH_STATE_BONDING)
+               {
+                       if (r == E_SUCCESS)
+                       {
+                               if (__pHdpAdapter->ConnectToSource(__pairingTargetAddress, __pAppId.get()) != E_SUCCESS)
+                               {
+                                       // callback responded with E_SYSTEM
+                                       isFired = true;
+                                       responseResult = E_SYSTEM;
+                               }
+                       }
+                       else
+                       {
+                               // callback responded with r
+                               isFired = true;
+                               responseResult = r;
+                       }
+
+                       __currentState = _BT_HEALTH_STATE_ON_SERVICE;
+                       __pairingTargetAddress.Clear();
+               }
+               else if (__currentState == _BT_HEALTH_STATE_BOND_CANCELING)
+               {
+                       // callback responded with E_SYSTEM or E_OPERATION_CANCELED
+                       isFired = true;
+                       __currentState = _BT_HEALTH_STATE_IDLE;
+                       responseResult = E_SYSTEM;
+               }
+               // ignore other cases
+       }
+       // ignored otherwise
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothHealthEventArg* pArg = new (std::nothrow) _BluetoothHealthEventArg(-1,
+                               _BT_INVALID_DATA_TYPE, BT_HEALTH_DATA_CHANNEL_NONE, pPairedDevice, E_OPERATION_FAILED);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else // send the connected event in case of failure of pairing
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [CONNECTED_Event:%s]", GetStringOfCurrentState(),
+                       isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothHealthImpl::OnBluetoothHealthConnected(int channelId, BluetoothHealthDataChannelType channelType,
+               const BluetoothDevice* pRemoteDevice, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [channelId:%d], [ActionResult:%s]", GetStringOfCurrentState(),
+                       channelId, GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_HEALTH_STATE_ON_SERVICE)
+               || (__currentState == _BT_HEALTH_STATE_BONDING)
+               || (__currentState == _BT_HEALTH_STATE_BOND_CANCELING))
+       {
+               if (r == E_SUCCESS)
+               {
+                       __channelIdList.Add(channelId);
+               }
+               else
+               {
+                       SysLogException(NID_NET_BT, r, "[%s] exception occurred on the response of the Health connect request.", GetErrorMessage(r));
+               }
+
+               isFired = true;
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothHealthEventArg* pArg = new (std::nothrow) _BluetoothHealthEventArg(channelId, __dataType, channelType,
+                                       pRemoteDevice, r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [CONNECTED_Event:%s]", GetStringOfCurrentState(),
+                       isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothHealthImpl::OnBluetoothHealthDisconnected(int channelId, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [channelId:%d], [ActionResult:%s]", GetStringOfCurrentState(),
+                       channelId, GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_HEALTH_STATE_ON_SERVICE)
+               || (__currentState == _BT_HEALTH_STATE_BONDING)
+               || (__currentState == _BT_HEALTH_STATE_BOND_CANCELING))
+       {
+               if (r == E_SUCCESS)
+               {
+                       if (__channelIdList.Contains(channelId) == true)
+                       {
+                               __channelIdList.Remove(channelId);
+                               isFired = true;
+                       }
+                       else
+                       {
+                               SysLog(NID_NET_BT, "channelId(%d) is NOT exist.", channelId);
+                       }
+               }
+               else
+               {
+                       SysLogException(NID_NET_BT, r, "[%s] exception occurred on the response of the Health disconnect request.", GetErrorMessage(r));
+               }
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothHealthEventArg* pArg = new (std::nothrow) _BluetoothHealthEventArg(channelId, r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DISCONNECTED_Event:%s]", GetStringOfCurrentState(),
+                       isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothHealthImpl::OnBluetoothHealthDataReceived(int channelId, Tizen::Base::ByteBuffer& buffer)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_HEALTH_STATE_ON_SERVICE)
+               || (__currentState == _BT_HEALTH_STATE_BONDING)
+               || (__currentState == _BT_HEALTH_STATE_BOND_CANCELING))
+       {
+               if (__channelIdList.Contains(channelId) == true)
+               {
+                       isFired = true;
+               }
+               else
+               {
+                       SysLog(NID_NET_BT, "channelId(%d) is NOT exist.", channelId);
+               }
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothHealthEventArg* pArg = new (std::nothrow) _BluetoothHealthEventArg(channelId, buffer);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       // use Fire() instead of FireAsync() to improve the transfer rate.
+                       __pEvent->Fire(*pArg);
+               }
+       }
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DATA_RECIEVED_Event:%s]", GetStringOfCurrentState(),
+                       isFired ? "Fired" : "NotFired");
+}
+
+const char*
+_BluetoothHealthImpl::GetStringOfCurrentState(void) const
+{
+       const char* pStateString = null;
+
+       switch (__currentState)
+       {
+       case _BT_HEALTH_STATE_DISABLED:
+               pStateString = "DISABLED";
+               break;
+
+       case _BT_HEALTH_STATE_IDLE:
+               pStateString = "IDLE";
+               break;
+
+       case _BT_HEALTH_STATE_ON_SERVICE:
+               pStateString = "ON_SERVICE";
+               break;
+
+       case _BT_HEALTH_STATE_BONDING:
+               pStateString = "BONDING";
+               break;
+
+       case _BT_HEALTH_STATE_BOND_CANCELING:
+               pStateString = "BOND_CANCELING";
+               break;
+
+       default:
+               pStateString = "Unknown";
+               break;
+       }
+
+       return pStateString;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothIpcMessages.cpp b/src/FNetBt_BluetoothIpcMessages.cpp
new file mode 100644 (file)
index 0000000..5f364d2
--- /dev/null
@@ -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    FNetBt_BluetoothIpcMessages.cpp
+ * @brief   This is the generator of IPC messages for the Connectivity daemon service.
+ */
+
+#define IPC_MESSAGE_IMPL
+#include "FNetBt_ConnectivityIpcMessages.h"
+
+// Generate constructors.
+#include <ipc/struct_constructor_macros.h>
+#include "FNetBt_ConnectivityIpcMessages.h"
+
+// Generate destructors.
+#include <ipc/struct_destructor_macros.h>
+#include "FNetBt_ConnectivityIpcMessages.h"
+
+// Generate param traits write methods.
+#include <ipc/param_traits_write_macros.h>
+namespace IPC {
+#include "FNetBt_ConnectivityIpcMessages.h"
+}  // namespace IPC
+
+// Generate param traits read methods.
+#include <ipc/param_traits_read_macros.h>
+namespace IPC {
+#include "FNetBt_ConnectivityIpcMessages.h"
+}  // namespace IPC
diff --git a/src/FNetBt_BluetoothIpcProxy.cpp b/src/FNetBt_BluetoothIpcProxy.cpp
new file mode 100755 (executable)
index 0000000..5fa6056
--- /dev/null
@@ -0,0 +1,158 @@
+//
+// 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                       FNetBt_BluetoothIpcProxy.cpp
+// @brief              This is the implementation file for the %_BluetoothIpcProxy class.
+//
+// This file contains the implementation of the %_BluetoothIpcProxy class.
+//
+
+#include <pthread.h>
+#include <FBaseSysLog.h>
+#include <FIo_IpcClient.h>
+#include "FNetBt_BluetoothIpcProxy.h"
+#include "FNetBt_ConnectivityIpcMessages.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothIpcProxy* _BluetoothIpcProxy::__pInstance = null;
+
+_BluetoothIpcProxy::_BluetoothIpcProxy(void) :
+               __pIpcClient(null)
+{
+}
+
+_BluetoothIpcProxy::~_BluetoothIpcProxy(void)
+{
+       delete __pIpcClient;
+}
+
+result
+_BluetoothIpcProxy::Construct(void)
+{
+       result r = E_SUCCESS;
+
+       __pIpcClient = new (std::nothrow) _IpcClient;
+       SysTryReturnResult(NID_NET_BT, __pIpcClient != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       r = __pIpcClient->Construct(BLUETOOTH_CONNECTIVITY_IPC_SERVER_NAME, null);
+       if (IsFailed(r))
+       {
+               delete __pIpcClient;
+               __pIpcClient = null;
+
+               SysLog(NID_NET_BT, "[%s] Construction of the IPC client for the Bluetooth proxy has failed.", GetErrorMessage(r));
+       }
+
+       return r;
+}
+
+void
+_BluetoothIpcProxy::InitSingleton(void)
+{
+       result r = E_SUCCESS;
+       static _BluetoothIpcProxy inst;
+
+       r = inst.Construct();
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       __pInstance = &inst;
+}
+
+_BluetoothIpcProxy*
+_BluetoothIpcProxy::GetInstance(void)
+{
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (__pInstance == null)
+       {
+               ClearLastResult();
+               pthread_once(&onceBlock, InitSingleton);
+               result r = GetLastResult();
+               if (IsFailed(r))
+               {
+                       onceBlock = PTHREAD_ONCE_INIT;
+               }
+       }
+
+       return __pInstance;
+}
+
+result
+_BluetoothIpcProxy::GetLocalDeviceName(Tizen::Base::String& deviceName) const
+{
+       result r = E_SUCCESS;
+       IPC::Message* pMessage = null;
+       unsigned long ret = 0;
+
+       pMessage = new (std::nothrow) ConnectivityBluetoothServiceMsg_getLocalDeviceName(&deviceName, &ret);
+       SysTryReturnResult(NID_NET_BT, pMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       r = __pIpcClient->SendRequest(*pMessage);
+       delete pMessage;
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "A system error occurred.");
+       SysTryReturnResult(NID_NET_BT, ret == E_SUCCESS, ret, "Propagating.");
+
+       SysLog(NID_NET_BT, "The Bluetooth name obtained through IPC is [%ls].", deviceName.GetPointer());
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothIpcProxy::SetLocalDeviceName(const Tizen::Base::String& deviceName) const
+{
+       result r = E_SUCCESS;
+       IPC::Message* pMessage = null;
+       unsigned long ret = 0;
+
+       pMessage = new (std::nothrow) ConnectivityBluetoothServiceMsg_setLocalDeviceName(deviceName, &ret);
+       SysTryReturnResult(NID_NET_BT, pMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       r = __pIpcClient->SendRequest(*pMessage);
+       delete pMessage;
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "A system error occurred.");
+       SysTryReturnResult(NID_NET_BT, ret == E_SUCCESS, ret, "Propagating.");
+
+       SysLog(NID_NET_BT, "Setting the Bluetooth name through IPC is successful.");
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothIpcProxy::SetDiscoverableMode(int mode, int seconds) const
+{
+       result r = E_SUCCESS;
+       IPC::Message* pMessage = null;
+       unsigned long ret = 0;
+
+       pMessage = new (std::nothrow) ConnectivityBluetoothServiceMsg_setDiscoverableMode(mode, seconds, &ret);
+       SysTryReturnResult(NID_NET_BT, pMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       r = __pIpcClient->SendRequest(*pMessage);
+       delete pMessage;
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "A system error occurred.");
+       SysTryReturnResult(NID_NET_BT, ret == E_SUCCESS, ret, "Propagating.");
+
+       SysLog(NID_NET_BT, "Setting the Bluetooth discoverable mode through IPC is successful.");
+
+       return E_SUCCESS;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothIpcProxy.h b/src/FNetBt_BluetoothIpcProxy.h
new file mode 100644 (file)
index 0000000..567399e
--- /dev/null
@@ -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       FNetBt_BluetoothIpcProxy.h
+ * @brief      This is the header file for the %_BluetoothIpcProxy class.
+ *
+ * This header file contains the declarations of the %_BluetoothIpcProxy class.
+ */
+
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_IPC_PROXY_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_IPC_PROXY_H_
+
+#include <FBaseObject.h>
+
+// Forward declaration
+namespace Tizen { namespace Base
+{
+class String;
+} }
+
+namespace Tizen { namespace Io
+{
+class _IpcClient;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+ * @class   _BluetoothIpcProxy
+ * @brief   This class represents an IPC proxy for %Bluetooth service.
+ *
+ * This class represents an IPC proxy for %Bluetooth service to communicate with Connectivity service daemon.
+ */
+class _BluetoothIpcProxy
+       : public Tizen::Base::Object
+{
+public:
+       static _BluetoothIpcProxy* GetInstance(void);
+
+       result GetLocalDeviceName(Tizen::Base::String& deviceName) const;
+       result SetLocalDeviceName(const Tizen::Base::String& deviceName) const;
+       result SetDiscoverableMode(int mode, int seconds) const;
+
+private:
+       _BluetoothIpcProxy(void);
+       virtual ~_BluetoothIpcProxy(void);
+       result Construct(void);
+
+
+       _BluetoothIpcProxy(const _BluetoothIpcProxy& value);
+       _BluetoothIpcProxy& operator =(const _BluetoothIpcProxy& rhs);
+
+       static void InitSingleton(void);
+
+private:
+       Tizen::Io::_IpcClient* __pIpcClient;
+       static _BluetoothIpcProxy* __pInstance;
+
+}; // _BluetoothIpcProxy
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_IPC_PROXY_H_
diff --git a/src/FNetBt_BluetoothManagerEvent.cpp b/src/FNetBt_BluetoothManagerEvent.cpp
new file mode 100644 (file)
index 0000000..a5fa2c5
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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    FNetBt_BluetoothManagerEvent.cpp
+// @brief   This is the implementation file for the _BluetoothManagerEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
+#include "FNetBt_BluetoothManagerEvent.h"
+#include "FNetBt_BluetoothManagerEventArg.h"
+#include "FNetBtIBluetoothManagerEventListener.h"
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothManagerEvent::_BluetoothManagerEvent(void)
+{
+}
+
+_BluetoothManagerEvent::~_BluetoothManagerEvent(void)
+{
+}
+
+result
+_BluetoothManagerEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothManagerEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       IBluetoothManagerEventListener* pEventListener = dynamic_cast <IBluetoothManagerEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pEventListener != null, E_INVALID_ARG, "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothManagerEventArg* pEventArg = dynamic_cast <const _BluetoothManagerEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothMangerEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case _BT_MANAGER_EVENT_ACTIVATED:
+               SysLog(NID_NET_BT, "Firing Bluetooth Manager Event (Type: _BT_MANAGER_EVENT_ACTIVATED)");
+               pEventListener->OnBluetoothActivated(pEventArg->GetErrorResult());
+               break;
+
+       case _BT_MANAGER_EVENT_DEACTIVATED:
+               SysLog(NID_NET_BT, "Firing Bluetooth Manager Event (Type: _BT_MANAGER_EVENT_DEACTIVATED)");
+               pEventListener->OnBluetoothDeactivated(pEventArg->GetErrorResult());
+               break;
+
+       case _BT_MANAGER_EVENT_DISCOVERABLE:
+               SysLog(NID_NET_BT, "Firing Bluetooth Manager Event (Type: _BT_MANAGER_EVENT_DISCOVERABLE)");
+               pEventListener->OnBluetoothDiscoverableModeChanged(pEventArg->GetDiscoverableMode());
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothManagerEvent.h b/src/FNetBt_BluetoothManagerEvent.h
new file mode 100644 (file)
index 0000000..6f54926
--- /dev/null
@@ -0,0 +1,83 @@
+//
+// 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    FNetBt_BluetoothManagerEvent.h
+ * @brief   This is the header file for the _BluetoothManagerEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothManagerEvent class.
+ * The _BluetoothManagerEvent class can call a method of a listener (IBluetoothManagerEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+ * @class   _BluetoothManagerEvent
+ * @brief   This class handles Bluetooth manager events.
+ *
+ * When a Bluetooth manager event occurs, the _BluetoothManagerEvent object finds a IBluetoothManagerEventListener object
+ * and calls an appropriate method of the listener.
+ */
+class _BluetoothManagerEvent
+       : public Base::Runtime::_Event
+{
+public:
+       /**
+        * This is the default constructor.
+        */
+       _BluetoothManagerEvent(void);
+
+       /**
+        * This is the class destructor.
+        */
+       virtual ~_BluetoothManagerEvent(void);
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate pListener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth manger event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothManagerEvent(const _BluetoothManagerEvent& value);
+       _BluetoothManagerEvent& operator =(const _BluetoothManagerEvent& rhs);
+
+}; // _BluetoothManagerEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_EVENT_H_
diff --git a/src/FNetBt_BluetoothManagerEventArg.cpp b/src/FNetBt_BluetoothManagerEventArg.cpp
new file mode 100644 (file)
index 0000000..bb40bca
--- /dev/null
@@ -0,0 +1,64 @@
+//
+// 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    FNetBt_BluetoothManagerEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothManagerEventArg class.
+//
+
+#include "FNetBt_BluetoothManagerEventArg.h"
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// This is a class constructor for _BT_MANAGER_EVENT_ACTIVATED or _BT_MANAGER_EVENT_DEACTIVATED.
+_BluetoothManagerEventArg::_BluetoothManagerEventArg(_BluetoothMangerEventType evt, result r)
+       : __evt(evt)
+       , __result(r)
+       , __mode(BT_DISC_MODE_NOT_DISCOVERABLE)
+{
+}
+
+// This is a class constructor for _BT_MANAGER_EVENT_DISCOVERABLE.
+_BluetoothManagerEventArg::_BluetoothManagerEventArg(BluetoothDiscoverableMode mode)
+       : __evt(_BT_MANAGER_EVENT_DISCOVERABLE)
+       , __result(E_SUCCESS)
+       , __mode(mode)
+{
+}
+
+_BluetoothManagerEventArg::~_BluetoothManagerEventArg(void)
+{
+}
+
+_BluetoothMangerEventType
+_BluetoothManagerEventArg::GetEventType(void) const
+{
+       return __evt;
+}
+
+result
+_BluetoothManagerEventArg::GetErrorResult(void) const
+{
+       return __result;
+}
+
+BluetoothDiscoverableMode
+_BluetoothManagerEventArg::GetDiscoverableMode(void) const
+{
+       return __mode;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothManagerEventArg.h b/src/FNetBt_BluetoothManagerEventArg.h
new file mode 100644 (file)
index 0000000..48a73af
--- /dev/null
@@ -0,0 +1,114 @@
+//
+// 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    FNetBt_BluetoothManagerEventArg.h
+ * @brief   This is the header file for the _BluetoothManagerEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothManagerEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+ * @enum    _BluetoothMangerEventType
+ * Type for specifying the type of _BluetoothMangerEvent
+ */
+enum _BluetoothMangerEventType
+{
+       _BT_MANAGER_EVENT_ACTIVATED,         /**< For notifying that Bluetooth is activated */
+       _BT_MANAGER_EVENT_DEACTIVATED,       /**< For notifying that Bluetooth is deactivated */
+       _BT_MANAGER_EVENT_DISCOVERABLE       /**< For notifying that Bluetooth discoverable mode is changed */
+};
+
+/**
+ * @class   _BluetoothManagerEventArg
+ * @brief   This class is used as an argument for callback methods of the IBluetoothManagerEventListener class.
+ *
+ * When a _BluetoothManagerEvent occurs, the _BluetoothManagerEvent finds a IBluetoothManagerEventListener instance
+ * which is registered for the _BluetoothManagerEvent and calls an appropriate method of the listener.
+ * @see     IBluetoothManagerEventListener
+ */
+class _BluetoothManagerEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor for _BT_MANAGER_EVENT_ACTIVATED or _BT_MANAGER_EVENT_DEACTIVATED.
+        *
+        * @param[in]    evt                The type of the event
+        * @param[in]    r                  The result of the event
+        */
+       _BluetoothManagerEventArg(_BluetoothMangerEventType evt, result r);
+
+       /**
+        * This is a class constructor for _BT_MANAGER_EVENT_DISCOVERABLE.
+        *
+        * @param[in]    mode               The changed discoverable mode
+        */
+       _BluetoothManagerEventArg(BluetoothDiscoverableMode mode);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothManagerEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothMangerEventType GetEventType(void) const;
+
+       /**
+        * Gets the error result of this event.
+        *
+        * @return      The result of the event
+        */
+       result GetErrorResult(void) const;
+
+       /**
+        * Gets the discoverable mode of this event.
+        *
+        * @return      The discoverable mode
+        */
+       BluetoothDiscoverableMode GetDiscoverableMode(void) const;
+
+private:
+       _BluetoothManagerEventArg(void);
+       _BluetoothManagerEventArg(const _BluetoothManagerEventArg& eventArg);
+       _BluetoothManagerEventArg& operator =(const _BluetoothManagerEventArg& rValue);
+
+private:
+       _BluetoothMangerEventType __evt;
+       result __result;
+       BluetoothDiscoverableMode __mode;
+
+}; // _BluetoothManagerEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothManagerImpl.cpp b/src/FNetBt_BluetoothManagerImpl.cpp
new file mode 100755 (executable)
index 0000000..01c3f24
--- /dev/null
@@ -0,0 +1,1841 @@
+//
+// 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        FNetBt_BluetoothManagerImpl.cpp
+// @brief       This is the implementation file for the _BluetoothManagerImpl class.
+//
+
+#include <FBaseByteBuffer.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtBluetoothManager.h>
+#include <FNetBtIBluetoothManagerEventListener.h>
+#include <FNetBtIBluetoothDeviceEventListener.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothDeviceImpl.h"
+#include "FNetBt_BluetoothManagerImpl.h"
+#include "FNetBt_BluetoothIpcProxy.h"
+#include "FNetBt_BluetoothManagerEvent.h"
+#include "FNetBt_BluetoothManagerEventArg.h"
+#include "FNetBt_BluetoothDeviceEvent.h"
+#include "FNetBt_BluetoothDeviceEventArg.h"
+#include "FNetBt_BluetoothConnectionEvent.h"
+#include "FNetBt_BluetoothConnectionEventArg.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothManagerImpl::_BluetoothManagerImpl(void)
+       : __pIpcProxy(null)
+       , __pGapAdapter(null)
+       , __pMgrEvent(null)
+       , __pDevEvent(null)
+       , __pConEvent(null)
+       , __pDevEvtListener(null)
+       , __pConEvtListener(null)
+       , __pLocalDevice(null)
+       , __pairedDeviceList()
+       , __pairedDeviceMap()
+       , __stateMutex()
+       , __pairedDevMapMutex()
+       , __currentState(_BT_MGR_STATE_DEACTIVATED)
+       , __pairingState(_BT_PAIRING_STATE_NONE)
+       , __pairingTargetAddress()
+       , __discoveredDeviceList()
+{
+}
+
+_BluetoothManagerImpl::~_BluetoothManagerImpl(void)
+{
+       if (__pGapAdapter != null)
+       {
+               if ((__currentState == _BT_MGR_STATE_DISCOVERY_REQUESTED)
+                       || (__currentState == _BT_MGR_STATE_ON_DISCOVERY))
+               {
+                       SysLog(NID_NET_BT, "Cancel the device discovery for resource clean.");
+                       (void) CancelDiscovery();
+               }
+
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+               __pGapAdapter->UnregisterDeviceEventListener(*this);
+       }
+}
+
+result
+_BluetoothManagerImpl::Construct(IBluetoothManagerEventListener& listener)
+{
+       result r = E_SUCCESS;
+       unique_ptr<_BluetoothManagerEvent> pMgrEvent;
+       unique_ptr<_BluetoothDeviceEvent> pDevEvent;
+       unique_ptr<_BluetoothConnectionEvent> pConEvent;
+
+       r = __stateMutex.Create();
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to create the state mutex.");
+
+       r = __pairedDevMapMutex.Create();
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to create the map mutex.");
+
+       r = __pairingTargetAddress.Construct(_BT_ADDRESS_LENGTH);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to construct the address for pairing.");
+
+       __pIpcProxy = _BluetoothIpcProxy::GetInstance();
+       SysTryReturnResult(NID_NET_BT, __pIpcProxy != null, E_SYSTEM, "Failed to get an instance of _BluetoothIpcProxy.");
+
+       __pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturnResult(NID_NET_BT, __pGapAdapter != null, E_SYSTEM, "Failed to get an instance of _BluetoothGapSystemAdapter.");
+
+       pMgrEvent.reset(new (std::nothrow) _BluetoothManagerEvent());
+       SysTryReturnResult(NID_NET_BT, pMgrEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       r = pMgrEvent->Construct();
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to construct the event.");
+
+       pDevEvent.reset(new (std::nothrow) _BluetoothDeviceEvent());
+       SysTryReturnResult(NID_NET_BT, pDevEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       r = pDevEvent->Construct();
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to construct the event.");
+
+       pConEvent.reset(new (std::nothrow) _BluetoothConnectionEvent());
+       SysTryReturnResult(NID_NET_BT, pConEvent != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       r = pConEvent->Construct();
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to construct the event.");
+
+       // add the IBluetoothManagerEventListener instance to a new created _BluetoothManagerEvent.
+       r = pMgrEvent->AddListener(listener, true);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM,
+                       "Failed to add the application listener for BluetoothManager event");
+
+       // initialize the paired device list which is used for old version APIs
+       __pairedDeviceList.Construct();
+       r = RefreshPairedDeviceList();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, r, r, "[%s] Failed to make the paired device list.", GetErrorMessage(r));
+
+       // initialize the paired device map which is used since 2.0
+       __pairedDeviceMap.Construct();
+       r = RefreshPairedDeviceMap();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, r, r, "[%s] Failed to make the paired device map.", GetErrorMessage(r));
+
+       // registers this listener to the manager event of the system adapter for activation/deactivation
+       r = __pGapAdapter->RegisterManagerEventListener(*this, false);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, 
+                          "Failed to register the manager event listener to _BluetoothSystemAdapter.");
+
+       // registers this listener to the device event of the system adapter for device/service discovery
+       r = __pGapAdapter->RegisterDeviceEventListener(*this);
+       if (r != E_SUCCESS)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+               SysLogException(NID_NET_BT, E_SYSTEM,
+                               "[E_SYSTEM] Failed to register the device event listener to _BluetoothSystemAdapter.");
+               return E_SYSTEM;
+       }
+
+       // checks the initial state of local Bluetooth
+       __stateMutex.Acquire();
+
+       if (__pGapAdapter->IsActivated() == true)
+       {
+               if (__pGapAdapter->IsDiscoveryInProgress() == true)
+               {
+                       __currentState = _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM;
+               }
+               else
+               {
+                       __currentState = _BT_MGR_STATE_ACTIVATED;
+               }
+       }
+
+       __stateMutex.Release();
+
+       __pMgrEvent = move(pMgrEvent);
+       __pDevEvent = move(pDevEvent);
+       __pConEvent = move(pConEvent);
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothManagerImpl::Activate(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_DEACTIVATED:
+               r = __pGapAdapter->Activate();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_ACTIVATING;
+               }
+               break;
+
+       case _BT_MGR_STATE_ACTIVATING:
+               r = E_IN_PROGRESS;
+               break;
+
+       default:
+               r = E_INVALID_OPERATION;
+               break;
+       }
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on activating Bluetooth.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::Deactivate(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_DEACTIVATED:
+       case _BT_MGR_STATE_ACTIVATING:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_MGR_STATE_DEACTIVATING:
+               r = E_IN_PROGRESS;
+               break;
+
+       default:
+               r = __pGapAdapter->Deactivate();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_DEACTIVATING;
+               }
+               break;
+       }
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on deactivating Bluetooth.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+bool
+_BluetoothManagerImpl::IsAvailable(BluetoothConnectionType type) const
+{
+       return __pGapAdapter->IsAvailable(type);
+}
+
+const BluetoothDevice*
+_BluetoothManagerImpl::GetLocalDevice(void)
+{
+       ByteBuffer localAddr;
+       String localAddrStr;
+       String localName;
+       result r = E_SUCCESS;
+       _BluetoothDeviceImpl* pImpl = null;
+
+       // Gets the Bluetooth address.
+       localAddrStr = __pGapAdapter->GetLocalDeviceAddress();
+       localAddr.Construct(_BT_ADDRESS_LENGTH);
+       r = _BluetoothDeviceImpl::GetAddressByteBuffer(localAddrStr, L":", localAddr);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] Getting the Bluetooth address has failed.");
+
+       // Gets the Bluetooth local name.
+       localName = GetLocalDeviceName();
+
+       if (__pLocalDevice == null)
+       {
+               __pLocalDevice = new (std::nothrow) BluetoothDevice();
+               if (__pLocalDevice == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient on creation of BluetoothDevice.");
+                       SetLastResult(E_OUT_OF_MEMORY);
+                       return null;
+               }
+
+               pImpl = _BluetoothDeviceImpl::GetInstance(*__pLocalDevice);
+               pImpl->SetAddress(localAddr);
+               pImpl->SetName(localName);
+               pImpl->SetMajorDeviceClassType(BT_COD_MAJ_DEV_CLS_PHONE);
+               pImpl->SetMinorDeviceClassType(BT_COD_MIN_DEV_CLS_CELLULAR);
+               pImpl->SetServiceClassList(BT_COD_SVC_UNKNOWN);
+               pImpl->SetServiceList(BT_SVC_NONE);
+       }
+       else
+       {
+               r = _BluetoothDeviceImpl::GetInstance(*__pLocalDevice)->SetAddress(localAddr);
+               if (r == E_SUCCESS)
+               {
+                       _BluetoothDeviceImpl::GetInstance(*__pLocalDevice)->SetName(localName);
+               }
+               else
+               {
+                       SysLogException(NID_NET_BT, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
+                       SetLastResult(E_SYSTEM);
+                       return null;
+               }
+       }
+
+       SetLastResult(E_SUCCESS);
+
+       return __pLocalDevice;
+}
+
+Tizen::Base::String
+_BluetoothManagerImpl::GetLocalDeviceAddress(void) const
+{
+       return __pGapAdapter->GetLocalDeviceAddress();
+}
+
+Tizen::Base::String
+_BluetoothManagerImpl::GetLocalDeviceName(void) const
+{
+       result r = E_SUCCESS;
+       String localName;
+
+       // Get the local name from osp-connectivity-service.
+       r = __pIpcProxy->GetLocalDeviceName(localName);
+       SysTryLog(NID_NET_BT, r == E_SUCCESS, "Getting the local name through osp-connectivity-service has failed.");
+       // Ignores other cases
+
+       return localName;
+}
+
+BluetoothDeviceStateType
+_BluetoothManagerImpl::GetLocalDeviceState() const
+{
+       if (__pGapAdapter->IsActivated() == true)
+       {
+               if (__pGapAdapter->GetDiscoverableMode() == BT_DISC_MODE_DISCOVERABLE)
+               {
+                       return BT_DEVICE_STATE_DISCOVERABLE;
+               }
+
+               return BT_DEVICE_STATE_NOT_DISCOVERABLE;
+       }
+
+       return BT_DEVICE_STATE_OFF;
+}
+
+int
+_BluetoothManagerImpl::GetRemainingTimeAsDiscoverable(void) const
+{
+       return __pGapAdapter->GetRemainingTimeAsDiscoverable();
+}
+
+bool
+_BluetoothManagerImpl::IsActivated(void) const
+{
+       return __pGapAdapter->IsActivated();
+}
+
+BluetoothDiscoverableMode
+_BluetoothManagerImpl::GetDiscoverableMode(void) const
+{
+       return __pGapAdapter->GetDiscoverableMode();
+}
+
+bool
+_BluetoothManagerImpl::IsDiscoveryInProgress(void) const
+{
+       return __pGapAdapter->IsDiscoveryInProgress();
+}
+
+result
+_BluetoothManagerImpl::SetLocalDeviceName(const Tizen::Base::String& deviceName)
+{
+       result r = E_SUCCESS;
+
+       SysTryReturn(NID_NET_BT, deviceName.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The specified input name is an empty string.");
+
+       // Sets the local name through osp-connectivity-service.
+       r = __pIpcProxy->SetLocalDeviceName(deviceName);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, r, r,
+                               "[%s] Setting the local device name through osp-connectivity-service has failed.", GetErrorMessage(r));
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothManagerImpl::SetDiscoverableMode(BluetoothDiscoverableMode mode, int seconds)
+{
+       result r = E_SUCCESS;
+
+       // Sets the discoverable mode through osp-connectivity-service.
+       r = __pIpcProxy->SetDiscoverableMode((int)mode, seconds);
+       SysTryReturnResult(NID_NET_BT, r != E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
+                               "The application does not have the privilege to call this method.");
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, r, r,
+                               "[%s] Setting the the discoverable mode through osp-connectivity-service has failed.", GetErrorMessage(r));
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothManagerImpl::RefreshPairedDeviceList(void)
+{
+       result r = E_SUCCESS;
+       IList* pList = null;
+       BluetoothDevice* pPairedDevice = null;
+       int numOfElements = 0;
+
+       pList = __pGapAdapter->GetAllPairedDeviceListN();
+
+       if (pList != null)
+       {
+               __pairedDeviceList.RemoveAll(true);
+               numOfElements = pList->GetCount();
+
+               for (int i = 0; i < numOfElements; i++)
+               {
+                       pPairedDevice = (BluetoothDevice*) pList->GetAt(i);
+
+                       if (pPairedDevice != null)
+                       {
+                               r = __pairedDeviceList.Add(*pPairedDevice);
+
+                               // propagates all kinds of exception as E_SYSTEM
+                               // except E_OUT_OF_MEMORY
+                               r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+                       }
+                       else
+                       {
+                               r = E_SYSTEM;
+                       }
+
+                       if (r != E_SUCCESS)
+                       {
+                               pList->RemoveAll(true);
+                               __pairedDeviceList.RemoveAll(false);
+                               break;
+                       }
+               }
+
+               delete pList;
+       }
+       else
+       {
+               r = E_SYSTEM;
+       }
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] Internal error occurred on getting all paired device list from system.", GetErrorMessage(r));
+       }
+
+       return r;
+}
+
+const BluetoothDevice*
+_BluetoothManagerImpl::GetPairedDeviceByAddress(const Tizen::Base::ByteBuffer& deviceAddress) const
+{
+       const ByteBuffer* pAddress = null;
+       int numOfElements = 0;
+
+       numOfElements = __pairedDeviceList.GetCount();
+
+       for (int i = 0; i < numOfElements; i++)
+       {
+               BluetoothDevice* pListDevice = (BluetoothDevice*) __pairedDeviceList.GetAt(i);
+
+               if (pListDevice != null)
+               {
+                       pAddress = pListDevice->GetAddress();
+
+                       if (pAddress->Equals(deviceAddress))
+                       {
+                               return pListDevice;
+                       }
+               }
+       }
+
+       SysLogException(NID_NET_BT, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] No device is matched by the input address.");
+       SetLastResult(E_OBJ_NOT_FOUND);
+
+       return null;
+}
+
+BluetoothDevice*
+_BluetoothManagerImpl::GetPairedDeviceByAddressN(const Tizen::Base::ByteBuffer& deviceAddress) const
+{
+       BluetoothDevice* pResultDevice = null;
+       const BluetoothDevice* pListedDevice = null;
+       result r = E_SUCCESS;
+
+       (const_cast<_BluetoothManagerImpl*>(this))->__pairedDevMapMutex.Acquire();
+
+       pListedDevice = dynamic_cast<const BluetoothDevice*>(__pairedDeviceMap.GetValue(deviceAddress));
+       if (pListedDevice != null)
+       {
+               pResultDevice = new (std::nothrow) BluetoothDevice(*pListedDevice);
+               if (pResultDevice == null)
+               {
+                       r = GetLastResult();
+               }
+       }
+       else
+       {
+               r = E_OBJ_NOT_FOUND;
+       }
+
+       (const_cast<_BluetoothManagerImpl*>(this))->__pairedDevMapMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred.", GetErrorMessage(r));
+               SetLastResult(r);
+       }
+
+       return pResultDevice;
+}
+
+Tizen::Base::Collection::IList*
+_BluetoothManagerImpl::GetPairedDeviceByNameN(const Base::String& deviceName) const
+{
+       unique_ptr<ArrayList, AllElementsDeleter> pSearchedList;
+       BluetoothDevice* pListedDevice = null;
+       BluetoothDevice* pResultDevice = null;
+       result r = E_SUCCESS;
+
+       pSearchedList.reset(new (std::nothrow) ArrayList);
+
+       if (pSearchedList != null)
+       {
+               // initialize the capacity of the result list
+               pSearchedList->Construct(2);
+               (const_cast<_BluetoothManagerImpl*>(this))->__pairedDevMapMutex.Acquire();
+
+               IMapEnumerator* pMapEnum = __pairedDeviceMap.GetMapEnumeratorN();
+
+               if (pMapEnum)
+               {
+                       while (pMapEnum->MoveNext() == E_SUCCESS)
+                       {
+                               pListedDevice = dynamic_cast<BluetoothDevice*>(pMapEnum->GetValue());
+                               if (pListedDevice != null)
+                               {
+                                       String listedDeviceName = pListedDevice->GetName();
+                                       int indexOf = 0;
+
+                                       if (listedDeviceName.IndexOf(deviceName, 0, indexOf) == E_SUCCESS)
+                                       {
+                                               pResultDevice = new (std::nothrow) BluetoothDevice(*pListedDevice);
+                                               if (pResultDevice == null)
+                                               {
+                                                       r = GetLastResult();
+                                                       break;
+                                               }
+
+                                               // doesn't check the result of Add() method to avoid the versioning issue
+                                               (void) pSearchedList->Add(*pResultDevice);
+                                       }
+                               }
+                       }
+
+                       delete pMapEnum;
+               }
+               else
+               {
+                       r = E_OUT_OF_MEMORY;
+               }
+
+               (const_cast<_BluetoothManagerImpl*>(this))->__pairedDevMapMutex.Release();
+       }
+       else
+       {
+               r = E_OUT_OF_MEMORY;
+       }
+
+       if ((r == E_SUCCESS) && (pSearchedList->GetCount() <= 0))
+       {
+               r = E_OBJ_NOT_FOUND;
+       }
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred.", GetErrorMessage(r));
+               SetLastResult(r);
+               return null;
+       }
+
+       return pSearchedList.release();
+}
+
+const BluetoothDevice*
+_BluetoothManagerImpl::GetPairedDeviceAt(int index) const
+{
+       BluetoothDevice* pResultDevice = null;
+
+       if ((index >= 0) && (index < __pairedDeviceList.GetCount()))
+       {
+               pResultDevice = (BluetoothDevice*) __pairedDeviceList.GetAt(index);
+       }
+
+       if (pResultDevice == null)
+       {
+               SysLogException(NID_NET_BT, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Index is not available.");
+               SetLastResult(E_OBJ_NOT_FOUND);
+       }
+
+       return pResultDevice;
+}
+
+const Tizen::Base::Collection::IList*
+_BluetoothManagerImpl::GetPairedDeviceList(void) const
+{
+       return &__pairedDeviceList;
+}
+
+Tizen::Base::Collection::IList*
+_BluetoothManagerImpl::GetPairedDeviceListN(void) const
+{
+       unique_ptr<ArrayList, AllElementsDeleter> pResultList;
+       BluetoothDevice* pListedDevice = null;
+       BluetoothDevice* pResultDevice = null;
+       result r = E_SUCCESS;
+       int resultCount = 0;
+
+       pResultList.reset(new (std::nothrow) ArrayList);
+
+       if (pResultList)
+       {
+               (const_cast<_BluetoothManagerImpl*>(this))->__pairedDevMapMutex.Acquire();
+
+               // initialize the capacity of the result list
+               resultCount = __pairedDeviceMap.GetCount();
+               pResultList->Construct(resultCount);
+
+               IMapEnumerator* pMapEnum = __pairedDeviceMap.GetMapEnumeratorN();
+
+               if (pMapEnum)
+               {
+                       while (pMapEnum->MoveNext() == E_SUCCESS)
+                       {
+                               pListedDevice = dynamic_cast<BluetoothDevice*>(pMapEnum->GetValue());
+                               if (pListedDevice != null)
+                               {
+                                       pResultDevice = new (std::nothrow) BluetoothDevice(*pListedDevice);
+                                       if (pResultDevice == null)
+                                       {
+                                               r = GetLastResult();
+                                               break;
+                                       }
+
+                                       // doesn't check the result of Add() method to avoid the versioning issue
+                                       (void) pResultList->Add(*pResultDevice);
+                               }
+                       }
+
+                       delete pMapEnum;
+               }
+               else
+               {
+                       r = E_OUT_OF_MEMORY;
+               }
+
+               (const_cast<_BluetoothManagerImpl*>(this))->__pairedDevMapMutex.Release();
+       }
+       else
+       {
+               r = E_OUT_OF_MEMORY;
+       }
+
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, null, r, "[%s] error occurred.", GetErrorMessage(r));
+
+       return pResultList.release();
+}
+
+result
+_BluetoothManagerImpl::SetBluetoothDeviceListener(IBluetoothDeviceEventListener* pListener)
+{
+       result r = E_SUCCESS;
+
+       SysTryReturnResult(NID_NET_BT, __pDevEvtListener != pListener, E_SUCCESS, "the listener instance is already registered.");
+
+       if (__pDevEvtListener != null)
+       {
+               // remove the previous IBluetoothDeviceEventListener instance from the _BluetoothDeviceEvent.
+               r = __pDevEvent->RemoveListener(*__pDevEvtListener);
+               SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to remove the previous IBluetoothDeviceEventListener.");
+               SysLog(NID_NET_BT, "Removing the previous IBluetoothDeviceEventListener is successful.");
+               __pDevEvtListener = null;
+       }
+
+       if (pListener != null)
+       {
+               // add the specified new IBluetoothDeviceEventListener instance to the _BluetoothDeviceEvent.
+               r = __pDevEvent->AddListener(*pListener, true);
+               SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to add the new IBluetoothDeviceEventListener.");
+               SysLog(NID_NET_BT, "Adding the new IBluetoothDeviceEventListener is successful.");
+               __pDevEvtListener = pListener;
+       }
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::SetBluetoothConnectionListener(_IBluetoothConnectionEventListener* pListener)
+{
+       result r = E_SUCCESS;
+
+       SysTryReturnResult(NID_NET_BT, __pConEvtListener != pListener, E_SUCCESS, "the listener instance is already registered.");
+
+       if (__pConEvtListener != null)
+       {
+               // remove the previous IBluetoothDeviceEventListener instance from the _BluetoothDeviceEvent.
+               r = __pMgrEvent->RemoveListener(*__pConEvtListener);
+               SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to remove the previous _IBluetoothConnectionEventListener.");
+               SysLog(NID_NET_BT, "Removing the previous _IBluetoothConnectionEventListener is successful.");
+               __pConEvtListener = null;
+       }
+
+       if (pListener != null)
+       {
+               // add the specified new IBluetoothDeviceEventListener instance to the _BluetoothDeviceEvent.
+               r = __pMgrEvent->AddListener(*pListener, true);
+               SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Failed to add the new _IBluetoothConnectionEventListener.");
+               SysLog(NID_NET_BT, "Adding the new _IBluetoothConnectionEventListener is successful.");
+               __pConEvtListener = pListener;
+       }
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::StartDiscovery(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __discoveredDeviceList.RemoveAll(true);
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ACTIVATED:
+               r = __pGapAdapter->StartDiscovery();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_DISCOVERY_REQUESTED;
+               }
+               break;
+
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+       case _BT_MGR_STATE_ON_DISCOVERY:
+       case _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM:
+               r = E_IN_PROGRESS;
+               break;
+
+       default:
+               r = E_INVALID_OPERATION;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on starting the device discovery.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::CancelDiscovery(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+       case _BT_MGR_STATE_ON_DISCOVERY:
+               r = __pGapAdapter->CancelDiscovery();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_DISCOVERY_CANCELING;
+               }
+               break;
+
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+               r = E_IN_PROGRESS;
+               break;
+
+       default:
+               r = E_INVALID_OPERATION;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on canceling the device discovery.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::RetrieveServiceList(const BluetoothDevice& pairedDevice)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+       const ByteBuffer* pKeyAddress = null;
+       BluetoothDevice* pListedDevice = null;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ACTIVATED:
+               // check paredDevice really exists in the paired device list
+               pKeyAddress = pairedDevice.GetAddress();
+
+               __pairedDevMapMutex.Acquire();
+
+               // TODO: move to the following logic to _BluetoothSystemAdapter::IsPaired()
+               pListedDevice = (BluetoothDevice*) __pairedDeviceMap.GetValue(*pKeyAddress);
+               if (pListedDevice)
+               {
+                       r = __pGapAdapter->RetrieveServiceList(*pKeyAddress);
+               }
+               else
+               {
+                       r = E_NOT_PAIRED;
+               }
+
+               __pairedDevMapMutex.Release();
+
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_SERVICE_RETRIEVING;
+               }
+               break;
+
+       case _BT_MGR_STATE_SERVICE_RETRIEVING:
+               r = E_IN_PROGRESS;
+               break;
+
+       default:
+               r = E_INVALID_OPERATION;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on retrieving the service list from the remote device.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::Pair(const BluetoothDevice& remoteDevice)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [PairingState:%s]", GetStringOfCurrentState(), GetStringOfPairingState());
+
+       result r = E_SUCCESS;
+       const ByteBuffer* pAddress = null;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ACTIVATED:
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+       case _BT_MGR_STATE_ON_DISCOVERY:
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+       case _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM:
+       case _BT_MGR_STATE_SERVICE_RETRIEVING:
+               if (__pairingState == _BT_PAIRING_STATE_NONE)
+               {
+                       pAddress = remoteDevice.GetAddress();
+                       r = __pGapAdapter->Pair(*pAddress);
+                       if (r == E_SUCCESS)
+                       {
+                               // copy the address of the pairing device to the local variable
+                               __pairingTargetAddress.SetArray(pAddress->GetPointer(), 0, _BT_ADDRESS_LENGTH);
+                               __pairingTargetAddress.SetPosition(0);
+
+                               __pairingState = _BT_PAIRING_STATE_PAIRING;
+                       }
+               }
+               else
+               {
+                       r = E_DEVICE_BUSY;
+               }
+               break;
+
+       default:
+               r = E_INVALID_OPERATION;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on pairing with the remote device.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PairingState:%s], [result:%s]", GetStringOfCurrentState(),
+                       GetStringOfPairingState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::CancelPair(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [PairingState:%s]", GetStringOfCurrentState(), GetStringOfPairingState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ACTIVATED:
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+       case _BT_MGR_STATE_ON_DISCOVERY:
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+       case _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM:
+       case _BT_MGR_STATE_SERVICE_RETRIEVING:
+               if (__pairingState == _BT_PAIRING_STATE_PAIRING)
+               {
+                       r = __pGapAdapter->CancelPair();
+                       if (r == E_SUCCESS)
+                       {
+                               __pairingState = _BT_PAIRING_STATE_CANCELING;
+                       }
+               }
+               else if (__pairingState == _BT_PAIRING_STATE_CANCELING)
+               {
+                       r = E_IN_PROGRESS;
+               }
+               else
+               {
+                       r = E_INVALID_OPERATION;
+               }
+               break;
+
+       default:
+               r = E_INVALID_OPERATION;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on canceling the pairing process.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PairingState:%s], [result:%s]", GetStringOfCurrentState(),
+                       GetStringOfPairingState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothManagerImpl::Unpair(const BluetoothDevice& pairedDevice)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [PairingState:%s]", GetStringOfCurrentState(), GetStringOfPairingState());
+
+       result r = E_SUCCESS;
+       const ByteBuffer* pKeyAddress = null;
+       BluetoothDevice* pListedDevice = null;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ACTIVATED:
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+       case _BT_MGR_STATE_ON_DISCOVERY:
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+       case _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM:
+       case _BT_MGR_STATE_SERVICE_RETRIEVING:
+               // check paredDevice really exists in the paired device list
+               pKeyAddress = pairedDevice.GetAddress();
+
+               __pairedDevMapMutex.Acquire();
+
+               // TODO: move to the following logic to _BluetoothSystemAdapter::IsPaired()
+               pListedDevice = (BluetoothDevice*) __pairedDeviceMap.GetValue(*pKeyAddress);
+               if (pListedDevice)
+               {
+                       r = __pGapAdapter->Unpair(*pKeyAddress);
+               }
+               else
+               {
+                       r = E_NOT_PAIRED;
+               }
+
+               __pairedDevMapMutex.Release();
+
+               break;
+
+       default:
+               r = E_INVALID_OPERATION;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on unpairing with the remote device.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PairingState:%s], [result:%s]", GetStringOfCurrentState(),
+                       GetStringOfPairingState(), GetErrorMessage(r));
+
+       return r;
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothActivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+       result resRefresh = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_DEACTIVATED:
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_ACTIVATED;
+                       isFired = true;
+               }
+               break;
+
+       case _BT_MGR_STATE_ACTIVATING:
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_ACTIVATED;
+               }
+               else
+               {
+                       __currentState = _BT_MGR_STATE_DEACTIVATED;
+               }
+               isFired = true;
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       // refresh the paired device list
+       resRefresh = RefreshPairedDeviceList();
+       SysLog(NID_NET_BT, "Refreshing the paired device list %s.", (resRefresh == E_SUCCESS) ? "is successful" : "fails");
+
+       // refresh the paired device map which is used since 2.0
+       resRefresh = RefreshPairedDeviceMap();
+       SysLog(NID_NET_BT, "Refreshing the paired device map %s.", (resRefresh == E_SUCCESS) ? "is successful" : "fails");
+
+       if (isFired)
+       {
+               _BluetoothManagerEventArg* pArg = new (std::nothrow) _BluetoothManagerEventArg(_BT_MANAGER_EVENT_ACTIVATED, r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pMgrEvent->FireAsync(*pArg);
+               }
+       }
+
+       if ((isFired) && (r != E_SUCCESS))
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred in Bluetooth activation callback.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ACTIVATED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothDeactivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ACTIVATED:
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+       case _BT_MGR_STATE_ON_DISCOVERY:
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+       case _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM:
+       case _BT_MGR_STATE_SERVICE_RETRIEVING:
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_DEACTIVATED;
+                       isFired = true;
+               }
+               break;
+
+       case _BT_MGR_STATE_DEACTIVATING:
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_DEACTIVATED;
+               }
+               else
+               {
+                       __currentState = _BT_MGR_STATE_ACTIVATED;
+               }
+               isFired = true;
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothManagerEventArg* pArg = new (std::nothrow) _BluetoothManagerEventArg(_BT_MANAGER_EVENT_DEACTIVATED, r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pMgrEvent->FireAsync(*pArg);
+               }
+       }
+
+       if ((isFired) && (r != E_SUCCESS))
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred in Bluetooth deactivation callback.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ACTIVATED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       bool isFired = false;
+
+       _BluetoothManagerEventArg* pArg = new (std::nothrow) _BluetoothManagerEventArg(mode);
+       if (pArg == null)
+       {
+               SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       }
+       else
+       {
+               __pMgrEvent->FireAsync(*pArg);
+               isFired = true;
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [VISIBILITY_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothDiscoveryStarted(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [result:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ACTIVATED:
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM;
+               }
+               break;
+
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_MGR_STATE_ON_DISCOVERY;
+               }
+               else
+               {
+                       __currentState = _BT_MGR_STATE_ACTIVATED;
+               }
+
+               isFired = true;
+               break;
+
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+               if (r == E_SUCCESS)
+               {
+                       // the current status is not changed while firing
+                       isFired = true;
+               }
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothDeviceEventArg* pArg = new (std::nothrow) _BluetoothDeviceEventArg(r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pDevEvent->FireAsync(*pArg);
+               }
+
+               if (r != E_SUCCESS)
+               {
+                       SysLogException(NID_NET_BT, r, "[%s] exception occurred in the discovery discovery callback.", GetErrorMessage(r));
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DISCOVERY_STARTED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothRemoteDeviceFound(const BluetoothDevice& foundDevice)
+{
+       bool isFired = false;
+       unique_ptr<ByteBuffer> pFoundDeviceAddress;
+       _BluetoothDeviceEventArg* pArg = null;
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ON_DISCOVERY:
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+               pFoundDeviceAddress.reset(new (std::nothrow) ByteBuffer());
+               if(pFoundDeviceAddress == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       break;
+               }
+               pFoundDeviceAddress->Construct(*foundDevice.GetAddress());
+
+               if(__discoveredDeviceList.Contains(*pFoundDeviceAddress.get()) == true)
+               {
+                       SysLog(NID_NET_BT, "The found device already exist.");
+                       break;
+               }
+
+               (void) __discoveredDeviceList.Add(*pFoundDeviceAddress.release());
+
+               pArg = new (std::nothrow) _BluetoothDeviceEventArg(_BT_DEVICE_EVENT_DEVICE_FOUND,
+                               foundDevice);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+               }
+               else
+               {
+                       __pDevEvent->FireAsync(*pArg);
+                       isFired = true;
+               }
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       SysLog(NID_NET_BT, "[CurrentState:%s], [DEVICE_FOUND_Event:%s]", GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothDiscoveryDone(bool isCompleted)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [DiscoveryDone:%s]",
+                               GetStringOfCurrentState(), isCompleted ? "Completed" : "NotCompleted");
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_ON_DISCOVERY:
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+               __currentState = _BT_MGR_STATE_ACTIVATED;
+               isFired = true;
+               break;
+
+       case _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM:
+               __currentState = _BT_MGR_STATE_ACTIVATED;
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothDeviceEventArg* pArg = new (std::nothrow) _BluetoothDeviceEventArg(isCompleted);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pDevEvent->FireAsync(*pArg);
+               }
+       }
+
+       __discoveredDeviceList.RemoveAll(true);
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DISCOVERY_DONE_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothServiceListReceived(const Tizen::Base::ByteBuffer& address, unsigned long serviceList,
+                                                                                                               const Tizen::Base::Collection::IList* pServiceUuidList, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ServiceList:%ld], [result:%s]",
+                               GetStringOfCurrentState(), serviceList, GetErrorMessage(r));
+
+       bool isFired = false;
+       BluetoothDevice* pListedDevice = null;
+       BluetoothDevice* pResultDevice = null;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_SERVICE_RETRIEVING:
+               __currentState = _BT_MGR_STATE_ACTIVATED;
+               isFired = true;
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       // updates internal information regardless of the current status if r is E_SUCCESS
+       __pairedDevMapMutex.Acquire();
+
+       pListedDevice = (BluetoothDevice*) __pairedDeviceMap.GetValue(address);
+
+       if (pListedDevice != null)
+       {
+               if ((r == E_SUCCESS) && (pServiceUuidList != null))
+               {
+                       _BluetoothDeviceImpl* pDevImpl = _BluetoothDeviceImpl::GetInstance(*pListedDevice);
+                       pDevImpl->SetServiceList(serviceList);
+                       pDevImpl->SetServiceUuidList(pServiceUuidList, true);
+               }
+
+               if (isFired == true)
+               {
+                       // target device instance should be copied
+                       // because the original instance in the list is able to be removed out of the mutex span.
+                       pResultDevice = new (std::nothrow) BluetoothDevice(*pListedDevice);
+                       if (pResultDevice == null)
+                       {
+                               r = E_SYSTEM;
+                       }
+               }
+       }
+       else
+       {
+               r = E_SYSTEM;
+       }
+
+       __pairedDevMapMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               serviceList = 0;
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred in the service list reception callback.", GetErrorMessage(r));
+       }
+
+       if (isFired)
+       {
+               _BluetoothDeviceEventArg* pArg = null;
+               if (pResultDevice == null)
+               {
+                       // It is almost impossible for this case to occur.
+                       // The only case is that the paired device is unpaired and removed from the paired list
+                       // during the service discovery.
+                       // So, the below code is just to prevent system fault at some undefined exceptional cases.
+                       BluetoothDevice dummyDevice(address, String("Dummy"), BT_COD_MAJ_DEV_CLS_UNCLASSIFIED,
+                                                                               BT_COD_MIN_DEV_CLS_UNCLASSIFIED, 0, 0);
+                       pArg = new (std::nothrow) _BluetoothDeviceEventArg(dummyDevice, serviceList, r);
+               }
+               else
+               {
+                       pArg = new (std::nothrow) _BluetoothDeviceEventArg(*pResultDevice, serviceList, r);
+                       delete pResultDevice;
+               }
+
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pDevEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [result:%s], [SERVICELIST_RECEIVED_Event:%s]",
+                               GetStringOfCurrentState(), GetErrorMessage(r), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [PairingState:%s], [result:%s]",
+                               GetStringOfCurrentState(), GetStringOfPairingState(), GetErrorMessage(r));
+
+       result res = E_SUCCESS;
+       bool isFired = false;
+       const ByteBuffer* pKeyAddress = null;
+       BluetoothDevice* pListedDevice = null;
+       ByteBuffer* pCloneAddress = null;
+       BluetoothDevice* pCloneDevice = null;
+       _BluetoothDeviceEventArg* pArg = null;
+
+       pKeyAddress = pPairedDevice->GetAddress();
+
+       // update the paired list regardless whether the pairing operation is issued by this instance or not
+       // when the pairing process is finished successfully.
+       if (r == E_SUCCESS)
+       {
+               __pairedDevMapMutex.Acquire();
+
+               pListedDevice = dynamic_cast<BluetoothDevice*> (__pairedDeviceMap.GetValue(*pKeyAddress));
+               res = GetLastResult();
+
+               // insert the clone instance of the paired device into the paired device list
+               if ((pListedDevice == null) && (res == E_OBJ_NOT_FOUND))
+               {
+                       pCloneAddress = new (std::nothrow) ByteBuffer();
+                       if (pCloneAddress)
+                       {
+                               pCloneAddress->Construct(*pKeyAddress);
+                               pCloneDevice = new (std::nothrow) BluetoothDevice(*pPairedDevice);
+                               if (pCloneDevice)
+                               {
+                                       r = __pairedDeviceMap.Add(*pCloneAddress, *pCloneDevice);
+                                       // TODO: the following statement should be replaced by the special MACRO function.
+                                       r = (r == E_SUCCESS) ? E_SUCCESS : E_OPERATION_FAILED;
+                               }
+                               else
+                               {
+                                       delete pCloneAddress;
+                                       r = E_OUT_OF_MEMORY;
+                               }
+                       }
+                       else
+                       {
+                               r = E_OUT_OF_MEMORY;
+                       }
+               }
+               // If the device is already contained in the paired list, the BluetoothDevice instance is updated.
+               else if (pListedDevice != null)
+               {
+                       *pListedDevice = *pPairedDevice;
+               }
+
+               __pairedDevMapMutex.Release();
+       }
+
+       // send event if the pairing process is finished successfully.
+       if (r == E_SUCCESS)
+       {
+               __pairingState = _BT_PAIRING_STATE_NONE;
+               pArg = new (std::nothrow) _BluetoothDeviceEventArg(pPairedDevice, E_SUCCESS);
+               SysTryReturnVoidResult(NID_NET_BT, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient." );
+               isFired = true;
+       }
+       // send event if the pairing operation is issued by this instance although the pairing process fails.
+       else if ((__pairingState != _BT_PAIRING_STATE_NONE) && (pPairedDevice->GetAddress()->Equals(__pairingTargetAddress)))
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred in the paired callback.", GetErrorMessage(r));
+               __pairingState = _BT_PAIRING_STATE_NONE;
+               pArg = new (std::nothrow) _BluetoothDeviceEventArg(null, r);
+               SysTryReturnVoidResult(NID_NET_BT, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient." );
+               isFired = true;
+       }
+
+       if (isFired == true)
+       {
+               __pDevEvent->FireAsync(*pArg);
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PairingState:%s], [PAIRED_Event:%s]",
+                               GetStringOfCurrentState(), GetStringOfPairingState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothUnpaired(const Tizen::Base::ByteBuffer& address)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [PairingState:%s]", GetStringOfCurrentState(), GetStringOfPairingState());
+
+       result r = E_SUCCESS;
+       bool isFired = false;
+       BluetoothDevice* pListedDevice = null;
+       BluetoothDevice* pResultDevice = null;
+
+       __pairedDevMapMutex.Acquire();
+
+       pListedDevice = (BluetoothDevice*) __pairedDeviceMap.GetValue(address);
+       if (pListedDevice != null)
+       {
+               // target device instance should be copied
+               // because the original instance in the list will be removed from the list and deleted below.
+               pResultDevice = new (std::nothrow) BluetoothDevice(*pListedDevice);
+               if (pResultDevice != null)
+               {
+                       isFired = true;
+               }
+
+               // Removes the unpaired device from the paired device list regardless whether the listener exists or not.
+               (void) __pairedDeviceMap.Remove(address, true);
+       }
+       else
+       {
+               r = GetLastResult();
+       }
+
+       __pairedDevMapMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothDeviceEventArg* pArg = new (std::nothrow) _BluetoothDeviceEventArg(_BT_DEVICE_EVENT_UNPAIRED, *pResultDevice);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pDevEvent->FireAsync(*pArg);
+               }
+       }
+
+       delete pResultDevice;
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred in the unpaired callback.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PairingState:%s], [UNPAIRED_Event:%s]",
+                               GetStringOfCurrentState(), GetStringOfPairingState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothDeviceConnected(const Tizen::Base::ByteBuffer& address)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       bool isFired = false;
+
+       _BluetoothConnectionEventArg* pArg = new (std::nothrow) _BluetoothConnectionEventArg(_BT_CONNECTION_EVENT_CONNECTED, address);
+       if (pArg == null)
+       {
+               SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       }
+       else
+       {
+               __pConEvent->FireAsync(*pArg);
+               isFired = true;
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [CONNECTED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothManagerImpl::OnBluetoothDeviceDisconnected(const Tizen::Base::ByteBuffer& address)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       bool isFired = false;
+
+       _BluetoothConnectionEventArg* pArg = new (std::nothrow) _BluetoothConnectionEventArg(_BT_CONNECTION_EVENT_DISCONNECTED, address);
+       if (pArg == null)
+       {
+               SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       }
+       else
+       {
+               __pConEvent->FireAsync(*pArg);
+               isFired = true;
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DISCONNECTED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+result
+_BluetoothManagerImpl::RefreshPairedDeviceMap(void)
+{
+       result r = E_SUCCESS;
+       BluetoothDevice* pPairedDevice = null;
+       ByteBuffer* pKeyAddress = null;
+       IList* pList = null;
+
+       pList = __pGapAdapter->GetAllPairedDeviceListN();
+       SysTryReturn(NID_NET_BT, pList != null, E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] Internal error occurred on getting all paired device list from system.");
+
+       __pairedDevMapMutex.Acquire();
+
+       // remove all BluetoothDevice instance which the paired device map contains
+       __pairedDeviceMap.RemoveAll(true);
+
+       for (int i = 0; i < pList->GetCount(); i++)
+       {
+               pPairedDevice = (BluetoothDevice*) pList->GetAt(i);
+
+               pKeyAddress = new (std::nothrow) ByteBuffer();
+
+               if (pKeyAddress)
+               {
+                       pKeyAddress->Construct(*(pPairedDevice->GetAddress()));
+
+                       r = __pairedDeviceMap.Add(*pKeyAddress, *pPairedDevice);
+                       if (r != E_SUCCESS)
+                       {
+                               // determines the exception type to be passed to the application.
+                               // propagates only E_OUT_OF_MEMORY exception.
+                               if (r != E_OUT_OF_MEMORY)
+                               {
+                                       r = E_SYSTEM;
+                               }
+
+                               delete pKeyAddress;
+                               break;
+                       }
+               }
+               else
+               {
+                       r = E_OUT_OF_MEMORY;
+                       break;
+               }
+       }
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] Internal error occurred on getting all paired device list from system.", GetErrorMessage(r));
+               __pairedDeviceMap.RemoveAll(true);
+       }
+
+       __pairedDevMapMutex.Release();
+
+       delete pList;
+
+       return r;
+}
+
+const char*
+_BluetoothManagerImpl::GetStringOfCurrentState(void) const
+{
+       const char* pStateString = null;
+
+       switch (__currentState)
+       {
+       case _BT_MGR_STATE_DEACTIVATED:
+               pStateString = "DEACTIVATED";
+               break;
+
+       case _BT_MGR_STATE_ACTIVATING:
+               pStateString = "ACTIVATING";
+               break;
+
+       case _BT_MGR_STATE_DEACTIVATING:
+               pStateString = "DEACTIVATING";
+               break;
+
+       case _BT_MGR_STATE_ACTIVATED:
+               pStateString = "ACTIVATED";
+               break;
+
+       case _BT_MGR_STATE_DISCOVERY_REQUESTED:
+               pStateString = "DISCOVERY_REQUESTED";
+               break;
+
+       case _BT_MGR_STATE_ON_DISCOVERY:
+               pStateString = "ON_DISCOVERY";
+               break;
+
+       case _BT_MGR_STATE_DISCOVERY_CANCELING:
+               pStateString = "DISCOVERY_CANCELING";
+               break;
+
+       case _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM:
+               pStateString = "ON_DISCOVERY_BY_SYSTEM";
+               break;
+
+       case _BT_MGR_STATE_SERVICE_RETRIEVING:
+               pStateString = "SERVICE_RETRIEVING";
+               break;
+
+       default:
+               pStateString = "Unknown";
+               break;
+       }
+
+       return pStateString;
+}
+
+const char*
+_BluetoothManagerImpl::GetStringOfPairingState(void) const
+{
+       const char* pStateString = null;
+
+       switch (__pairingState)
+       {
+       case _BT_PAIRING_STATE_NONE:
+               pStateString = "NONE";
+               break;
+
+       case _BT_PAIRING_STATE_PAIRING:
+               pStateString = "PAIRING";
+               break;
+
+       case _BT_PAIRING_STATE_CANCELING:
+               pStateString = "CANCELING";
+               break;
+
+       default:
+               pStateString = "Unknown";
+               break;
+       }
+
+       return pStateString;
+}
+
+_BluetoothManagerImpl*
+_BluetoothManagerImpl::GetInstance(BluetoothManager& bluetoothManager)
+{
+       return bluetoothManager.__pImpl;
+}
+
+const _BluetoothManagerImpl*
+_BluetoothManagerImpl::GetInstance(const BluetoothManager& bluetoothManager)
+{
+       return bluetoothManager.__pImpl;
+}
+
+} } } // Tizen::Net::Bluetooth
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+_OSP_EXPORT_ result
+_BluetoothManagerImpl_Activate(void)
+{
+       Tizen::Net::Bluetooth::_BluetoothGapSystemAdapter* pGapAdapter =
+                                       Tizen::Net::Bluetooth::_BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturnResult(NID_NET_BT, pGapAdapter != null, E_OUT_OF_MEMORY,
+                                       "Failed to get an instance of _BluetoothGapSystemAdapter.");
+
+       return pGapAdapter->Activate();
+}
+
+_OSP_EXPORT_ result
+_BluetoothManagerImpl_Deactivate(void)
+{
+       Tizen::Net::Bluetooth::_BluetoothGapSystemAdapter* pGapAdapter =
+                                       Tizen::Net::Bluetooth::_BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturnResult(NID_NET_BT, pGapAdapter != null, E_OUT_OF_MEMORY,
+                                       "Failed to get an instance of _BluetoothGapSystemAdapter.");
+
+       return pGapAdapter->Deactivate();
+}
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/src/FNetBt_BluetoothOppClientEvent.cpp b/src/FNetBt_BluetoothOppClientEvent.cpp
new file mode 100644 (file)
index 0000000..4aa4c83
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// 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    FNetBt_BluetoothOppClientEvent.cpp
+// @brief   This is the implementation file for the _BluetoothOppClientEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
+#include "FNetBt_BluetoothOppClientEvent.h"
+#include "FNetBt_BluetoothOppClientEventArg.h"
+#include "FNetBtIBluetoothOppClientEventListener.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothOppClientEvent::_BluetoothOppClientEvent(void)
+{
+}
+
+_BluetoothOppClientEvent::~_BluetoothOppClientEvent(void)
+{
+}
+
+result
+_BluetoothOppClientEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothOppClientEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       IBluetoothOppClientEventListener* pListener = dynamic_cast <IBluetoothOppClientEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pListener != null, E_INVALID_ARG, "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothOppClientEventArg* pEventArg = dynamic_cast <const _BluetoothOppClientEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothOppClientEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case _BT_OPP_CLIENT_EVENT_PUSH_RESPONDED:
+               SysLog(NID_NET_BT, "Firing Bluetooth OPP Client Event (Type: _BT_OPP_CLIENT_EVENT_PUSH_RESPONDED)");
+               pListener->OnOppPushResponded(pEventArg->GetErrorResult());
+               break;
+
+       case _BT_OPP_CLIENT_EVENT_TRANSFER_DONE:
+               SysLog(NID_NET_BT, "Firing Bluetooth OPP Client Event (Type: _BT_OPP_CLIENT_EVENT_TRANSFER_DONE)");
+               pListener->OnOppTransferDone(pEventArg->GetFilePath(), pEventArg->GetFileSize(), pEventArg->IsTransferCompleted());
+               break;
+
+       case _BT_OPP_CLIENT_EVENT_TRANSFER_PROGRESS:
+               SysLog(NID_NET_BT, "Firing Bluetooth OPP Client Event (Type: _BT_OPP_CLIENT_EVENT_TRANSFER_PROGRESS)");
+               pListener->OnOppTransferInProgress(pEventArg->GetPercent());
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothOppClientEvent.h b/src/FNetBt_BluetoothOppClientEvent.h
new file mode 100644 (file)
index 0000000..0285569
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// 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    FNetBt_BluetoothOppClientEvent.h
+ * @brief   This is the header file for the _BluetoothOppClientEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothOppClientEvent class.
+ * The _BluetoothOppClientEvent class can call a method of a listener (IBluetoothOppClientEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+// Forward declaration
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// @class   _BluetoothOppClientEvent
+// @brief   This class handles Bluetooth OPP Client events.
+//
+// When a Bluetooth device event occurs, the _BluetoothOppClientEvent object finds a IBluetoothOppClientEventListener
+// object and calls an appropriate method of the listener.
+//
+class _BluetoothOppClientEvent
+       : public Tizen::Base::Runtime::_Event
+{
+public:
+       _BluetoothOppClientEvent(void);
+       virtual ~_BluetoothOppClientEvent(void);
+
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate pListener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth OPP Client event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothOppClientEvent(const _BluetoothOppClientEvent& value);
+       _BluetoothOppClientEvent& operator =(const _BluetoothOppClientEvent& rhs);
+
+private:
+       bool __isServerEvent;
+
+}; // _BluetoothOppClientEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_EVENT_H_
diff --git a/src/FNetBt_BluetoothOppClientEventArg.cpp b/src/FNetBt_BluetoothOppClientEventArg.cpp
new file mode 100644 (file)
index 0000000..8871e8e
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// 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    FNetBt_BluetoothOppClientEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothOppClientEventArg class.
+//
+
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothOppClientEventArg.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// This is a class constructor for _BT_OPP_CLIENT_EVENT_PUSH_RESPONDED event.
+//
+_BluetoothOppClientEventArg::_BluetoothOppClientEventArg(result r)
+       : __evtType(_BT_OPP_CLIENT_EVENT_PUSH_RESPONDED)
+       , __result(r)
+       , __filePath()
+       , __fileSize(0)
+       , __isCompleted(true)
+       , __percent(0)
+{
+}
+
+//
+// This is a class constructor for _BT_OPP_CLIENT_EVENT_TRANSFER_DONE event.
+//
+_BluetoothOppClientEventArg::_BluetoothOppClientEventArg(const Tizen::Base::String& filePath, int fileSize, bool isCompleted)
+       : __evtType(_BT_OPP_CLIENT_EVENT_TRANSFER_DONE)
+       , __result(E_SUCCESS)
+       , __filePath(filePath)
+       , __fileSize(fileSize)
+       , __isCompleted(isCompleted)
+       , __percent(0)
+{
+}
+
+//
+// This is a class constructor for _BT_OPP_CLIENT_EVENT_TRANSFER_PROGRESS event.
+//
+_BluetoothOppClientEventArg::_BluetoothOppClientEventArg(int percent)
+       : __evtType(_BT_OPP_CLIENT_EVENT_TRANSFER_PROGRESS)
+       , __result(E_SUCCESS)
+       , __filePath()
+       , __fileSize(0)
+       , __isCompleted(true)
+       , __percent(percent)
+{
+}
+
+_BluetoothOppClientEventArg::~_BluetoothOppClientEventArg(void)
+{
+}
+
+_BluetoothOppClientEventType
+_BluetoothOppClientEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
+
+result
+_BluetoothOppClientEventArg::GetErrorResult(void) const
+{
+       return __result;
+}
+
+Tizen::Base::String
+_BluetoothOppClientEventArg::GetFilePath(void) const
+{
+       return __filePath;
+}
+
+int
+_BluetoothOppClientEventArg::GetFileSize(void) const
+{
+       return __fileSize;
+}
+
+bool
+_BluetoothOppClientEventArg::IsTransferCompleted(void) const
+{
+       return __isCompleted;
+}
+
+int
+_BluetoothOppClientEventArg::GetPercent(void) const
+{
+       return __percent;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothOppClientEventArg.h b/src/FNetBt_BluetoothOppClientEventArg.h
new file mode 100644 (file)
index 0000000..22988de
--- /dev/null
@@ -0,0 +1,153 @@
+//
+// 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    FNetBt_BluetoothOppClientEventArg.h
+ * @brief   This is the header file for the _BluetoothOppClientEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothOppClientEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseString.h>
+#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declaration
+class BluetoothDevice;
+
+/**
+  * @enum    _BluetoothOppClientEventType
+  * Type for specifying the type of _BluetoothOppClientEvent
+  */
+enum _BluetoothOppClientEventType
+{
+       _BT_OPP_CLIENT_EVENT_PUSH_RESPONDED,      /**< For notifying the OPP server responded to the push request */
+       _BT_OPP_CLIENT_EVENT_TRANSFER_DONE,       /**< For notifying the file transfer has finished */
+       _BT_OPP_CLIENT_EVENT_TRANSFER_PROGRESS,       /**< For notifying the file is being transferred */
+};
+
+/**
+ * @class   _BluetoothOppClientEventArg
+ * @brief   This class is used as an argument for callback methods of the _IBluetoothOppClientEventListener class.
+ *
+ * When a _BluetoothOppClientEvent occurs, the _BluetoothOppClientEvent finds a _IBluetoothOppClientEventListener instance
+ * which is registered for the _BluetoothOppClientEvent and calls an appropriate method of the listener.
+ * @see     _IBluetoothOppClientEventListener
+ */
+class _BluetoothOppClientEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor for _BT_OPP_CLIENT_EVENT_PUSH_RESPONDED event.
+        *
+        * @param[in]   r                    The result of the event
+        * @exception   E_SUCCESS            The connection is established successfully.
+        * @exception   E_SYSTEM             The connection fails.
+        */
+       _BluetoothOppClientEventArg(result r);
+
+       /**
+        * This is a class constructor for  _BT_OPP_CLIENT_EVENT_TRANSFER_DONE event.
+        *
+        * @param[in]   filePath            The path of the transferred file
+        * @param[in]   fileSize            The size of the transferred file
+        * @param[in]   isCompleted         Set to @c true if the transfer is successfully completed, @n
+        *                                  else @c false
+        */
+        _BluetoothOppClientEventArg(const Tizen::Base::String& filePath, int fileSize, bool isCompleted);
+
+       /**
+        * This is a class constructor for _BT_OPP_CLIENT_EVENT_TRANSFER_PROGRESS event.
+        *
+        * @param[in]   percent         The progress in percentage ranging from @c 1 to @c 100 percent
+        */
+        _BluetoothOppClientEventArg(int percent);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothOppClientEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothOppClientEventType GetEventType(void) const;
+
+       /**
+        * Gets the error result of this event.
+        *
+        * @return      The result of the event
+        */
+       result GetErrorResult(void) const;
+
+       /**
+        * Gets the sent file path.
+        *
+        * @return      The sent file path
+        */
+       Tizen::Base::String GetFilePath(void) const;
+
+       /**
+        * Gets the sent file size.
+        *
+        * @return      The sent file size
+        */
+       int GetFileSize(void) const;
+
+       /**
+        * Is the file transfer completed.
+        *
+        * @return      @c true if the transfer is successfully completed, @n
+        *              else @c false
+        */
+       bool IsTransferCompleted(void) const;
+
+       /**
+        * Gets the progress information as a type of percentage.
+        *
+        * @return      The percentage that represents the progress of file transfer
+        */
+       int GetPercent(void) const;
+
+private:
+       _BluetoothOppClientEventArg(void);
+       _BluetoothOppClientEventArg(const _BluetoothOppClientEventArg& eventArg);
+       _BluetoothOppClientEventArg& operator =(const _BluetoothOppClientEventArg& rValue);
+
+private:
+       _BluetoothOppClientEventType __evtType;
+       result __result;
+       Tizen::Base::String __filePath;
+       int __fileSize;
+       bool __isCompleted;
+       int __percent;
+
+}; // _BluetoothOppClientEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothOppClientImpl.cpp b/src/FNetBt_BluetoothOppClientImpl.cpp
new file mode 100755 (executable)
index 0000000..7ca3029
--- /dev/null
@@ -0,0 +1,583 @@
+//
+// 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    FNetBtBluetoothOppClientImpl.cpp
+// @brief   This is the implementation file for the _BluetoothOppClientImpl class.
+//
+
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothOppClientEventListener.h>
+#include <FBaseSysLog.h>
+#include <FIo_FileImpl.h>
+#include <FApp_AppInfo.h>
+#include "FNetBt_BluetoothOppClientImpl.h"
+#include "FNetBt_BluetoothOppSystemAdapter.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothOppClientEvent.h"
+#include "FNetBt_BluetoothOppClientEventArg.h"
+
+using namespace std;
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothOppClientImpl::_BluetoothOppClientImpl(void)
+       : __pGapAdapter(null)
+       , __pOppAdapter(null)
+       , __pEvent(null)
+       , __stateMutex()
+       , __currentState(_BT_OPP_CLI_STATE_DISABLED)
+       , __pairingAddress()
+       , __pushedFilePath()
+       , __minProgressInterval(__defaultProgressInterval)
+       , __previousProgress(0)
+{
+}
+
+_BluetoothOppClientImpl::~_BluetoothOppClientImpl(void)
+{
+       if (__pOppAdapter != null)
+       {
+               if ((__currentState == _BT_OPP_CLI_STATE_PUSH_READY)
+                       || (__currentState == _BT_OPP_CLI_STATE_ON_TRANSFER))
+               {
+                       (void) CancelPush();
+               }
+       }
+
+       if (__pGapAdapter != null)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+               __pGapAdapter->UnregisterDeviceEventListener(*this);
+       }
+}
+
+result
+_BluetoothOppClientImpl::Construct(IBluetoothOppClientEventListener& listener)
+{
+       result r = E_SUCCESS;
+       std::unique_ptr<_BluetoothOppClientEvent> pEvent;
+
+       r = __stateMutex.Create();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create the state mutex.");
+
+       r = __pairingAddress.Construct(_BT_ADDRESS_LENGTH);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct the address for pairing.");
+
+       __pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturn(NID_NET_BT, __pGapAdapter != null, E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] Failed to invoke _BluetoothGapSystemAdapter::GetInstance().");
+
+       __pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       pEvent.reset(new (std::nothrow) _BluetoothOppClientEvent());
+       SysTryReturn(NID_NET_BT, pEvent != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       r = pEvent->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct the event.");
+       // add the IBluetoothOppClientEventListener instance to a new created _BluetoothOppClientEvent.
+       r = pEvent->AddListener(listener, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                       "[%s] Propagating. Failed to add the application listener for OPP client", GetErrorMessage(r));
+
+       // registers this callback listener to the system adapter for activation/deactivation event
+       r = __pGapAdapter->RegisterManagerEventListener(*this, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                          "[E_SYSTEM] Failed to register the callback listener to _BluetoothGapSystemAdapter.");
+
+       // registers this callback listener to the system adapter for paired event
+       r = __pGapAdapter->RegisterDeviceEventListener(*this);
+       if (r != E_SUCCESS)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+       }
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                          "[E_SYSTEM] Failed to register the callback listener to _BluetoothGapSystemAdapter.");
+
+       // checks whether the Bluetooth is available
+       __stateMutex.Acquire();
+
+       if (__pGapAdapter->IsActivated() == true)
+       {
+               __currentState = _BT_OPP_CLI_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       __pEvent = move(pEvent);
+
+       return E_SUCCESS;
+}
+
+
+result
+_BluetoothOppClientImpl::PushFile(const BluetoothDevice& remoteDevice, const Base::String& filePath)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+       String physicalPath;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_OPP_CLI_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_OPP_CLI_STATE_IDLE:
+               if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+               {
+                       if (Tizen::Io::_FileImpl::ConvertVirtualToPhysicalPath(filePath, physicalPath) != E_SUCCESS)
+                       {
+                               r = E_INACCESSIBLE_PATH;
+                               break;
+                       }
+               }
+               else
+               {
+                       physicalPath = filePath;
+               }
+
+               if (__pGapAdapter->IsPaired(*(remoteDevice.GetAddress())) == true)
+               {
+                       r = __pOppAdapter->PushOppFile(*this, *(remoteDevice.GetAddress()), physicalPath);
+                       if (r == E_SUCCESS)
+                       {
+                               __currentState = _BT_OPP_CLI_STATE_PUSH_READY;
+                       }
+               }
+               else
+               {
+                       // start the pairing process
+                       if (__pGapAdapter->Pair(*(remoteDevice.GetAddress())) == E_SUCCESS)
+                       {
+                               // copy the address of the pairing device to the local variable
+                               __pairingAddress.SetArray(remoteDevice.GetAddress()->GetPointer(), 0, _BT_ADDRESS_LENGTH);
+                               __pairingAddress.SetPosition(0);
+                               // copy the file path to the local variable
+                               __pushedFilePath.Clear();
+                               __pushedFilePath = physicalPath;
+
+                               r = E_SUCCESS;
+                               __currentState = _BT_OPP_CLI_STATE_BONDING;
+                       }
+                       else
+                       {
+                               r = E_FAILURE;
+                       }
+               }
+               break;
+
+       case _BT_OPP_CLI_STATE_BONDING:
+       case _BT_OPP_CLI_STATE_PUSH_READY:
+       case _BT_OPP_CLI_STATE_REQ_CANCELING:   //TODO: this state should return E_INVALID_OPERATION. (Versioning)
+       case _BT_OPP_CLI_STATE_ON_TRANSFER:
+       case _BT_OPP_CLI_STATE_TRANS_CANCELING:   //TODO: this state should return E_INVALID_OPERATION. (Versioning)
+               r = E_IN_PROGRESS;
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on pushing a file.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothOppClientImpl::CancelPush()
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_OPP_CLI_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_OPP_CLI_STATE_IDLE:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_OPP_CLI_STATE_REQ_CANCELING:
+       case _BT_OPP_CLI_STATE_TRANS_CANCELING:
+               r = E_IN_PROGRESS;
+               break;
+
+       case _BT_OPP_CLI_STATE_BONDING: //TODO: Versioning check
+               if (__pGapAdapter->CancelPair() == E_SUCCESS)
+               {
+                       r = E_SUCCESS;
+                       __currentState = _BT_OPP_CLI_STATE_REQ_CANCELING;
+               }
+               // It will be changed to IDLE after receiving the OnBluetoothPaired event.
+               break;
+
+       case _BT_OPP_CLI_STATE_PUSH_READY:
+               r = __pOppAdapter->CancelOppPush();
+
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_OPP_CLI_STATE_REQ_CANCELING;
+               }
+               // It will be changed to IDLE after receiving the OnOppTransferDone event.
+               break;
+
+       case _BT_OPP_CLI_STATE_ON_TRANSFER:
+               r = __pOppAdapter->CancelOppPush();
+
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_OPP_CLI_STATE_TRANS_CANCELING;
+               }
+               // It will be changed to IDLE after receiving the OnOppTransferDone event.
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on canceling the push.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothOppClientImpl::SetMinProgressInterval(int percent)
+{
+       result r = E_SUCCESS;
+
+       if ((percent < 1) || (percent > 100))
+       {
+               r = E_OUT_OF_RANGE;
+               SysLogException(NID_NET_BT, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The input argument - percent - is outside the valid range.");
+       }
+       else
+       {
+               __minProgressInterval = percent;
+       }
+
+       return r;
+}
+
+void
+_BluetoothOppClientImpl::OnBluetoothActivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_OPP_CLI_STATE_DISABLED)
+               && (r == E_SUCCESS))
+       {
+               __currentState = _BT_OPP_CLI_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothOppClientImpl::OnBluetoothDeactivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if (r == E_SUCCESS)
+       {
+               __currentState = _BT_OPP_CLI_STATE_DISABLED;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothOppClientImpl::OnOppPushResponded(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_OPP_CLI_STATE_PUSH_READY) || (__currentState == _BT_OPP_CLI_STATE_REQ_CANCELING))
+       {
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_OPP_CLI_STATE_ON_TRANSFER;
+               }
+               else // including both cases of being canceled by the user and rejected by the remote device
+               {
+                       __currentState = _BT_OPP_CLI_STATE_IDLE;
+                       SysLogException(NID_NET_BT, r, "[%s] exception occurred on the response of the OPP push request.", GetErrorMessage(r));
+               }
+
+               isFired = true;
+       }
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothOppClientEventArg* pArg = new (std::nothrow) _BluetoothOppClientEventArg(r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PUSH_RESPONDED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothOppClientImpl::OnOppTransferInProgress(int percent)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [Progress:%d]", GetStringOfCurrentState(), percent);
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_OPP_CLI_STATE_ON_TRANSFER) || (__currentState == _BT_OPP_CLI_STATE_TRANS_CANCELING))
+       {
+               if (((percent - __previousProgress) >= __minProgressInterval) || (percent >= 100))
+               {
+                       isFired = true;
+                       __previousProgress = percent;
+               }
+       }
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothOppClientEventArg* pArg = new (std::nothrow) _BluetoothOppClientEventArg(percent);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [TRANSFER_IN_PROGRESS_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothOppClientImpl::OnOppTransferDone(const Tizen::Base::String& filePath, int fileSize, bool isCompleted)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [filePath:%ls], [fileSize:%d], [%s]",
+                               GetStringOfCurrentState(), filePath.GetPointer(), fileSize, isCompleted ? "Completed" : "Incompleted");
+
+       bool isFired = false;
+       String pushedFilePath;
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_OPP_CLI_STATE_ON_TRANSFER) || (__currentState == _BT_OPP_CLI_STATE_TRANS_CANCELING))
+       {
+               __currentState = _BT_OPP_CLI_STATE_IDLE;
+               isFired = true;
+               __previousProgress = 0;        // initialization for the next push transaction
+       }
+
+       __stateMutex.Release();
+
+       if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+       {
+               r = Tizen::Io::_FileImpl::ConvertPhysicalToVirtualPath(__pushedFilePath, pushedFilePath);
+               if(r != E_SUCCESS)
+               {
+                       SysLogException(NID_NET_BT, r, "[%s] exception occurred on converting the file path from physical to virtual.", GetErrorMessage(r));
+                       pushedFilePath = __pushedFilePath;
+               }
+       }
+       else
+       {
+               pushedFilePath = __pushedFilePath;
+       }
+
+       if (isFired)
+       {
+               _BluetoothOppClientEventArg* pArg = new (std::nothrow) _BluetoothOppClientEventArg(pushedFilePath, fileSize, isCompleted);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [TRANSFER_DONE_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothOppClientImpl::OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+       result responseResult = E_SYSTEM;
+
+       __stateMutex.Acquire();
+
+       if (pPairedDevice->GetAddress()->Equals(__pairingAddress))
+       {
+               if (__currentState == _BT_OPP_CLI_STATE_BONDING)
+               {
+                       if (r == E_SUCCESS)
+                       {
+                               if (__pOppAdapter->PushOppFile(*this, __pairingAddress, __pushedFilePath) == E_SUCCESS)
+                               {
+                                       __currentState = _BT_OPP_CLI_STATE_PUSH_READY;
+                               }
+                               else
+                               {
+                                       // callback responded with E_SYSTEM
+                                       isFired = true;
+                                       __currentState = _BT_OPP_CLI_STATE_IDLE;
+                                       responseResult = E_SYSTEM;
+                               }
+                       }
+                       else
+                       {
+                               // callback responded with r
+                               isFired = true;
+                               __currentState = _BT_OPP_CLI_STATE_IDLE;
+                               responseResult = r;
+                       }
+
+                       __pairingAddress.Clear();
+               }
+               else if (__currentState == _BT_OPP_CLI_STATE_REQ_CANCELING)
+               {
+                       // callback responded with E_SYSTEM or E_OPERATION_CANCELED
+                       isFired = true;
+                       __currentState = _BT_OPP_CLI_STATE_IDLE;
+                       responseResult = E_SYSTEM;
+               }
+       }
+       // ignored otherwise
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothOppClientEventArg* pArg = new (std::nothrow) _BluetoothOppClientEventArg(responseResult);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PUSH_RESPONDED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+const char*
+_BluetoothOppClientImpl::GetStringOfCurrentState(void) const
+{
+       const char* pStateString = null;
+
+       switch (__currentState)
+       {
+       case _BT_OPP_CLI_STATE_DISABLED:
+               pStateString = "DISABLED";
+               break;
+
+       case _BT_OPP_CLI_STATE_IDLE:
+               pStateString = "IDLE";
+               break;
+
+       case _BT_OPP_CLI_STATE_BONDING:
+               pStateString = "BONDING";
+               break;
+
+       case _BT_OPP_CLI_STATE_PUSH_READY:
+               pStateString = "PUSH_READY";
+               break;
+
+       case _BT_OPP_CLI_STATE_REQ_CANCELING:
+               pStateString = "REQ_CANCELING";
+               break;
+
+       case _BT_OPP_CLI_STATE_ON_TRANSFER:
+               pStateString = "ON_TRANSFER";
+               break;
+
+       case _BT_OPP_CLI_STATE_TRANS_CANCELING:
+               pStateString = "TRANS_CANCELING";
+               break;
+
+       default:
+               pStateString = "Unknown";
+               break;
+       }
+
+       return pStateString;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothOppServerEvent.cpp b/src/FNetBt_BluetoothOppServerEvent.cpp
new file mode 100644 (file)
index 0000000..0d51dac
--- /dev/null
@@ -0,0 +1,87 @@
+//
+// 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    FNetBt_BluetoothOppServerEvent.cpp
+// @brief   This is the implementation file for the _BluetoothOppServerEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
+#include "FNetBt_BluetoothOppServerEvent.h"
+#include "FNetBt_BluetoothOppServerEventArg.h"
+#include "FNetBtIBluetoothOppServerEventListener.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothOppServerEvent::_BluetoothOppServerEvent(void)
+{
+}
+
+_BluetoothOppServerEvent::~_BluetoothOppServerEvent(void)
+{
+}
+
+result
+_BluetoothOppServerEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothOppServerEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       const BluetoothDevice* pDevice = null;
+
+       IBluetoothOppServerEventListener* pListener = dynamic_cast <IBluetoothOppServerEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pListener != null, E_INVALID_ARG, "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothOppServerEventArg* pEventArg = dynamic_cast <const _BluetoothOppServerEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothOppServerEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case _BT_OPP_SERVER_EVENT_PUSH_REQUESTED:
+               pDevice = pEventArg->GetRequester();
+               if (pDevice != null)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth OPP Server Event (Type: _BT_OPP_SERVER_EVENT_PUSH_REQUESTED)");
+                       pListener->OnOppPushRequested(*pDevice);
+               }
+               break;
+
+       case _BT_OPP_SERVER_EVENT_TRANSFER_DONE:
+               SysLog(NID_NET_BT, "Firing Bluetooth OPP Server Event (Type: _BT_OPP_SERVER_EVENT_TRANSFER_DONE)");
+               pListener->OnOppTransferDone(pEventArg->GetFileName(), pEventArg->GetFileSize(), pEventArg->IsTransferCompleted());
+               break;
+
+       case _BT_OPP_SERVER_EVENT_TRANSFER_PROGRESS:
+               SysLog(NID_NET_BT, "Firing Bluetooth OPP Server Event (Type: _BT_OPP_SERVER_EVENT_TRANSFER_PROGRESS)");
+               pListener->OnOppTransferInProgress(pEventArg->GetPercent());
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothOppServerEvent.h b/src/FNetBt_BluetoothOppServerEvent.h
new file mode 100644 (file)
index 0000000..df6cd3b
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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    FNetBt_BluetoothOppServerEvent.h
+ * @brief   This is the header file for the _BluetoothOppServerEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothOppServerEvent class.
+ * The _BluetoothOppServerEvent class can call a method of a listener (_IBluetoothOppServerEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+// Forward declaration
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// @class   _BluetoothOppServerEvent
+// @brief   This class handles Bluetooth OPP Server events.
+//
+// When a Bluetooth device event occurs, the _BluetoothOppServerEvent object finds a _IBluetoothOppServerEventListener object
+// and calls an appropriate method of the listener.
+//
+class _BluetoothOppServerEvent
+       : public Tizen::Base::Runtime::_Event
+{
+public:
+       _BluetoothOppServerEvent(void);
+       virtual ~_BluetoothOppServerEvent(void);
+
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate pListener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth SPP Acceptor event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothOppServerEvent(const _BluetoothOppServerEvent& value);
+       _BluetoothOppServerEvent& operator =(const _BluetoothOppServerEvent& rhs);
+
+}; // _BluetoothOppServerEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_EVENT_H_
diff --git a/src/FNetBt_BluetoothOppServerEventArg.cpp b/src/FNetBt_BluetoothOppServerEventArg.cpp
new file mode 100755 (executable)
index 0000000..577184c
--- /dev/null
@@ -0,0 +1,113 @@
+//
+// 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    FNetBt_BluetoothOppServerEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothOppServerEventArg class.
+//
+
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothOppServerEventArg.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// This is a class constructor for _BT_OPP_SERVER_EVENT_PUSH_REQUESTED event.
+//
+_BluetoothOppServerEventArg::_BluetoothOppServerEventArg(const BluetoothDevice& device)
+       : __evtType(_BT_OPP_SERVER_EVENT_PUSH_REQUESTED)
+       , __pRequester(null)
+       , __fileName()
+       , __fileSize(0)
+       , __isCompleted(true)
+       , __percent(0)
+{
+       __pRequester = new (std::nothrow) BluetoothDevice(device);
+       SysTryReturnVoidResult(NID_NET_BT, __pRequester != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+}
+
+//
+// This is a class constructor for _BT_OPP_SERVER_EVENT_TRANSFER_DONE event.
+//
+_BluetoothOppServerEventArg::_BluetoothOppServerEventArg(const Tizen::Base::String& fileName, int fileSize, bool isCompleted)
+       : __evtType(_BT_OPP_SERVER_EVENT_TRANSFER_DONE)
+       , __pRequester(null)
+       , __fileName(fileName)
+       , __fileSize(fileSize)
+       , __isCompleted(isCompleted)
+       , __percent(0)
+{
+}
+
+//
+// This is a class constructor for _BT_OPP_SERVER_EVENT_TRANSFER_PROGRESS event.
+//
+_BluetoothOppServerEventArg::_BluetoothOppServerEventArg(int percent)
+       : __evtType(_BT_OPP_SERVER_EVENT_TRANSFER_PROGRESS)
+       , __pRequester(null)
+       , __fileName()
+       , __fileSize(0)
+       , __isCompleted(true)
+       , __percent(percent)
+{
+}
+
+_BluetoothOppServerEventArg::~_BluetoothOppServerEventArg(void)
+{
+       delete __pRequester;
+}
+
+_BluetoothOppServerEventType
+_BluetoothOppServerEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
+
+const BluetoothDevice*
+_BluetoothOppServerEventArg::GetRequester(void) const
+{
+       return __pRequester;
+}
+
+Tizen::Base::String
+_BluetoothOppServerEventArg::GetFileName(void) const
+{
+       return __fileName;
+}
+
+int
+_BluetoothOppServerEventArg::GetFileSize(void) const
+{
+       return __fileSize;
+}
+
+bool
+_BluetoothOppServerEventArg::IsTransferCompleted(void) const
+{
+       return __isCompleted;
+}
+
+int
+_BluetoothOppServerEventArg::GetPercent(void) const
+{
+       return __percent;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothOppServerEventArg.h b/src/FNetBt_BluetoothOppServerEventArg.h
new file mode 100644 (file)
index 0000000..4160b4f
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// 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    FNetBt_BluetoothOppServerEventArg.h
+ * @brief   This is the header file for the _BluetoothOppServerEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothOppServerEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseString.h>
+#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declaration
+class BluetoothDevice;
+
+/**
+  * @enum    _BluetoothOppServerEventType
+  * Type for specifying the type of _BluetoothOppServerEvent
+  */
+enum _BluetoothOppServerEventType
+{
+       _BT_OPP_SERVER_EVENT_PUSH_REQUESTED,      /**< For notifying an incoming push request is received from a remote OPP client */
+       _BT_OPP_SERVER_EVENT_TRANSFER_PROGRESS,   /**< For notifying the file transfer has finished */
+       _BT_OPP_SERVER_EVENT_TRANSFER_DONE        /**< For notifying the file is being transferred */
+};
+
+/**
+ * @class   _BluetoothOppServerEventArg
+ * @brief   This class is used as an argument for callback methods of the IBluetoothOppServerEventListener class.
+ *
+ * When a _BluetoothOppServerEvent occurs, the _BluetoothOppServerEvent finds a IBluetoothOppServerEventListener instance
+ * which is registered for the _BluetoothOppServerEvent and calls an appropriate method of the listener.
+ * @see     IBluetoothOppServerEventListener
+ */
+class _BluetoothOppServerEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor for _BT_OPP_SERVER_EVENT_PUSH_REQUESTED event.
+        *
+        * @param[in]   device               The OPP client device that requests the connection
+        */
+       _BluetoothOppServerEventArg(const BluetoothDevice& device);
+
+       /**
+        * This is a class constructor for _BT_OPP_SERVER_EVENT_TRANSFER_DONE event.
+        *
+        * @param[in]       fileName        The name of the transferred file
+        * @param[in]       fileSize        The size of the transferred file
+        * @param[in]       isCompleted     Set to @c true if the transfer is successfully completed, @n
+        *                                  else @c false
+        */
+       _BluetoothOppServerEventArg(const Tizen::Base::String& fileName, int fileSize, bool isCompleted);
+
+       /**
+        * This is a class constructor for _BT_OPP_SERVER_EVENT_TRANSFER_PROGRESS event.
+        *
+        * @param[in]   percent         The progress in percentage ranging from @c 1 to @c 100 percent
+        */
+       _BluetoothOppServerEventArg(int percent);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothOppServerEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothOppServerEventType GetEventType(void) const;
+
+       /**
+        * Gets the OPP client device.
+        *
+        * @return      The pointer of the OPP client device which request to connect
+        */
+       const BluetoothDevice* GetRequester(void) const;
+
+       /**
+        * Gets the received file name.
+        *
+        * @return      The received file name
+        */
+       Tizen::Base::String GetFileName(void) const;
+
+       /**
+        * Gets the received file size.
+        *
+        * @return      The received file size
+        */
+       int GetFileSize(void) const;
+
+       /**
+        * Is the file transfer completed.
+        *
+        * @return      @c true if the transfer is successfully completed, @n
+        *              else @c false
+        */
+       bool IsTransferCompleted(void) const;
+
+       /**
+        * Gets the progress information as a type of percentage.
+        *
+        * @return      The percentage that represents the progress of file transfer
+        */
+       int GetPercent(void) const;
+
+private:
+       _BluetoothOppServerEventArg(void);
+       _BluetoothOppServerEventArg(const _BluetoothOppServerEventArg& eventArg);
+       _BluetoothOppServerEventArg& operator =(const _BluetoothOppServerEventArg& rValue);
+
+private:
+       _BluetoothOppServerEventType __evtType;
+       BluetoothDevice* __pRequester;
+       Tizen::Base::String __fileName;
+       int __fileSize;
+       bool __isCompleted;
+       int __percent;
+
+}; // _BluetoothOppServerEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothOppServerImpl.cpp b/src/FNetBt_BluetoothOppServerImpl.cpp
new file mode 100755 (executable)
index 0000000..814c0ac
--- /dev/null
@@ -0,0 +1,663 @@
+//
+// 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    FNetBt_BluetoothOppServerImpl.cpp
+// @brief   This is the implementation file for the _BluetoothOppServerImpl class.
+//
+
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothOppServerEventListener.h>
+#include <FBaseSysLog.h>
+#include <FIo_FileImpl.h>
+#include <FApp_AppInfo.h>
+#include "FNetBt_BluetoothOppServerImpl.h"
+#include "FNetBt_BluetoothOppSystemAdapter.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothOppServerEvent.h"
+#include "FNetBt_BluetoothOppServerEventArg.h"
+
+using namespace std;
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothOppServerImpl::_BluetoothOppServerImpl(void)
+       : __pGapAdapter(null)
+       , __pOppAdapter(null)
+       , __pEvent(null)
+       , __stateMutex()
+       , __currentState(_BT_OPP_SVR_STATE_DISABLED)
+       , __pushedFileName()
+       , __minProgressInterval(__defaultProgressInterval)
+       , __previousProgress(0)
+{
+}
+
+_BluetoothOppServerImpl::~_BluetoothOppServerImpl(void)
+{
+       if (__pOppAdapter != null)
+       {
+               if ((__currentState == _BT_OPP_SVR_STATE_ON_SERVICE)
+                       || (__currentState == _BT_OPP_SVR_STATE_PUSH_REQUESTED)
+                       || (__currentState == _BT_OPP_SVR_STATE_ON_TRANSFER))
+               {
+                       (void) StopService(); // Ignores the result of this function.
+               }
+               __pOppAdapter = null;
+       }
+
+       if (__pGapAdapter != null)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+               __pGapAdapter = null;
+       }
+}
+
+result
+_BluetoothOppServerImpl::Construct(IBluetoothOppServerEventListener& listener)
+{
+       result r = E_SUCCESS;
+       unique_ptr<_BluetoothOppServerEvent> pEvent;
+
+       r = __stateMutex.Create();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create the state mutex.");
+
+       __pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturn(NID_NET_BT, __pGapAdapter != null, E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] Failed to invoke _BluetoothSysteAdapter::GetInstance().");
+
+       __pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       pEvent.reset(new (std::nothrow) _BluetoothOppServerEvent());
+       SysTryReturn(NID_NET_BT, pEvent != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       r = pEvent->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct the event.");
+       // add the IBluetoothOppServerEventListener instance to a new created _BluetoothOppServerEvent.
+       r = pEvent->AddListener(listener, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                               "[%s] Propagating. Failed to add the application listener for OPP Server", GetErrorMessage(r));
+
+       // registers this callback listener to the system adapter for activation/deactivation event
+       r = __pGapAdapter->RegisterManagerEventListener(*this, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                          "[E_SYSTEM] Failed to register the callback listener to _BluetoothSystemAdapter.");
+
+       // check whether the Bluetooth is available
+       __stateMutex.Acquire();
+
+       if (__pGapAdapter->IsActivated() == true)
+       {
+               __currentState = _BT_OPP_SVR_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       __pEvent = move(pEvent);
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothOppServerImpl::AcceptPush(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_OPP_SVR_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_OPP_SVR_STATE_IDLE:
+       case _BT_OPP_SVR_STATE_ON_SERVICE:
+       case _BT_OPP_SVR_STATE_ON_TRANSFER:
+       case _BT_OPP_SVR_STATE_ON_STOPPING:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_OPP_SVR_STATE_PUSH_REQUESTED:
+               r = __pOppAdapter->AcceptOppPush(__pushedFileName);
+
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_OPP_SVR_STATE_ON_TRANSFER;
+               }
+               else
+               {
+                       __currentState = _BT_OPP_SVR_STATE_ON_SERVICE;
+               }
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on accepting a push request.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothOppServerImpl::RejectPush(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_OPP_SVR_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_OPP_SVR_STATE_IDLE:
+       case _BT_OPP_SVR_STATE_ON_SERVICE:
+       case _BT_OPP_SVR_STATE_ON_TRANSFER:
+       case _BT_OPP_SVR_STATE_ON_STOPPING:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_OPP_SVR_STATE_PUSH_REQUESTED:
+               r = __pOppAdapter->RejectOppPush();
+
+               // change the state into ON_SERVICE regardless of the result
+               __currentState = _BT_OPP_SVR_STATE_ON_SERVICE;
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on rejecting a push request.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothOppServerImpl::SetDestinationPath(const Tizen::Base::String& dstPath)
+{
+       result r = E_INVALID_OPERATION;
+       String physicalPath;
+
+       if ((__currentState != _BT_OPP_SVR_STATE_ON_TRANSFER) &&
+               (__currentState != _BT_OPP_SVR_STATE_ON_STOPPING))
+       {
+               if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+               {
+                       if (Tizen::Io::_FileImpl::ConvertVirtualToPhysicalPath(dstPath, physicalPath) != E_SUCCESS)
+                       {
+                               r = E_INACCESSIBLE_PATH;
+                       }
+                       else
+                       {
+                               r = __pOppAdapter->SetOppReceivePath(physicalPath);
+                       }
+               }
+               else
+               {
+                       r = __pOppAdapter->SetOppReceivePath(dstPath);
+               }
+       }
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on setting the destination path.", GetErrorMessage(r));
+       }
+
+       return r;
+}
+
+result
+_BluetoothOppServerImpl::SetMinProgressInterval(int percent)
+{
+       result r = E_SUCCESS;
+
+       if ((percent < 1) || (percent > 100))
+       {
+               r = E_OUT_OF_RANGE;
+               SysLogException(NID_NET_BT, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The input argument - percent - is outside the valid range.");
+       }
+       else
+       {
+               __minProgressInterval = percent;
+       }
+
+       return r;
+}
+
+result
+_BluetoothOppServerImpl::StartService(const Tizen::Base::String& dstPath)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+       String physicalPath;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_OPP_SVR_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_OPP_SVR_STATE_IDLE:
+               if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+               {
+                       if (Tizen::Io::_FileImpl::ConvertVirtualToPhysicalPath(dstPath, physicalPath) != E_SUCCESS)
+                       {
+                               r = E_INACCESSIBLE_PATH;
+                               break;
+                       }
+               }
+               else
+               {
+                       physicalPath = dstPath;
+               }
+
+               r = __pOppAdapter->StartOppServer(*this, physicalPath);
+
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_OPP_SVR_STATE_ON_SERVICE;
+               }
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_SERVICE:
+       case _BT_OPP_SVR_STATE_PUSH_REQUESTED:
+       case _BT_OPP_SVR_STATE_ON_TRANSFER:
+               r = E_IN_PROGRESS;
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_STOPPING:
+               r = E_INVALID_OPERATION;
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on starting OPP service.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothOppServerImpl::StopService(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_OPP_SVR_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_OPP_SVR_STATE_IDLE:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_SERVICE:
+       case _BT_OPP_SVR_STATE_ON_STOPPING:
+               r = __pOppAdapter->StopOppServer();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_OPP_SVR_STATE_IDLE;
+               }
+               break;
+
+       case _BT_OPP_SVR_STATE_PUSH_REQUESTED:
+               r = __pOppAdapter->RejectOppPush();
+               if (r == E_SUCCESS)
+               {
+                       r = __pOppAdapter->StopOppServer();
+                       if (r == E_SUCCESS)
+                       {
+                               __currentState = _BT_OPP_SVR_STATE_IDLE;
+                       }
+                       else
+                       {
+                               __currentState = _BT_OPP_SVR_STATE_ON_SERVICE;
+                       }
+               }
+               // Stays in the current status, if the rejection fails
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_TRANSFER:
+               r = __pOppAdapter->StopOppTransfer();
+               r = TransExceptionsInclusive(r ,E_FAILURE, E_OPERATION_FAILED);
+               if (r == E_SUCCESS)
+               {
+                       r = __pOppAdapter->StopOppServer();
+                       if (r == E_SUCCESS)
+                       {
+                               __currentState = _BT_OPP_SVR_STATE_IDLE;
+                       }
+                       else
+                       {
+                               __currentState = _BT_OPP_SVR_STATE_ON_SERVICE;
+                       }
+               }
+               // Stays in the current status, if the terminating file transfer fails
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on stopping OPP service.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothOppServerImpl::StopTransfer(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_OPERATION_FAILED;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_OPP_SVR_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_OPP_SVR_STATE_IDLE:
+       case _BT_OPP_SVR_STATE_ON_SERVICE:
+       case _BT_OPP_SVR_STATE_PUSH_REQUESTED:
+       case _BT_OPP_SVR_STATE_ON_STOPPING:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_TRANSFER:
+               r = __pOppAdapter->StopOppTransfer();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_OPP_SVR_STATE_ON_STOPPING;
+               }
+               // It will be changed to IDLE after receiving the TransferDone event.
+               break;
+
+       default:
+               // ignore other cases
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on stopping OPP service.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+void
+_BluetoothOppServerImpl::OnBluetoothActivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_OPP_SVR_STATE_DISABLED) && (r == E_SUCCESS))
+       {
+               __currentState = _BT_OPP_SVR_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothOppServerImpl::OnBluetoothDeactivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if (r == E_SUCCESS)
+       {
+               __currentState = _BT_OPP_SVR_STATE_DISABLED;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothOppServerImpl::OnOppPushRequested(const BluetoothDevice& device)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if (__currentState == _BT_OPP_SVR_STATE_ON_SERVICE)
+       {
+               __currentState = _BT_OPP_SVR_STATE_PUSH_REQUESTED;
+               isFired = true;
+       }
+       else if ((__currentState == _BT_OPP_SVR_STATE_PUSH_REQUESTED)
+                        || (__currentState == _BT_OPP_SVR_STATE_ON_TRANSFER)
+                        || (__currentState == _BT_OPP_SVR_STATE_ON_STOPPING))
+       {
+               (void) __pOppAdapter->RejectOppPush(); // ignore the result
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothOppServerEventArg* pArg = new (std::nothrow) _BluetoothOppServerEventArg(device);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [PUSH_REQUESTED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothOppServerImpl::OnOppTransferInProgress(int percent)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [Progress:%d]", GetStringOfCurrentState(), percent);
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_OPP_SVR_STATE_ON_TRANSFER) || (__currentState == _BT_OPP_SVR_STATE_ON_STOPPING))
+       {
+               if (((percent - __previousProgress) >= __minProgressInterval) || (percent >= 100))
+               {
+                       isFired = true;
+                       __previousProgress = percent;
+               }
+       }
+       // ignore other scases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothOppServerEventArg* pArg = new (std::nothrow) _BluetoothOppServerEventArg(percent);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [TRANSFER_IN_PROGRESS_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothOppServerImpl::OnOppTransferDone(const Tizen::Base::String& filePath, int fileSize, bool isCompleted)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [TransferDone:%s]",
+                               GetStringOfCurrentState(), isCompleted ? "Completed" : "NotCompleted");
+
+       result r = E_SUCCESS;
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if (__currentState == _BT_OPP_SVR_STATE_IDLE)
+       {
+               isFired = true;
+               __previousProgress = 0;        // initialization for the next push transaction
+       }
+       else if ((__currentState == _BT_OPP_SVR_STATE_ON_TRANSFER) || (__currentState == _BT_OPP_SVR_STATE_ON_STOPPING))
+       {
+               __currentState = _BT_OPP_SVR_STATE_ON_SERVICE;
+               isFired = true;
+               __previousProgress = 0;        // initialization for the next push transaction
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothOppServerEventArg* pArg = new (std::nothrow) _BluetoothOppServerEventArg(filePath, fileSize, isCompleted);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       if ((isFired) && (r != E_SUCCESS))
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on stopping OPP service in the transfer-done callback.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s], [TRANSFER_DONE_Event:%s]",
+                               GetStringOfCurrentState(), GetErrorMessage(r), isFired ? "Fired" : "NotFired");
+}
+
+const char*
+_BluetoothOppServerImpl::GetStringOfCurrentState(void) const
+{
+       const char* pStateString = null;
+
+       switch (__currentState)
+       {
+       case _BT_OPP_SVR_STATE_DISABLED:
+               pStateString = "DISABLED";
+               break;
+
+       case _BT_OPP_SVR_STATE_IDLE:
+               pStateString = "IDLE";
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_SERVICE:
+               pStateString = "ON_SERVICE";
+               break;
+
+       case _BT_OPP_SVR_STATE_PUSH_REQUESTED:
+               pStateString = "PUSH_REQUESTED";
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_TRANSFER:
+               pStateString = "ON_TRANSFER";
+               break;
+
+       case _BT_OPP_SVR_STATE_ON_STOPPING:
+               pStateString = "ON_STOPPING";
+               break;
+
+       default:
+               pStateString = "Unknown";
+               break;
+       }
+
+       return pStateString;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothOppSystemAdapter.cpp b/src/FNetBt_BluetoothOppSystemAdapter.cpp
new file mode 100755 (executable)
index 0000000..e3d126d
--- /dev/null
@@ -0,0 +1,380 @@
+//
+// 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        FNetBt_BluetoothOppSystemAdapter.cpp
+// @brief       This is the implementation file for the _BluetoothOppSystemAdapter class.
+//
+
+#include <unique_ptr.h>
+#include <pthread.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseUtilStringUtil.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include "FNetBt_BluetoothOppSystemAdapter.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothDeviceImpl.h"
+#include "FNetBt_BluetoothOppClientImpl.h"
+#include "FNetBt_BluetoothOppServerImpl.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothOppSystemAdapter* _BluetoothOppSystemAdapter::__pInstance = null;
+
+_BluetoothOppSystemAdapter::_BluetoothOppSystemAdapter(void)
+       : __pOppServerImpl(null)
+       , __pOppClientImpl(null)
+       , __serverTransferId(0)
+       , __serverRecvFileName()
+       , __serverRecvFileSize(0)
+{
+}
+
+_BluetoothOppSystemAdapter::~_BluetoothOppSystemAdapter(void)
+{
+}
+
+void
+_BluetoothOppSystemAdapter::InitSingleton(void)
+{
+       static _BluetoothOppSystemAdapter inst = _BluetoothOppSystemAdapter();
+
+       __pInstance = &inst;
+}
+
+_BluetoothOppSystemAdapter*
+_BluetoothOppSystemAdapter::GetInstance(void)
+{
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (__pInstance == null)
+       {
+               ClearLastResult();
+               pthread_once(&onceBlock, InitSingleton);
+               result r = GetLastResult();
+               if (IsFailed(r))
+               {
+                       onceBlock = PTHREAD_ONCE_INIT;
+               }
+       }
+
+       return __pInstance;
+}
+
+result
+_BluetoothOppSystemAdapter::StartOppServer(const _BluetoothOppServerImpl& impl, const Tizen::Base::String& dstPath)
+{
+       unique_ptr<char[]> pUuidStr;
+       bool isUsed = false;
+       unique_ptr<char[]> pConvertedDestPath;
+       result r = E_SUCCESS;
+       int ret = BT_ERROR_NONE;
+
+       // check OPP server's availability
+       pUuidStr.reset(_StringConverter::CopyToCharArrayN(UuId(BT_SVC_UUID_OPP).ToString()));
+       ret = bt_adapter_is_service_used(pUuidStr.get() , &isUsed);
+       SysTryReturnResult(NID_NET_BT, (ret == BT_ERROR_NONE) && !isUsed, E_SERVICE_UNAVAILABLE, "OPP Server is not available. [0x%08X]", ret);
+
+       pConvertedDestPath.reset(_StringConverter::CopyToCharArrayN(dstPath));
+       SysTryReturnResult(NID_NET_BT, pConvertedDestPath != null, E_INACCESSIBLE_PATH, "The file path is invalid.");
+
+       ret = bt_opp_server_initialize_by_connection_request(pConvertedDestPath.get(), &OnOppServerConnectionRequested, null);
+       SysLog(NID_NET_BT, "Starting the OPP Server %s. [0x%-04X]", ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               __pOppServerImpl = const_cast <_BluetoothOppServerImpl*>(&impl);
+       }
+       else
+       {
+               r = E_FAILURE;
+       }
+
+       return r;
+}
+
+result
+_BluetoothOppSystemAdapter::StopOppServer(void)
+{
+       int ret = BT_ERROR_NONE;
+
+       ret = bt_opp_server_deinitialize();
+       SysLog(NID_NET_BT, "Stop the OPP Server %s. [0x%08X]", ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               __pOppServerImpl = null;
+               return E_SUCCESS;
+       }
+
+       return E_FAILURE;
+}
+
+result
+_BluetoothOppSystemAdapter::SetOppReceivePath(const Tizen::Base::String& dstPath)
+{
+       char* pConvertedDestPath = NULL;
+       result r = E_FAILURE;
+       int ret = BT_ERROR_NONE;
+
+       pConvertedDestPath = _StringConverter::CopyToCharArrayN(dstPath);
+       SysTryReturnResult(NID_NET_BT, pConvertedDestPath != null, E_INACCESSIBLE_PATH, "The file path is invalid.");
+
+       ret = bt_opp_server_set_destination(pConvertedDestPath);
+       SysLog(NID_NET_BT, "Setting the receive path of the OPP Server %s. [0x%08X]",
+                       ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       delete[] pConvertedDestPath;
+       return r;
+}
+
+result
+_BluetoothOppSystemAdapter::AcceptOppPush(const Tizen::Base::String& fileName)
+{
+       result r = E_FAILURE;
+       int ret = BT_ERROR_NONE;
+
+       char* pConvertedfileName = _StringConverter::CopyToCharArrayN(fileName);
+       SysTryReturnResult(NID_NET_BT, pConvertedfileName != null, E_FAILURE, "The file name is invalid.");
+
+       ret = bt_opp_server_accept(&OnOppServerTransferInProgress, &OnOppServerTransferCompleted, pConvertedfileName, null,
+                       &__serverTransferId);
+       SysLog(NID_NET_BT, "Accepting the OPP push request %s. [0x%08X]", ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       delete[] pConvertedfileName;
+       return r;
+}
+
+result
+_BluetoothOppSystemAdapter::RejectOppPush(void)
+{
+       int ret = BT_ERROR_NONE;
+
+       ret = bt_opp_server_reject();
+       SysLog(NID_NET_BT, "Rejecting the OPP push request %s. [0x%08X]", ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               return E_SUCCESS;
+       }
+
+       return E_FAILURE;
+}
+
+result
+_BluetoothOppSystemAdapter::StopOppTransfer(void)
+{
+       int ret = BT_ERROR_NONE;
+
+       // if a file transfer is not started yet, the default transfer ID (0) is used for terminating the OPP server.
+       ret = bt_opp_server_cancel_transfer(__serverTransferId);
+       SysLog(NID_NET_BT, "Stop the OPP file transfer (ID:%d) %s. [0x%08X]", __serverTransferId,
+                       ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               return E_SUCCESS;
+       }
+
+       return E_OPERATION_FAILED;
+}
+
+result
+_BluetoothOppSystemAdapter::PushOppFile(const _BluetoothOppClientImpl& impl, const Tizen::Base::ByteBuffer& serverAddress,
+               const Tizen::Base::String& filePath)
+{
+       result r = E_FAILURE;
+       int ret = BT_ERROR_NONE;
+       unique_ptr<char[]> pServerDevAddr;
+       unique_ptr<char[]> pFileName;
+
+       SysTryReturnResult(NID_NET_BT, __pOppClientImpl == null, E_SERVICE_UNAVAILABLE, "The already OPP client is running.");
+       SysTryReturnResult(NID_NET_BT, serverAddress.GetRemaining() == _BT_ADDRESS_LENGTH, E_FAILURE,
+                                               "The address of the remote device is incorrect.");
+
+       pFileName.reset(_StringConverter::CopyToCharArrayN(filePath));
+       SysTryReturnResult(NID_NET_BT, pFileName != null, E_INACCESSIBLE_PATH, "The file path is invalid.");
+       pServerDevAddr.reset(_StringConverter::CopyToCharArrayN(_BluetoothDeviceImpl::GetAddressString(serverAddress)));
+       SysTryReturnResult(NID_NET_BT, pServerDevAddr != null, E_FAILURE, "The server address is invalid.");
+
+       if (bt_opp_client_initialize() == BT_ERROR_NONE)
+       {
+               (void) bt_opp_client_add_file(pFileName.get());
+               ret = bt_opp_client_push_files(pServerDevAddr.get(), &OnOppClientConnectionResponded, &OnOppClientTransferInProgress,
+                               &OnOppClientTransferCompleted, null);
+               SysLog(NID_NET_BT, "Sending a push request to  device [%s] %s. [0x%08X]", pServerDevAddr.get(),
+                               ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+               if (ret == BT_ERROR_NONE)
+               {
+                       __pOppClientImpl = const_cast<_BluetoothOppClientImpl*>(&impl);
+                       r = E_SUCCESS;
+               }
+               else
+               {
+                       bt_opp_client_deinitialize();
+               }
+       }
+
+       return r;
+}
+
+result
+_BluetoothOppSystemAdapter::CancelOppPush(void)
+{
+       int ret = BT_ERROR_NONE;
+
+       ret = bt_opp_client_cancel_push();
+       SysLog(NID_NET_BT, "Cancel the OPP file transfer %s. [0x%08X]", ret == BT_ERROR_NONE ? "is successful" : "fails", ret);
+
+       if (ret == BT_ERROR_NONE)
+       {
+               return E_SUCCESS;
+       }
+
+       return E_FAILURE;
+}
+
+void
+_BluetoothOppSystemAdapter::OnOppClientConnectionResponded(int status, const char* pRemoteAddress, void* pUserData)
+{
+       _BluetoothOppSystemAdapter* pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       if (pOppAdapter->__pOppClientImpl)
+       {
+               if (status == BT_ERROR_NONE)
+               {
+                       pOppAdapter->__pOppClientImpl->OnOppPushResponded(E_SUCCESS);
+               }
+               else
+               {
+                       pOppAdapter->__pOppClientImpl->OnOppPushResponded(E_SYSTEM);
+                       pOppAdapter->__pOppClientImpl = null;
+                       bt_opp_client_deinitialize();
+               }
+       }
+}
+
+void
+_BluetoothOppSystemAdapter::OnOppClientTransferInProgress(const char* pFilePath, long long fileSize, int progress, void* pUserData)
+{
+       _BluetoothOppSystemAdapter* pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       pOppAdapter->__serverRecvFileSize = fileSize;
+       // converts the UTF8 multibyte string to Unicode String
+       (void) StringUtil::Utf8ToString(pFilePath, pOppAdapter->__serverRecvFileName);
+
+       if (pOppAdapter->__pOppClientImpl)
+       {
+               pOppAdapter->__pOppClientImpl->OnOppTransferInProgress(progress);
+       }
+}
+
+void
+_BluetoothOppSystemAdapter::OnOppClientTransferCompleted(int status, const char* pRemoteAddress, void* pUserData)
+{
+       bool isCompleted = true;
+       _BluetoothOppSystemAdapter* pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       if (pOppAdapter->__pOppClientImpl)
+       {
+               if (status != BT_ERROR_NONE)
+               {
+                       isCompleted = false;
+               }
+
+               pOppAdapter->__pOppClientImpl->OnOppTransferDone(pOppAdapter->__serverRecvFileName, pOppAdapter->__serverRecvFileSize,
+                               isCompleted);
+               pOppAdapter->__pOppClientImpl = null;
+               // TODO: Is it right that the following statement is located in the next of callback?
+               bt_opp_client_deinitialize();
+       }
+}
+
+void
+_BluetoothOppSystemAdapter::OnOppServerConnectionRequested(const char* pRemoteAddress, void* pUserData)
+{
+       result r = E_SUCCESS;
+       BluetoothDevice requester;
+       ByteBuffer deviceAddress;
+       String deviceAddressStr(pRemoteAddress);
+       _BluetoothOppSystemAdapter* pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       if (pOppAdapter->__pOppServerImpl)
+       {
+               deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+               (void) _BluetoothDeviceImpl::GetAddressByteBuffer(deviceAddressStr, L":", deviceAddress);
+
+               r = _BluetoothGapSystemAdapter::GetPairedDevice(deviceAddress, requester);
+               SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Getting information of the request has failed.");
+
+               pOppAdapter->__pOppServerImpl->OnOppPushRequested(requester);
+       }
+}
+
+void
+_BluetoothOppSystemAdapter::OnOppServerTransferInProgress(const char* pFilePath, long long fileSize, int progress, void* pUserData)
+{
+       _BluetoothOppSystemAdapter* pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       if (pOppAdapter->__pOppServerImpl)
+       {
+               pOppAdapter->__pOppServerImpl->OnOppTransferInProgress(progress);
+       }
+}
+
+void
+_BluetoothOppSystemAdapter::OnOppServerTransferCompleted(int status, const char* pFilePath, long long fileSize, void* pUserData)
+{
+       bool isCompleted = true;
+       String convertedFilePath;
+
+       _BluetoothOppSystemAdapter* pOppAdapter = _BluetoothOppSystemAdapter::GetInstance();
+
+       if (pOppAdapter->__pOppServerImpl)
+       {
+               pOppAdapter->__serverTransferId = 0;
+
+               if (status != BT_ERROR_NONE)
+               {
+                       isCompleted = false;
+               }
+               // TODO: not file name but file path
+               // converts the UTF8 multibyte string to Unicode String
+               (void) StringUtil::Utf8ToString(pFilePath, convertedFilePath);
+               pOppAdapter->__pOppServerImpl->OnOppTransferDone(convertedFilePath, fileSize, isCompleted);
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothOppSystemAdapter.h b/src/FNetBt_BluetoothOppSystemAdapter.h
new file mode 100644 (file)
index 0000000..05ca2d3
--- /dev/null
@@ -0,0 +1,209 @@
+//
+// 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    FNetBt_BluetoothOppSystemAdapter.h
+ * @brief   This is the header file for the _BluetoothOppSystemAdapter class.
+ *
+ * This header file contains the declaration of the _BluetoothOppSystemAdapter class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_OPP_SYSTEM_ADAPTER_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_OPP_SYSTEM_ADAPTER_H_
+
+#include <bluetooth.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseString.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Base {
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class _BluetoothOppClientImpl;
+class _BluetoothOppServerImpl;
+
+/**
+ * @class   _BluetoothOppSystemAdapter
+ * @brief   This class provides functions related to deliver the system events to the listeners such as
+ *          _BluetoothManagerImpl. This class is a type of singleton, therefore only one instance should be allowed.
+ */
+class _BluetoothOppSystemAdapter
+       : 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 _BluetoothOppSystemAdapter* GetInstance(void);
+
+       //-----------------------------------------------------------------------------------------------------------------
+       // OPP Server
+       //-----------------------------------------------------------------------------------------------------------------
+
+       /**
+        * Start the OPP server and register an instance of _BluetoothOppServerImpl class into the internal.
+        * Currently, the only one instance can be registered.
+        *
+        * @return      An error code
+        * @param[in]   impl                    The instance of _BluetoothOppServerImpl to be registered
+        * @param[in]   dstPath                 The new destination file path
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SERVICE_UNAVAILABLE   OPP Server service is not available because the number of registered instances
+        *                                      are exceeded to the max number.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result StartOppServer(const _BluetoothOppServerImpl& impl, const Tizen::Base::String& dstPath);
+
+       /**
+        * Stop the running OPP server and unset the registered instance of _BluetoothOppServerImpl class.
+        *
+        * @return      An error code
+        * @param[in]   impl                    The instance of _BluetoothOppServerImpl to be unregistered
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result StopOppServer(void);
+
+       /**
+        * Sets the destination path of the file to be received.
+        *
+        * @return       An error code
+        * @param[in]    dstPath                The new destination file path
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_INACCESSIBLE_PATH    The specified @c path contains an invalid value.
+        * @exception    E_FAILURE              The method failed.
+        */
+       result SetOppReceivePath(const Tizen::Base::String& dstPath);
+
+       /**
+        * Accepts an OPP Push request from a remote device.
+        *
+        * @return       An error code
+        * @param[in]    fileName               The name of the file to be saved which is received from the request device.
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_FAILURE              The method failed.
+        */
+       result AcceptOppPush(const Tizen::Base::String& fileName);
+
+       /**
+        * Rejects an OPP Push request from a remote device.
+        *
+        * @return       An error code
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_FAILURE              The method failed.
+        */
+       result RejectOppPush(void);
+
+       /**
+        * Disconnects OPP connection and stops the file transfer in progress at the server side.
+        *
+        * @return       An error code
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_FAILURE              The method failed.
+        */
+       result StopOppTransfer(void);
+
+       //-----------------------------------------------------------------------------------------------------------------
+       // OPP Client
+       //-----------------------------------------------------------------------------------------------------------------
+
+       /**
+        * Request a push request after creating an OPP client.
+        *
+        * @return      An error code
+        * @param[in]   impl                    The instance of _BluetoothOppClientImpl to be registered
+        * @param[in]   serverAddress           The address of the target OPP server
+        * @param[in]   filePath                The path of the source file to be pushed
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result PushOppFile(const _BluetoothOppClientImpl& impl, const Tizen::Base::ByteBuffer& serverAddress,
+                       const Tizen::Base::String& filePath);
+
+       /**
+        * Cancels the Push request sent previously or stops the file transfer in progress.
+        *
+        * @return       An error code
+        * @exception    E_SUCCESS              The method is successful.
+        * @exception    E_FAILURE              The method failed.
+        */
+       result CancelOppPush(void);
+
+       //-----------------------------------------------------------------------------------------------------------------
+       // Callback method
+       //-----------------------------------------------------------------------------------------------------------------
+
+       /**
+        * Callback to notify that a push request is responded from the requested OPP server.
+        */
+       static void OnOppClientConnectionResponded(int status, const char* pRemoteAddress, void* pUserData);
+
+       /**
+        * Callback to notify the progress information of the client side during the file transfer.
+        */
+       static void OnOppClientTransferInProgress(const char* pFilePath, long long fileSize, int progress, void* pUserData);
+
+       /**
+        * Callback to notify that the file transfer of the client side is completed.
+        */
+       static void OnOppClientTransferCompleted(int status, const char* pRemoteAddress, void* pUserData);
+
+       /**
+        * Callback to notify that a push request is received from a remote OPP client.
+        */
+       static void OnOppServerConnectionRequested(const char* pRemoteAddress, void* pUserData);
+
+       /**
+        * Callback to notify the progress information of the server side during the file transfer.
+        */
+       static void OnOppServerTransferInProgress(const char* pFilePath, long long fileSize, int progress, void* pUserData);
+
+       /**
+        * Callback to notify that the file transfer of the server side is completed.
+        */
+       static void OnOppServerTransferCompleted(int status, const char* pFilePath, long long fileSize, void* pUserData);
+
+
+private:
+       _BluetoothOppSystemAdapter(void);
+       ~_BluetoothOppSystemAdapter(void);
+
+       _BluetoothOppSystemAdapter(const _BluetoothOppSystemAdapter& value);
+       _BluetoothOppSystemAdapter& operator =(const _BluetoothOppSystemAdapter& value);
+
+       static void InitSingleton(void);
+
+private:
+       _BluetoothOppServerImpl* __pOppServerImpl;
+       _BluetoothOppClientImpl* __pOppClientImpl;
+       int __serverTransferId;
+       Tizen::Base::String __serverRecvFileName;
+       long long __serverRecvFileSize;
+       static _BluetoothOppSystemAdapter* __pInstance;
+
+}; // _BluetoothOppSystemAdapter
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_OPP_SYSTEM_ADAPTER_H_
diff --git a/src/FNetBt_BluetoothSppAcceptorEvent.cpp b/src/FNetBt_BluetoothSppAcceptorEvent.cpp
new file mode 100644 (file)
index 0000000..d98c38b
--- /dev/null
@@ -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    FNetBt_BluetoothSppAcceptorEvent.cpp
+// @brief   This is the implementation file for the _BluetoothSppAcceptorEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseRtIEventArg.h>
+#include "FNetBt_BluetoothSppAcceptorEvent.h"
+#include "FNetBt_BluetoothSppAcceptorEventArg.h"
+#include "FNetBtIBluetoothSppAcceptorEventListener.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothSppAcceptorEvent::_BluetoothSppAcceptorEvent(void)
+{
+}
+
+_BluetoothSppAcceptorEvent::~_BluetoothSppAcceptorEvent(void)
+{
+}
+
+result
+_BluetoothSppAcceptorEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothSppAcceptorEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       const BluetoothDevice* pDevice = null;
+       ByteBuffer* pData = null;
+
+       IBluetoothSppAcceptorEventListener* pListener = dynamic_cast <IBluetoothSppAcceptorEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pListener != null, E_INVALID_ARG, "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothSppAcceptorEventArg* pEventArg = dynamic_cast <const _BluetoothSppAcceptorEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothSppAcceptorEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case _BT_SPP_ACCEPTOR_EVENT_CONN_REQUESTED:
+               pDevice = pEventArg->GetRequester();
+               if (pDevice != null)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth SPP Acceptor Event (Type: _BT_SPP_ACCEPTOR_EVENT_CONN_REQUESTED)");
+                       pListener->OnSppConnectionRequested(*pDevice);
+               }
+               break;
+
+       case _BT_SPP_ACCEPTOR_EVENT_DISCONNECTED:
+               SysLog(NID_NET_BT, "Firing Bluetooth SPP Acceptor Event (Type: _BT_SPP_ACCEPTOR_EVENT_DISCONNECTED)");
+               pListener->OnSppDisconnected(pEventArg->GetErrorResult());
+               break;
+
+       case _BT_SPP_ACCEPTOR_EVENT_DATA_RECEIVED:
+               pData = pEventArg->GetReceivedData();
+               if (pData != null)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth SPP Acceptor Event (Type: _BT_SPP_ACCEPTOR_EVENT_DATA_RECEIVED)");
+                       pListener->OnSppDataReceived(*pData);
+               }
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothSppAcceptorEvent.h b/src/FNetBt_BluetoothSppAcceptorEvent.h
new file mode 100644 (file)
index 0000000..f200c99
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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    FNetBt_BluetoothSppAcceptorEvent.h
+ * @brief   This is the header file for the _BluetoothSppAcceptorEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothSppAcceptorEvent class.
+ * The _BluetoothSppAcceptorEvent class can call a method of a listener (_IBluetoothSppAcceptorEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+// Forward declaration
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// @class   _BluetoothSppAcceptorEvent
+// @brief   This class handles Bluetooth SPP Acceptor events.
+//
+// When a Bluetooth device event occurs, the _BluetoothSppAcceptorEvent object finds a _IBluetoothSppAcceptorEventListener object
+// and calls an appropriate method of the listener.
+//
+class _BluetoothSppAcceptorEvent
+       : public Tizen::Base::Runtime::_Event
+{
+public:
+       _BluetoothSppAcceptorEvent(void);
+       virtual ~_BluetoothSppAcceptorEvent(void);
+
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate pListener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth SPP Acceptor event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothSppAcceptorEvent(const _BluetoothSppAcceptorEvent& value);
+       _BluetoothSppAcceptorEvent& operator =(const _BluetoothSppAcceptorEvent& rhs);
+
+}; // _BluetoothSppAcceptorEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_EVENT_H_
diff --git a/src/FNetBt_BluetoothSppAcceptorEventArg.cpp b/src/FNetBt_BluetoothSppAcceptorEventArg.cpp
new file mode 100755 (executable)
index 0000000..841ed81
--- /dev/null
@@ -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    FNetBt_BluetoothSppAcceptorEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothSppAcceptorEventArg class.
+//
+
+#include <FBaseByteBuffer.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothSppAcceptorEventArg.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// This is a class constructor for _BT_SPP_ACCEPTOR_EVENT_CONN_REQUESTED event.
+//
+_BluetoothSppAcceptorEventArg::_BluetoothSppAcceptorEventArg(const BluetoothDevice& device)
+       : __evtType(_BT_SPP_ACCEPTOR_EVENT_CONN_REQUESTED)
+       , __pRequester(null)
+       , __result(E_SUCCESS)
+       , __pData(null)
+{
+       __pRequester = new (std::nothrow) BluetoothDevice(device);
+       SysTryReturnVoidResult(NID_NET_BT, __pRequester != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+}
+
+//
+// This is a class constructor for _BT_SPP_ACCEPTOR_EVENT_DISCONNECTED event.
+//
+_BluetoothSppAcceptorEventArg::_BluetoothSppAcceptorEventArg(result r)
+       : __evtType(_BT_SPP_ACCEPTOR_EVENT_DISCONNECTED)
+       , __pRequester(null)
+       , __result(r)
+       , __pData(null)
+{
+}
+
+//
+// This is a class constructor for _BT_SPP_ACCEPTOR_EVENT_DATA_RECEIVED event.
+//
+_BluetoothSppAcceptorEventArg::_BluetoothSppAcceptorEventArg(const Tizen::Base::ByteBuffer& buffer)
+       : __evtType(_BT_SPP_ACCEPTOR_EVENT_DATA_RECEIVED)
+       , __pRequester(null)
+       , __result(E_SUCCESS)
+       , __pData(null)
+{
+       __pData = new (std::nothrow) ByteBuffer();
+       SysTryReturnVoidResult(NID_NET_BT, __pData != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       __pData->Construct(buffer);
+       __pData->SetPosition(0);
+}
+
+_BluetoothSppAcceptorEventArg::~_BluetoothSppAcceptorEventArg(void)
+{
+       delete __pRequester;
+       delete __pData;
+}
+
+_BluetoothSppAcceptorEventType
+_BluetoothSppAcceptorEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
+
+const BluetoothDevice*
+_BluetoothSppAcceptorEventArg::GetRequester(void) const
+{
+       return __pRequester;
+}
+
+result
+_BluetoothSppAcceptorEventArg::GetErrorResult(void) const
+{
+       return __result;
+}
+
+Tizen::Base::ByteBuffer*
+_BluetoothSppAcceptorEventArg::GetReceivedData(void) const
+{
+       return __pData;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothSppAcceptorEventArg.h b/src/FNetBt_BluetoothSppAcceptorEventArg.h
new file mode 100644 (file)
index 0000000..de30e57
--- /dev/null
@@ -0,0 +1,137 @@
+//
+// 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    FNetBt_BluetoothSppAcceptorEventArg.h
+ * @brief   This is the header file for the _BluetoothSppAcceptorEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothSppAcceptorEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+
+// Forward declaration
+namespace Tizen { namespace Base {
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declaration
+class BluetoothDevice;
+
+/**
+  * @enum    _BluetoothSppAcceptorEventType
+  * Type for specifying the type of _BluetoothSppAcceptorEvent
+  */
+enum _BluetoothSppAcceptorEventType
+{
+       _BT_SPP_ACCEPTOR_EVENT_CONN_REQUESTED,      /**< For notifying that a new connection request is received */
+       _BT_SPP_ACCEPTOR_EVENT_DISCONNECTED,        /**< For notifying that the connection is disconnected */
+       _BT_SPP_ACCEPTOR_EVENT_DATA_RECEIVED,       /**< For notifying that the data has been received */
+};
+
+/**
+ * @class   _BluetoothSppAcceptorEventArg
+ * @brief   This class is used as an argument for callback methods of the IBluetoothSppAcceptorEventListener class.
+ *
+ * When a _BluetoothSppAcceptorEvent occurs, the _BluetoothSppAcceptorEvent finds a IBluetoothSppAcceptorEventListener instance
+ * which is registered for the _BluetoothSppAcceptorEvent and calls an appropriate method of the listener.
+ * @see     IBluetoothSppAcceptorEventListener
+ */
+class _BluetoothSppAcceptorEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor for _BT_SPP_ACCEPTOR_EVENT_CONN_REQUESTED event.
+        *
+        * @param[in]   device               The SPP initiator device
+        */
+       _BluetoothSppAcceptorEventArg(const BluetoothDevice& device);
+
+       /**
+        * This is a class constructor for _BT_SPP_ACCEPTOR_EVENT_DISCONNECTED event.
+        *
+        * @param[in]   r                    The result of the event
+        * @exception   E_SUCCESS            The connection is terminated successfully.
+        * @exception   E_SYSTEM             The method has failed to disconnect.
+        */
+       _BluetoothSppAcceptorEventArg(result r);
+
+       /**
+        * This is a class constructor for _BT_SPP_ACCEPTOR_EVENT_DATA_RECEIVED event.
+        *
+        * @param[in]   buffer               The received data
+        */
+       _BluetoothSppAcceptorEventArg(const Tizen::Base::ByteBuffer& buffer);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothSppAcceptorEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothSppAcceptorEventType GetEventType(void) const;
+
+       /**
+        * Gets the SPP initiator device.
+        *
+        * @return      The pointer of the SPP initiator device which request to connect
+        */
+       const BluetoothDevice* GetRequester(void) const;
+
+       /**
+        * Gets the error result of this event.
+        *
+        * @return      The result of the event
+        */
+       result GetErrorResult(void) const;
+
+       /**
+        * Gets The received data.
+        *
+        * @return      The received data
+        */
+       Tizen::Base::ByteBuffer* GetReceivedData(void) const;
+
+private:
+       _BluetoothSppAcceptorEventArg(void);
+       _BluetoothSppAcceptorEventArg(const _BluetoothSppAcceptorEventArg& eventArg);
+       _BluetoothSppAcceptorEventArg& operator =(const _BluetoothSppAcceptorEventArg& rValue);
+
+private:
+       _BluetoothSppAcceptorEventType __evtType;
+       BluetoothDevice* __pRequester;
+       result __result;
+       Tizen::Base::ByteBuffer* __pData;
+
+}; // _BluetoothSppAcceptorEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothSppAcceptorImpl.cpp b/src/FNetBt_BluetoothSppAcceptorImpl.cpp
new file mode 100755 (executable)
index 0000000..fcbfc48
--- /dev/null
@@ -0,0 +1,642 @@
+//
+// 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    FNetBt_BluetoothSppAcceptorImpl.cpp
+// @brief   This is the implementation file for the _BluetoothSppAcceptorImpl class.
+//
+
+#include <FBaseByteBuffer.h>
+#include <FBaseUuId.h>
+#include <FOspConfig.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothSppAcceptorEventListener.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothSppAcceptorEvent.h"
+#include "FNetBt_BluetoothSppAcceptorEventArg.h"
+#include "FNetBt_BluetoothSppAcceptorImpl.h"
+#include "FNetBt_BluetoothSppSystemAdapter.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothSppAcceptorImpl::_BluetoothSppAcceptorImpl(void)
+       : __pGapAdapter(null)
+       , __pSppAdapter(null)
+       , __pEvent(null)
+       , __stateMutex()
+       , __currentState(_BT_SPP_ACC_STATE_DISABLED)
+       , __parentSocketFd(_BT_INVALID_SOCKET_FD)
+       , __childSocketFd(_BT_INVALID_SOCKET_FD)
+{
+}
+
+_BluetoothSppAcceptorImpl::~_BluetoothSppAcceptorImpl(void)
+{
+       if (__pSppAdapter != null)
+       {
+               if ((__currentState == _BT_SPP_ACC_STATE_ON_SERVICE) ||
+                       (__currentState == _BT_SPP_ACC_STATE_CONNECT_REQUESTED) ||
+                       (__currentState == _BT_SPP_ACC_STATE_CONNECTED))
+               {
+                       (void) StopService();    // Ignores the result of this function.
+               }
+       }
+
+       if (__pGapAdapter != null)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+       }
+}
+
+result
+_BluetoothSppAcceptorImpl::Construct(IBluetoothSppAcceptorEventListener& listener)
+{
+       result r = E_SUCCESS;
+       std::unique_ptr<_BluetoothSppAcceptorEvent> pEvent;
+
+       r = __stateMutex.Create();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create the state mutex.");
+
+       __pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturn(NID_NET_BT, __pGapAdapter != null, E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] Failed to invoke _BluetoothGapSystemAdapter::GetInstance().");
+
+       __pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();
+       SysTryReturn(NID_NET_BT, __pSppAdapter != null, E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] Failed to invoke _BluetoothSppSystemAdapter::GetInstance().");
+
+       pEvent.reset(new (std::nothrow) _BluetoothSppAcceptorEvent());
+       SysTryReturn(NID_NET_BT, pEvent != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       r = pEvent->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct the event.");
+       // add the IBluetoothSppAcceptorEventListener instance to a new created _BluetoothSppAcceptorEvent.
+       r = pEvent->AddListener(listener, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                       "[%s] Propagating. Failed to add the application listener for SPP Acceptor", GetErrorMessage(r));
+
+       // registers this callback listener to the system adapter for activation/deactivation event
+       r = __pGapAdapter->RegisterManagerEventListener(*this, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                          "[E_SYSTEM] Failed to register the callback listener to _BluetoothGapSystemAdapter.");
+
+       // check whether the Bluetooth is available
+       __stateMutex.Acquire();
+
+       if (__pGapAdapter->IsActivated() == true)
+       {
+               __currentState = _BT_SPP_ACC_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       __pEvent = move(pEvent);
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothSppAcceptorImpl::AcceptConnection(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+       int clientSocketFd = _BT_INVALID_SOCKET_FD;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_ACC_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_ACC_STATE_IDLE:
+       case _BT_SPP_ACC_STATE_ON_SERVICE:
+       case _BT_SPP_ACC_STATE_CONNECTED:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECT_REQUESTED:
+               r = __pSppAdapter->AcceptSocketRequest(__parentSocketFd, clientSocketFd);
+
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_ACC_STATE_CONNECTED;
+                       __childSocketFd = clientSocketFd;
+               }
+               else
+               {
+                       __currentState = _BT_SPP_ACC_STATE_ON_SERVICE;
+               }
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on accepting a connection request.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothSppAcceptorImpl::RejectConnection()
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_ACC_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_ACC_STATE_IDLE:
+       case _BT_SPP_ACC_STATE_ON_SERVICE:
+       case _BT_SPP_ACC_STATE_CONNECTED:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECT_REQUESTED:
+               r = __pSppAdapter->RejectSocketRequest(__parentSocketFd);
+               __currentState = _BT_SPP_ACC_STATE_ON_SERVICE;
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on rejecting a connection request.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothSppAcceptorImpl::StartService(const Tizen::Base::UuId& serviceUuid)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+       int serverSocketFd = _BT_INVALID_SOCKET_FD;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_ACC_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_ACC_STATE_IDLE:
+               r = __pSppAdapter->OpenServerSocket(serviceUuid, *this, serverSocketFd);
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_ACC_STATE_ON_SERVICE;
+                       __parentSocketFd = serverSocketFd;
+               }
+               break;
+
+       case _BT_SPP_ACC_STATE_ON_SERVICE:
+       case _BT_SPP_ACC_STATE_CONNECT_REQUESTED:
+               r = E_IN_PROGRESS;
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECTED:
+               r = E_ALREADY_CONNECTED;
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on starting SPP service.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothSppAcceptorImpl::StopService(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+       result resDisconnect = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_ACC_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_ACC_STATE_IDLE:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_SPP_ACC_STATE_ON_SERVICE:
+               r = __pSppAdapter->CloseServerSocket(__parentSocketFd);
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_ACC_STATE_IDLE;
+                       __parentSocketFd = _BT_INVALID_SOCKET_FD;
+               }
+               break;
+
+       // Stays in the current status, if StopSppServer() fails
+       case _BT_SPP_ACC_STATE_CONNECT_REQUESTED:
+               r = __pSppAdapter->RejectSocketRequest(__parentSocketFd);
+               if (r == E_SUCCESS)
+               {
+                       r = __pSppAdapter->CloseServerSocket(__parentSocketFd);
+                       if (r == E_SUCCESS)
+                       {
+                               __currentState = _BT_SPP_ACC_STATE_IDLE;
+                               __parentSocketFd = _BT_INVALID_SOCKET_FD;
+                       }
+                       else
+                       {
+                               __currentState = _BT_SPP_ACC_STATE_ON_SERVICE;
+                       }
+               }
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECTED:
+               resDisconnect = ProcessAsyncDisconnect();
+               // stop server socket regardless whether disconnection is successful
+               r = __pSppAdapter->CloseServerSocket(__parentSocketFd);
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_ACC_STATE_IDLE;
+                       __parentSocketFd = _BT_INVALID_SOCKET_FD;
+               }
+               else if (resDisconnect == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_ACC_STATE_ON_SERVICE;
+               }
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on stopping SPP service.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothSppAcceptorImpl::SendData(const Tizen::Base::ByteBuffer& buffer)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_ACC_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_ACC_STATE_IDLE:
+       case _BT_SPP_ACC_STATE_ON_SERVICE:
+       case _BT_SPP_ACC_STATE_CONNECT_REQUESTED:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECTED:
+               if (buffer.GetRemaining() > 0)
+               {
+                       r = __pSppAdapter->SendSocketData(__childSocketFd, buffer);
+               }
+               else
+               {
+                       r = E_INVALID_ARG;
+               }
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on sending data.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothSppAcceptorImpl::Disconnect()
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_SUCCESS;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_ACC_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_ACC_STATE_IDLE:
+       case _BT_SPP_ACC_STATE_ON_SERVICE:
+       case _BT_SPP_ACC_STATE_CONNECT_REQUESTED:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECTED:
+               // send a disconnected event here if the disconnect method is successful
+               // because the disconnect method of the underlying system is sync call. (transform sync into async)
+               r = ProcessAsyncDisconnect();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_ACC_STATE_ON_SERVICE;
+               }
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on disconnecting the connection.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+void
+_BluetoothSppAcceptorImpl::OnBluetoothActivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_SPP_ACC_STATE_DISABLED) && (r == E_SUCCESS))
+       {
+               __currentState = _BT_SPP_ACC_STATE_IDLE;
+       }
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothSppAcceptorImpl::OnBluetoothDeactivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if (r == E_SUCCESS)
+       {
+               __currentState = _BT_SPP_ACC_STATE_DISABLED;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothSppAcceptorImpl::OnSocketConnectionRequested(const BluetoothDevice& device)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if (__currentState == _BT_SPP_ACC_STATE_ON_SERVICE)
+       {
+               __currentState = _BT_SPP_ACC_STATE_CONNECT_REQUESTED;
+               isFired = true;
+       }
+       else if ((__currentState == _BT_SPP_ACC_STATE_CONNECT_REQUESTED) ||
+                        (__currentState == _BT_SPP_ACC_STATE_CONNECTED))
+       {
+               (void) __pSppAdapter->RejectSocketRequest(__parentSocketFd);
+       }
+       // ignore othre cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothSppAcceptorEventArg* pArg = new (std::nothrow) _BluetoothSppAcceptorEventArg(device);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [CONNECT_REQUESTED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothSppAcceptorImpl::OnSocketDisconnected(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_SPP_ACC_STATE_CONNECT_REQUESTED) ||
+               (__currentState == _BT_SPP_ACC_STATE_CONNECTED))
+       {
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_ACC_STATE_ON_SERVICE;
+                       __childSocketFd = _BT_INVALID_SOCKET_FD;
+
+                       isFired = true;
+               }
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothSppAcceptorEventArg* pArg = new (std::nothrow) _BluetoothSppAcceptorEventArg(r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+                       if (r != E_SUCCESS)
+                       {
+                               SysLogException(NID_NET_BT, r, "[%s] exception occurred on SPP-disconnect callback.", GetErrorMessage(r));
+                       }
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DISCONNECTED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothSppAcceptorImpl::OnSocketDataReceived(Tizen::Base::ByteBuffer& buffer)
+{
+       bool isFired = false;
+
+       if (__currentState == _BT_SPP_ACC_STATE_CONNECTED)
+       {
+               _BluetoothSppAcceptorEventArg* pArg = new (std::nothrow) _BluetoothSppAcceptorEventArg(buffer);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+               }
+               else
+               {
+                       // use Fire() instead of FireAsync() to improve the transfer rate.
+                       __pEvent->Fire(*pArg);
+                       isFired = true;
+               }
+       }
+
+       SysLog(NID_NET_BT, "[CurrentState:%s], [DATA_RECEIVED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+result
+_BluetoothSppAcceptorImpl::ProcessAsyncDisconnect(void)
+{
+       result r = E_SUCCESS;
+
+       r = __pSppAdapter->DisconnectSocket(__childSocketFd);
+
+       // send a disconnected event here if the disconnect method is successful
+       // because the disconnect method of the underlying system is sync call. (transform sync into async)
+       if (r == E_SUCCESS)
+       {
+               __childSocketFd = _BT_INVALID_SOCKET_FD;
+
+               _BluetoothSppAcceptorEventArg* pArg = new (std::nothrow) _BluetoothSppAcceptorEventArg(r);
+               if (pArg != null)
+               {
+                       __pEvent->FireAsync(*pArg);
+                       SysLog(NID_NET_BT, "[DISCONNECTED_Event:Fired]");
+               }
+       }
+
+       return r;
+}
+
+const char*
+_BluetoothSppAcceptorImpl::GetStringOfCurrentState(void) const
+{
+       const char* pStateString = null;
+
+       switch (__currentState)
+       {
+       case _BT_SPP_ACC_STATE_DISABLED:
+               pStateString = "DISABLED";
+               break;
+
+       case _BT_SPP_ACC_STATE_IDLE:
+               pStateString = "IDLE";
+               break;
+
+       case _BT_SPP_ACC_STATE_ON_SERVICE:
+               pStateString = "ON_SERVICE";
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECT_REQUESTED:
+               pStateString = "CONNECT_REQUESTED";
+               break;
+
+       case _BT_SPP_ACC_STATE_CONNECTED:
+               pStateString = "CONNECTED";
+               break;
+
+       default:
+               pStateString = "Unknown";
+               break;
+       }
+
+       return pStateString;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothSppInitiatorEvent.cpp b/src/FNetBt_BluetoothSppInitiatorEvent.cpp
new file mode 100644 (file)
index 0000000..e96c6c2
--- /dev/null
@@ -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    FNetBt_BluetoothSppInitiatorEvent.cpp
+// @brief   This is the implementation file for the _BluetoothSppInitiatorEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseRtIEventArg.h>
+#include "FNetBt_BluetoothSppInitiatorEvent.h"
+#include "FNetBt_BluetoothSppInitiatorEventArg.h"
+#include "FNetBtIBluetoothSppInitiatorEventListener.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothSppInitiatorEvent::_BluetoothSppInitiatorEvent(void)
+{
+}
+
+_BluetoothSppInitiatorEvent::~_BluetoothSppInitiatorEvent(void)
+{
+}
+
+result
+_BluetoothSppInitiatorEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+_BluetoothSppInitiatorEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       ByteBuffer* pData = null;
+
+       IBluetoothSppInitiatorEventListener* pListener = dynamic_cast <IBluetoothSppInitiatorEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_BT, pListener != null, E_INVALID_ARG,
+                               "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const _BluetoothSppInitiatorEventArg* pEventArg = dynamic_cast <const _BluetoothSppInitiatorEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_BT, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       _BluetoothSppInitiatorEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case _BT_SPP_INITIATOR_EVENT_CONN_RESPONDED:
+               SysLog(NID_NET_BT, "Firing Bluetooth SPP Initiator Event (Type: _BT_SPP_INITIATOR_EVENT_CONN_RESPONDED)");
+               pListener->OnSppConnectionResponded(pEventArg->GetErrorResult());
+               break;
+
+       case _BT_SPP_INITIATOR_EVENT_DISCONNECTED:
+               SysLog(NID_NET_BT, "Firing Bluetooth SPP Initiator Event (Type: _BT_SPP_INITIATOR_EVENT_DISCONNECTED)");
+               pListener->OnSppDisconnected(pEventArg->GetErrorResult());
+               break;
+
+       case _BT_SPP_INITIATOR_EVENT_DATA_RECEIVED:
+               pData = pEventArg->GetReceivedData();
+               if (pData != null)
+               {
+                       SysLog(NID_NET_BT, "Firing Bluetooth SPP Initiator Event (Type: _BT_SPP_INITIATOR_EVENT_DATA_RECEIVED)");
+                       pListener->OnSppDataReceived(*pData);
+               }
+               break;
+
+       default:
+               break;
+       }
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothSppInitiatorEvent.h b/src/FNetBt_BluetoothSppInitiatorEvent.h
new file mode 100644 (file)
index 0000000..c5dd923
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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    FNetBt_BluetoothSppInitiatorEvent.h
+ * @brief   This is the header file for the _BluetoothSppInitiatorEvent class.
+ *
+ * This header file contains the declarations of the _BluetoothSppInitiatorEvent class.
+ * The _BluetoothSppInitiatorEvent class can call a method of a listener (IBluetoothSppInitiatorEventListener object).
+ * So, when a device event is occurred, listener instances can handle it appropriately.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_EVENT_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_EVENT_H_
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseRt_Event.h>
+
+// Forward declaration
+namespace Tizen { namespace Base { namespace Runtime
+{
+class IEventListener;
+class IEventArg;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// @class   _BluetoothSppInitiatorEvent
+// @brief   This class handles Bluetooth SPP Initiator events.
+//
+// When a Bluetooth device event occurs, the _BluetoothSppInitiatorEvent object finds a IBluetoothSppInitiatorEventListener
+// object and calls an appropriate method of the listener.
+//
+class _BluetoothSppInitiatorEvent
+       : public Tizen::Base::Runtime::_Event
+{
+public:
+       _BluetoothSppInitiatorEvent(void);
+       virtual ~_BluetoothSppInitiatorEvent(void);
+
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the argument and finds out the type of event. After that, this method calls appropriate pListener's method.
+        *
+        * @return      A result code.
+        * @param[in]   pListener           An event listener related to this Bluetooth SPP Initiator event.
+        * @param[in]   arg                 An event argument including information to be passed to the event listeners
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_INVALID_ARG       The argument passed to a method contains invalid values.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       _BluetoothSppInitiatorEvent(const _BluetoothSppInitiatorEvent& value);
+       _BluetoothSppInitiatorEvent& operator =(const _BluetoothSppInitiatorEvent& rhs);
+
+}; // _BluetoothSppInitiatorEvent
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_EVENT_H_
diff --git a/src/FNetBt_BluetoothSppInitiatorEventArg.cpp b/src/FNetBt_BluetoothSppInitiatorEventArg.cpp
new file mode 100755 (executable)
index 0000000..530bd76
--- /dev/null
@@ -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    FNetBt_BluetoothSppInitiatorEventArg.cpp
+// @brief   This is the implementation file for the _BluetoothSppInitiatorEventArg class.
+//
+
+#include <FBaseByteBuffer.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothSppInitiatorEventArg.h"
+
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+//
+// This is a class constructor for _BT_SPP_INITIATOR_EVENT_CONN_RESPONDED and _BT_SPP_INITIATOR_EVENT_DISCONNECTED event.
+//
+_BluetoothSppInitiatorEventArg::_BluetoothSppInitiatorEventArg(bool isResponse, result r)
+       : __evtType(_BT_SPP_INITIATOR_EVENT_CONN_RESPONDED)
+       , __result(r)
+       , __pData(null)
+{
+       if (!isResponse)
+       {
+               __evtType = _BT_SPP_INITIATOR_EVENT_DISCONNECTED;
+       }
+}
+
+//
+// This is a class constructor for _BT_SPP_INITIATOR_EVENT_DATA_RECEIVED event.
+//
+_BluetoothSppInitiatorEventArg::_BluetoothSppInitiatorEventArg(const Tizen::Base::ByteBuffer& buffer)
+       : __evtType(_BT_SPP_INITIATOR_EVENT_DATA_RECEIVED)
+       , __result(E_SUCCESS)
+       , __pData(null)
+{
+       __pData = new (std::nothrow) ByteBuffer();
+       SysTryReturnVoidResult(NID_NET_BT, __pData != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+       __pData->Construct(buffer);
+       __pData->SetPosition(0);
+}
+
+_BluetoothSppInitiatorEventArg::~_BluetoothSppInitiatorEventArg(void)
+{
+       delete __pData;
+}
+
+_BluetoothSppInitiatorEventType
+_BluetoothSppInitiatorEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
+
+result
+_BluetoothSppInitiatorEventArg::GetErrorResult(void) const
+{
+       return __result;
+}
+
+Tizen::Base::ByteBuffer*
+_BluetoothSppInitiatorEventArg::GetReceivedData(void) const
+{
+       return __pData;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothSppInitiatorEventArg.h b/src/FNetBt_BluetoothSppInitiatorEventArg.h
new file mode 100644 (file)
index 0000000..b98a76d
--- /dev/null
@@ -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    FNetBt_BluetoothSppInitiatorEventArg.h
+ * @brief   This is the header file for the _BluetoothSppInitiatorEventArg class.
+ *
+ * This header file contains the declarations of the _BluetoothSppInitiatorEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_EVENT_ARG_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+
+// Forward declaration
+namespace Tizen { namespace Base {
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declaration
+class BluetoothDevice;
+
+/**
+  * @enum    _BluetoothSppInitiatorEventType
+  * Type for specifying the type of _BluetoothSppInitiatorEvent
+  */
+enum _BluetoothSppInitiatorEventType
+{
+       _BT_SPP_INITIATOR_EVENT_CONN_RESPONDED,      /**< For notifying that the response of the connection request is received */
+       _BT_SPP_INITIATOR_EVENT_DISCONNECTED,        /**< For notifying that the connection is disconnected */
+       _BT_SPP_INITIATOR_EVENT_DATA_RECEIVED,       /**< For notifying that the data has been received */
+};
+
+/**
+ * @class   _BluetoothSppInitiatorEventArg
+ * @brief   This class is used as an argument for callback methods of the _IBluetoothSppInitiatorEventListener class.
+ *
+ * When a _BluetoothSppInitiatorEvent occurs, the _BluetoothSppInitiatorEvent finds a _IBluetoothSppInitiatorEventListener instance
+ * which is registered for the _BluetoothSppInitiatorEvent and calls an appropriate method of the listener.
+ * @see     _IBluetoothSppInitiatorEventListener
+ */
+class _BluetoothSppInitiatorEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor for _BT_SPP_INITIATOR_EVENT_CONN_RESPONDED and _BT_SPP_INITIATOR_EVENT_DISCONNECTED event.
+        *
+        * @param[in]   isResponse           @c true if the event is a connection response,
+        *                                   else @c false
+        * @param[in]   r                    The result of the event
+        * @exception   E_SUCCESS            The connection is established successfully.
+        * @exception   E_SYSTEM             The connection fails.
+        */
+       _BluetoothSppInitiatorEventArg(bool isResponse, result r);
+
+       /**
+        * This is a class constructor for _BT_SPP_INITIATOR_EVENT_DATA_RECEIVED event.
+        *
+        * @param[in]   buffer               The received data
+        */
+       _BluetoothSppInitiatorEventArg(const Tizen::Base::ByteBuffer& buffer);
+
+       /**
+        * This is the class destructor.
+        */
+       ~_BluetoothSppInitiatorEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       _BluetoothSppInitiatorEventType GetEventType(void) const;
+
+       /**
+        * Gets the error result of this event.
+        *
+        * @return      The result of the event
+        */
+       result GetErrorResult(void) const;
+
+       /**
+        * Gets The received data.
+        *
+        * @return      The received data
+        */
+       Tizen::Base::ByteBuffer* GetReceivedData(void) const;
+
+private:
+       _BluetoothSppInitiatorEventArg(void);
+       _BluetoothSppInitiatorEventArg(const _BluetoothSppInitiatorEventArg& eventArg);
+       _BluetoothSppInitiatorEventArg& operator =(const _BluetoothSppInitiatorEventArg& rValue);
+
+private:
+       _BluetoothSppInitiatorEventType __evtType;
+       result __result;
+       Tizen::Base::ByteBuffer* __pData;
+
+}; // _BluetoothSppInitiatorEventArg
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_EVENT_ARG_H_
diff --git a/src/FNetBt_BluetoothSppInitiatorImpl.cpp b/src/FNetBt_BluetoothSppInitiatorImpl.cpp
new file mode 100755 (executable)
index 0000000..5614e57
--- /dev/null
@@ -0,0 +1,608 @@
+//
+// 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        FNetBt_BluetoothSppInitiatorImpl.cpp
+// @brief       This is the implementation file for the _BluetoothSppInitiatorImpl class.
+//
+
+#include <FOspConfig.h>
+#include <FBaseUuId.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FNetBtIBluetoothSppInitiatorEventListener.h>
+#include <FBaseSysLog.h>
+#include "FNetBt_BluetoothSppInitiatorEvent.h"
+#include "FNetBt_BluetoothSppInitiatorEventArg.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothSppSystemAdapter.h"
+#include "FNetBt_BluetoothSppInitiatorImpl.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+_BluetoothSppInitiatorImpl::_BluetoothSppInitiatorImpl(void)
+       : __pGapAdapter(null)
+       , __pSppAdapter(null)
+       , __pEvent(null)
+       , __stateMutex()
+       , __currentState(_BT_SPP_INI_STATE_DISABLED)
+       , __pairingAddress()
+       , __pairingUuid()
+       , __socketFd(_BT_INVALID_SOCKET_FD)
+{
+}
+
+_BluetoothSppInitiatorImpl::~_BluetoothSppInitiatorImpl(void)
+{
+       if (__pSppAdapter != null)
+       {
+               if ((__currentState == _BT_SPP_INI_STATE_BONDING)
+                       || (__currentState == _BT_SPP_INI_STATE_CONNECT_READY)
+                       || (__currentState == _BT_SPP_INI_STATE_CONNECTED))
+               {
+                       (void) ProcessAsyncDisconnect();    // Ignores the result of this function.
+               }
+       }
+
+       if (__pGapAdapter != null)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+               __pGapAdapter->UnregisterDeviceEventListener(*this);
+       }
+}
+
+result
+_BluetoothSppInitiatorImpl::Construct(IBluetoothSppInitiatorEventListener& listener)
+{
+       result r = E_SUCCESS;
+       std::unique_ptr<_BluetoothSppInitiatorEvent> pEvent;
+
+       r = __stateMutex.Create();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create the state mutex.");
+
+       r = __pairingAddress.Construct(_BT_ADDRESS_LENGTH);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct the address for pairing.");
+
+       __pGapAdapter = _BluetoothGapSystemAdapter::GetInstance();
+       SysTryReturn(NID_NET_BT, __pGapAdapter != null, E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] Failed to invoke _BluetoothGapSystemAdapter::GetInstance().");
+
+       __pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();
+       SysTryReturn(NID_NET_BT, __pSppAdapter != null, E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] Failed to invoke _BluetoothSppSystemAdapter::GetInstance().");
+
+       pEvent.reset(new (std::nothrow) _BluetoothSppInitiatorEvent());
+       SysTryReturn(NID_NET_BT, pEvent != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       pEvent->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct the event.");
+       // add the IBluetoothSppInitiatorEventListener instance to a new created _BluetoothSppInitiatorEvent.
+       r = pEvent->AddListener(listener, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                       "[%s] Propagating. Failed to add the application listener for SPP Initiator", GetErrorMessage(r));
+
+       // registers this callback listener to the system adapter for activation/deactivation event
+       r = __pGapAdapter->RegisterManagerEventListener(*this, true);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                          "[E_SYSTEM] Failed to register the callback listener to _BluetoothGapSystemAdapter.");
+
+       // registers this callback listener to the system adapter for paired event
+       r = __pGapAdapter->RegisterDeviceEventListener(*this);
+       if (r != E_SUCCESS)
+       {
+               __pGapAdapter->UnregisterManagerEventListener(*this);
+       }
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
+                          "[E_SYSTEM] Failed to register the callback listener to _BluetoothGapSystemAdapter.");
+
+       // checks whether the Bluetooth is available
+       __stateMutex.Acquire();
+
+       if (__pGapAdapter->IsActivated() == true)
+       {
+               __currentState = _BT_SPP_INI_STATE_IDLE;
+       }
+
+       __stateMutex.Release();
+
+       __pEvent = move(pEvent);
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothSppInitiatorImpl::SendData(const Tizen::Base::ByteBuffer& buffer)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_INI_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_INI_STATE_IDLE:
+       case _BT_SPP_INI_STATE_BONDING:         //TODO: this state should return E_INVALID_OPERATION. Versioning
+       case _BT_SPP_INI_STATE_CONNECT_READY:
+       case _BT_SPP_INI_STATE_REQ_CANCELING:   //TODO: this state should return E_INVALID_OPERATION. Versioning
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_SPP_INI_STATE_CONNECTED:
+               if (buffer.GetRemaining() > 0)
+               {
+                       r = __pSppAdapter->SendSocketData(__socketFd, buffer);
+               }
+               else
+               {
+                       r = E_INVALID_ARG;
+               }
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on sending data.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothSppInitiatorImpl::Connect(const BluetoothDevice& remoteDevice, const Tizen::Base::UuId& serviceUuid)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_INI_STATE_DISABLED:
+       case _BT_SPP_INI_STATE_REQ_CANCELING:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_INI_STATE_IDLE:
+               if (__pGapAdapter->IsPaired(*(remoteDevice.GetAddress())) == true)
+               {
+                       r = __pSppAdapter->ConnectSocket(*(remoteDevice.GetAddress()), serviceUuid, *this);
+                       if (r == E_SUCCESS)
+                       {
+                               __currentState = _BT_SPP_INI_STATE_CONNECT_READY;
+                       }
+               }
+               else
+               {
+                       // start the pairing process
+                       if (__pGapAdapter->Pair(*(remoteDevice.GetAddress())) == E_SUCCESS)
+                       {
+                               // copy the address of the pairing device to the local variable
+                               __pairingAddress.SetArray(remoteDevice.GetAddress()->GetPointer(), 0, _BT_ADDRESS_LENGTH);
+                               __pairingAddress.SetPosition(0);
+                               __pairingUuid = serviceUuid;
+
+                               r = E_SUCCESS;
+                               __currentState = _BT_SPP_INI_STATE_BONDING;
+                       }
+                       else
+                       {
+                               r = E_FAILURE;
+                       }
+               }
+               break;
+
+       case _BT_SPP_INI_STATE_BONDING:   //TODO: Versioning check
+       case _BT_SPP_INI_STATE_CONNECT_READY:
+               r = E_IN_PROGRESS;
+               break;
+
+       case _BT_SPP_INI_STATE_CONNECTED:
+               r = E_ALREADY_CONNECTED;
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on requesting a connection.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+result
+_BluetoothSppInitiatorImpl::Disconnect(void)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       result r = E_FAILURE;
+
+       __stateMutex.Acquire();
+
+       switch (__currentState)
+       {
+       case _BT_SPP_INI_STATE_DISABLED:
+               r = E_INVALID_STATE;
+               break;
+
+       case _BT_SPP_INI_STATE_IDLE:
+               r = E_INVALID_OPERATION;
+               break;
+
+       case _BT_SPP_INI_STATE_BONDING:   //TODO: Versioning check
+               if (__pGapAdapter->CancelPair() == E_SUCCESS)
+               {
+                       r = E_SUCCESS;
+                       __currentState = _BT_SPP_INI_STATE_REQ_CANCELING;
+               }
+               // It will be changed to IDLE after receiving the OnBluetoothPaired event.
+               break;
+
+       case _BT_SPP_INI_STATE_CONNECT_READY:
+               // TODO: how does it cancel to request the connection? __socketFd is not determined at this time.
+               r = ProcessAsyncDisconnect();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_INI_STATE_REQ_CANCELING;
+               }
+               // It will be changed to IDLE after receiving the OnSppDisconnected event.
+               break;
+
+       case _BT_SPP_INI_STATE_REQ_CANCELING:
+               r = E_IN_PROGRESS;
+               break;
+
+       case _BT_SPP_INI_STATE_CONNECTED:
+               r = ProcessAsyncDisconnect();
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_INI_STATE_IDLE;
+               }
+               // It will be changed to IDLE after receiving the OnSppDisconnected event.
+               break;
+
+       default:
+               r = E_FAILURE;
+               break;
+       }
+
+       __stateMutex.Release();
+
+       if (r != E_SUCCESS)
+       {
+               SysLogException(NID_NET_BT, r, "[%s] exception occurred on disconnecting the connection.", GetErrorMessage(r));
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       return r;
+}
+
+void
+_BluetoothSppInitiatorImpl::OnBluetoothActivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_SPP_INI_STATE_DISABLED) && (r == E_SUCCESS))
+       {
+               __currentState = _BT_SPP_INI_STATE_IDLE;
+       }
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothSppInitiatorImpl::OnBluetoothDeactivated(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       __stateMutex.Acquire();
+
+       if (r == E_SUCCESS)
+       {
+               __currentState = _BT_SPP_INI_STATE_DISABLED;
+       }
+
+       __stateMutex.Release();
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s]", GetStringOfCurrentState());
+}
+
+void
+_BluetoothSppInitiatorImpl::OnSocketConnectionResponded(int socketFd, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if ((__currentState == _BT_SPP_INI_STATE_CONNECT_READY)
+               || (__currentState == _BT_SPP_INI_STATE_REQ_CANCELING))
+       {
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_INI_STATE_CONNECTED;
+                       __socketFd = socketFd;
+               }
+               else
+               {
+                       // including the cases as r == E_REJECTED or r == E_MAX_EXCEEDED
+                       // E_MAX_EXCEEDED is originated in the previous version.
+                       __currentState = _BT_SPP_INI_STATE_IDLE;
+                       SysLogException(NID_NET_BT, r, "[%s] exception occurred on the response of the SPP connect request.", GetErrorMessage(r));
+               }
+
+               isFired = true;
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothSppInitiatorEventArg* pArg = new (std::nothrow) _BluetoothSppInitiatorEventArg(true, r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [CONNECT_RESPONDED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothSppInitiatorImpl::OnSocketDisconnected(result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if (__currentState == _BT_SPP_INI_STATE_CONNECTED)
+       {
+               if (r == E_SUCCESS)
+               {
+                       __currentState = _BT_SPP_INI_STATE_IDLE;
+                       __socketFd = _BT_INVALID_SOCKET_FD;
+                       isFired = true;
+               }
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothSppInitiatorEventArg* pArg = new (std::nothrow) _BluetoothSppInitiatorEventArg(false, r);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DISCONNECTED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothSppInitiatorImpl::OnSocketDataReceived(Tizen::Base::ByteBuffer& buffer)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s]", GetStringOfCurrentState());
+
+       bool isFired = false;
+
+       __stateMutex.Acquire();
+
+       if (__currentState == _BT_SPP_INI_STATE_CONNECTED)
+       {
+               isFired = true;
+       }
+       // ignore other cases
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothSppInitiatorEventArg* pArg = new (std::nothrow) _BluetoothSppInitiatorEventArg(buffer);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       // use Fire() instead of FireAsync() to improve the transfer rate.
+                       __pEvent->Fire(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [DATA_RECIEVED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+void
+_BluetoothSppInitiatorImpl::OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r)
+{
+       SysLog(NID_NET_BT, "EntryPoint, [CurrentState:%s], [ActionResult:%s]", GetStringOfCurrentState(), GetErrorMessage(r));
+
+       bool isFired = false;
+       result responseResult = E_SYSTEM;
+
+       __stateMutex.Acquire();
+
+       if (pPairedDevice->GetAddress()->Equals(__pairingAddress))
+       {
+               if (__currentState == _BT_SPP_INI_STATE_BONDING)
+               {
+                       if (r == E_SUCCESS)
+                       {
+                               if (__pSppAdapter->ConnectSocket(__pairingAddress, __pairingUuid, *this) == E_SUCCESS)
+                               {
+                                       __currentState = _BT_SPP_INI_STATE_CONNECT_READY;
+                               }
+                               else
+                               {
+                                       // callback responded with E_SYSTEM
+                                       isFired = true;
+                                       __currentState = _BT_SPP_INI_STATE_IDLE;
+                                       responseResult = E_SYSTEM;
+                               }
+                       }
+                       else
+                       {
+                               // callback responded with r
+                               isFired = true;
+                               __currentState = _BT_SPP_INI_STATE_IDLE;
+                               responseResult = r;
+                       }
+
+                       __pairingAddress.Clear();
+               }
+               else if (__currentState == _BT_SPP_INI_STATE_REQ_CANCELING)
+               {
+                       // callback responded with E_SYSTEM or E_OPERATION_CANCELED
+                       isFired = true;
+                       __currentState = _BT_SPP_INI_STATE_IDLE;
+                       responseResult = E_SYSTEM;
+               }
+               // ignore other cases
+       }
+       // ignored otherwise
+
+       __stateMutex.Release();
+
+       if (isFired)
+       {
+               _BluetoothSppInitiatorEventArg* pArg = new (std::nothrow) _BluetoothSppInitiatorEventArg(true, responseResult);
+               if (pArg == null)
+               {
+                       SysLogException(NID_NET_BT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+                       isFired = false;
+               }
+               else
+               {
+                       __pEvent->FireAsync(*pArg);
+               }
+       }
+
+       SysLog(NID_NET_BT, "ExitPoint, [CurrentState:%s], [CONNECT_RESPONDED_Event:%s]",
+                               GetStringOfCurrentState(), isFired ? "Fired" : "NotFired");
+}
+
+result
+_BluetoothSppInitiatorImpl::ProcessAsyncDisconnect(void)
+{
+       result r = E_SUCCESS;
+
+       r = __pSppAdapter->DisconnectSocket(__socketFd);
+
+       // send a disconnected event here if the disconnect method is successful
+       // because the disconnect method of the underlying system is sync call. (transform sync into async)
+       if (r == E_SUCCESS)
+       {
+               __socketFd = _BT_INVALID_SOCKET_FD;
+
+               _BluetoothSppInitiatorEventArg* pArg = new (std::nothrow) _BluetoothSppInitiatorEventArg(false, r);
+               if (pArg != null)
+               {
+                       __pEvent->FireAsync(*pArg);
+                       SysLog(NID_NET_BT, "[DISCONNECTED_Event:Fired]");
+               }
+       }
+
+       return r;
+}
+
+const char*
+_BluetoothSppInitiatorImpl::GetStringOfCurrentState(void) const
+{
+       const char* pStateString = null;
+
+       switch (__currentState)
+       {
+       case _BT_SPP_INI_STATE_DISABLED:
+               pStateString = "DISABLED";
+               break;
+
+       case _BT_SPP_INI_STATE_IDLE:
+               pStateString = "IDLE";
+               break;
+
+       case _BT_SPP_INI_STATE_BONDING:
+               pStateString = "BONDING";
+               break;
+
+       case _BT_SPP_INI_STATE_CONNECT_READY:
+               pStateString = "CONNECT_READY";
+               break;
+
+       case _BT_SPP_INI_STATE_REQ_CANCELING:
+               pStateString = "REQ_CANCELING";
+               break;
+
+       case _BT_SPP_INI_STATE_CONNECTED:
+               pStateString = "CONNECTED";
+               break;
+
+       default:
+               pStateString = "Unknown";
+               break;
+       }
+
+       return pStateString;
+}
+
+} } } // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothSppSystemAdapter.cpp b/src/FNetBt_BluetoothSppSystemAdapter.cpp
new file mode 100755 (executable)
index 0000000..11fcc36
--- /dev/null
@@ -0,0 +1,528 @@
+//
+// 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        FNetBt_BluetoothSppSystemAdapter.cpp
+// @brief       This is the implementation file for the _BluetoothSppSystemAdapter class.
+//
+
+#include <pthread.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseString.h>
+#include <FBaseUuId.h>
+#include <FBaseColArrayList.h>
+#include <FBaseColHashMapT.h>
+#include <FBaseColIComparerT.h>
+#include <FBaseColIHashCodeProviderT.h>
+#include <FBaseUtilStringUtil.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FNetBtBluetoothDevice.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include "FNetBt_BluetoothSppSystemAdapter.h"
+#include "FNetBt_BluetoothGapSystemAdapter.h"
+#include "FNetBt_BluetoothDeviceImpl.h"
+#include "FNetBt_IBluetoothSocketListener.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+struct _SocketFdDeleter
+{
+       void operator()(int* serverSocketFd)
+       {
+               (void) bt_socket_destroy_rfcomm(*serverSocketFd);
+       }
+};
+
+/*
+ * @class              _BluetoothAddressComparer
+ * @brief              The _BluetoothAddressComparer class provides the comparer about two specified String
+ *              which consists of Bluetooth address and service UUID.
+ */
+class _BluetoothAddressComparer
+       : public Tizen::Base::Collection::IComparerT <Tizen::Base::String>
+       , public Tizen::Base::Object
+{
+public:
+       _BluetoothAddressComparer(void){}
+       virtual ~_BluetoothAddressComparer(void){}
+
+       virtual result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
+       {
+               cmp = obj1.CompareTo(obj2);
+               return E_SUCCESS;
+       }
+
+private:
+       _BluetoothAddressComparer(const _BluetoothAddressComparer& value);
+       _BluetoothAddressComparer& operator =(const _BluetoothAddressComparer& value);
+
+};     //_BluetoothAddressComparer
+
+/*
+ * @class              _BluetoothAddressHashCodeProviderT
+ * @brief              The _BluetoothAddressHashCodeProviderT class provides the hash code of a specified String
+ *              which consists of Bluetooth address and service UUID.
+ */
+class _BluetoothAddressHashCodeProvider
+       : public Tizen::Base::Collection::IHashCodeProviderT <Tizen::Base::String>
+{
+public:
+       _BluetoothAddressHashCodeProvider(void) {}
+       virtual ~_BluetoothAddressHashCodeProvider(void) {}
+       virtual int GetHashCode(const Tizen::Base::String& obj) const
+       {
+               return obj.GetHashCode();
+       }
+
+private:
+       _BluetoothAddressHashCodeProvider(const _BluetoothAddressHashCodeProvider& value);
+       _BluetoothAddressHashCodeProvider& operator =(const _BluetoothAddressHashCodeProvider& value);
+
+};     //_BluetoothAddressHashCodeProvider
+
+
+static _BluetoothAddressComparer _btAddressComparer;
+static _BluetoothAddressHashCodeProvider _btAddressHashCodeProvider;
+
+_BluetoothSppSystemAdapter* _BluetoothSppSystemAdapter::__pInstance = null;
+
+_BluetoothSppSystemAdapter::_BluetoothSppSystemAdapter(void)
+       : __pServerSocketMap(null)
+       , __pSocketMap(null)
+       , __pClientSocketMap(null)
+{
+}
+
+_BluetoothSppSystemAdapter::~_BluetoothSppSystemAdapter(void)
+{
+       // unregister the callback methods from the underlying layer
+       (void) bt_socket_unset_connection_state_changed_cb();
+       (void) bt_socket_unset_data_received_cb();
+       (void) bt_socket_unset_connection_requested_cb();
+}
+
+void
+_BluetoothSppSystemAdapter::InitSingleton(void)
+{
+       bool r = false;
+       static _BluetoothSppSystemAdapter inst;
+
+       r = inst.Construct();
+       SysTryReturnVoidResult(NID_NET_BT, r == true, E_SYSTEM, "[E_SYSTEM] Propagating.");
+
+       __pInstance = &inst;
+}
+
+_BluetoothSppSystemAdapter*
+_BluetoothSppSystemAdapter::GetInstance(void)
+{
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (__pInstance == null)
+       {
+               ClearLastResult();
+               pthread_once(&onceBlock, InitSingleton);
+               result r = GetLastResult();
+               if (IsFailed(r))
+               {
+                       onceBlock = PTHREAD_ONCE_INIT;
+               }
+       }
+
+       return __pInstance;
+}
+
+bool
+_BluetoothSppSystemAdapter::Construct(void)
+{
+       result r = E_SUCCESS;
+       int err = BT_ERROR_NONE;
+       unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > pServerSocketMap;
+       unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > pSocketMap;
+       unique_ptr< Tizen::Base::Collection::HashMapT<Tizen::Base::String, _IBluetoothSocketListener*> > pClientSocketMap;
+
+       pServerSocketMap.reset(new (std::nothrow) HashMapT<int, _IBluetoothSocketListener*>);
+       SysTryReturn(NID_NET_BT, pServerSocketMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       r = pServerSocketMap->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       pSocketMap.reset(new (std::nothrow) HashMapT<int, _IBluetoothSocketListener*>);
+       SysTryReturn(NID_NET_BT, pSocketMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       r = pSocketMap->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       pClientSocketMap.reset(new (std::nothrow) HashMapT<String, _IBluetoothSocketListener*>);
+       SysTryReturn(NID_NET_BT, pClientSocketMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       //construct map with default capacity(16) and loadFactor(0.75f) value.
+       r = pClientSocketMap->Construct(16, 0.75f, _btAddressHashCodeProvider, _btAddressComparer);
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       err = bt_socket_set_connection_state_changed_cb(&OnSocketConnectionStateChanged, null);
+       SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");
+
+       err = bt_socket_set_data_received_cb(&OnSocketDataReceived, null);
+       if (err != BT_ERROR_NONE)
+       {
+               (void) bt_socket_unset_connection_state_changed_cb();
+       }
+       SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");
+
+       err = bt_socket_set_connection_requested_cb(&OnSocketConnectionRequested, null);
+       if (err != BT_ERROR_NONE)
+       {
+               (void) bt_socket_unset_connection_state_changed_cb();
+               (void) bt_socket_unset_data_received_cb();
+       }
+       SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");
+
+       __pServerSocketMap = move(pServerSocketMap);
+       __pSocketMap = move(pSocketMap);
+       __pClientSocketMap = move(pClientSocketMap);
+
+       return true;
+}
+
+result
+_BluetoothSppSystemAdapter::OpenServerSocket(const UuId& serviceUuid, _IBluetoothSocketListener& listener, int& serverSocketFd)
+{
+       int err = BT_ERROR_NONE;
+       result r = E_FAILURE;
+       unique_ptr<char[]> pUuidStr;
+       unique_ptr<int, _SocketFdDeleter> pSocketFd(&serverSocketFd);
+       bool isUsed = false;
+
+       pUuidStr.reset(_StringConverter::CopyToCharArrayN(serviceUuid.ToString()));
+       SysTryReturnResult(NID_NET_BT, pUuidStr != null, E_INVALID_ARG, "The service UUID is invalid.");
+
+       err = bt_adapter_is_service_used(pUuidStr.get(), &isUsed);
+       SysTryReturnResult(NID_NET_BT, (err == BT_ERROR_NONE) && !isUsed, E_SERVICE_UNAVAILABLE,
+                       "Server socket with the specified service UUID is not available.");
+
+       err = bt_socket_create_rfcomm(pUuidStr.get(), &serverSocketFd);
+       SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Creating a server socket has failed.");
+
+       err = bt_socket_listen(serverSocketFd, 1);
+       SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Listen of the server socket has failed.");
+
+       SysLog(NID_NET_BT, "A rfcomm server socket (FD: %d) is created.", serverSocketFd);
+
+       // add the _IBluetoothSocketListener pointer to the server socket map.
+       r = __pServerSocketMap->Add(serverSocketFd, &listener);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "Propagating.");
+
+       pSocketFd.release();
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothSppSystemAdapter::CloseServerSocket(const int serverSocketFd)
+{
+       int err = BT_ERROR_NONE;
+       result r  = E_SUCCESS;
+
+       err = bt_socket_destroy_rfcomm(serverSocketFd);
+       SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Closing the server socket has failed.");
+       SysLog(NID_NET_BT, "The server socket (FD: %d) is closed.", serverSocketFd);
+
+       // remove the _IBluetoothSocketListener pointer related to the specified socket FD from the server socket map.
+       r = __pServerSocketMap->Remove(serverSocketFd);
+       if (r != E_SUCCESS)
+       {
+               SysLog(NID_NET_BT, "But the server socket could not be removed from the server socket map.");
+               // 'r', the error result generated after destroying the socket successfully, is NOT propagated
+       }
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothSppSystemAdapter::AcceptSocketRequest(int serverSocketFd, int& socketFd)
+{
+       int err = BT_ERROR_NONE;
+       result r  = E_SUCCESS;
+       _IBluetoothSocketListener* pListener = null;
+
+       // find the appropriate _IBluetoothSocketListener pointer with the server socket FD.
+       r = __pServerSocketMap->GetValue(serverSocketFd, pListener);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "The server socket number is unknown.");
+
+       err = bt_socket_accept(serverSocketFd, &socketFd);
+       SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Accepting the connection request has failed.");
+
+       SysLog(NID_NET_BT, "The connection request to the server socket (FD: %d) is accepted. (child socket FD: %d)",
+                       serverSocketFd, socketFd);
+
+       // add the _IBluetoothSocketListener pointer to the socket map.
+       // In case for server socket event, _IBluetoothSocketListener pointer is copied from __pServerSocketMap to __pSocketMap
+       r = __pSocketMap->Add(socketFd, pListener);
+       if (r != E_SUCCESS)
+       {
+               (void) bt_socket_disconnect_rfcomm(socketFd);
+       }
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "Propagating.");
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothSppSystemAdapter::RejectSocketRequest(int serverSocketFd)
+{
+       result r = E_FAILURE;
+
+       if (bt_socket_reject(serverSocketFd) ==  BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+
+       SysLog(NID_NET_BT, "Rejecting the connection request to the server socket (FD: %d) ", serverSocketFd,
+                               r == E_SUCCESS ? "is successful." : "has failed.");
+
+       return r;
+}
+
+result
+_BluetoothSppSystemAdapter::ConnectSocket(const ByteBuffer& serverAddress, const UuId& serviceUuid,
+                                                                       _IBluetoothSocketListener& listener)
+{
+       result r = E_SUCCESS;
+       unique_ptr<char[]> pAddressStr;
+       unique_ptr<char[]> pUuidStr;
+       int err = BT_ERROR_NONE;
+       String address;
+       String uuid;
+       String key;
+
+       SysTryReturnResult(NID_NET_BT, serverAddress.GetRemaining() == _BT_ADDRESS_LENGTH, E_INVALID_ARG,
+                                               "The address of the remote device is incorrect.");
+
+       uuid = serviceUuid.ToString();
+       pUuidStr.reset(_StringConverter::CopyToCharArrayN(uuid));
+       SysTryReturnResult(NID_NET_BT, pUuidStr != null, E_INVALID_ARG, "The service UUID is invalid.");
+
+       address = _BluetoothDeviceImpl::GetAddressString(serverAddress);
+       pAddressStr.reset(_StringConverter::CopyToCharArrayN(address));
+       SysTryReturnResult(NID_NET_BT, pAddressStr != null, E_INVALID_ARG, "The service UUID is invalid.");
+
+       err = bt_socket_connect_rfcomm(pAddressStr.get(), pUuidStr.get());
+       SysTryReturnResult(NID_NET_BT, err ==  BT_ERROR_NONE, E_FAILURE, "Connecting to the server has failed.");
+
+       SysLog(NID_NET_BT, "Sending a connection request to [%s] is successful.", pAddressStr.get());
+
+       // add the _IBluetoothSocketListener pointer to the client socket map.
+       key = address + String(L"+") + uuid;
+       r = __pClientSocketMap->Add(key, &listener);
+       if (r != E_SUCCESS)
+       {
+               // TODO: check the feature that cancels the connection request.
+               (void) bt_socket_disconnect_rfcomm(_BT_INVALID_SOCKET_FD);
+       }
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "Propagating.");
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothSppSystemAdapter::DisconnectSocket(int socketFd)
+{
+       result r = E_SUCCESS;
+       int err = BT_ERROR_NONE;
+
+       // TODO: more detailed error resolution is needed
+       err = bt_socket_disconnect_rfcomm(socketFd);
+       SysTryReturnResult(NID_NET_BT, err ==  BT_ERROR_NONE, E_FAILURE, "Disconnecting the rfcomm socket has failed.");
+
+       SysLog(NID_NET_BT, "Disconnecting the rfcomm socket (FD: %d) is successful.", socketFd);
+
+       r = __pSocketMap->Remove(socketFd);
+       if (r != E_SUCCESS)
+       {
+               SysLog(NID_NET_BT, "But, The socket (FD: %d) could not be removed from the socket map.", socketFd);
+               // 'r', the error result generated after destroying the socket successfully, is NOT propagated
+       }
+
+       return E_SUCCESS;
+}
+
+result
+_BluetoothSppSystemAdapter::SendSocketData(int socketFd, const Tizen::Base::ByteBuffer& data)
+{
+       result r = E_SUCCESS;
+       const byte* pSendData = null;
+       int dataLength = 0;
+
+       pSendData = data.GetPointer();
+       pSendData += data.GetPosition();
+       dataLength = data.GetRemaining();
+
+       if (bt_socket_send_data(socketFd, (char*) pSendData, dataLength) == BT_ERROR_NONE)
+       {
+               r = E_SUCCESS;
+       }
+       else
+       {
+               r = E_SYSTEM;
+       }
+
+       SysLog(NID_NET_BT, "Sending data (%d bytes) through the rfcomm socket (FD: %d) %s", dataLength, socketFd,
+                               r == E_SUCCESS ?"is successful." : "has failed.");
+
+       return r;
+}
+
+void
+_BluetoothSppSystemAdapter::OnSocketConnectionRequested(int serverSocketFd, const char* pRemoteAddress, void* pUserData)
+{
+       result r = E_SUCCESS;
+       ByteBuffer deviceAddress;
+       BluetoothDevice requester;
+       String deviceAddressStr(pRemoteAddress);
+       _IBluetoothSocketListener* pListener = null;
+       _BluetoothSppSystemAdapter* pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();
+
+       // find the appropriate _IBluetoothSocketListener pointer with the server socket FD.
+       // the server socket FD is used for distinguishing the recipient from the registered server sockets.
+       r = pSppAdapter->__pServerSocketMap->GetValue(serverSocketFd, pListener);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The socket number is unknown.");
+
+       deviceAddress.Construct(_BT_ADDRESS_LENGTH);
+       (void) _BluetoothDeviceImpl::GetAddressByteBuffer(deviceAddressStr, L":", deviceAddress);
+
+       r = _BluetoothGapSystemAdapter::GetPairedDevice(deviceAddress, requester);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Getting information of the request has failed.");
+
+       pListener->OnSocketConnectionRequested(requester);
+}
+
+void
+_BluetoothSppSystemAdapter::OnSocketConnectionStateChanged(int status, bt_socket_connection_state_e connectionState,
+                                                                                                                       bt_socket_connection_s* pConnectionInfo, void* pUserData)
+{
+       result r = E_SUCCESS;
+       _IBluetoothSocketListener* pListener = null;
+       _BluetoothSppSystemAdapter* pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();
+
+       switch (connectionState)
+       {
+       case BT_SOCKET_CONNECTED:
+               if (pConnectionInfo->local_role == BT_SOCKET_CLIENT)
+               {
+                       SysLog(NID_NET_BT, "Connected event from [address: %s, uuid: %s] is received.",
+                                       pConnectionInfo->remote_address, pConnectionInfo->service_uuid);
+
+                       String address(pConnectionInfo->remote_address);
+                       String uuid(pConnectionInfo->service_uuid);
+                       String key = address + String(L"+") + uuid;
+
+                       // find the appropriate _IBluetoothSocketListener pointer with the server address and the service UUID.
+                       r = pSppAdapter->__pClientSocketMap->GetValue(key, pListener);
+                       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The server address or the service UUID is unknown.");
+
+                       // TODO: more detailed error resolution is needed
+                       if (status == BT_ERROR_NONE)
+                       {
+                               // add the _IBluetoothSocketListener pointer to the socket map.
+                               // In case for client socket event, the _IBluetoothSocketListener ponter is moved
+                               // from __pClientSocketMap to __pSocketMap
+                               r = pSppAdapter->__pSocketMap->Add(pConnectionInfo->socket_fd, pListener);
+                               if (r != E_SUCCESS)
+                               {
+                                       SysLogException(NID_NET_BT, E_SYSTEM, "[%s] Propagating. the socket could not be added to the socket map.",
+                                                       GetErrorMessage(r));
+                                       r = E_SYSTEM;
+                               }
+                       }
+                       else
+                       {
+                               SysLog(NID_NET_BT, "[E_SYSTEM] Connection request failure is reported by the subsystem.");
+                               r = E_SYSTEM;
+                       }
+
+                       pListener->OnSocketConnectionResponded(pConnectionInfo->socket_fd, r);
+
+                       // remove the _IBluetoothSocketListener pointer related to the specified server address and UUID
+                       // from the client socket map.
+                       r = pSppAdapter->__pClientSocketMap->Remove(key);
+                       if (r != E_SUCCESS)
+                       {
+                               SysLog(NID_NET_BT, "But the socket could not be removed from the client socket map.");
+                               // 'r', the error result is ignored.
+                       }
+
+               }
+               // this event is ignored in case of SERVER ROLE.
+
+               break;
+
+       case BT_SOCKET_DISCONNECTED:
+               SysLog(NID_NET_BT, "Disconnected event with [socket fd: %d] is received.", pConnectionInfo->socket_fd);
+
+               // find the appropriate _IBluetoothSocketListener pointer with the socket FD
+               r = pSppAdapter->__pSocketMap->GetValue(pConnectionInfo->socket_fd, pListener);
+               SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The socket number is unknown.");
+
+               // TODO: more detailed error resolution is needed
+               r = ((status == BT_ERROR_NONE) ? E_SUCCESS : E_SYSTEM);
+
+               pListener->OnSocketDisconnected(r);
+
+               // remove the _IBluetoothSocketListener pointer related to the specified socket FD from the socket map.
+               r = pSppAdapter->__pSocketMap->Remove(pConnectionInfo->socket_fd);
+               if (r != E_SUCCESS)
+               {
+                       SysLog(NID_NET_BT, "But the socket (FD: %d) could not be removed from the socket map.",
+                                       pConnectionInfo->socket_fd);
+                       // 'r', the error result is ignored.
+               }
+
+               break;
+
+       default:
+               // ignore other cases
+               SysLog(NID_NET_BT, "The connection state is invalid.");
+               break;
+       }
+}
+
+void
+_BluetoothSppSystemAdapter::OnSocketDataReceived(bt_socket_received_data_s* pData, void* pUserData)
+{
+       result r = E_SUCCESS;
+       ByteBuffer dataBuffer;
+       _IBluetoothSocketListener* pListener = null;
+       _BluetoothSppSystemAdapter* pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();
+
+       SysLog(NID_NET_BT, "Data (%d bytes) through the socket (FD: %d) is received.", pData->data_size, pData->socket_fd);
+
+       // find the appropriate _IBluetoothSocketListener pointer with the socket FD
+       r = pSppAdapter->__pSocketMap->GetValue(pData->socket_fd, pListener);
+       SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The socket number is unknown.");
+
+       // TODO: The deep copy should be modified to a shallow copy for better performance
+       dataBuffer.Construct(pData->data_size);
+       dataBuffer.SetArray((byte*) pData->data, 0, pData->data_size);
+       dataBuffer.SetPosition(0);
+
+       pListener->OnSocketDataReceived(dataBuffer);
+}
+
+} } }  // Tizen::Net::Bluetooth
diff --git a/src/FNetBt_BluetoothSppSystemAdapter.h b/src/FNetBt_BluetoothSppSystemAdapter.h
new file mode 100644 (file)
index 0000000..d741a9c
--- /dev/null
@@ -0,0 +1,203 @@
+//
+// 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    FNetBt_BluetoothSppSystemAdapter.h
+ * @brief   This is the header file for the _BluetoothSppSystemAdapter class.
+ *
+ * This header file contains the declaration of the _BluetoothSppSystemAdapter class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_SYSTEM_ADAPTER_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_SYSTEM_ADAPTER_H_
+
+#include <unique_ptr.h>
+#include <bluetooth.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FNetBtBluetoothTypes.h>
+
+static const int _BT_INVALID_SOCKET_FD = -1;
+
+// forward declarations
+namespace Tizen { namespace Base {
+class ByteBuffer;
+class String;
+class UuId;
+
+namespace Collection {
+class ArrayList;
+template<class keyType, class valueType> class HashMapT;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class _IBluetoothSocketListener;
+
+/**
+ * @class   _BluetoothSppSystemAdapter
+ * @brief   This class provides functions related to RFCOMM socket (SPP) and have a role of adaptation OSP classes and the
+ *          underlying subsystem. This class is a type of singleton, therefore only one instance should be allowed.
+ */
+class _BluetoothSppSystemAdapter
+       : 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 _BluetoothSppSystemAdapter* GetInstance(void);
+
+
+       //-----------------------------------------------------------------------------------------------------------------
+       // Server Socket
+       //-----------------------------------------------------------------------------------------------------------------
+
+       /**
+        * Create and initialize a server socket, and start to listen the socket events. @n
+        * An instance of _IBluetoothSocketListener class is registered internally.
+        *
+        * @return      An error code
+        * @param[in]   serviceUuid             The service UUID
+        * @param[in]   listener                The instance of _IBluetoothSocketListener to be registered
+        * @param[out]  serverSocketFd          The server socket FD
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SERVICE_UNAVAILABLE   The service is not available.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result OpenServerSocket(const Tizen::Base::UuId& serviceUuid, _IBluetoothSocketListener& listener, int& serverSocketFd);
+
+       /**
+        * Close the specified server socket. @n
+        * All child sockets involved in this server socket will be automatically disconnected.
+        *
+        * @return      An error code
+        * @param[in]   serverSocketFd          The server socket FD
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result CloseServerSocket(int serverSocketFd);
+
+       /**
+        * Accept the connection request received to the specified server socket. @n
+        * A new child socket is created if the accept is successful.
+        *
+        * @return      An error code
+        * @param[in]   serverSocketFd          The server socket FD
+        * @param[out]  socketFd                The child socket FD for the connection
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result AcceptSocketRequest(int serverSocketFd, int& socketFd);
+
+       /**
+        * Reject the connection request received to the specified server socket.
+        *
+        * @return      An error code
+        * @param[in]   serverSocketFd          The server socket FD
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result RejectSocketRequest(int serverSocketFd);
+
+
+       //-----------------------------------------------------------------------------------------------------------------
+       // socket
+       //-----------------------------------------------------------------------------------------------------------------
+
+       /**
+        * Connect with the specified server. @n
+        * A new socket FD can be acquired on
+        * OnSocketConnected() callback method invoked when the connection is completely established.
+        *
+        * @return      An error code
+        * @param[in]   serverAddress           The address of the server
+        * @param[in]   serviceUuid             The service UUID
+        * @param[in]   listener                The socket event listener
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result ConnectSocket(const Tizen::Base::ByteBuffer& serverAddress, const Tizen::Base::UuId& serviceUuid,
+                       _IBluetoothSocketListener& listener);
+
+       /**
+        * Close the connection related to the specified socket. @n
+        *
+        * @return      An error code
+        * @param[in]   socketFd                The socket FD
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result DisconnectSocket(int socketFd);
+
+       /**
+        * Send data through the connection related to the specified socket. @n
+        *
+        * @return      An error code
+        * @param[in]   socketFd                The socket FD
+        * @param[in]   data                    The data to be sent
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result SendSocketData(int socketFd, const Tizen::Base::ByteBuffer& data);
+
+
+       //-----------------------------------------------------------------------------------------------------------------
+       // Callback methods
+       //-----------------------------------------------------------------------------------------------------------------
+
+       /**
+        * Callback called by the underlying system to notify that the RFCOMM server socket is received the connection request.
+        */
+       static void OnSocketConnectionRequested(int serverSocketFd, const char* pRemoteAddress, void* pUserData);
+
+       /**
+        * Callback called by the underlying system to notify that the connection state has changed to connected or disconnected.
+        */
+       static void OnSocketConnectionStateChanged(int status, bt_socket_connection_state_e connectionState,
+                       bt_socket_connection_s* pConnectionInfo, void* pUserData);
+
+       /**
+        * Callback used by the underlying system to notify that data is received on the established connection.
+        */
+       static void OnSocketDataReceived(bt_socket_received_data_s* pData, void* pUserData);
+
+private:
+       _BluetoothSppSystemAdapter(void);
+       ~_BluetoothSppSystemAdapter(void);
+
+       _BluetoothSppSystemAdapter(const _BluetoothSppSystemAdapter& value);
+       _BluetoothSppSystemAdapter& operator =(const _BluetoothSppSystemAdapter& value);
+
+       bool Construct(void);
+
+       static void InitSingleton(void);
+
+private:
+       std::unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > __pServerSocketMap;
+       std::unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > __pSocketMap;
+       std::unique_ptr< Tizen::Base::Collection::HashMapT<Tizen::Base::String, _IBluetoothSocketListener*> > __pClientSocketMap;
+       static _BluetoothSppSystemAdapter* __pInstance;
+}; // _BluetoothSppSystemAdapter
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_SYSTEM_ADAPTER_H_
diff --git a/src/inc/FNetBt_BluetoothAdapterUtility.h b/src/inc/FNetBt_BluetoothAdapterUtility.h
new file mode 100644 (file)
index 0000000..6bc47de
--- /dev/null
@@ -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    FNetBt_BluetoothAdapterUtility.h
+ * @brief   This is the header file for the _BluetoothAdapterUtility class.
+ *
+ * This header file contains the declaration of the _BluetoothAdapterUtility class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_ADAPTER_UTILITY_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_ADAPTER_UTILITY_H_
+
+#include <bluetooth.h>
+#include <FBaseResult.h>
+#include <FNetBtBluetoothTypes.h>
+
+// forward declarations
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+
+namespace Collection
+{
+class IList;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+
+/**
+ * @class   _BluetoothAdapterUtility
+ * @brief   This class provides utilitiy functions such as converting data structure to other data class, and printing data class.
+ */
+class _OSP_EXPORT_ _BluetoothAdapterUtility
+{
+public:
+       static BluetoothMajorDeviceClassType ConvertToMajorDeviceClassType(bt_major_device_class_e majorClass);
+       static BluetoothMinorDeviceClassType ConvertToMinorDeviceClassType(bt_major_device_class_e majorClass, bt_minor_device_class_e minorClass);
+       static unsigned long ConvertToServiceClassList(int serviceClass);
+       static unsigned long ConvertToServiceList(char** pServiceUuid, int& serviceUuidCount);
+       static Tizen::Base::Collection::IList* ConvertServiceUuidListN(char** pServiceUuid, int& serviceUuidCount);
+       static void PrintDeviceInfo(const BluetoothDevice& device);
+       static void PrintServiceList(unsigned long type);
+       static void PrintServiceUuidList(const Tizen::Base::Collection::IList* pList);
+
+private:
+       _BluetoothAdapterUtility(void);
+       ~_BluetoothAdapterUtility(void);
+
+       _BluetoothAdapterUtility(const _BluetoothAdapterUtility& value);
+       _BluetoothAdapterUtility& operator =(const _BluetoothAdapterUtility& value);
+
+}; // _BluetoothAdapterUtility
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_ADAPTER_UTILITY_H_
diff --git a/src/inc/FNetBt_BluetoothDeviceImpl.h b/src/inc/FNetBt_BluetoothDeviceImpl.h
new file mode 100755 (executable)
index 0000000..bc3c9cd
--- /dev/null
@@ -0,0 +1,318 @@
+//
+// 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    FNetBt_BluetoothDeviceImpl.h
+ * @brief   This is the header file for the _BluetoothDeviceImpl Class.
+ *
+ * This header file contains the declarations of the _BluetoothDeviceImpl Class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_IMPL_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FNetBtBluetoothTypes.h>
+#include <FBaseResult.h>
+#include <FBaseObject.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseString.h>
+
+// forward declarations
+namespace Tizen { namespace Base { namespace Collection
+{
+class IList;
+} } }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+
+/**
+  *  @class   _BluetoothDeviceImpl
+  * @brief   This class provides extended methods for BluetoothDevice class.
+  *
+  * The detailed description will be located here (TBD)
+  */
+class _OSP_EXPORT_ _BluetoothDeviceImpl
+       : public Tizen::Base::Object
+{
+public:
+       /**
+        * This is the default constructor for this class.
+        */
+       _BluetoothDeviceImpl(void);
+
+       /**
+        * Initializes this instance of BluetoothDevice with the specified parameters.
+        *
+        * @deprecated  This constructor is deprecated because most of the information is generated internally.
+        *              Therefore, creating a %BluetoothDevice instance directly by the application is not recommended.
+        *              Instead of using this method for copying an instance, the copy constructor is recommended.
+        *
+        * @param[in]   address                 The %Bluetooth device address
+        * @param[in]   deviceName              The name of the device
+        * @param[in]   majorClassType          The major class type of a %Bluetooth device
+        * @param[in]   minorClassType          The minor class type of a %Bluetooth device
+        * @param[in]   serviceClassList        The service class type list
+        * @param[in]   serviceList             The service type list
+        * @remarks     The @c serviceClassList parameter consists of Tizen::Net::Bluetooth::BluetoothServiceClassType values
+        *              which are joined by the logical OR operator. @n
+        *              The @c serviceList parameter consists of Tizen::Net::Bluetooth::BluetoothServiceType values which are
+        *              joined by the logical OR operator.
+        */
+       _BluetoothDeviceImpl(const Tizen::Base::ByteBuffer& address, const Tizen::Base::String& deviceName, BluetoothMajorDeviceClassType majorClassType, BluetoothMinorDeviceClassType minorClassType, unsigned long serviceClassList, unsigned long serviceList);
+
+       /**
+        * This is the copy constructor for the %_BluetoothDeviceImpl class. @n
+        *
+        * @param[in]   value                   An instance of %_BluetoothDeviceImpl
+        */
+       _BluetoothDeviceImpl(const _BluetoothDeviceImpl& value);
+
+       /**
+        * This is the destructor for this class.
+        */
+       ~_BluetoothDeviceImpl(void);
+
+       /**
+        * Gets the %Bluetooth device's address.
+        *
+        * @return      The address of the %Bluetooth device
+        */
+       const Tizen::Base::ByteBuffer* GetAddress(void) const;
+
+       /**
+        * Gets the %Bluetooth device name.
+        *
+        * @return      The %Bluetooth device name
+        */
+       Tizen::Base::String GetName(void) const;
+
+       /**
+        * Checks whether this device is paired with the local device.
+        *
+        * @return      @c true if this device is paired with the local device, @n
+        *              else @c false
+        */
+       bool IsPaired(void) const;
+
+       /**
+        * Gets the Received Signal Strength Indication (RSSI) value of the device at the time of device discovery (scan).
+        *
+        * @return      The RSSI value in dbm
+        */
+       int GetRssi(void) const;
+
+       /**
+        * Gets the major device class.
+        *
+        * @return      The major device class
+        */
+       BluetoothMajorDeviceClassType GetMajorDeviceClassType(void) const;
+
+       /*
+        * Gets the minor device class.
+        *
+        * @return      The minor device class
+        */
+       BluetoothMinorDeviceClassType GetMinorDeviceClassType(void) const;
+
+       /**
+        * Gets the service class of the %Bluetooth device. @n
+        * This service class list consists of Tizen::Net::Bluetooth::BluetoothServiceClassType values which are joined by
+        * the logical OR operator.
+        *
+        * @return      The service class of the device
+        * @remarks     This operation is not supported in the local device acquired by BluetoothManager::GetLocalDevice().
+        */
+       unsigned long GetServiceClassList(void) const;
+
+       /**
+        * Gets the %Bluetooth device service list. @n
+        * This service list consists of Tizen::Net::Bluetooth::BluetoothServiceType values which are joined by the logical
+        * OR operator.
+        *
+        * @return      The %Bluetooth device serviceList
+        * @remarks     This operation is not supported in the local device acquired by BluetoothManager::GetLocalDevice().
+        */
+       unsigned long GetServiceList(void) const;
+
+       /**
+        * Gets the %Bluetooth device service UUID list. @n
+        * This service list consists of Tizen::Base::UuId instances, which represents service UUIDs the device supports.
+        *
+        * @return      The %Bluetooth device service UUID list
+        * @remarks     This operation returns @c null, if it is called in the local device acquired by
+        *              BluetoothManager::GetLocalDevice().
+        */
+       const Tizen::Base::Collection::IList* GetServiceUuidList(void) const;
+
+       /**
+        * Compares the calling instance with the specified instance.
+        *
+        * @return      @c true, if both the instances are equal @n
+        *              @c false, otherwise
+        * @param[in]   obj                     The object to compare
+        */
+       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
+        * @remarks     Two equal instances return the same hash value.
+        */
+       virtual int GetHashCode(void) const;
+
+       /**
+        * Sets the address of the %Bluetooth device.
+        *
+        * @return      An error code
+        * @param[in]   address                 The Bluetooth device address
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_ARG           The argument is invalid.
+        */
+       result SetAddress(const Tizen::Base::ByteBuffer& address);
+
+       /**
+        * Sets the name of the %Bluetooth device.
+        *
+        * @param[in]   name                    The Bluetooth device address
+        */
+       void SetName(const Tizen::Base::String& name);
+
+       /**
+        * Sets the major device class.
+        *
+        * @param[in]   type                    The major device class
+        */
+       void SetMajorDeviceClassType(BluetoothMajorDeviceClassType type);
+
+       /**
+        * Sets the minor device class.
+        *
+        * @param[in]   type                    The minor device class
+        */
+       void SetMinorDeviceClassType(BluetoothMinorDeviceClassType type);
+
+       /**
+        * Sets the service class of the %Bluetooth device. @n
+        * This service class list should consist of Tizen::Net::Bluetooth::BluetoothServiceClassType values which are joined by
+        * the logical OR operator.
+        *
+        * @param[in]   listValue               The service class of the device
+        */
+       void SetServiceClassList(unsigned long listValue);
+
+       /**
+        * Sets the service list value of the %Bluetooth device.
+        *
+        * @param[in]   serviceList             The service type list
+        */
+       void SetServiceList(unsigned long serviceList);
+
+       /**
+        * Sets the service UUID list of the %Bluetooth device.
+        *
+        * @param[in]   pSrcUuidList            The service UUID list
+        * @param[in]   isDeepCopy              Set to @c true if the UUID list should be copied deeply @n
+        *                                      else @c false
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         Insufficient memory.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       result SetServiceUuidList(const Tizen::Base::Collection::IList* pSrcUuidList, bool isDeepCopy);
+
+       /**
+        * Sets the service list value of the %Bluetooth device.
+        *
+        * @param[in]   isPaired                The service type list
+        */
+       void SetPaired(bool isPaired);
+
+       /**
+        * Sets the service list value of the %Bluetooth device.
+        *
+        * @param[in]   rssi                    The service type list
+        */
+       void SetRssi(int rssi);
+
+       /**
+        * Transforms the %Bluetooth address from the string type to the byte type.
+        *
+        * @return      An error code
+        * @param[in]   srcAddr                 The original %Bluetooth address to be converted
+        * @param[in]   delimiters              The delimiters
+        * @param[out]  dstAddr                 The converted %Bluetooth address as the byte type
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       static result GetAddressByteBuffer(const Tizen::Base::String& srcAddr, const Tizen::Base::String& delimiters, Tizen::Base::ByteBuffer& dstAddr);
+
+       /**
+        * Transforms the %Bluetooth address from the byte type to the string type.
+        *
+        * @return      The converted address string
+        * @param[in]   address                 The original %Bluetooth address to be converted as the byte type
+        */
+       static Tizen::Base::String GetAddressString(const Tizen::Base::ByteBuffer& address);
+
+       /**
+        * This assignment operator copies the information from the specified instance of %_BluetoothDeviceImpl to the
+        * calling instance of %_BluetoothDeviceImpl.
+        *
+        * @return      A reference to the %_BluetoothDeviceImpl instance
+        * @param[in]   rhs                     A reference to the %_BluetoothDeviceImpl instance to copy
+        */
+       _BluetoothDeviceImpl& operator =(const _BluetoothDeviceImpl& rhs);
+
+public:
+   /**
+        * Gets the Impl instance.
+        *
+        * @return      The pointer to _BluetoothDeviceImpl
+        * @param[in]   pBluetoothDevice            An instance of BluetoothDevice
+        */
+       static _BluetoothDeviceImpl* GetInstance(BluetoothDevice& bluetoothDevice);
+
+       /**
+        * Gets the Impl instance.
+        *
+        * @return      The pointer to  _BluetoothDeviceImpl
+        * @param[in]   pBluetoothDevice     An instance of BluetoothDevice
+        */
+       static const _BluetoothDeviceImpl* GetInstance(const BluetoothDevice& bluetoothDevice);
+
+private:
+       Tizen::Base::ByteBuffer __deviceAddress;
+       Tizen::Base::String __deviceName;
+       bool __isPaired;
+       int __rssi;
+       BluetoothMajorDeviceClassType __majorClassType;
+       BluetoothMinorDeviceClassType __minorClassType;
+       unsigned long __serviceClassList;
+       unsigned long __serviceList;
+       std::unique_ptr<Tizen::Base::Collection::IList, Tizen::Base::Collection::AllElementsDeleter> __pServiceUuidList;
+
+       static const int BT_ADDRESS_LENGTH = 6;
+
+}; // _BluetoothDeviceImpl
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_DEVICE_IMPL_H_
diff --git a/src/inc/FNetBt_BluetoothHealthImpl.h b/src/inc/FNetBt_BluetoothHealthImpl.h
new file mode 100644 (file)
index 0000000..7575721
--- /dev/null
@@ -0,0 +1,218 @@
+//
+// 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    FNetBt_BluetoothHealthImpl.h
+ * @brief   This is the header file for the _BluetoothHealthImpl class.
+ *
+ * This header file contains the declaration of the _BluetoothHealthImpl class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_IMPL_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseRtMutex.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseColLinkedListT.h>
+#include "FNetBt_IBluetoothManagerEventListener.h"
+#include "FNetBt_IBluetoothDeviceEventListener.h"
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+struct _CharDeleter
+{
+       void operator()(char* pChar)
+       {
+               free(pChar);
+       }
+};
+
+// Forward declarations
+class BluetoothDevice;
+class IBluetoothHealthEventListener;
+class _BluetoothGapSystemAdapter;
+class _BluetoothHdpSystemAdapter;
+class _BluetoothHealthEvent;
+
+/**
+  * @class   _BluetoothHealthImpl
+  * @brief   TBD
+  */
+class _OSP_EXPORT_ _BluetoothHealthImpl
+       : public Tizen::Base::Object
+       , public _IBluetoothManagerEventListener
+       , public _IBluetoothDeviceEventListener
+{
+/**
+ * @enum    _BluetoothHealthStateType
+ * Defines the states of the Bluetooth Health service.
+ */
+       enum _BluetoothHealthStateType
+       {
+               _BT_HEALTH_STATE_DISABLED,
+               _BT_HEALTH_STATE_IDLE,
+               _BT_HEALTH_STATE_ON_SERVICE,
+               _BT_HEALTH_STATE_BONDING,
+               _BT_HEALTH_STATE_BOND_CANCELING
+       } ;
+
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks     After creating an instance of this class, you must explicitly call
+        *              construction method to initialize the instance.
+        * @see         Construct()
+        */
+       _BluetoothHealthImpl(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       ~_BluetoothHealthImpl(void);
+
+       /**
+        * Constructs a BluetoothHealth and attaches a listener to it.
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for the %BluetoothHealth
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result Construct(IBluetoothHealthEventListener& listener);
+
+       /**
+        * Starts %Bluetooth health as a role of sink with the specified data type.
+        *
+        * @return      An error code
+        * @param[in]   dataType                The type of data used in communication which is defined in ISO/IEEE
+        *                                      11073-20601 and represents type of health device such as thermometer,
+        *                                      heart rate monitor, weight scale, and so on
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_IN_PROGRESS           The sink role with the specified data type has already started.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the sink role already started with another data type.
+        * @exception   E_SERVICE_UNAVAILABLE   The sink role with the specified data type is unavailable now because it
+        *                                      has started by other instance or application.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result StartAsSink(int dataType);
+
+       /**
+        * Stops %Bluetooth health as a role of sink. @n
+        * This method disconnects all established channels before stop.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the sink role is not started yet.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result Stop(void);
+
+       /**
+        * Sets up a new connection (channel) with a remote health device which has source role. @n
+        * This method establishes a channel after the source device accepts the request.
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice            The remote device to be connected with
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the sink role is not started yet.
+        * @exception   E_DEVICE_BUSY           The pairing and connection process is in progress.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result ConnectToSource(const BluetoothDevice& remoteDevice);
+
+       /**
+        * Disconnects the connection which has the specified channel ID. @n
+        *
+        * @return      An error code
+        * @param[in]   channelId               The ID of the specified channel to be disconnected
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, there is no connection with the specified channel ID.
+        * @exception   E_OPERATION_FAILED      The method has failed.
+        */
+       result Disconnect(int channelId);
+
+       /**
+        * Sends the specified data on the specified channel.
+        *
+        * @return      An error code
+        * @param[in]   channelId               The ID of the specified channel to send data on
+        * @param[in]   buffer                  The data to be sent
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, there is no connection with the specified channel ID.
+        * @exception   E_INVALID_ARG           The input buffer has no data.
+        * @exception   E_OPERATION_FAILED      The operation has failed.
+        */
+       result SendData(int channelId, const Tizen::Base::ByteBuffer& buffer);
+
+       virtual void OnBluetoothActivated(result r);
+       virtual void OnBluetoothDeactivated(result r);
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode) {}
+       virtual void OnBluetoothDiscoveryStarted(result r) {}
+       virtual void OnBluetoothRemoteDeviceFound(const BluetoothDevice& foundDevice) {}
+       virtual void OnBluetoothDiscoveryDone(bool isCompleted) {}
+       virtual void OnBluetoothServiceListReceived(const Tizen::Base::ByteBuffer& address, unsigned long serviceList,
+                                                                                               const Tizen::Base::Collection::IList* pServiceUuidList, result r) {};
+       virtual void OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r);
+       virtual void OnBluetoothUnpaired(const Tizen::Base::ByteBuffer& address) {}
+       virtual void OnBluetoothDeviceConnected(const Tizen::Base::ByteBuffer& address) {}
+       virtual void OnBluetoothDeviceDisconnected(const Tizen::Base::ByteBuffer& address) {}
+       void OnBluetoothHealthConnected(int channelId, BluetoothHealthDataChannelType channelType,
+                       const BluetoothDevice* pRemoteDevice, result r);
+       void OnBluetoothHealthDisconnected(int channelId, result r);
+       void OnBluetoothHealthDataReceived(int channelId, Tizen::Base::ByteBuffer& buffer);
+
+private:
+       _BluetoothHealthImpl(const _BluetoothHealthImpl& value);
+       _BluetoothHealthImpl& operator =(const _BluetoothHealthImpl& value);
+
+       const char* GetStringOfCurrentState(void) const;
+
+private:
+       _BluetoothGapSystemAdapter* __pGapAdapter;
+       _BluetoothHdpSystemAdapter* __pHdpAdapter;
+       std::unique_ptr<_BluetoothHealthEvent> __pEvent;
+       Tizen::Base::Runtime::Mutex __stateMutex;
+       _BluetoothHealthStateType __currentState;
+       Tizen::Base::Collection::LinkedListT<int> __channelIdList;
+       Tizen::Base::ByteBuffer __pairingTargetAddress;
+       std::unique_ptr<char, _CharDeleter> __pAppId;
+       int __dataType;
+
+       static const int _BT_INVALID_DATA_TYPE = 0;
+
+}; // _BluetoothHealthImpl
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_HEALTH_IMPL_H_
diff --git a/src/inc/FNetBt_BluetoothManagerImpl.h b/src/inc/FNetBt_BluetoothManagerImpl.h
new file mode 100755 (executable)
index 0000000..89d57d1
--- /dev/null
@@ -0,0 +1,529 @@
+//
+// 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    FNetBt_BluetoothManagerImpl.h
+ * @brief   This is the header file for the _BluetoothManagerImpl class.
+ *
+ * This header file contains the declaration of the _BluetoothManagerImpl class.
+ */
+
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_IMPL_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseColArrayList.h>
+#include <FBaseColHashMap.h>
+#include <FBaseColLinkedList.h>
+#include <FBaseRtMutex.h>
+#include "FNetBt_IBluetoothManagerEventListener.h"
+#include "FNetBt_IBluetoothDeviceEventListener.h"
+#include "FNetBt_IBluetoothConnectionEventListener.h"
+
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// Forward declaration
+class BluetoothDevice;
+class IBluetoothManagerEventListener;
+class IBluetoothDeviceEventListener;
+class _BluetoothManagerEvent;
+class _BluetoothDeviceEvent;
+class _BluetoothConnectionEvent;
+class _BluetoothIpcProxy;
+class _BluetoothGapSystemAdapter;
+
+/**
+  * @class   BluetoothManager
+  * @brief   This class is used to get information about devices and discover objects, as well as to configure the
+  *          Bluetooth stack.
+  */
+class _OSP_EXPORT_ _BluetoothManagerImpl
+       : public Tizen::Base::Object
+       , public _IBluetoothManagerEventListener
+       , public _IBluetoothDeviceEventListener
+       , public _IBluetoothConnectionEventListener
+{
+       /**
+        * @enum    _BluetoothManagerStateType
+        * Defines the states of the Bluetooth Manager.
+        */
+       enum _BluetoothManagerStateType
+       {
+               _BT_MGR_STATE_DEACTIVATED,
+               _BT_MGR_STATE_ACTIVATING,
+               _BT_MGR_STATE_DEACTIVATING,
+               _BT_MGR_STATE_ACTIVATED,
+               _BT_MGR_STATE_DISCOVERY_REQUESTED,
+               _BT_MGR_STATE_ON_DISCOVERY,
+               _BT_MGR_STATE_DISCOVERY_CANCELING,
+               _BT_MGR_STATE_ON_DISCOVERY_BY_SYSTEM,
+               _BT_MGR_STATE_SERVICE_RETRIEVING
+       };
+
+       /**
+        * @enum    _BluetoothPairingStateType
+        * Defines the states which is related to pairing.
+        */
+       enum _BluetoothPairingStateType
+       {
+               _BT_PAIRING_STATE_NONE,
+               _BT_PAIRING_STATE_PAIRING,
+               _BT_PAIRING_STATE_CANCELING
+       };
+
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks     After creating an instance of this class, you must explicitly call
+        *              the Construct() method to initialize the instance.
+        * @see Construct()
+        */
+       _BluetoothManagerImpl(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       ~_BluetoothManagerImpl(void);
+
+       /**
+        * Initializes a BluetoothManager instance.
+        *
+        * @return      An error code
+        * @param[in]   listener                    The listener to handle %Bluetooth manager event
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OUT_OF_MEMORY             Insufficient memory.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result Construct(IBluetoothManagerEventListener& listener);
+
+       /**
+        * Activates %Bluetooth on the device.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The %Bluetooth 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 %Bluetooth is already activated.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result Activate(void);
+
+       /**
+        * Deactivates Bluetooth.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The %Bluetooth 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 %Bluetooth is already deactivated.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result Deactivate(void);
+
+       /**
+        * Checks whether the Bluetooth-specific profile is available.
+        *
+        * @deprecated  This method is deprecated because multiple clients as well as multiple SPP servers with unique
+        *              service UUIDs are supported. Instead of using this method for OPP server,
+        *              BluetoothOppServer::StartService() without checking the OPP server connection's availability is
+        *              recommended. If a new OPP server is not available, the method returns the E_SERVICE_UNAVAILABLE
+        *              exception.
+        *
+        * @return      @c true if connection is available @n
+        *              @c false, otherwise
+        * @param[in]   type                        The connection type
+        *
+        */
+       bool IsAvailable(BluetoothConnectionType type) const;
+
+       /**
+        * Gets the local device information.
+        *
+        * @deprecated  This method is deprecated because the return value of this method is a dangling pointer if this
+        *              instance of BluetoothManagerInpl is deleted. Instead of using this method, GetLocalDeviceAddress() and
+        *              GetLocalDeviceName() are recommended.
+        *
+        * @return      The local device information as a BluetoothDevice instance
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OUT_OF_MEMORY             Insufficient memory.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       const BluetoothDevice* GetLocalDevice(void);
+
+       /**
+        * Gets the local %Bluetooth device address.
+        *
+        * @return      The local %Bluetooth device address
+        * @remarks     The address is expressed as a 6 byte hexadecimal value delimited by colon. @n
+        *              For example, "00:3D:47:EF:8A:03".
+        */
+       Tizen::Base::String GetLocalDeviceAddress(void) const;
+
+       /**
+        * Gets the local %Bluetooth device name.
+        *
+        * @return      The local %Bluetooth device name
+        */
+       Tizen::Base::String GetLocalDeviceName(void) const;
+
+       /**
+        * Gets the operational mode of the %Bluetooth unit.
+        *
+        * @deprecated  BluetoothDeviceStateType is deprecated. Therefore, this method is also deprecated, because the
+        *              return value of this method is of type BluetoothDeviceStateType. Instead of using this method,
+        *              IsActivated() and GetDiscoverableMode() are recommended.
+        *
+        * @return      The operational mode
+        */
+       BluetoothDeviceStateType GetLocalDeviceState(void) const;
+
+       /**
+        * Checks whether the local %Bluetooth is activated.
+        *
+        * @deprecated  This method is deprecated because multiple clients as well as multiple SPP servers with unique
+        *              service UUIDs are supported. Instead of using this method,
+        *              BluetoothOppServer::StartService() without checking the OPP server connection's availability is
+        *              recommended. If a new OPP server is not available, the method returns the E_SERVICE_UNAVAILABLE
+        *              exception.
+        *
+        * @return      @c true, if the local %Bluetooth is activated @n
+        *              @c false, otherwise
+        */
+       bool IsActivated(void) const;
+
+       /**
+        * Gets the discoverable mode of the local device.
+        *
+        * @return      The discoverable mode of the local device
+        */
+       BluetoothDiscoverableMode GetDiscoverableMode(void) const;
+
+       /**
+        * Gets the remaining time, in seconds, until the discoverable mode is changed from
+        * BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE to be BT_DISC_MODE_NOT_DISCOVERABLE. @n
+        * This method is valid only if the current discoverable mode is BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        *
+        * @return      The remaining time, in seconds, until the local device to be not discoverable.
+        * @remarks     0 will be returned if the current discoverable mode is not BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        */
+       int GetRemainingTimeAsDiscoverable(void) const;
+
+       /**
+        * Checks whether the device discovery is in progress.
+        *
+        * @return      @c true, if the device discovery is in progress @n
+        *              @c false, otherwise
+        */
+       bool IsDiscoveryInProgress(void) const;
+
+       /**
+        * Sets the name of local device.
+        *
+        * @return      An error code
+        * @param[in]   deviceName                  The new device name
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_ARG               The specified device name is an empty string.
+        * @exception   E_SYSTEM                    A system error occurred.
+        * @remarks     This method does not affect system settings. The device name is only valid while an application is
+        *              active. The searching device detects the local devices in close proximity based on the specified
+        *              device name. @n
+        *              The specified device name is automatically truncated if its size is greater than 64 bytes.
+        */
+       result SetLocalDeviceName(const Tizen::Base::String& deviceName);
+
+       /**
+        * Sets the discoverable mode of the local device.
+        *
+        * @visibility  partner-manufacturer
+        * @privlevel   system
+        * @privilege   http://tizen.org/privilege/bluetoothmanager
+        *
+        * @return      An error code
+        * @param[in]   mode                        The new discoverable mode
+        * @param[in]   seconds                     The duration in seconds for which the local device is discoverable
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_ARG               The specified @c seconds should be greater than 0 if the specified
+        *                                          @c mode is BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        * @exception   E_INVALID_OPERATION         %Bluetooth is not 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         IBluetoothManagerEventListener::OnBluetoothDiscoverableModeChanged()
+        * @remarks     @c seconds is adopted only if the specified @c mode is BT_DISC_MODE_TIME_LIMITED_DISCOVERABLE.
+        */
+       result SetDiscoverableMode(BluetoothDiscoverableMode mode, int seconds = 0);
+
+       /**
+        * Refreshes the paired device list.
+        *
+        * @deprecated  This method is deprecated because the paired device list is refreshed automatically.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OUT_OF_MEMORY             Insufficient memory.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result RefreshPairedDeviceList(void);
+
+       /**
+        * Searches for an element that matches a %Bluetooth address.
+        *
+        * @deprecated  This API is deprecated because the return value of this API is a dangling pointer.
+        *              Instead of using this API, it recommended to use GetPairedDeviceByAddressN().
+        *
+        * @return      The BluetoothDevice containing the specified address if successful @n
+        *              @c null, otherwise
+        * @param[in]   deviceAddress               The address to locate
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified device was not found in the paired device list.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       const BluetoothDevice* GetPairedDeviceByAddress(const Tizen::Base::ByteBuffer& deviceAddress) const;
+
+       /**
+        * Searches for an element that matches a %Bluetooth address.
+        *
+        * @return      The BluetoothDevice containing the specified address if successful @n
+        *              @c null, otherwise
+        * @param[in]   deviceAddress               The address to locate
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified device was not found in the paired device list.
+        * @exception   E_OUT_OF_MEMORY             Insufficient memory.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       BluetoothDevice* GetPairedDeviceByAddressN(const Tizen::Base::ByteBuffer& deviceAddress) const;
+
+       /**
+        * Searches for elements matching a device name in the paired devices list.
+        *
+        * @return      A list containing the matching device if successful @n
+        *              @c null, otherwise
+        * @param[in]   deviceName                  The name of the device to locate
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified device was not found in the paired device list.
+        * @exception   E_OUT_OF_MEMORY             Insufficient memory.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       Tizen::Base::Collection::IList* GetPairedDeviceByNameN(const Tizen::Base::String& deviceName) const;
+
+       /**
+        * Gets the element at the specified index.
+        *
+        * @deprecated  This API is deprecated because the return value of this API is a dangling pointer.
+        *              Instead of using this API, it recommended to use GetPairedDeviceListN() and
+        *              Tizen::Base::Collection::IList operations.
+        *
+        * @return      The BluetoothDevice at the given index, if successful @n
+        *              @c null, otherwise
+        * @param[in]   index                       The index in the list
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OBJ_NOT_FOUND             The specified index was not found in the PairedDevice list.
+        */
+       const BluetoothDevice* GetPairedDeviceAt(int index) const;
+
+       /**
+        * Gets the paired device list.
+        *
+        * @deprecated  This API is deprecated because the return value of this API is a dangling pointer.
+        *              Instead of using this API, it recommended to use GetPairedDeviceListN().
+        *
+        * @return      Pointer to the paired device list on success @n
+        *              @c null, otherwise
+        */
+       const Tizen::Base::Collection::IList* GetPairedDeviceList(void) const;
+
+       /**
+        * Gets the paired device list.
+        *
+        * @return      A pointer to the paired device list on success @n
+        *              @c null, otherwise
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_OUT_OF_MEMORY             Insufficient memory.
+        * @remarks     The specific error code can be accessed using the GetLastResult() method.
+        */
+       Tizen::Base::Collection::IList* GetPairedDeviceListN(void) const;
+
+       /**
+        * Sets a Device event listener for searching devices and services.
+        *
+        * @return      An error code
+        * @param[in]   pListener                   The Device event listener to be added
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result SetBluetoothDeviceListener(IBluetoothDeviceEventListener* pListener);
+
+       /**
+        * Sets a Connection event listener.
+        *
+        * @return      An error code
+        * @param[in]   pListener                   The Connection event listener to be added
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result SetBluetoothConnectionListener(_IBluetoothConnectionEventListener* pListener);
+
+       /**
+        * Starts a device discovery process.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The discovery process is in progress.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this operation.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result StartDiscovery(void);
+
+       /**
+        * Stops the device discovery process.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The canceling is in progress.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this operation. E.g. Discovery is not started.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result CancelDiscovery(void);
+
+       /**
+        * Retrieves the service list from a remote device.
+        *
+        * @return      An error code
+        * @param[in]   pairedDevice                A remote device which is already paired with this local device
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_IN_PROGRESS               The retrieving is in progress.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the discovery is in progress.
+        * @exception   E_NOT_PAIRED                The input device is not found in the paired device list.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       result RetrieveServiceList(const BluetoothDevice& pairedDevice);
+
+       /**
+        * Pairs with the specified remote device.
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice                The remote %Bluetooth device to be paired with
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the %Bluetooth is not activated.
+        * @exception   E_DEVICE_BUSY               The device cannot be approached because other operation is in progress.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        */
+       result Pair(const BluetoothDevice& remoteDevice);
+
+       /**
+        * Stops the pairing process.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the pairing process is not in progress.
+        * @exception   E_IN_PROGRESS               The termination of the pairing process is in progress.
+        * @exception   E_SYSTEM                    A system error has occurred.
+        */
+       result CancelPair(void);
+
+       /**
+        * Unpairs the paired devices.
+        *
+        * @return      An error code
+        * @param[in]   pairedDevice                The paired device to unpair
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_INVALID_OPERATION         The current state of the instance prohibits the execution of this
+        *                                          operation. @n
+        *                                          For example, the %Bluetooth is not activated or retrieving the service
+        *                                          list is in progress.
+        * @exception   E_NOT_PAIRED                The input device is not found in the paired device list.
+        * @exception   E_SYSTEM                    A system error occurred.
+        * @remarks     The process of unpairing is to remove the specified device from the paired device list. No
+        *              notification is transmitted to the remote device. @n
+        *              This method is synchronous. When the result of this method is E_SUCCESS, the unpaired event is
+        *              fired. @n
+        */
+       result Unpair(const BluetoothDevice& pairedDevice);
+
+
+       // Callback functions which called by _BluetoothSystemAdapter
+       virtual void OnBluetoothActivated(result r);
+       virtual void OnBluetoothDeactivated(result r);
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode);
+       virtual void OnBluetoothDiscoveryStarted(result r);
+       virtual void OnBluetoothRemoteDeviceFound(const BluetoothDevice& foundDevice);
+       virtual void OnBluetoothDiscoveryDone(bool isCompleted);
+       virtual void OnBluetoothServiceListReceived(const Tizen::Base::ByteBuffer& address, unsigned long serviceList,
+                                                                                               const Tizen::Base::Collection::IList* pServiceUuidList, result r);
+       virtual void OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r);
+       virtual void OnBluetoothUnpaired(const Tizen::Base::ByteBuffer& address);
+       virtual void OnBluetoothDeviceConnected(const Tizen::Base::ByteBuffer& address);
+       virtual void OnBluetoothDeviceDisconnected(const Tizen::Base::ByteBuffer& address);
+
+private:
+       _BluetoothManagerImpl(const _BluetoothManagerImpl& value);
+       _BluetoothManagerImpl& operator =(const _BluetoothManagerImpl& value);
+
+       result RefreshPairedDeviceMap(void);
+       const char* GetStringOfCurrentState(void) const;
+       const char* GetStringOfPairingState(void) const;
+
+public:
+   /**
+        * Gets the Impl instance.
+        *
+        * @return      The pointer to _BluetoothManagerImpl
+        * @param[in]   bluetoothManager            An instance of BluetoothManager
+        */
+       static _BluetoothManagerImpl* GetInstance(BluetoothManager& bluetoothManager);
+
+       /**
+        * Gets the Impl instance.
+        *
+        * @return      The pointer to  _BluetoothDeviceImpl
+        * @param[in]   bluetoothManager     An instance of BluetoothManager
+        */
+       static const _BluetoothManagerImpl* GetInstance(const BluetoothManager& bluetoothManager);
+
+private:
+       _BluetoothIpcProxy* __pIpcProxy;
+       _BluetoothGapSystemAdapter* __pGapAdapter;
+       std::unique_ptr<_BluetoothManagerEvent> __pMgrEvent;
+       std::unique_ptr<_BluetoothDeviceEvent> __pDevEvent;
+       std::unique_ptr<_BluetoothConnectionEvent> __pConEvent;
+       const IBluetoothDeviceEventListener* __pDevEvtListener;
+       const _IBluetoothConnectionEventListener* __pConEvtListener;
+       BluetoothDevice* __pLocalDevice;
+       Tizen::Base::Collection::ArrayList __pairedDeviceList;        // for APIs prior to 2.0
+       Tizen::Base::Collection::HashMap __pairedDeviceMap;
+       Tizen::Base::Runtime::Mutex __stateMutex;
+       Tizen::Base::Runtime::Mutex __pairedDevMapMutex;
+       _BluetoothManagerStateType __currentState;
+       _BluetoothPairingStateType __pairingState;
+       Tizen::Base::ByteBuffer __pairingTargetAddress;
+       Tizen::Base::Collection::LinkedList __discoveredDeviceList;
+}; // _BluetoothManagerImpl
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_MANAGER_IMPL_H_
diff --git a/src/inc/FNetBt_BluetoothOppClientImpl.h b/src/inc/FNetBt_BluetoothOppClientImpl.h
new file mode 100644 (file)
index 0000000..3f5ed4e
--- /dev/null
@@ -0,0 +1,177 @@
+//
+// 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    FNetBt_BluetoothOppClientImpl.h
+ * @brief   This is the header file for the _BluetoothOppClientImpl class.
+ *
+ * This header file contains the declaration of the _BluetoothOppClientImpl class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_IMPL_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FOspConfig.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseString.h>
+#include <FBaseRtMutex.h>
+#include "FNetBt_IBluetoothManagerEventListener.h"
+#include "FNetBt_IBluetoothDeviceEventListener.h"
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class IBluetoothOppClientEventListener;
+class _BluetoothGapSystemAdapter;
+class _BluetoothOppSystemAdapter;
+class _BluetoothOppClientEvent;
+
+/**
+  * @class   _BluetoothOppClientImpl
+  * @brief   TBD.
+  */
+class _OSP_EXPORT_ _BluetoothOppClientImpl
+       : public Tizen::Base::Object
+       , public _IBluetoothManagerEventListener
+       , public _IBluetoothDeviceEventListener
+{
+/**
+ * @enum    _BluetoothOppClientStateType
+ * Defines the states of the Bluetooth Opp client.
+ */
+       enum _BluetoothOppClientStateType
+       {
+               _BT_OPP_CLI_STATE_DISABLED,
+               _BT_OPP_CLI_STATE_IDLE,
+               _BT_OPP_CLI_STATE_BONDING,
+               _BT_OPP_CLI_STATE_PUSH_READY,
+               _BT_OPP_CLI_STATE_REQ_CANCELING,
+               _BT_OPP_CLI_STATE_ON_TRANSFER,
+               _BT_OPP_CLI_STATE_TRANS_CANCELING
+       };
+
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks     After creating an instance of this class, you must explicitly call
+        *              construction method to initialize the instance.
+        * @see Construct()
+        */
+       _BluetoothOppClientImpl(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       ~_BluetoothOppClientImpl(void);
+
+       /**
+        * Constructs a BluetoothOppClient and attaches a listener to it.
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for OPP client.
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         Insufficient memory.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result Construct(IBluetoothOppClientEventListener& listener);
+
+       /**
+        * Pushes a file to a remote OPP server.
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice            The remote OPP server.
+        * @param[in]   filePath                The path of the source file
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method has failed.
+        * @exception   E_IN_PROGRESS           The push process is in progress.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INACCESSIBLE_PATH     The specified @c filePath is inaccessible.
+        * @exception   E_SERVICE_UNAVAILABLE   OPP service is not available.
+        */
+       result PushFile(const BluetoothDevice& remoteDevice, const Tizen::Base::String& filePath);
+
+       /**
+        * Cancels the file push request in progress.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_IN_PROGRESS           The canceling 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 push request is not sent or accepted by a remote device.
+        */
+       result CancelPush(void);
+
+       /**
+        * Specifies the minimum interval of invocation of OnOppTransferInProgress() in percentage.
+        * The default value is 5.
+        *
+        * @return      An error code
+        * @param[in]   percent                 The minimum period of progress interval as a percentage value
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_RANGE          The value of the argument is outside the valid range defined by the method.
+        *
+        * @see         IBluetoothOppClientEventListener::OnOppTransferInProgress()
+        */
+       result SetMinProgressInterval(int percent);
+
+
+       // Callback functions which called by _BluetoothOppSystemAdapter
+       virtual void OnBluetoothActivated(result r);
+       virtual void OnBluetoothDeactivated(result r);
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode) {}
+       virtual void OnBluetoothDiscoveryStarted(result r) {}
+       virtual void OnBluetoothRemoteDeviceFound(const BluetoothDevice& foundDevice) {}
+       virtual void OnBluetoothDiscoveryDone(bool isCompleted) {}
+       virtual void OnBluetoothServiceListReceived(const Tizen::Base::ByteBuffer& address, unsigned long serviceList,
+                                                                                               const Tizen::Base::Collection::IList* pServiceUuidList, result r) {};
+       virtual void OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r);
+       virtual void OnBluetoothUnpaired(const Tizen::Base::ByteBuffer& address) {}
+       virtual void OnBluetoothDeviceConnected(const Tizen::Base::ByteBuffer& address) {}
+       virtual void OnBluetoothDeviceDisconnected(const Tizen::Base::ByteBuffer& address) {}
+       void OnOppPushResponded(result r);
+       void OnOppTransferInProgress(int percent);
+       void OnOppTransferDone(const Tizen::Base::String& filePath, int fileSize, bool isCompleted);
+
+private:
+       _BluetoothOppClientImpl(const _BluetoothOppClientImpl& value);
+       _BluetoothOppClientImpl& operator =(const _BluetoothOppClientImpl& value);
+
+       const char* GetStringOfCurrentState(void) const;
+
+private:
+       const static int __defaultProgressInterval = 5;
+
+       _BluetoothGapSystemAdapter* __pGapAdapter;
+       _BluetoothOppSystemAdapter* __pOppAdapter;
+       std::unique_ptr<_BluetoothOppClientEvent> __pEvent;
+       Tizen::Base::Runtime::Mutex __stateMutex;
+       _BluetoothOppClientStateType __currentState;
+       Tizen::Base::ByteBuffer __pairingAddress;
+       Tizen::Base::String __pushedFilePath;
+       int __minProgressInterval;
+       int __previousProgress;
+}; // _BluetoothOppClientImpl
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_OPP_CLIENT_IMPL_H_
diff --git a/src/inc/FNetBt_BluetoothOppServerImpl.h b/src/inc/FNetBt_BluetoothOppServerImpl.h
new file mode 100644 (file)
index 0000000..bb26a49
--- /dev/null
@@ -0,0 +1,224 @@
+//
+// 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    FNetBt_BluetoothOppServerImpl.h
+ * @brief   This is the header file for the _BluetoothOppServerImpl Class.
+ *
+ * This header file contains the declaration of the _BluetoothOppServerImpl Class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_IMPL_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FOspConfig.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseString.h>
+#include <FBaseRtMutex.h>
+#include "FNetBt_IBluetoothManagerEventListener.h"
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class IBluetoothOppServerEventListener;
+class _BluetoothGapSystemAdapter;
+class _BluetoothOppSystemAdapter;
+class _BluetoothOppServerEvent;
+
+/**
+  * @class   _BluetoothOppServerImpl
+  * @brief   TBD.
+  */
+class _OSP_EXPORT_ _BluetoothOppServerImpl
+       : public Tizen::Base::Object
+       , public _IBluetoothManagerEventListener
+{
+/**
+ * @enum    _BluetoothOppServerStateType
+ * Defines the states of the Bluetooth SPP Acceptor.
+ */
+       enum _BluetoothOppServerStateType
+       {
+               _BT_OPP_SVR_STATE_DISABLED,
+               _BT_OPP_SVR_STATE_IDLE,
+               _BT_OPP_SVR_STATE_ON_SERVICE,
+               _BT_OPP_SVR_STATE_PUSH_REQUESTED,
+               _BT_OPP_SVR_STATE_ON_TRANSFER,
+               _BT_OPP_SVR_STATE_ON_STOPPING
+       };
+
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks     After creating an instance of this class, you must explicitly call
+        *              construction method to initialize the instance.
+        * @see         Construct()
+        */
+       _BluetoothOppServerImpl(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       ~_BluetoothOppServerImpl(void);
+
+       /**
+        * Constructs a BluetoothOppServer and attaches a listener to it.
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for OPP server
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         Insufficient memory.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result Construct(IBluetoothOppServerEventListener& listener);
+
+       /**
+        * Accepts a push request from a remote OPP client.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a push request is not
+        *                                      received from a remote device.
+        */
+       result AcceptPush(void);
+
+       /**
+        * Rejects a push request from a remote OPP client.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a push request is not
+        *                                      received from a remote device.
+        */
+       result RejectPush(void);
+
+       /**
+        * Sets the destination path of the file to be received.
+        *
+        * @return      An error code
+        * @param[in]   dstPath                 The new destination file path
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, trying to change the path on Push transition is prohibited.
+        * @exception   E_INACCESSIBLE_PATH     The specified @c dstPath is inaccessible.
+        * @exception   E_FAILURE               The method has failed.
+        */
+       result SetDestinationPath(const Tizen::Base::String& dstPath);
+
+       /**
+        * Starts the OPP service and associates a listener with it.
+        *
+        * @return      An error code
+        * @param[in]   dstPath                 The new destination file path
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_IN_PROGRESS           The service has already started.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, The stop process is in progress.
+        * @exception   E_INACCESSIBLE_PATH     The specified @c dstPath is inaccessible.
+        * @exception   E_SERVICE_UNAVAILABLE   OPP service is not available.
+        */
+       result StartService(const Tizen::Base::String& dstPath);
+
+       /**
+        * Stops the OPP service.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started as yet.
+        */
+       result StopService(void);
+
+       /**
+        * Stops the file transfer in progress which was started by the client. @n
+        * If this method is called during the file transfer, the IBluetoothOppServerEventListener::OnOppTransferDone()
+        * method is called with @c isCompleted as @c false.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_INVALID_STATE         This instance is in an invalid state. @n
+        *                                      For example, %Bluetooth is not activated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the file transfer is not in progress.
+        * @exception   E_OPERATION_FAILED      The operation has failed.
+        * @see         IBluetoothOppServerEventListener::OnOppTransferDone()
+        */
+       result StopTransfer(void);
+
+       /**
+        * Specifies the minimum interval of invocation of OnOppTransferInProgress() in percentage.
+        * The default value is 5.
+        *
+        * @return      An error code
+        * @param[in]   percent                 The minimum period of progress interval as a percentage value
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_RANGE          The value of the argument is outside the valid range defined by the method.
+        *
+        * @see         IBluetoothOppServerEventListener::OnOppTransferInProgress()
+        */
+       result SetMinProgressInterval(int percent);
+
+
+       // Callback functions which called by _BluetoothSystemAdapter
+       virtual void OnBluetoothActivated(result r);
+       virtual void OnBluetoothDeactivated(result r);
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode) {}
+       void OnOppPushRequested(const BluetoothDevice& device);
+       void OnOppTransferInProgress(int percent);
+       void OnOppTransferDone(const Tizen::Base::String& filePath, int fileSize, bool isCompleted);
+
+private:
+       _BluetoothOppServerImpl(const _BluetoothOppServerImpl& value);
+       _BluetoothOppServerImpl& operator =(const _BluetoothOppServerImpl& value);
+
+       const char* GetStringOfCurrentState(void) const;
+
+private:
+       const static int __defaultProgressInterval = 5;
+
+       _BluetoothGapSystemAdapter* __pGapAdapter;
+       _BluetoothOppSystemAdapter* __pOppAdapter;
+       std::unique_ptr<_BluetoothOppServerEvent> __pEvent;
+       Tizen::Base::Runtime::Mutex __stateMutex;
+       _BluetoothOppServerStateType __currentState;
+       Tizen::Base::String __pushedFileName;
+       int __minProgressInterval;
+       int __previousProgress;
+
+}; // _BluetoothOppServerImpl
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_OPP_SERVER_IMPL_H_
diff --git a/src/inc/FNetBt_BluetoothSppAcceptorImpl.h b/src/inc/FNetBt_BluetoothSppAcceptorImpl.h
new file mode 100644 (file)
index 0000000..9286254
--- /dev/null
@@ -0,0 +1,212 @@
+//
+// 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    FNetBt_BluetoothSppAcceptorImpl.h
+ * @brief   This is the header file for the _BluetoothSppAcceptorImpl class.
+ *
+ * This header file contains the declaration of the _BluetoothSppAcceptorImpl class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_IMPL_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FBaseResult.h>
+#include <FBaseObject.h>
+#include <FBaseRtMutex.h>
+#include "FNetBt_IBluetoothManagerEventListener.h"
+#include "FNetBt_IBluetoothSocketListener.h"
+
+//Forward declarations
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+class UuId;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class IBluetoothSppAcceptorEventListener;
+class _BluetoothSppAcceptorEvent;
+class _BluetoothGapSystemAdapter;
+class _BluetoothSppSystemAdapter;
+
+/**
+  * @class   _BluetoothSppAcceptorImpl
+  * @brief   TBD.
+  */
+class _OSP_EXPORT_ _BluetoothSppAcceptorImpl
+       : public Tizen::Base::Object
+       , public _IBluetoothManagerEventListener
+       , public _IBluetoothSocketListener
+{
+/**
+ * @enum    _BluetoothSppAcceptorStateType
+ * Defines the states of the Bluetooth SPP Acceptor.
+ */
+       enum _BluetoothSppAcceptorStateType
+       {
+               _BT_SPP_ACC_STATE_DISABLED,
+               _BT_SPP_ACC_STATE_IDLE,
+               _BT_SPP_ACC_STATE_ON_SERVICE,
+               _BT_SPP_ACC_STATE_CONNECT_REQUESTED,
+               _BT_SPP_ACC_STATE_CONNECTED
+       };
+
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks     After creating an instance of this class, you must explicitly call
+        *              construction method to initialize the instance.
+        * @see         Construct()
+        */
+       _BluetoothSppAcceptorImpl(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       ~_BluetoothSppAcceptorImpl(void);
+
+       /**
+        * Constructs a BluetoothSppAcceptor and attaches a listener to it.
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for SPP accepter.
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         Insufficient memory.
+        * @exception   E_SYSTEM                A system error has occurred.
+        */
+       result Construct(IBluetoothSppAcceptorEventListener& listener);
+
+       /**
+        * Accepts a connection request from a remote SPP initiator.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or the connection request is
+        *                                      not yet received from a remote device.
+        */
+       result AcceptConnection(void);
+
+       /**
+        * Rejects a connection request from a remote SPP initiator.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or the connection request is
+        *                                      not yet received from a remote device.
+        */
+       result RejectConnection(void);
+
+       /**
+        * Starts SPP service with the specified service UUID.
+        *
+        * @return      An error code
+        * @param[in]   serviceUuid             The UUID of SPP service
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_SERVICE_UNAVAILABLE   SPP service with the specified UUID is not available.
+        * @exception   E_INVALID_ARG           The specified input parameter is invalid.
+        * @exception   E_IN_PROGRESS           The service has already started.
+        * @exception   E_ALREADY_CONNECTED     The connection with an SPP initiator has already been established.
+        */
+       result StartService(const Tizen::Base::UuId& serviceUuid);
+
+       /**
+        * Stops the SPP service.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet.
+        */
+       result StopService(void);
+
+       /**
+        * Disconnects the current connection.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a connection with a remote
+        *                                      device is not established.
+        */
+       result Disconnect(void);
+
+       /**
+        * Sends data.
+        *
+        * @return      An error code
+        * @param[in]   buffer                  The data to send
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method has failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_ARG           The argument is null or contains an invalid value.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the service is not started yet or a connection with a remote
+        *                                      device is not established.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       result SendData(const Tizen::Base::ByteBuffer& buffer);
+
+       virtual void OnBluetoothActivated(result r);
+       virtual void OnBluetoothDeactivated(result r);
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode) {}
+       virtual void OnSocketConnectionRequested(const BluetoothDevice& device);
+       virtual void OnSocketConnectionResponded(int socketFd, result r) {}
+       virtual void OnSocketDisconnected(result r);
+       virtual void OnSocketDataReceived(Tizen::Base::ByteBuffer& buffer);
+
+private:
+       _BluetoothSppAcceptorImpl(const _BluetoothSppAcceptorImpl& value);
+       _BluetoothSppAcceptorImpl& operator =(const _BluetoothSppAcceptorImpl& value);
+
+       const char* GetStringOfCurrentState(void) const;
+       result ProcessAsyncDisconnect(void);
+
+private:
+       _BluetoothGapSystemAdapter* __pGapAdapter;
+       _BluetoothSppSystemAdapter* __pSppAdapter;
+       std::unique_ptr<_BluetoothSppAcceptorEvent> __pEvent;
+       Tizen::Base::Runtime::Mutex __stateMutex;
+       _BluetoothSppAcceptorStateType __currentState;
+       int __parentSocketFd;
+       int __childSocketFd;
+
+}; // _BluetoothSppAcceptorImpl
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_ACCEPTOR_IMPL_H_
diff --git a/src/inc/FNetBt_BluetoothSppInitiatorImpl.h b/src/inc/FNetBt_BluetoothSppInitiatorImpl.h
new file mode 100644 (file)
index 0000000..8e3bfe6
--- /dev/null
@@ -0,0 +1,184 @@
+//
+// 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    FNetBt_BluetoothSppInitiatorImpl.h
+ * @brief   This is the header file for the _BluetoothSppInitiatorImpl class.
+ *
+ * This header file contains the declaration of the _BluetoothSppInitiatorImpl class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_IMPL_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_IMPL_H_
+
+#include <unique_ptr.h>
+#include <FOspConfig.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseRtMutex.h>
+#include "FNetBt_IBluetoothManagerEventListener.h"
+#include "FNetBt_IBluetoothDeviceEventListener.h"
+#include "FNetBt_IBluetoothSocketListener.h"
+
+//Forward declarations
+namespace Tizen { namespace Base
+{
+class UuId;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class IBluetoothSppInitiatorEventListener;
+class _BluetoothSppInitiatorEvent;
+class _BluetoothGapSystemAdapter;
+class _BluetoothSppSystemAdapter;
+
+/**
+  * @class   _BluetoothSppInitiatorImpl
+  * @brief   TBD
+  */
+class _OSP_EXPORT_ _BluetoothSppInitiatorImpl
+       : public Tizen::Base::Object
+       , public _IBluetoothManagerEventListener
+       , public _IBluetoothDeviceEventListener
+       , public _IBluetoothSocketListener
+{
+/**
+ * @enum    _BluetoothSppInitiatorStateType
+ * Defines the states of the Bluetooth SPP Acceptor.
+ */
+       enum _BluetoothSppInitiatorStateType
+       {
+               _BT_SPP_INI_STATE_DISABLED,
+               _BT_SPP_INI_STATE_IDLE,
+               _BT_SPP_INI_STATE_BONDING,
+               _BT_SPP_INI_STATE_CONNECT_READY,
+               _BT_SPP_INI_STATE_REQ_CANCELING,
+               _BT_SPP_INI_STATE_CONNECTED
+       } ;
+
+public:
+       /**
+        * This is the default constructor for this class.
+        *
+        * @remarks     After creating an instance of this class, you must explicitly call
+        *              construction method to initialize the instance.
+        * @see         Construct()
+        */
+       _BluetoothSppInitiatorImpl(void);
+
+       /**
+        * This is the destructor for this class.
+        */
+       ~_BluetoothSppInitiatorImpl(void);
+
+       /**
+        * Constructs a BluetoothSppInitiator and attaches a listener to it.
+        *
+        * @return      An error code
+        * @param[in]   listener                The event listener for SPP initiator.
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_OUT_OF_MEMORY         Insufficient memory.
+        */
+       result Construct(IBluetoothSppInitiatorEventListener& listener);
+
+       /**
+        * Sets up a connection to a remote SPP acceptor.
+        *
+        * @return      An error code
+        * @param[in]   remoteDevice            The remote device to be connected
+        * @param[in]   serviceUuid             The UUID of SPP service to be connected
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_ARG           A specified input parameter is invalid.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_IN_PROGRESS           The connection process is in progress.
+        * @exception   E_ALREADY_CONNECTED     The connection with an SPP acceptor has already been established.
+        */
+       result Connect(const BluetoothDevice& remoteDevice, const Tizen::Base::UuId& serviceUuid);
+
+       /**
+        * Disconnects the current connection.
+        *
+        * @return      An error code
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the connection request is not sent or a connection with a
+        *                                      remote device is not established yet.
+        */
+       result Disconnect(void);
+
+       /**
+        * Sends data.
+        *
+        * @return      An error code
+        * @param[in]   buffer                  The data to send
+        * @exception   E_SUCCESS               The method is successful.
+        * @exception   E_FAILURE               The method has failed.
+        * @exception   E_INVALID_STATE         Bluetooth has been deactivated.
+        * @exception   E_INVALID_ARG           The argument is null or contains an invalid value.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified
+        *                                      operation. @n
+        *                                      For example, the connection request is not sent or a connection with a
+        *                                      remote device is not established yet.
+        * @exception   E_SYSTEM                A system error occurred.
+        */
+       result SendData(const Tizen::Base::ByteBuffer& buffer);
+
+       virtual void OnBluetoothActivated(result r);
+       virtual void OnBluetoothDeactivated(result r);
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode) {}
+       virtual void OnBluetoothDiscoveryStarted(result r) {}
+       virtual void OnBluetoothRemoteDeviceFound(const BluetoothDevice& foundDevice) {}
+       virtual void OnBluetoothDiscoveryDone(bool isCompleted) {}
+       virtual void OnBluetoothServiceListReceived(const Tizen::Base::ByteBuffer& address, unsigned long serviceList,
+                                                                                               const Tizen::Base::Collection::IList* pServiceUuidList, result r) {};
+       virtual void OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r);
+       virtual void OnBluetoothUnpaired(const Tizen::Base::ByteBuffer& address) {}
+       virtual void OnBluetoothDeviceConnected(const Tizen::Base::ByteBuffer& address) {}
+       virtual void OnBluetoothDeviceDisconnected(const Tizen::Base::ByteBuffer& address) {}
+       virtual void OnSocketConnectionRequested(const BluetoothDevice& device) {}
+       virtual void OnSocketConnectionResponded(int socketFd, result r);
+       virtual void OnSocketDisconnected(result r);
+       virtual void OnSocketDataReceived(Tizen::Base::ByteBuffer& buffer);
+
+private:
+       _BluetoothSppInitiatorImpl(const _BluetoothSppInitiatorImpl& value);
+       _BluetoothSppInitiatorImpl& operator =(const _BluetoothSppInitiatorImpl& value);
+
+       const char* GetStringOfCurrentState(void) const;
+       result ProcessAsyncDisconnect(void);
+
+private:
+       _BluetoothGapSystemAdapter* __pGapAdapter;
+       _BluetoothSppSystemAdapter* __pSppAdapter;
+       std::unique_ptr<_BluetoothSppInitiatorEvent> __pEvent;
+       Tizen::Base::Runtime::Mutex __stateMutex;
+       _BluetoothSppInitiatorStateType __currentState;
+       Tizen::Base::ByteBuffer __pairingAddress;
+       Tizen::Base::UuId __pairingUuid;
+       int __socketFd;
+
+}; // _BluetoothSppInitiatorImpl
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_INITIATOR_IMPL_H_
diff --git a/src/inc/FNetBt_ConnectivityIpcMessages.h b/src/inc/FNetBt_ConnectivityIpcMessages.h
new file mode 100644 (file)
index 0000000..4d52b1a
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// 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       FNetBt_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 <ipc/ipc_message_macros.h>
+#include <FIo_IpcCommonParamTraits.h>
+#include <FIo_IpcMessageStart.h>
+
+#ifndef BLUETOOTH_CONNECTIVITY_IPC_SERVER_NAME
+#define BLUETOOTH_CONNECTIVITY_IPC_SERVER_NAME "osp.net.bluetooth.ipcserver.connectivity"
+#endif
+
+#define IPC_MESSAGE_START ConnectivityBluetoothServiceMsgStart
+
+// Client -> Server (sync)
+IPC_SYNC_MESSAGE_CONTROL0_2(ConnectivityBluetoothServiceMsg_getLocalDeviceName, Tizen::Base::String /* local name */, unsigned long /* result */)
+IPC_SYNC_MESSAGE_CONTROL1_1(ConnectivityBluetoothServiceMsg_setLocalDeviceName, Tizen::Base::String /* local name */, unsigned long /* result */)
+IPC_SYNC_MESSAGE_CONTROL2_1(ConnectivityBluetoothServiceMsg_setDiscoverableMode, int /* mode */, int /* seconds */ , unsigned long /* result */)
diff --git a/src/inc/FNetBt_IBluetoothConnectionEventListener.h b/src/inc/FNetBt_IBluetoothConnectionEventListener.h
new file mode 100644 (file)
index 0000000..7956f2e
--- /dev/null
@@ -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    FNetBt_IBluetoothConnectionEventListener.h
+ * @brief   This is the header file for the _IBluetoothConnectionEventListener interface.
+ *
+ * This header file contains the declaration of the _IBluetoothConnectionEventListener interface.
+ *
+ */
+#ifndef _FNET_BT_INTERNAL_IBLUETOOTH_CONNECTION_EVENT_LISTENER_H_
+#define _FNET_BT_INTERNAL_IBLUETOOTH_CONNECTION_EVENT_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+namespace Collection
+{
+class IList;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declaration
+class BluetoothDevice;
+
+/**
+  * @interface   _IBluetoothConnectionEventListener
+  * @brief       This interface specifies the methods used for notifying the change of connection with local device
+  */
+class _OSP_EXPORT_ _IBluetoothConnectionEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This is the virtual destructor for this class.
+        */
+       virtual ~_IBluetoothConnectionEventListener(void) {}
+
+       /**
+        * Callback used to notify that the paired device is connected.
+        *
+        * @param[in]   isCompleted                 @c true, if the transfer is successfully completed @n
+        *                                          @c false, otherwise.
+        */
+       virtual void OnBluetoothDeviceConnected(const Tizen::Base::ByteBuffer& address) = 0;
+
+       /**
+        * Callback used to notify that the paired device is disconnected.
+        *
+        * @param[in]   isCompleted                 @c true, if the transfer is successfully completed @n
+        *                                          @c false, otherwise.
+        */
+       virtual void OnBluetoothDeviceDisconnected(const Tizen::Base::ByteBuffer& address) = 0;
+
+}; // _IBluetoothConnectionEventListener
+
+} } }
+#endif // _FNET_BT_INTERNAL_IBLUETOOTH_CONNECTION_EVENT_LISTENER_H_
diff --git a/src/inc/FNetBt_IBluetoothDeviceEventListener.h b/src/inc/FNetBt_IBluetoothDeviceEventListener.h
new file mode 100644 (file)
index 0000000..0559233
--- /dev/null
@@ -0,0 +1,130 @@
+//
+// 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    FNetBt_IBluetoothDeviceEventListener.h
+ * @brief   This is the header file for the _IBluetoothDeviceEventListener interface.
+ *
+ * This header file contains the declaration of the _IBluetoothDeviceEventListener interface.
+ *
+ */
+#ifndef _FNET_BT_INTERNAL_IBLUETOOTH_DEVICE_EVENT_LISTENER_H_
+#define _FNET_BT_INTERNAL_IBLUETOOTH_DEVICE_EVENT_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+namespace Collection
+{
+class IList;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declaration
+class BluetoothDevice;
+
+/**
+  * @interface   _IBluetoothDeviceEventListener
+  * @brief       This interface specifies the methods used for notifying different kinds of Bluetooth remote device related
+  *              events such as search result.
+  */
+class _OSP_EXPORT_ _IBluetoothDeviceEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This is the virtual destructor for this class.
+        */
+       virtual ~_IBluetoothDeviceEventListener(void) {}
+
+       /**
+        * Callback used to notify that the device discovery process is started.
+        *
+        * @param[in]   r                           The result of the event
+        * @exception   E_SUCCESS                   The discovery was started successfully.
+        * @exception   E_SYSTEM                    A failure occurred from the underlying system.
+        */
+       virtual void OnBluetoothDiscoveryStarted(result r) = 0;
+
+       /**
+        * Callback used to notify that a new remote device is found.
+        *
+        * @param[in]   foundDevice                 A remote device which is found.
+        */
+       virtual void OnBluetoothRemoteDeviceFound(const BluetoothDevice& foundDevice) = 0;
+
+       /**
+        * Callback used to notify that the device discovery process is done.
+        *
+        * @param[in]   isCompleted                 @c true, if the transfer is successfully completed @n
+        *                                          @c false, otherwise.
+        */
+       virtual void OnBluetoothDiscoveryDone(bool isCompleted) = 0;
+
+       /**
+        * Callback used to notify that the service list is received from a remote device.
+        *
+        * @param[in]   address                     The address of the remote device which sent its service list
+        * @param[in]   serviceList                 The received service list
+        * @param[in]   pServiceUuidList            The received service UUID list
+        * @param[in]   r                           The result of receiving service list
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_REMOTE_SERVICE_NOT_FOUND  The service list of the remote device is not found.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       virtual void OnBluetoothServiceListReceived(const Tizen::Base::ByteBuffer& address, unsigned long serviceList,
+                                                                                               const Tizen::Base::Collection::IList* pServiceUuidList, result r) = 0;
+
+       /**
+        * Callback used to notify that a new remote device is paired with this local device.
+        *
+        * @param[in]   pPairedDevice               The device which the local device is paired with
+        * @param[in]   r                           The result of pairing
+        * @exception   E_SUCCESS                   The method is successful.
+        * @exception   E_SYSTEM                    A system error occurred.
+        */
+       virtual void OnBluetoothPaired(const BluetoothDevice* pPairedDevice, result r) = 0;
+
+       /**
+        * Callback used to notify that the already paired device is unpaired with this local device.
+        *
+        * @param[in]   address                     The address of the device which the local device is unpaired with
+        */
+       virtual void OnBluetoothUnpaired(const Tizen::Base::ByteBuffer& address) = 0;
+
+       /**
+        * Callback used to notify that the paired device is connected.
+        *
+        * @param[in]   address                     The address of the device which the local device is connected with
+        */
+       virtual void OnBluetoothDeviceConnected(const Tizen::Base::ByteBuffer& address) = 0;
+
+       /**
+        * Callback used to notify that the paired device is disconnected.
+        *
+        * @param[in]   address                     The address of the device which the local device is disconnected with
+        */
+       virtual void OnBluetoothDeviceDisconnected(const Tizen::Base::ByteBuffer& address) = 0;
+
+}; // _IBluetoothDeviceEventListener
+
+} } }
+#endif // _FNET_BT_INTERNAL_IBLUETOOTH_DEVICE_EVENT_LISTENER_H_
diff --git a/src/inc/FNetBt_IBluetoothManagerEventListener.h b/src/inc/FNetBt_IBluetoothManagerEventListener.h
new file mode 100644 (file)
index 0000000..2e6b2ce
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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    FNetBt_IBluetoothManagerEventListener.h
+ * @brief   This is the header file for the _IBluetoothManagerEventListener interface.
+ *
+ * This header file contains the declaration of the _IBluetoothManagerEventListener interface.
+ *
+ */
+#ifndef _FNET_BT_INTERNAL_IBLUETOOTH_MANAGER_EVENT_LISTENER_H_
+#define _FNET_BT_INTERNAL_IBLUETOOTH_MANAGER_EVENT_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+#include <FNetBtBluetoothTypes.h>
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+/**
+  * @interface   _IBluetoothManagerEventListener
+  * @brief       This interface specifies the methods used for notifying different kinds of Bluetooth manager(adapter)
+  *              related events such as activation and deactivation.
+  */
+class _OSP_EXPORT_ _IBluetoothManagerEventListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This is the virtual destructor for this class.
+        */
+       virtual ~_IBluetoothManagerEventListener(void) {}
+
+
+       /**
+        * Callback used to notify that Bluetooth is activated on the device.
+        *
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void OnBluetoothActivated(result r) = 0;
+
+       /**
+        * Callback used to notify that Bluetooth is deactivated on the device.
+        *
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_SYSTEM            A system error occurred.
+        */
+       virtual void OnBluetoothDeactivated(result r) = 0;
+
+       /**
+        * Callback used to notify that Bluetooth is deactivated on the device.
+        *
+        * @param[in]   mode                The changed discoverable mode
+        */
+       virtual void OnBluetoothDiscoverableModeChanged(BluetoothDiscoverableMode mode) = 0;
+
+}; // _IBluetoothManagerEventListener
+
+} } }
+#endif // _FNET_BT_INTERNAL_IBLUETOOTH_MANAGER_EVENT_LISTENER_H_
diff --git a/src/inc/FNetBt_IBluetoothSocketListener.h b/src/inc/FNetBt_IBluetoothSocketListener.h
new file mode 100644 (file)
index 0000000..b35e063
--- /dev/null
@@ -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    FNetBt_IBluetoothSocketListener.h
+ * @brief   This is the header file for the _IBluetoothSocketListener interface.
+ *
+ * This header file contains the declaration of the _IBluetoothSocketListener interface.
+ *
+ */
+#ifndef _FNET_BT_INTERNAL_IBLUETOOTH_SOCKET_LISTENER_H_
+#define _FNET_BT_INTERNAL_IBLUETOOTH_SOCKET_LISTENER_H_
+
+#include <FBaseRtIEventListener.h>
+
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declaration
+class BluetoothDevice;
+
+/**
+  * @interface   _IBluetoothSocketListener
+  * @brief       This interface specifies the methods used for notifying different kinds of Bluetooth socket (SPP) related
+  *              events such as connection and disconnection.
+  */
+class _OSP_EXPORT_ _IBluetoothSocketListener
+       : public Base::Runtime::IEventListener
+{
+public:
+       /**
+        * This is the virtual destructor for this class.
+        */
+       virtual ~_IBluetoothSocketListener(void) {}
+
+       /**
+        * Callback used to notify that a new connection request is received from the socket client.
+        *
+        * @param[in]    device                  The socket client device
+        */
+       virtual void OnSocketConnectionRequested(const BluetoothDevice& device) = 0;
+
+       /**
+        * Callback used to notify that the response of the connection request is received from the socket server.
+        *
+        * @param[in]    socketFd                The new generated client socket FD
+        * @param[in]    r                       The result of the event
+        * @exception    E_SUCCESS               The connection is established successfully.
+        * @exception    E_SYSTEM                The connection fails.
+        */
+       virtual void OnSocketConnectionResponded(int socketFd, result r) = 0;
+
+       /**
+        * Callback used to notify that the connection is disconnected.
+        *
+        * @param[in]    r                       The result of the event
+        * @exception    E_SUCCESS               The connection is terminated successfully.
+        * @exception    E_SYSTEM                The method has failed to disconnect.
+        */
+       virtual void OnSocketDisconnected(result r) = 0;
+
+       /**
+        * Callback used to notify that the data has been received.
+        *
+        * @param[in]    buffer                  The received data
+        */
+       virtual void OnSocketDataReceived(Tizen::Base::ByteBuffer& buffer) = 0;
+
+}; // _IBluetoothSocketListener
+
+} } }
+#endif // _FNET_BT_INTERNAL_IBLUETOOTH_SOCKET_LISTENER_H_