Generate event for user described callback 05/152905/1 accepted/tizen/unified/20170929.081908 submit/tizen/20170928.232941
authorJiung <jiung.yu@samsung.com>
Wed, 27 Sep 2017 10:25:26 +0000 (19:25 +0900)
committerJiung <jiung.yu@samsung.com>
Wed, 27 Sep 2017 10:25:36 +0000 (19:25 +0900)
Change-Id: I31d149196a85b05d2f8553790467dfcb11132c37
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
packaging/capi-network-asp.spec
src/asp-client.c

index e194935..310b5c5 100755 (executable)
@@ -2,7 +2,7 @@
 
 Name:       capi-network-asp
 Summary:    An Application Service Platform(ASP) libraries in Native API
-Version:    0.0.17
+Version:    0.0.18
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index 955a8ef..f1d428f 100644 (file)
@@ -132,6 +132,57 @@ static int __asp_err_string_to_enum(const char *error)
                return ASP_ERROR_OPERATION_FAILED;
 }
 
+static asp_client_advert_s *get_advert_by_id(unsigned int adv_id)
+{
+       asp_client_advert_s *advert = NULL;
+       GList *temp = NULL;
+
+       for (temp = g_list_first(asp_adverts);
+                       temp != NULL; temp = g_list_next(temp)) {
+               advert = temp->data;
+               if (advert != NULL && advert->adv_id == adv_id)
+                       break;
+               advert = NULL;
+       }
+
+       return advert;
+
+}
+
+static asp_client_seek_s *get_seek_by_id(long long unsigned search_id)
+{
+       asp_client_seek_s *seek = NULL;
+       GList *temp = NULL;
+
+       for (temp = g_list_first(asp_seeks);
+                       temp != NULL; temp = g_list_next(temp)) {
+               seek = temp->data;
+               if (seek != NULL && seek->search_id == search_id)
+                       break;
+               seek = NULL;
+       }
+
+       return seek;
+
+}
+
+static asp_client_session_s *get_session_by_id_mac(const char *session_mac, unsigned int session_id)
+{
+       asp_client_session_s *session = NULL;
+       GList *temp = NULL;
+
+       for (temp = g_list_first(asp_sessions);
+               temp != NULL; temp = g_list_next(temp)) {
+               session = temp->data;
+               if (session != NULL && session->session_id == session_id &&
+                               memcmp(session->session_mac, session_mac, MACSTR_LEN) == 0)
+                       break;
+               session = NULL;
+       }
+
+       return session;
+}
+
 static char* __asp_create_service_info_from_g_variant(GVariant *variant)
 {
        GVariantIter *iter = NULL;
@@ -168,6 +219,7 @@ void asp_process_seek_search_result(GDBusConnection *connection,
 
        GVariantIter *iter = NULL;
        GVariant *var = NULL;
+       asp_client_seek_s *seek = NULL;
        const char *key = NULL;
        unsigned int search_id = 0;
        const char *service_mac = NULL;
@@ -175,10 +227,12 @@ void asp_process_seek_search_result(GDBusConnection *connection,
        unsigned int config_method = 0;
        const char *instance_name = NULL;
        char *service_info = NULL;
+       int service_info_len = 0;
        unsigned char status = 0;
+       int error_code = ASP_ERROR_NONE;
 
        if (!client->seek_search_result_cb) {
-               ASP_LOGE("search_result_cb is NULL!!");
+               ASP_LOGD("search_result_cb is NULL!!");
                return;
        }
 
@@ -202,8 +256,10 @@ void asp_process_seek_search_result(GDBusConnection *connection,
                } else if (!g_strcmp0(key, "service_info")) {
                        g_free(service_info);
                        service_info = __asp_create_service_info_from_g_variant(var);
-                       if (service_info)
+                       if (service_info) {
                                ASP_LOGD("Service Info: %s", service_info);
+                               service_info_len = strlen(service_info);
+                       }
                } else if (!g_strcmp0(key, "service_status")) {
                        g_variant_get(var, "y", &status);
                }  else {
@@ -211,7 +267,15 @@ void asp_process_seek_search_result(GDBusConnection *connection,
                }
        }
 
-       //TODO :client->search_result_cb
+       seek = get_seek_by_id(search_id);
+       if (!seek) {
+               ASP_LOGD("There's no related seek");
+               return;
+       }
+
+       client->seek_search_result_cb(error_code,(asp_seek_service_h)seek, service_mac,
+                       advertisement_id, (asp_wps_type_e)config_method, instance_name, service_info,
+                       service_info_len, status, client->user_data_for_cb_seek_search_result);
        g_variant_iter_free(iter);
        g_free(service_info);
        __ASP_LOG_FUNC_END__;
@@ -224,12 +288,13 @@ void asp_process_advert_status_changed(GDBusConnection *connection,
        __ASP_LOG_FUNC_START__;
 
        asp_client_info_s *client = &g_client_info;
+       asp_client_advert_s *advert = NULL;
        unsigned int advertisement_id = 0;
        unsigned char status = 0;
        int reason = 0;
 
        if (!client->advert_status_changed_cb) {
-               ASP_LOGE("search_result_cb is NULL!!");
+               ASP_LOGD("search_result_cb is NULL!!");
                return;
        }
 
@@ -240,7 +305,16 @@ void asp_process_advert_status_changed(GDBusConnection *connection,
 
        g_variant_get(parameters, "(uyi)", &advertisement_id, &status, &reason);
 
-       //TODO :client->advert_status_changed_cb
+       advert = get_advert_by_id(advertisement_id);
+       if (!advert) {
+               ASP_LOGD("There's no related advert");
+               return;
+       }
+
+       client->advert_status_changed_cb(
+                       (asp_advert_service_h)advert, (asp_service_status_e)status,
+                       (asp_advert_status_reason_e)reason,
+                       client->user_data_for_cb_advert_status_changed);
 
        __ASP_LOG_FUNC_END__;
        return;
@@ -269,13 +343,6 @@ int __handle_session_request(unsigned int adv_id, const char *session_mac,
                return -1;
        }
 
-       if (service->auto_accept == FALSE) {
-               ASP_LOGD("Don't accept request automatically");
-               __ASP_LOG_FUNC_END__;
-               return 0;
-
-       }
-
        ASP_LOGD("Process auto accept service");
 
        temp = NULL;
@@ -301,6 +368,12 @@ int __handle_session_request(unsigned int adv_id, const char *session_mac,
                asp_sessions = g_list_prepend(asp_sessions, session);
        }
 
+       if (service->auto_accept == FALSE) {
+               ASP_LOGD("Don't accept request automatically");
+               __ASP_LOG_FUNC_END__;
+               return 0;
+       }
+
        asp_session_confirm(session, TRUE, NULL);
        ASP_LOGD("asp_confirm_session");
        __ASP_LOG_FUNC_END__;
@@ -313,6 +386,8 @@ void asp_process_session_request(GDBusConnection *connection,
        __ASP_LOG_FUNC_START__;
 
        asp_client_info_s *client = &g_client_info;
+       asp_client_advert_s *advert = NULL;
+       asp_client_session_s *session = NULL;
 
        GVariantIter *iter = NULL;
        GVariant *var = NULL;
@@ -322,8 +397,10 @@ void asp_process_session_request(GDBusConnection *connection,
        const char * device_name = NULL;
        unsigned int session_id = 0;
        const char *session_info = NULL;
+       int info_size = 0;
        gboolean get_network_config_pin = FALSE;
        const char *network_config_pin = NULL;
+       int error_code = ASP_ERROR_NONE;
 
        if (!client->session_request_cb) {
                ASP_LOGE("session_request_cb is NULL!!");
@@ -342,12 +419,14 @@ void asp_process_session_request(GDBusConnection *connection,
                        g_variant_get(var, "u", &adv_id);
                } else if (!g_strcmp0(key, "session_id")) {
                        g_variant_get(var, "u", &session_id);
-               }  else if (!g_strcmp0(key, "session_mac")) {
+               } else if (!g_strcmp0(key, "session_mac")) {
                        g_variant_get(var, "&s", &session_mac);
                } else if (!g_strcmp0(key, "device_name")) {
                        g_variant_get(var, "&s", &device_name);
                } else if (!g_strcmp0(key, "session_info")) {
                        g_variant_get(var, "&s", &session_info);
+                       if (session_info)
+                               info_size = strlen(session_info);
                } else if (!g_strcmp0(key, "get_pin")) {
                        g_variant_get(var, "b", &get_network_config_pin);
                } else if (!g_strcmp0(key, "pin")) {
@@ -357,8 +436,7 @@ void asp_process_session_request(GDBusConnection *connection,
                }
        }
 
-       if (session_mac == NULL)
-       {
+       if (session_mac == NULL) {
                ASP_LOGE("session_mac is NULL");
                g_variant_iter_free(iter);
                __ASP_LOG_FUNC_END__;
@@ -367,9 +445,24 @@ void asp_process_session_request(GDBusConnection *connection,
 
        if (__handle_session_request(adv_id, session_mac,
                        session_id, session_info) == 0) {
-               //TODO :client->session_request_cb
-       }
 
+               advert = get_advert_by_id(adv_id);
+               if (!advert) {
+                       ASP_LOGD("There's no related advert");
+                       return;
+               }
+
+               session = get_session_by_id_mac(session_mac, session_id);
+               if (!advert) {
+                       ASP_LOGD("There's no related advert");
+                       return;
+               }
+
+               client->session_request_cb(error_code, advert, session,
+                               device_name, session_info, info_size,
+                               (bool)get_network_config_pin, network_config_pin,
+                               client->user_data_for_cb_session_config_request);
+       }
        g_variant_iter_free(iter);
 
        __ASP_LOG_FUNC_END__;
@@ -382,13 +475,16 @@ void asp_process_session_config_request(GDBusConnection *connection,
        __ASP_LOG_FUNC_START__;
 
        asp_client_info_s *client = &g_client_info;
+       asp_client_session_s *session = NULL;
 
        GVariantIter *iter = NULL;
        GVariant *var = NULL;
        const char *key = NULL;
+       const char *session_mac = NULL;
        unsigned int session_id = 0;
        gboolean get_pin = false;
        const char *config_pin = NULL;
+       int error_code = ASP_ERROR_NONE;
 
        if (!client->session_config_request_cb) {
                ASP_LOGE("session_config_request_cb is NULL!!");
@@ -404,6 +500,8 @@ void asp_process_session_config_request(GDBusConnection *connection,
        while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
                if (!g_strcmp0(key, "session_id")) {
                        g_variant_get(var, "u", &session_id);
+               } else if (!g_strcmp0(key, "session_mac")) {
+                       g_variant_get(var, "&s", &session_mac);
                } else if (!g_strcmp0(key, "get_pin")) {
                        g_variant_get(var, "b", &get_pin);
                } else if (!g_strcmp0(key, "pin")) {
@@ -413,7 +511,22 @@ void asp_process_session_config_request(GDBusConnection *connection,
                }
        }
 
-       //TODO :client->session_config_request_cb
+       if (session_mac == NULL) {
+               ASP_LOGE("session_mac is NULL");
+               g_variant_iter_free(iter);
+               __ASP_LOG_FUNC_END__;
+               return;
+       }
+
+       session = get_session_by_id_mac(session_mac, session_id);
+       if (!session) {
+               ASP_LOGD("There's no related session");
+               return;
+       }
+
+       client->session_config_request_cb(error_code, (asp_session_h)session,
+                       (bool)get_pin, config_pin,
+                       client->user_data_for_cb_session_config_request);
        g_variant_iter_free(iter);
 
        __ASP_LOG_FUNC_END__;
@@ -426,6 +539,7 @@ void asp_process_session_connect_status(GDBusConnection *connection,
        __ASP_LOG_FUNC_START__;
 
        asp_client_info_s *client = &g_client_info;
+       asp_client_session_s *session = NULL;
 
        GVariantIter *iter = NULL;
        GVariant *var = NULL;
@@ -434,6 +548,8 @@ void asp_process_session_connect_status(GDBusConnection *connection,
        unsigned int session_id = 0;
        int status = 0;
        const char *deferred_resp = NULL;
+       int res_len = 0;
+       int error_code = ASP_ERROR_NONE;
 
        if (!client->session_connect_status_cb) {
                ASP_LOGE("connect_status_cb is NULL!!");
@@ -455,12 +571,29 @@ void asp_process_session_connect_status(GDBusConnection *connection,
                        g_variant_get(var, "i", &status);
                } else if (!g_strcmp0(key, "deferred_resp")) {
                        g_variant_get(var, "&s", &deferred_resp);
+                       if (deferred_resp)
+                               res_len = strlen(deferred_resp);
                }  else {
                        ;/* Do Nothing */
                }
        }
 
-       //TODO :client->session_connect_status_cb
+       if (session_mac == NULL) {
+               ASP_LOGE("session_mac is NULL");
+               g_variant_iter_free(iter);
+               __ASP_LOG_FUNC_END__;
+               return;
+       }
+
+       session = get_session_by_id_mac(session_mac, session_id);
+       if (!session) {
+               ASP_LOGD("There's no related session");
+               return;
+       }
+
+       client->session_connect_status_cb(error_code, (asp_session_h)session,
+                       (asp_connect_status_e)status, deferred_resp, res_len,
+                       client->user_data_for_cb_session_connect_status);
        g_variant_iter_free(iter);
 
        __ASP_LOG_FUNC_END__;
@@ -473,6 +606,7 @@ void asp_process_session_status(GDBusConnection *connection,
        __ASP_LOG_FUNC_START__;
 
        asp_client_info_s *client = &g_client_info;
+       asp_client_session_s *session = NULL;
 
        GVariantIter *iter = NULL;
        GVariant *var = NULL;
@@ -482,6 +616,7 @@ void asp_process_session_status(GDBusConnection *connection,
        int state = 0;
        int status = 0;
        const char *requested_info = NULL;
+       int error_code = ASP_ERROR_NONE;
 
        if (!client->session_status_cb) {
                ASP_LOGE("session_status_cb is NULL!!");
@@ -510,7 +645,22 @@ void asp_process_session_status(GDBusConnection *connection,
                }
        }
 
-       //TODO :client->session_status_cb
+       if (session_mac == NULL) {
+               ASP_LOGE("session_mac is NULL");
+               g_variant_iter_free(iter);
+               __ASP_LOG_FUNC_END__;
+               return;
+       }
+
+       session = get_session_by_id_mac(session_mac, session_id);
+       if (!session) {
+               ASP_LOGD("There's no related session");
+               return;
+       }
+
+       client->session_status_cb(error_code, (asp_session_h)session,
+                       (asp_session_state_e) state, requested_info,
+                       client->user_data_for_cb_session_status);
 
        __ASP_LOG_FUNC_END__;
        return;
@@ -522,6 +672,7 @@ void asp_process_session_port_status(GDBusConnection *connection,
        __ASP_LOG_FUNC_START__;
 
        asp_client_info_s *client = &g_client_info;
+       asp_client_session_s *session = NULL;
 
        GVariantIter *iter = NULL;
        GVariant *var = NULL;
@@ -532,6 +683,7 @@ void asp_process_session_port_status(GDBusConnection *connection,
        int port = 0;
        int proto = 0;
        int status = 0;
+       int error_code = ASP_ERROR_NONE;
 
        if (!client->session_port_status_cb) {
                ASP_LOGE("port_status_cb is NULL!!");
@@ -562,7 +714,22 @@ void asp_process_session_port_status(GDBusConnection *connection,
                }
        }
 
-       //TODO :client->session_port_status_cb
+       if (session_mac == NULL) {
+               ASP_LOGE("session_mac is NULL");
+               g_variant_iter_free(iter);
+               __ASP_LOG_FUNC_END__;
+               return;
+       }
+
+       session = get_session_by_id_mac(session_mac, session_id);
+       if (!session) {
+               ASP_LOGD("There's no related session");
+               return;
+       }
+
+       client->session_port_status_cb(error_code, (asp_session_h)session,
+                       ip_address, port, proto, (asp_port_status_e)status,
+                       client->user_data_for_cb_session_port_status);
 
        __ASP_LOG_FUNC_END__;
        return;