Replacing libnet-client API's with Connection CAPI's 35/206235/5 accepted/tizen/unified/20190708.052543 submit/tizen/20190703.065107
authorAvichal <avichal.a@samsung.com>
Wed, 15 May 2019 09:41:44 +0000 (15:11 +0530)
committerAvichal <avichal.a@samsung.com>
Tue, 2 Jul 2019 08:53:21 +0000 (14:23 +0530)
Change-Id: Icb357a9e12ef3c426b6facc36ed24052689d6cdc
Signed-off-by: Avichal <avichal.a@samsung.com>
CMakeLists.txt
lbs-server/src/data_connection.c
packaging/lbs-server.spec

index 4a2250e..ad6dab5 100644 (file)
@@ -8,7 +8,7 @@ SET(BIN_DIR "${PREFIX}/bin")
 
 #Dependencies
 SET(common_dp "glib-2.0 lbs-dbus dlog gio-2.0 lbs-location")
-SET(server_dp "${common_dp} network tapi vconf vconf-internal-keys gthread-2.0  gio-unix-2.0 capi-network-wifi-manager capi-system-info libtzplatform-config")
+SET(server_dp "${common_dp} tapi vconf vconf-internal-keys gthread-2.0  gio-unix-2.0 capi-network-connection capi-network-wifi-manager capi-system-info libtzplatform-config")
 SET(module_dp "${common_dp} gmodule-2.0")
 
 # Set required packages
index fcc6819..fa18724 100644 (file)
@@ -35,8 +35,8 @@
 #include <setjmp.h>
 
 #include "data_connection.h"
-#include <network-cm-intf.h>
 #include "debug_util.h"
+#include <net_connection.h>
 
 int noti_resp_init(int *noti_pipe_fds);
 int noti_resp_wait(int *noti_pipe_fds);
@@ -46,6 +46,8 @@ int noti_resp_deinit(int *noti_pipe_fds);
 
 unsigned int g_ipaddr;
 static int pdp_pipe_fds[2];
+static connection_h g_con = NULL;
+static connection_profile_h g_profile;
 
 typedef enum {
        DEACTIVATED,
@@ -54,8 +56,6 @@ typedef enum {
        DEACTIVATING
 } pdp_status;
 
-char profile_name[NET_PROFILE_NAME_LEN_MAX + 1];
-
 pdp_status act_level;
 
 char *PdpStat[] = { "Deactivated", "Activating", "Activated", "Deactivating" };
@@ -73,80 +73,34 @@ static pdp_status get_connection_status()
 
 static void pdp_proxy_conf()
 {
-       net_proxy_t proxy;
-       int ret;
-       ret = net_get_active_proxy(&proxy);
+       int ret = CONNECTION_ERROR_NOT_SUPPORTED;
+       char *address = NULL;
 
-       if (ret == NET_ERR_NONE) {
-               if (strncmp(proxy.proxy_addr, "0.0.0.0", 7)) {
+       ret = connection_get_proxy(g_con, CONNECTION_ADDRESS_FAMILY_IPV4, &address);
+       if (ret == CONNECTION_ERROR_NONE) {
+               if (strncmp(address, "0.0.0.0", 7)) {
                        char buf[100];
-                       snprintf(buf, sizeof(buf), "http://%s/", proxy.proxy_addr);
+                       snprintf(buf, sizeof(buf), "http://%s/", address);
                        setenv("http_proxy", buf, 1);
                } else {
                        unsetenv("http_proxy");
                }
-       } else {
-               LOG_GPS(DBG_ERR, "Fail to get proxy\n");
        }
+
 }
 
-void pdp_evt_cb(net_event_info_t *event_cb, void *user_data)
+void pdp_evt_cb(connection_error_e result, void* user_data)
 {
-       switch (event_cb->Event) {
-       case NET_EVENT_OPEN_RSP: {
-               LOG_GPS(DBG_LOW, "event_cb->Error : [%d]\n", event_cb->Error);
-               if (get_connection_status() != ACTIVATING) {
-                       LOG_GPS(DBG_LOW, "Not Activating status\n");
-               } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) {
-                       LOG_GPS(DBG_LOW, "Successful PDP Activation\n");
-                       net_profile_info_t *prof_info = NULL;
-                       net_dev_info_t *net_info = NULL;
-
-                       prof_info = (net_profile_info_t *) event_cb->Data;
-                       net_info = &(prof_info->ProfileInfo.Pdp.net_info);
-
-                       strncpy(profile_name, net_info->ProfileName, NET_PROFILE_NAME_LEN_MAX);
-
-                       set_connection_status(ACTIVATED);
-                       pdp_proxy_conf();
-                       noti_resp_noti(pdp_pipe_fds, TRUE);
-               } else {
-                       LOG_GPS(DBG_ERR, " PDP Activation Failed - PDP Error[%d]\n", event_cb->Error);
-                       set_connection_status(DEACTIVATED);
-                       noti_resp_noti(pdp_pipe_fds, FALSE);
-               }
-       }
-       break;
-
-       case NET_EVENT_CLOSE_RSP:
-               if (get_connection_status() != ACTIVATED && get_connection_status() != DEACTIVATING) {
-                       LOG_GPS(DBG_ERR, "Not Activated && Deactivating status\n");
-               } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_UNKNOWN) {
-                       LOG_GPS(DBG_LOW, "Successful PDP De-Activation\n");
-                       set_connection_status(DEACTIVATED);
-                       noti_resp_noti(pdp_pipe_fds, TRUE);
-               } else {
-                       LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", event_cb->Error);
-                       noti_resp_noti(pdp_pipe_fds, FALSE);
-               }
-               break;
-
-       case NET_EVENT_CLOSE_IND:
-               if (get_connection_status() != ACTIVATED && get_connection_status() != DEACTIVATING) {
-                       LOG_GPS(DBG_ERR, "Not Activated && Deactivating status\n");
-               } else if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_UNKNOWN) {
-                       LOG_GPS(DBG_LOW, "Successful PDP De-Activation\n");
+       if (result == CONNECTION_ERROR_NONE) {
+               LOG_GPS(DBG_LOW, "Connected");
+               LOG_GPS(DBG_LOW, "Successful PDP Activation\n");
+               set_connection_status(ACTIVATED);
+               pdp_proxy_conf();
+               noti_resp_noti(pdp_pipe_fds, TRUE);
+       } else {
+                       LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", result);
                        set_connection_status(DEACTIVATED);
-                       noti_resp_noti(pdp_pipe_fds, TRUE);
-               } else {
-                       LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", event_cb->Error);
                        noti_resp_noti(pdp_pipe_fds, FALSE);
-               }
-               break;
-       case NET_EVENT_OPEN_IND:
-               break;
-       default:
-               break;
        }
 }
 
@@ -162,26 +116,54 @@ unsigned int start_pdp_connection(void)
                return FALSE;
        }
 
-       err = net_register_client((net_event_cb_t) pdp_evt_cb, NULL);
+       err = connection_create(&g_con);
 
-       if (err == NET_ERR_NONE || err == NET_ERR_APP_ALREADY_REGISTERED) {
+       if (err == CONNECTION_ERROR_NONE ) {
                LOG_GPS(DBG_LOW, "Client registration is succeed\n");
        } else {
                LOG_GPS(DBG_WARN, "Error in net_register_client [%d]\n", err);
+               return FALSE;
+       }
+
+
+       if (noti_resp_wait(pdp_pipe_fds) > 0) {
+                       if (noti_resp_check(pdp_pipe_fds)) {
+                               LOG_GPS(DBG_LOW, "PDP Activation Successful\n");
+
+                       } else {
+                               LOG_GPS(DBG_ERR, "PDP failed\n");
+                               noti_resp_deinit(pdp_pipe_fds);
+                               err = connection_destroy(g_con);
+                               if (err == CONNECTION_ERROR_NONE)
+                                       LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
+                               else
+                                       LOG_GPS(DBG_ERR, "Error deregistering the client\n");
+
+                               return FALSE;
+                       }
+       } else {
+               LOG_GPS(DBG_ERR, "NO Pdp Act Response or Some error in select.\n");
                noti_resp_deinit(pdp_pipe_fds);
+
+               err = connection_destroy(g_con);
+               if (err == CONNECTION_ERROR_NONE)
+                       LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
+               else
+                       LOG_GPS(DBG_ERR, "Error deregistering the client\n");
+
                return FALSE;
        }
 
-       set_connection_status(ACTIVATING);
-       err = net_open_connection_with_preference(NET_SERVICE_INTERNET);
 
-       if (err == NET_ERR_NONE) {
+       err = connection_get_default_cellular_service_profile(g_con,CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET,&g_profile);
+
+       if (err == CONNECTION_ERROR_NONE) {
                LOG_GPS(DBG_LOW, "Sent PDP Activation.\n");
        } else {
                LOG_GPS(DBG_WARN, "Error in net_open_connection_with_preference() [%d]\n", err);
                set_connection_status(DEACTIVATED);
-               err = net_deregister_client();
-               if (err == NET_ERR_NONE)
+               err = connection_destroy(g_con);
+               if (err == CONNECTION_ERROR_NONE)
                        LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
                else
                        LOG_GPS(DBG_ERR, "Error deregistering the client\n");
@@ -190,35 +172,58 @@ unsigned int start_pdp_connection(void)
                return FALSE;
        }
 
-       if (noti_resp_wait(pdp_pipe_fds) > 0) {
-               if (noti_resp_check(pdp_pipe_fds)) {
-                       LOG_GPS(DBG_LOW, "PDP Activation Successful\n");
-                       noti_resp_deinit(pdp_pipe_fds);
-                       return TRUE;
-               } else {
-                       LOG_GPS(DBG_ERR, "PDP failed\n");
-                       noti_resp_deinit(pdp_pipe_fds);
+       err = connection_open_profile(g_con,g_profile, pdp_evt_cb, NULL);
 
-                       err = net_deregister_client();
-                       if (err == NET_ERR_NONE)
-                               LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
-                       else
-                               LOG_GPS(DBG_ERR, "Error deregistering the client\n");
-
-                       return FALSE;
-               }
+       if (err == CONNECTION_ERROR_NONE) {
+               set_connection_status(ACTIVATING);
+               LOG_GPS(DBG_LOW, "Sent PDP Activation.\n");
+               return TRUE;
        } else {
-               LOG_GPS(DBG_ERR, "NO Pdp Act Response or Some error in select.\n");
-               noti_resp_deinit(pdp_pipe_fds);
-
-               err = net_deregister_client();
-               if (err == NET_ERR_NONE)
+               LOG_GPS(DBG_WARN, "Error in net_open_connection_with_preference() [%d]\n", err);
+               set_connection_status(DEACTIVATED);
+               err = connection_destroy(g_con);
+               if (err == CONNECTION_ERROR_NONE)
                        LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
                else
                        LOG_GPS(DBG_ERR, "Error deregistering the client\n");
 
+               noti_resp_deinit(pdp_pipe_fds);
                return FALSE;
        }
+
+
+}
+void connectio_close_cb(connection_error_e result, void* user_data)
+{
+       if (result == CONNECTION_ERROR_NONE) {
+               LOG_GPS(DBG_LOW, "DisConnected");
+               LOG_GPS(DBG_LOW, "Successful PDP Diactivation\n");
+               set_connection_status(DEACTIVATED);
+               pdp_proxy_conf();
+               noti_resp_noti(pdp_pipe_fds, TRUE);
+               if (noti_resp_wait(pdp_pipe_fds) > 0) {
+                       if (noti_resp_check(pdp_pipe_fds))
+                               LOG_GPS(DBG_LOW, "Close Connection success\n");
+                       else
+                               LOG_GPS(DBG_ERR, "Close connection failed\n");
+               }
+
+               noti_resp_deinit(pdp_pipe_fds);
+
+               set_connection_status(DEACTIVATED);
+
+               result = connection_destroy(g_con);
+               if (result == CONNECTION_ERROR_NONE) {
+                       LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
+               } else {
+                       LOG_GPS(DBG_WARN, "Error deregistering the client\n");
+
+               }
+       } else {
+                       LOG_GPS(DBG_ERR, " PDP DeActivation Failed - PDP Error[%d]\n", result);
+                       set_connection_status(DEACTIVATED);
+                       noti_resp_noti(pdp_pipe_fds, FALSE);
+       }
 }
 
 unsigned int stop_pdp_connection(void)
@@ -238,8 +243,8 @@ unsigned int stop_pdp_connection(void)
        }
 
        set_connection_status(DEACTIVATING);
-       err = net_close_connection(profile_name);
-       if (err == NET_ERR_NONE) {
+       err = connection_close_profile(g_con,g_profile,connectio_close_cb,NULL);
+       if (err == CONNECTION_ERROR_NONE) {
                LOG_GPS(DBG_LOW, "Success net_close_connection\n");
        } else {
                LOG_GPS(DBG_WARN, "Error in sending net_close_connection error=%d\n", err);
@@ -247,24 +252,7 @@ unsigned int stop_pdp_connection(void)
                noti_resp_deinit(pdp_pipe_fds);
                return FALSE;
        }
-       if (noti_resp_wait(pdp_pipe_fds) > 0) {
-               if (noti_resp_check(pdp_pipe_fds))
-                       LOG_GPS(DBG_LOW, "Close Connection success\n");
-               else
-                       LOG_GPS(DBG_ERR, "Close connection failed\n");
-       }
 
-       noti_resp_deinit(pdp_pipe_fds);
-
-       set_connection_status(DEACTIVATED);
-
-       err = net_deregister_client();
-       if (err == NET_ERR_NONE) {
-               LOG_GPS(DBG_LOW, "Client deregistered successfully\n");
-       } else {
-               LOG_GPS(DBG_WARN, "Error deregistering the client\n");
-               return FALSE;
-       }
 
        return TRUE;
 }
index 3892ac4..66d5c7a 100644 (file)
@@ -11,7 +11,6 @@ Source3: location-lbs-server.manifest
 Source4: lbs-server.asan.conf
 BuildRequires: cmake
 BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(network)
 BuildRequires: pkgconfig(tapi)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(dlog)
@@ -25,6 +24,7 @@ BuildRequires: pkgconfig(vconf-internal-keys)
 BuildRequires: pkgconfig(gthread-2.0)
 BuildRequires: pkgconfig(gmodule-2.0)
 BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(capi-network-connection)
 
 %description
 LBS Server for Tizen