Mercurial > audlegacy-plugins
changeset 2732:1a27c497e526
indentation and some small bug fixing
author | Paula Stanciu <paula.stanciu@gmail.com> |
---|---|
date | Mon, 30 Jun 2008 00:34:56 +0300 |
parents | 324f950774cb |
children | d5c5c89aee86 |
files | src/bluetooth/bluetooth.c src/bluetooth/gui.c src/bluetooth/scan_gui.c src/bluetooth/scan_gui.o |
diffstat | 4 files changed, 187 insertions(+), 181 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bluetooth/bluetooth.c Sun Jun 29 00:04:49 2008 -0500 +++ b/src/bluetooth/bluetooth.c Mon Jun 30 00:34:56 2008 +0300 @@ -48,183 +48,184 @@ void bluetooth_cleanup ( void ) { printf("bluetooth: exit\n"); - if (config ==1 ){ - destroy_scan_window(); - config =0; - } - if(discover_finish == 2) { - dbus_g_connection_flush (bus); - dbus_g_connection_unref(bus); + if (config ==1 ){ + destroy_scan_window(); + config =0; } - disconnect_dbus_signals(); - -} + if(discover_finish == 2) { + dbus_g_connection_flush (bus); + if(window){ + dbus_g_connection_unref(bus); + } + disconnect_dbus_signals(); -void bt_about( void ) -{ - printf("about call\n"); - show_scan(); -} + } + + void bt_about( void ) + { + printf("about call\n"); + show_scan(); + } -void bt_cfg(void) -{ config =1; - if(discover_finish == 2){ - if (devices_no == 0){ - printf("no devs!\n"); - show_scan(); - show_no_devices(); - }else - results_ui(); + void bt_cfg(void) + { config =1; + if(discover_finish == 2){ + if (devices_no == 0){ + printf("no devs!\n"); + show_scan(); + show_no_devices(); + }else + results_ui(); + } + else show_scan(); } - else show_scan(); -} -void disconnect_dbus_signals(){ + void disconnect_dbus_signals(){ - dbus_g_proxy_disconnect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus); - dbus_g_proxy_disconnect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus); - dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus); - dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL); + dbus_g_proxy_disconnect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus); + dbus_g_proxy_disconnect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus); + dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus); + dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL); -} + } -void refresh_call(void){ - printf("refresh function called\n"); - disconnect_dbus_signals(); - if(discover_finish == 0 ||discover_finish== 2){ - discover_finish = 0; - discover_devices(); + void refresh_call(void){ + printf("refresh function called\n"); + disconnect_dbus_signals(); + if(discover_finish == 0 ||discover_finish== 2){ + discover_finish = 0; + discover_devices(); + } + else + printf("Scanning please wait!\n"); } - else - printf("Scanning please wait!\n"); -} -void connect_call(void){ - printf("connect function \n"); -} + void connect_call(void){ + printf("connect function \n"); + } -static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data) -{ - int found_in_list=FALSE; - g_static_mutex_lock(&mutex); - current_device = audio_devices; - if((class & 0x200404)==0x200404) + static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data) { + int found_in_list=FALSE; + g_static_mutex_lock(&mutex); + current_device = audio_devices; + if((class & 0x200404)==0x200404) + { + while(current_device != NULL) + { + if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) + { + found_in_list = TRUE; + break; + } + current_device=g_list_next(current_device); + } + if(!found_in_list) + { + DeviceData *dev= g_new0(DeviceData, 1); + dev->class = class; + dev->address = g_strdup(address); + dev->name = NULL; + audio_devices=g_list_prepend(audio_devices, dev); + } + } + g_static_mutex_unlock(&mutex); + } + + static void discovery_started(DBusGProxy *object, gpointer user_data) + { + g_print("Signal: DiscoveryStarted()\n"); + discover_finish = 1; + } + + static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data) + { + g_static_mutex_lock(&mutex); + current_device=audio_devices; while(current_device != NULL) { if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) { - found_in_list = TRUE; + ((DeviceData*)(current_device->data))->name=g_strdup(name); break; } current_device=g_list_next(current_device); } - if(!found_in_list) - { - DeviceData *dev= g_new0(DeviceData, 1); - dev->class = class; - dev->address = g_strdup(address); - dev->name = NULL; - audio_devices=g_list_prepend(audio_devices, dev); + g_static_mutex_unlock(&mutex); + } + static void print_results() + { + int i=0; + g_print("Final Scan results:\n"); + devices_no = g_list_length(audio_devices); + g_print("Number of audio devices: %d \n",devices_no); + if(devices_no==0 ) { + if(config ==1) show_no_devices(); + } else { + current_device=audio_devices; + while(current_device != NULL) + { + g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i, + ((DeviceData*)(current_device->data))-> name, + ((DeviceData*)(current_device->data))-> class, + ((DeviceData*)(current_device->data))-> address); + current_device=g_list_next(current_device); + } + destroy_scan_window(); + if(config==1) { + destroy_scan_window(); + results_ui(); + } + // refresh_tree(); } } - g_static_mutex_unlock(&mutex); -} - -static void discovery_started(DBusGProxy *object, gpointer user_data) -{ - g_print("Signal: DiscoveryStarted()\n"); - discover_finish = 1; -} - -static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data) -{ - g_static_mutex_lock(&mutex); - current_device=audio_devices; - while(current_device != NULL) - { - if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) - { - ((DeviceData*)(current_device->data))->name=g_strdup(name); - break; - } - current_device=g_list_next(current_device); - } - g_static_mutex_unlock(&mutex); -} -static void print_results() -{ - int i=0; - g_print("Final Scan results:\n"); - devices_no = g_list_length(audio_devices); - g_print("Number of audio devices: %d \n",devices_no); - if(devices_no==0 ) { - if(config ==1) show_no_devices(); - } else { - current_device=audio_devices; - while(current_device != NULL) - { - g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i, - ((DeviceData*)(current_device->data))-> name, - ((DeviceData*)(current_device->data))-> class, - ((DeviceData*)(current_device->data))-> address); - current_device=g_list_next(current_device); - } - destroy_scan_window(); - if(config==1) { - destroy_scan_window(); - results_ui(); - } - // refresh_tree(); - } -} -static void discovery_completed(DBusGProxy *object, gpointer user_data) -{ - g_print("Signal: DiscoveryCompleted()\n"); - discover_finish =2; - print_results(); -} + static void discovery_completed(DBusGProxy *object, gpointer user_data) + { + g_print("Signal: DiscoveryCompleted()\n"); + discover_finish =2; + print_results(); + } -void discover_devices(void){ - GError *error = NULL; - // g_type_init(); - g_log_set_always_fatal (G_LOG_LEVEL_WARNING); - bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); - if (error != NULL) - { - g_printerr("Connecting to system bus failed: %s\n", error->message); - g_error_free(error); - } - obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"); - printf("bluetooth plugin - start discovery \n"); - dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_INT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); + void discover_devices(void){ + GError *error = NULL; + // g_type_init(); + g_log_set_always_fatal (G_LOG_LEVEL_WARNING); + bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (error != NULL) + { + g_printerr("Connecting to system bus failed: %s\n", error->message); + g_error_free(error); + } + obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"); + printf("bluetooth plugin - start discovery \n"); + dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_INT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); - dbus_g_proxy_add_signal(obj, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus, NULL); + dbus_g_proxy_add_signal(obj, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus, NULL); - dbus_g_proxy_add_signal(obj, "DiscoveryStarted", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus, NULL); + dbus_g_proxy_add_signal(obj, "DiscoveryStarted", G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus, NULL); - dbus_g_proxy_add_signal(obj, "DiscoveryCompleted", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus, NULL); + dbus_g_proxy_add_signal(obj, "DiscoveryCompleted", G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus, NULL); - dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL, NULL); + dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL, NULL); - dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID); - if (error != NULL) - { - g_printerr("Failed to discover devices: %s\n", error->message); - g_error_free(error); - } + dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID); + if (error != NULL) + { + g_printerr("Failed to discover devices: %s\n", error->message); + g_error_free(error); + } -} + }
--- a/src/bluetooth/gui.c Sun Jun 29 00:04:49 2008 -0500 +++ b/src/bluetooth/gui.c Mon Jun 30 00:34:56 2008 +0300 @@ -41,19 +41,19 @@ * else we print the "no devices found message */ if(discover_finish == 1) /*we are scanning*/ - status = g_strdup_printf("Scanning"); - else - status = g_strdup_printf("No devices found!"); - /* add the status to the list */ + status = g_strdup_printf("Scanning"); + else + status = g_strdup_printf("No devices found!"); + /* add the status to the list */ gtk_list_store_append(store,&iter); gtk_list_store_set(store,&iter, COLUMN_PRODUCER,status,-1); return GTK_TREE_MODEL(store); - } + } while(dev != NULL) { gtk_list_store_append(store,&iter); gtk_list_store_set(store,&iter, COLUMN_PRODUCER, - ((DeviceData*)(dev->data))-> name,-1); + ((DeviceData*)(dev->data))-> name,-1); dev = g_list_next(dev); } @@ -76,34 +76,34 @@ /*add inf to test_data from audio_devices */ dev_no = g_list_length(audio_devices); dev = audio_devices; - if(dev == NULL || discover_finish == 0) { + if(dev == NULL || discover_finish == 0) { /*if we are scanning for devices now then print the Scanning message, * else we print the "no devices found message */ printf("discover: %d\n",discover_finish); if(discover_finish == 1) { /*we are scanning*/ - status = g_strdup_printf("Scanning"); + status = g_strdup_printf("Scanning"); } else - status = g_strdup_printf("No devices found!"); - /* add the status to the list */ + status = g_strdup_printf("No devices found!"); + /* add the status to the list */ gtk_list_store_append(store,&iter); gtk_list_store_set(store,&iter, COLUMN_PRODUCER,status,-1); gtk_label_set_text(GTK_LABEL(label_prod),status); return GTK_TREE_MODEL(store); - } - + } + /* add data to the list store */ while(dev != NULL) { gtk_list_store_append(store,&iter); gtk_list_store_set(store,&iter, COLUMN_PRODUCER, - ((DeviceData*)(dev->data))-> name,-1); + ((DeviceData*)(dev->data))-> name,-1); dev = g_list_next(dev); } //set the labels - // temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class); + // temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class); gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(dev->data))->name); -// gtk_label_set_text(GTK_LABEL(label_class),temp); + // gtk_label_set_text(GTK_LABEL(label_class),temp); gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address); g_free(temp); return GTK_TREE_MODEL(store); @@ -160,22 +160,22 @@ for(i=0;i<sel;i++) dev = g_list_next(dev); if(dev != NULL) { - temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class); - gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(dev->data))->name); - gtk_label_set_text(GTK_LABEL(label_class),temp); - gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address); - gtk_tree_path_free (path); - g_free(temp); + temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class); + gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(dev->data))->name); + gtk_label_set_text(GTK_LABEL(label_class),temp); + gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address); + gtk_tree_path_free (path); + g_free(temp); }else gtk_label_set_text(GTK_LABEL(label_prod),status); g_free(status); - + } } void results_ui() { - gchar *temp; + gchar *temp; if (!window) { window = gtk_window_new (GTK_WINDOW_TOPLEVEL); @@ -265,11 +265,11 @@ dev = audio_devices; if(dev != NULL) { - temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class); - gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(dev->data))->name); - gtk_label_set_text(GTK_LABEL(label_class),temp); - gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address); - g_free(temp); + temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class); + gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(dev->data))->name); + gtk_label_set_text(GTK_LABEL(label_class),temp); + gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address); + g_free(temp); } gtk_window_set_default_size (GTK_WINDOW (window), 460, 150);
--- a/src/bluetooth/scan_gui.c Sun Jun 29 00:04:49 2008 -0500 +++ b/src/bluetooth/scan_gui.c Mon Jun 30 00:34:56 2008 +0300 @@ -10,20 +10,25 @@ gpointer progress() { -for(;;){ - gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); - printf("threadfunction\n"); - sleep(1); - if(discover_finish == 2 ) { - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); + for(;;){ + if(window){ + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); + } + sleep(1); + if(discover_finish == 2 ) { + if(window){ + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); + } return 0; } } -return 0; + return 0; } void show_no_devices(){ - gtk_label_set_text(GTK_LABEL(scan_label),"No devices found!"); + if(window ){ + gtk_label_set_text(GTK_LABEL(scan_label),"No devices found!"); + } } void destroy_scan_window(){ gtk_widget_hide(window); @@ -68,12 +73,12 @@ if (!GTK_WIDGET_VISIBLE (window)) gtk_widget_show_all (window); else - { + { gtk_widget_destroy (window); g_free(filename); window = NULL; } - } + } }