Merge "A2DP profile multiple source support" into tizen
[platform/core/connectivity/bluetooth-frwk.git] / test / gatt-test / bluetooth-gatt-test.c
old mode 100644 (file)
new mode 100755 (executable)
index 1648197..cb7ef22
@@ -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.
@@ -34,8 +28,6 @@
 #include <stdint.h>
 #include <string.h>
 #include <glib.h>
-#include <dbus/dbus-glib.h>
-
 #include "bluetooth-api.h"
 
 
 
 GMainLoop *main_loop = NULL;
 
-typedef struct
-{
+typedef struct {
        const char *tc_name;
        int tc_code;
 } tc_table_t;
 
-tc_table_t tc_table[] =
-{
+tc_table_t tc_table[] = {
        {"Send alert to remote le device"               , 1},
        {"Set Link loss alert"          , 2},
 
@@ -65,7 +55,7 @@ tc_table_t tc_table[] =
 };
 
 #define tc_result(success, tc_index) \
-       TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS)?"Success":"Failed"));
+       TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS) ? "Success" : "Failed"));
 
 char *g_alert_char_handle = NULL;
 guint8 g_alert_level = 0;
@@ -140,13 +130,17 @@ static void __accept_bdaddress(bluetooth_device_address_t *device_address)
 
        addr = get_bd_from_file(BD_ADDR_FILE);
        if (addr) {
-               TC_PRT("Remote bd adress from file: %s", addr);
+               TC_PRT("Remote bd address from file: %s", addr);
                convert_addr_string_to_addr_type(device_address, addr);
+               g_free(addr);
                return;
        }
 
        TC_PRT("Enter bd address: ");
-       scanf("%s", str_address);
+       int ret = 0;
+       ret = scanf("%s", str_address);
+       if (ret < 0)
+               TC_PRT("Some read error");
        TC_PRT("You have entered bd address %s\n", str_address);
        convert_addr_string_to_addr_type(device_address, str_address);
 }
@@ -154,8 +148,11 @@ static void __accept_bdaddress(bluetooth_device_address_t *device_address)
 static void __accept_alert_level()
 {
        TC_PRT("Enter alert level \n 0 - no alert 1 - mild alert 2 - High alert : ");
-       scanf("%d", &g_alert_level);
-       TC_PRT("You have selected alert level %d ", g_alert_level);
+       int ret = 0;
+       ret = scanf("%c", &g_alert_level);
+       if (ret < 0)
+               TC_PRT("Some read error");
+       TC_PRT("You have selected alert level %hu ", g_alert_level);
 }
 
 int test_input_callback(void *data)
@@ -219,19 +216,15 @@ void startup()
 {
        TC_PRT("bluetooth framework TC startup");
 
-       if (!g_thread_supported())
-               g_thread_init(NULL);
-
-       dbus_g_thread_init();
+       dbus_threads_init_default();
 
-       g_type_init();
        main_loop = g_main_loop_new(NULL, FALSE);
 }
 
 void cleanup()
 {
        TC_PRT("bluetooth framework TC cleanup");
-       if ( main_loop != NULL)
+       if (main_loop != NULL)
                g_main_loop_unref(main_loop);
 }
 
@@ -270,7 +263,7 @@ void bt_event_callback(int event, bluetooth_event_param_t* param,
 {
        TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        TC_PRT("bt event callback 0x%04x", event);
-       switch(event) {
+       switch (event) {
        case BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID:
        {
                TC_PRT("BLUETOOTH_EVENT_GATT_GET_CHAR_FROM_UUID");
@@ -297,12 +290,12 @@ static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
        unsigned int len = 0;
        int test_id;
 
-       if (g_io_channel_read(chan, buf, sizeof(buf), &len) !=
-                                                       G_IO_ERROR_NONE) {
+       if (g_io_channel_read_chars(chan, buf, sizeof(buf),
+                       &len, NULL) ==  G_IO_STATUS_ERROR) {
                printf("IO Channel read error");
                return FALSE;
        }
-       printf("%s\n",buf);
+       printf("%s\n", buf);
        tc_usage_print();
 
        test_id = atoi(buf);