summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Kibum <kb0929.kim@samsung.com>2012-04-29 16:58:23 +0900
committerKim Kibum <kb0929.kim@samsung.com>2012-04-29 16:58:23 +0900
commit9ef936a92b45b60ba3d9573269c411e34b9f25bf (patch)
tree6528b5e8fdd1c3fd2640fb040d5cf019349ae624
parent9655a4418200506aaf07083abd3258a4bba0cc00 (diff)
downloadconnection-9ef936a92b45b60ba3d9573269c411e34b9f25bf.tar.gz
connection-9ef936a92b45b60ba3d9573269c411e34b9f25bf.tar.bz2
connection-9ef936a92b45b60ba3d9573269c411e34b9f25bf.zip
upload tizen1.0 source
-rw-r--r--.gitignore51
-rw-r--r--CMakeLists.txt7
-rw-r--r--capi-network-connection.pc.in3
-rw-r--r--debian/changelog38
-rw-r--r--debian/control6
-rwxr-xr-xinclude/net_connection.h527
-rw-r--r--include/net_connection_private.h192
-rw-r--r--packaging/capi-network-connection.spec26
-rwxr-xr-xsrc/connection.c755
-rw-r--r--test/CMakeLists.txt3
-rw-r--r--test/connection_test.c314
-rw-r--r--test/connection_test_regress.c330
-rw-r--r--test/examples/getting-connection-setting-example.c39
-rw-r--r--test/examples/openconnection-example.c101
14 files changed, 882 insertions, 1510 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 85209fb..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,51 +0,0 @@
-CMakeCache.txt
-*/CMakeFiles/*
-*.cmake
-CMakeFiles*
-*.a
-*.so
-Testing
-cmake.depends
-cmake.check_depends
-cmake.check_cache
-core
-core.*
-gmon.out
-install_manifest.txt
-doc/html/*
-*~
-.kdev_include_paths
-src.kdev4
-.cproject
-.project
-tet_captured
-tet_lock
-*.pc
-Makefile
-*-test
-TC/config
-samples/.metadata
-TC/results/
-TC/testcase/connection_test
-build-stamp
-cmake_build_tmp/
-config.cfg
-configure-stamp
-debian/capi-network-connection-dbg.debhelper.log
-debian/capi-network-connection-dbg.substvars
-debian/capi-network-connection-dbg/
-debian/capi-network-connection-dev.debhelper.log
-debian/capi-network-connection-dev.substvars
-debian/capi-network-connection-dev/
-debian/debhelper.log
-debian/files
-debian/substvars
-debian/tmp/
-debian/capi-network-connection.debhelper.log
-debian/capi-network-connection.postinst.debhelper
-debian/capi-network-connection.postrm.debhelper
-debian/capi-network-connection.substvars
-debian/capi-network-connection/
-test/connection_test
-test/connection_test_regress
-
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c795c3..ddc07f3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,3 @@
-
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(fw_name "capi-network-connection")
@@ -10,7 +9,8 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(INC_DIR include)
INCLUDE_DIRECTORIES(${INC_DIR})
-SET(dependents "dlog vconf capi-base-common")
+SET(dependents "dlog vconf capi-base-common glib-2.0")
+SET(pc_dependents "capi-base-common")
INCLUDE(FindPkgConfig)
pkg_check_modules(${fw_name} REQUIRED ${dependents})
@@ -51,9 +51,8 @@ INSTALL(
)
SET(PC_NAME ${fw_name})
-SET(PC_REQUIRED ${dependents})
+SET(PC_REQUIRED ${pc_dependents})
SET(PC_LDFLAGS -l${fw_name})
-SET(PC_CFLAGS -I\${includedir}/network)
CONFIGURE_FILE(
${fw_name}.pc.in
diff --git a/capi-network-connection.pc.in b/capi-network-connection.pc.in
index fd41dbb..097a2d1 100644
--- a/capi-network-connection.pc.in
+++ b/capi-network-connection.pc.in
@@ -1,4 +1,3 @@
-
# Package Information for pkg-config
prefix=@PREFIX@
@@ -11,5 +10,5 @@ Description: @PACKAGE_DESCRIPTION@
Version: @VERSION@
Requires: @PC_REQUIRED@
Libs: -L${libdir} @PC_LDFLAGS@
-Cflags: -I${includedir} @PC_CFLAGS@
+Cflags: -I${includedir}
diff --git a/debian/changelog b/debian/changelog
index 3fab06c..82a0f6c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,7 +1,39 @@
+capi-network-connection (0.1.0-21) unstable; urgency=low
+
+ * Add ipv6 feature
+ * Git: api/connection
+ * Tag: capi-network-connection_0.1.0-21
+
+ -- JaeHyun Kim <jeik01.kim@samsung.com> Fri, 30 Mar 2012 18:15:20 +0900
+
+capi-network-connection (0.1.0-20) unstable; urgency=low
+
+ * Update DTS
+ * Git: api/connection
+ * Tag: capi-network-connection_0.1.0-20
+
+ -- JaeHyun Kim <jeik01.kim@samsung.com> Tue, 20 Mar 2012 16:08:10 +0900
+
+capi-network-connection (0.1.0-19) unstable; urgency=low
+
+ * Revise spec for OBS
+ * Git: api/connection
+ * Tag: capi-network-connection_0.1.0-19
+
+ -- Danny Jeongseok Seo <s.seo@samsung.com> Sat, 17 Mar 2012 18:31:44 +0900
+
+capi-network-connection (0.1.0-18) unstable; urgency=low
+
+ * Implementation of new APIs
+ * Git: api/connection
+ * Tag: capi-network-connection_0.1.0-18
+
+ -- JaeHyun Kim <jeik01.kim@samsung.com> Fri, 16 Mar 2012 18:46:37 +0900
+
capi-network-connection (0.1.0-17) unstable; urgency=low
- * Convert internal symbol to static
- * Git: slp/api/connection
+ * Convert internal function to static function
+ * Git: api/connection
* Tag: capi-network-connection_0.1.0-17
-- ByungWoo Lee <bw1212.lee@samsung.com> Mon, 20 Feb 2012 17:55:42 +0900
@@ -16,7 +48,7 @@ capi-network-connection (0.1.0-16) unstable; urgency=low
capi-network-connection (0.1.0-15) unstable; urgency=low
- * Fix bugs
+ * Fix bugs and related DTS
* Git: api/connection
* Tag: capi-network-connection_0.1.0-15
diff --git a/debian/control b/debian/control
index 9bf1815..d31a37f 100644
--- a/debian/control
+++ b/debian/control
@@ -2,16 +2,16 @@ 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
+Build-Depends: debhelper (>= 5), dlog-dev, capi-base-common-dev, libvconf-dev, libglib2.0-dev
Package: capi-network-connection
Architecture: any
-Depends: ${shilbs:Depends}, ${misc:Depends}
+Depends: ${shlibs: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}), dlog-dev, capi-base-common-dev, libvconf-dev
+Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-connection (= ${Source-Version}), capi-base-common-dev
Description: Network Connection library in TIZEN C API (DEV)
Package: capi-network-connection-dbg
diff --git a/include/net_connection.h b/include/net_connection.h
index 0a9ee73..6159cfa 100755
--- a/include/net_connection.h
+++ b/include/net_connection.h
@@ -11,427 +11,340 @@
* 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.
+ * 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>
-
+#include <tizen.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.
-*/
+ * @brief Enumerations of connection 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_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_ADDRESS_FAMILY_NOT_SUPPORTED = TIZEN_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED, /**< Address family not supported */
}connection_error_e;
/**
-* @enum connection_network_status_e
-* @brief Enumerations of network status.
-*/
-typedef enum
+ * @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;
+ CONNECTION_NETWORK_STATE_DISCONNECTED = 0, /**< Disconnected */
+ CONNECTION_NETWORK_STATE_WIFI = 1, /**< Wi-Fi is used for default connection */
+ CONNECTION_NETWORK_STATE_CELLULAR = 2, /**< Cellular is used for default connection */
+}connection_network_state_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;
-
-
+ * @brief Enumerations of Address type
+ */
+typedef enum
+{
+ CONNECTION_ADDRESS_FAMILY_IPV4 = 0, /**< IPV4 Address type */
+ CONNECTION_ADDRESS_FAMILY_IPV6 = 1, /**< IPV6 Address type */
+} connection_address_family_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 Enumerations of cellular network state.
+ */
+typedef enum
+{
+ CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE = 0, /**< Out of service */
+ CONNECTION_CELLULAR_STATE_FLIGHT_MODE = 1, /**< Flight mode */
+ CONNECTION_CELLULAR_STATE_ROAMING_OFF = 2, /**< Roaming is turned off */
+ CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE = 3, /**< Call is only available. */
+ CONNECTION_CELLULAR_STATE_AVAILABLE = 4, /**< Available */
+}connection_cellular_state_e;
+/**
+ * @brief This enumeration defines the Wi-Fi state.
+ */
+typedef enum
+{
+ CONNECTION_WIFI_STATE_DEACTIVATED = 0, /**< Deactivated state */
+ CONNECTION_WIFI_STATE_DISCONNECTED = 1, /**< disconnected state */
+ CONNECTION_WIFI_STATE_CONNECTED = 2, /**< Connected state */
+} connection_wifi_state_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
+ * @brief Called when the state of network is changed.
+ * @param[in] connection_network_state_e The state of current network connection
* @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);
+ * @see connection_set_network_status_changed_cb()
+ * @see connection_unset_network_status_changed_cb()
+ */
+typedef void(*connection_network_state_changed_cb)(connection_network_state_e state, void* user_data);
+/**
+ * @brief Called when the address is changed.
+ * @param[in] ipv4_address The ipv4 address of current network connection
+ * @param[in] ipv6_address The ipv6 address of current network connection
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see connection_set_ip_address_changed_cb()
+ * @see connection_unset_ip_address_changed_cb()
+ * @see connection_set_proxy_address_changed_cb()
+ * @see connection_unset_proxy_address_changed_cb()
+ */
+typedef void(*connection_address_changed_cb)(const char* ipv4_address, const char* ipv6_address, 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
+ * @remarks @a handle must be released with connection_destroy().
+ * @param[out] connection 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
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory
* @see connection_destroy()
- *
- *
-******************************************************************************************/
-int connection_create(connection_h * handle);
+ */
+int connection_create(connection_h* connection);
-/*****************************************************************************************/
/**
- * @brief Destroys the connection handle.
- *
- * @param[in] handle The handle to the connection
- *
+ * @brief Destroys the connection handle.
+ * @param[in] connection 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_INVALID_PARAMETER Invalid parameter
* @see connection_create()
- *
- *
-******************************************************************************************/
-int connection_destroy(connection_h handle);
+ */
+int connection_destroy(connection_h connection);
-/*****************************************************************************************/
/**
- * @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
+ * @brief Gets the network state.
+ * @details The returned status is for the current connection.
+ * @param[in] connection The handle to the connection
+ * @param[out] state The state of network
* @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);
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the state due to internal error
+ */
+int connection_get_network_state(connection_h connection, connection_network_state_e* state);
-/*****************************************************************************************/
/**
- * @brief Unregisters the callback function.
- * @param[in] handle The handle to the connection
+ * @brief Gets the IP address of the current connection.
+ * @remarks @a ip_address must be released with free() by you.
+ * @param[in] connection The handle to the connection
+ * @param[in] address_family The address family
+ * @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
- * @see connection_cb()
- * @see connection_set_cb()
-******************************************************************************************/
-int connection_unset_cb(connection_h handle);
-
-/*****************************************************************************************/
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the ip address due to internal error
+ */
+int connection_get_ip_address(connection_h connection, connection_address_family_e address_family, char** ip_address);
+
/**
- * @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.
+ * @brief Gets the proxy address of the current connection.
+ * @remarks @a proxy must be released with free() by you.
+ * @param[in] connection The handle to the connection
+ * @param[in] address_family The address family
+ * @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_ip_address(connection_h handle, char **ip_address);
-
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the proxy due to internal error
+ */
+int connection_get_proxy(connection_h connection, connection_address_family_e address_family, char** proxy);
-/*****************************************************************************************/
/**
- * @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
+ * @brief Gets the state of celluar connection.
+ * @details The returned state is for the cellular connection state.
+ * @param[in] connection The handle of connection
+ * @param[out] state The state of cellular connection
* @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);
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the state due to internal error
+ */
+int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state);
-/*****************************************************************************************/
/**
- * @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
+ * @brief Gets the state of Wi-Fi.
+ * @details The returned state is for the Wi-Fi connection state.
+ * @param[in] connection The handle of connection
+ * @param[out] state The state of Wi-Fi connection
* @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);
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the state due to internal error
+ */
+int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state);
+/**
+ * @brief Registers the callback called when the state of current connection is changed.
+ * @param[in] connection The handle of connection
+ * @param[in] callback The callback function to be called
+ * @param[in] user_data The user data 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
+ */
+int connection_set_network_state_changed_cb(connection_h connection, connection_network_state_changed_cb callback, void* user_data);
-/*****************************************************************************************/
/**
- * @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 )
+ * @brief Unregisters the callback called when the state of current connection is changed.
+ * @param[in] connection The handle of connection
* @return 0 on success, otherwise negative error value.
- * @retval #CONNECTION_ERROR_NONE Successful
+ * @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);
+ */
+int connection_unset_network_state_changed_cb(connection_h connection);
-/*****************************************************************************************/
/**
- * @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 )
+ * @brief Registers the callback called when the ip address is changed.
+ * @param[in] connection The handle of connection
+ * @param[in] callback The callback function to be called
+ * @param[in] user_data The user data passed to the callback function
* @return 0 on success, otherwise negative error value.
- * @retval #CONNECTION_ERROR_NONE Successful
+ * @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);
+ */
+int connection_set_ip_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data);
-/*****************************************************************************************/
/**
- * @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.
+ * @brief Unregisters the callback called when the ip address is changed.
+ * @param[in] connection The handle of 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);
+ */
+int connection_unset_ip_address_changed_cb(connection_h connection);
-/*****************************************************************************************/
/**
- * @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 )
+ * @brief Registers the callback called when the proxy address is changed.
+ * @param[in] connection The handle of connection
+ * @param[in] callback The callback function to be called
+ * @param[in] user_data The user data 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
- *
- *
- ******************************************************************************************/
-int connection_get_total_datacall_duration(connection_h handle, int * total_datacall_duration);
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int connection_set_proxy_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data);
-/*****************************************************************************************/
/**
- * @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)
+ * @brief Unregisters the callback called when the proxy address is changed.
+ * @param[in] connection The handle of connection
* @return 0 on success, otherwise negative error value.
- * @retval #CONNECTION_ERROR_NONE Successful
+ * @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);
+ */
+int connection_unset_proxy_address_changed_cb(connection_h connection);
-/*****************************************************************************************/
/**
- * @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)
+ * @brief Gets the received data size of the last cellular packet data connection.
+ * @param[in] connection The handle to the connection
+ * @param[out] 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_total_sent_data_size (connection_h handle, int * total_sent_data_size);
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_last_received_data_size(connection_h connection, int* size);
-/*****************************************************************************************/
/**
- * @brief Indicates connection status.
- *
- * @return Return @c true if connection is connected, otherwise @c false
- *
- *
-******************************************************************************************/
-bool connection_is_connected(void);
+ * @brief Gets the sent data size of the last cellular packet data connection.
+ * @param[in] connection The handle to the connection
+ * @param[out] 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
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_last_sent_data_size(connection_h connection, int* size);
-/*****************************************************************************************/
/**
- * @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 )
+ * @brief Gets the total received data size of all cellular packet data connections.
+ * @param[in] connection The handle to the connection
+ * @param[out] 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_wifi_last_datacall_duration(connection_h handle, int *wifi_last_datacall_duration);
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_total_received_data_size (connection_h connection, int* size);
-/*****************************************************************************************/
/**
- * @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 )
+ * @brief Gets the total sent data size of all cellular packet data connections.
+ * @param[in] connection The handle to the connection
+ * @param[out] 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_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);
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_total_sent_data_size (connection_h connection, int* 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.
+ * @brief Gets the received data size of the last Wi-Fi packet data connection.
+ * @param[in] connection The handle to the connection
+ * @param[out] size The received data size of the last Wi-Fi packet data connection ( bytes )
* @return 0 on success, otherwise negative error value.
- * @retval #CONNECTION_ERROR_NONE Successful
+ * @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);
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_wifi_last_received_data_size(connection_h connection, int* 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 )
+ * @brief Gets the sent data size of the last Wi-Fi packet data connection.
+ * @param[in] connection The handle to the connection
+ * @param[out] size The sent data size of the last Wi-Fi 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_total_datacall_duration(connection_h handle, int * wifi_total_datacall_duration);
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_wifi_last_sent_data_size(connection_h connection, int* size);
-/*****************************************************************************************/
/**
- * @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)
+ * @brief Gets the total received data size of all Wi-Fi packet data connections.
+ * @param[in] connection The handle to the connection
+ * @param[out] size The total received data size of all Wi-Fi packet data connections (bytes)
* @return 0 on success, otherwise negative error value.
- * @retval #CONNECTION_ERROR_NONE Successful
+ * @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);
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_wifi_total_received_data_size (connection_h connection, int* 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)
+ * @brief Gets the total sent data size of all Wi-Fi packet data connections.
+ * @param[in] connection The handle to the connection
+ * @param[out] size The total sent data size of all Wi-Fi 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);
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error
+ */
+int connection_get_wifi_total_sent_data_size (connection_h connection, int* size);
+
/**
* @}
-*/
-/**
- * @}
*/
diff --git a/include/net_connection_private.h b/include/net_connection_private.h
index cc8825f..b74d6a1 100644
--- a/include/net_connection_private.h
+++ b/include/net_connection_private.h
@@ -27,10 +27,13 @@ extern "C" {
typedef struct _connection_handle_s
{
- connection_cb callback;
- void *user_data;
-}connection_handle_s;
-
+ connection_network_state_changed_cb state_changed_callback;
+ connection_address_changed_cb ip_changed_callback;
+ connection_address_changed_cb proxy_changed_callback;
+ void *state_changed_user_data;
+ void *ip_changed_user_data;
+ void *proxy_changed_user_data;
+} connection_handle_s;
/**
* @internal
@@ -38,194 +41,15 @@ typedef struct _connection_handle_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 unsuccessfully.
- * @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 unsuccessfully.
- * @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);
-
+} stat_request_e;
#ifdef __cplusplus
}
diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec
index f31e896..f26a06a 100644
--- a/packaging/capi-network-connection.spec
+++ b/packaging/capi-network-connection.spec
@@ -1,28 +1,30 @@
+#sbs-git:api/connection
+
Name: capi-network-connection
Summary: Network Connection library in TIZEN C API
Version: 0.1.0
-Release: 1
-Group: TO_BE/FILLED_IN
-License: Apache-2.0
+Release: 19
+Group: System/Network
+License: Apache License Version 2.0
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(capi-base-common)
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%description
-
+Network Connection library in Tizen C API
%package devel
-Summary: Network Connection library in TIZEN C API (Development)
+Summary: Network Connection library in Tizen C API (Development)
Group: TO_BE/FILLED_IN
Requires: %{name} = %{version}-%{release}
%description devel
-
+Network Connection library in Tizen C API (Development)
%prep
@@ -30,9 +32,8 @@ Requires: %{name} = %{version}-%{release}
%build
-FULLVER=%{version}
-MAJORVER=`echo ${FULLVER} | cut -d '.' -f 1`
-cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER}
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
make %{?jobs:-j%jobs}
@@ -47,10 +48,9 @@ rm -rf %{buildroot}
%files
-%{_libdir}/libcapi-network-connection.so*
+%{_libdir}/libcapi-network-connection.so.*
%files devel
%{_includedir}/network/*.h
%{_libdir}/pkgconfig/*.pc
-
-
+%{_libdir}/libcapi-network-connection.so \ No newline at end of file
diff --git a/src/connection.c b/src/connection.c
index 4ab566f..c18a1bd 100755
--- a/src/connection.c
+++ b/src/connection.c
@@ -14,398 +14,575 @@
* 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>
+#include <string.h>
+#include <dlog.h>
+#include <glib.h>
+#include <vconf/vconf.h>
+#include <net_connection_private.h>
+
+#define TIZEN_NET_CONNECTION "CAPI_NETWORK_CONNECTION"
-#define TIZEN_N_CONNECTION "CAPI_NETWORK_CONNECTION"
+static GSList *conn_handle_list = NULL;
-static void __connection_cb_net_config_change_cb(keynode_t *node, void *user_data);
+static void __connection_cb_state_change_cb(keynode_t *node, void *user_data);
+static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data);
+static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data);
-// API to convert error codes back and forth
-static int __convert_error_code(int dnet_error_code)
+
+static int __connection_convert_net_state(int status)
{
- 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;
+ switch (status) {
+ case VCONFKEY_NETWORK_CELLULAR:
+ return CONNECTION_NETWORK_STATE_CELLULAR;
+ case VCONFKEY_NETWORK_WIFI:
+ return CONNECTION_NETWORK_STATE_WIFI;
+ default:
+ return CONNECTION_NETWORK_STATE_DISCONNECTED;
}
}
-static int __connection_set_callbacks(connection_h handle, void *callback, void *user_data)
+static int __connection_convert_cellular_state(int status)
{
- 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);
+ switch (status) {
+ case VCONFKEY_NETWORK_CELLULAR_ON:
+ return CONNECTION_CELLULAR_STATE_AVAILABLE;
+ case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF:
+ return CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE;
+ case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF:
+ return CONNECTION_CELLULAR_STATE_ROAMING_OFF;
+ case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE:
+ return CONNECTION_CELLULAR_STATE_FLIGHT_MODE;
+ default:
+ return CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
}
- else
- {
- return (CONNECTION_ERROR_INVALID_PARAMETER);
+}
+
+static int __connection_convert_wifi_state(int status)
+{
+ switch (status) {
+ case VCONFKEY_NETWORK_WIFI_CONNECTED:
+ return CONNECTION_WIFI_STATE_CONNECTED;
+ case VCONFKEY_NETWORK_WIFI_NOT_CONNECTED:
+ return CONNECTION_WIFI_STATE_DISCONNECTED;
+ default:
+ return CONNECTION_WIFI_STATE_DEACTIVATED;
}
}
-int connection_set_cb(connection_h handle, connection_cb callback, void *user_data)
+static int __connection_get_state_changed_callback_count(void)
{
- int retval = CONNECTION_ERROR_NONE;
+ GSList *list;
+ int count = 0;
- retval = __connection_set_callbacks(handle, callback, user_data);
+ for (list = conn_handle_list; list; list = list->next) {
+ connection_handle_s *local_handle = (connection_handle_s *)list->data;
+ if (local_handle->state_changed_callback) count++;
+ }
- return __convert_error_code(retval);
+ return count;
}
-int connection_unset_cb(connection_h handle)
+static int __connection_get_ip_changed_callback_count(void)
{
- int retval = CONNECTION_ERROR_NONE;
+ GSList *list;
+ int count = 0;
- retval = __connection_set_callbacks(handle, NULL, NULL);
+ for (list = conn_handle_list; list; list = list->next) {
+ connection_handle_s *local_handle = (connection_handle_s *)list->data;
+ if (local_handle->ip_changed_callback) count++;
+ }
- return __convert_error_code(retval);
+ return count;
}
-static void __connection_cb_net_config_change_cb(keynode_t *node, void *user_data)
+static int __connection_get_proxy_changed_callback_count(void)
{
- 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);
- }
+ GSList *list;
+ int count = 0;
+
+ for (list = conn_handle_list; list; list = list->next) {
+ connection_handle_s *local_handle = (connection_handle_s *)list->data;
+ if (local_handle->proxy_changed_callback) count++;
}
+
+ return count;
}
-int connection_create(connection_h *handle)
+static int __connection_set_state_changed_callback(connection_h connection, void *callback, void *user_data)
{
- if(handle==NULL)
- {
- LOGI(TIZEN_N_CONNECTION,"Wrong Parameter Passed\n");
- return CONNECTION_ERROR_INVALID_PARAMETER;
+ connection_handle_s *local_handle = (connection_handle_s *)connection;
+
+ if (callback) {
+ if (__connection_get_state_changed_callback_count() == 0)
+ vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS ,
+ __connection_cb_state_change_cb,
+ NULL);
+
+ local_handle->state_changed_user_data = user_data;
+ } else {
+ if (local_handle->state_changed_callback &&
+ __connection_get_state_changed_callback_count() == 1)
+ vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS,
+ __connection_cb_state_change_cb);
+ }
+
+ local_handle->state_changed_callback = callback;
+ return CONNECTION_ERROR_NONE;
+}
+
+static int __connection_set_ip_changed_callback(connection_h connection, void *callback, void *user_data)
+{
+ connection_handle_s *local_handle = (connection_handle_s *)connection;
+
+ if (callback) {
+ if (__connection_get_ip_changed_callback_count() == 0)
+ vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
+ __connection_cb_ip_change_cb,
+ NULL);
+
+ local_handle->ip_changed_user_data = user_data;
+ } else {
+ if (local_handle->ip_changed_callback &&
+ __connection_get_ip_changed_callback_count() == 1)
+ vconf_ignore_key_changed(VCONFKEY_NETWORK_IP,
+ __connection_cb_ip_change_cb);
+ }
+
+ local_handle->ip_changed_callback = callback;
+ return CONNECTION_ERROR_NONE;
+}
+
+static int __connection_set_proxy_changed_callback(connection_h connection, void *callback, void *user_data)
+{
+ connection_handle_s *local_handle = (connection_handle_s *)connection;
+
+ if (callback) {
+ if (__connection_get_proxy_changed_callback_count() == 0)
+ vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY,
+ __connection_cb_proxy_change_cb,
+ NULL);
+
+ local_handle->proxy_changed_callback = user_data;
+ } else {
+ if (local_handle->proxy_changed_callback &&
+ __connection_get_proxy_changed_callback_count() == 1)
+ vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY,
+ __connection_cb_proxy_change_cb);
+ }
+
+ local_handle->proxy_changed_callback = callback;
+ return CONNECTION_ERROR_NONE;
+}
+
+static void __connection_cb_state_change_cb(keynode_t *node, void *user_data)
+{
+ LOGI(TIZEN_NET_CONNECTION,"Net Status Changed Indication\n");
+
+ GSList *list;
+ int state = vconf_keynode_get_int(node);
+
+ for (list = conn_handle_list; list; list = list->next) {
+ connection_handle_s *local_handle = (connection_handle_s *)list->data;
+ if (local_handle->state_changed_callback)
+ local_handle->state_changed_callback(
+ __connection_convert_net_state(state),
+ local_handle->state_changed_user_data);
+ }
+}
+
+static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data)
+{
+ LOGI(TIZEN_NET_CONNECTION,"Net IP Changed Indication\n");
+
+ GSList *list;
+ char *ip_addr = vconf_keynode_get_str(node);
+
+ for (list = conn_handle_list; list; list = list->next) {
+ connection_handle_s *local_handle = (connection_handle_s *)list->data;
+ if (local_handle->ip_changed_callback)
+ local_handle->ip_changed_callback(
+ ip_addr, NULL,
+ local_handle->ip_changed_user_data);
}
- *handle = calloc(1, sizeof(connection_handle_s));
- if(*handle!=NULL)
- {
- LOGI(TIZEN_N_CONNECTION,"New Handle Created %p\n", *handle);
+}
+
+static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data)
+{
+ LOGI(TIZEN_NET_CONNECTION,"Net IP Changed Indication\n");
+
+ GSList *list;
+ char *proxy = vconf_keynode_get_str(node);
+
+ for (list = conn_handle_list; list; list = list->next) {
+ connection_handle_s *local_handle = (connection_handle_s *)list->data;
+ if (local_handle->proxy_changed_callback)
+ local_handle->proxy_changed_callback(
+ proxy, NULL,
+ local_handle->proxy_changed_user_data);
}
- else
- {
+}
+
+static bool __connection_check_handle_validity(connection_h connection)
+{
+ GSList *list;
+
+ for (list = conn_handle_list; list; list = list->next)
+ if (connection == list->data) return true;
+
+ return false;
+}
+
+int connection_create(connection_h* connection)
+{
+ if (connection == NULL || __connection_check_handle_validity(*connection)) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ *connection = g_try_malloc0(sizeof(connection_handle_s));
+ if (*connection != NULL) {
+ LOGI(TIZEN_NET_CONNECTION, "New Handle Created %p\n", *connection);
+ } else {
return CONNECTION_ERROR_OUT_OF_MEMORY;
}
- return (CONNECTION_ERROR_NONE);
+
+ conn_handle_list = g_slist_append(conn_handle_list, *connection);
+
+ return CONNECTION_ERROR_NONE;
}
-int connection_destroy(connection_h handle)
+int connection_destroy(connection_h connection)
{
- if(handle==NULL)
- {
- LOGI(TIZEN_N_CONNECTION,"Wrong Parameter Passed\n");
+ if (connection == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
return CONNECTION_ERROR_INVALID_PARAMETER;
}
- LOGI(TIZEN_N_CONNECTION,"Destroy Handle : %p\n", handle);
- free(handle);
+ conn_handle_list = g_slist_remove(conn_handle_list, connection);
+
+ LOGI(TIZEN_NET_CONNECTION, "Destroy Handle : %p\n", connection);
+
+ __connection_set_state_changed_callback(connection, NULL, NULL);
+ __connection_set_ip_changed_callback(connection, NULL, NULL);
+ __connection_set_proxy_changed_callback(connection, NULL, NULL);
+
+ g_free(connection);
return CONNECTION_ERROR_NONE;
}
-int connection_get_network_status(connection_network_type_e network_type,
- connection_network_status_e* network_status)
+int connection_get_network_state(connection_h connection, connection_network_state_e* state)
{
+ int status = 0;
- if (network_status==NULL ||
- network_type > CONNECTION_WIFI_TYPE ||
- network_type < CONNECTION_DEFAULT_TYPE)
- {
+ if (state == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
return CONNECTION_ERROR_INVALID_PARAMETER;
}
- int status = 0;
+ if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) {
+ LOGI(TIZEN_NET_CONNECTION,"vconf_get_int Failed = %d\n", status);
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+
+ LOGI(TIZEN_NET_CONNECTION,"Connected Network = %d\n", status);
- if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status))
- {
- LOGI(TIZEN_N_CONNECTION,"First Step Failure = %d\n", status);
+ *state = __connection_convert_net_state(status);
+
+ return CONNECTION_ERROR_NONE;
+}
+
+int connection_get_ip_address(connection_h connection, connection_address_family_e address_family, char** ip_address)
+{
+ if (ip_address == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ switch (address_family) {
+ case CONNECTION_ADDRESS_FAMILY_IPV4:
+ *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
+ break;
+ case CONNECTION_ADDRESS_FAMILY_IPV6:
+ LOGI(TIZEN_NET_CONNECTION, "Not supported yet\n");
+ return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
+ break;
+ default:
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (*ip_address == NULL) {
+ LOGI(TIZEN_NET_CONNECTION,"vconf_get_str Failed\n");
return CONNECTION_ERROR_INVALID_OPERATION;
}
- LOGI(TIZEN_N_CONNECTION,"Connected Network = %d\n", status);
-
- if (network_type==CONNECTION_DEFAULT_TYPE)
- {
- switch(status)
- {
- case VCONFKEY_NETWORK_CELLULAR:
- case VCONFKEY_NETWORK_WIFI:
- *network_status = CONNECTION_STATUS_AVAILABLE;
- break;
- default :
- *network_status = CONNECTION_STATUS_UNAVAILABLE;
- break;
- }
- return CONNECTION_ERROR_NONE;
+ LOGI(TIZEN_NET_CONNECTION,"IP Address %s\n", *ip_address);
+
+ return CONNECTION_ERROR_NONE;
+}
+
+int connection_get_proxy(connection_h connection, connection_address_family_e address_family, char** proxy)
+{
+ if (proxy == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
}
- 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_ON)
- {
- *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;
- }
+ switch (address_family) {
+ case CONNECTION_ADDRESS_FAMILY_IPV4:
+ *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
+ break;
+ case CONNECTION_ADDRESS_FAMILY_IPV6:
+ LOGI(TIZEN_NET_CONNECTION, "Not supported yet\n");
+ return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
+ break;
+ default:
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
}
- 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_CONNECTED)
- {
- *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;
- }
+ if (*proxy == NULL) {
+ LOGI(TIZEN_NET_CONNECTION,"vconf_get_str Failed\n");
+ return CONNECTION_ERROR_INVALID_OPERATION;
}
- return CONNECTION_ERROR_INVALID_PARAMETER;
+
+ LOGI(TIZEN_NET_CONNECTION,"Proxy Address %s\n", *proxy);
+
+ return CONNECTION_ERROR_NONE;
}
-bool connection_is_connected(void)
+int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
{
- int network_status = 0;
- if (!vconf_get_int(VCONFKEY_NETWORK_STATUS, &network_status))
- {
- return (network_status > VCONFKEY_NETWORK_OFF) ? true : false;
+ int status = 0;
+
+ if (state == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status)) {
+ LOGI(TIZEN_NET_CONNECTION,"Cellular = %d\n", status);
+ *state = __connection_convert_cellular_state(status);
+ return CONNECTION_ERROR_NONE;
+ } else {
+ LOGI(TIZEN_NET_CONNECTION,"vconf_get_int Failed = %d\n", status);
+ return CONNECTION_ERROR_INVALID_OPERATION;
}
- else
- return false;
}
-int connection_get_ip_address(connection_h handle, char **ip_address)
+int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state)
{
- if(handle)
- {
- *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
- LOGI(TIZEN_N_CONNECTION,"IP Address %s\n", *ip_address);
+ int status = 0;
+
+ if (state == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &status)) {
+ LOGI(TIZEN_NET_CONNECTION,"WiFi = %d\n", status);
+ *state = __connection_convert_wifi_state(status);
return CONNECTION_ERROR_NONE;
+ } else {
+ LOGI(TIZEN_NET_CONNECTION,"vconf_get_int Failed = %d\n", status);
+ return CONNECTION_ERROR_INVALID_OPERATION;
}
- return (CONNECTION_ERROR_INVALID_PARAMETER);
}
-int connection_get_proxy(connection_h handle, char **proxy)
+int connection_set_network_state_changed_cb(connection_h connection,
+ connection_network_state_changed_cb callback, void* user_data)
{
- 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);
-}
-
-static 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);
+ if (callback == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
}
- return (CONNECTION_ERROR_INVALID_PARAMETER);
+
+ return __connection_set_state_changed_callback(connection, callback, user_data);
}
-int connection_get_last_datacall_duration(connection_h handle, int *value)
+int connection_unset_network_state_changed_cb(connection_h connection)
{
- return __fill_call_statistic(handle, LAST_DATACALL_DURATION, value);
+ if (!(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ return __connection_set_state_changed_callback(connection, NULL, NULL);
+}
+
+int connection_set_ip_address_changed_cb(connection_h connection,
+ connection_address_changed_cb callback, void* user_data)
+{
+ if (callback == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ return __connection_set_ip_changed_callback(connection, callback, user_data);
+}
+
+int connection_unset_ip_address_changed_cb(connection_h connection)
+{
+ if (!(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ return __connection_set_ip_changed_callback(connection, NULL, NULL);
}
-int connection_get_last_received_data_size(connection_h handle, int *value)
+int connection_set_proxy_address_changed_cb(connection_h connection,
+ connection_address_changed_cb callback, void* user_data)
{
- return __fill_call_statistic(handle, LAST_RECEIVED_DATA_SIZE, value);
+ if (callback == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ return __connection_set_proxy_changed_callback(connection, callback, user_data);
}
-int connection_get_last_sent_data_size(connection_h handle, int *value)
+int connection_unset_proxy_address_changed_cb(connection_h connection)
{
- return __fill_call_statistic(handle, LAST_SENT_DATA_SIZE, value);
+ if (!(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ return __connection_set_proxy_changed_callback(connection, NULL, NULL);
}
-int connection_get_total_datacall_duration(connection_h handle, int *value)
+static int __fill_call_statistic(connection_h connection, stat_request_e member, int *size)
{
- return __fill_call_statistic(handle, TOTAL_DATACALL_DURATION, value);
+ if (size == NULL || !(__connection_check_handle_validity(connection))) {
+ LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ switch (member) {
+ case LAST_SENT_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get LAST_SENT_DATA_SIZE = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"LAST_SENT_DATA_SIZE:%d bytes\n", *size);
+
+ break;
+ case LAST_RECEIVED_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get LAST_RECEIVED_DATA_SIZE: = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"LAST_RECEIVED_DATA_SIZE:%d bytes\n", *size);
+ break;
+ case TOTAL_SENT_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get TOTAL_SENT_DATA_SIZE: = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"TOTAL_SENT_DATA_SIZE:%d bytes\n", *size);
+ break;
+ case TOTAL_RECEIVED_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get TOTAL_RECEIVED_DATA_SIZE: = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"TOTAL_RECEIVED_DATA_SIZE:%d bytes\n", *size);
+ break;
+ case LAST_WIFI_SENT_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get LAST_WIFI_SENT_DATA_SIZE: = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"LAST_WIFI_SENT_DATA_SIZE:%d bytes\n", *size);
+ break;
+ case LAST_WIFI_RECEIVED_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get LAST_WIFI_RECEIVED_DATA_SIZE: = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"LAST_WIFI_RECEIVED_DATA_SIZE:%d bytes\n", *size);
+ break;
+ case TOTAL_WIFI_SENT_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get TOTAL_WIFI_SENT_DATA_SIZE: = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"TOTAL_WIFI_SENT_DATA_SIZE:%d bytes\n", *size);
+ break;
+ case TOTAL_WIFI_RECEIVED_DATA_SIZE:
+ if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, size)) {
+ LOGI(TIZEN_NET_CONNECTION,
+ "Cannot Get TOTAL_WIFI_RECEIVED_DATA_SIZE: = %d\n",
+ *size);
+ *size = 0;
+ return CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ LOGI(TIZEN_NET_CONNECTION,"TOTAL_WIFI_RECEIVED_DATA_SIZE:%d bytes\n", *size);
+ break;
+ }
+ return CONNECTION_ERROR_NONE;
}
-int connection_get_total_received_data_size (connection_h handle, int *value)
+int connection_get_last_received_data_size(connection_h connection, int *size)
{
- return __fill_call_statistic(handle, TOTAL_RECEIVED_DATA_SIZE, value);
+ return __fill_call_statistic(connection, LAST_RECEIVED_DATA_SIZE, size);
}
-int connection_get_total_sent_data_size (connection_h handle, int *value)
+int connection_get_last_sent_data_size(connection_h connection, int *size)
{
- return __fill_call_statistic(handle, TOTAL_SENT_DATA_SIZE, value);
+ return __fill_call_statistic(connection, LAST_SENT_DATA_SIZE, size);
}
-int connection_get_wifi_last_datacall_duration(connection_h handle, int *value)
+int connection_get_total_received_data_size (connection_h connection, int *size)
{
- return __fill_call_statistic(handle, LAST_WIFI_DATACALL_DURATION, value);
+ return __fill_call_statistic(connection, TOTAL_RECEIVED_DATA_SIZE, size);
}
-int connection_get_wifi_last_received_data_size(connection_h handle, int *value)
+int connection_get_total_sent_data_size (connection_h connection, int *size)
{
- return __fill_call_statistic(handle, LAST_WIFI_RECEIVED_DATA_SIZE, value);
+ return __fill_call_statistic(connection, TOTAL_SENT_DATA_SIZE, size);
}
-int connection_get_wifi_last_sent_data_size(connection_h handle, int *value)
+int connection_get_wifi_last_received_data_size(connection_h connection, int *size)
{
- return __fill_call_statistic(handle, LAST_WIFI_SENT_DATA_SIZE, value);
+ return __fill_call_statistic(connection, LAST_WIFI_RECEIVED_DATA_SIZE, size);
}
-int connection_get_wifi_total_datacall_duration(connection_h handle, int *value)
+int connection_get_wifi_last_sent_data_size(connection_h connection, int *size)
{
- return __fill_call_statistic(handle, TOTAL_WIFI_DATACALL_DURATION, value);
+ return __fill_call_statistic(connection, LAST_WIFI_SENT_DATA_SIZE, size);
}
-int connection_get_wifi_total_received_data_size (connection_h handle, int *value)
+int connection_get_wifi_total_received_data_size (connection_h connection, int *size)
{
- return __fill_call_statistic(handle, TOTAL_WIFI_RECEIVED_DATA_SIZE, value);
+ return __fill_call_statistic(connection, TOTAL_WIFI_RECEIVED_DATA_SIZE, size);
}
-int connection_get_wifi_total_sent_data_size (connection_h handle, int *value)
+int connection_get_wifi_total_sent_data_size (connection_h connection, int *size)
{
- return __fill_call_statistic(handle, TOTAL_WIFI_SENT_DATA_SIZE, value);
+ return __fill_call_statistic(connection, TOTAL_WIFI_SENT_DATA_SIZE, size);
}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 97657b6..7715cac 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -8,9 +8,6 @@ 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)
diff --git a/test/connection_test.c b/test/connection_test.c
index ff6159c..b161573 100644
--- a/test/connection_test.c
+++ b/test/connection_test.c
@@ -35,37 +35,44 @@
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_network_state(void);
+int test_get_cellular_state(void);
+int test_get_wifi_state(void);
int test_get_current_proxy(void);
-int test_get_current_device_info(void);
+int test_get_current_ip(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)
+
+connection_h connection = NULL;
+
+static void test_state_changed_callback(connection_network_state_e state, void* user_data)
{
- char *ptr = NULL;
- connection_get_ip_address(handle, &ptr);
- printf("Param Name : %d IP Address = %s\n", param, ptr);
- free(ptr);
+ printf("State changed callback, state : %d\n", state);
}
-int test_register_client(void){
+static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
+{
+ printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
+ ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
+}
- int err = connection_create(&handle);
+static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
+{
+ printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
+ ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
+}
- if(CONNECTION_ERROR_NONE==err) //set callbacks
- {
- if(handle==NULL)
- printf("Handle is NULL\n");
- connection_set_cb(handle, net_callback, NULL);
- }
- else
- {
+int test_register_client(void)
+{
+
+ int err = connection_create(&connection);
+
+ if (CONNECTION_ERROR_NONE == err) {
+ connection_set_network_state_changed_cb(connection, test_state_changed_callback, NULL);
+ connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
+ connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
+ } else {
printf("Client registration failed %d\n", err);
return -1;
}
@@ -74,11 +81,12 @@ int test_register_client(void){
return 1;
}
-int test_deregister_client(void){
+int test_deregister_client(void)
+{
int rv = 0;
- if(handle!=NULL)
- rv = connection_destroy(handle);
+ if (connection != NULL)
+ rv = connection_destroy(connection);
else
printf("Cannot deregister : Handle is NULL\n");
@@ -91,174 +99,123 @@ int test_deregister_client(void){
return 1;
}
-int test_open_connection(void){
- int rv =0;
+int test_get_network_state(void)
+{
+ int rv = 0;
+ connection_network_state_e net_state;
- //rv = connection_open(handle, CONNECTION_DEFAULT_TYPE);
+ rv = connection_get_network_state(connection, &net_state);
- if (rv != CONNECTION_ERROR_NONE){
- printf("Fail to call open connection [%d]\n", rv);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get network state [%d]\n", rv);
return -1;
}
- printf("open connection api is called [%d]\n", rv);
+ printf("Retval = %d network connection state [%d]\n", rv, net_state);
+
return 1;
}
-int test_close_connection(void){
- int rv =0;
+int test_get_cellular_state(void)
+{
+ int rv = 0;
+ connection_cellular_state_e cellular_state;
- //rv = connection_close(handle);
+ rv = connection_get_cellular_state(connection, &cellular_state);
- if (rv != CONNECTION_ERROR_NONE){
- printf("Fail to call close connection [%d]\n", rv);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get Cellular state [%d]\n", rv);
return -1;
}
- printf("close connection api is called\n");
+ printf("Retval = %d Cellular state [%d]\n", rv, cellular_state);
+
return 1;
}
+int test_get_wifi_state(void)
+{
+ int rv = 0;
+ connection_wifi_state_e wifi_state;
-int test_is_connected(void){
- int rv =0;
-
- rv = connection_is_connected();
+ rv = connection_get_wifi_state(connection, &wifi_state);
- if(rv != 1){
- printf("There is no active connection\n");
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get WiFi state [%d]\n", rv);
return -1;
}
- printf("Connected\n");
- printf("is connected api is called\n");
+ printf("Retval = %d WiFi state [%d]\n", rv, wifi_state);
+
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;
- }
+int test_get_current_proxy(void)
+{
+ char *proxy_addr = NULL;
- rv = connection_get_proxy(handle, &proxy_addr);
+ connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
- if(proxy_addr == NULL){
+ 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");
+ g_free(proxy_addr);
+
return 1;
}
-int test_get_current_device_info(void){
- int rv=0;
- rv = connection_is_connected();
+int test_get_current_ip(void)
+{
+ char *ip_addr = NULL;
+
+ connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
- if(rv != 1){
- printf("There is no active connection\n");
+ if (ip_addr == NULL) {
+ printf("IP address does not exist\n");
return -1;
}
- test_print_device_info();
+ printf("IPv4 address : %s\n", ip_addr);
+ g_free(ip_addr);
- 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);
-
+int test_get_call_statistics_info(void)
+{
+ int rv = 0;
- printf("get call statistics information is called\n");
+ connection_get_last_received_data_size(connection, &rv);
+ printf("last recv data size [%d]\n", rv);
+ connection_get_last_sent_data_size(connection, &rv);
+ printf("last sent data size [%d]\n",rv );
+ connection_get_total_received_data_size (connection, &rv);
+ printf("total received data size [%d]\n",rv );
+ connection_get_total_sent_data_size (connection, &rv);
+ printf("total sent data size [%d]\n", rv);
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);
-
+int test_get_wifi_call_statistics_info(void)
+{
+ int rv = 0;
- printf("get WiFi call statistics information is called\n");
+ connection_get_wifi_last_received_data_size(connection, &rv);
+ printf("WiFi last recv data size [%d]\n", rv);
+ connection_get_wifi_last_sent_data_size(connection, &rv);
+ printf("WiFi last sent data size [%d]\n",rv );
+ connection_get_wifi_total_received_data_size (connection, &rv);
+ printf("WiFi total received data size [%d]\n",rv );
+ connection_get_wifi_total_sent_data_size (connection, &rv);
+ printf("WiFi total sent data size [%d]\n", rv);
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;
@@ -269,8 +226,6 @@ int main(int argc, char **argv){
printf("Test Thread created...\n");
- test_register_client();
-
g_main_loop_run (mainloop);
return 0;
@@ -278,64 +233,61 @@ int main(int argc, char **argv){
gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
{
- int rv=0;
+ int rv = 0;
char a[100];
memset(a, '\0', 100);
- printf("Event received from stdin \n");
+ 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("\n\n Network Connection API 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("1 - Create Handle and set callbacks\n");
+ printf("2 - Destroy Handle(unset callbacks automatically)\n");
+ printf("3 - Get network state\n");
+ printf("4 - Get cellular state (please insert SIM Card)\n");
+ printf("5 - Get wifi state (please turn on WiFi)\n");
+ printf("6 - Get current proxy address \n");
+ printf("7 - Get current Ip address\n");
+ printf("8 - Get cellular data call statistics\n");
+ printf("9 - Get WiFi data call statistics\n");
printf("0 - Exit \n");
printf("ENTER - Show options menu.......\n");
}
- switch (a[0])
- {
- case '1':{
+ switch (a[0]) {
+ case '1': {
rv = test_register_client();
- }break;
- case '2':{
+ } break;
+ case '2': {
rv = test_deregister_client();
- }break;
- case '3':{
+ } break;
+ case '3': {
+ rv = test_get_network_state();
+ } break;
+ case '4': {
+ rv = test_get_cellular_state();
+ } break;
+ case '5': {
+ rv = test_get_wifi_state();
+ } break;
+ case '6': {
rv = test_get_current_proxy();
- }break;
- case '4':{
- rv = test_is_connected();
- }break;
- case '5':{
- rv = test_get_current_device_info();
- }break;
- case '6':{
+ } break;
+ case '7': {
+ rv = test_get_current_ip();
+ } break;
+ case '8': {
rv = test_get_call_statistics_info();
- }break;
- case '7':{
+ } break;
+ case '9': {
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;
+ } break;
}
return TRUE;
}
diff --git a/test/connection_test_regress.c b/test/connection_test_regress.c
deleted file mode 100644
index a735542..0000000
--- a/test/connection_test_regress.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * 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
deleted file mode 100644
index cf88172..0000000
--- a/test/examples/getting-connection-setting-example.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *
- * 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
deleted file mode 100644
index 63b6ce2..0000000
--- a/test/examples/openconnection-example.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- *
- * 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
- }
- }
-}
-