Tizen 2.1 base
authorJinkun Jang <jinkun.jang@samsung.com>
Tue, 12 Mar 2013 16:50:34 +0000 (01:50 +0900)
committerJinkun Jang <jinkun.jang@samsung.com>
Tue, 12 Mar 2013 16:50:34 +0000 (01:50 +0900)
49 files changed:
CMakeLists.txt [new file with mode: 0755]
LICENSE.APLv2.0 [new file with mode: 0644]
LICENSE.Flora [new file with mode: 0755]
NOTICE [new file with mode: 0755]
data/.readme [new file with mode: 0755]
icons/screen-density-xhigh/mainmenu.png [new file with mode: 0644]
inc/BluetoothConnectivityIpcStub.h [new file with mode: 0644]
inc/BluetoothService.h [new file with mode: 0644]
inc/ConnectivityService.h [new file with mode: 0644]
inc/IWifiProximityEventListener.h [new file with mode: 0644]
inc/NetConnectivityIpcStub.h [new file with mode: 0644]
inc/NetService.h [new file with mode: 0644]
inc/NfcConnectivityIpcStub.h [new file with mode: 0644]
inc/NfcMessagePushDelegate.h [new file with mode: 0644]
inc/NfcMessageRegisterService.h [new file with mode: 0644]
inc/NfcService.h [new file with mode: 0644]
inc/TelephonyConnectivityIpcStub.h [new file with mode: 0644]
inc/TelephonyService.h [new file with mode: 0644]
inc/WifiConnectivityIpcStub.h [new file with mode: 0644]
inc/WifiProximityEvent.h [new file with mode: 0644]
inc/WifiProximityEventArg.h [new file with mode: 0644]
inc/WifiProximityService.h [new file with mode: 0644]
inc/WifiService.h [new file with mode: 0644]
manifest.xml [new file with mode: 0644]
osp-connectivity-service.manifest [new file with mode: 0644]
packaging/osp-connectivity-service.spec [new file with mode: 0755]
src/BluetoothConnectivityIpcMessages.cpp [new file with mode: 0644]
src/BluetoothConnectivityIpcStub.cpp [new file with mode: 0644]
src/BluetoothService.cpp [new file with mode: 0644]
src/ConnectivityService.cpp [new file with mode: 0644]
src/ConnectivityServiceEntry.cpp [new file with mode: 0644]
src/NetConnectivityIpcMessages.cpp [new file with mode: 0644]
src/NetConnectivityIpcStub.cpp [new file with mode: 0644]
src/NetService.cpp [new file with mode: 0644]
src/NfcConnectivityIpcMessages.cpp [new file with mode: 0644]
src/NfcConnectivityIpcStub.cpp [new file with mode: 0644]
src/NfcMessagePushDelegate.cpp [new file with mode: 0644]
src/NfcMessageRegisterService.cpp [new file with mode: 0644]
src/NfcService.cpp [new file with mode: 0644]
src/TelephonyConnectivityIpcMessages.cpp [new file with mode: 0644]
src/TelephonyConnectivityIpcStub.cpp [new file with mode: 0755]
src/TelephonyService.cpp [new file with mode: 0755]
src/WifiConnectivityIpcMessages.cpp [new file with mode: 0644]
src/WifiConnectivityIpcStub.cpp [new file with mode: 0644]
src/WifiProximityEvent.cpp [new file with mode: 0644]
src/WifiProximityEventArg.cpp [new file with mode: 0644]
src/WifiProximityService.cpp [new file with mode: 0644]
src/WifiService.cpp [new file with mode: 0644]
system-service-export.ver [new file with mode: 0755]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b01f87a
--- /dev/null
@@ -0,0 +1,83 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET (this_target osp-connectivity-service)
+SET (APPID 57r43275q7)
+
+SET(CMAKE_EXECUTABLE_SUFFIX ".exe")
+SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/output")
+
+INCLUDE_DIRECTORIES (
+       /usr/include/glib-2.0
+       /usr/lib/glib-2.0/include
+       /usr/include/osp
+       /usr/include/osp/app
+       /usr/include/osp/base
+       /usr/include/osp/io
+       /usr/include/osp/system
+       /usr/include/osp/security
+       /usr/include/osp/net
+       /usr/include/osp/telephony
+       /usr/include/chromium
+       /usr/include/vconf
+       /usr/include/appfw
+       /usr/include/ecore-1
+       /usr/include/evas-1
+       /usr/include/eina-1
+       /usr/include/eina-1/eina
+       /usr/include/bt-service
+       /usr/include/system
+       /usr/include/wifi
+       /usr/include/wifi-direct
+       /usr/include/network
+       /usr/include/telephony
+       /usr/include/telephony-client
+       inc
+       )
+
+SET (${this_target}_SOURCE_FILES
+       src/BluetoothConnectivityIpcMessages.cpp
+       src/BluetoothConnectivityIpcStub.cpp
+       src/BluetoothService.cpp
+       src/ConnectivityService.cpp
+       src/ConnectivityServiceEntry.cpp
+       src/NetConnectivityIpcMessages.cpp
+       src/NetConnectivityIpcStub.cpp
+       src/NetService.cpp
+       src/NfcConnectivityIpcMessages.cpp
+       src/NfcConnectivityIpcStub.cpp
+       src/NfcMessagePushDelegate.cpp
+       src/NfcMessageRegisterService.cpp
+       src/NfcService.cpp
+       src/TelephonyConnectivityIpcMessages.cpp
+       src/TelephonyConnectivityIpcStub.cpp
+       src/TelephonyService.cpp
+       src/WifiConnectivityIpcMessages.cpp
+       src/WifiConnectivityIpcStub.cpp
+       src/WifiProximityEvent.cpp
+       src/WifiProximityEventArg.cpp
+       src/WifiProximityService.cpp
+       src/WifiService.cpp
+       )
+       
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fPIE -Wall -pthread -g3" )
+
+## 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_EXECUTABLE (${this_target} ${${this_target}_SOURCE_FILES})
+
+
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --no-undefined -Xlinker --as-needed -pie)
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --version-script=${CMAKE_CURRENT_SOURCE_DIR}/system-service-export.ver)
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -losp-net -losp-wifi -lchromium -lcapi-network-wifi -lcapi-network-bluetooth -lcapi-network-connection -lcapi-network-nfc -lwifi-direct -lvconf -lcapi-telephony-sim -lSLP-tapi -lecore_x -lcapi-appfw-app-manager)
+
+## Cory additional info
+INSTALL(TARGETS ${this_target} DESTINATION ../usr/apps/${APPID}/bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/manifest.xml DESTINATION ../usr/apps/${APPID}/info)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ../usr/apps/${APPID})
diff --git a/LICENSE.APLv2.0 b/LICENSE.APLv2.0
new file mode 100644 (file)
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/LICENSE.Flora b/LICENSE.Flora
new file mode 100755 (executable)
index 0000000..9c95663
--- /dev/null
@@ -0,0 +1,206 @@
+Flora License
+
+Version 1.0, May, 2012
+
+http://floralicense.org/license/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction,
+and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by
+the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and
+all other entities that control, are controlled by, or are
+under common control with that entity. For the purposes of
+this definition, "control" means (i) the power, direct or indirect,
+to cause the direction or management of such entity,
+whether by contract or otherwise, or (ii) ownership of fifty percent (50%)
+or more of the outstanding shares, or (iii) beneficial ownership of
+such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity
+exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications,
+including but not limited to software source code, documentation source,
+and configuration files.
+
+"Object" form shall mean any form resulting from mechanical
+transformation or translation of a Source form, including but
+not limited to compiled object code, generated documentation,
+and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form,
+made available under the License, as indicated by a copyright notice
+that is included in or attached to the work (an example is provided
+in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form,
+that is based on (or derived from) the Work and for which the editorial
+revisions, annotations, elaborations, or other modifications represent,
+as a whole, an original work of authorship. For the purposes of this License,
+Derivative Works shall not include works that remain separable from,
+or merely link (or bind by name) to the interfaces of, the Work and
+Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original
+version of the Work and any modifications or additions to that Work or
+Derivative Works thereof, that is intentionally submitted to Licensor
+for inclusion in the Work by the copyright owner or by an individual or
+Legal Entity authorized to submit on behalf of the copyright owner.
+For the purposes of this definition, "submitted" means any form of
+electronic, verbal, or written communication sent to the Licensor or
+its representatives, including but not limited to communication on
+electronic mailing lists, source code control systems, and issue
+tracking systems that are managed by, or on behalf of, the Licensor
+for the purpose of discussing and improving the Work, but excluding
+communication that is conspicuously marked or otherwise designated
+in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity
+on behalf of whom a Contribution has been received by Licensor and
+subsequently incorporated within the Work.
+
+"Tizen Certified Platform" shall mean a software platform that complies
+with the standards set forth in the Compatibility Definition Document
+and passes the Compatibility Test Suite as defined from time to time
+by the Tizen Technical Steering Group and certified by the Tizen
+Association or its designated agent.
+
+2. Grant of Copyright License.  Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the
+Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License.  Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+(except as stated in this section) patent license to make, have made,
+use, offer to sell, sell, import, and otherwise transfer the Work
+solely as incorporated into a Tizen Certified Platform, where such
+license applies only to those patent claims licensable by such
+Contributor that are necessarily infringed by their Contribution(s)
+alone or by combination of their Contribution(s) with the Work solely
+as incorporated into a Tizen Certified Platform to which such
+Contribution(s) was submitted. If You institute patent litigation
+against any entity (including a cross-claim or counterclaim
+in a lawsuit) alleging that the Work or a Contribution incorporated
+within the Work constitutes direct or contributory patent infringement,
+then any patent licenses granted to You under this License for that
+Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution.  You may reproduce and distribute copies of the
+Work or Derivative Works thereof pursuant to the copyright license
+above, in any medium, with or without modifications, and in Source or
+Object form, provided that You meet the following conditions:
+
+  1. You must give any other recipients of the Work or Derivative Works
+     a copy of this License; and
+  2. You must cause any modified files to carry prominent notices stating
+     that You changed the files; and
+  3. You must retain, in the Source form of any Derivative Works that
+     You distribute, all copyright, patent, trademark, and attribution
+     notices from the Source form of the Work, excluding those notices
+     that do not pertain to any part of the Derivative Works; and
+  4. If the Work includes a "NOTICE" text file as part of its distribution,
+     then any Derivative Works that You distribute must include a readable
+     copy of the attribution notices contained within such NOTICE file,
+     excluding those notices that do not pertain to any part of
+     the Derivative Works, in at least one of the following places:
+     within a NOTICE text file distributed as part of the Derivative Works;
+     within the Source form or documentation, if provided along with the
+     Derivative Works; or, within a display generated by the Derivative Works,
+     if and wherever such third-party notices normally appear.
+     The contents of the NOTICE file are for informational purposes only
+     and do not modify the License.
+
+You may add Your own attribution notices within Derivative Works
+that You distribute, alongside or as an addendum to the NOTICE text
+from the Work, provided that such additional attribution notices
+cannot be construed as modifying the License. You may add Your own
+copyright statement to Your modifications and may provide additional or
+different license terms and conditions for use, reproduction, or
+distribution of Your modifications, or for any such Derivative Works
+as a whole, provided Your use, reproduction, and distribution of
+the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+any Contribution intentionally submitted for inclusion in the Work
+by You to the Licensor shall be under the terms and conditions of
+this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify
+the terms of any separate license agreement you may have executed
+with Licensor regarding such Contributions.
+
+6. Trademarks.  This License does not grant permission to use the trade
+names, trademarks, service marks, or product names of the Licensor,
+except as required for reasonable and customary use in describing the
+origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+agreed to in writing, Licensor provides the Work (and each
+Contributor provides its Contributions) on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+implied, including, without limitation, any warranties or conditions
+of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+PARTICULAR PURPOSE. You are solely responsible for determining the
+appropriateness of using or redistributing the Work and assume any
+risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+whether in tort (including negligence), contract, or otherwise,
+unless required by applicable law (such as deliberate and grossly
+negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special,
+incidental, or consequential damages of any character arising as a
+result of this License or out of the use or inability to use the
+Work (including but not limited to damages for loss of goodwill,
+work stoppage, computer failure or malfunction, or any and all
+other commercial damages or losses), even if such Contributor
+has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+the Work or Derivative Works thereof, You may choose to offer,
+and charge a fee for, acceptance of support, warranty, indemnity,
+or other liability obligations and/or rights consistent with this
+License. However, in accepting such obligations, You may act only
+on Your own behalf and on Your sole responsibility, not on behalf
+of any other Contributor, and only if You agree to indemnify,
+defend, and hold each Contributor harmless for any liability
+incurred by, or claims asserted against, such Contributor by reason
+of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Flora License to your work
+
+To apply the Flora License to your work, attach the following
+boilerplate notice, with the fields enclosed by brackets "[]"
+replaced with your own identifying information. (Don't include
+the brackets!) The text should be enclosed in the appropriate
+comment syntax for the file format. We also recommend that a
+file or class name and description of purpose be included on the
+same "printed page" as the copyright notice for easier
+identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Flora License, Version 1.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://floralicense.org/license/
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
diff --git a/NOTICE b/NOTICE
new file mode 100755 (executable)
index 0000000..158c7a0
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,8 @@
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE file for Apache License terms and conditions.
+
+Several source codes may have its original copyright owner and/or
+be licensed under other than Apache License, Version 2, say, Flora License, Version 1.
+Please, see copyright and license comments section in the header of each file,
+and the LICENSE.Flora for Flora License terms and conditions.
\ No newline at end of file
diff --git a/data/.readme b/data/.readme
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/icons/screen-density-xhigh/mainmenu.png b/icons/screen-density-xhigh/mainmenu.png
new file mode 100644 (file)
index 0000000..b0979b1
Binary files /dev/null and b/icons/screen-density-xhigh/mainmenu.png differ
diff --git a/inc/BluetoothConnectivityIpcStub.h b/inc/BluetoothConnectivityIpcStub.h
new file mode 100644 (file)
index 0000000..b0f6769
--- /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       BluetoothConnectivityIpcStub.h
+ * @brief      This is the header file for the %BluetoothConnectivityIpcStub class.
+ *
+ * This header file contains the declarations of the %BluetoothConnectivityIpcStub class.
+ */
+
+#ifndef _BLUETOOTH_CONNECTIVITY_IPC_STUB_H_
+#define _BLUETOOTH_CONNECTIVITY_IPC_STUB_H_
+
+#include <FBaseObject.h>
+#include <FIo_IIpcServerEventListener.h>
+
+namespace Tizen { namespace Base {
+class String;
+} }
+
+namespace Tizen { namespace Io {
+class _IpcServer;
+} }
+
+class BluetoothService;
+
+/**
+ * @class      BluetoothConnectivityIpcStub
+ * @brief      This class represents an IPC stub for the Connectivity daemon service.
+ *
+ * @since      2.1
+ *
+ * This class represents an IPC stub for the Connectivity daemon service.
+ */
+class BluetoothConnectivityIpcStub
+    : public Tizen::Base::Object
+    , public Tizen::Io::_IIpcServerEventListener
+{
+public:
+       BluetoothConnectivityIpcStub(void);
+       virtual ~BluetoothConnectivityIpcStub(void);
+       result Construct(void);
+
+
+       // from _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+private:
+       BluetoothConnectivityIpcStub(const BluetoothConnectivityIpcStub& rhs);
+       BluetoothConnectivityIpcStub& operator =(const BluetoothConnectivityIpcStub& rhs);
+
+       // Bluetooth
+       void OnGetBluetoothLocalDeviceName(Tizen::Base::String* pLocalName, unsigned long* pResult);
+       void OnSetBluetoothLocalDeviceName(Tizen::Base::String localName, unsigned long* pResult);
+       void OnSetBluetoothDiscoverableMode(int mode, int seconds, unsigned long* pResult);
+
+private:
+       BluetoothService* __pBtService;
+       Tizen::Io::_IpcServer* __pIpcServer;
+
+};
+
+#endif // _BLUETOOTH_CONNECTIVITY_IPC_STUB_H_
diff --git a/inc/BluetoothService.h b/inc/BluetoothService.h
new file mode 100644 (file)
index 0000000..51463cd
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       BluetoothService.h
+ * @brief      This is the header file for the %BluetoothService class.
+ *
+ * This header file contains the declarations of the %BluetoothService class.
+ */
+
+#ifndef _BLUETOOTH_SERVICE_H_
+#define _BLUETOOTH_SERVICE_H_
+
+#include <bluetooth.h>
+#include <FBaseString.h>
+#include <FApp_IAppManagerEventListener.h>
+
+/**
+ * @class      BluetoothService
+ * @brief      This class represents %Bluetooth service of the Connectivity service daemon.
+ *
+ * @since 2.1
+ *
+ * This class represents %Bluetooth service of the Connectivity service daemon.
+ */
+class BluetoothService
+       : public Tizen::App::_IAppManagerEventListener
+{
+public:
+       BluetoothService(void);
+       virtual ~BluetoothService(void);
+       result Construct(void);
+
+       result GetLocalDeviceName(Tizen::Base::String* pLocalName);
+       result SetLocalDeviceName(const Tizen::Base::String& clientAppId, const Tizen::Base::String& localName);
+       result SetDiscoverableMode(int mode, int seconds);
+
+       // From _IAppManagerEventListener;
+       virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+       virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+       // Callback used by SLP BT F/W to notify that %Bluetooth is activated on the device.
+       static  void OnBluetoothAdapterStateChanged(int result, bt_adapter_state_e adapterState, void* pUserData);
+private:
+       result UpdateLocalDeviceName(const Tizen::Base::String& name);
+
+private:
+       Tizen::Base::String __nameChangerId;
+       Tizen::Base::String __newName;
+
+};
+
+#endif // _BLUETOOTH_SERVICE_H_
diff --git a/inc/ConnectivityService.h b/inc/ConnectivityService.h
new file mode 100644 (file)
index 0000000..f64d42b
--- /dev/null
@@ -0,0 +1,61 @@
+//\r
+// Open Service Platform\r
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//     http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+/**\r
+ * @file       ConnectivityService.h\r
+ * @brief      This is the header file for the %ConnectivityService class.\r
+ *\r
+ * This header file contains the declarations of the %ConnectivityService class.\r
+ */\r
+\r
+#ifndef _CONNECTIVITY_SERVICE_H_\r
+#define _CONNECTIVITY_SERVICE_H_\r
+\r
+#include <unique_ptr.h>\r
+#include <FAppServiceApp.h>\r
+\r
+// Forward declaration\r
+class NetConnectivityIpcStub;\r
+class WifiConnectivityIpcStub;\r
+class NfcConnectivityIpcStub;\r
+class BluetoothConnectivityIpcStub;\r
+class TelephonyConnectivityIpcStub;\r
+\r
+class ConnectivityService\r
+       : public Tizen::App::ServiceApp\r
+{\r
+public:\r
+       ConnectivityService(void);\r
+       ~ConnectivityService(void);\r
+\r
+\r
+       static Tizen::App::ServiceApp* CreateInstance(void);\r
+\r
+\r
+       virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);\r
+       virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);\r
+\r
+private:\r
+       std::unique_ptr<NetConnectivityIpcStub> __pNetIpcStub;\r
+       std::unique_ptr<WifiConnectivityIpcStub> __pWifiIpcStub;\r
+       std::unique_ptr<NfcConnectivityIpcStub> __pNfcIpcStub;\r
+       std::unique_ptr<BluetoothConnectivityIpcStub> __pBluetoothIpcStub;\r
+       std::unique_ptr<TelephonyConnectivityIpcStub> __pTelephonyIpcStub;\r
+\r
+};\r
+\r
+#endif // _CONNECTIVITY_SERVICE_H_\r
diff --git a/inc/IWifiProximityEventListener.h b/inc/IWifiProximityEventListener.h
new file mode 100644 (file)
index 0000000..7e8b5ad
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       IWifiProximityEventListener.h
+ * @brief   This is the header file for the IWifiProximityEventListener interface.
+ *
+ * This is the header file for the internal interface of Wi-Fi Proximity events.
+ */
+
+#ifndef _IWIFI_PROXIMITY_EVENT_LISTENER_H_
+#define _IWIFI_PROXIMITY_EVENT_LISTENER_H_
+
+/**
+ * @interface   IWifiProximityEventListener
+ * @brief       This interface implements listeners for WifiProximityService internal events.
+ */
+
+class IWifiProximityEventListener:
+       public Tizen::Base::Runtime::IEventListener
+{
+
+public:
+       virtual ~IWifiProximityEventListener(void) {}
+
+    /**
+      * Called to notify the application that the proximity service is activated.
+      */
+    virtual void OnWifiProximityActivated(void) = 0;
+
+    /**
+      * Called to notify the application that the proximity service is deactivated.
+      */
+    virtual void OnWifiProximityDeactivated(void) = 0;
+
+}; // _IWifiManagerEventListener
+
+#endif /* _IWIFI_PROXIMITY_EVENT_LISTENER_H_ */
diff --git a/inc/NetConnectivityIpcStub.h b/inc/NetConnectivityIpcStub.h
new file mode 100644 (file)
index 0000000..ed47d43
--- /dev/null
@@ -0,0 +1,82 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       NetConnectivityIpcStub.h
+ * @brief      This is the header file for the %NetNetConnectivityIpcStub class.
+ *
+ * This header file contains the declarations of the %NetNetConnectivityIpcStub class.
+ */
+
+#ifndef _NET_CONNECTIVITY_IPC_STUB_H_
+#define _NET_CONNECTIVITY_IPC_STUB_H_
+
+#include <FBaseObject.h>
+#include <FNetNetAccountInfo.h>
+#include <FIo_IIpcServerEventListener.h>
+
+namespace Tizen { namespace Base {
+class String;
+} }
+
+namespace Tizen { namespace Io {
+class _IpcServer;
+} }
+
+class NetService;
+
+/**
+ * @class      NetConnectivityIpcStub
+ * @brief      This class represents an IPC stub for the Connectivity daemon service.
+ *
+ * @since      2.1
+ *
+ * This class represents an IPC stub for the Connectivity daemon service.
+ */
+class NetConnectivityIpcStub
+    : public Tizen::Base::Object
+    , public Tizen::Io::_IIpcServerEventListener
+{
+public:
+       NetConnectivityIpcStub(void);
+       virtual ~NetConnectivityIpcStub(void);
+       result Construct(void);
+
+       // from _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+private:
+       NetConnectivityIpcStub(const NetConnectivityIpcStub& rhs);
+       NetConnectivityIpcStub& operator =(const NetConnectivityIpcStub& rhs);
+
+       // Net
+       void OnGetAppNetAccountId(const Tizen::Base::String& profileName, int* pNetAccountId, unsigned long* pResult);
+       void OnSetNetAccountId(int netAccountId, int* pNetAccountId2, unsigned long* pResult);
+       void OnUpdateSystemNetAccount(const Tizen::Base::String& profileName, const Tizen::Net::NetAccountInfo& netAccountInfo,
+                       int bearerType, unsigned long* pResult);
+
+private:
+       NetService* __pNetService;
+       Tizen::Io::_IpcServer* __pIpcServer;
+
+};
+
+#endif // _NET_CONNECTIVITY_IPC_STUB_H_
diff --git a/inc/NetService.h b/inc/NetService.h
new file mode 100644 (file)
index 0000000..e30ef7e
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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    NetService.h
+ * @brief   This is the header file for the %NetService class.
+ *
+ * This header file contains the declarations of the %NetService class.
+ */
+
+#ifndef _NET_SERVICE_H_
+#define _NET_SERVICE_H_
+
+#include <FBaseString.h>
+#include <FNetNetAccountInfo.h>
+#include <FNetNetTypes.h>
+
+/**
+ * @class   NetService
+ * @brief   This class represents Net service of the Connectivity service daemon.
+ *
+ * @since 2.1
+ *
+ * This class represents Net service of the Connectivity service daemon.
+ */
+class NetService
+{
+public:
+    NetService(void);
+
+    virtual ~NetService(void);
+
+    result GetAppNetAccountId(const Tizen::Base::String& profileName, int& netAccountId);
+    result SetNetAccountId(int netAccountId, int& netAccountId2);
+    result UpdateSystemNetAccount(const Tizen::Base::String& profileName, const Tizen::Net::NetAccountInfo& netAccountInfo, int bearerType);
+
+private:
+    void* GetPsProfileHandleN(const Tizen::Base::String& profileName);
+    result ConvertToProfileInfo(void* pProfileHandle, const Tizen::Net::NetAccountInfo& netAccountInfo, int bearerType) const;
+
+};
+
+#endif // _NET_SERVICE_H_
diff --git a/inc/NfcConnectivityIpcStub.h b/inc/NfcConnectivityIpcStub.h
new file mode 100644 (file)
index 0000000..7848297
--- /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       NfcConnectivityIpcStub.h
+ * @brief      This is the header file for the %NfcConnectivityIpcStub class.
+ *
+ * This header file contains the declarations of the %NfcConnectivityIpcStub class.
+ */
+
+#ifndef _NFC_CONNECTIVITY_IPC_STUB_H_
+#define _NFC_CONNECTIVITY_IPC_STUB_H_
+
+#include <FBaseObject.h>
+#include <FIo_IIpcServerEventListener.h>
+
+namespace Tizen { namespace Base {
+class String;
+} }
+
+namespace Tizen { namespace Io {
+class _IpcServer;
+} }
+
+class NfcService;
+
+/**
+ * @class      NfcConnectivityIpcStub
+ * @brief      This class represents an IPC stub for the Connectivity daemon service.
+ *
+ * @since      2.1
+ *
+ * This class represents an IPC stub for the Connectivity daemon service.
+ */
+class NfcConnectivityIpcStub
+    : public Tizen::Base::Object
+    , public Tizen::Io::_IIpcServerEventListener
+{
+public:
+       NfcConnectivityIpcStub(void);
+       virtual ~NfcConnectivityIpcStub(void);
+       result Construct(void);
+
+
+       // from _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+private:
+       NfcConnectivityIpcStub(const NfcConnectivityIpcStub& rhs);
+       NfcConnectivityIpcStub& operator =(const NfcConnectivityIpcStub& rhs);
+
+       // Nfc
+       void OnInitializeNfc(unsigned long* pResult);
+       void OnSetNfcLaunchPopupEnabled(bool enable, unsigned long* pResult);
+       void OnRegisterNfcPushMessage(const Tizen::Base::ByteBuffer& pushMessageBuffer, const Tizen::Base::String& description,
+                       unsigned long* pResult);
+       void OnUnregisterNfcPushMessage(unsigned long* pResult);
+
+private:
+       NfcService* __pNfcService;
+       Tizen::Io::_IpcServer* __pIpcServer;
+
+};
+
+#endif // _NFC_CONNECTIVITY_IPC_STUB_H_
diff --git a/inc/NfcMessagePushDelegate.h b/inc/NfcMessagePushDelegate.h
new file mode 100644 (file)
index 0000000..c4d1a40
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       NfcMessagePushDelegate.h
+ * @brief      This is the header file for the %NfcMessagePushDelegate class.
+ *
+ * This header file contains the declarations of the %NfcMessagePushDelegate class.
+ */
+
+#ifndef _NFC_MESSAGE_PUSH_DELEGATE_H_
+#define _NFC_MESSAGE_PUSH_DELEGATE_H_
+
+#include <vconf.h>
+#include <nfc.h>
+#include <FBaseResult.h>
+#include <FBaseString.h>
+#include <FAppIAppControlEventListener.h>
+
+/**
+ * @class      NfcMessagePushDelegate
+ * @brief      This class represents NFC service of the Connectivity service daemon.
+ *
+ * @since 2.1
+ *
+ * This class represents NFC service of the Connectivity service daemon.
+ */
+class NfcMessagePushDelegate
+       : public Tizen::App::IAppControlEventListener
+{
+public:
+       NfcMessagePushDelegate(void);
+       virtual ~NfcMessagePushDelegate(void);
+
+       void Initialize(void);
+       void Deinitialize(void);
+
+       void InvokeNfcPushUiAppControl(const Tizen::Base::String& iconPath, const Tizen::Base::String& appName, const Tizen::Base::String& description);
+
+       // IAppControlEventListener
+       virtual void OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList);
+
+       static void OnNfcDeviceDiscovered(nfc_discovered_type_e type, nfc_p2p_target_h target, void* pUserData);
+       static void OnNfcReservedPushStateChanged(keynode_t* pKeyNode, void* pUserData);
+       static void OnNdefMessageSent(nfc_error_e res, void* pUserData);
+
+private:
+       void UpdatePushEnabled(void);
+       bool IsHomeScreenAtTopmost(void);
+       void SendReservedMessage(nfc_p2p_target_h targetH);
+
+public:
+       static const wchar_t* _NFC_PUSH_UI_AC_PROVIDER_ID;
+       static const wchar_t* _NFC_PUSH_UI_AC_OPERATION_ID;
+
+private:
+       bool __isPushEnabled;
+       nfc_p2p_target_h __p2pTargetHandle;
+};
+
+#endif // _NFC_MESSAGE_PUSH_DELEGATE_H_
diff --git a/inc/NfcMessageRegisterService.h b/inc/NfcMessageRegisterService.h
new file mode 100644 (file)
index 0000000..d5b84ee
--- /dev/null
@@ -0,0 +1,82 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       NfcMessageRegisterService.h
+ * @brief      This is the header file for the %NfcMessageRegisterService class.
+ *
+ * This header file contains the declarations of the %NfcMessageRegisterService class.
+ */
+
+#ifndef _NFC_MESSAGE_REGISTER_SERVICE_H_
+#define _NFC_MESSAGE_REGISTER_SERVICE_H_
+
+#include <FBaseResult.h>
+#include <FBaseRtMutex.h>
+#include <FBaseString.h>
+#include <FBaseColLinkedListT.h>
+#include <FIoDatabase.h>
+#include <FAppPkgIPackageInstallationEventListener.h>
+
+// forward declarations
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+/**
+ * @class      NfcMessageRegisterService
+ * @brief      This class represents NFC service of the Connectivity service daemon.
+ *
+ * @since 2.1
+ *
+ * This class represents NFC service of the Connectivity service daemon.
+ */
+class NfcMessageRegisterService
+       : public Tizen::App::Package::IPackageInstallationEventListener
+{
+public:
+       NfcMessageRegisterService(void);
+       virtual ~NfcMessageRegisterService(void);
+
+       result Construct(void);
+
+       result RegisterPushMessage(const Tizen::Base::String& appId, const Tizen::Base::ByteBuffer& pushMessageBuffer,
+                       const Tizen::Base::String& description);
+       result UnregisterPushMessage(const Tizen::Base::String& appId);
+
+       // From IPackageInstallationEventListener;
+       virtual void OnPackageInstallationCompleted(const Tizen::App::PackageId& packageId, Tizen::App::Package::PackageInstallationResult installationResult) {}
+       virtual void OnPackageUninstallationCompleted(const Tizen::App::PackageId& packageId, bool uninstallationResult);
+       virtual void OnPackageInstallationInProgress(const Tizen::App::PackageId& packageId, int progress) {}
+
+private:
+       result InitializeAppIdList(void);
+
+public:
+       static const wchar_t* _META_DATA_DB_NAME;
+       static const wchar_t* _PUSH_MESSAGE_DIRECTORY;
+       static const wchar_t* _PUSH_MESSAGE_EXT_NAME;
+
+private:
+       Tizen::Io::Database __rsvdPushDb;
+       Tizen::Base::Runtime::Mutex __appIdListMutex;
+       Tizen::Base::Collection::LinkedListT<Tizen::Base::String> __reserverAppIdList;
+
+};
+
+#endif // _NFC_MESSAGE_REGISTER_SERVICE_H_
diff --git a/inc/NfcService.h b/inc/NfcService.h
new file mode 100644 (file)
index 0000000..0518196
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       NfcService.h
+ * @brief      This is the header file for the %NfcService class.
+ *
+ * This header file contains the declarations of the %NfcService class.
+ */
+
+#ifndef _NFC_SERVICE_H_
+#define _NFC_SERVICE_H_
+
+#include <vconf.h>
+#include <FBaseRtMutex.h>
+#include <FBaseString.h>
+#include <FBaseColLinkedListT.h>
+#include <FApp_IAppManagerEventListener.h>
+
+// forward declarations
+namespace Tizen { namespace Base
+{
+class ByteBuffer;
+} }
+
+class NfcMessageRegisterService;
+class NfcMessagePushDelegate;
+
+/**
+ * @class      NfcService
+ * @brief      This class represents NFC service of the Connectivity service daemon.
+ *
+ * @since 2.1
+ *
+ * This class represents NFC service of the Connectivity service daemon.
+ */
+class NfcService
+       : public Tizen::App::_IAppManagerEventListener
+{
+public:
+       NfcService(void);
+       virtual ~NfcService(void);
+       result Construct(void);
+
+       result AddNfcAppId(const Tizen::Base::String& appId);
+       result SetLaunchPopupEnabled(const Tizen::Base::String& clientAppId, bool enable);
+       result RegisterPushMessage(const Tizen::Base::String& clientAppId, const Tizen::Base::ByteBuffer& pushMessageBuffer,
+                       const Tizen::Base::String& description);
+       result UnregisterPushMessage(const Tizen::Base::String& clientAppId);
+
+       void RemoveNfcAppId(const Tizen::Base::String& appId);
+
+       // From _IAppManagerEventListener;
+       virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+       virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+
+       static void OnNfcActivationChanged(keynode_t* pKeyNode, void* pUserData);
+
+private:
+       NfcMessageRegisterService* __pRegisterService;
+       NfcMessagePushDelegate* __pPushDelegate;
+       Tizen::Base::Runtime::Mutex __enablingMutex;
+       bool __popupEnabled;
+       Tizen::Base::String __serviceDaemonAppId;
+       Tizen::Base::String __popupDisablerId;
+       Tizen::Base::Runtime::Mutex __appIdListMutex;
+       Tizen::Base::Collection::LinkedListT<Tizen::Base::String> __appIdList;
+
+};
+
+#endif // _NFC_SERVICE_H_
diff --git a/inc/TelephonyConnectivityIpcStub.h b/inc/TelephonyConnectivityIpcStub.h
new file mode 100644 (file)
index 0000000..192e31a
--- /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       TelephonyConnectivityIpcStub.h
+ * @brief      This is the header file for the %TelephonyConnectivityIpcStub class.
+ *
+ * This header file contains the declarations of the %TelephonyConnectivityIpcStub class.
+ */
+
+#ifndef _TELEPHONY_CONNECTIVITY_IPC_STUB_H_
+#define _TELEPHONY_CONNECTIVITY_IPC_STUB_H_
+
+#include <FBaseObject.h>
+#include <FNetNetAccountInfo.h>
+#include <FIo_IIpcServerEventListener.h>
+
+namespace Tizen { namespace Base {
+class String;
+} }
+
+namespace Tizen { namespace Io {
+class _IpcServer;
+} }
+
+class TelephonyService;
+
+/**
+ * @class      TelephonyConnectivityIpcStub
+ * @brief      This class represents an IPC stub for the Connectivity daemon service.
+ *
+ * @since 2.1
+ *
+ * This class represents an IPC stub for the Connectivity daemon service.
+ */
+class TelephonyConnectivityIpcStub
+    : public Tizen::Base::Object
+    , public Tizen::Io::_IIpcServerEventListener
+{
+public:
+       TelephonyConnectivityIpcStub(void);
+       virtual ~TelephonyConnectivityIpcStub(void);
+       result Construct(void);
+
+    result SendNetworkSelectionModeReceived(int clientId, bool isManual, unsigned long res);
+    result SendNetworkSelectionCompleted(int clientId, unsigned long res);
+    result SendNetworkSearchCompleted(int clientId, Tizen::Base::String message, unsigned long res);
+
+    result SendCallForwardNumberReceived(int clientId, Tizen::Base::String phoneNumber, unsigned long res);
+    result SendCallForwardResponseReceived(int clientId, Tizen::Base::String phoneNumber, unsigned long res);
+    result SendCallForwardStopped(int clientId, Tizen::Base::String phoneNumber, unsigned long res);
+
+
+       // from _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+private:
+       TelephonyConnectivityIpcStub(const TelephonyConnectivityIpcStub& rhs);
+       TelephonyConnectivityIpcStub& operator =(const TelephonyConnectivityIpcStub& rhs);
+
+       // Telephony
+       void OnGetTelephonyImsi(Tizen::Base::String* pImsi, unsigned long* pResult);
+       void OnHasTelephonySystemPrivilege(unsigned long* pResult);
+       void OnGetTelephonyNetworkSelectionMode(unsigned long* pResult);
+       void OnSelectTelephonyNetworkManual(const Tizen::Base::String& plmn, const int networkType, unsigned long* pResult);
+       void OnSelectTelephonyNetworkAutomatic(unsigned long* pResult);
+       void OnSearchTelephonyNetwork(unsigned long* pResult);
+       void OnHasCallForwardPrivilege(unsigned long* pResult);
+       void OnRequestCallForward(const Tizen::Base::String& phoneNumber, unsigned long* pResult);
+       void OnStopCallForward(unsigned long* pResult);
+       void OnGetCallForwardNumber(unsigned long* pResult);
+
+private:
+       TelephonyService* __pTelephonyService;
+       Tizen::Io::_IpcServer* __pIpcServer;
+
+};
+
+#endif // _TELEPHONY_CONNECTIVITY_IPC_STUB_H_
diff --git a/inc/TelephonyService.h b/inc/TelephonyService.h
new file mode 100644 (file)
index 0000000..3b969fc
--- /dev/null
@@ -0,0 +1,120 @@
+//
+// 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    TelephonyService.h
+ * @brief   This is the header file for the %TelephonyService class.
+ *
+ * This header file contains the declarations of the %TelephonyService class.
+ */
+
+#ifndef _TELEPHONY_SERVICE_H_
+#define _TELEPHONY_SERVICE_H_
+
+#include <tapi_type.h>
+#include <TelNetwork.h>
+#include <FBaseString.h>
+
+
+class TelephonyConnectivityIpcStub;
+
+/**
+ * @class   TelephonyService
+ * @brief   This class represents Telephony service of the Connectivity service daemon.
+ *
+ * @since 2.1
+ *
+ * This class represents Wi-Fi service of the Connectivity service daemon.
+ */
+class TelephonyService
+{
+public:
+    static TelephonyService* GetInstance(void);
+
+    result Construct(TelephonyConnectivityIpcStub* pStub);
+
+    result GetImsi(Tizen::Base::String* pImsi);
+    result GetNetworkSelectionMode(int clientId);
+    result SelectNetwork(int clientId, const Tizen::Base::String& plmn, int networkType);
+    result SelectNetwork(int clientId);
+    result SearchNetwork(int clientId);
+
+    result RequestCallForward(int clientId, const Tizen::Base::String& phoneNumber);
+    result StopCallForward(int clientId);
+    result GetCallForwardNumber(int clientId);
+
+    static void OnNetworkSelectionModeReceived(TapiHandle* pHandle, int err, void* pData, void* pUserData);
+    static void OnNetworkSelectCompleted(TapiHandle* pHandle, int err, void* pData, void* pUserData);
+    static void OnNetworkSearchCompleted(TapiHandle* pHandle, int err, void* pData, void* pUserData);
+
+    /**
+     * Called when a call forward number is received.
+     *
+     * @param[in] pHandle   The call handle.
+     * @param[in] err    The enumeration of errors
+     * @param[in] pData     The values for call forwarding record
+     * @param[in] pUserData The user data passed from the callback registration function
+     *
+     * @see GetCallForwardNumber()
+     */
+    static void OnCallForwardNumberReceivedCallback(TapiHandle* pHandle, int err, void* pData, void* pUserData);
+
+    /**
+     * Called when the status of a call is changed.
+     *
+     * @param[in] pHandle   The call handle.
+     * @param[in] err    The enumeration of errors
+     * @param[in] pData     The values for call forwarding record
+     * @param[in] pUserData The user data passed from the callback registration function
+     *
+     * @see RequestCallForward()
+     */
+    static void OnCallForwardResponseReceivedCallback(TapiHandle* pHandle, int err, void* pData, void* pUserData);
+
+    /**
+     * Called when the status of a call is changed.
+     *
+     * @param[in] pHandle   The call handle.
+     * @param[in] err    The enumeration of errors
+     * @param[in] pData     The values for call forwarding record
+     * @param[in] pUserData The user data passed from the callback registration function
+     *
+     * @see StopCallForward()
+     */
+    static void OnCallForwardStoppedCallback(TapiHandle* pHandle, int err, void* pData, void* pUserData);
+
+
+
+
+    static Tizen::Base::String MakeNetworkInfoMessage(TelNetworkIdentity_t& info);
+    static result ConvertError(int err);
+
+
+private:
+    TelephonyService(void);
+    virtual ~TelephonyService(void);
+    static void InitTelephonyService();
+
+private:
+    Tizen::Base::String __imsi;
+    TapiHandle* __pHandle;
+    TelephonyConnectivityIpcStub* __pStub;
+
+    static TelephonyService* __pTelephonyService;
+};
+
+#endif // _WIFI_SERVICE_H_
diff --git a/inc/WifiConnectivityIpcStub.h b/inc/WifiConnectivityIpcStub.h
new file mode 100644 (file)
index 0000000..bd412be
--- /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       WifiConnectivityIpcStub.h
+ * @brief      This is the header file for the %WifiConnectivityIpcStub class.
+ *
+ * This header file contains the declarations of the %WifiConnectivityIpcStub class.
+ */
+
+#ifndef _WIFI_CONNECTIVITY_IPC_STUB_H_
+#define _WIFI_CONNECTIVITY_IPC_STUB_H_
+
+#include <unique_ptr.h>
+#include <FBaseObject.h>
+#include <FIo_IIpcServerEventListener.h>
+
+namespace Tizen { namespace Base {
+class String;
+} }
+
+namespace Tizen { namespace Io {
+class _IpcServer;
+} }
+
+namespace Tizen { namespace Net { namespace Wifi {
+class WifiBssInfo;
+} } }
+
+class WifiService;
+class WifiProximityService;
+
+/**
+ * @class      WifiConnectivityIpcStub
+ * @brief      This class represents an IPC stub for the Connectivity daemon service.
+ *
+ * @since      2.1
+ *
+ * This class represents an IPC stub for the Connectivity daemon service.
+ */
+class WifiConnectivityIpcStub
+    : public Tizen::Base::Object
+    , public Tizen::Io::_IIpcServerEventListener
+{
+public:
+       WifiConnectivityIpcStub(void);
+       virtual ~WifiConnectivityIpcStub(void);
+       result Construct(void);
+
+    result SendProximityCheckActivated(int clientId);
+    result SendProximityCheckDeactivated(int clientId);
+    result SendWifiBssDetected(int clientId, const Tizen::Net::Wifi::WifiBssInfo& wifiBssInfo);
+    result SendWifiBssLost(int clientId, const Tizen::Base::String& bssId);
+
+       // from _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+private:
+       WifiConnectivityIpcStub(const WifiConnectivityIpcStub& rhs);
+       WifiConnectivityIpcStub& operator =(const WifiConnectivityIpcStub& rhs);
+
+       // Wifi
+       void OnSetWifiSystemScanMode(int mode, unsigned long* pResult);
+       void OnCheckWifiSystemSettingPrivilege(unsigned long* pResult);
+       void OnUpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo, unsigned long* pResult);
+       void OnInitializeWifiDirect(unsigned long* pResult);
+       void OnGetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName, unsigned long* pResult);
+       void OnSetWifiDirectLocalDeviceName(Tizen::Base::String localName, unsigned long* pResult);
+
+       // WifiProximity
+       void OnRegisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult);
+       void OnUnregisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult);
+       void OnProximityCheckActivated(unsigned long* pResult);
+       void OnProximityCheckDeactivated(unsigned long* pResult);
+       void OnIsProximityCheckActivated(bool* pIsActivated, unsigned long* pResult);
+
+private:
+       std::unique_ptr<WifiProximityService> __pWifiProximityService;
+       std::unique_ptr<WifiService> __pWifiService;
+       std::unique_ptr<Tizen::Io::_IpcServer> __pIpcServer;
+
+};
+
+#endif // _WIFI_CONNECTIVITY_IPC_STUB_H_
diff --git a/inc/WifiProximityEvent.h b/inc/WifiProximityEvent.h
new file mode 100644 (file)
index 0000000..f18d4b4
--- /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        WifiProximityEvent.h
+ * @brief       This is the header file for the WifiProximityEvent class.
+ *
+ * This header file contains the declarations of the WifiProximityEvent class.
+ * The WifiProximityEvent class can call a method of a listener (IWifiProximityEventListener).
+ * So, when the event is occurred, listener instances can handle it appropriately.
+ */
+
+#ifndef _WIFI_PROXIMITY_EVENT_H_
+#define _WIFI_PROXIMITY_EVENT_H_
+
+#include <FBaseRt_Event.h>
+
+/**
+ * @class   WifiProximityEvent
+ * @brief   This class handles Wi-Fi proximity events.
+ *
+ * When a Wi-Fi proximity event occurs, the WifiProximityEvent object finds an
+ * IWifiProximityEventListener object and calls an appropriate method of the listener.
+ */
+class WifiProximityEvent:
+    public Tizen::Base::Runtime::_Event
+{
+
+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.
+        */
+       WifiProximityEvent(void);
+
+       /**
+        * This destructor overrides Tizen::Base::Runtime::_Event::~_Event().
+        */
+       virtual ~WifiProximityEvent(void);
+
+       /**
+        * Initializes this instance.
+        */
+       result Construct(void);
+
+protected:
+       /**
+        * Checks the arg and finds out the type of event. After that this method calls appropriate pListener's method.
+        *
+        * @param[in]   listener        An event listener (IWifiProximityEventListener)
+        * @param[in]   arg             An argument-like instance of Wi-Fi proximity event retransmitted to the listener's method.
+        * @exception   E_SUCCESS       The method is successful.
+        * @exception   E_INVALID_ARG   The argument passed to a method contains an invalid value.
+        */
+       void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
+
+private:
+       WifiProximityEvent(const WifiProximityEvent& rhs);
+       WifiProximityEvent& operator=(const WifiProximityEvent& rhs);
+
+}; // WifiProximityEvent
+
+#endif // _WIFI_PROXIMITY_EVENT_H_
diff --git a/inc/WifiProximityEventArg.h b/inc/WifiProximityEventArg.h
new file mode 100644 (file)
index 0000000..e7fc5ac
--- /dev/null
@@ -0,0 +1,82 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file    WifiProximityEventArg.h
+ * @brief   This is the header file for the WifiProximityEventArg class.
+ *
+ * This header file contains the declarations of the WifiProximityEventArg class which includes information to be
+ * passed to the event listeners
+ */
+#ifndef _WIFI_PROXIMITY_EVENT_ARG_H_
+#define _WIFI_PROXIMITY_EVENT_ARG_H_
+
+#include <FBaseObject.h>
+//#include <FOspConfig.h>
+#include <FBaseRtIEventArg.h>
+
+/**
+ * @enum    WifiProximityEventType
+ * Type for specifying the type of WifiProximityEvent
+ */
+enum WifiProximityEventType
+{
+       WIFI_PROXIMITY_EVENT_ACTIVATED,     /**< For notifying that Wi-Fi proximity checking is activated */
+       WIFI_PROXIMITY_EVENT_DEACTIVATED    /**< For notifying that Wi-Fi proximity checking is deactivated */
+};
+
+/**
+ * @class   WifiProximityEventArg
+ * @brief   This class is used as an argument for callback methods of the IWifiProximityEventListener class.
+ *
+ * When a WifiProximityEvent occurs, the WifiProximityEvent finds a IWifiProximityEventListener instance
+ * which is registered for the WifiProximityEvent and calls an appropriate method of the listener.
+ */
+class WifiProximityEventArg
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::IEventArg
+{
+public:
+       /**
+        * This is a class constructor.
+        *
+        * @param[in]    type              The type of the event
+        */
+       WifiProximityEventArg(WifiProximityEventType type);
+
+       /**
+        * This is the class destructor.
+        */
+       ~WifiProximityEventArg(void);
+
+       /**
+        * Gets the type of this event.
+        *
+        * @return      The type of the event
+        */
+       WifiProximityEventType GetEventType(void) const;
+
+private:
+       WifiProximityEventArg(void);
+       WifiProximityEventArg(const WifiProximityEventArg& eventArg);
+       WifiProximityEventArg& operator =(const WifiProximityEventArg& rValue);
+
+private:
+       WifiProximityEventType __evtType;
+
+}; // WifiProximityEventArg
+
+#endif // _WIFI_PROXIMITY_EVENT_ARG_H_
diff --git a/inc/WifiProximityService.h b/inc/WifiProximityService.h
new file mode 100644 (file)
index 0000000..de3c039
--- /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       WifiProximityService.h
+ * @brief      This is the header file for the %WifiProximityService class.
+ *
+ * This header file contains the declarations of the %WifiProximityService class.
+ */
+
+#ifndef _WIFI_PROXIMITY_SERVICE_H_
+#define _WIFI_PROXIMITY_SERVICE_H_
+
+#include <wifi.h>
+#include <FBaseRtTimer.h>
+#include <FBaseRtITimerEventListener.h>
+#include <FBaseColHashMapT.h>
+#include <FBaseColMultiHashMapT.h>
+#include "IWifiProximityEventListener.h"
+#include "WifiProximityEvent.h"
+
+namespace Tizen { namespace Base
+{
+class String;
+} }
+
+class ConnectivityIpcStub;
+
+class WifiProximityService
+       : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::ITimerEventListener
+       , public IWifiProximityEventListener
+{
+public:
+       WifiProximityService(void);
+       virtual ~WifiProximityService(void);
+       result Construct(WifiConnectivityIpcStub* pStub);
+
+       result RegisterBssId(const Tizen::Base::String& macAddress, const int clientId);
+       result UnregisterBssId(const Tizen::Base::String& macAddress, const int clientId);
+       result UnregisterClient(const int clientId);
+       result ActivateProximityCheck(const int clientId);
+       result DeactivateProximityCheck(const int clientId);
+       bool IsProximityCheckActivated(void) const;
+
+       // from ITimerEventListener
+       virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+
+       // from IWifiProximityServiceEventListener
+       virtual void OnWifiProximityActivated(void);
+    virtual void OnWifiProximityDeactivated(void);
+
+    // callback methods that the underlying system defines
+       static void OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData);
+       static void OnWifiScanCompleted(wifi_error_e error_code, void* pUserData);
+       static bool OnWifiEachAccessPointFound(wifi_ap_h apHandler, void* pUserData);
+
+private:
+       result ScanAndResetTimer(void);
+       result ResetTimer(void);
+       void CheckingProximityStatusChanged(void);
+
+private:
+       Tizen::Base::Collection::HashMapT<int, bool> __clientStateMap;
+       Tizen::Base::Collection::MultiHashMapT<Tizen::Base::String, int> __bssClientMap;
+       Tizen::Base::Collection::HashMapT<Tizen::Base::String, bool> __bssDetectionMap;
+       Tizen::Base::Runtime::Timer __timer;
+       WifiConnectivityIpcStub* __pStub;
+       WifiProximityEvent __proxEvent;
+
+       bool __isWifiActivated;
+       bool __isProximityCheckActivated;
+       bool __isTimerOn;
+};
+
+#endif // _WIFI_PROXIMITY_SERVICE_H_
diff --git a/inc/WifiService.h b/inc/WifiService.h
new file mode 100644 (file)
index 0000000..2f7ed2e
--- /dev/null
@@ -0,0 +1,82 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       WifiService.h
+ * @brief      This is the header file for the %WifiService class.
+ *
+ * This header file contains the declarations of the %WifiService class.
+ */
+
+#ifndef _WIFI_SERVICE_H_
+#define _WIFI_SERVICE_H_
+
+#include <wifi.h>
+#include <FBaseString.h>
+#include <FBaseRtMutex.h>
+#include <FBaseColLinkedList.h>
+#include <FApp_IAppManagerEventListener.h>
+
+namespace Tizen { namespace Net { namespace Wifi {
+class WifiBssInfo;
+} } }
+
+/**
+ * @class      WifiService
+ * @brief      This class represents Wi-Fi service of the Connectivity service daemon.
+ *
+ * @since 2.1
+ *
+ * This class represents Wi-Fi service of the Connectivity service daemon.
+ */
+class WifiService
+       : public Tizen::App::_IAppManagerEventListener
+{
+public:
+       WifiService(void);
+       virtual ~WifiService(void);
+       result Construct(void);
+
+       result SetWifiSystemScanMode(int mode);
+       result UpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo);
+       result Initialize(const Tizen::Base::String& clientAppId);
+       result GetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName);
+       result SetWifiDirectLocalDeviceName(const Tizen::Base::String& clientAppId, const Tizen::Base::String& localName);
+
+       // Callback used by SLP Wi-Fi Direct F/W to notify that Wi-Fi Direct is activated on the device.
+       void OnWifiDirectActivated(void);
+
+       // From _IAppManagerEventListener;
+       virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+       virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type);
+
+    static bool OnWifiEachAccessPointFound(wifi_ap_h apHandle, void* pUserData);
+
+private:
+       result UpdateWifiDirectLocalDeviceName(const Tizen::Base::String& name);
+       bool IsWifiDirectActivated(void) const;
+       wifi_ap_h GetApHandle(const Tizen::Base::String& bssId);
+
+private:
+       Tizen::Base::String __newWifiDirectName;
+       Tizen::Base::String __wifiDirectNameChangerId;
+       Tizen::Base::Runtime::Mutex __appIdListMutex;
+       Tizen::Base::Collection::LinkedList __appIdList;
+
+};
+
+#endif // _WIFI_SERVICE_H_
diff --git a/manifest.xml b/manifest.xml
new file mode 100644 (file)
index 0000000..b2d7226
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Manifest xmlns="http://schemas.tizen.org/2012/06/manifest">
+    <Id>57r43275q7</Id>
+    <Version>1.0.0</Version>
+    <Type>C++App</Type>
+    <Vendors>
+        <Vendor Locale="eng-GB">Samsung Electronics</Vendor>
+    </Vendors>
+    <Descriptions>
+        <Description Locale="eng-US">Connectivity service daemon</Description>
+    </Descriptions>
+    <Url/>
+    <Requirements>
+        <Feature Name="tizen.platform.core.cpu.arch">armv7</Feature>
+    </Requirements>
+    <Apps>
+        <ApiVersion>2.1</ApiVersion>
+        <Secret>42E1041F4B5834A70EE443351DCEC1A9</Secret>
+        <Privileges/>
+        <ServiceApp AutoRestart="False" Default="True" ExecutableName="osp-connectivity-service" LaunchOnBoot="False">
+            <Names>
+                <Name Locale="eng-GB">osp-connectivity-service</Name>
+            </Names>
+            <Icons/>
+            <AppControls/>
+            <DataControls/>
+            <LaunchConditions/>
+            <Notifications/>
+        </ServiceApp>
+    </Apps>
+</Manifest>
diff --git a/osp-connectivity-service.manifest b/osp-connectivity-service.manifest
new file mode 100644 (file)
index 0000000..3620fbd
--- /dev/null
@@ -0,0 +1,12 @@
+<manifest>
+       <define>
+               <domain name="osp-connectivity-service"/>
+       </define>
+       <request>
+               <domain name="osp-connectivity-service"/>
+       </request>
+       <assign>
+               <filesystem path="/usr/apps/57r43275q7/bin/osp-connectivity-service.exe" label="osp-connectivity-service" exec_label="osp-connectivity-service"/>
+               <filesystem path="/usr/share/license/osp-connectivity-service" label="_"/>
+       </assign>
+</manifest>
\ No newline at end of file
diff --git a/packaging/osp-connectivity-service.spec b/packaging/osp-connectivity-service.spec
new file mode 100755 (executable)
index 0000000..b1e7657
--- /dev/null
@@ -0,0 +1,86 @@
+Name:          osp-connectivity-service
+Summary:       osp connectivity service
+Version:       1.2.1.0
+Release:       2
+Group:         TO_BE/FILLED_IN
+License:       TO_BE/FILLED_IN
+Source0:       %{name}-%{version}.tar.gz
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(chromium)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(capi-telephony-sim)
+BuildRequires:  pkgconfig(wifi-direct)
+BuildRequires:  pkgconfig(capi-network-wifi)
+BuildRequires:  pkgconfig(capi-network-nfc)
+BuildRequires:  pkgconfig(capi-network-bluetooth)
+BuildRequires:  pkgconfig(capi-network-connection)
+BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(capi-system-device)
+BuildRequires:  pkgconfig(osp-appfw)
+BuildRequires:  osp-appfw-internal-devel
+BuildRequires:  pkgconfig(osp-net)
+BuildRequires:  osp-net-internal-devel
+BuildRequires:  pkgconfig(osp-nfc)
+BuildRequires:  osp-nfc-internal-devel
+BuildRequires:  pkgconfig(osp-bluetooth)
+BuildRequires:  osp-bluetooth-internal-devel
+BuildRequires:  pkgconfig(osp-telephony)
+BuildRequires:  osp-telephony-devel
+BuildRequires:  osp-telephony-internal-devel
+BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(tapi)
+BuildRequires:  pkgconfig(pkgmgr)
+BuildRequires:  pkgconfig(evas)
+BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(capi-appfw-app-manager)
+
+# runtime requires
+Requires: osp-appfw 
+Requires: osp-installer 
+Requires: osp-app-service
+Requires: osp-channel-service
+
+%description
+osp connectivity service
+
+%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}
+%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}
+%endif
+
+# Call make instruction with smp support
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+cp %{_builddir}/%{name}-%{version}/LICENSE.Flora  %{buildroot}/usr/share/license/%{name}
+cat %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 >> %{buildroot}/usr/share/license/%{name}
+
+%make_install
+
+%post
+mkdir -p /opt/usr/share/nfcpush
+
+/bin/rm -fr /opt/apps/57r43275q7
+
+/usr/etc/package-manager/backend/tpk -i /usr/apps/57r43275q7
+cp -f /usr/lib/osp/osp-system-service-loader /usr/apps/57r43275q7/bin/osp-connectivity-service
+if [ -f /usr/lib/rpm-plugins/msm.so ]
+then
+       chsmack -a osp-connectivity-service /usr/apps/57r43275q7/bin/osp-connectivity-service
+       chsmack -e osp-connectivity-service /usr/apps/57r43275q7/bin/osp-connectivity-service
+fi
+
+#%postun -p /sbin/ldconfig
+
+%files
+%manifest osp-connectivity-service.manifest
+/usr/share/license/%{name}
+/usr/apps/*
diff --git a/src/BluetoothConnectivityIpcMessages.cpp b/src/BluetoothConnectivityIpcMessages.cpp
new file mode 100644 (file)
index 0000000..5dd005e
--- /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    BluetoothConnectivityIpcMessages.cpp
+ * @brief   This is the generator of IPC messages for the Connectivity service daemon.
+ */
+
+#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/BluetoothConnectivityIpcStub.cpp b/src/BluetoothConnectivityIpcStub.cpp
new file mode 100644 (file)
index 0000000..875f6b1
--- /dev/null
@@ -0,0 +1,196 @@
+//
+// 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    BluetoothConnectivityIpcStub.cpp
+ * @brief   This is the implementation file for the %BluetoothConnectivityIpcStub class.
+ */
+#include <unique_ptr.h>
+#include <FBaseSysLog.h>
+#include <FIo_IpcServer.h>
+#include <FNetBt_ConnectivityIpcMessages.h>
+#include <FIo_IpcCommonParamTraits.h>
+#include <FSec_AccessController.h>
+#include "BluetoothConnectivityIpcStub.h"
+#include "BluetoothService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+using namespace Tizen::Net;
+
+BluetoothConnectivityIpcStub::BluetoothConnectivityIpcStub(void)
+       : __pBtService(null)
+       , __pIpcServer(null)
+{
+}
+
+BluetoothConnectivityIpcStub::~BluetoothConnectivityIpcStub(void)
+{
+       delete __pIpcServer;
+       delete __pBtService;
+}
+
+result
+BluetoothConnectivityIpcStub::Construct(void)
+{
+       result r = E_SUCCESS;
+       result retVal = E_SUCCESS;
+
+       __pBtService = new (std::nothrow) BluetoothService;
+       SysTryCatch(NID_NET_BT, __pBtService != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = __pBtService->Construct();
+       if (r == E_SUCCESS)
+       {
+               SysLog(NID_NET_BT, "BluetoothService is created.");
+       }
+       else
+       {
+               // skip Bluetooth service
+               SysLogException(NID_NET_BT, r, "[%s] Failed to construct BluetoothService.", GetErrorMessage(r));
+               delete __pBtService;
+               __pBtService = null;
+       }
+
+       __pIpcServer = new (std::nothrow) _IpcServer;
+       SysTryCatch(NID_NET_BT, __pIpcServer != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = __pIpcServer->Construct(BLUETOOTH_CONNECTIVITY_IPC_SERVER_NAME, *this);
+       SysTryCatch(NID_NET_BT, r == E_SUCCESS, retVal = E_SYSTEM, E_SYSTEM,
+                       "[%s] A system error has been occurred. Failed to construct IpcServer.", GetErrorMessage(E_SYSTEM));
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+
+       delete __pBtService;
+       __pBtService = null;
+
+       return retVal;
+}
+
+void
+BluetoothConnectivityIpcStub::OnIpcServerStarted(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET_BT, "BluetoothConnectivityIpcStub started.");
+}
+
+void
+BluetoothConnectivityIpcStub::OnIpcServerStopped(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET_BT, "BluetoothConnectivityIpcStub stopped.");
+}
+
+void
+BluetoothConnectivityIpcStub::OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId)
+{
+       SysLog(NID_NET_BT, "Connected with clientId[%d].", clientId);
+}
+
+void
+BluetoothConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId)
+{
+       SysLog(NID_NET_BT, "Disconnected with clientId[%d].", clientId);
+}
+
+void
+BluetoothConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message)
+{
+       IPC_BEGIN_MESSAGE_MAP(BluetoothConnectivityIpcStub, message)
+       IPC_MESSAGE_HANDLER(ConnectivityBluetoothServiceMsg_getLocalDeviceName, OnGetBluetoothLocalDeviceName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityBluetoothServiceMsg_setLocalDeviceName, OnSetBluetoothLocalDeviceName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityBluetoothServiceMsg_setDiscoverableMode, OnSetBluetoothDiscoverableMode, &server)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+BluetoothConnectivityIpcStub::OnGetBluetoothLocalDeviceName(Tizen::Base::String* pLocalName, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_BT, "Received the request of getting the local device name with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pBtService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pBtService->GetLocalDeviceName(pLocalName);
+       }
+#else
+       SysLog(NID_NET_BT, "Invalid Operation because Bluetooth is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+BluetoothConnectivityIpcStub::OnSetBluetoothLocalDeviceName(Tizen::Base::String localName, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_BT, "Received the request of setting the local device name with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pBtService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pBtService->SetLocalDeviceName(__pIpcServer->GetClientAppId(), localName);
+       }
+#else
+       SysLog(NID_NET_BT, "Invalid Operation because Bluetooth is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+BluetoothConnectivityIpcStub::OnSetBluetoothDiscoverableMode(int mode, int seconds, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_BT, "Received the request of setting the discoverable mode with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       String appId = __pIpcServer->GetClientAppId();
+
+       *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_BLUETOOTHMANAGER);
+
+       if (*pResult != E_SUCCESS)
+       {
+               *pResult = E_PRIVILEGE_DENIED;
+               SysLogException(NID_NET_BT, E_PRIVILEGE_DENIED,
+                               "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+       }
+       else if (__pBtService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pBtService->SetDiscoverableMode(mode, seconds);
+       }
+#else
+       SysLog(NID_NET_BT, "Invalid Operation because Bluetooth is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
diff --git a/src/BluetoothService.cpp b/src/BluetoothService.cpp
new file mode 100644 (file)
index 0000000..53675be
--- /dev/null
@@ -0,0 +1,251 @@
+//
+// 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    BluetoothService.cpp
+ * @brief   This is the implementation file for the %BluetoothService class.
+ */
+
+#include <glib.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <FBaseUtilStringUtil.h>
+#include <FBaseSysLog.h>
+#include <FApp_AppManagerImpl.h>
+#include <FSys_SystemInfoImpl.h>
+#include <FBase_StringConverter.h>
+#include "BluetoothService.h"
+
+static const int BLUETOOTH_DEVICE_NAME_LENGTH_MAX = 248;
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::App;
+using namespace Tizen::Io;
+using namespace Tizen::System;
+
+BluetoothService::BluetoothService(void)
+       : __nameChangerId()
+       , __newName()
+{
+}
+
+BluetoothService::~BluetoothService(void)
+{
+       (void) bt_deinitialize();
+       (void) bt_adapter_unset_state_changed_cb();
+       (void) _AppManagerImpl::GetInstance()->RemoveEventListener(*this);
+}
+
+result
+BluetoothService::Construct(void)
+{
+       result r = E_SUCCESS;
+       int ret = 0;
+       bool isBtSupported = false;
+
+       r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"BluetoothSupported", isBtSupported);
+       TryReturn((r == E_SUCCESS) && (isBtSupported == true), E_UNSUPPORTED_OPERATION,
+                       "[E_UNSUPPORTED_OPERATION] Bluetooth is not supported.");
+
+       // No need to unregister the callback method when BluetoothService::Construct() fails
+       // because BluetoothService instance will be removed instantly
+       ret = bt_initialize();
+       SysTryReturnResult(NID_NET_BT, ret == BT_ERROR_NONE, E_SYSTEM,
+                                       "Initialize of Bluetooth has failed.");
+
+       ret = bt_adapter_set_state_changed_cb(OnBluetoothAdapterStateChanged, this);
+       SysTryReturnResult(NID_NET_BT, ret == BT_ERROR_NONE, E_SYSTEM,
+                                       "Registration of a Bluetooth callback method has failed.");
+
+       r = _AppManagerImpl::GetInstance()->AddEventListener(*this);
+       SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM,
+                                       "Registration of an _IAppManagerEventListener has failed.");
+
+       return E_SUCCESS;
+}
+
+result
+BluetoothService::GetLocalDeviceName(Tizen::Base::String* pLocalName)
+{
+       result r = E_SYSTEM;
+       int ret = 0;
+       char* localName  = null;
+       char* pPhoneName = null;
+       bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
+
+       // Gets the local name from the underlying Bluetooth subsystem, if BT is on.
+       ret = bt_adapter_get_state(&adapter_state);
+
+       if (ret == BT_ERROR_NONE && adapter_state == BT_ADAPTER_ENABLED)
+       {
+               ret = bt_adapter_get_name(&localName);
+               SysTryReturnResult(NID_NET_BT, ret == BT_ERROR_NONE, E_SYSTEM,  "Getting the local name of Bluetooth has failed");
+
+               // Converts the UTF8 multibyte string to Unicode String
+               r = StringUtil::Utf8ToString(localName, *pLocalName);
+       }
+       // Gets the name to be set, if BT is off and there is the name set by an application
+       else if (__newName.GetLength() > 0)
+       {
+               *pLocalName = __newName;
+               r = E_SUCCESS;
+       }
+       // Gets the phone name from the system info
+       else
+       {
+               pPhoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+        SysTryReturnResult(NID_NET_BT, pPhoneName != null, E_SYSTEM,  "Getting the phone name has failed");
+
+               // Converts the UTF8 multibyte string to Unicode String
+               r = StringUtil::Utf8ToString(pPhoneName, *pLocalName);
+               free(pPhoneName);
+       }
+
+       return r;
+}
+
+result
+BluetoothService::SetLocalDeviceName(const Tizen::Base::String& clientAppId, const Tizen::Base::String& localName)
+{
+       result r = E_SUCCESS;
+       int ret = 0;
+       bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
+
+       // Updates the local name instantly if the Bluetooth is turned on.
+       // Saves the setting name for the later use, otherwise.
+       ret = bt_adapter_get_state(&adapter_state);
+
+       if (ret == BT_ERROR_NONE && adapter_state == BT_ADAPTER_ENABLED)
+       {
+               r = UpdateLocalDeviceName(localName);
+               if (!IsFailed(r))
+               {
+                       __newName = localName;
+                       __nameChangerId = clientAppId;
+               }
+       }
+       else
+       {
+               __newName = localName;
+               __nameChangerId = clientAppId;
+       }
+
+       return r;
+}
+
+result
+BluetoothService::SetDiscoverableMode(int mode, int seconds)
+{
+       int ret = 0;
+       bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
+       bt_adapter_visibility_mode_e discoverable_mode = (bt_adapter_visibility_mode_e)mode;
+
+       // Updates the local name instantly if the Bluetooth is turned on.
+       // Saves the setting name for the later use, otherwise.
+       ret = bt_adapter_get_state(&adapter_state);
+       SysTryReturnResult(NID_NET_BT, (ret == BT_ERROR_NONE && adapter_state == BT_ADAPTER_ENABLED), E_SYSTEM,
+                       "Setting the discoverable mode of Bluetooth has failed");
+
+       ret = bt_adapter_set_visibility(discoverable_mode, seconds);
+       SysTryReturnResult(NID_NET_BT, ret == BT_ERROR_NONE, E_SYSTEM,  "Setting the discoverable mode of Bluetooth has failed");
+
+       return E_SUCCESS;
+}
+
+result
+BluetoothService::UpdateLocalDeviceName(const Tizen::Base::String& name)
+{
+       int ret = 0;
+       char* pConvertedName = NULL;
+       char deviceName[BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1]  = {0,};
+
+       pConvertedName = _StringConverter::CopyToCharArrayN(name);
+       SysTryReturnResult(NID_NET_BT, pConvertedName != NULL, E_INVALID_ARG, "Invalid device name.");
+
+       strncpy(deviceName, pConvertedName, BLUETOOTH_DEVICE_NAME_LENGTH_MAX);
+       delete[] pConvertedName;
+       ret = bt_adapter_set_name(deviceName);
+       SysTryReturnResult(NID_NET_BT, ret == BT_ERROR_NONE, E_SYSTEM,
+                                               "Internal error occurred to set the local name.");
+
+       SysLog(NID_NET_BT, "Updating the Bluetooth local name is successful.");
+
+       return E_SUCCESS;
+}
+
+void
+BluetoothService::OnBluetoothAdapterStateChanged(int result, bt_adapter_state_e adapterState, void* pUserData)
+{
+       BluetoothService* pService = static_cast<BluetoothService*>(pUserData);
+
+       // if the Bluetooth is activated successfully
+       if (result == BT_ERROR_NONE && adapterState == BT_ADAPTER_ENABLED)
+       {
+               // Updates the local Bluetooth name.
+               // This is a reserved action.
+               if (pService->__newName.GetLength() > 0)
+               {
+                       pService->UpdateLocalDeviceName(pService->__newName);
+               }
+       }
+}
+
+void
+BluetoothService::OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type)
+{
+       // do nothing.
+}
+
+void
+BluetoothService::OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type)
+{
+       char* phoneName = null;
+       String convertedName;
+       result r = E_SUCCESS;
+       int ret = 0;
+       bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
+
+       if (__nameChangerId == appId)
+       {
+               SysLog(NID_NET_BT, "The application which set the BT local name is terminated.");
+
+               ret = bt_adapter_get_state(&adapter_state);
+
+               if (ret == BT_ERROR_NONE && adapter_state == BT_ADAPTER_ENABLED)
+               {
+                       SysLog(NID_NET_BT, "The BT local name is restored to the phone name.");
+
+                       // Gets the phone name from the system info
+                       phoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+                       if (phoneName)
+                       {
+                               r = StringUtil::Utf8ToString(phoneName, convertedName);
+                               free(phoneName);
+
+                               if (!IsFailed(r))
+                               {
+                                       // Updates the Bluetooth local name with the phone name
+                                       (void) UpdateLocalDeviceName(convertedName);
+                               }
+                       }
+               }
+
+               __newName.Clear();
+               __nameChangerId.Clear();
+       }
+}
diff --git a/src/ConnectivityService.cpp b/src/ConnectivityService.cpp
new file mode 100644 (file)
index 0000000..9cfd4d0
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// 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    ConnectivityService.cpp
+ * @brief   This is the implementation file for the %ConnectivityService class.
+ */
+
+#include <FAppAppRegistry.h>
+#include <FBaseSysLog.h>
+#include "ConnectivityService.h"
+#include "NetConnectivityIpcStub.h"
+#include "WifiConnectivityIpcStub.h"
+#include "NfcConnectivityIpcStub.h"
+#include "BluetoothConnectivityIpcStub.h"
+#include "TelephonyConnectivityIpcStub.h"
+
+using namespace std;
+
+ConnectivityService::ConnectivityService(void)
+       : __pNetIpcStub(null)
+       , __pWifiIpcStub(null)
+       , __pNfcIpcStub(null)
+       , __pBluetoothIpcStub(null)
+       , __pTelephonyIpcStub(null)
+{
+}
+
+ConnectivityService::~ConnectivityService(void)
+{
+
+}
+
+Tizen::App::ServiceApp*
+ConnectivityService::CreateInstance(void)
+{
+       // Create the instance through the constructor.
+       return new (std::nothrow) ConnectivityService();
+}
+
+bool
+ConnectivityService::OnAppInitializing(Tizen::App::AppRegistry& appRegistry)
+{
+       result r = E_SUCCESS;
+
+       SysLog(NID_NET, "Initializing ConnectivityService...");
+
+       unique_ptr<NetConnectivityIpcStub> pNetIpcStub(new (std::nothrow) NetConnectivityIpcStub);
+       SysTryReturn(NID_NET, pNetIpcStub != null, false, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       unique_ptr<WifiConnectivityIpcStub> pWifiIpcStub(new (std::nothrow) WifiConnectivityIpcStub);
+       SysTryReturn(NID_NET, pWifiIpcStub != null, false, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       unique_ptr<NfcConnectivityIpcStub> pNfcIpcStub(new (std::nothrow) NfcConnectivityIpcStub);
+       SysTryReturn(NID_NET_NFC, pNfcIpcStub != null, false, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       unique_ptr<BluetoothConnectivityIpcStub> pBluetoothIpcStub(new (std::nothrow) BluetoothConnectivityIpcStub);
+       SysTryReturn(NID_NET_BT, pBluetoothIpcStub != null, false, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       unique_ptr<TelephonyConnectivityIpcStub> pTelephonyIpcStub(new (std::nothrow) TelephonyConnectivityIpcStub);
+       SysTryReturn(NID_TEL, pTelephonyIpcStub != null, false, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       r = pNetIpcStub->Construct();
+       SysTryReturn(NID_NET, r == E_SUCCESS, false, r, "Construction of NetConnectivityIpcStub has failed.");
+
+       r = pWifiIpcStub->Construct();
+       SysTryReturn(NID_NET, r == E_SUCCESS, false, r, "Construction of WifiConnectivityIpcStub has failed.");
+
+       r = pNfcIpcStub->Construct();
+       SysTryReturn(NID_NET_NFC, r == E_SUCCESS, false, r, "Construction of NfcConnectivityIpcStub has failed.");
+
+       r = pBluetoothIpcStub->Construct();
+       SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "Construction of BluetoothConnectivityIpcStub has failed.");
+
+       r = pTelephonyIpcStub->Construct();
+       SysTryReturn(NID_TEL, r == E_SUCCESS, false, r, "Construction of TelephonyConnectivityIpcStub has failed.");
+
+       __pNetIpcStub = move(pNetIpcStub);
+       __pWifiIpcStub = move(pWifiIpcStub);
+       __pNfcIpcStub = move(pNfcIpcStub);
+       __pBluetoothIpcStub = move(pBluetoothIpcStub);
+       __pTelephonyIpcStub = move(pTelephonyIpcStub);
+
+       SysLog(NID_NET, "Initializing ConnectivityService is successful.");
+
+       return true;
+}
+
+bool
+ConnectivityService::OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination)
+{
+       SysLog(NID_NET, "Terminating ConnectivityService...");
+
+       return true;
+}
diff --git a/src/ConnectivityServiceEntry.cpp b/src/ConnectivityServiceEntry.cpp
new file mode 100644 (file)
index 0000000..be57360
--- /dev/null
@@ -0,0 +1,68 @@
+//
+// 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    ConnectivityServiceEntry.cpp
+ * @brief   This is the implementation file for the main method of the %ConnectivityService application.
+ */
+
+#include <FOspConfig.h>
+#include <FBaseResult.h>
+#include <FBaseColArrayList.h>
+#include <FBaseSysLog.h>
+#include "ConnectivityService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+_OSP_EXPORT_ int OspMain(int argc, char *pArgv[]);
+
+/**
+ * The entry function of bada application called by the operating system.
+ */
+int
+OspMain(int argc, char *pArgv[])
+{
+       result r = E_SUCCESS;
+
+       SysLog(NID_NET, "ConnectivityService daemon started.");
+       ArrayList* pArgs = new (std::nothrow) ArrayList();
+       pArgs->Construct();
+       for (int i = 0; i < argc; i++)
+               pArgs->Add(*(new (std::nothrow) String(pArgv[i])));
+
+       r = Tizen::App::ServiceApp::Execute(ConnectivityService::CreateInstance, pArgs);
+       if (IsFailed(r))
+       {
+               SysLogException(NID_NET, r, "[%s] Execution of ConnectivityService has failed.", GetErrorMessage(r));
+               r &= 0x0000FFFF;
+       }
+
+       pArgs->RemoveAll(true);
+       delete pArgs;
+       SysLog(NID_NET, "ConnectivityService daemon finished.");
+
+       return static_cast< int >(r);
+}
+#ifdef __cplusplus
+}
+#endif // __cplusplus
diff --git a/src/NetConnectivityIpcMessages.cpp b/src/NetConnectivityIpcMessages.cpp
new file mode 100644 (file)
index 0000000..e800c41
--- /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    NetConnectivityIpcMessages.cpp
+ * @brief   This is the generator of IPC messages for the Connectivity service daemon.
+ */
+
+#define IPC_MESSAGE_IMPL
+#include <FNet_ConnectivityIpcMessages.h>
+
+// Generate constructors.
+#include <ipc/struct_constructor_macros.h>
+#include <FNet_ConnectivityIpcMessages.h>
+
+// Generate destructors.
+#include <ipc/struct_destructor_macros.h>
+#include <FNet_ConnectivityIpcMessages.h>
+
+// Generate param traits write methods.
+#include <ipc/param_traits_write_macros.h>
+namespace IPC {
+#include <FNet_ConnectivityIpcMessages.h>
+}  // namespace IPC
+
+// Generate param traits read methods.
+#include <ipc/param_traits_read_macros.h>
+namespace IPC {
+#include <FNet_ConnectivityIpcMessages.h>
+}  // namespace IPC
diff --git a/src/NetConnectivityIpcStub.cpp b/src/NetConnectivityIpcStub.cpp
new file mode 100644 (file)
index 0000000..a60e7fc
--- /dev/null
@@ -0,0 +1,231 @@
+//
+// 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    NetConnectivityIpcStub.cpp
+ * @brief   This is the implementation file for the %NetConnectivityIpcStub class.
+ */
+#include <unique_ptr.h>
+#include <FBaseSysLog.h>
+#include <FIo_IpcServer.h>
+#include <FNet_ConnectivityIpcMessages.h>
+#include <FIo_IpcCommonParamTraits.h>
+#include <FSec_AccessController.h>
+#include "NetConnectivityIpcStub.h"
+#include "NetService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+using namespace Tizen::Net;
+
+NetConnectivityIpcStub::NetConnectivityIpcStub(void)
+       : __pNetService(null)
+       , __pIpcServer(null)
+{
+}
+
+NetConnectivityIpcStub::~NetConnectivityIpcStub(void)
+{
+       delete __pIpcServer;
+       delete __pNetService;
+}
+
+result
+NetConnectivityIpcStub::Construct(void)
+{
+       result r = E_SUCCESS;
+       result retVal = E_SUCCESS;
+
+       __pNetService = new (std::nothrow) NetService;
+       SysTryCatch(NID_NET, __pNetService != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       SysLog(NID_NET, "NetService is created.");
+
+       __pIpcServer = new (std::nothrow) _IpcServer;
+       SysTryCatch(NID_NET, __pIpcServer != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = __pIpcServer->Construct(NET_CONNECTIVITY_IPC_SERVER_NAME, *this);
+       SysTryCatch(NID_NET, r == E_SUCCESS, retVal = E_SYSTEM, E_SYSTEM,
+                       "[%s] A system error has been occurred. Failed to construct IpcServer.", GetErrorMessage(E_SYSTEM));
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+
+       delete __pNetService;
+       __pNetService = null;
+
+       return retVal;
+}
+
+void
+NetConnectivityIpcStub::OnIpcServerStarted(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET, "NetConnectivityIpcStub started.");
+}
+
+void
+NetConnectivityIpcStub::OnIpcServerStopped(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET, "NetConnectivityIpcStub stopped.");
+}
+
+void
+NetConnectivityIpcStub::OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId)
+{
+       SysLog(NID_NET, "Connected with clientId[%d].", clientId);
+}
+
+void
+NetConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId)
+{
+       SysLog(NID_NET, "Disconnected with clientId[%d].", clientId);
+}
+
+void
+NetConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message)
+{
+       IPC_BEGIN_MESSAGE_MAP(NetConnectivityIpcStub, message)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getAppNetAccountId, OnGetAppNetAccountId, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_setNetAccountId, OnSetNetAccountId, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_updateSystemNetAccount, OnUpdateSystemNetAccount, &server)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+NetConnectivityIpcStub::OnGetAppNetAccountId(const String& profileName, int* pNetAccountId, unsigned long* pResult)
+{
+    SysLog(NID_NET, "Received the request of getting application specific account id with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+    int netAccountId = INVALID_HANDLE;
+
+     *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_CUSTOMNETACCOUNT);
+
+    if (*pResult != E_SUCCESS)
+    {
+        *pResult = E_PRIVILEGE_DENIED;
+        SysLogException(NID_NET, E_PRIVILEGE_DENIED,
+                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+        *pResult = __pNetService->GetAppNetAccountId(profileName, netAccountId);
+        *pNetAccountId = netAccountId;
+    }
+}
+
+void
+NetConnectivityIpcStub::OnSetNetAccountId(int netAccountId, int* pNetAccountId2, unsigned long* pResult)
+{
+    SysLog(NID_NET, "Received the request of setting network account id with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+    int netAccountId2 = INVALID_HANDLE;
+
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_CUSTOMNETACCOUNT);
+
+    if (*pResult != E_SUCCESS)
+    {
+        *pResult = E_PRIVILEGE_DENIED;
+        SysLogException(NID_NET, E_PRIVILEGE_DENIED,
+                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+        *pResult = __pNetService->SetNetAccountId(netAccountId, netAccountId2);
+        *pNetAccountId2 = netAccountId2;
+    }
+}
+
+void
+NetConnectivityIpcStub::OnUpdateSystemNetAccount(const String& profileName, const NetAccountInfo& netAccountInfo, int bearerType,
+               unsigned long* pResult)
+{
+    SysLog(NID_NET, "Received the request of updating system network account with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_NETWORKMANAGER);
+
+    if (*pResult != E_SUCCESS)
+    {
+        *pResult = E_PRIVILEGE_DENIED;
+        SysLogException(NID_NET, E_PRIVILEGE_DENIED,
+                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+       NetNapAuthType authType;
+       String authId;
+       String authPw;
+       netAccountInfo.GetAuthenticationInfo(authType, authId, authPw);
+
+       SysLog(NID_NET, "ProfileName : %ls, BearerType : %d, AccessPointName : %ls, AccountId : %d, AccountName : %ls",
+                       profileName.GetPointer(), bearerType, netAccountInfo.GetAccessPointName().GetPointer(),
+                       netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName().GetPointer());
+       SysLog(NID_NET, "AuthType : %d, AuthId : %ls, AuthPassword : %ls, HomeURL : %ls",
+                       authType, authId.GetPointer(), authPw.GetPointer(), netAccountInfo.GetHomeUrl().GetPointer());
+
+               if (netAccountInfo.GetDnsAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+               {
+               SysLog(NID_NET, "Dns Address Scheme is static.");
+
+               if (netAccountInfo.GetPrimaryDnsAddress() != null)
+               {
+                       SysLog(NID_NET, "Primary Dns Address is %ls", netAccountInfo.GetPrimaryDnsAddress()->ToString().GetPointer());
+               }
+
+               if (netAccountInfo.GetSecondaryDnsAddress() != null)
+               {
+                       SysLog(NID_NET, "Secondary Dns Address is %ls", netAccountInfo.GetSecondaryDnsAddress()->ToString().GetPointer());
+               }
+               }
+               else
+               {
+               SysLog(NID_NET, "Dns Address Scheme is dynamic.");
+               }
+
+               if (netAccountInfo.GetLocalAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+               {
+               SysLog(NID_NET, "Local Address Scheme is static.");
+
+               if (netAccountInfo.GetLocalAddress() != null )
+               {
+                       SysLog(NID_NET, "Local Address is %ls", netAccountInfo.GetLocalAddress()->ToString().GetPointer());
+               }
+               }
+               else
+               {
+               SysLog(NID_NET, "Local Address Scheme is dynamic.");
+               }
+
+       if (netAccountInfo.GetProxyAddress() != null)
+       {
+               SysLog(NID_NET, "Proxy Address is %ls", netAccountInfo.GetProxyAddress()->GetNetEndPoint().GetPointer());
+       }
+
+        *pResult = __pNetService->UpdateSystemNetAccount(profileName, netAccountInfo, bearerType);
+    }
+}
diff --git a/src/NetService.cpp b/src/NetService.cpp
new file mode 100644 (file)
index 0000000..bcf7243
--- /dev/null
@@ -0,0 +1,382 @@
+//
+// 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    NetService.cpp
+ * @brief   This is the implementation file for the %NetService class.
+ */
+
+#include <net_connection.h>
+#include <FApp_AppManagerImpl.h>
+#include <FBaseSysLog.h>
+
+#include <FNetNetAccountManager.h>
+#include <FBaseString.h>
+#include <FNet_NetTypes.h>
+#include "FBase_StringConverter.h"
+#include "NetService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Net;
+
+
+NetService::NetService(void)
+{
+}
+
+
+NetService::~NetService(void)
+{
+}
+
+result
+NetService::GetAppNetAccountId(const String& profileName, int& netAccountId)
+{
+       result r = E_SUCCESS;
+       bool isKnownProfile = false;
+
+       if (profileName.Equals(L"SNS", true))
+       {
+               isKnownProfile = true;
+       }
+       else if (profileName.Equals(L"EMail", true))
+       {
+               isKnownProfile = true;
+       }
+       else if (profileName.Equals(L"Br", true))
+       {
+               isKnownProfile = true;
+       }
+       else if (profileName.Equals(L"IM", true))
+       {
+               isKnownProfile = true;
+       }
+       else if (profileName.Equals(L"MMS", true))
+       {
+               isKnownProfile = true;
+       }
+       else
+       {
+               isKnownProfile = false;
+       }
+
+       if (isKnownProfile)
+       {
+               netAccountId = _DEFAULT_PS_ACCOUNT_ID;
+       }
+       else
+       {
+               netAccountId = INVALID_HANDLE;
+               r = E_INVALID_ARG;
+       }
+
+       return r;
+}
+
+result
+NetService::SetNetAccountId(int netAccountId, int& netAccountId2)
+{
+       result r = E_SUCCESS;
+
+       netAccountId2 = netAccountId;
+
+       return r;
+}
+
+
+
+result
+NetService::UpdateSystemNetAccount(const String& profileName, const NetAccountInfo& netAccountInfo, int bearerType)
+{
+       result r = E_SUCCESS;
+
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = null;
+       connection_profile_h profileHandle = null;
+
+       ret = connection_create(&connectionHandle);
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_create() is %d", ret);
+
+       SysAssertf(connectionHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+       profileHandle = GetPsProfileHandleN(profileName);
+       SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ACCOUNT,
+                       "Invalid network account. The current value of account id is %d", netAccountInfo.GetAccountId());
+
+       r = ConvertToProfileInfo((void*)profileHandle, netAccountInfo, bearerType);
+       if (IsFailed(r))
+       {
+               SysLogException(NID_NET, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               connection_profile_destroy(profileHandle);
+               connection_destroy(&connectionHandle);
+
+               return r;
+       }
+
+       ret = connection_update_profile((void*)connectionHandle, profileHandle);
+
+       connection_profile_destroy(profileHandle);
+       connection_destroy(&connectionHandle);
+
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_update_profile() is %d", ret);
+
+       return r;
+}
+
+void*
+NetService::GetPsProfileHandleN(const String& profileName)
+{
+       SysLog(NID_NET, "GetPsProfileHandleN() has been called with ProfileName : %ls", profileName.GetPointer());
+
+       ClearLastResult();
+
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = null;
+       connection_profile_iterator_h iterator = null;
+       connection_profile_h profileHandle = null;
+       connection_profile_h matchingProfileHandle = null;
+
+       SysTryReturn(NID_NET, !profileName.IsEmpty(), null, E_INVALID_ARG,
+                       "[%s] Invalid argument is used. profileName is an empty string.", GetErrorMessage(E_INVALID_ARG));
+
+       ret = connection_create(&connectionHandle);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_create() is %d", GetErrorMessage(E_SYSTEM), ret);
+
+       ret = connection_get_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iterator);
+       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, , E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d", GetErrorMessage(E_SYSTEM), ret);
+
+       ret = connection_profile_iterator_next(iterator, &profileHandle);
+       while (profileHandle != null)
+       {
+               char* pTempProfileName = null;
+               String tempProfileName;
+
+               ret = connection_profile_get_name(profileHandle, &pTempProfileName);
+               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, , E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d", GetErrorMessage(E_SYSTEM), ret);
+
+               tempProfileName = String(pTempProfileName);
+               free(pTempProfileName);
+
+               if (profileName.Equals(tempProfileName))
+               {
+                       ret = connection_profile_clone(&matchingProfileHandle, profileHandle);
+                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, matchingProfileHandle = null, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value from connection_profile_clone() is %d", GetErrorMessage(E_SYSTEM), ret);
+
+                       break;
+               }
+
+               profileHandle = null;
+               ret = connection_profile_iterator_next(iterator, &profileHandle);
+       }
+
+       SysTryCatch(NID_NET, matchingProfileHandle != null, , E_INVALID_ACCOUNT,
+                       "[%s] Matching account is not found. profileName=%ls", GetErrorMessage(E_INVALID_ACCOUNT), profileName.GetPointer());
+
+       connection_destroy_profile_iterator(iterator);
+       connection_destroy(connectionHandle);
+
+       return matchingProfileHandle;
+
+CATCH:
+       if (iterator != null)
+       {
+               connection_destroy_profile_iterator(iterator);
+       }
+
+       if (connectionHandle != null)
+       {
+               connection_destroy(connectionHandle);
+       }
+
+       return null;
+}
+
+result
+NetService::ConvertToProfileInfo(void* pProfileHandle, const NetAccountInfo& netAccountInfo, int bearerType) const
+{
+       result r = E_SUCCESS;
+       connection_profile_h profileHandle = (connection_profile_h)pProfileHandle;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_cellular_auth_type_e cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
+
+       char* pApn = null;
+       char* pAuthId = null;
+       char* pAuthPassword = null;
+       char* pHomeUrl = null;
+       char* pDnsAddr = null;
+       char* pLocalAddr = null;
+       char* pProxyAddr = null;
+       String proxyAddr;
+
+       NetNapAuthType authType;
+       String authId;
+       String authPw;
+
+       SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ARG, "pProfileHandle is null.");
+       SysTryReturnResult(NID_NET, ((bearerType == NET_BEARER_PS) || (bearerType == NET_BEARER_MMS)),
+                       E_INVALID_ARG, "Invalid argument is used. BearerType has to be PS. bearerType=%d", bearerType);
+
+       if (!netAccountInfo.GetAccessPointName().IsEmpty())
+       {
+               pApn = _StringConverter::CopyToCharArrayN(netAccountInfo.GetAccessPointName());
+               // Todo: Can this be replaced with SysTryReturnResult() ??
+               SysTryCatch(NID_NET, pApn != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                               "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               ret = connection_profile_set_cellular_apn(profileHandle, pApn);
+               delete[] pApn;
+               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_set_cellular_apn() is %d", GetErrorMessage(E_SYSTEM), ret);
+       }
+
+       netAccountInfo.GetAuthenticationInfo(authType, authId, authPw);
+
+       if (authType == NET_NAPAUTH_PAP)
+       {
+               cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
+       }
+       else if (authType == NET_NAPAUTH_CHAP)
+       {
+               cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
+       }
+       else
+       {
+               cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
+       }
+
+       if (!authId.IsEmpty())
+       {
+               pAuthId = _StringConverter::CopyToCharArrayN(authId);
+               // OOM can occur.
+       }
+
+       if (!authPw.IsEmpty())
+       {
+               pAuthPassword = _StringConverter::CopyToCharArrayN(authPw);
+               // OOM can occur.
+       }
+
+       if ((pAuthId != null) && (pAuthPassword != null))
+       {
+               ret = connection_profile_set_cellular_auth_info(profileHandle, cellAuthType, pAuthId, pAuthPassword);
+       }
+       if (pAuthId != null)
+       {
+               delete[] pAuthId;
+       }
+       if (pAuthPassword != null)
+       {
+               delete[] pAuthPassword;
+       }
+       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_profile_set_cellular_auth_info() is %d", GetErrorMessage(E_SYSTEM), ret);
+
+       if (!netAccountInfo.GetHomeUrl().IsEmpty())
+       {
+               pHomeUrl = _StringConverter::CopyToCharArrayN(netAccountInfo.GetHomeUrl());
+               SysTryCatch(NID_NET, pHomeUrl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+
+               ret = connection_profile_set_cellular_home_url(profileHandle, pHomeUrl);
+               delete[] pHomeUrl;
+               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_set_cellular_home_url() is %d", GetErrorMessage(E_SYSTEM), ret);
+       }
+
+       if (netAccountInfo.GetDnsAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+       {
+               if (netAccountInfo.GetPrimaryDnsAddress() != null)
+               {
+                       pDnsAddr = _StringConverter::CopyToCharArrayN(netAccountInfo.GetPrimaryDnsAddress()->ToString());
+                       SysTryCatch(NID_NET, pDnsAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       ret = connection_profile_set_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, pDnsAddr);
+                       delete[] pDnsAddr;
+                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", GetErrorMessage(E_SYSTEM), ret);
+               }
+
+               if (netAccountInfo.GetSecondaryDnsAddress() != null)
+               {
+                       pDnsAddr = _StringConverter::CopyToCharArrayN(netAccountInfo.GetSecondaryDnsAddress()->ToString());
+                       SysTryCatch(NID_NET, pDnsAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       ret = connection_profile_set_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, pDnsAddr);
+                       delete[] pDnsAddr;
+                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", GetErrorMessage(E_SYSTEM), ret);
+               }
+       }
+
+       if (netAccountInfo.GetLocalAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+       {
+               ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_STATIC);
+               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM,
+                               E_SYSTEM, "[%s] A system error has been occurred. The return value from connection_profile_set_ip_config_type() is %d", ret);
+
+               SysTryCatch(NID_NET, netAccountInfo.GetLocalAddress() != null, r = E_INVALID_ARG, E_INVALID_ARG,
+                               "[%s] Invalid argument is used. Local Address Scheme is static, but local address is null.", GetErrorMessage(E_INVALID_ARG));
+
+               pLocalAddr = _StringConverter::CopyToCharArrayN(netAccountInfo.GetLocalAddress()->ToString());
+               SysTryCatch(NID_NET, pLocalAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                               "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               ret = connection_profile_set_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pLocalAddr);
+               delete[] pLocalAddr;
+               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_set_ip_address() is %d", GetErrorMessage(E_SYSTEM), ret);
+       }
+       else
+       {
+               ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
+               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value connection_profile_set_ip_config_type() is %d", GetErrorMessage(E_SYSTEM), ret);
+       }
+
+       if (netAccountInfo.GetProxyAddress() != null)
+       {
+               proxyAddr = netAccountInfo.GetProxyAddress()->GetNetEndPoint();
+               if (proxyAddr.IsEmpty() == false)
+               {
+                       ret = connection_profile_set_proxy_type(profileHandle, CONNECTION_PROXY_TYPE_MANUAL);
+                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value connection_profile_set_proxy_type() is %d", GetErrorMessage(E_SYSTEM), ret);
+
+                       pProxyAddr = _StringConverter::CopyToCharArrayN(proxyAddr);
+                       SysTryCatch(NID_NET, pProxyAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pProxyAddr);
+                       delete[] pProxyAddr;
+                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value connection_profile_set_proxy_address() is %d", GetErrorMessage(E_SYSTEM), ret);
+               }
+       }
+
+       return r;
+
+CATCH:
+       return r;
+}
diff --git a/src/NfcConnectivityIpcMessages.cpp b/src/NfcConnectivityIpcMessages.cpp
new file mode 100644 (file)
index 0000000..f9e764e
--- /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    NfcConnectivityIpcMessages.cpp
+ * @brief   This is the generator of IPC messages for the Connectivity service daemon.
+ */
+
+#define IPC_MESSAGE_IMPL
+#include <FNetNfc_ConnectivityIpcMessages.h>
+
+// Generate constructors.
+#include <ipc/struct_constructor_macros.h>
+#include <FNetNfc_ConnectivityIpcMessages.h>
+
+// Generate destructors.
+#include <ipc/struct_destructor_macros.h>
+#include <FNetNfc_ConnectivityIpcMessages.h>
+
+// Generate param traits write methods.
+#include <ipc/param_traits_write_macros.h>
+namespace IPC {
+#include <FNetNfc_ConnectivityIpcMessages.h>
+}  // namespace IPC
+
+// Generate param traits read methods.
+#include <ipc/param_traits_read_macros.h>
+namespace IPC {
+#include <FNetNfc_ConnectivityIpcMessages.h>
+}  // namespace IPC
diff --git a/src/NfcConnectivityIpcStub.cpp b/src/NfcConnectivityIpcStub.cpp
new file mode 100644 (file)
index 0000000..19a3143
--- /dev/null
@@ -0,0 +1,190 @@
+//
+// 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    NfcConnectivityIpcStub.cpp
+ * @brief   This is the implementation file for the %NfcConnectivityIpcStub class.
+ */
+#include <unique_ptr.h>
+#include <FBaseSysLog.h>
+#include <FIo_IpcServer.h>
+#include <FNetNfc_ConnectivityIpcMessages.h>
+#include <FIo_IpcCommonParamTraits.h>
+#include <FSec_AccessController.h>
+#include "NfcConnectivityIpcStub.h"
+#include "NfcService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+using namespace Tizen::Net;
+
+NfcConnectivityIpcStub::NfcConnectivityIpcStub(void)
+       : __pNfcService(null)
+       , __pIpcServer(null)
+{
+}
+
+NfcConnectivityIpcStub::~NfcConnectivityIpcStub(void)
+{
+       delete __pIpcServer;
+       delete __pNfcService;
+}
+
+result
+NfcConnectivityIpcStub::Construct(void)
+{
+       result r = E_SUCCESS;
+       result retVal = E_SUCCESS;
+
+       __pNfcService = new (std::nothrow) NfcService;
+       SysTryReturnResult(NID_NET_NFC, __pNfcService != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       r = __pNfcService->Construct();
+       if (r == E_SUCCESS)
+       {
+               SysLog(NID_NET_NFC, "NfcService is created.");
+       }
+       else
+       {
+               // skip NFC service
+               SysLogException(NID_NET_NFC, r, "[%s] Failed to construct NfcService.", GetErrorMessage(r));
+               delete __pNfcService;
+               __pNfcService = null;
+       }
+
+       __pIpcServer = new (std::nothrow) _IpcServer;
+       SysTryCatch(NID_NET_NFC, __pIpcServer != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = __pIpcServer->Construct(NFC_CONNECTIVITY_IPC_SERVER_NAME, *this);
+       SysTryCatch(NID_NET_NFC, r == E_SUCCESS, retVal = E_SYSTEM, E_SYSTEM,
+                       "[%s] A system error has been occurred. Failed to construct IpcServer.", GetErrorMessage(E_SYSTEM));
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+
+       delete __pNfcService;
+       __pNfcService = null;
+
+       return retVal;
+}
+
+void
+NfcConnectivityIpcStub::OnIpcServerStarted(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET_NFC, "NfcConnectivityIpcStub started.");
+}
+
+void
+NfcConnectivityIpcStub::OnIpcServerStopped(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET_NFC, "NfcConnectivityIpcStub stopped.");
+}
+
+void
+NfcConnectivityIpcStub::OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId)
+{
+       SysLog(NID_NET_NFC, "Connected with clientId[%d].", clientId);
+}
+
+void
+NfcConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId)
+{
+       SysLog(NID_NET_NFC, "Disconnected with clientId[%d].", clientId);
+}
+
+void
+NfcConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message)
+{
+       IPC_BEGIN_MESSAGE_MAP(NfcConnectivityIpcStub, message)
+       IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_initialize, OnInitializeNfc, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_setLaunchPopupEnabled, OnSetNfcLaunchPopupEnabled, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_registerPushMessage, OnRegisterNfcPushMessage, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_unregisterPushMessage, OnUnregisterNfcPushMessage, &server)
+       IPC_END_MESSAGE_MAP()
+}
+
+
+void
+NfcConnectivityIpcStub::OnInitializeNfc(unsigned long* pResult)
+{
+       SysLog(NID_NET_NFC, "Received the request of initializing the NFC with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pNfcService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pNfcService->AddNfcAppId(__pIpcServer->GetClientAppId());
+       }
+}
+
+void
+NfcConnectivityIpcStub::OnSetNfcLaunchPopupEnabled(bool enable, unsigned long* pResult)
+{
+       SysLog(NID_NET_NFC, "Received the request of setting the launch popup enabled with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pNfcService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pNfcService->SetLaunchPopupEnabled(__pIpcServer->GetClientAppId(), enable);
+       }
+}
+
+void
+NfcConnectivityIpcStub::OnRegisterNfcPushMessage(const Tizen::Base::ByteBuffer& pushMessageBuffer,
+               const Tizen::Base::String& description, unsigned long* pResult)
+{
+       SysLog(NID_NET_NFC, "Received the request of registering the NFC push message with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pNfcService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pNfcService->RegisterPushMessage(__pIpcServer->GetClientAppId(), pushMessageBuffer, description);
+       }
+}
+
+void
+NfcConnectivityIpcStub::OnUnregisterNfcPushMessage(unsigned long* pResult)
+{
+       SysLog(NID_NET_NFC, "Received the request of unregistering the NFC push message with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pNfcService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pNfcService->UnregisterPushMessage(__pIpcServer->GetClientAppId());
+       }
+}
+
diff --git a/src/NfcMessagePushDelegate.cpp b/src/NfcMessagePushDelegate.cpp
new file mode 100644 (file)
index 0000000..68ca4bb
--- /dev/null
@@ -0,0 +1,378 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file    NfcMessagePushDelegate.cpp
+ * @brief   This is the implementation file for the %NfcMessagePushDelegate class.
+ */
+
+#include <unique_ptr.h>
+#include <string.h>
+#include <vconf-internal-nfc-keys.h>
+#include <vconf-internal-setting-keys.h>
+#include <Ecore_Evas.h>
+#include <Ecore_X.h>
+#include <app_manager.h>
+#include <FAppAppControl.h>
+#include <FAppAppManager.h>
+#include <FBaseSysLog.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseUtilStringUtil.h>
+#include <FBaseColArrayList.h>
+#include <FIoFile.h>
+#include <FIoFileAttributes.h>
+#include "NfcMessagePushDelegate.h"
+#include "NfcMessageRegisterService.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::App;
+using namespace Tizen::Io;
+using namespace Tizen::Base::Collection;
+
+const wchar_t* NfcMessagePushDelegate::_NFC_PUSH_UI_AC_PROVIDER_ID = L"http://tizen.org/appcontrol/provider/nfcpushui";
+const wchar_t* NfcMessagePushDelegate::_NFC_PUSH_UI_AC_OPERATION_ID = L"http://tizen.org/appcontrol/operation/nfc/animation/show";
+
+struct _CharDeleter
+{
+       void operator()(char* pChar)
+       {
+               free(pChar);
+       }
+};
+
+NfcMessagePushDelegate::NfcMessagePushDelegate(void)
+       : __isPushEnabled(false)
+       , __p2pTargetHandle(null)
+{
+       // Checks whether the reserved push feature is enabled or disabled
+       UpdatePushEnabled();
+
+       // set vconf callback about the Reserved Push setting
+       vconf_notify_key_changed(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, OnNfcReservedPushStateChanged, this);
+}
+
+NfcMessagePushDelegate::~NfcMessagePushDelegate(void)
+{
+       Deinitialize();
+    // unset vconf callback
+    vconf_ignore_key_changed(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, OnNfcReservedPushStateChanged);
+}
+
+void
+NfcMessagePushDelegate::Initialize(void)
+{
+       // set NFC target discovered callback
+       nfc_manager_set_p2p_target_discovered_cb(&OnNfcDeviceDiscovered, this);
+}
+
+void
+NfcMessagePushDelegate::Deinitialize(void)
+{
+       nfc_manager_unset_p2p_target_discovered_cb();
+}
+
+void
+NfcMessagePushDelegate::UpdatePushEnabled(void)
+{
+       int vconfRes = -1;
+       int isEnabled = 0;
+
+       // get the value for the predefined item
+       vconfRes = vconf_get_bool(VCONFKEY_NFC_PREDEFINED_ITEM_STATE, &isEnabled);
+       SysTryReturnVoidResult(NID_NET_NFC, vconfRes == 0, E_SYSTEM,
+                       "[E_SYSTEM] Failed to get the vconf - reserved push state - value.");
+
+       __isPushEnabled = (isEnabled == 0) ? false : true;
+
+       SysLog(NID_NET_NFC, "The Reserved Push is %s.", __isPushEnabled ? "enabled" : "disabled");
+}
+
+bool
+NfcMessagePushDelegate::IsHomeScreenAtTopmost(void)
+{
+//     unique_ptr<char, _CharDeleter> pHomeScreenId;
+       unique_ptr<char, _CharDeleter> pHomeMenuId;
+       char* pTopmostAppId = 0;
+       Ecore_X_Window activeWin = 0;
+       int winPid = 0;
+       Eina_Bool ecoreRes = EINA_FALSE;
+       int appRes = APP_MANAGER_ERROR_NONE;
+       bool thisRes = false;
+
+       // get the value for the home menu app id
+       pHomeMenuId.reset(vconf_get_str(VCONFKEY_SETAPPL_SELECTED_PACKAGE_NAME));
+       SysTryReturn(NID_NET_NFC, pHomeMenuId != null, false, E_SYSTEM, "[E_SYSTEM] Failed to get the Home Menu App ID.");
+       SysLog(NID_NET_NFC, "Home Menu ID: %s", pHomeMenuId.get());
+
+       // get the value for the home screen app id
+       // TODO: block the below code for preventing build error in RSA because the specified vconf key is not defined in RSA
+//     pHomeScreenId.reset(vconf_get_str(VCONFKEY_SETAPPL_SELECTED_HOMESCREEN_PACKAGE_NAME));
+//     SysTryReturn(NID_NET_NFC, pHomeScreenId != null, false, E_SYSTEM, "[E_SYSTEM] Failed to get the Home Screen App ID.");
+//     SysLog(NID_NET_NFC, "Home Screen ID: %s", pHomeScreenId.get());
+
+       // get the topmost (focused) window
+       activeWin = ecore_x_window_focus_get();
+
+       // get the PID(process ID) of the topmost window
+       ecoreRes = ecore_x_netwm_pid_get(activeWin, &winPid);
+       SysTryReturn(NID_NET_NFC, ecoreRes == EINA_TRUE, false, E_SYSTEM, "[E_SYSTEM] Failed to get the PID of the active window.");
+
+       // get the App ID of the topmost window through PID
+       appRes = app_manager_get_app_id(winPid, &pTopmostAppId);
+       SysTryReturn(NID_NET_NFC, (appRes == APP_MANAGER_ERROR_NONE) && (pTopmostAppId != null), false, E_SYSTEM,
+                       "[E_SYSTEM] Failed to get the topmost app ID.");
+       SysLog(NID_NET_NFC, "Topmost App ID: %s", pTopmostAppId);
+
+       // compare the topmost App ID with the Home screen App ID and the Home menu App ID
+       // TODO: block the below conditions for preventing build error in RSA
+       // if ((strcmp(pHomeScreenId.get(), pTopmostAppId) == 0) || (strcmp(pHomeMenuId.get(), pTopmostAppId) == 0))
+       if (strcmp(pHomeMenuId.get(), pTopmostAppId) == 0)
+       {
+               SysLog(NID_NET_NFC, "Home screen or Home menu is the topmost running app.");
+               thisRes = true;
+       }
+
+       free(pTopmostAppId);
+
+       return thisRes;
+}
+
+void
+NfcMessagePushDelegate::SendReservedMessage(nfc_p2p_target_h targetH)
+{
+       ByteBuffer messageBuffer;
+       int nfcRes = NFC_ERROR_NONE;
+       result r = E_SUCCESS;
+       File msgFile;
+       FileAttributes msgFileAttr;
+       String msgFilePath;
+       nfc_ndef_message_h ndefMessageH = NULL;
+       char* pSelectedItem = null;
+       String selectedItemStr;
+
+       // get the value for the predefined item
+       pSelectedItem = vconf_get_str(VCONFKEY_NFC_PREDEFINED_ITEM);
+       SysTryReturnVoidResult(NID_NET_NFC, pSelectedItem != null, E_SYSTEM,
+                       "[E_SYSTEM] Failed to get the selected item among the item list.");
+
+       selectedItemStr = String(pSelectedItem);
+       free(pSelectedItem);
+       SysLog(NID_NET_NFC, "Try to send the reserved NDEF message (ID: %ls) to the detected peer device...",
+                       selectedItemStr.GetPointer());
+
+       // make the push message file path which consists of the directory path, appId as the name, and "ndef" as the extension.
+       msgFilePath = NfcMessageRegisterService::_PUSH_MESSAGE_DIRECTORY + selectedItemStr +
+                       NfcMessageRegisterService::_PUSH_MESSAGE_EXT_NAME;
+
+       // create a ByteBuffer instance to fill the content of the message file into it.
+       r = File::GetAttributes(msgFilePath, msgFileAttr);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Getting the size of the NDEF message file has failed. (File path: %ls)",
+                       msgFilePath.GetPointer());
+
+       r = messageBuffer.Construct(msgFileAttr.GetFileSize());
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Construction of the ByteBuffer for reading has failed.");
+
+       // get NdefMessage from the file
+       r = msgFile.Construct(msgFilePath, L"r");
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Construction of the push message file for reading has failed. (File path: %ls)",
+                       msgFilePath.GetPointer());
+
+       r = msgFile.Read(messageBuffer);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Reading the NDEF message file has failed.");
+       messageBuffer.Flip();
+
+       SysLog(NID_NET_NFC, "Reading the reserved NDEF message is successful.");
+
+       // send the reserved NDEF message as a raw format - byte array type.
+       nfcRes = nfc_ndef_message_create_from_rawdata(&ndefMessageH, messageBuffer.GetPointer() + messageBuffer.GetPosition(),
+                       messageBuffer.GetRemaining());
+       SysTryReturnVoidResult(NID_NET_NFC, nfcRes == NFC_ERROR_NONE, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Failed to convert raw data to NDEF message [0x%08X].", nfcRes);
+
+       nfcRes = nfc_p2p_send(targetH, ndefMessageH, &OnNdefMessageSent, null);
+       nfc_ndef_message_destroy(ndefMessageH); // free the resources. (the result is ignored)
+       SysTryReturnVoidResult(NID_NET_NFC, nfcRes == NFC_ERROR_NONE, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Failed to send the NDEF message [0x%08X].", nfcRes);
+
+       SysLog(NID_NET_NFC, "Sending the reserved NDEF message is successfully started.");
+}
+
+void
+NfcMessagePushDelegate::InvokeNfcPushUiAppControl(const String& iconPath, const String& appName, const String& description)
+{
+       result r = E_SUCCESS;
+       std::unique_ptr<ArrayList> pDataList;
+       std::unique_ptr<String> pData1;
+       std::unique_ptr<String> pData2;
+       std::unique_ptr<String> pData3;
+       std::unique_ptr<AppControl> pAc;
+
+       // array list for args
+       pDataList.reset(new (std::nothrow) ArrayList());
+       SysTryReturnVoidResult(NID_NET_NFC, pDataList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+       r = pDataList->Construct();
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r, "[%s] An unexpected error has occurred.", GetErrorMessage(r));
+
+       // iconPath
+       pData1.reset(new (std::nothrow) String(L"iconPath:"));
+       SysTryReturnVoidResult(NID_NET_NFC, pData1 != null, E_OUT_OF_MEMORY, "Insufficient memory.");
+       r = pData1->Append(iconPath);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                       "[%s] exception occurred. Failed to make a parameter for icon path.", GetErrorMessage(r));
+       r = pDataList->Add(*pData1);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                       "[%s] exception occurred. Failed to make a parameter for icon path.", GetErrorMessage(r));
+
+       // appName
+       pData2.reset(new (std::nothrow) String(L"appName:"));
+       SysTryReturnVoidResult(NID_NET_NFC, pData2 != null, E_OUT_OF_MEMORY, "[%s] Insufficient memory.", GetErrorMessage(r));
+       r = pData2->Append(appName);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                       "[%s] exception occurred.  Failed to make a parameter for app name.", GetErrorMessage(r));
+       r = pDataList->Add(*pData2);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                       "[%s] exception occurred. Failed to make a parameter for app name.", GetErrorMessage(r));
+
+       // description
+       pData3.reset(new (std::nothrow) String(L"description:"));
+       SysTryReturnVoidResult(NID_NET_NFC, pData3 != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+       r = pData3->Append(description);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                       "[%s] exception occurred. Failed to make a parameter for description.", GetErrorMessage(r));
+       r = pDataList->Add(*pData3);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                       "[%s] exception occurred. Failed to make a parameter for description.", GetErrorMessage(r));
+
+       // find app control
+       pAc.reset(AppManager::FindAppControlN(_NFC_PUSH_UI_AC_PROVIDER_ID, _NFC_PUSH_UI_AC_OPERATION_ID));
+       SysTryReturnVoidResult(NID_NET_NFC, pAc != null, GetLastResult(),
+                       "[%s] exception occurred. Failed to find app control.", GetErrorMessage(GetLastResult()));
+
+       // start app control
+       r = pAc->Start(pDataList.get(), this);
+       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                       "[%s] exception occurred. Failed to start app control", GetErrorMessage(r));
+
+       return;
+}
+
+void
+NfcMessagePushDelegate::OnNfcDeviceDiscovered(nfc_discovered_type_e type, nfc_p2p_target_h target, void* pUserData)
+{
+       NfcMessagePushDelegate* pDelegate = null;
+
+       pDelegate = static_cast<NfcMessagePushDelegate*>(pUserData);
+
+       if(type == NFC_DISCOVERED_TYPE_ATTACHED)
+       {
+               SysLog(NID_NET_NFC, "NFC peer device is detected. (Reserved Push is %s)",
+                               pDelegate->__isPushEnabled ? "ENABLED" : "DISABLED");
+               if ((target != NULL) && pDelegate->__isPushEnabled && pDelegate->IsHomeScreenAtTopmost())
+               {
+                       // set p2p target handle
+                       pDelegate->__p2pTargetHandle = target;
+
+                       ////////////////////////////////////////////////////////////////////////////////
+                       // TODO. invoke app control. This should uncommented soon.
+                       ////////////////////////////////////////////////////////////////////////////////
+                       // SysLog(NID_NET_NFC, "invoking app control...");
+                       // pDelegate->InvokeNfcPushUiAppControl(L"temporary/icon/path/", L"app name", L"this is app description.");
+                       ////////////////////////////////////////////////////////////////////////////////
+               }
+       }
+       else if (type == NFC_DISCOVERED_TYPE_DETACHED)
+       {
+               SysLog(NID_NET_NFC, "NFC peer device is lost.");
+               pDelegate->__p2pTargetHandle = null;
+       }
+       // ignore other cases
+}
+
+//-----------------------------------------------------------------------------------------------------------------------
+// VCONFKEY_NFC_PREDEFINED_ITEM_STATE  "db/nfc/predefined_item_state   /* Enable or disable the Reserved Push feature */
+//-----------------------------------------------------------------------------------------------------------------------
+void
+NfcMessagePushDelegate::OnNfcReservedPushStateChanged(keynode_t* pKeyNode, void* pUserData)
+{
+       char* pKeyStr = null;
+       NfcMessagePushDelegate* pDelegate = null;
+
+       SysLog(NID_NET_NFC, "The key changed event (VCONFKEY_NFC_PREDEFINED_ITEM_STATE) is invoked.");
+
+       // check the key name
+       pKeyStr = vconf_keynode_get_name(pKeyNode);
+       SysTryReturnVoidResult(NID_NET_NFC, pKeyStr != null, E_SYSTEM, "[E_SYSTEM] Failed to get the vconf pKeyNode name.");
+       SysTryReturnVoidResult(NID_NET_NFC, strcmp(pKeyStr, VCONFKEY_NFC_PREDEFINED_ITEM_STATE) == 0, E_SYSTEM,
+                       "[E_SYSTEM] the vconf key name is not about the state for Reserved Push.");
+
+       pDelegate = static_cast<NfcMessagePushDelegate*>(pUserData);
+       pDelegate->UpdatePushEnabled();
+}
+
+void
+NfcMessagePushDelegate::OnNdefMessageSent(nfc_error_e res, void* pUserData)
+{
+       SysTryReturnVoidResult(NID_NET_NFC, res == NFC_ERROR_NONE, E_OPERATION_FAILED,
+                       "[E_OPERATION_FAILED] Sending the NDEF Message has failed [0x%08X].", res);
+
+       SysLog(NID_NET_NFC, "The NDEF Message has successfully sent to the target device.");
+}
+
+void
+NfcMessagePushDelegate::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
+{
+       result r = E_SUCCESS;
+       String* pAppControlResult = null;
+
+       if (providerId == _NFC_PUSH_UI_AC_PROVIDER_ID && operationId == _NFC_PUSH_UI_AC_OPERATION_ID)
+       {
+               SysTryReturnVoidResult(NID_NET_NFC, pResultList != null, E_OPERATION_FAILED,
+                               "[E_OPERATION_FAILED] NfcPushUi app control completed. But no result come.");
+
+               pAppControlResult = (Tizen::Base::String*)(pResultList->GetAt(0));
+               SysTryReturnVoidResult(NID_NET_NFC, pAppControlResult != null, E_OPERATION_FAILED,
+                               "[E_OPERATION_FAILED] There is no result in the array list.");
+
+               // check the app control result
+               if (pAppControlResult->Equals(APPCONTROL_RESULT_SUCCEEDED))
+               {
+                       SysLog(NID_NET_NFC, "APPCONTROL_RESULT_SUCCEEDED was come.");
+                       SysTryReturnVoidResult(NID_NET_NFC, __p2pTargetHandle != null, E_OPERATION_FAILED,
+                                       "[E_OPERATION_FAILED] There is no attached device.");
+
+                       // send reserved NDEF message
+                       SendReservedMessage(__p2pTargetHandle);
+                       r = GetLastResult();
+                       SysTryReturnVoidResult(NID_NET_NFC, r == E_SUCCESS, r,
+                                       "[%s] Sending of the reserved push message file has failed.", GetErrorMessage(r));
+               }
+               else if (pAppControlResult->Equals(APPCONTROL_RESULT_CANCELED))
+               {
+                       SysLog(NID_NET_NFC, "APPCONTROL_RESULT_CANCELED was come.");
+               }
+               else if (pAppControlResult->Equals(APPCONTROL_RESULT_FAILED))
+               {
+                       SysLog(NID_NET_NFC, "APPCONTROL_RESULT_FAILED was come.");
+               }
+       }
+}
diff --git a/src/NfcMessageRegisterService.cpp b/src/NfcMessageRegisterService.cpp
new file mode 100644 (file)
index 0000000..b737d0c
--- /dev/null
@@ -0,0 +1,316 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file    NfcMessageRegisterService.cpp
+ * @brief   This is the implementation file for the %NfcMessageRegisterService class.
+ */
+
+#include <vconf.h>
+#include <vconf-internal-setting-keys.h>
+#include <unique_ptr.h>
+#include <FBaseSysLog.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseRtMutexGuard.h>
+#include <FAppPkgPackageInfo.h>
+#include <FIoFile.h>
+#include <FIoDbStatement.h>
+#include <FIoDbEnumerator.h>
+#include <FAppPkg_PackageManagerImpl.h>
+#include <FBase_StringConverter.h>
+#include "NfcMessageRegisterService.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::App;
+using namespace Tizen::App::Package;
+using namespace Tizen::Io;
+
+const wchar_t* NfcMessageRegisterService::_META_DATA_DB_NAME = L"/opt/usr/dbspace/.net-nfcpush.db";
+const wchar_t* NfcMessageRegisterService::_PUSH_MESSAGE_DIRECTORY = L"/opt/usr/share/nfcpush/";
+const wchar_t* NfcMessageRegisterService::_PUSH_MESSAGE_EXT_NAME = L".ndef";
+
+NfcMessageRegisterService::NfcMessageRegisterService(void)
+       : __rsvdPushDb()
+       , __appIdListMutex()
+       , __reserverAppIdList()
+{
+}
+
+NfcMessageRegisterService::~NfcMessageRegisterService(void)
+{
+       (void) _PackageManagerImpl::GetInstance()->RemoveEventListener(this);
+}
+
+result
+NfcMessageRegisterService::Construct(void)
+{
+       result r = E_SUCCESS;
+
+       r = __appIdListMutex.Create();
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
+
+       r = InitializeAppIdList();
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM,
+                       "Failed to initialize the list of the application from DB which registered push messages.");
+
+       r = _PackageManagerImpl::GetInstance()->AddEventListener(this);
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Registration of an _IAppManagerEventListener has failed.");
+
+       return E_SUCCESS;
+}
+
+result
+NfcMessageRegisterService::RegisterPushMessage(const Tizen::Base::String& appId, const Tizen::Base::ByteBuffer& pushMessageBuffer,
+               const Tizen::Base::String& description)
+{
+       // SQL to insert if the appid exists in the table or replace otherwise.
+       const wchar_t* _INSERT_ROW_SQL = L"INSERT OR REPLACE INTO NfcPushMsgTable \
+                       (AppId, PkgName, IconPath, MsgDesc) VALUES (?, ?, ?, ?)";
+       result r = E_SUCCESS;
+       File msgFile;
+       String msgFilePath;
+       unique_ptr<DbStatement> pInsertStmt;
+       unique_ptr<DbEnumerator> pInsertEnum;
+    PackageInfo* pPackageInfo = null;
+    String appName;
+    String appIconPath;
+    char* pAppIdStr = null;
+    int vconfRes = -1;
+
+       // make the push message file path which consists of the directory path, appId as the name, and "ndef" as the extension.
+       msgFilePath = _PUSH_MESSAGE_DIRECTORY + appId + _PUSH_MESSAGE_EXT_NAME;
+
+       // get the app name and icon path from the package manager
+       pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(appId);
+       SysTryReturnResult(NID_NET_NFC, pPackageInfo != null, E_SYSTEM, "Getting package information has failed.");
+
+       appName = pPackageInfo->GetDisplayName();
+       //appIconPath = packageInfo.GetAppIconPath();
+
+       delete pPackageInfo;
+
+       MutexGuard locked(__appIdListMutex);
+
+       // If the push message of the specified app already exists, it is updated by the new message.
+       // Otherwise, a new push message file is created.
+       r = msgFile.Construct(msgFilePath, L"w+");
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construction of the push message file has failed.");
+
+       r = msgFile.Write(pushMessageBuffer);
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Writing the push message file has failed.");
+
+       SysLog(NID_NET_NFC, "Writing the new NFC push message is successful.");
+
+       // Add or update the application ID and message description to the DB
+       __rsvdPushDb.BeginTransaction();
+
+       pInsertStmt.reset(__rsvdPushDb.CreateStatementN(_INSERT_ROW_SQL));
+       pInsertStmt->BindString(0, appId);
+       pInsertStmt->BindString(1, appName);
+       pInsertStmt->BindString(2, appIconPath);
+       pInsertStmt->BindString(3, description);
+
+       pInsertEnum.reset(__rsvdPushDb.ExecuteStatementN(*pInsertStmt));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM,
+                       "[E_SYSTEM] derived from [%s]. Insertion a new row to the DB has failed.", GetErrorMessage(r));
+
+       __rsvdPushDb.CommitTransaction();
+
+       // The application ID is added to the list
+       if (!__reserverAppIdList.Contains(appId))
+       {
+               r = __reserverAppIdList.Add(appId);
+               SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Insertion a new app ID to the list has failed.");
+
+               // Modify vconf - the selected item - value if the new message (appId) becomes the first element of the list
+               if (__reserverAppIdList.GetCount() == 1)
+               {
+                       pAppIdStr = _StringConverter::CopyToCharArrayN(appId);
+                       SysTryReturnResult(NID_NET_NFC, pAppIdStr != null, E_SYSTEM, "Failed set the Predefined Item value (vconf).");
+
+                       vconfRes = vconf_set_str(VCONFKEY_NFC_PREDEFINED_ITEM, pAppIdStr);
+                       delete[] pAppIdStr;
+                       SysTryReturnResult(NID_NET_NFC, vconfRes == 0, E_SYSTEM, "Failed to set the Predefined Item value (vconf).");
+                       SysLog(NID_NET_NFC, "The NDEF message of (AppId: %ls) is chosen initially for the Reserved Push.",
+                                       appId.GetPointer());
+               }
+       }
+
+       locked.Unlock();
+
+       return r;
+}
+
+result
+NfcMessageRegisterService::UnregisterPushMessage(const Tizen::Base::String& appId)
+{
+       const wchar_t* _DELETE_ROW_SQL = L"DELETE FROM NfcPushMsgTable WHERE AppId = ?";
+       result r = E_SUCCESS;
+       String msgFilePath;
+    DbStatement* pDeleteStmt = null;
+    DbEnumerator* pDeleteEnum = null;
+    char* pCurrentItemStr = null;
+    int vconfRes = -1;
+
+       // make the push message file path which consists of the directory path, appId as the name, and "ndef" as the extension.
+       msgFilePath = _PUSH_MESSAGE_DIRECTORY + appId + _PUSH_MESSAGE_EXT_NAME;
+
+       MutexGuard locked(__appIdListMutex);
+
+       // remove the push message file.
+       if (File::IsFileExist(msgFilePath))
+       {
+               r = File::Remove(msgFilePath);
+               if (r != E_SUCCESS)
+               {
+                       SysLogException(NID_NET_NFC, E_SYSTEM,
+                                       "[%s] Propagating. Removing the push message file has failed.", GetErrorMessage(r));
+               }
+       }
+
+       // The application ID and message description is removed from the DB
+       __rsvdPushDb.BeginTransaction();
+
+       pDeleteStmt = __rsvdPushDb.CreateStatementN(_DELETE_ROW_SQL);
+       pDeleteStmt->BindString(0, appId);
+
+       pDeleteEnum = __rsvdPushDb.ExecuteStatementN(*pDeleteStmt);
+       if (pDeleteEnum == null)
+       {
+               r = GetLastResult();
+               if (r != E_SUCCESS)
+               {
+                       SysLogException(NID_NET_NFC, r, "[%s] Propagating. Deleting the row to the DB has failed.", GetErrorMessage(r));
+               }
+       }
+
+       __rsvdPushDb.CommitTransaction();
+
+       // The application ID is removed from the list
+       if (__reserverAppIdList.Contains(appId))
+       {
+               r = __reserverAppIdList.Remove(appId);
+               SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Removing the specific app ID from the list has failed.");
+
+               // Checks the removed item is the currently selected item.
+               pCurrentItemStr = vconf_get_str(VCONFKEY_NFC_PREDEFINED_ITEM);
+               SysTryReturnResult(NID_NET_NFC, pCurrentItemStr != null, E_SYSTEM, "Failed to get the Predefined Item value (vconf).");
+
+               if (appId.Equals(String(pCurrentItemStr)))
+               {
+                       if (__reserverAppIdList.GetCount() <= 0)
+                       {
+                               // Especially, if no more element in the list, set the value by "None"
+                               vconfRes = vconf_set_str(VCONFKEY_NFC_PREDEFINED_ITEM, "None");
+                               SysTryReturnResult(NID_NET_NFC, vconfRes == 0, E_SYSTEM, "Failed set the Predefined Item value (vconf).");
+                               SysLog(NID_NET_NFC, "The selected NDEF message for the Reserved Push is set to \"None\".");
+                       }
+                       else
+                       {
+                               // Set the vconf value by the first element of the list if it exists.
+                               String newItem;
+                               char* pNewItemStr = null;
+                               r = __reserverAppIdList.GetAt(0, newItem);
+                               SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to set the Predefined Item value (vconf).");
+
+                               pNewItemStr = _StringConverter::CopyToCharArrayN(newItem);
+                               SysTryReturnResult(NID_NET_NFC, pNewItemStr != null, E_SYSTEM, "Failed set the Predefined Item value (vconf).");
+
+                               vconfRes = vconf_set_str(VCONFKEY_NFC_PREDEFINED_ITEM, pNewItemStr);
+                               delete[] pNewItemStr;
+                               SysTryReturnResult(NID_NET_NFC, vconfRes == 0, E_SYSTEM, "Failed set the Predefined Item value (vconf).");
+                               SysLog(NID_NET_NFC, "The NDEF message (AppId: %ls) for the Reserved Push is selected.", newItem.GetPointer());
+                       }
+               }
+
+               free(pCurrentItemStr);
+       }
+
+       delete pDeleteEnum;
+       delete pDeleteStmt;
+
+       locked.Unlock();
+
+       return r;
+}
+
+void
+NfcMessageRegisterService::OnPackageUninstallationCompleted(const Tizen::App::PackageId& packageId, bool uninstallationResult)
+{
+       if ((__reserverAppIdList.Contains(packageId)) && (uninstallationResult == true))
+       {
+               SysLog(NID_NET_NFC, "The application (ID:%ls) which was reserving the NFC push message is uninstalled.", packageId.GetPointer());
+               UnregisterPushMessage(packageId);
+       }
+}
+
+result
+NfcMessageRegisterService::InitializeAppIdList(void)
+{
+       const wchar_t* _CREATE_TABLE_SQL =
+                       L"CREATE TABLE IF NOT EXISTS NfcPushMsgTable ( AppId TEXT PRIMARY KEY, PkgName TEXT, IconPath TEXT, MsgDesc TEXT )";
+       const wchar_t* _QUERY_ALL_ITEM_SQL = L"SELECT * FROM NfcPushMsgTable";
+       result r = E_SUCCESS;
+       DbEnumerator* pQueryEnum = null;
+
+       r = __rsvdPushDb.Construct(_META_DATA_DB_NAME, true);
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construction of the database has failed.");
+
+       // create the table if it does not exist.
+       r = __rsvdPushDb.ExecuteSql(_CREATE_TABLE_SQL, true);
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Creating the DB table for push message has failed.");
+
+       pQueryEnum = __rsvdPushDb.QueryN(_QUERY_ALL_ITEM_SQL);
+       if (pQueryEnum != null)
+       {
+               String appId;
+
+               while (pQueryEnum->MoveNext() == E_SUCCESS)
+               {
+                       appId.Clear();
+                       r = pQueryEnum->GetStringAt(0, appId);
+                       if (r == E_SUCCESS)
+                       {
+                               r = __reserverAppIdList.Add(appId);
+                               if (r == E_SUCCESS)
+                               {
+                                       SysLog(NID_NET_NFC, "There is a reserved push message for app (ID:%ls)", appId.GetPointer());
+                               }
+                               else
+                               {
+                                       SysLogException(NID_NET_NFC, E_SYSTEM, "[E_SYSTEM] Insertion a new item to the app ID list has failed.");
+                                       // continue
+                               }
+                       }
+                       else
+                       {
+                               SysLogException(NID_NET_NFC, E_SYSTEM, "[E_SYSTEM] Getting the list of app ID from the DB table has failed.");
+                               // continue
+                       }
+               }
+
+               delete pQueryEnum;
+       }
+
+       SysLog(NID_NET_NFC, "Reading the database for NFC Reserved Push is completed.");
+
+       return E_SUCCESS;
+}
diff --git a/src/NfcService.cpp b/src/NfcService.cpp
new file mode 100644 (file)
index 0000000..358320f
--- /dev/null
@@ -0,0 +1,311 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file    NfcService.cpp
+ * @brief   This is the implementation file for the %NfcService class.
+ */
+
+#include <glib.h>
+#include <nfc.h>
+#include <unique_ptr.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtMutexGuard.h>
+#include <FAppApp.h>
+#include <FApp_AppManagerImpl.h>
+#include <FSys_SystemInfoImpl.h>
+#include "NfcService.h"
+#include "NfcMessageRegisterService.h"
+#include "NfcMessagePushDelegate.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::App;
+using namespace Tizen::System;
+
+NfcService::NfcService(void)
+       : __pRegisterService(null)
+       , __pPushDelegate(null)
+       , __enablingMutex()
+       , __popupEnabled(false)
+       , __serviceDaemonAppId()
+       , __popupDisablerId()
+       , __appIdListMutex()
+       , __appIdList()
+{
+       __serviceDaemonAppId = App::GetInstance()->GetAppId();
+}
+
+
+NfcService::~NfcService(void)
+{
+    vconf_ignore_key_changed(VCONFKEY_NFC_STATE, OnNfcActivationChanged);
+       (void) _AppManagerImpl::GetInstance()->RemoveEventListener(*this);
+
+       delete __pRegisterService;
+       delete __pPushDelegate;
+
+       if (__appIdList.GetCount() > 0)
+       {
+               (void) nfc_manager_deinitialize();
+       }
+}
+
+result
+NfcService::Construct(void)
+{
+       result r = E_SUCCESS;
+       bool isNfcSupported = false;
+       int vconfRes = 0;
+       int nfcState = -1;
+
+       r = _SystemInfoImpl::GetSysInfo(L"NFCSupported", isNfcSupported);
+       SysTryReturnResult(NID_NET_NFC, (r == E_SUCCESS) && (isNfcSupported == true), E_UNSUPPORTED_OPERATION,
+                         "NFC is not supported.");
+
+       r = __enablingMutex.Create();
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
+
+       r = __appIdListMutex.Create();
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
+
+       __pRegisterService = new (std::nothrow) NfcMessageRegisterService();
+       SysTryReturnResult(NID_NET_NFC, __pRegisterService != null, E_OUT_OF_MEMORY, "Insufficient memory.");
+
+       r = __pRegisterService->Construct();
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to construct NfcMessageRegisterService.");
+
+       __pPushDelegate = new (std::nothrow) NfcMessagePushDelegate();
+       SysTryReturnResult(NID_NET_NFC, __pPushDelegate != null, E_OUT_OF_MEMORY, "Insufficient memory.");
+
+       // get the current NFC state value (1 on ACTIVATED, 0 on DEACTIVATED)
+       vconfRes = vconf_get_bool(VCONFKEY_NFC_STATE, &nfcState);
+       SysTryReturnResult(NID_NET_NFC, vconfRes == 0, E_SYSTEM, "Failed to get the vconf - NFC STATE - value.");
+
+       if (nfcState == VCONFKEY_NFC_STATE_ON)
+       {
+               SysLog(NID_NET_NFC, "NFC is currently activated.");
+               // initialize NFC because NFC is already turned on
+               r = AddNfcAppId(__serviceDaemonAppId);
+               SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, r, "Propagating.");
+       }
+
+       // register AppManager event listener for noticing that the managed applications terminate
+       r = _AppManagerImpl::GetInstance()->AddEventListener(*this);
+       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Registration of an _IAppManagerEventListener has failed.");
+
+       // set vconf callback about the NFC activation mode change
+       vconf_notify_key_changed(VCONFKEY_NFC_STATE, OnNfcActivationChanged, this);
+
+       return E_SUCCESS;
+}
+
+result
+NfcService::AddNfcAppId(const Tizen::Base::String& appId)
+{
+       result r = E_SUCCESS;
+    int nfcRes = NFC_ERROR_NONE;
+
+       MutexGuard locked(__appIdListMutex);
+
+       // Initialize NFC client of osp-connectivity-service if the first application initializes its NFC client.
+       if (__appIdList.GetCount() == 0)
+       {
+           nfcRes = nfc_manager_initialize(null, null);
+           SysTryReturnResult(NID_NET_NFC, nfcRes == NFC_ERROR_NONE, E_SYSTEM, "Initializing NFC has failed. [0x%x]", nfcRes);
+
+           __pPushDelegate->Initialize();
+               SysLog(NID_NET_NFC, "Initializing NFC is successful.");
+       }
+
+       // Add the ID of the application which initializes Nfc client to the list.
+       if (!__appIdList.Contains(appId))
+       {
+               r = __appIdList.Add(appId);
+               SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Insertion a new item to the app ID list has failed.");
+       }
+
+       locked.Unlock();
+
+       return E_SUCCESS;
+}
+
+void
+NfcService::RemoveNfcAppId(const Tizen::Base::String& appId)
+{
+       result r = E_SUCCESS;
+    int nfcRes = NFC_ERROR_NONE;
+
+       // Deinitialize NFC client if the last application which initialized the NFC is terminated.
+    MutexGuard locked(__appIdListMutex);
+
+       if (__appIdList.Contains(appId))
+       {
+               r = __appIdList.Remove(appId);
+
+               if ((r == E_SUCCESS) && (__appIdList.GetCount() == 0))
+               {
+                       nfcRes = nfc_manager_deinitialize();
+                   SysTryReturnVoidResult(NID_NET_NFC, nfcRes == NFC_ERROR_NONE, E_SYSTEM,
+                               "[E_SYSTEM] Deinitializing NFC has failed. [0x%x]", nfcRes);
+
+                   __pPushDelegate->Deinitialize();
+                       SysLog(NID_NET_NFC, "Deinitializing NFC is successful.");
+               }
+       }
+
+       locked.Unlock();
+}
+
+result
+NfcService::SetLaunchPopupEnabled(const Tizen::Base::String& clientAppId, bool enable)
+{
+       result r = E_SUCCESS;
+       int nfcRes = NFC_ERROR_NONE;
+
+       MutexGuard locked(__enablingMutex);
+
+       // Updates the setting value and saves the ID of the setter application.
+       if (enable == false)
+       {
+               nfcRes = nfc_manager_set_system_handler_enable(false);
+
+               if (nfcRes == NFC_ERROR_NONE)
+               {
+                       __popupEnabled = false;
+                       __popupDisablerId = clientAppId;
+
+                       SysLog(NID_NET_NFC, "Disabling the launch popup is successful.");
+               }
+               else
+               {
+                       r = E_SYSTEM;
+                       SysLog(NID_NET_NFC, "Disabling the launch popup has failed.");
+               }
+       }
+       else
+       {
+               if ((__popupEnabled == false) && (__popupDisablerId == clientAppId))
+               {
+                       nfcRes = nfc_manager_set_system_handler_enable(true);
+
+                       if (nfcRes == NFC_ERROR_NONE)
+                       {
+                               __popupEnabled = true;
+                               __popupDisablerId.Clear();
+
+                               SysLog(NID_NET_NFC, "Enabling the launch popup is successful.");
+                       }
+                       else
+                       {
+                               r = E_SYSTEM;
+                               SysLog(NID_NET_NFC, "Enabling the launch popup has failed.");
+                       }
+               }
+       }
+
+       locked.Unlock();
+
+       return r;
+}
+
+result
+NfcService::RegisterPushMessage(const Tizen::Base::String& clientAppId, const Tizen::Base::ByteBuffer& pushMessageBuffer,
+               const Tizen::Base::String& description)
+{
+       return __pRegisterService->RegisterPushMessage(clientAppId, pushMessageBuffer, description);
+}
+
+result
+NfcService::UnregisterPushMessage(const Tizen::Base::String& clientAppId)
+{
+       return __pRegisterService->UnregisterPushMessage(clientAppId);
+}
+
+void
+NfcService::OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type)
+{
+       // do nothing.
+}
+
+void
+NfcService::OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type)
+{
+       int nfcRes = NFC_ERROR_NONE;
+
+       MutexGuard locked(__enablingMutex);
+
+       if ((__popupEnabled == false) && (__popupDisablerId == appId))
+       {
+               SysLog(NID_NET_NFC, "The application (ID:'%S') which disabled the launch popup is terminated.", appId.GetPointer());
+
+               nfcRes = nfc_manager_set_system_handler_enable(true);
+
+               if (nfcRes == NFC_ERROR_NONE)
+               {
+                       __popupEnabled = true;
+                       __popupDisablerId.Clear();
+
+                       SysLog(NID_NET_NFC, "Enabling the launch popup is successful.");
+               }
+               else
+               {
+                       SysLog(NID_NET_NFC, "Enabling the launch popup has failed.");
+               }
+       }
+
+       locked.Unlock();
+
+       // Remove appId if it was added to the list.
+       RemoveNfcAppId(appId);
+}
+
+void
+NfcService::OnNfcActivationChanged(keynode_t* pKeyNode, void* pUserData)
+{
+       char* pKeyStr = null;
+       NfcService* pService = null;
+       int vconfRes = 0;
+       int nfcState = -1;
+
+       SysLog(NID_NET_NFC, "The key changed event (VCONFKEY_NFC_STATE) is invoked.");
+
+       // check the key name
+       pKeyStr = vconf_keynode_get_name(pKeyNode);
+       SysTryReturnVoidResult(NID_NET_NFC, pKeyStr != null, E_SYSTEM, "[E_SYSTEM] Failed to get the vconf pKeyNode name.");
+       SysTryReturnVoidResult(NID_NET_NFC, strcmp(pKeyStr, VCONFKEY_NFC_STATE) == 0, E_SYSTEM,
+                       "[E_SYSTEM] the vconf key name is not about the NFC activation.");
+
+       // get the NFC state value
+       vconfRes = vconf_get_bool(VCONFKEY_NFC_STATE, &nfcState);
+       SysTryReturnVoidResult(NID_NET_NFC, vconfRes == 0, E_SYSTEM, "[E_SYSTEM] Failed to get the vconf - NFC STATE - value.");
+
+       pService = static_cast<NfcService*>(pUserData);
+
+       if (nfcState == VCONFKEY_NFC_STATE_ON)
+       {
+               pService->AddNfcAppId(pService->__serviceDaemonAppId);
+       }
+       else if (nfcState == VCONFKEY_NFC_STATE_OFF)
+       {
+               pService->RemoveNfcAppId(pService->__serviceDaemonAppId);
+       }
+       // ignore other cases
+}
diff --git a/src/TelephonyConnectivityIpcMessages.cpp b/src/TelephonyConnectivityIpcMessages.cpp
new file mode 100644 (file)
index 0000000..3a6033b
--- /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    TelephonyConnectivityIpcMessages.cpp
+ * @brief   This is the generator of IPC messages for the Connectivity service daemon.
+ */
+
+#define IPC_MESSAGE_IMPL
+#include <FTel_ConnectivityIpcMessages.h>
+
+// Generate constructors.
+#include <ipc/struct_constructor_macros.h>
+#include <FTel_ConnectivityIpcMessages.h>
+
+// Generate destructors.
+#include <ipc/struct_destructor_macros.h>
+#include <FTel_ConnectivityIpcMessages.h>
+
+// Generate param traits write methods.
+#include <ipc/param_traits_write_macros.h>
+namespace IPC {
+#include <FTel_ConnectivityIpcMessages.h>
+}  // namespace IPC
+
+// Generate param traits read methods.
+#include <ipc/param_traits_read_macros.h>
+namespace IPC {
+#include <FTel_ConnectivityIpcMessages.h>
+}  // namespace IPC
diff --git a/src/TelephonyConnectivityIpcStub.cpp b/src/TelephonyConnectivityIpcStub.cpp
new file mode 100755 (executable)
index 0000000..51df7d6
--- /dev/null
@@ -0,0 +1,405 @@
+//
+// 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    TelephonyConnectivityIpcStub.cpp
+ * @brief   This is the implementation file for the %TelephonyConnectivityIpcStub class.
+ */
+#include <unique_ptr.h>
+#include <FBaseSysLog.h>
+#include <FIo_IpcServer.h>
+#include <FTel_ConnectivityIpcMessages.h>
+#include <FIo_IpcCommonParamTraits.h>
+#include <FSec_AccessController.h>
+#include "TelephonyConnectivityIpcStub.h"
+#include "TelephonyService.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+using namespace Tizen::Net;
+
+TelephonyConnectivityIpcStub::TelephonyConnectivityIpcStub(void)
+       : __pTelephonyService(null)
+       , __pIpcServer(null)
+{
+}
+
+TelephonyConnectivityIpcStub::~TelephonyConnectivityIpcStub(void)
+{
+       delete __pIpcServer;
+}
+
+result
+TelephonyConnectivityIpcStub::Construct(void)
+{
+       result r = E_SUCCESS;
+       result retVal = E_SUCCESS;
+
+       __pTelephonyService = TelephonyService::GetInstance();
+       SysTryCatch(NID_TEL, __pTelephonyService != null, retVal = E_SYSTEM, E_SYSTEM,
+                       "[%s] A system error has been occurred. Failed to get the instance of TelephonyService.");
+
+       r = __pTelephonyService->Construct(this);
+       if (r == E_SUCCESS)
+    {
+           SysLog(NID_TEL, "TelephonyService is created.");
+    }
+    else
+    {
+        // skip Telephony service
+        SysLogException(NID_TEL, r, "[%s] Failed to construct TelephonyService.", GetErrorMessage(r));
+        __pTelephonyService = null;
+    }
+
+       __pIpcServer = new (std::nothrow) _IpcServer;
+       SysTryCatch(NID_TEL, __pIpcServer != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = __pIpcServer->Construct(TELEPHONY_CONNECTIVITY_IPC_SERVER_NAME, *this);
+       SysTryCatch(NID_TEL, r == E_SUCCESS, retVal = E_SYSTEM, E_SYSTEM,
+                       "[%s] A system error has been occurred. Failed to construct IpcServer.", GetErrorMessage(E_SYSTEM));
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+
+       return retVal;
+}
+
+void
+TelephonyConnectivityIpcStub::OnIpcServerStarted(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_TEL, "TelephonyConnectivityIpcStub started.");
+}
+
+void
+TelephonyConnectivityIpcStub::OnIpcServerStopped(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_TEL, "TelephonyConnectivityIpcStub stopped.");
+}
+
+void
+TelephonyConnectivityIpcStub::OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId)
+{
+       SysLog(NID_TEL, "Connected with clientId[%d].", clientId);
+}
+
+void
+TelephonyConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId)
+{
+       SysLog(NID_TEL, "Disconnected with clientId[%d].", clientId);
+}
+
+void
+TelephonyConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message)
+{
+       IPC_BEGIN_MESSAGE_MAP(TelephonyConnectivityIpcStub, message)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_getImsi, OnGetTelephonyImsi, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_hasSystemPrivilege, OnHasTelephonySystemPrivilege, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_getNetworkSelectionMode, OnGetTelephonyNetworkSelectionMode, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_selectNetworkManual, OnSelectTelephonyNetworkManual, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_selectNetworkAutomatic, OnSelectTelephonyNetworkAutomatic, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_searchNetwork, OnSearchTelephonyNetwork, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_hasCallForwardPrivilege, OnHasCallForwardPrivilege, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_requestCallForward, OnRequestCallForward, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_stopCallForward, OnStopCallForward, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_getCallForwardNumber, OnGetCallForwardNumber, &server)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+TelephonyConnectivityIpcStub::OnGetTelephonyImsi(Tizen::Base::String* pImsi, unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request of getting the telephony imsi with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_USERIDENTITY);
+
+    if (*pResult != E_SUCCESS)
+    {
+        *pResult = E_PRIVILEGE_DENIED;
+        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+        *pResult = __pTelephonyService->GetImsi(pImsi);
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnHasTelephonySystemPrivilege(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request of checking system privilege with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_TELEPHONYMANAGER);
+
+    if (*pResult != E_SUCCESS)
+    {
+        *pResult = E_PRIVILEGE_DENIED;
+        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnGetTelephonyNetworkSelectionMode(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request of getting the network selected mode with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    SysLog(NID_TEL, "ipcserver : %d",__pIpcServer);
+
+    String appId = __pIpcServer->GetClientAppId();
+
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_TELEPHONYMANAGER);
+
+    if (*pResult != E_SUCCESS)
+    {
+       *pResult = E_PRIVILEGE_DENIED;
+       SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                  "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+       *pResult = __pTelephonyService->GetNetworkSelectionMode(__pIpcServer->GetClientId());
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnSelectTelephonyNetworkManual(const Tizen::Base::String& plmn, const int networkType, unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for selecting network manually with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_TELEPHONYMANAGER);
+
+    if (*pResult != E_SUCCESS)
+    {
+       *pResult = E_PRIVILEGE_DENIED;
+       SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                  "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+       *pResult = __pTelephonyService->SelectNetwork(__pIpcServer->GetClientId(), plmn, networkType);
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnSelectTelephonyNetworkAutomatic(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for selecting network automatically with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_TELEPHONYMANAGER);
+
+
+    if (*pResult != E_SUCCESS)
+    {
+       *pResult = E_PRIVILEGE_DENIED;
+       SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                  "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+       *pResult = __pTelephonyService->SelectNetwork(__pIpcServer->GetClientId());
+
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnSearchTelephonyNetwork(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for searching network with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_TELEPHONYMANAGER);
+
+    if (*pResult != E_SUCCESS)
+    {
+       *pResult = E_PRIVILEGE_DENIED;
+       SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                  "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+       *pResult = __pTelephonyService->SearchNetwork(__pIpcServer->GetClientId());
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnHasCallForwardPrivilege(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request of checking call forward privilege with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+    String appId = __pIpcServer->GetClientAppId();
+    *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_CALLFORWARD);
+
+    if (*pResult != E_SUCCESS)
+    {
+        *pResult = E_PRIVILEGE_DENIED;
+        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnRequestCallForward(const String& phoneNumber, unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for requesting call forward with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       String appId = __pIpcServer->GetClientAppId();
+       *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_CALLFORWARD);
+
+    if (*pResult != E_SUCCESS)
+    {
+       *pResult = E_PRIVILEGE_DENIED;
+       SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                  "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+       *pResult = __pTelephonyService->RequestCallForward(__pIpcServer->GetClientId(), phoneNumber);
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnStopCallForward(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for stopping call forward with clientId : %d, AppId : %ls",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       String appId = __pIpcServer->GetClientAppId();
+       *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_CALLFORWARD);
+
+    if (*pResult != E_SUCCESS)
+    {
+       *pResult = E_PRIVILEGE_DENIED;
+       SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                  "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+       *pResult = __pTelephonyService->StopCallForward(__pIpcServer->GetClientId());
+    }
+}
+
+void
+TelephonyConnectivityIpcStub::OnGetCallForwardNumber(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for getting call forward number with clientId : %d, AppId : %ls",
+          __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       String appId = __pIpcServer->GetClientAppId();
+       *pResult = _AccessController::CheckSystemPrivilege(appId, _PRV_CALLFORWARD);
+
+    if (*pResult != E_SUCCESS)
+    {
+        *pResult = E_PRIVILEGE_DENIED;
+        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
+                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+    }
+    else
+    {
+         *pResult = __pTelephonyService->GetCallForwardNumber(__pIpcServer->GetClientId());
+    }
+}
+result
+TelephonyConnectivityIpcStub::SendNetworkSelectionModeReceived(int clientId, bool isManual, unsigned long res)
+{
+    SysLog(NID_TEL, "SendNetworkSelectionModeReceived with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow)
+               ConnectivityTelephonyServiceMsg_onNetworkSelectionModeReceived(isManual, res));
+    SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    SysLog(NID_TEL, "before SendResponse");
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+
+}
+
+result
+TelephonyConnectivityIpcStub::SendNetworkSelectionCompleted(int clientId, unsigned long res)
+{
+    SysLog(NID_TEL, "SendNetworkSelectionCompleted with clientId : %d", clientId);
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityTelephonyServiceMsg_onNetworkSelectionCompleted(res));
+    SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+TelephonyConnectivityIpcStub::SendNetworkSearchCompleted(int clientId, Tizen::Base::String message, unsigned long res)
+{
+    SysLog(NID_TEL, "SendNetworkSearchCompleted with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow)
+               ConnectivityTelephonyServiceMsg_onNetworkSearchCompleted(message, res));
+    SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+
+}
+
+
+result
+TelephonyConnectivityIpcStub::SendCallForwardNumberReceived(int clientId, String phoneNumber, unsigned long res)
+{
+    SysLog(NID_TEL, "SendCallForwardNumberReceived with clientId : %d",        clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow)
+               ConnectivityTelephonyServiceMsg_onCallForwardNumberReceived(phoneNumber, res));
+    SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+TelephonyConnectivityIpcStub::SendCallForwardResponseReceived(int clientId, String phoneNumber, unsigned long res)
+{
+    SysLog(NID_TEL, "SendCallForwardResponseReceived with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow)
+               ConnectivityTelephonyServiceMsg_onCallForwardResponseReceived(phoneNumber, res));
+    SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+TelephonyConnectivityIpcStub::SendCallForwardStopped(int clientId, String phoneNumber, unsigned long res)
+{
+    SysLog(NID_TEL, "SendCallForwardStopped with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityTelephonyServiceMsg_onCallForwardStopped(phoneNumber, res));
+    SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
diff --git a/src/TelephonyService.cpp b/src/TelephonyService.cpp
new file mode 100755 (executable)
index 0000000..10811db
--- /dev/null
@@ -0,0 +1,487 @@
+//
+// 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    TelephonyService.cpp
+ * @brief   This is the implementation file for the %TelephonyService class.
+ */
+#include <unique_ptr.h> 
+#include <pthread.h>
+#include <sim.h>
+#include <ITapiNetwork.h>
+#include <ITapiSs.h>
+#include <TapiUtility.h>
+#include <TelNetwork.h>
+#include <FApp_AppManagerImpl.h>
+#include <FBaseSysLog.h>
+#include <FBaseString.h>
+#include <TelephonyConnectivityIpcStub.h>
+#include "FBase_StringConverter.h"
+#include "TelephonyService.h"
+
+using namespace std;
+using namespace Tizen::Base;
+
+TelephonyService* TelephonyService::__pTelephonyService = null;
+
+void
+TelephonyService::InitTelephonyService()
+{
+    static TelephonyService telephonyService;
+    __pTelephonyService = &telephonyService;
+}
+
+TelephonyService*
+TelephonyService::GetInstance(void)
+{
+    static pthread_once_t once_block = PTHREAD_ONCE_INIT;
+
+    if (__pTelephonyService == null)
+    {
+        pthread_once(&once_block, InitTelephonyService);
+    }
+
+    return __pTelephonyService;
+}
+
+
+TelephonyService::TelephonyService(void)
+    : __pHandle(null)
+    , __pStub(null)
+{
+}
+
+
+TelephonyService::~TelephonyService(void)
+{
+    if (__pHandle != null)
+    {
+        tel_deinit(__pHandle);
+    }
+}
+
+result
+TelephonyService::Construct(TelephonyConnectivityIpcStub* pStub)
+{
+    __pHandle = tel_init(null);
+    SysTryReturnResult(NID_TEL, __pHandle != null, E_SYSTEM, "Failed to get Tapi handle.");
+
+    __pStub = pStub;
+
+    return E_SUCCESS;
+}
+
+result
+TelephonyService::GetImsi(Tizen::Base::String* pImsi)
+{
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    String imsi;
+
+    int err = SIM_ERROR_NONE;
+    char* pMcc = null;
+    char* pMnc = null;
+    char* pMsin = null;
+
+    err = sim_get_mcc(&pMcc);
+    SysLog(NID_TEL, "[%d] return value of sim_get_mcc() - mcc : %s", err, pMcc);
+    SysTryReturnResult(NID_TEL, err == SIM_ERROR_NONE, E_SYSTEM, "Failed to get mcc.");
+
+    err = sim_get_mnc(&pMnc);
+    SysLog(NID_TEL, "[%d] return value of sim_get_mnc() - mnc : %s", err, pMnc);
+    SysTryCatch(NID_TEL, err == SIM_ERROR_NONE, , E_SYSTEM, "Failed to get mnc.");
+
+    err = sim_get_msin(&pMsin);
+    SysLog(NID_TEL, "[%d] return value of sim_get_msin() - msin : %s", err, pMsin);
+    SysTryCatch(NID_TEL, err == SIM_ERROR_NONE, , E_SYSTEM, "Failed to get msin.");
+
+    pImsi->Append(pMcc);
+    pImsi->Trim();
+    pImsi->Append(pMnc);
+    pImsi->Trim();
+    pImsi->Append(pMsin);
+    pImsi->Trim();
+
+    return E_SUCCESS;
+
+CATCH:
+    if (pMcc != null)
+    {
+        free(pMcc);
+    }
+
+    if (pMnc != null)
+    {
+        free(pMnc);
+    }
+
+    return E_SYSTEM;
+}
+
+result
+TelephonyService::GetNetworkSelectionMode(int clientId)
+{
+    SysAssertf(__pStub != null, "Not yet constructed. Construct() should be called before use.");
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    int* pClientId = new int(clientId);
+
+    int err = tel_get_network_selection_mode(__pHandle, OnNetworkSelectionModeReceived, pClientId);
+    SysLog(NID_TEL, "[%d] return value of tel_get_network_selection_mode()", err);
+
+    SysTryReturnResult(NID_TEL, err == TAPI_API_SUCCESS, E_SYSTEM, "Failed to get network selection mode.");
+
+    return E_SUCCESS;
+}
+
+result
+TelephonyService::SelectNetwork(int clientId, const Tizen::Base::String& plmn, int networkType)
+{
+    SysAssertf(__pStub != null, "Not yet constructed. Construct() should be called before use.");
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    int* pClientId = new int(clientId);
+
+    char* pPlmn = _StringConverter::CopyToCharArrayN(plmn);
+    int err = tel_select_network_manual(__pHandle, pPlmn, networkType, OnNetworkSelectCompleted, pClientId);
+    SysLog(NID_TEL, "[%d] return value of tel_select_network_manual()", err);
+
+    free(pPlmn);
+
+    SysTryReturnResult(NID_TEL, err == TAPI_API_SUCCESS, E_SYSTEM, "Failed to select network manually.");
+
+    return E_SUCCESS;
+}
+
+result
+TelephonyService::SelectNetwork(int clientId)
+{
+    SysAssertf(__pStub != null, "Not yet constructed. Construct() should be called before use.");
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    int* pClientId = new int(clientId);
+
+    int err = tel_select_network_automatic(__pHandle, OnNetworkSelectCompleted, pClientId);
+    SysLog(NID_TEL, "[%d] return value of tel_select_network_automatic()", err);
+
+    SysTryReturnResult(NID_TEL, err == TAPI_API_SUCCESS, E_SYSTEM, "Failed to select network automatically.");
+
+    return E_SUCCESS;
+}
+
+result
+TelephonyService::SearchNetwork(int clientId)
+{
+    SysAssertf(__pStub != null, "Not yet constructed. Construct() should be called before use.");
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    int* pClientId = new int(clientId);
+
+    int err = tel_search_network(__pHandle, OnNetworkSearchCompleted, pClientId);
+    SysLog(NID_TEL, "[%d] return value of tel_search_network()", err);
+
+    SysTryReturnResult(NID_TEL, err == TAPI_API_SUCCESS, E_SYSTEM, "Failed on search operation.");
+
+    return E_SUCCESS;
+}
+
+result
+TelephonyService::RequestCallForward(int clientId, const Tizen::Base::String& phoneNumber)
+{
+    SysAssertf(__pStub != null, "Not yet constructed. Construct() should be called before use.");
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    int* pClientId = new int(clientId);
+    int err = TAPI_SS_SUCCESS;
+       unique_ptr<char[]> pTempPhoneNumber;
+    TelSsForwardInfo_t forwardInfo = {};
+    forwardInfo.Class = TAPI_SS_CLASS_VOICE;
+    forwardInfo.Mode = TAPI_SS_CF_MODE_REGISTRATION_EV;
+    forwardInfo.Condition = TAPI_SS_CF_WHEN_CFU;
+    forwardInfo.NoReplyConditionTimer = TAPI_SS_CF_NO_REPLY_TIME_10_SECS;
+       pTempPhoneNumber.reset(_StringConverter::CopyToCharArrayN(phoneNumber));
+       SysTryReturnResult(NID_TEL, pTempPhoneNumber != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       strcpy(forwardInfo.szPhoneNumber, pTempPhoneNumber.get());
+       err = tel_set_ss_forward(__pHandle, &forwardInfo, OnCallForwardResponseReceivedCallback, pClientId);
+       SysLog(NID_TEL, "The forwardInfo.szPhoneNumber is %s and err value is 0x%x", forwardInfo.szPhoneNumber, err);
+    SysTryReturnResult(NID_TEL, err == TAPI_SS_SUCCESS, E_SYSTEM, "Failed to request a call forwarding.");
+
+    return E_SUCCESS;
+}
+
+result
+TelephonyService::StopCallForward(int clientId)
+{
+    SysAssertf(__pStub != null, "Not yet constructed. Construct() should be called before use.");
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    int* pClientId = new int(clientId);
+
+    int err = TAPI_SS_SUCCESS;
+    TelSsForwardInfo_t forwardInfo = {};
+    forwardInfo.Class = TAPI_SS_CLASS_VOICE;
+    forwardInfo.Mode = TAPI_SS_CF_MODE_ERASURE_EV;
+       forwardInfo.Condition = TAPI_SS_CF_WHEN_CFU;
+    err = tel_set_ss_forward(__pHandle, &forwardInfo, OnCallForwardStoppedCallback, pClientId);
+       SysLog(NID_TEL, "The  err value is 0x%x", err);
+    SysTryReturnResult(NID_TEL, err == TAPI_API_SUCCESS, E_SYSTEM, "Failed to stop a call forwarding.");
+
+    return E_SUCCESS;
+}
+
+result
+TelephonyService::GetCallForwardNumber(int clientId)
+{
+    SysAssertf(__pStub != null, "Not yet constructed. Construct() should be called before use.");
+    SysAssertf(__pHandle != null, "Not yet constructed. Construct() should be called before use.");
+
+    int* pClientId = new int(clientId);
+    int err = TAPI_SS_SUCCESS;
+
+    err = tel_get_ss_forward_status(__pHandle, TAPI_SS_CLASS_ALL_TELE, TAPI_SS_CF_WHEN_CFU,
+            OnCallForwardNumberReceivedCallback, pClientId);
+       SysLog(NID_TEL, "The err value is 0x%x and the clientId is %d", err, clientId);
+    SysTryReturnResult(NID_TEL, err == TAPI_SS_SUCCESS, E_SYSTEM, "Failed to request a call forwarding number.");
+
+    return E_SUCCESS;
+}
+
+void
+TelephonyService::OnNetworkSelectionModeReceived(TapiHandle* pHandle, int err, void* pData, void* pUserData)
+{
+    SysLog(NID_TEL, "Called OnNetworkSelectionModeReceived : 0x%x", err);
+
+    int* pClientId = static_cast<int*>(pUserData);
+    SysLog(NID_TEL, "Client ID : %d", *pClientId);
+
+    result r = ConvertError(err);
+    TelNetworkSelectionMode_t mode = *(static_cast<TelNetworkSelectionMode_t*>(pData));
+    SysLog(NID_TEL, "Selection mode is %d ", mode);
+
+    result res = E_SUCCESS;
+
+    if (mode == TAPI_NETWORK_SELECTIONMODE_MANUAL)
+    {
+        res = __pTelephonyService->__pStub->SendNetworkSelectionModeReceived(*pClientId, true ,r);
+    }
+    else
+    {
+        res = __pTelephonyService->__pStub->SendNetworkSelectionModeReceived(*pClientId, false ,r);
+    }
+    SysLog(NID_TEL, "Called SendNetworkSelectionModeReceived : %s", GetErrorMessage(res));
+
+    delete pClientId;
+}
+
+void
+TelephonyService::OnNetworkSelectCompleted(TapiHandle* pHandle, int err, void* pData, void* pUserData)
+{
+    SysLog(NID_TEL, "Called OnNetworkSelectCompleted : 0x%x", err);
+
+    int* pClientId = static_cast<int*>(pUserData);
+    SysLog(NID_TEL, "Client ID : %d", *pClientId);
+
+    result r = ConvertError(err);
+
+    result res = __pTelephonyService->__pStub->SendNetworkSelectionCompleted(*pClientId, r);
+    SysLog(NID_TEL, "Called SendNetworkSelectionCompleted : %s", GetErrorMessage(res));
+
+    delete pClientId;
+}
+
+void
+TelephonyService::OnNetworkSearchCompleted(TapiHandle* pHandle, int err, void* pData, void* pUserData)
+{
+    SysLog(NID_TEL, "Called OnNetworkSearchCompleted : 0x%x", err);
+
+    int* pClientId = static_cast<int*>(pUserData);
+    SysLog(NID_TEL, "Client ID : %d", *pClientId);
+   
+    result r = ConvertError(err);
+    String responseMessage;
+    TelNetworkPlmnList_t* pList = (TelNetworkPlmnList_t*) pData;
+    int networkInfoCount = static_cast<int>(pList->networks_count);
+
+    responseMessage.Append(networkInfoCount);
+    responseMessage.Append(L":");
+    SysLog(NID_TEL, "Append the number of list : %d", networkInfoCount);
+    
+    for (int i = 0 ; i < networkInfoCount ; i++)
+    {
+        responseMessage.Append(MakeNetworkInfoMessage(pList->network_list[i]));
+    }
+
+    SysLog(NID_TEL, "Full Message - %ls", responseMessage.GetPointer());
+
+    result res = __pTelephonyService->__pStub->SendNetworkSearchCompleted(*pClientId, responseMessage, r);
+    SysLog(NID_TEL, "Called SendNetworkSearchCompleted : %s", GetErrorMessage(res));
+
+    delete pClientId;
+}
+
+void
+TelephonyService::OnCallForwardNumberReceivedCallback(TapiHandle* pHandle,int err, void* pData, void* pUserData)
+{
+    SysLog(NID_TEL, "Called OnCallForwardNumberReceivedCallback : 0x%x", err);
+
+    TelSsForwardResp_t* pCallForwardData = (TelSsForwardResp_t*)pData;
+    int* pClientId = static_cast<int*>(pUserData);
+    result r = E_SUCCESS;
+
+    String phoneNumber;
+
+    switch (err)
+    {
+    case TAPI_SS_SUCCESS:
+        r = E_SUCCESS;
+        phoneNumber = String((const char*) pCallForwardData->record[0].szCallForwardingNumber);
+        break;
+    case TAPI_SS_NOTAVAILABLE:
+        SysLog(NID_TEL, "[E_SERVICE_DEACTIVATED] The call forwarding service is not available.");
+        r = E_SERVICE_DEACTIVATED;
+        break;
+    case TAPI_SS_TIMEREXPIRE:
+        SysLog(NID_TEL, "[E_NOT_RESPONDING] The server on the telephony network is not responding.");
+        r = E_NOT_RESPONDING;
+        break;
+    default:
+        r = E_SYSTEM;
+        break;
+    }
+
+    result res = __pTelephonyService->__pStub->SendCallForwardNumberReceived(*pClientId, phoneNumber, r);
+    SysLog(NID_TEL, "Called SendCallForwardNumberReceived : %s", GetErrorMessage(res));
+
+    delete pClientId;
+}
+
+void
+TelephonyService::OnCallForwardResponseReceivedCallback(TapiHandle* pHandle,int err, void* pData, void* pUserData)
+{
+    SysLog(NID_TEL, "Called OnCallForwardResponseReceivedCallback : 0x%x", err);
+
+    TelSsForwardResp_t* pCallForwardData = (TelSsForwardResp_t*)pData;
+    int* pClientId = static_cast<int*>(pUserData);
+    result r = E_SUCCESS;
+    String phoneNumber;
+
+    switch (err)
+    {
+    case TAPI_SS_SUCCESS:
+        r = E_SUCCESS;
+        phoneNumber = String((const char*) pCallForwardData->record[0].szCallForwardingNumber);
+        break;
+    case TAPI_SS_TIMEREXPIRE:
+        SysLog(NID_TEL, "[E_NOT_RESPONDING] The server on the telephony network is not responding.");
+        r = E_NOT_RESPONDING;
+        break;
+    default:
+        r = E_SYSTEM;
+        break;
+    }
+
+    result res = __pTelephonyService->__pStub->SendCallForwardResponseReceived(*pClientId, phoneNumber, r);
+    SysLog(NID_TEL, "Called SendCallForwardResponseReceived : %s", GetErrorMessage(res));
+}
+
+void
+TelephonyService::OnCallForwardStoppedCallback(TapiHandle* pHandle,int err, void* pData, void* pUserData)
+{
+    SysLog(NID_TEL, "Called OnCallForwardStoppedCallback : 0x%x", err);
+
+    TelSsForwardResp_t* pCallForwardData = (TelSsForwardResp_t*)pData;
+    int* pClientId = static_cast<int*>(pUserData);
+    result r = E_SUCCESS;
+    String phoneNumber;
+
+    switch (err)
+    {
+    case TAPI_SS_SUCCESS:
+        r = E_SUCCESS;
+        phoneNumber = String((const char*) pCallForwardData->record[0].szCallForwardingNumber);
+        break;
+    case TAPI_SS_TIMEREXPIRE:
+        SysLog(NID_TEL, "[E_NOT_RESPONDING] The server on the telephony network is not responding.");
+        r = E_NOT_RESPONDING;
+        break;
+    default:
+    r = E_SYSTEM;
+        break;
+    }
+
+    result res = __pTelephonyService->__pStub->SendCallForwardStopped(*pClientId, phoneNumber, r);
+    SysLog(NID_TEL, "Called SendCallForwardResponseReceived : %s", GetErrorMessage(res));
+}
+
+String
+TelephonyService::MakeNetworkInfoMessage(TelNetworkIdentity_t& info)
+{
+    SysLog(NID_TEL, "SLP info plmn : %d, networkName : %s, system type : %d", info.plmn_id, info.network_name, info.access_technology);
+
+    String plmn;
+    plmn.Append(static_cast<int>(info.plmn_id));
+
+    String networkName;
+    networkName.Append(info.network_name);
+    TelNetworkSystemType_t networkType = info.access_technology;
+
+    String length;
+    String message;
+
+       // Appending plmn info
+    length.Format(3, L"%2d", plmn.GetLength());
+    message.Append(length);
+    message.Append(plmn);
+    message.Append(L":");
+    SysLog(NID_TEL, "plmn : %ls", plmn.GetPointer());
+
+    // Appending network name(operator name)
+    length.Format(3, L"%2d", networkName.GetLength());
+    message.Append(length);
+    message.Append(networkName);
+    message.Append(L":");
+    SysLog(NID_TEL, "networkName : %ls", networkName.GetPointer());
+
+    // Appending network type
+    message.Append(networkType);
+    message.Append(L":");
+    SysLog(NID_TEL, "networkType : %d", networkType);
+
+    return message;
+}
+
+result
+TelephonyService::ConvertError(int err)
+{
+    result r = E_SUCCESS;
+
+    if (err == 0)
+    {
+        r = E_SUCCESS;
+    }
+    else if (err == -1)
+    {
+        r = E_NOT_RESPONDING;
+    }
+    else
+    {
+        r = E_SYSTEM;
+    }
+
+    return r;
+}
diff --git a/src/WifiConnectivityIpcMessages.cpp b/src/WifiConnectivityIpcMessages.cpp
new file mode 100644 (file)
index 0000000..0a49428
--- /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    WifiConnectivityIpcMessages.cpp
+ * @brief   This is the generator of IPC messages for the Connectivity service daemon.
+ */
+
+#define IPC_MESSAGE_IMPL
+#include <FNetWifi_ConnectivityIpcMessages.h>
+
+// Generate constructors.
+#include <ipc/struct_constructor_macros.h>
+#include <FNetWifi_ConnectivityIpcMessages.h>
+
+// Generate destructors.
+#include <ipc/struct_destructor_macros.h>
+#include <FNetWifi_ConnectivityIpcMessages.h>
+
+// Generate param traits write methods.
+#include <ipc/param_traits_write_macros.h>
+namespace IPC {
+#include <FNetWifi_ConnectivityIpcMessages.h>
+}  // namespace IPC
+
+// Generate param traits read methods.
+#include <ipc/param_traits_read_macros.h>
+namespace IPC {
+#include <FNetWifi_ConnectivityIpcMessages.h>
+}  // namespace IPC
diff --git a/src/WifiConnectivityIpcStub.cpp b/src/WifiConnectivityIpcStub.cpp
new file mode 100644 (file)
index 0000000..da53dc4
--- /dev/null
@@ -0,0 +1,436 @@
+//
+// 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    WifiConnectivityIpcStub.cpp
+ * @brief   This is the implementation file for the %WifiConnectivityIpcStub class.
+ */
+
+#include <FBaseSysLog.h>
+#include <FNetWifiWifiBssInfo.h>
+#include <FIo_IpcServer.h>
+#include <FNetWifi_ConnectivityIpcMessages.h>
+#include <FSec_AccessController.h>
+#include "WifiConnectivityIpcStub.h"
+#include "WifiService.h"
+#include "WifiProximityService.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Io;
+using namespace Tizen::Security;
+using namespace Tizen::Net;
+
+WifiConnectivityIpcStub::WifiConnectivityIpcStub(void)
+       : __pWifiProximityService(null)
+       , __pWifiService(null)
+       , __pIpcServer(null)
+{
+}
+
+WifiConnectivityIpcStub::~WifiConnectivityIpcStub(void)
+{
+
+}
+
+result
+WifiConnectivityIpcStub::Construct(void)
+{
+       result r = E_SUCCESS;
+
+       unique_ptr<WifiService> pWifiService(new (std::nothrow) WifiService());
+       SysTryReturnResult(NID_NET_WIFI, pWifiService != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       r = pWifiService->Construct();
+
+       if (r == E_SUCCESS)
+       {
+               __pWifiService = move(pWifiService);
+               SysLog(NID_NET_WIFI, "WifiService is created.");
+
+               unique_ptr<WifiProximityService> pWifiProximityService(new (std::nothrow) WifiProximityService());
+               SysTryReturnResult(NID_NET_WIFI, pWifiProximityService != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+               r = pWifiProximityService->Construct(this);
+
+               if (r == E_SUCCESS)
+           {
+                       __pWifiProximityService = move(pWifiProximityService);
+                   SysLog(NID_NET_WIFI, "WifiProximityService is created.");
+           }
+           else
+           {
+               // skip WifiProximity service
+               SysLogException(NID_NET_WIFI, r, "[%s] Failed to construct WifiProximityService.", GetErrorMessage(r));
+           }
+       }
+       else
+       {
+               // skip Wifi/WifiDirect service
+               SysLogException(NID_NET_WIFI, r, "[%s] Failed to construct WifiService.", GetErrorMessage(r));
+       }
+
+       unique_ptr<_IpcServer> pIpcServer(new (std::nothrow) _IpcServer());
+       SysTryReturnResult(NID_NET_WIFI, pIpcServer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       r = pIpcServer->Construct(WIFI_CONNECTIVITY_IPC_SERVER_NAME, *this);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM,
+                       "[%s] A system error has been occurred. Failed to construct IpcServer.", GetErrorMessage(E_SYSTEM));
+
+       __pIpcServer = move(pIpcServer);
+
+       return E_SUCCESS;
+}
+
+void
+WifiConnectivityIpcStub::OnIpcServerStarted(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET_WIFI, "WifiConnectivityIpcStub started.");
+}
+
+void
+WifiConnectivityIpcStub::OnIpcServerStopped(const Tizen::Io::_IpcServer& server)
+{
+       SysLog(NID_NET_WIFI, "WifiConnectivityIpcStub stopped.");
+}
+
+void
+WifiConnectivityIpcStub::OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId)
+{
+       SysLog(NID_NET_WIFI, "Connected with clientId[%d].", clientId);
+}
+
+void
+WifiConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId)
+{
+       SysLog(NID_NET_WIFI, "Disconnected with clientId[%d].", clientId);
+
+       if (__pWifiProximityService != null)
+       {
+               __pWifiProximityService->UnregisterClient(clientId);
+       }
+}
+
+void
+WifiConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message)
+{
+       IPC_BEGIN_MESSAGE_MAP(WifiConnectivityIpcStub, message)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_setSystemScanMode, OnSetWifiSystemScanMode, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_checkSystemSettingPrivilege, OnCheckWifiSystemSettingPrivilege, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_updateWifiBssInfo, OnUpdateWifiBssInfo, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_initializeWifiDirect, OnInitializeWifiDirect, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiDirectLocalDeviceName, OnGetWifiDirectLocalDeviceName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_setWifiDirectLocalDeviceName, OnSetWifiDirectLocalDeviceName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_registerBssId, OnRegisterBssId, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_unregisterBssId, OnUnregisterBssId, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_activateProximityCheck, OnProximityCheckActivated, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_deactivateProximityCheck, OnProximityCheckDeactivated, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_isProximityCheckActivated, OnIsProximityCheckActivated, &server)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+WifiConnectivityIpcStub::OnSetWifiSystemScanMode(int mode, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "Received the request of setting the Wi-Fi system scan mode with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       *pResult = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_WIFIMANAGER);
+
+       if (*pResult != E_SUCCESS)
+       {
+               *pResult = E_PRIVILEGE_DENIED;
+               SysLogException(NID_NET_WIFI, E_PRIVILEGE_DENIED,
+                               "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+       }
+       else if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiService->SetWifiSystemScanMode(mode);
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnCheckWifiSystemSettingPrivilege(unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "Received the request of checking the Wi-Fi system setting privilege with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       *pResult = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_WIFIMANAGER);
+
+       if (*pResult != E_SUCCESS)
+       {
+               *pResult = E_PRIVILEGE_DENIED;
+               SysLogException(NID_NET_WIFI, E_PRIVILEGE_DENIED,
+                               "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnUpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "Received the request of updating the Wi-Fi BSS info with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       *pResult = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_WIFIMANAGER);
+
+       if (*pResult != E_SUCCESS)
+       {
+               *pResult = E_PRIVILEGE_DENIED;
+               SysLogException(NID_NET_WIFI, E_PRIVILEGE_DENIED,
+                               "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+       }
+       else if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiService->UpdateWifiBssInfo(bssInfo);
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnInitializeWifiDirect(unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "Received the request of initializing the Wi-Fi Direct with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiService->Initialize(__pIpcServer->GetClientAppId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnGetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "Received the request of getting the local device name with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiService->GetWifiDirectLocalDeviceName(pLocalName);
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnSetWifiDirectLocalDeviceName(Tizen::Base::String localName, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "Received the request of setting the local device name with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiService->SetWifiDirectLocalDeviceName(__pIpcServer->GetClientAppId(), localName);
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnRegisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnRegisterBssId with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->RegisterBssId(bssId, __pIpcServer->GetClientId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnUnregisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnUnregisterBssId with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->UnregisterBssId(bssId, __pIpcServer->GetClientId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnProximityCheckActivated(unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnProximityCheckActivated with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->ActivateProximityCheck(__pIpcServer->GetClientId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnProximityCheckDeactivated(unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnProximityCheckDeactivated with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->DeactivateProximityCheck(__pIpcServer->GetClientId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnIsProximityCheckActivated(bool* isActivated, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnIsProximityCheckActivated with clientId : %d, AppId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientAppId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = E_SUCCESS;
+               *isActivated = __pWifiProximityService->IsProximityCheckActivated();
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+result
+WifiConnectivityIpcStub::SendProximityCheckActivated(int clientId)
+{
+    SysLog(NID_NET_WIFI, "SendProximityCheckActivated with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onProximityCheckActivated());
+    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendProximityCheckDeactivated(int clientId)
+{
+    SysLog(NID_NET_WIFI, "SendProximityCheckDeactivated with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onProximityCheckDeactivated());
+    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendWifiBssDetected(int clientId, const Tizen::Net::Wifi::WifiBssInfo& wifiBssInfo)
+{
+    SysLog(NID_NET_WIFI, "SendWifiBssDetected with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiBssDetected(wifiBssInfo));
+    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendWifiBssLost(int clientId, const Tizen::Base::String& bssId)
+{
+    SysLog(NID_NET_WIFI, "SendWifiBssLost with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiBssLost(bssId));
+    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
diff --git a/src/WifiProximityEvent.cpp b/src/WifiProximityEvent.cpp
new file mode 100644 (file)
index 0000000..5134865
--- /dev/null
@@ -0,0 +1,68 @@
+//
+// 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    WifiProximityEvent.cpp
+// @brief   This is the implementation file for the WifiProximityEvent class.
+//
+
+#include <FBaseRtIEventListener.h>
+#include <FBaseSysLog.h>
+#include <FBaseRtIEventArg.h>
+#include "IWifiProximityEventListener.h"
+#include "WifiProximityEvent.h"
+#include "WifiProximityEventArg.h"
+
+
+WifiProximityEvent::WifiProximityEvent(void)
+{
+}
+
+WifiProximityEvent::~WifiProximityEvent(void)
+{
+}
+
+result
+WifiProximityEvent::Construct(void)
+{
+       return _Event::Initialize();
+}
+
+void
+WifiProximityEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
+{
+       IWifiProximityEventListener* pEventListener = dynamic_cast <IWifiProximityEventListener*>(&listener);
+       SysTryReturnVoidResult(NID_NET_WIFI, pEventListener != null, E_INVALID_ARG,
+                       "[E_INVALID_ARG] The listener argument is invalid.");
+
+       const WifiProximityEventArg* pEventArg = dynamic_cast <const WifiProximityEventArg*>(&arg);
+       SysTryReturnVoidResult(NID_NET_WIFI, pEventArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The event argument is invalid type.");
+
+       WifiProximityEventType eventType = pEventArg->GetEventType();
+
+       switch (eventType)
+       {
+       case WIFI_PROXIMITY_EVENT_ACTIVATED:
+               pEventListener->OnWifiProximityActivated();
+               break;
+
+       case WIFI_PROXIMITY_EVENT_DEACTIVATED:
+               pEventListener->OnWifiProximityDeactivated();
+               break;
+
+       default:
+               break;
+       }
+}
diff --git a/src/WifiProximityEventArg.cpp b/src/WifiProximityEventArg.cpp
new file mode 100644 (file)
index 0000000..bbaf662
--- /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    WifiProximityEventArg.cpp
+// @brief   This is the implementation file for the WifiProximityEventArg class.
+//
+
+#include "WifiProximityEventArg.h"
+
+
+WifiProximityEventArg::WifiProximityEventArg(WifiProximityEventType type)
+       : __evtType(type)
+{
+}
+
+WifiProximityEventArg::~WifiProximityEventArg(void)
+{
+}
+
+WifiProximityEventType
+WifiProximityEventArg::GetEventType(void) const
+{
+       return __evtType;
+}
diff --git a/src/WifiProximityService.cpp b/src/WifiProximityService.cpp
new file mode 100644 (file)
index 0000000..4985b3f
--- /dev/null
@@ -0,0 +1,640 @@
+//
+// 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    WifiProximityService.cpp
+ * @brief   This is the implementation file for the %WifiProximityService class.
+ */
+
+#include <unique_ptr.h>
+#include <FBaseSysLog.h>
+#include <FNetWifiWifiBssInfo.h>
+#include <WifiConnectivityIpcStub.h>
+#include "FNetWifi_WifiUtility.h"
+#include "WifiProximityService.h"
+#include "WifiProximityEventArg.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Net::Wifi;
+
+static const int _PROX_BG_SCAN_DURATION = 30 * 1000;    // 30 seconds
+static const long _PROX_RSSI_THRESHOLD_DETECTED = -85;  // -85 dB
+static const long _PROX_RSSI_THRESHOLD_LOST = -100;     // -100 dB
+
+/*
+ * @class   _StringComparer
+ * @brief   The _StringComparer class provides the comparer about two specified String.
+ */
+class _StringComparer
+       : public Tizen::Base::Collection::IComparerT <Tizen::Base::String>
+       , public Tizen::Base::Object
+{
+public:
+       _StringComparer(void) {}
+       virtual ~_StringComparer(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:
+       _StringComparer(const _StringComparer& value);
+       _StringComparer& operator =(const _StringComparer& value);
+
+};     //_StringComparer
+
+/*
+ * @class   _StringHashCodeProvider
+ * @brief   The _StringHashCodeProvider class provides the hash code of a specified String.
+ */
+class _StringHashCodeProvider
+       : public Tizen::Base::Collection::IHashCodeProviderT <Tizen::Base::String>
+{
+public:
+       _StringHashCodeProvider(void) {}
+       virtual ~_StringHashCodeProvider(void) {}
+       virtual int GetHashCode(const Tizen::Base::String& obj) const
+       {
+               return obj.GetHashCode();
+       }
+
+private:
+       _StringHashCodeProvider(const _StringHashCodeProvider& value);
+       _StringHashCodeProvider& operator =(const _StringHashCodeProvider& value);
+
+};     //_StringHashCodeProvider
+
+
+WifiProximityService::WifiProximityService(void)
+       : __clientStateMap()
+       , __bssClientMap()
+       , __bssDetectionMap()
+       , __timer()
+       , __pStub(null)
+       , __proxEvent()
+       , __isWifiActivated(false)
+       , __isProximityCheckActivated(false)
+       , __isTimerOn(false)
+{
+}
+
+WifiProximityService::~WifiProximityService(void)
+{
+       (void) wifi_unset_device_state_changed_cb();
+       (void) wifi_unset_background_scan_cb();
+       (void) wifi_deinitialize();
+}
+
+result
+WifiProximityService::Construct(WifiConnectivityIpcStub* pStub)
+{
+       result r = E_SUCCESS;
+       int err = WIFI_ERROR_NONE;
+       static _StringHashCodeProvider strHashCodeProvider;
+       static _StringComparer strComparer;
+
+       r = __clientStateMap.Construct();
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Constructing the internal map(table) has failed.");
+
+       r = __bssClientMap.Construct(16, 0.75f, strHashCodeProvider, strComparer);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Constructing the internal map(table) has failed.");
+
+       r = __bssDetectionMap.Construct(16, 0.75f, strHashCodeProvider, strComparer);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Constructing the internal map(table) has failed.");
+
+       r = __timer.Construct(*this);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Constructing the internal timer has failed.");
+
+       r = __proxEvent.Construct();
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Constructing the internal event has failed.");
+
+       r = __proxEvent.AddListener(*((IWifiProximityEventListener*)this), true);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Adding listeners to the internal event has failed.");
+
+       err = wifi_initialize();
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Initializing Wi-Fi has failed. [0x%08X]", err);
+
+       err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, this);
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM,
+                       "Registration of a Wi-Fi callback method about the state change has failed. [0x%08X]", err);
+
+       err = wifi_set_background_scan_cb(OnWifiScanCompleted, this);
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM,
+                       "Registration of a Wi-Fi callback method about the scanning has failed. [0x%08X]", err);
+
+       err = wifi_is_activated(&__isWifiActivated);
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Checking Wi-Fi activation has failed. [0x%08X]", err);
+
+       __pStub = pStub;
+
+       return r;
+}
+
+result
+WifiProximityService::RegisterBssId(const Tizen::Base::String& bssId, const int clientId)
+{
+       result r = E_SUCCESS;
+       bool contains = false;
+       bool isDefault = false;
+
+       // if the specified BSS ID is an empty string,
+       // just add client to the client list for notifying activated/deactived events.
+       if (bssId.GetLength() == 0)
+       {
+               __clientStateMap.ContainsKey(clientId, contains);
+               if (contains)
+               {
+                       __clientStateMap.GetValue(clientId, isDefault);
+                       SysTryReturnResult(NID_NET_WIFI, isDefault == false, E_OBJ_ALREADY_EXIST, "The client was already registered.");
+
+                       __clientStateMap.SetValue(clientId, true);
+               }
+               else
+               {
+                       r = __clientStateMap.Add(clientId, true);
+                       r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+                       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
+               }
+       }
+       else
+       {
+               __clientStateMap.ContainsKey(clientId, contains);
+               if (!contains)
+               {
+                       r = __clientStateMap.Add(clientId, false);
+                       r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+                       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
+               }
+
+               __bssClientMap.Contains(bssId, clientId, contains);
+               if (!contains)
+               {
+                       r = __bssClientMap.Add(bssId, clientId);
+                       r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+                       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
+
+                       __bssDetectionMap.ContainsKey(bssId, contains);
+                       if (!contains)
+                       {
+                               r = __bssDetectionMap.Add(bssId, false);
+                               r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+                               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
+                       }
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+result
+WifiProximityService::UnregisterBssId(const Tizen::Base::String& bssId, const int clientId)
+{
+       result r = E_SUCCESS;
+       bool contains = false;
+       bool isDefault = false;
+
+       // if the specified BSS ID is an empty string, remove all elements related to the specified Client ID.
+       if (bssId.GetLength() == 0)
+       {
+               __clientStateMap.ContainsKey(clientId, contains);
+               SysTryReturnResult(NID_NET_WIFI, contains == true, E_OBJ_NOT_FOUND, "The client was not registered.");
+
+               __clientStateMap.GetValue(clientId, isDefault);
+               SysTryReturnResult(NID_NET_WIFI, isDefault == true, E_OBJ_NOT_FOUND, "The client was not registered.");
+
+               contains = __bssClientMap.ContainsValue(clientId);
+               if (contains)
+               {
+                       __clientStateMap.SetValue(clientId, false);
+               }
+               else
+               {
+                       __clientStateMap.Remove(clientId);
+               }
+       }
+       else
+       {
+               __bssClientMap.Contains(bssId, clientId, contains);
+               if (contains)
+               {
+                       __bssClientMap.Remove(bssId, clientId);
+
+                       __bssClientMap.ContainsKey(bssId, contains);
+                       if (!contains)
+                       {
+                               __bssDetectionMap.Remove(bssId);
+                       }
+
+                       contains = __bssClientMap.ContainsValue(clientId);
+                       if (!contains)
+                       {
+                               __clientStateMap.GetValue(clientId, isDefault);
+                               if (!isDefault)
+                               {
+                                       __clientStateMap.Remove(clientId);
+                               }
+                       }
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+result
+WifiProximityService::UnregisterClient(const int clientId)
+{
+       // remove all elements related to the specified clientId
+       result r = E_SUCCESS;
+       unique_ptr< IMapEnumeratorT<String, int> > pMapEnum;
+       bool contains = false;
+       String bssId;
+       int registeredClientId = 0;
+
+       __clientStateMap.ContainsKey(clientId, contains);
+       if (contains)
+       {
+               __clientStateMap.Remove(clientId);
+       }
+
+       pMapEnum.reset(__bssClientMap.GetMapEnumeratorN());
+       while(pMapEnum->MoveNext() == E_SUCCESS)
+       {
+               r = pMapEnum->GetKey(bssId);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Internal map error.");
+
+               r = pMapEnum->GetValue(registeredClientId);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Internal map error.");
+
+               if (registeredClientId == clientId)
+               {
+                       __bssClientMap.Remove(bssId, clientId);
+                       SysLog(NID_NET_WIFI, "Client(ID:%d) is removed from the internal map.", clientId);
+               }
+
+               __bssClientMap.ContainsKey(bssId, contains);
+               if (!contains)
+               {
+                       __bssDetectionMap.Remove(bssId);
+                       SysLog(NID_NET_WIFI, "BSS(ID:%ls) is removed from the internal map.", bssId.GetPointer());
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+result
+WifiProximityService::ActivateProximityCheck(const int clientId)
+{
+       result r = E_SUCCESS;
+
+       SysTryReturnResult(NID_NET_WIFI, __isProximityCheckActivated == false, E_INVALID_STATE,
+                       "Proximity checking is already activated.");
+
+       __isProximityCheckActivated = true;
+
+       r = ScanAndResetTimer();
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Starting the periodical background scanning has failed.");
+
+       WifiProximityEventArg* pEventArg = new (std::nothrow) WifiProximityEventArg(WIFI_PROXIMITY_EVENT_ACTIVATED);
+       SysTryReturnResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "Insufficient memory.");
+
+       // fire the activated event for itself to send the async IPC callback to all clients
+       __proxEvent.FireAsync(*pEventArg);
+
+       SysLog(NID_NET_WIFI, "Activation of Proximity Check is successful.");
+
+       return E_SUCCESS;
+}
+
+result
+WifiProximityService::DeactivateProximityCheck(const int clientId)
+{
+       SysTryReturnResult(NID_NET_WIFI, __isProximityCheckActivated == true, E_INVALID_STATE,
+                       "Proximity checking is already activated.");
+
+       __isProximityCheckActivated = false;
+
+       WifiProximityEventArg* pEventArg = new (std::nothrow) WifiProximityEventArg(WIFI_PROXIMITY_EVENT_DEACTIVATED);
+       SysTryReturnResult(NID_NET_WIFI, pEventArg != null, E_OUT_OF_MEMORY, "Insufficient memory.");
+
+       // fire the deactivated event for itself to send the async IPC callback to all clients
+       __proxEvent.FireAsync(*pEventArg);
+
+       SysLog(NID_NET_WIFI, "Deactivation of Proximity Check is successful.");
+
+       return E_SUCCESS;
+}
+
+bool
+WifiProximityService::IsProximityCheckActivated(void) const
+{
+       return __isProximityCheckActivated;
+}
+
+result
+WifiProximityService::ScanAndResetTimer(void)
+{
+       result r = E_SUCCESS;
+
+       // if the scan is not the first time, off the timer.
+       if (__isTimerOn)
+       {
+               r = __timer.Cancel();
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Canceling the timer has failed.");
+               __isTimerOn = false;
+       }
+
+       // scan nearby Wi-Fi APs in background and set the timer with the predefined duration time.
+       if (__isWifiActivated && __isProximityCheckActivated)
+       {
+               int err = wifi_scan(OnWifiScanCompleted, this);
+               SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Wi-Fi scan has failed. [0x%08X]", err);
+
+               r = __timer.Start(_PROX_BG_SCAN_DURATION);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Starting the timer has failed.");
+               __isTimerOn = true;
+
+               SysLog(NID_NET_WIFI, "Wi-Fi scanning is successful and the timer for periodic Wi-Fi scanning is reset.");
+       }
+
+       return E_SUCCESS;
+}
+
+result
+WifiProximityService::ResetTimer(void)
+{
+       result r = E_SUCCESS;
+
+       if (__isTimerOn)
+       {
+               r = __timer.Cancel();
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Canceling the timer has failed.");
+               __isTimerOn = false;
+
+               r = __timer.Start(_PROX_BG_SCAN_DURATION);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Starting the timer has failed.");
+               __isTimerOn = true;
+
+               SysLog(NID_NET_WIFI, "The timer for periodic Wi-Fi scanning is reset.");
+       }
+
+       return E_SUCCESS;
+}
+
+void
+WifiProximityService::CheckingProximityStatusChanged(void)
+{
+       result r = E_SUCCESS;
+       LinkedList bssInfoList(SingleObjectDeleter);
+       int err = WIFI_ERROR_NONE;
+       unique_ptr< IMapEnumeratorT<String, bool> > pMapEnum;
+       int bssCount = 0;
+
+       if (!__isProximityCheckActivated)
+       {
+               return;
+       }
+
+       err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, &bssInfoList);
+       SysTryReturnVoidResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM,
+                       "[E_SYSTEM] wifi_foreach_found_aps() has failed. [0x%08X]", err);
+
+       bssCount = bssInfoList.GetCount();
+
+       // inspects the all APs in the result of scanning
+       pMapEnum.reset(__bssDetectionMap.GetMapEnumeratorN());
+       while(pMapEnum->MoveNext() == E_SUCCESS)
+       {
+               String bssId;
+               bool wasDetected = false;
+               WifiBssInfo* pWifiBssInfo = null;
+
+               r = pMapEnum->GetKey(bssId);
+               SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS,  E_SYSTEM, "[E_SYSTEM] Getting the key from the map has failed.");
+
+               r = pMapEnum->GetValue(wasDetected);
+               SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS,  E_SYSTEM, "[E_SYSTEM] Getting the value from the map has failed.");
+
+               // checks whether the AP comes under the lost case ==================================================
+               if (wasDetected)
+               {
+                       bool isLost = true;
+
+                       for (int i = 0; i < bssCount; i++)
+                       {
+                               pWifiBssInfo = dynamic_cast<WifiBssInfo*>(bssInfoList.GetAt(i));
+                               SysTryReturnVoidResult(NID_NET_WIFI, pWifiBssInfo != null, E_SYSTEM,
+                                               "[E_SYSTEM] An internal dynamic casting error.");
+
+                               if (bssId.Equals(pWifiBssInfo->GetBssId()))
+                               {
+                                       if (pWifiBssInfo->GetRssi() > _PROX_RSSI_THRESHOLD_LOST)
+                                       {
+                                               // this BSS is not lost because it is also detected in this turn.
+                                               isLost = false;
+                                       }
+
+                                       break;
+                               }
+                       }
+
+                       if (isLost)
+                       {
+                               SysLog(NID_NET_WIFI, "The observed BSS (Id: %ls) is lost.", bssId.GetPointer());
+                               __bssDetectionMap.SetValue(bssId, false);
+
+                               unique_ptr< IEnumeratorT<int> > pValueEnum(__bssClientMap.GetValuesN(bssId));
+                               while(pValueEnum->MoveNext() == E_SUCCESS)
+                               {
+                                       int clientId = 0;
+                                       pValueEnum->GetCurrent(clientId);
+
+                                       r = __pStub->SendWifiBssLost(clientId, bssId);
+                                       SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS,  r, "[%s] Propagatig. (IPC error)", GetErrorMessage(r));
+                               }
+                       }
+               }
+               // checks whether the AP comes under the detection case =============================================
+               else
+               {
+                       bool isDetected = false;
+
+                       for (int i = 0; i < bssCount; i++)
+                       {
+                               pWifiBssInfo = dynamic_cast<WifiBssInfo*>(bssInfoList.GetAt(i));
+                               SysTryReturnVoidResult(NID_NET_WIFI, pWifiBssInfo != null, E_SYSTEM,
+                                               "[E_SYSTEM] An internal dynamic casting error.");
+
+                               if (bssId.Equals(pWifiBssInfo->GetBssId()))
+                               {
+                                       if (pWifiBssInfo->GetRssi() > _PROX_RSSI_THRESHOLD_DETECTED)
+                                       {
+                                               // this BSS is newly detected because it was not detected in the previous turns.
+                                               isDetected = true;
+                                       }
+
+                                       break;
+                               }
+                       }
+
+                       if (isDetected)
+                       {
+                               SysLog(NID_NET_WIFI, "The observed BSS (Id: %ls) is detected.", bssId.GetPointer());
+                               __bssDetectionMap.SetValue(bssId, true);
+
+                               unique_ptr< IEnumeratorT<int> > pValueEnum(__bssClientMap.GetValuesN(bssId));
+                               while(pValueEnum->MoveNext() == E_SUCCESS)
+                               {
+                                       int clientId = 0;
+                                       pValueEnum->GetCurrent(clientId);
+
+                                       r = __pStub->SendWifiBssDetected(clientId, *pWifiBssInfo);
+                                       SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS,  r, "[%s] Propagatig. (IPC error)", GetErrorMessage(r));
+                               }
+                       }
+               }
+       }
+}
+
+void
+WifiProximityService::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
+{
+       result r = E_SUCCESS;
+
+       SysLog(NID_NET_WIFI, "The timer for periodic Wi-Fi scanning is expired.");
+
+       __isTimerOn = false;
+       r = ScanAndResetTimer();
+       SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Scanning and set the timer has failed.");
+}
+
+void
+WifiProximityService::OnWifiProximityActivated(void)
+{
+       unique_ptr< IListT<int> >pClientList;
+       int count = 0;
+
+       SysLog(NID_NET_WIFI, "Sending the event to notify that Wi-FI Proximity Checking is activated.");
+
+       pClientList.reset(__clientStateMap.GetKeysN());
+       SysTryReturnVoidResult(NID_NET_WIFI, pClientList != null, E_OUT_OF_MEMORY,
+                       "[E_OUT_OF_MEMORY] Propagating. Internal map error.");
+       count = pClientList->GetCount();
+
+       for (int i = 0; i < count; i++)
+       {
+               result r = E_SUCCESS;
+               int clientId = 0;
+
+               r = pClientList->GetAt(i, clientId);
+               SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Internal map error.");
+
+               r = __pStub->SendProximityCheckActivated(clientId);
+               SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS,  r, "[%s] Propagatig. (IPC error)", GetErrorMessage(r));
+       }
+}
+
+void
+WifiProximityService::OnWifiProximityDeactivated(void)
+{
+       unique_ptr< IListT<int> >pClientList;
+       int count = 0;
+
+       SysLog(NID_NET_WIFI, "Sending the event to notify that Wi-FI Proximity Checking is deactivated.");
+
+       pClientList.reset(__clientStateMap.GetKeysN());
+       SysTryReturnVoidResult(NID_NET_WIFI, pClientList != null, E_OUT_OF_MEMORY,
+                       "[E_OUT_OF_MEMORY] Propagating. Internal map error.");
+       count = pClientList->GetCount();
+
+       for (int i = 0; i < count; i++)
+       {
+               result r = E_SUCCESS;
+               int clientId = 0;
+
+               r = pClientList->GetAt(i, clientId);
+               SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Internal map error.");
+
+               r = __pStub->SendProximityCheckDeactivated(clientId);
+               SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS,  r, "[%s] Propagatig. (IPC error)", GetErrorMessage(r));
+       }
+}
+
+void
+WifiProximityService::OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData)
+{
+       WifiProximityService* pWifiProximityService = static_cast<WifiProximityService*>(pUserData);
+
+       switch (state)
+       {
+       case WIFI_DEVICE_STATE_ACTIVATED:
+               pWifiProximityService->__isWifiActivated = true;
+               pWifiProximityService->ScanAndResetTimer();
+               break;
+       case WIFI_DEVICE_STATE_DEACTIVATED:
+               pWifiProximityService->__isWifiActivated = false;
+               break;
+       default:
+               break;
+       }
+}
+
+void
+WifiProximityService::OnWifiScanCompleted(wifi_error_e errorCode, void* pUserData)
+{
+       WifiProximityService* pWifiProximityService = static_cast<WifiProximityService*>(pUserData);
+
+       SysLog(NID_NET_WIFI, "The Wi-FI BG Scanning is completed %s. [0x%08X] ",
+                       errorCode == WIFI_ERROR_NONE ? "successfully" : "insuccessfully", errorCode);
+
+       pWifiProximityService->ResetTimer(); // ignore the result
+
+       if (errorCode == WIFI_ERROR_NONE)
+       {
+               pWifiProximityService->CheckingProximityStatusChanged();
+       }
+}
+
+bool
+WifiProximityService::OnWifiEachAccessPointFound(wifi_ap_h apHandler, void* pUserData)
+{
+       unique_ptr<WifiBssInfo> pBssInfo;
+       int err = WIFI_ERROR_NONE;
+       result r = E_SUCCESS;
+       LinkedList* pBssInfoList = static_cast<LinkedList*>(pUserData);
+       wifi_ap_h apHandlerCopy;
+
+       err = wifi_ap_clone(&apHandlerCopy, apHandler);
+       SysTryReturn(NID_NET_WIFI, err == WIFI_ERROR_NONE, false, E_SYSTEM,
+                       "[E_SYSTEM] Cloning the wifi_ap_h has failed. [0x%08X]", err);
+
+       pBssInfo.reset(_WifiUtility::CreateWifiBssInfoInstanceN(apHandlerCopy));
+       // keeps processing although creating instance fails.
+       SysTryReturn(NID_NET_WIFI, pBssInfo != null, true, E_SYSTEM, "[E_SYSTEM] Creating a WifiBssInfo instance has failed.");
+
+       r = pBssInfoList->Add(*pBssInfo);
+       // keeps processing although adding instance to the list fails.
+       SysTryReturn(NID_NET_WIFI, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
+       // transfer the ownership.
+       pBssInfo.release();
+
+       return true;
+}
diff --git a/src/WifiService.cpp b/src/WifiService.cpp
new file mode 100644 (file)
index 0000000..0eb225d
--- /dev/null
@@ -0,0 +1,513 @@
+//
+// 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    WifiService.cpp
+ * @brief   This is the implementation file for the %WifiService class.
+ */
+
+#include <glib.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <wifi-direct.h>
+#include <unique_ptr.h>
+#include <FBaseUtilStringUtil.h>
+#include <FBaseRtMutexGuard.h>
+#include <FBaseSysLog.h>
+#include <FNetIp4Address.h>
+#include <FNetWifiWifiTypes.h>
+#include <FNetWifiWifiBssInfo.h>
+#include <FApp_AppManagerImpl.h>
+#include <FSys_SystemInfoImpl.h>
+#include <FBase_StringConverter.h>
+#include <FNetWifi_WifiBssInfoImpl.h>
+#include <FNetWifi_WifiUtility.h>
+#include "WifiService.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::App;
+using namespace Tizen::System;
+using namespace Tizen::Net;
+using namespace Tizen::Net::Wifi;
+
+static void WifiDirectDeviceStateChangedCallbackFunction(int error_code, wifi_direct_device_state_e device_state,
+                                                                                                                       void* user_data);
+
+struct _WifiBssIdHandlePair
+{
+       const Tizen::Base::String* pBssId;
+       wifi_ap_h apHandle;
+};
+
+WifiService::WifiService(void)
+       : __newWifiDirectName()
+       , __wifiDirectNameChangerId()
+       , __appIdListMutex()
+       , __appIdList()
+{
+}
+
+WifiService::~WifiService(void)
+{
+       (void) _AppManagerImpl::GetInstance()->RemoveEventListener(*this);
+
+       if (__appIdList.GetCount() > 0)
+       {
+           (void) wifi_direct_unset_device_state_changed_cb();
+           (void) wifi_direct_deinitialize();
+       }
+
+       (void)__appIdList.RemoveAll(true);
+}
+
+result
+WifiService::Construct(void)
+{
+       result r = E_SUCCESS;
+       bool isWifiDirectSupported = false;
+    String key(L"http://tizen.org/feature/network.wifi.direct");
+
+       r = Tizen::System::_SystemInfoImpl::GetSysInfo(key, isWifiDirectSupported);
+       SysTryReturnResult(NID_NET_WIFI, (r == E_SUCCESS) && (isWifiDirectSupported == true), E_UNSUPPORTED_OPERATION,
+                       "Wi-Fi Direct is not supported.");
+
+       r = __appIdListMutex.Create();
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
+
+       r = _AppManagerImpl::GetInstance()->AddEventListener(*this);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM,
+                                       "Registration of an _IAppManagerEventListener has failed.");
+
+       return E_SUCCESS;
+}
+
+result
+WifiService::SetWifiSystemScanMode(int mode)
+{
+       // changes vconf value about Wi-Fi UG running mode.
+       // Key:   VCONFKEY_WIFI_UG_RUN_STATE                "memory/wifi/ug_run_state"
+       // Value: VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND
+       //        VCONFKEY_WIFI_UG_RUN_STATE_OFF
+       int vconfRes = 0;
+       int ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_OFF;
+       WifiSystemScanMode scanMode = (WifiSystemScanMode) mode;
+
+       switch(scanMode)
+       {
+       case WIFI_SYSTEM_SCAN_MODE_ACTIVE:
+               ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND;
+               SysLog(NID_NET_WIFI, "Change UG state (ON_FOREGROUND)");
+               break;
+       case WIFI_SYSTEM_SCAN_MODE_PASSIVE:
+       default:
+               ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_OFF;
+               SysLog(NID_NET_WIFI, "Change UG state (OFF)");
+               break;
+       }
+
+       vconfRes = vconf_set_int(VCONFKEY_WIFI_UG_RUN_STATE, ugRunState);
+       SysTryReturnResult(NID_NET_WIFI, vconfRes == 0, E_OPERATION_FAILED, "Setting the running mode of the Wi-Fi UG has failed.");
+
+       return E_SUCCESS;
+}
+
+result
+WifiService::UpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo)
+{
+       wifi_ap_h apHandle = null;
+       const _WifiBssInfoImpl* pBssInfoImpl = null;
+       int apRes = WIFI_ERROR_NONE;
+       NetAddressScheme ipScheme = NET_ADDRESS_SCHEME_DYNAMIC;
+       wifi_ip_config_type_e apIpScheme = WIFI_IP_CONFIG_TYPE_NONE;
+       const IpAddress* pAddress = null;
+       unique_ptr<char[]> pAddressStr;
+       NetProxyType proxyType = NET_PROXY_TYPE_NONE;
+       wifi_proxy_type_e apProxyType = WIFI_PROXY_TYPE_DIRECT;
+       String proxyAddressStr;
+       bool isKnown = false;
+
+       pBssInfoImpl = _WifiBssInfoImpl::GetInstance(bssInfo);
+       apHandle = GetApHandle(pBssInfoImpl->GetBssId());
+       SysTryReturnResult(NID_NET_WIFI, apHandle != null, E_OPERATION_FAILED,
+                       "The AP is not found in the current AP list of the system.");
+
+       // Setting the AP unknown
+       apRes = wifi_ap_is_favorite(apHandle, &isKnown);
+       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                       "Checking the AP is a known device has failed. [0x%08X].", apRes);
+       if (isKnown && !(pBssInfoImpl->IsKnown()))
+       {
+               apRes = wifi_forget_ap(apHandle);
+               SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                               "Setting the AP unknown has failed. [0x%08X].", apRes);
+       }
+
+       // Setting the IP address scheme. Only IPv4 as the address family is taken into consideration for now.
+       ipScheme = pBssInfoImpl->GetLocalAddressScheme();
+       apIpScheme = (ipScheme == NET_ADDRESS_SCHEME_STATIC) ? WIFI_IP_CONFIG_TYPE_STATIC : WIFI_IP_CONFIG_TYPE_DYNAMIC;
+       apRes = wifi_ap_set_ip_config_type(apHandle, WIFI_ADDRESS_FAMILY_IPV4, apIpScheme);
+       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                       "Setting the IP address scheme to AP has failed. [0x%08X].", apRes);
+
+       if (ipScheme == NET_ADDRESS_SCHEME_STATIC)
+       {
+               // Setting the IP address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetLocalAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       apRes = wifi_ap_set_ip_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the IP address to AP has failed. [0x%08X].", apRes);
+               }
+
+               // Setting the subnet mask. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetSubnetMaskAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       apRes = wifi_ap_set_subnet_mask(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the subnet mask to AP has failed. [0x%08X].", apRes);
+               }
+
+               // Setting the default gateway address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetDefaultGatewayAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       apRes = wifi_ap_set_gateway_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the default gateway address to AP has failed. [0x%08X].", apRes);
+               }
+
+               // Setting the primary DNS address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetPrimaryDnsAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       apRes = wifi_ap_set_dns_address(apHandle, 1, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the primary DNS address to AP has failed. [0x%08X].", apRes);
+               }
+
+               // Setting the secondary DNS address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetSecondaryDnsAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       apRes = wifi_ap_set_dns_address(apHandle, 2, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the secondary DNS address to AP has failed. [0x%08X].", apRes);
+               }
+       }
+
+       proxyType = pBssInfoImpl->GetProxyType();
+
+       if (proxyType == NET_PROXY_TYPE_MANUAL)
+       {
+               // Setting the proxy address. Only IPv4 as the address family is taken into consideration for now.
+               proxyAddressStr = pBssInfoImpl->GetProxyAddress();
+               pAddressStr.reset(_StringConverter::CopyToCharArrayN(proxyAddressStr));
+               apRes = wifi_ap_set_proxy_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+               SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                               "Setting the proxy address to AP has failed. [0x%08X].", apRes);
+       }
+
+       // Setting the proxy type.
+       apProxyType = (proxyType == NET_PROXY_TYPE_MANUAL) ? WIFI_PROXY_TYPE_MANUAL : WIFI_PROXY_TYPE_DIRECT;
+       apRes = wifi_ap_set_proxy_type(apHandle, apProxyType);
+       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                       "Setting the proxy type to AP has failed. [0x%08X].", apRes);
+
+       return E_SUCCESS;
+}
+
+result
+WifiService::Initialize(const Tizen::Base::String& clientAppId)
+{
+       result r = E_SUCCESS;
+    int ret = WIFI_DIRECT_ERROR_NONE;
+
+       MutexGuard locked(__appIdListMutex);
+
+       // Initialize Wi-Fi Direct client of osp-connectivity-service
+       // if the first application initializes its Wi-Fi Direct client.
+       if (__appIdList.GetCount() == 0)
+       {
+           ret = wifi_direct_initialize();
+           SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE, E_SYSTEM,
+                               "Initializing Wi-Fi Direct has failed. [0x%08X]", ret);
+
+               ret = wifi_direct_set_device_state_changed_cb(WifiDirectDeviceStateChangedCallbackFunction, this);
+               if (ret != WIFI_DIRECT_ERROR_NONE)
+               {
+                       SysLogException(NID_NET_WIFI, E_SYSTEM,
+                               "[E_SYSTEM] Registration of a Wi-Fi Direct callback method has failed. [0x%08X]", ret);
+                   (void) wifi_direct_deinitialize();
+                       return E_SYSTEM;
+               }
+
+               SysLog(NID_NET_WIFI, "Initializing Wi-Fi Direct is successful.");
+       }
+
+       // Add the ID of the application which initializes Wi-Fi Direct client to the list.
+       if (!__appIdList.Contains(clientAppId))
+       {
+               r = __appIdList.Add(*(new (std::nothrow) String(clientAppId)));
+               // Ignore the error result of list operation.
+               SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "Insertion a new item to the app ID list has failed. (%s)", GetErrorMessage(r));
+       }
+
+       locked.Unlock();
+
+       return r;
+}
+
+result
+WifiService::GetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName)
+{
+       result r = E_SYSTEM;
+       int ret = WIFI_DIRECT_ERROR_NONE;
+
+       // Gets the local name from the underlying Wi-Fi Direct subsystem, if Wi-Fi Direct is on.
+       if (IsWifiDirectActivated() == true)
+       {
+           char* pDeviceName = null;
+               ret = wifi_direct_get_device_name(&pDeviceName);
+               SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE && pDeviceName != null, E_SYSTEM,
+                               "Getting the SSID from Wi-Fi Direct subsystem has failed. [0x%x]", ret);
+
+               // Converts the UTF8 multibyte string to Unicode String
+               r = StringUtil::Utf8ToString(pDeviceName, *pLocalName);
+               free(pDeviceName);
+       }
+       // Gets the name to be set, if Wi-Fi Direct is off and there is the name set by an application
+       else if (__newWifiDirectName.GetLength() > 0)
+       {
+               *pLocalName = __newWifiDirectName;
+               r = E_SUCCESS;
+       }
+       // Gets the phone name from the system info
+       else
+       {
+           char* pPhoneName = null;
+               pPhoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+               SysTryReturnResult(NID_NET_WIFI, pPhoneName != null, E_SYSTEM, "Getting the phone name has failed");
+
+               // Converts the UTF8 multibyte string to Unicode String
+               r = StringUtil::Utf8ToString(pPhoneName, *pLocalName);
+               free(pPhoneName);
+       }
+
+       return r;
+}
+
+result
+WifiService::SetWifiDirectLocalDeviceName(const Tizen::Base::String& clientAppId, const Tizen::Base::String& localName)
+{
+       result r = E_SUCCESS;
+
+       // Updates the local name instantly if the Wi-Fi Direct is turned on.
+       // Saves the setting name for the later use, otherwise.
+       if (IsWifiDirectActivated() == true)
+       {
+               r = UpdateWifiDirectLocalDeviceName(localName);
+               if (!IsFailed(r))
+               {
+                       __newWifiDirectName = localName;
+                       __wifiDirectNameChangerId = clientAppId;
+               }
+       }
+       else
+       {
+               __newWifiDirectName = localName;
+               __wifiDirectNameChangerId = clientAppId;
+               SysLog(NID_NET_WIFI, "The input name is reserved as the Wi-Fi Direct local name.");
+       }
+
+       return r;
+}
+
+result
+WifiService::UpdateWifiDirectLocalDeviceName(const Tizen::Base::String& name)
+{
+       int ret = 0;
+       char* pConvertedName = NULL;
+
+       pConvertedName = _StringConverter::CopyToCharArrayN(name);
+       SysTryReturnResult(NID_NET_WIFI, pConvertedName != null, E_INVALID_ARG, "Invalid device name.");
+
+       ret = wifi_direct_set_device_name(pConvertedName);
+
+       delete[] pConvertedName;
+       SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE, E_SYSTEM,
+                                               "Setting the Wi-Fi Direct SSID (local name) has failed. [0x%x]", ret);
+
+       SysLog(NID_NET_WIFI, "Updating the Wi-Fi Direct local name is successful.");
+
+       return E_SUCCESS;
+}
+
+bool
+WifiService::IsWifiDirectActivated(void) const
+{
+       int ret = WIFI_DIRECT_ERROR_NONE;
+       wifi_direct_state_e currentState = WIFI_DIRECT_STATE_DEACTIVATED;
+
+       ret = wifi_direct_get_state(&currentState);
+       if (ret == WIFI_DIRECT_ERROR_NONE)
+       {
+               if (currentState != WIFI_DIRECT_STATE_DEACTIVATED)
+               {
+                       return true;
+               }
+       }
+       else
+       {
+               SysLog(NID_NET_WIFI, "Getting the current status of Wi-Fi Direct has failed. [0x%x]", ret);
+       }
+
+       return false;
+}
+
+wifi_ap_h
+WifiService::GetApHandle(const Tizen::Base::String& bssId)
+{
+       _WifiBssIdHandlePair pair;
+       pair.pBssId = &bssId;
+       pair.apHandle = null;
+
+    wifi_foreach_found_aps(OnWifiEachAccessPointFound, &pair);
+
+    return pair.apHandle;
+}
+
+void
+WifiService::OnWifiDirectActivated(void)
+{
+       // Updates the local Wi-Fi Direct name.
+       // This is a reserved action.
+       if (__newWifiDirectName.GetLength() > 0)
+       {
+               (void) UpdateWifiDirectLocalDeviceName(__newWifiDirectName);
+       }
+}
+
+void
+WifiService::OnApplicationLaunched(const Tizen::App::AppId& appId, Tizen::App::_AppType type)
+{
+       // do nothing.
+}
+
+void
+WifiService::OnApplicationTerminated(const Tizen::App::AppId& appId, Tizen::App::_AppType type)
+{
+       char* pPhoneName = null;
+       String convertedName;
+       result r = E_SUCCESS;
+
+       if (__wifiDirectNameChangerId == appId)
+       {
+               SysLog(NID_NET_WIFI, "The application which set the Wi-Fi Direct local name is terminated.");
+
+               if (IsWifiDirectActivated() == true)
+               {
+                       SysLog(NID_NET_WIFI, "The Wi-Fi Direct SSID is restored to the phone name.");
+
+                       // Gets the phone name from the system info
+                       pPhoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+                       if (pPhoneName)
+                       {
+                               r = StringUtil::Utf8ToString(pPhoneName, convertedName);
+                               free(pPhoneName);
+
+                               if (!IsFailed(r))
+                               {
+                                       // Updates the Wi-Fi Direct local name with the phone name
+                                       (void) UpdateWifiDirectLocalDeviceName(convertedName);
+                               }
+                       }
+               }
+
+               __newWifiDirectName.Clear();
+               __wifiDirectNameChangerId.Clear();
+       }
+
+       // Deinitialize Wi-Fi Direct client if the last application which initialized Wi-Fi Direct is terminated.
+       __appIdListMutex.Acquire();
+
+       if (__appIdList.Contains(appId))
+       {
+               (void) __appIdList.Remove(appId, true);
+
+               if (__appIdList.GetCount() == 0)
+               {
+                   (void) wifi_direct_unset_device_state_changed_cb();
+                   (void) wifi_direct_deinitialize();
+                       SysLog(NID_NET_WIFI, "Deinitializing Wi-Fi Direct is successful.");
+               }
+       }
+
+       __appIdListMutex.Release();
+}
+
+bool
+WifiService::OnWifiEachAccessPointFound(wifi_ap_h apHandle, void* pUserData)
+{
+       int res = WIFI_ERROR_NONE;
+       char* bssId = null;
+       _WifiBssIdHandlePair* pPair = static_cast<_WifiBssIdHandlePair*>(pUserData);
+
+    res = wifi_ap_get_bssid (apHandle, &bssId);
+    SysTryReturn(NID_NET_WIFI, res == WIFI_ERROR_NONE && bssId != null, true, E_OPERATION_FAILED,
+               "[E_OPERATION_FAILED] Getting BSSID has failed.");
+
+    if (pPair->pBssId->Equals(String(_WifiUtility::ConvertMacAddress(bssId))))
+    {
+       pPair->apHandle = apHandle;
+       return false;
+    }
+
+    return true;
+}
+
+void
+WifiDirectDeviceStateChangedCallbackFunction(int error_code, wifi_direct_device_state_e device_state, void* user_data)
+{
+       WifiService* pService = (WifiService*)user_data;
+
+       switch (device_state)
+       {
+       case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
+               // if the Wi-Fi Direct is activated successfully
+               if (error_code == WIFI_DIRECT_ERROR_NONE)
+               {
+                       SysLog(NID_NET_WIFI, "An event received from SLP Wi-Fi Direct FW (type: WIFI_DIRECT_DEVICE_STATE_ACTIVATED)");
+                       pService->OnWifiDirectActivated();
+               }
+               break;
+
+       default:
+               break;       // ignore other types of event
+       }
+}
+
diff --git a/system-service-export.ver b/system-service-export.ver
new file mode 100755 (executable)
index 0000000..68c06a8
--- /dev/null
@@ -0,0 +1,6 @@
+{
+global:
+       OspMain;
+local:
+       *;
+};