Fix the coding style errors (bt-api)
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-request-sender.c
index 44fc216..b240fb8 100644 (file)
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * 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.
@@ -21,7 +15,6 @@
  *
  */
 
-#include <dbus/dbus-glib.h>
 #include <glib.h>
 #include <dlog.h>
 #include <string.h>
@@ -30,6 +23,7 @@
 #include "bluetooth-hid-api.h"
 #include "bluetooth-audio-api.h"
 #include "bt-internal-types.h"
+#include "bluetooth-ipsp-api.h"
 
 #include "bt-common.h"
 #include "bt-request-sender.h"
 
 static GSList *sending_requests;
 
-DBusGConnection *service_conn;
-DBusGConnection *system_conn;
-DBusGProxy *service_proxy;
-
-static GDBusConnection *service_gconn;
 static GDBusProxy *service_gproxy;
 
 static GDBusProxy *__bt_gdbus_init_service_proxy(void)
 {
+       GDBusConnection *service_gconn;
        GDBusProxy *proxy;
        GError *err = NULL;
 
-       g_type_init();
+       service_gconn = _bt_gdbus_get_system_gconn();
 
-       if (service_gconn == NULL)
-               service_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-
-       if (!service_gconn) {
-               if (err) {
-                       BT_ERR("Unable to connect to dbus: %s", err->message);
-                       g_clear_error(&err);
-               }
+       if (!service_gconn)
                return NULL;
-       }
 
        proxy =  g_dbus_proxy_new_sync(service_gconn,
                        G_DBUS_PROXY_FLAGS_NONE, NULL,
@@ -78,8 +60,6 @@ static GDBusProxy *__bt_gdbus_init_service_proxy(void)
                         g_clear_error(&err);
                }
 
-               g_object_unref(service_gconn);
-               service_gconn = NULL;
                return NULL;
        }
 
@@ -96,13 +76,8 @@ static GDBusProxy *__bt_gdbus_get_service_proxy(void)
 void _bt_gdbus_deinit_proxys(void)
 {
        if (service_gproxy) {
-               g_object_unref(service_proxy);
-               service_proxy = NULL;
-       }
-
-       if (service_gconn) {
-               g_object_unref(service_gconn);
-               service_gconn = NULL;
+               g_object_unref(service_gproxy);
+               service_gproxy = NULL;
        }
 }
 
@@ -175,6 +150,18 @@ static void __bt_get_event_info(int service_function, GArray *output,
                ret_if(output == NULL);
                *param_data = &g_array_index(output, char, 0);
                break;
+       case BT_AV_SOURCE_CONNECT:
+               *event_type = BT_A2DP_SOURCE_EVENT;
+               *event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
+               ret_if(output == NULL);
+               *param_data = &g_array_index(output, char, 0);
+               break;
+       case BT_AV_SOURCE_DISCONNECT:
+               *event_type = BT_A2DP_SOURCE_EVENT;
+               *event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
+               ret_if(output == NULL);
+               *param_data = &g_array_index(output, char, 0);
+               break;
        case BT_HF_CONNECT:
                *event_type = BT_HF_AGENT_EVENT;
                *event = BLUETOOTH_EVENT_HF_CONNECTED;
@@ -220,6 +207,20 @@ static void __bt_get_event_info(int service_function, GArray *output,
                ret_if(output == NULL);
                *param_data = &g_array_index(output, char, 0);
                break;
+       case BT_CONNECT_LE:
+               *event_type = BT_DEVICE_EVENT;
+               *event = BLUETOOTH_EVENT_GATT_CONNECTED;
+               ret_if(output == NULL);
+               *param_data = &g_array_index(output,
+                               bluetooth_device_address_t, 0);
+               break;
+       case BT_DISCONNECT_LE:
+               *event_type = BT_DEVICE_EVENT;
+               *event = BLUETOOTH_EVENT_GATT_DISCONNECTED;
+               ret_if(output == NULL);
+               *param_data = &g_array_index(output,
+                               bluetooth_device_address_t, 0);
+               break;
        default:
                BT_ERR("Unknown function");
                return;
@@ -257,9 +258,9 @@ static void __send_request_cb(GDBusProxy *proxy,
        GError *error = NULL;
        GVariant *value;
        GVariant *param1;
-       GVariant *param2;
+//     GVariant *param2;
        GArray *out_param1 = NULL;
-       GArray *out_param2 = NULL;
+//     GArray *out_param2 = NULL;
 
        BT_DBG("+");
        memset(&bt_event, 0x00, sizeof(bluetooth_event_param_t));
@@ -280,7 +281,7 @@ static void __send_request_cb(GDBusProxy *proxy,
                                &bt_event.event, &event_type,
                                &bt_event.param_data);
        } else {
-               g_variant_get(value, "(@ay@ay)", &param1, &param2);
+               g_variant_get(value, "(iv)", &result, &param1);
                g_variant_unref(value);
 
                if (param1) {
@@ -289,15 +290,15 @@ static void __send_request_cb(GDBusProxy *proxy,
                        g_variant_unref(param1);
                }
 
-               if (param2) {
-                       out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
-                       __bt_fill_garray_from_variant(param2, out_param2);
-                       result = g_array_index(out_param2, int, 0);
-                       g_variant_unref(param2);
-                       g_array_free(out_param2, TRUE);
-               } else {
-                       result = BLUETOOTH_ERROR_INTERNAL;
-               }
+//             if (param2) {
+//                     out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
+//                     __bt_fill_garray_from_variant(param2, out_param2);
+//                     result = g_array_index(out_param2, int, 0);
+//                     g_variant_unref(param2);
+//                     g_array_free(out_param2, TRUE);
+//             } else {
+//                     result = BLUETOOTH_ERROR_INTERNAL;
+//             }
 
                ret_if(cb_data == NULL);
 
@@ -344,6 +345,14 @@ static void __send_request_cb(GDBusProxy *proxy,
                ((media_cb_func_ptr)cb_data->cb)(bt_event.event,
                                (media_event_param_t *)&bt_event,
                                cb_data->user_data);
+       } else if (event_type == BT_A2DP_SOURCE_EVENT) {
+               ((bt_audio_func_ptr)cb_data->cb)(bt_event.event,
+                               (bt_audio_event_param_t *)&bt_event,
+                               cb_data->user_data);
+       } else if (event_type == BT_DEVICE_EVENT) {
+               ((bluetooth_cb_func_ptr)cb_data->cb)(bt_event.event,
+                               &bt_event,
+                               cb_data->user_data);
        } else {
                BT_INFO("Not handled event type : %d", event_type);
        }
@@ -365,7 +374,8 @@ int _bt_sync_send_request(int service_type, int service_function,
        int result = BLUETOOTH_ERROR_NONE;
        GError *error = NULL;
        GArray *in_param5 = NULL;
-       GArray *out_param2 = NULL;
+//     GArray *out_param2 = NULL;
+
        GDBusProxy  *proxy;
        GVariant *ret;
        GVariant *param1;
@@ -385,6 +395,8 @@ int _bt_sync_send_request(int service_type, int service_function,
 
                in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
 
+
+
                param1 = g_variant_new_from_data((const GVariantType *)"ay",
                                        in_param1->data, in_param1->len,
                                        TRUE, NULL, NULL);
@@ -431,9 +443,9 @@ int _bt_sync_send_request(int service_type, int service_function,
                }
 
                param1 = NULL;
-               param2 = NULL;
+//             param2 = NULL;
 
-               g_variant_get(ret, "(@ay@ay)", &param1, &param2);
+               g_variant_get(ret, "(iv)", &result, &param1);
 
                if (param1) {
                        *out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
@@ -441,15 +453,15 @@ int _bt_sync_send_request(int service_type, int service_function,
                        g_variant_unref(param1);
                }
 
-               if (param2) {
-                       out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
-                       __bt_fill_garray_from_variant(param2, out_param2);
-                       result = g_array_index(out_param2, int, 0);
-                       g_variant_unref(param2);
-                       g_array_free(out_param2, TRUE);
-               } else {
-                       result = BLUETOOTH_ERROR_INTERNAL;
-               }
+//             if (param2) {
+//                     out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
+//                     __bt_fill_garray_from_variant(param2, out_param2);
+//                     result = g_array_index(out_param2, int, 0);
+//                     g_variant_unref(param2);
+//                     g_array_free(out_param2, TRUE);
+//             } else {
+//                     result = BLUETOOTH_ERROR_INTERNAL;
+//             }
 
                g_variant_unref(ret);
                break;
@@ -468,6 +480,7 @@ int _bt_async_send_request(int service_type, int service_function,
 {
        GArray* in_param5 = NULL;
        bt_req_info_t *cb_data;
+
        GDBusProxy *proxy;
        int timeout;
        GVariant *param1;
@@ -533,6 +546,9 @@ int _bt_async_send_request(int service_type, int service_function,
 
                g_array_free(in_param5, TRUE);
                break;
+       default:
+               g_free(cb_data);
+               break;
        }
 
        return BLUETOOTH_ERROR_NONE;