Git init
authorKibum Kim <kb0929.kim@samsung.com>
Fri, 6 Jan 2012 15:42:28 +0000 (00:42 +0900)
committerKibum Kim <kb0929.kim@samsung.com>
Fri, 6 Jan 2012 15:42:28 +0000 (00:42 +0900)
21 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
LICENSE [new file with mode: 0644]
capi-network-connection.pc.in [new file with mode: 0644]
debian/capi-network-connection-dev.install [new file with mode: 0644]
debian/capi-network-connection-dev.postinst [new file with mode: 0644]
debian/capi-network-connection.install [new file with mode: 0644]
debian/capi-network-connection.postinst [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/rules [new file with mode: 0755]
include/net_connection.h [new file with mode: 0755]
include/net_connection_private.h [new file with mode: 0755]
packaging/capi-network-connection.spec [new file with mode: 0644]
src/connection.c [new file with mode: 0755]
test/CMakeLists.txt [new file with mode: 0644]
test/connection_test.c [new file with mode: 0644]
test/connection_test_regress.c [new file with mode: 0644]
test/examples/getting-connection-setting-example.c [new file with mode: 0644]
test/examples/openconnection-example.c [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..7597890
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Sanjeev Ba <as2902.b@samsung.com>
+Kangho Hur <kanho.hur@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3c2483d
--- /dev/null
@@ -0,0 +1,90 @@
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-network-connection")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(dependents "dlog vconf capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${dependents})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+    ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DTIZEN_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
+aux_source_directory(src SOURCES)
+ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+INSTALL(TARGETS ${fw_name} DESTINATION lib)
+INSTALL(
+        DIRECTORY ${INC_DIR}/ DESTINATION include/network
+        FILES_MATCHING
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "${INC_DIR}/*.h"
+        )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${dependents})
+SET(PC_LDFLAGS -l${fw_name})
+SET(PC_CFLAGS -I\${includedir}/network)
+
+CONFIGURE_FILE(
+    ${fw_name}.pc.in
+    ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig)
+
+ADD_SUBDIRECTORY(test)
+
+IF(UNIX)
+
+ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
+ADD_CUSTOM_COMMAND(
+        DEPENDS clean 
+        COMMENT "distribution clean"
+        COMMAND find
+        ARGS    . 
+        -not -name config.cmake -and \(
+        -name tester.c -or
+        -name Testing -or
+        -name CMakeFiles -or
+        -name cmake.depends -or
+        -name cmake.check_depends -or
+        -name CMakeCache.txt -or
+        -name cmake.check_cache -or
+        -name *.cmake -or
+        -name Makefile -or
+        -name core -or
+        -name core.* -or
+        -name gmon.out -or
+        -name install_manifest.txt -or
+        -name *.pc -or
+        -name *~ \)
+        | grep -v TC | xargs rm -rf
+        TARGET  distclean
+        VERBATIM
+)
+
+ENDIF(UNIX)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..a06208b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 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/capi-network-connection.pc.in b/capi-network-connection.pc.in
new file mode 100644 (file)
index 0000000..fd41dbb
--- /dev/null
@@ -0,0 +1,15 @@
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib
+includedir=/usr/include/network
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@ 
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir} @PC_CFLAGS@
+
diff --git a/debian/capi-network-connection-dev.install b/debian/capi-network-connection-dev.install
new file mode 100644 (file)
index 0000000..761a28b
--- /dev/null
@@ -0,0 +1,4 @@
+/usr/include/*
+/usr/include/*/*
+/usr/lib/pkgconfig/*.pc
+
diff --git a/debian/capi-network-connection-dev.postinst b/debian/capi-network-connection-dev.postinst
new file mode 100644 (file)
index 0000000..1a24852
--- /dev/null
@@ -0,0 +1 @@
+#!/bin/sh
diff --git a/debian/capi-network-connection.install b/debian/capi-network-connection.install
new file mode 100644 (file)
index 0000000..4a755a4
--- /dev/null
@@ -0,0 +1 @@
+/usr/lib/lib*.so*
diff --git a/debian/capi-network-connection.postinst b/debian/capi-network-connection.postinst
new file mode 100644 (file)
index 0000000..1a24852
--- /dev/null
@@ -0,0 +1 @@
+#!/bin/sh
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..db4f9ea
--- /dev/null
@@ -0,0 +1,13 @@
+capi-network-connection (0.1.0-13) unstable; urgency=low
+
+  * Update version
+  * Git: api/connection
+  * Tag: capi-network-connection_0.1.0-13
+
+ -- Sanjeev BA <as2902.b@samsung.com>  Thu, 15 Dec 2011 13:30:49 +0900
+
+capi-network-connection (0.0.1-1) unstable; urgency=low
+
+  * Initial Release.
+
+ -- Sanjeev BA <as2902.b@samsung.com>  Wed, 07 Dec 2011 13:03:56 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7f8f011
--- /dev/null
@@ -0,0 +1 @@
+7
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..1ccdf31
--- /dev/null
@@ -0,0 +1,21 @@
+Source: capi-network-connection
+Section: libs
+Priority: extra
+Maintainer: Sanjeev BA <as2902.b@samsung.com>
+Build-Depends: debhelper (>= 5),dlog-dev, capi-base-common-dev, libvconf-dev
+
+Package: capi-network-connection
+Architecture: any
+Depends: ${shilbs:Depends}, ${misc:Depends}
+Description: Network Connection library in TIZEN C API
+
+Package: capi-network-connection-dev
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-connection (= ${Source-Version})
+Description: Network Connection library in TIZEN C API (DEV)
+
+Package: capi-network-connection-dbg
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-connection (= ${Source-Version})
+Description: Network Connection library in TIZEN C API (DBG)
+
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..06ff135
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/make -f
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+else
+       CFLAGS += -O2
+endif
+CMAKE_ROOT_DIR ?= $(CURDIR)
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake ..
+       touch configure-stamp
+
+
+build: build-stamp
+build-stamp: configure-stamp 
+       dh_testdir
+       cd $(CMAKE_BUILD_DIR) && $(MAKE)
+       touch $@
+
+clean:
+       cd $(CMAKE_ROOT_DIR)
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+       rm -f `find . -name *.pc`
+       rm -rf $(CMAKE_BUILD_DIR)
+       dh_clean
+       
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+
+       cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+binary-indep: build install
+
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installchangelogs 
+       dh_installdocs
+       dh_installexamples
+       dh_install --sourcedir=debian/tmp
+       dh_installman
+       dh_link
+       dh_strip --dbg-package=capi-network-connection-dbg
+       dh_fixperms
+       dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
+
diff --git a/include/net_connection.h b/include/net_connection.h
new file mode 100755 (executable)
index 0000000..16a61ef
--- /dev/null
@@ -0,0 +1,443 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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. 
+ */
+
+
+#ifndef __NET_CONNECTION_INTF_H__        /* To prevent inclusion of a header file twice */
+#define __NET_CONNECTION_INTF_H__
+
+#include <tizen_error.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifndef DEPRECATED
+#define DEPRECATED __attribute__((deprecated))
+#endif
+
+
+
+/**
+ * @addtogroup CAPI_NETWORK_FRAMEWORK
+ * @{
+*/
+
+/**
+ * @addtogroup CAPI_NETWORK_CONNECTION_MODULE
+ * @{
+*/
+
+#include <arpa/inet.h>
+
+
+/**
+* @enum connection_error_e
+* @brief Enumerations of network API errors.
+*/
+typedef enum
+{
+       CONNECTION_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+
+       CONNECTION_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+
+    CONNECTION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */
+    CONNECTION_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */
+
+}connection_error_e;
+
+/**
+* @enum connection_network_status_e
+* @brief Enumerations of network status.
+*/
+typedef enum 
+{
+
+    /** Not connected / Suspended / Idle / Connecting / Disconnecting */
+    CONNECTION_STATUS_UNAVAILABLE,
+
+    /** Active */
+    CONNECTION_STATUS_AVAILABLE,
+
+    /** Service unknown */
+    CONNECTION_STATUS_UNKNOWN,
+
+}connection_network_status_e;
+
+/**
+* @enum connection_network_type_e
+* @brief Enumerations of network connection type.
+*/
+typedef enum{
+       /** Default type \n
+             The automatic connection is established.  \n
+             WiFi connection has higher priority than 3G connection. \n
+             If Wifi connection is established by user selection or auto joining,\n
+             3G connection will be automatically moved to WiFi connection in NET_DEFAULT_TYPE case. */
+       CONNECTION_DEFAULT_TYPE = 0x00,
+
+       /** Mobile Type \n
+               Network connection is established in 3G network \n
+       */
+       CONNECTION_MOBILE_TYPE  = 0x01,
+
+       /** WiFi Type \n
+               Network connection is established in WiFi network \n
+       */
+       CONNECTION_WIFI_TYPE    = 0x02,
+
+}connection_network_type_e;
+
+
+
+/**
+* @enum connection_network_param_e
+* @brief Enumerations of changed network parameter.
+* These are received as param in #connection_cb.
+*/
+typedef enum{
+    /** Network Status has changed. \n
+       */
+       CONNECTION_NETWORK_STATUS = 0x00,
+
+       /** IP Address has changed. \n
+       */
+       CONNECTION_IP_ADDRESS   = 0x01,
+
+       /** Proxy Address has changed. \n
+       */
+       CONNECTION_PROXY_ADDRESS        = 0x02,
+
+}connection_network_param_e;
+
+
+/**
+ * @brief  The connection handle for all connection functions.
+*/
+typedef struct connection_handle_s  * connection_h;
+
+
+
+/**
+ * @brief Called when a connection event occurs. 
+ * @param[in] param The enum of the parameter that changed. #connection_network_param_e
+ * @param[in] user_data The user data passed from the callback registration function
+ * @pre Register this function using connection_set_cb().
+ * @see  connection_set_cb() 
+ * @see connection_unset_cb()
+ *
+*/
+typedef void (*connection_cb) (const connection_network_param_e param, void *user_data);
+
+
+/**
+ * @brief Creates a handle for managing data connections.
+ *
+ * @remarks @a handle must be released with connection_destroy(). \n
+ *
+ * @param[out] handle      The handle to the connection
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ * @retval #CONNECTION_ERROR_OUT_OF_MEMORY  Out of memory error 
+ * @see connection_destroy()
+ *
+ *
+******************************************************************************************/
+int connection_create(connection_h * handle);
+
+/*****************************************************************************************/
+/**
+ * @brief  Destroys the connection handle.
+ *
+ * @param[in] handle      The handle to the connection
+ *
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @see connection_create()
+ *
+ *
+******************************************************************************************/
+int connection_destroy(connection_h handle);
+
+/*****************************************************************************************/
+/**
+ * @brief  Registers a callback function to be invoked when connection event occurs.
+ * @param[in] handle      The handle to the connection
+ * @param[in] callback    The callback function to register
+ * @param[in] user_data   The user data to be passed to the callback function 
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER  Invalid parameter 
+ * @post  connection_cb() will be invoked.
+ * @see connection_create()
+ * @see connection_cb() 
+ * @see connection_unset_cb()
+ *
+******************************************************************************************/
+int connection_set_cb(connection_h handle, connection_cb callback, void *user_data);
+
+/*****************************************************************************************/
+/**
+ * @brief  Unregisters the callback function.
+ * @param[in] handle      The handle to the connection
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER  Invalid parameter 
+ * @see connection_cb()
+ * @see connection_set_cb()
+******************************************************************************************/
+int connection_unset_cb(connection_h handle);
+
+/*****************************************************************************************/
+/**
+ * @brief      Gets the IP address of an existing connection. 
+ *
+ * @remarks     @a ip_address must be released with free() by you. 
+ * @param[in]  handle     The handle to the connection
+ * @param[out] ip_address          The pointer to IP address string.
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ *
+******************************************************************************************/
+int connection_get_ip_address(connection_h handle, char **ip_address);
+
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the proxy address of the current connection. 
+ *
+ * @remarks  @a proxy must be released with free() by you.
+ *
+ * @param[in]  handle     The handle to the connection
+ * @param[out] proxy   The proxy address 
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ *
+ *
+******************************************************************************************/
+int connection_get_proxy(connection_h handle, char **proxy);
+
+/*****************************************************************************************/
+/**
+ * @brief  Gets the network status. 
+ *
+ * @details The returned status is for the overall connection of the phone, not per application.
+ *
+ * @param[in]  network_type            The network type 
+ * @param[out]         network_status          The status of network 
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION   Cannot retrieve the status due to internal error
+ * 
+ *
+******************************************************************************************/
+int connection_get_network_status(connection_network_type_e network_type, connection_network_status_e* network_status);
+
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the duration of the last cellular packet data connection.
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] last_datacall_duration    The time duration of the last cellular packet data connection ( seconds )
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ ******************************************************************************************/
+int connection_get_last_datacall_duration(connection_h handle, int *last_datacall_duration);
+
+/*****************************************************************************************/
+/**
+ * @brief  Gets the received data size of the last cellular packet data connection. 
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] last_recv_data_size     The received data size of the last cellular packet data connection ( bytes )
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ ******************************************************************************************/
+int connection_get_last_received_data_size(connection_h handle, int * last_recv_data_size);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the sent data size of the last cellular packet data connection. 
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] last_sent_data_size     the sent data size of the last cellular packet data connection.
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ * 
+ *
+ ******************************************************************************************/
+int connection_get_last_sent_data_size(connection_h handle, int * last_sent_data_size);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the total time duration of all cellular packet data connections.
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] total_datacall_duration    The total time duration of all cellular packet data connections ( seconds )
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ * 
+ *
+ ******************************************************************************************/
+int connection_get_total_datacall_duration(connection_h handle, int * total_datacall_duration);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the total received data size of all cellular packet data connections. 
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] total_recv_data_size    The total received data size of all cellular packet data connections (bytes)
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ * 
+ *
+ ******************************************************************************************/
+int connection_get_total_received_data_size (connection_h handle, int * total_recv_data_size);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the total sent data size of all cellular packet data connections.
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] total_sent_data_size     The total sent data size of all cellular packet data connections (bytes)
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ *
+ *
+ ******************************************************************************************/
+int connection_get_total_sent_data_size (connection_h handle, int * total_sent_data_size);
+
+/*****************************************************************************************/
+/**
+ * @brief Indicates connection status.
+ *
+ * @return Return @c true if connection is connected, otherwise @c false 
+ *
+ *
+******************************************************************************************/
+bool connection_is_connected(void);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the duration of the last WiFi packet data connection.
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] wifi_last_datacall_duration    The time duration of the last WiFi packet data connection ( seconds )
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ ******************************************************************************************/
+int connection_get_wifi_last_datacall_duration(connection_h handle, int *wifi_last_datacall_duration);
+
+/*****************************************************************************************/
+/**
+ * @brief  Gets the received data size of the last WiFi packet data connection. 
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] wifi_last_recv_data_size     The received data size of the last WiFi packet data connection ( bytes )
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ ******************************************************************************************/
+int connection_get_wifi_last_received_data_size(connection_h handle, int * wifi_last_recv_data_size);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the sent data size of the last WiFi packet data connection. 
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] wifi_last_sent_data_size     the sent data size of the last WiFi packet data connection.
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ * 
+ *
+ ******************************************************************************************/
+int connection_get_wifi_last_sent_data_size(connection_h handle, int * wifi_last_sent_data_size);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the total time duration of all WiFi packet data connections.
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] wifi_total_datacall_duration    The total time duration of all WiFi packet data connections ( seconds )
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ * 
+ *
+ ******************************************************************************************/
+int connection_get_wifi_total_datacall_duration(connection_h handle, int * wifi_total_datacall_duration);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the total received data size of all WiFi packet data connections. 
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] wifi_total_recv_data_size    The total received data size of all WiFi packet data connections (bytes)
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter
+ * 
+ *
+ ******************************************************************************************/
+int connection_get_wifi_total_received_data_size (connection_h handle, int * wifi_total_recv_data_size);
+
+/*****************************************************************************************/
+/**
+ * @brief Gets the total sent data size of all WiFi packet data connections.
+ *
+ * @param[in]   handle     The handle to the connection
+ * @param[out] wifi_total_sent_data_size     The total sent data size of all WiFi packet data connections (bytes)
+ * @return 0 on success, otherwise negative error value.
+ * @retval #CONNECTION_ERROR_NONE  Successful 
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER   Invalid parameter 
+ *
+ *
+ ******************************************************************************************/
+int connection_get_wifi_total_sent_data_size (connection_h handle, int *wifi_total_sent_data_size);
+
+/**
+ * @}
+*/
+/** 
+ * @}
+ */
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/include/net_connection_private.h b/include/net_connection_private.h
new file mode 100755 (executable)
index 0000000..9dd62e0
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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. 
+ */
+
+
+
+#ifndef __NET_CONNECTION_PRIVATE_H__        /* To prevent inclusion of a header file twice */
+#define __NET_CONNECTION_PRIVATE_H__
+
+#include <net_connection.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef struct _connection_handle_s
+{
+       connection_cb                           callback;
+       void                                    *user_data;
+}connection_handle_s;
+
+
+/**
+ * @internal
+ * @brief same as number of callbacks in connection_event_callbacks_s
+ */
+typedef enum
+{
+       LAST_DATACALL_DURATION,
+       LAST_SENT_DATA_SIZE,
+       LAST_RECEIVED_DATA_SIZE,
+       TOTAL_DATACALL_DURATION,
+       TOTAL_SENT_DATA_SIZE,
+       TOTAL_RECEIVED_DATA_SIZE,
+    LAST_WIFI_DATACALL_DURATION,
+       LAST_WIFI_SENT_DATA_SIZE,
+       LAST_WIFI_RECEIVED_DATA_SIZE,
+       TOTAL_WIFI_DATACALL_DURATION,
+       TOTAL_WIFI_SENT_DATA_SIZE,
+       TOTAL_WIFI_RECEIVED_DATA_SIZE,
+
+}stat_request_e;
+
+
+/**
+ * @brief Registers the callback to be invoked for Connection Open Response.
+ * @details
+ *
+ *       Applications MUST call this API if they want to get the async response of connection_open() API.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @param[in] callback    Pointer to function of type (connection_cb).
+ * @param[in] user_data   User data param provided by application. 
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create
+ *
+ * @par Example
+ * @ref CONNECTION_MANAGER_EXAMPLE_1
+ ******************************************************************************************/
+int connection_set_open_response_cb(connection_h handle, connection_cb callback, void *user_data);
+
+/**
+ * @brief Deregisters callback for Connection Open Response.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create, #connection_set_open_response_cb
+ *
+******************************************************************************************/
+int connection_unset_open_response_cb(connection_h handle);
+
+/**
+ * @brief Registers the callback to be invoked for Connection Close Response.
+ *
+ * @details
+ *       Applications MUST call this API if they want to get the async response of connection_close() API.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @param[in] callback    Pointer to function of type (connection_cb).
+ * @param[in] user_data   User data param provided by application.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create
+ * @par Example
+ * @ref CONNECTION_MANAGER_EXAMPLE_1
+ *
+******************************************************************************************/
+int connection_set_close_response_cb(connection_h handle, connection_cb callback, void *user_data);
+
+/**
+ * @brief Deregisters the callback for Connection Close Response.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create, #connection_set_close_response_cb
+ *
+******************************************************************************************/
+int connection_unset_close_response_cb(connection_h handle);
+
+/**
+ * @brief Registers the callback to be invoked when the data connection get suspended by the network.
+ *
+ * @details
+ *       Applications MUST call this API if they want to get notified of network suspend indications.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @param[in] callback    Pointer to function of type (connection_cb).
+ * @param[in] user_data   User data param provided by application. 
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create
+ *
+******************************************************************************************/
+int connection_set_suspend_indication_cb(connection_h handle, connection_cb callback, void *user_data);
+
+/**
+ * @brief Deregisters the callback for suspend indications.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed unccessfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create, #connection_set_suspend_indication_cb
+ *
+******************************************************************************************/
+int connection_unset_suspend_indication_cb(connection_h handle);
+
+/**
+* @brief Registers the callback to be invoked when a suspended data connection gets resumed by the network.
+ *
+ * @details
+ *       Applications MUST call this API if they want to get notified of network resume indications.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @param[in] callback    Pointer to function of type (connection_cb).
+ * @param[in] user_data   User data param provided by application.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed unccessfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create
+ *
+******************************************************************************************/
+int connection_set_resume_indication_cb(connection_h handle, connection_cb callback, void *user_data);
+
+/**
+ * @brief Deregisters the callback for resume indications.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create, #connection_set_resume_indication_cb
+ *
+******************************************************************************************/
+int connection_unset_resume_indication_cb(connection_h handle);
+
+/**
+ * @brief Registers the callback to be invoked network status changes.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @param[in] callback    Pointer to function of type (connection_cb).
+ * @param[in] user_data   User data param provided by application. 
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create
+ *
+******************************************************************************************/
+int connection_set_network_status_indication_cb(connection_h handle, connection_cb callback, void *user_data);
+
+/**
+ * @brief Deregisters the callback for network status change indications.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create, #connection_set_network_status_indication_cb
+ *
+******************************************************************************************/
+int connection_unset_network_status_indication_cb(connection_h handle);
+
+/**
+ * @brief Registers the callback to be invoked IP Address changes.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @param[in] callback    Pointer to function of type (connection_cb).
+ * @param[in] user_data   User data param provided by application. 
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create
+ *
+******************************************************************************************/
+int connection_set_ip_changed_cb(connection_h handle, connection_cb callback, void *user_data);
+
+/**
+ * @brief Deregisters the callback for IP changed indications.
+ *
+ * @param[in] handle      Handle received as a result of connection_create() API.
+ * @return 0 on success, otherwise negative error value.
+ * @retval CONNECTION_ERROR_NONE - the operation has completed successfully.
+ * @retval TIZEN_ERROR_INVALID_PARAMETER - handle is invalid or callback is null
+ * @pre #connection_create, #connection_set_ip_changed_cb
+ *
+******************************************************************************************/
+int connection_unset_ip_changed_cb(connection_h handle);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec
new file mode 100644 (file)
index 0000000..b1aeff0
--- /dev/null
@@ -0,0 +1,53 @@
+Name:       capi-network-connection
+Summary:    Network Connection library in TIZEN C API
+Version:    0.0.1
+Release:    1
+Group:      TO_BE/FILLED_IN
+License:    TO BE FILLED IN
+Source0:    %{name}-%{version}.tar.gz
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(dnet)
+BuildRequires:  pkgconfig(capi-base-common)
+Requires(post): /sbin/ldconfig  
+Requires(postun): /sbin/ldconfig
+
+%description
+
+
+%package devel
+Summary:  Network Connection library in TIZEN C API (Development)
+Group:    TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+
+
+
+%prep
+%setup -q
+
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=/usr
+
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+
+%files
+%{_libdir}/libcapi-network-connection.so
+
+%files devel
+%{_includedir}/network/*.h
+%{_libdir}/pkgconfig/*.pc
+
+
diff --git a/src/connection.c b/src/connection.c
new file mode 100755 (executable)
index 0000000..6e3d1a1
--- /dev/null
@@ -0,0 +1,398 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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. 
+ */
+
+#include <net_connection.h>
+#include <net_connection_private.h>
+#include <vconf/vconf.h>
+#include <dlog.h>
+#include <string.h>
+#include <stdio.h>
+
+#define TIZEN_N_CONNECTION "CAPI_NETWORK_CONNECTION"
+
+void connection_cb_net_config_change_cb(keynode_t *node, void *user_data);
+
+// API to convert error codes back and forth
+int convert_error_code(int dnet_error_code)
+{
+       switch(dnet_error_code)
+       {
+               case CONNECTION_ERROR_NONE:
+                       return CONNECTION_ERROR_NONE;
+               case CONNECTION_ERROR_INVALID_PARAMETER:
+                       return CONNECTION_ERROR_INVALID_PARAMETER;
+               default:
+                       return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+}
+
+int connection_set_callbacks(connection_h handle, void *callback, void *user_data)
+{
+       if(handle!=NULL)
+       {
+               connection_handle_s *local_handle = (connection_handle_s *)handle;
+               local_handle->user_data = user_data;
+               local_handle->callback = callback;
+        if(callback)
+        {
+            // This single vconf key will notify 
+            // network status, ip and proxy changes.
+                   vconf_notify_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 
+                                               connection_cb_net_config_change_cb,
+                                               local_handle);
+        }
+        else
+        {
+                   vconf_ignore_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 
+                                               connection_cb_net_config_change_cb);
+        }
+               return (CONNECTION_ERROR_NONE);
+       }
+       else
+       {
+               return (CONNECTION_ERROR_INVALID_PARAMETER);
+       }
+}
+
+int connection_set_cb(connection_h handle, connection_cb callback, void *user_data)
+{
+       int retval = CONNECTION_ERROR_NONE;
+
+       retval = connection_set_callbacks(handle, callback, user_data);
+
+       return convert_error_code(retval);
+}
+
+int connection_unset_cb(connection_h handle)
+{
+       int retval = CONNECTION_ERROR_NONE;
+
+       retval = connection_set_callbacks(handle, NULL, NULL);
+
+       return convert_error_code(retval);
+}
+
+void connection_cb_net_config_change_cb(keynode_t *node, void *user_data)
+{
+       LOGI(TIZEN_N_CONNECTION,"Net Status Indication\n");
+       if((user_data!=NULL))
+       {
+               connection_handle_s *temp = user_data;
+               if(temp->callback!=NULL)
+               {
+            if(!strcmp(vconf_keynode_get_name(node), VCONFKEY_NETWORK_STATUS))
+                temp->callback(CONNECTION_NETWORK_STATUS, temp->user_data);
+            if(!strcmp(vconf_keynode_get_name(node), VCONFKEY_NETWORK_IP))
+                temp->callback(CONNECTION_IP_ADDRESS, temp->user_data);
+            if(!strcmp(vconf_keynode_get_name(node), VCONFKEY_NETWORK_PROXY))
+                temp->callback(CONNECTION_PROXY_ADDRESS, temp->user_data);
+               }
+       }
+}
+
+int connection_create(connection_h *handle)
+{
+       if(handle==NULL)
+       {
+               LOGI(TIZEN_N_CONNECTION,"Wrong Parameter Passed\n");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+       *handle = calloc(1, sizeof(connection_handle_s));
+       if(*handle!=NULL)
+       {
+               LOGI(TIZEN_N_CONNECTION,"New Handle Created %p\n", *handle);
+       }
+       else
+       {
+               return CONNECTION_ERROR_OUT_OF_MEMORY;
+       }
+       return (CONNECTION_ERROR_NONE);
+}
+
+int connection_destroy(connection_h handle)
+{
+       if(handle!=NULL)
+       {
+               LOGI(TIZEN_N_CONNECTION,"Destroy Handle : %p\n", handle);
+               free(handle);
+       }
+       return CONNECTION_ERROR_NONE;
+}
+
+int connection_get_network_status(connection_network_type_e network_type, connection_network_status_e* network_status)
+{
+
+    if (network_status==NULL)
+    {
+           return CONNECTION_ERROR_INVALID_PARAMETER;
+    }
+
+    int status = 0;
+
+       if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status))
+       {
+        LOGI(TIZEN_N_CONNECTION,"First Step Failure = %d\n", status);
+        return CONNECTION_ERROR_INVALID_OPERATION;
+       }
+    LOGI(TIZEN_N_CONNECTION,"Connected Network = %d\n", status);
+
+    if (network_type==CONNECTION_DEFAULT_TYPE)
+        network_type = CONNECTION_WIFI_TYPE;
+
+    if (status!=network_type)
+    {
+        LOGI(TIZEN_N_CONNECTION,"Mismatch = %d\n", network_type);
+        *network_status = CONNECTION_STATUS_UNAVAILABLE;
+        return CONNECTION_ERROR_NONE;
+    }
+
+       if (network_type == CONNECTION_MOBILE_TYPE)
+       {
+               if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE,&status))
+               {
+            LOGI(TIZEN_N_CONNECTION,"Mobile = %d\n", status);
+            if (status!=VCONFKEY_NETWORK_CELLULAR_NO_SERVICE)
+            {
+                *network_status = CONNECTION_STATUS_AVAILABLE;
+            }
+            else
+            {
+                *network_status = CONNECTION_STATUS_UNAVAILABLE;
+            }
+                       return CONNECTION_ERROR_NONE;
+               }
+        else
+        {
+            *network_status = CONNECTION_STATUS_UNKNOWN;
+            LOGI(TIZEN_N_CONNECTION,"3G Failed = %d\n", status);
+            return CONNECTION_ERROR_INVALID_OPERATION;
+        }
+       }
+
+       if (network_type == CONNECTION_WIFI_TYPE)
+       {
+               if (!vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE,&status))
+               {
+            LOGI(TIZEN_N_CONNECTION,"WiFi = %d\n", status);
+            if (status!=VCONFKEY_NETWORK_WIFI_OFF)
+            {
+                *network_status = CONNECTION_STATUS_AVAILABLE;
+            }
+            else
+            {
+                *network_status = CONNECTION_STATUS_UNAVAILABLE;
+            }
+                       return CONNECTION_ERROR_NONE;
+               }
+        else
+        {
+            *network_status = CONNECTION_STATUS_UNKNOWN;
+            LOGI(TIZEN_N_CONNECTION,"WiFi Failed = %d\n", status);
+            return CONNECTION_ERROR_INVALID_OPERATION;
+        }
+       }
+       return CONNECTION_ERROR_INVALID_PARAMETER;
+}
+
+bool connection_is_connected(void)
+{
+       int network_status = 0;
+       if (!vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status))
+       {
+               return (network_status > VCONFKEY_NETWORK_OFF) ? true : false;
+       }
+       else
+               return false;
+}
+
+int connection_get_ip_address(connection_h handle, char **ip_address)
+{
+       if(handle)
+       {
+               *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
+               LOGI(TIZEN_N_CONNECTION,"IP Address %s\n", *ip_address);
+               return CONNECTION_ERROR_NONE;
+       }
+       return (CONNECTION_ERROR_INVALID_PARAMETER);
+}
+
+int connection_get_proxy(connection_h handle, char **proxy)
+{
+       if(handle)
+       {
+               *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
+               LOGI(TIZEN_N_CONNECTION,"Proxy Address %s\n", *proxy);
+               return (CONNECTION_ERROR_NONE);
+       }
+       return (CONNECTION_ERROR_INVALID_PARAMETER);
+}
+
+int fill_call_statistic(connection_h handle, stat_request_e member, int *value)
+{
+       if(handle && value)
+       {
+        switch(member)
+        {
+            case LAST_DATACALL_DURATION:
+                       *value = 0;
+                break;
+            case LAST_SENT_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get LAST_SENT_DATA_SIZE = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"LAST_SENT_DATA_SIZE:%d bytes\n", *value);
+
+                break;
+            case LAST_RECEIVED_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get LAST_RECEIVED_DATA_SIZE: = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"LAST_RECEIVED_DATA_SIZE:%d bytes\n", *value);
+                break;
+            case TOTAL_DATACALL_DURATION:
+                       *value = 0;
+                break;
+            case TOTAL_SENT_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get TOTAL_SENT_DATA_SIZE: = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"TOTAL_SENT_DATA_SIZE:%d bytes\n", *value);
+                break;
+            case TOTAL_RECEIVED_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get TOTAL_RECEIVED_DATA_SIZE: = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"TOTAL_RECEIVED_DATA_SIZE:%d bytes\n", *value);
+                break;
+            case LAST_WIFI_DATACALL_DURATION:
+                       *value = 0;
+                break;
+            case LAST_WIFI_SENT_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get LAST_WIFI_SENT_DATA_SIZE: = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"LAST_WIFI_SENT_DATA_SIZE:%d bytes\n", *value);
+                break;
+            case LAST_WIFI_RECEIVED_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get LAST_WIFI_RECEIVED_DATA_SIZE: = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"LAST_WIFI_RECEIVED_DATA_SIZE:%d bytes\n", *value);
+                break;
+            case TOTAL_WIFI_DATACALL_DURATION:
+                       *value = 0;
+                break;
+            case TOTAL_WIFI_SENT_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get TOTAL_WIFI_SENT_DATA_SIZE: = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"TOTAL_WIFI_SENT_DATA_SIZE:%d bytes\n", *value);
+                break;
+            case TOTAL_WIFI_RECEIVED_DATA_SIZE:
+                if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, value))
+                {
+                    LOGI(TIZEN_N_CONNECTION,"Cannot Get TOTAL_WIFI_RECEIVED_DATA_SIZE: = %d\n", *value);
+                           *value = 0;
+                    return CONNECTION_ERROR_INVALID_OPERATION;
+                }
+                LOGI(TIZEN_N_CONNECTION,"TOTAL_WIFI_RECEIVED_DATA_SIZE:%d bytes\n", *value);
+                break;
+        }
+               return (CONNECTION_ERROR_NONE);
+       }
+       return (CONNECTION_ERROR_INVALID_PARAMETER);
+}
+
+int connection_get_last_datacall_duration(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, LAST_DATACALL_DURATION, value);
+}
+
+int connection_get_last_received_data_size(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, LAST_RECEIVED_DATA_SIZE, value);
+}
+
+int connection_get_last_sent_data_size(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, LAST_SENT_DATA_SIZE, value);
+}
+
+int connection_get_total_datacall_duration(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, TOTAL_DATACALL_DURATION, value);
+}
+
+int connection_get_total_received_data_size (connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, TOTAL_RECEIVED_DATA_SIZE, value);
+}
+
+int connection_get_total_sent_data_size (connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, TOTAL_SENT_DATA_SIZE, value);
+}
+
+int connection_get_wifi_last_datacall_duration(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, LAST_WIFI_DATACALL_DURATION, value);
+}
+
+int connection_get_wifi_last_received_data_size(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, LAST_WIFI_RECEIVED_DATA_SIZE, value);
+}
+
+int connection_get_wifi_last_sent_data_size(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, LAST_WIFI_SENT_DATA_SIZE, value);
+}
+
+int connection_get_wifi_total_datacall_duration(connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, TOTAL_WIFI_DATACALL_DURATION, value);
+}
+
+int connection_get_wifi_total_received_data_size (connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, TOTAL_WIFI_RECEIVED_DATA_SIZE, value);
+}
+
+int connection_get_wifi_total_sent_data_size (connection_h handle, int *value)
+{
+       return fill_call_statistic(handle, TOTAL_WIFI_SENT_DATA_SIZE, value);
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..97657b6
--- /dev/null
@@ -0,0 +1,20 @@
+SET(fw_test "${fw_name}-test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0)
+FOREACH(flag ${${fw_test}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
+
+#ADD_EXECUTABLE("system-sensor" system-sensor.c)
+#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS})
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+    GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+    MESSAGE("${src_name}")
+    ADD_EXECUTABLE(${src_name} ${src})
+    TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
diff --git a/test/connection_test.c b/test/connection_test.c
new file mode 100644 (file)
index 0000000..3b1c9e6
--- /dev/null
@@ -0,0 +1,341 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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. 
+ */
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/un.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <signal.h>
+#include "assert.h"
+#include "glib.h"
+#include <net_connection.h>
+#include <tizen_error.h>
+
+  
+gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
+int test_register_client(void);
+int test_deregister_client(void);
+int test_open_connection(void);
+int test_close_connection(void);
+int test_get_current_proxy(void);
+int test_get_current_device_info(void);
+int test_get_call_statistics_info(void);
+int test_get_wifi_call_statistics_info(void);
+int test_get_network_status(int);
+int test_set_default_profile_id(void);
+void test_print_device_info(void);
+connection_h handle = NULL;
+
+void net_callback(const connection_network_param_e param, void *user_data)
+{
+       char *ptr = NULL;
+       connection_get_ip_address(handle, &ptr);
+       printf("Param Name : %d IP Address = %s\n", param,  ptr);
+       free(ptr);
+}
+
+int test_register_client(void){
+
+       int err = connection_create(&handle);
+
+       if(CONNECTION_ERROR_NONE==err) //set callbacks
+       {
+               if(handle==NULL)
+                       printf("OOOOOPPPPSSS\n");
+               connection_set_cb(handle, net_callback, NULL);
+       }
+       else
+       {
+               printf("Client registration failed %d\n", err);
+               return -1;
+       }
+
+       printf("Client registration success\n");
+       return 1;
+}
+int  test_deregister_client(void){
+       int rv = 0;
+
+       if(handle!=NULL)
+               rv = connection_destroy(handle);
+       else
+               printf("Cannot deregister : Handle is NULL\n");
+
+       if (rv != CONNECTION_ERROR_NONE){
+               printf("Client deregistration fail [%d]\n", rv);
+               return -1;
+       }
+
+       printf("Client deregistration success\n");
+       return 1;
+}
+
+int test_open_connection(void){
+       int rv =0;
+
+       //rv = connection_open(handle, CONNECTION_DEFAULT_TYPE);
+
+       if (rv != CONNECTION_ERROR_NONE){
+               printf("Fail to call open connection [%d]\n", rv);
+               return -1;
+       }
+
+       printf("open connection api is called [%d]\n", rv);
+       return 1;
+}
+
+int test_close_connection(void){
+       int rv =0;
+
+       //rv = connection_close(handle);
+
+       if (rv  != CONNECTION_ERROR_NONE){
+               printf("Fail to call close connection [%d]\n", rv);
+               return -1;
+       }
+
+       printf("close connection api is called\n");
+       return 1;
+}
+
+
+int test_is_connected(void){
+       int rv =0;
+
+       rv = connection_is_connected();
+
+       if(rv != 1){
+               printf("There is no active connection\n");
+               return -1;
+       }
+
+       printf("Connected\n");
+       printf("is connected api is called\n");
+       return 1;
+}
+
+int test_get_current_proxy(void){
+       int rv=0;
+       char *proxy_addr=NULL;
+
+       rv = connection_is_connected();
+
+       if(rv != 1){
+               printf("There is no active connection\n");
+               return -1;
+       }
+
+       rv = connection_get_proxy(handle, &proxy_addr);
+
+       if(proxy_addr == NULL){
+               printf("Proxy address does not exist\n");
+               return -1;
+       }
+
+       printf("Current Proxy [%s]\n", proxy_addr);
+       free(proxy_addr);
+       
+       printf("get current proxy api is called\n");
+       return 1;
+}
+
+int test_get_current_device_info(void){
+       int rv=0;
+       rv = connection_is_connected();
+
+       if(rv != 1){
+               printf("There is no active connection\n");
+               return -1;
+       }
+
+       test_print_device_info();
+
+       printf("get current device information api is called\n");
+       
+       return 1;       
+}
+
+int test_get_call_statistics_info(void){
+       int rv=0;
+
+       connection_get_last_datacall_duration(handle, &rv);
+       printf("last received data pkg size [%d]\n", rv);
+       connection_get_last_received_data_size(handle, &rv);
+       printf("last recv data pkg size [%d]\n", rv);
+       connection_get_last_sent_data_size(handle, &rv);
+       printf("last sent data pkg size [%d]\n",rv );
+       connection_get_total_datacall_duration(handle, &rv);
+       printf("total data pkg size [%d]\n", rv);
+       connection_get_total_received_data_size (handle, &rv);
+       printf("total received data pkg size [%d]\n",rv );
+       connection_get_total_sent_data_size (handle, &rv);
+       printf("total sent data pkg size [%d]\n", rv);
+
+
+       printf("get call statistics information is called\n");
+
+       return 1;
+}
+
+int test_get_wifi_call_statistics_info(void){
+       int rv=0;
+
+       connection_get_wifi_last_datacall_duration(handle, &rv);
+       printf("WiFi last received data pkg size [%d]\n", rv);
+       connection_get_wifi_last_received_data_size(handle, &rv);
+       printf("WiFi last recv data pkg size [%d]\n", rv);
+       connection_get_wifi_last_sent_data_size(handle, &rv);
+       printf("WiFi last sent data pkg size [%d]\n",rv );
+       connection_get_wifi_total_datacall_duration(handle, &rv);
+       printf("WiFi total data pkg size [%d]\n", rv);
+       connection_get_wifi_total_received_data_size (handle, &rv);
+       printf("WiFi total received data pkg size [%d]\n",rv );
+       connection_get_wifi_total_sent_data_size (handle, &rv);
+       printf("WiFi total sent data pkg size [%d]\n", rv);
+
+
+       printf("get WiFi call statistics information is called\n");
+
+       return 1;
+}
+
+int test_get_network_status(int type){
+       int rv=0;
+       connection_network_status_e net_status;
+
+       memset(&net_status, 0 , sizeof(connection_network_status_e) );
+
+    if(type == 1)
+           rv = connection_get_network_status(CONNECTION_MOBILE_TYPE, &net_status);
+    if(type==2)
+           rv = connection_get_network_status(CONNECTION_WIFI_TYPE, &net_status);
+
+       if(rv != CONNECTION_ERROR_NONE){
+               printf("Fail to get network status [%d]\n",rv );
+               return -1;
+       }
+
+       printf("Retval = %d network connection status  [%d]\n", rv, net_status);
+
+       
+       return 1;               
+}
+
+
+void test_print_device_info(void){
+       char *temp=NULL;
+       if(!connection_get_ip_address(handle, &temp))
+       {
+               if(temp!=NULL)
+               {
+                       printf("IPv4 address : %s\n", temp);
+                       free(temp);
+               }
+               else
+                       printf("IPv4 address Not Provided by Network\n");
+       }
+       
+       return;
+}
+
+int main(int argc, char **argv){
+       
+       GMainLoop *mainloop;
+       mainloop = g_main_loop_new (NULL, FALSE);
+
+       GIOChannel *channel = g_io_channel_unix_new(0);
+       g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread,NULL );
+
+       printf("Test Thread created...\n");
+
+       test_register_client();
+       
+       g_main_loop_run (mainloop);
+
+       return 0;
+}
+
+gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
+{
+       int rv=0;
+       char a[100];
+       
+       memset(a, '\0', 100);
+       printf("Event received from stdin \n");
+       
+       rv = read(0, a, 100);
+       
+       if (rv < 0 || a[0] == '0') exit(1);
+
+       if (*a == '\n' || *a == '\r'){
+               printf("\n\n Network Framework Test App\n\n");
+               printf("Options..\n");
+               printf("1       - Create Handle\n");
+               printf("2       - Destroy Handle\n");
+               printf("3       - Get current proxy address \n");               
+               printf("4       - Is connected\n");
+               printf("5       - Get current network device information\n");
+
+               printf("6       - Get cellular data call statistics\n");
+               printf("7       - Get WiFi data call statistics\n");
+               printf("8       - Get cellular status (please insert SIM Card)\n");
+               printf("9       - Get wifi status (please turn on WiFi)\n");
+
+               printf("0       - Exit \n");
+
+               printf("ENTER  - Show options menu.......\n");
+       }
+
+       switch (a[0])
+       {
+               case '1':{
+                       rv = test_register_client();
+               }break;
+               case '2':{
+                       rv = test_deregister_client();
+               }break;
+               case '3':{
+                       rv = test_get_current_proxy();
+               }break;
+               case '4':{
+                       rv = test_is_connected();
+               }break;
+               case '5':{
+                       rv = test_get_current_device_info();
+               }break;
+               case '6':{
+                       rv = test_get_call_statistics_info();
+               }break;
+               case '7':{
+                       rv = test_get_wifi_call_statistics_info();
+               }break;
+               case '8':{
+                       rv = test_get_network_status(CONNECTION_MOBILE_TYPE);
+               }break;
+               case '9':{
+                       rv = test_get_network_status(CONNECTION_WIFI_TYPE);
+               }break;
+       }
+       return TRUE;
+}
diff --git a/test/connection_test_regress.c b/test/connection_test_regress.c
new file mode 100644 (file)
index 0000000..a735542
--- /dev/null
@@ -0,0 +1,330 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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. 
+ */
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/un.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <signal.h>
+#include "assert.h"
+#include "glib.h"
+#include <net_connection.h>
+#include <tizen_error.h>
+
+  
+gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
+int test_register_client(void);
+int test_deregister_client(void);
+int test_open_connection(void);
+int test_close_connection(void);
+int test_get_current_proxy(void);
+int test_get_current_device_info(void);
+int test_get_call_statistics_info(void);
+int test_get_network_status(int);
+int test_set_default_profile_id(void);
+void test_print_device_info(void);
+connection_h handle = NULL;
+int state_machine = 0;
+char a[2];
+void net_callback(const connection_network_param_e param, void *user_data)
+{
+       char *ptr = NULL;
+       connection_get_ip_address(handle, &ptr);
+       printf("Param Name : %d IP Address = %s\n", param,  ptr);
+       free(ptr);
+}
+
+int test_register_client(void){
+
+       int err = connection_create(&handle);
+
+       if(err==CONNECTION_ERROR_NONE) //set callbacks
+       {
+               if(handle==NULL)
+                       printf("OOOOOPPPPSSS\n");
+               connection_set_cb(handle, net_callback, NULL);
+       }
+       else
+       {
+               printf("Client registration failed %d\n", err);
+               return -1;
+       }
+
+       printf("Client registration success\n");
+       return 1;
+}
+int  test_deregister_client(void){
+       int rv = 0;
+
+       if(handle!=NULL)
+               rv = connection_destroy(handle);
+       else
+               printf("Cannot deregister : Handle is NULL\n");
+
+       if (rv != CONNECTION_ERROR_NONE){
+               printf("Client deregistration fail [%d]\n", rv);
+               return -1;
+       }
+
+       printf("Client deregistration success\n");
+       return 1;
+}
+
+int test_open_connection(void){
+       int rv =0;
+
+       //rv = connection_open(handle, CONNECTION_DEFAULT_TYPE);
+
+       if (rv != CONNECTION_ERROR_NONE){
+               printf("Fail to call open connection [%d]\n", rv);
+               return -1;
+       }
+
+       printf("open connection api is called [%d]\n", rv);
+       return 1;
+}
+
+int test_close_connection(void){
+       int rv =0;
+
+       //rv = connection_close(handle);
+
+       if (rv  != CONNECTION_ERROR_NONE){
+               printf("Fail to call close connection [%d]\n", rv);
+               return -1;
+       }
+
+       printf("close connection api is called\n");
+       return 1;
+}
+
+
+int test_is_connected(void){
+       int rv =0;
+
+       rv = connection_is_connected();
+
+       if(rv != 1){
+               printf("There is no active connection\n");
+               return -1;
+       }
+
+       printf("Connected\n");
+       printf("is connected api is called\n");
+       return 1;
+}
+
+int test_get_current_proxy(void){
+       int rv=0;
+       char *proxy_addr=NULL;
+
+       rv = connection_is_connected();
+
+       if(rv != 1){
+               printf("There is no active connection\n");
+               return -1;
+       }
+
+       rv = connection_get_proxy(handle, &proxy_addr);
+
+       if(proxy_addr == NULL){
+               printf("Proxy address does not exist\n");
+               return -1;
+       }
+
+       printf("Current Proxy [%s]\n", proxy_addr);
+       free(proxy_addr);
+       
+       printf("get current proxy api is called\n");
+       return 1;
+}
+
+int test_get_current_device_info(void){
+       int rv=0;
+       rv = connection_is_connected();
+
+       if(rv != 1){
+               printf("There is no active connection\n");
+               return -1;
+       }
+
+       test_print_device_info();
+
+       printf("get current device information api is called\n");
+       
+       return 1;       
+}
+
+int test_get_call_statistics_info(void){
+       int rv=0;
+
+       connection_get_last_datacall_duration(handle, &rv);
+       printf("last received data pkg size [%d]\n", rv);
+       connection_get_last_received_data_size(handle, &rv);
+       printf("last recv data pkg size [%d]\n", rv);
+       connection_get_last_sent_data_size(handle, &rv);
+       printf("last sent data pkg size [%d]\n",rv );
+       connection_get_total_datacall_duration(handle, &rv);
+       printf("total data pkg size [%d]\n", rv);
+       connection_get_total_received_data_size (handle, &rv);
+       printf("total received data pkg size [%d]\n",rv );
+       connection_get_total_sent_data_size (handle, &rv);
+       printf("total sent data pkg size [%d]\n", rv);
+
+
+       printf("get call statistics information is called\n");
+
+       return 1;
+}
+
+int test_get_network_status(int type){
+       int rv=0;
+       connection_network_status_e net_status;
+
+       memset(&net_status, 0 , sizeof(connection_network_status_e) );
+
+    if(type == 1)
+           rv = connection_get_network_status(CONNECTION_MOBILE_TYPE, &net_status);
+    if(type==2)
+           rv = connection_get_network_status(CONNECTION_WIFI_TYPE, &net_status);
+
+       if(rv != CONNECTION_ERROR_NONE){
+               printf("Fail to get network status [%d]\n",rv );
+               return -1;
+       }
+
+       printf("Retval = %d network connection status  [%d]\n", rv, net_status);
+
+       
+       return 1;               
+}
+
+
+void test_print_device_info(void){
+       char *temp=NULL;
+       if(!connection_get_ip_address(handle, &temp))
+       {
+               if(temp!=NULL)
+               {
+                       printf("IPv4 address : %s\n", temp);
+                       free(temp);
+               }
+               else
+                       printf("IPv4 address Not Provided by Network\n");
+       }
+       
+       return;
+}
+
+int main(int argc, char **argv){
+       
+       GMainLoop *mainloop;
+       a[0]='1';
+       mainloop = g_main_loop_new (NULL, FALSE);
+       g_idle_add((GSourceFunc)test_thread,NULL);
+       printf("Test Thread created...\n");
+       g_main_loop_run (mainloop);
+       return 0;
+}
+
+gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
+{
+       int rv=0;
+       
+       switch (a[0])
+       {
+               case '1':{
+                       rv = test_register_client();
+                       a[0] = '4';
+               }break;
+               case '2':{
+                       rv = test_deregister_client();
+                       a[0] = '1';
+               }break;
+               case '4':{
+                       if(state_machine==2)
+                       {
+                               state_machine = 3;
+                               a[0] = '7';
+                       }
+                       else if(state_machine==0)
+                       {
+                               rv = test_open_connection();
+                               if(rv<CONNECTION_ERROR_NONE)
+                               {
+                                       state_machine = 0;
+                                       a[0] = '2';
+                               }
+                               else
+                               {
+                                       state_machine = 1;
+                               }
+                       }
+               }break;
+               case '6':{
+                       if(state_machine==5){
+                               state_machine = 0;
+                               a[0] = '2';
+                       }
+                       else if(state_machine==3)
+                       {
+                               rv = test_close_connection();
+                               if(rv<CONNECTION_ERROR_NONE)
+                               {
+                                       state_machine = 0;
+                                       a[0] = '2';
+                               }
+                               else
+                               {
+                                       state_machine = 4;
+                               }
+                       }
+               }break;         
+               case '7':{
+                       rv = test_get_current_proxy();
+                       a[0] = '8';
+               }break;
+               case '8':{
+                       rv = test_is_connected();
+                       a[0] = '9';
+               }break;
+               case '9':{
+                       rv = test_get_current_device_info();
+                       a[0] = 'e';
+               }break;
+               case 'e':{
+                       rv = test_get_call_statistics_info();
+                       a[0] = 'f';
+               }break;
+               case 'f':{
+                       rv = test_get_network_status(CONNECTION_MOBILE_TYPE);
+                       a[0] = 'g';
+               }break;
+               case 'g':{
+                       rv = test_get_network_status(CONNECTION_WIFI_TYPE);
+                       a[0] = '6';
+               }break;
+       }
+       return TRUE;
+}
diff --git a/test/examples/getting-connection-setting-example.c b/test/examples/getting-connection-setting-example.c
new file mode 100644 (file)
index 0000000..cf88172
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ * 
+ * This software is the confidential and proprietary information of SAMSUNG 
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
+ * this software is owned by Samsung and you shall not disclose such 
+ * Confidential Information and shall use it only in accordance with the terms 
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
+ * make no representations or warranties about the suitability of the software, 
+ * either express or implied, including but not limited to the implied 
+ * warranties of merchantability, fitness for a particular purpose, or 
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
+ * licensee arising out of or related to this software.
+ * 
+ */
+
+
+#include <net_connection_interface.h>
+
+void foo(void)
+{
+    //..
+    // open connection  
+    //..
+    char *ip_address = NULL;
+    connection_get_ip_address(handle,&ip_address);
+    if(err != CONNECTION_ERROR_NONE)
+    {
+    // error handling
+    }
+    char *proxy = NULL;
+    connection_get_proxy(handle,&proxy);
+    if(err != CONNECTION_ERROR_NONE)
+    {
+    // error handling
+    }
+}
diff --git a/test/examples/openconnection-example.c b/test/examples/openconnection-example.c
new file mode 100644 (file)
index 0000000..63b6ce2
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ * 
+ * This software is the confidential and proprietary information of SAMSUNG 
+ * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
+ * this software is owned by Samsung and you shall not disclose such 
+ * Confidential Information and shall use it only in accordance with the terms 
+ * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
+ * make no representations or warranties about the suitability of the software, 
+ * either express or implied, including but not limited to the implied 
+ * warranties of merchantability, fitness for a particular purpose, or 
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
+ * licensee arising out of or related to this software.
+ * 
+ */
+
+
+#include <stdio.h>
+
+#include <app.h>
+#include <app_efl.h>
+#include <i18n.h>
+#include <Ecore_X.h>
+#include <net_connection_interface.h>
+#include <glib-2.0/glib.h>
+#include <dbus/dbus-glib.h>
+
+static GMutex *mutex= NULL; // mutex needed to synchronize connection callbacks
+
+int main(int argc, char *argv[])
+{
+
+       if(!g_thread_supported())
+       {
+               g_thread_init(NULL);
+       }
+
+       dbus_g_thread_init();
+
+       g_type_init();
+       GMainLoop *main_loop = NULL;
+       main_loop = g_main_loop_new(NULL, FALSE);
+
+       mutex = g_mutex_new(); // create mutex
+       g_thread_create(&connection_thread, NULL, false, NULL); // create new thread with our connection_thread function
+       // it's important to create new thread, because callbacks are called from main loop context - if we don’t return control to the main loop, the callback will never be called
+        g_main_loop_run(main_loop);
+       return 0;
+}
+
+void connection_callback(const char *param_name, void *user_data) // this callback will be called when IP is changed.
+{
+       g_mutex_unlock(mutex);
+}
+
+static gpointer connection_thread(gpointer data)
+{
+
+       int result;
+       void *user_data; // application specific or NULL
+       connection_h handle;
+       connection_error_e err = connection_create(&handle); // create handle
+       if(err != CONNECTION_ERROR_NONE)
+       {
+               // error handling
+       }
+
+       if(handle!=NULL)
+       { 
+               connection_error_e retval = connection_set_cb(handle, connection_callback, user_data); // set open connection callback, if connection is opened/closed our callback will be called
+               if(retval != CONNECTION_ERROR_NONE)
+               {
+                       // error handling
+               }
+               retval = connection_open(handle, CONNECTION_MOBILE_TYPE); // start opening connection
+               if(retval != CONNECTION_ERROR_NONE)
+               {
+                       // error handling
+               }
+               g_mutex_lock(mutex); // wait till open_callback is successfully called
+
+               // now you can perform network operations
+
+               // now the connection should be closed, because it is no longer needed
+               retval = connection_close(handle, CONNECTION_MOBILE_TYPE); // invoke connection closing
+               if(retval != CONNECTION_ERROR_NONE)
+               {
+                       // error handling
+               }
+               g_mutex_lock(mutex); // wait till close_callback is called
+
+               connection_error_e err = connection_destroy(handle); // free resources used by handle
+               if(err != CONNECTION_ERROR_NONE)
+               {
+                       // error handling
+               }
+       }
+}
+