From: Ji-hoon Jung Date: Fri, 8 Nov 2013 08:20:56 +0000 (+0900) Subject: revise logging and coding style X-Git-Tag: accepted/tizen/generic/20140317.083658~24^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=329e1adf0d6f4d4121127dbfd6116c5d67543750;p=platform%2Fcore%2Fconnectivity%2Fnfc-manager-neard.git revise logging and coding style Change-Id: Ifcdbdeb015980f4871c9b2896105c05087b3d52b Signed-off-by: Jihoon Jung --- diff --git a/client/net_nfc_client_p2p.c b/client/net_nfc_client_p2p.c index d62f42d..6593a23 100644 --- a/client/net_nfc_client_p2p.c +++ b/client/net_nfc_client_p2p.c @@ -42,33 +42,16 @@ static NetNfcGDbusP2p *p2p_proxy = NULL; static P2pSignalHandler p2p_signal_handler; static void p2p_device_detached(GObject *source_object, - gpointer user_data); - -static void p2p_device_discovered(GObject *source_object, - guint arg_handle, - gpointer user_data); - -static void p2p_device_data_received(GObject *source_object, - GVariant *arg_data, - gpointer user_data); - -static void p2p_call_send(GObject *source_object, - GAsyncResult *res, - gpointer user_data); - -static void p2p_device_detached(GObject *source_object, gpointer user_data) { NFC_INFO(">>> SIGNAL arrived"); + RET_IF(NULL == p2p_signal_handler.p2p_device_detached_cb); + /*llcp client function to set/unset the current target id needs to be implemented*/ /*net_nfc_client_llcp_current_target_id(NULL);*/ - if (p2p_signal_handler.p2p_device_detached_cb) - { - p2p_signal_handler.p2p_device_detached_cb( - p2p_signal_handler.p2p_device_detached_data); - } + p2p_signal_handler.p2p_device_detached_cb(p2p_signal_handler.p2p_device_detached_data); /*llcp client function to close all socket needs to be implemented*/ /*net_nfc_client_llcp_close_all_socket();*/ @@ -81,47 +64,47 @@ static void p2p_device_discovered(GObject *source_object, guint arg_handle, NFC_INFO(">>> SIGNAL arrived"); + RET_IF(NULL == p2p_signal_handler.p2p_device_discovered_cb); + handle_info = GUINT_TO_POINTER(arg_handle); - if (p2p_signal_handler.p2p_device_discovered_cb) - { - p2p_signal_handler.p2p_device_discovered_cb(handle_info, + + p2p_signal_handler.p2p_device_discovered_cb(handle_info, p2p_signal_handler.p2p_device_discovered_data); - } + } static void p2p_device_data_received(GObject *source_object, GVariant *arg_data, gpointer user_data) { - NFC_INFO(">>> SIGNAL arrived"); + data_s p2p_data = { NULL, }; - if (p2p_signal_handler.p2p_data_received_cb) - { - data_s p2p_data = { NULL, }; + NFC_INFO(">>> SIGNAL arrived"); - net_nfc_util_gdbus_variant_to_data_s(arg_data, &p2p_data); + RET_IF(NULL == p2p_signal_handler.p2p_data_received_cb); - p2p_signal_handler.p2p_data_received_cb(&p2p_data, - p2p_signal_handler.p2p_data_received_data); + net_nfc_util_gdbus_variant_to_data_s(arg_data, &p2p_data); + p2p_signal_handler.p2p_data_received_cb(&p2p_data, + p2p_signal_handler.p2p_data_received_data); - net_nfc_util_free_data(&p2p_data); - } + net_nfc_util_free_data(&p2p_data); } static void p2p_call_send(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NetNfcCallback *func_data = (NetNfcCallback *)user_data; - net_nfc_error_e out_result; + gboolean ret; GError *error = NULL; + net_nfc_error_e out_result; + NetNfcCallback *func_data = user_data; + net_nfc_client_p2p_send_completed callback; g_assert(user_data != NULL); - if (net_nfc_gdbus_p2p_call_send_finish( - NET_NFC_GDBUS_P2P(source_object), - (gint *)&out_result, - res, - &error) == FALSE) + ret = net_nfc_gdbus_p2p_call_send_finish(NET_NFC_GDBUS_P2P(source_object), + (gint *)&out_result, res, &error); + + if (FALSE == ret) { out_result = NET_NFC_IPC_FAIL; @@ -131,8 +114,7 @@ static void p2p_call_send(GObject *source_object, GAsyncResult *res, if (func_data->callback != NULL) { - net_nfc_client_p2p_send_completed callback = - (net_nfc_client_p2p_send_completed)func_data->callback; + callback = (net_nfc_client_p2p_send_completed)func_data->callback; callback(out_result, func_data->user_data); } @@ -147,22 +129,14 @@ API net_nfc_error_e net_nfc_client_p2p_send(net_nfc_target_handle_s *handle, GVariant *arg_data; NetNfcCallback *func_data; - if (p2p_proxy == NULL) - { - NFC_ERR("Can not get P2pProxy"); - - return NET_NFC_NOT_INITIALIZED; - } + RETV_IF(NULL == p2p_proxy, NET_NFC_NOT_INITIALIZED); /* prevent executing daemon when nfc is off */ - if (net_nfc_client_manager_is_activated() == false) { - return NET_NFC_INVALID_STATE; - } + RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); func_data = g_try_new0(NetNfcCallback, 1); - if (func_data == NULL) { + if (NULL == func_data) return NET_NFC_ALLOC_FAIL; - } func_data->callback = (gpointer)callback; func_data->user_data = user_data; @@ -186,36 +160,30 @@ API net_nfc_error_e net_nfc_client_p2p_send(net_nfc_target_handle_s *handle, API net_nfc_error_e net_nfc_client_p2p_send_sync(net_nfc_target_handle_s *handle, data_s *data) { + gboolean ret; GVariant *arg_data; GError *error = NULL; - net_nfc_error_e out_result; - if (p2p_proxy == NULL) - { - NFC_ERR("Can not get P2pProxy"); - - return NET_NFC_NOT_INITIALIZED; - } + RETV_IF(NULL == p2p_proxy, NET_NFC_NOT_INITIALIZED); /* prevent executing daemon when nfc is off */ - if (net_nfc_client_manager_is_activated() == false) { - return NET_NFC_INVALID_STATE; - } + RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE); arg_data = net_nfc_util_gdbus_data_to_variant(data); - if (net_nfc_gdbus_p2p_call_send_sync(p2p_proxy, - 0 /* FIXME */, - arg_data, - GPOINTER_TO_UINT(handle), - net_nfc_client_gdbus_get_privilege(), - (gint *)&out_result, - NULL, - &error) == FALSE) + ret = net_nfc_gdbus_p2p_call_send_sync(p2p_proxy, + 0 /* FIXME */, + arg_data, + GPOINTER_TO_UINT(handle), + net_nfc_client_gdbus_get_privilege(), + (gint *)&out_result, + NULL, + &error); + + if (FALSE == ret) { - NFC_ERR("p2p send (sync call) failed: %s", - error->message); + NFC_ERR("p2p send (sync call) failed: %s", error->message); g_error_free(error); out_result = NET_NFC_IPC_FAIL; @@ -228,8 +196,7 @@ API net_nfc_error_e net_nfc_client_p2p_send_sync(net_nfc_target_handle_s *handle API void net_nfc_client_p2p_set_device_discovered( net_nfc_client_p2p_device_discovered callback, void *user_data) { - if (callback == NULL) - return; + RET_IF(NULL == callback); p2p_signal_handler.p2p_device_discovered_cb = callback; p2p_signal_handler.p2p_device_discovered_data = user_data; @@ -239,8 +206,7 @@ API void net_nfc_client_p2p_set_device_discovered( API void net_nfc_client_p2p_set_device_detached( net_nfc_client_p2p_device_detached callback, void *user_data) { - if (callback == NULL) - return; + RET_IF(NULL == callback); p2p_signal_handler.p2p_device_detached_cb = callback; p2p_signal_handler.p2p_device_detached_data = user_data; @@ -250,8 +216,7 @@ API void net_nfc_client_p2p_set_device_detached( API void net_nfc_client_p2p_set_data_received( net_nfc_client_p2p_data_received callback, void *user_data) { - if (callback == NULL) - return; + RET_IF(NULL == callback); p2p_signal_handler.p2p_data_received_cb = callback; p2p_signal_handler.p2p_data_received_data = user_data; @@ -295,7 +260,8 @@ net_nfc_error_e net_nfc_client_p2p_init(void) "/org/tizen/NetNfcService/P2p", NULL, &error); - if (p2p_proxy == NULL) + + if (NULL == p2p_proxy) { NFC_ERR("Can not create proxy : %s", error->message); g_error_free(error); @@ -303,14 +269,9 @@ net_nfc_error_e net_nfc_client_p2p_init(void) return NET_NFC_UNKNOWN_ERROR; } - g_signal_connect(p2p_proxy, "detached", - G_CALLBACK(p2p_device_detached), NULL); - - g_signal_connect(p2p_proxy, "discovered", - G_CALLBACK(p2p_device_discovered), NULL); - - g_signal_connect(p2p_proxy, "received", - G_CALLBACK(p2p_device_data_received), NULL); + g_signal_connect(p2p_proxy, "detached", G_CALLBACK(p2p_device_detached), NULL); + g_signal_connect(p2p_proxy, "discovered", G_CALLBACK(p2p_device_discovered), NULL); + g_signal_connect(p2p_proxy, "received", G_CALLBACK(p2p_device_data_received), NULL); return NET_NFC_OK; }