changeset 2916:223822ba79f2

writing bonded device to the config file so it can be unbounded at start-up when the player doesn't stop normaly
author Paula Stanciu <paula.stanciu@gmail.com>
date Sat, 16 Aug 2008 21:46:08 +0300
parents 703cd5256849
children d354afe9df0d 049a7de72684
files src/bluetooth/agent.c src/bluetooth/bluetooth.c
diffstat 2 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/bluetooth/agent.c	Sat Aug 16 01:37:42 2008 +0200
+++ b/src/bluetooth/agent.c	Sat Aug 16 21:46:08 2008 +0300
@@ -711,6 +711,9 @@
 	dbus_g_proxy_call(object, "GetRemoteName", NULL,
 				G_TYPE_STRING, address, G_TYPE_INVALID,
 				G_TYPE_STRING, &name, G_TYPE_INVALID);
+     mcs_handle_t *cfgfile = aud_cfg_db_open();
+    aud_cfg_db_set_string(cfgfile,"BLUETOOTH_PLUGIN","bonded", address);
+    aud_cfg_db_close(cfgfile);
 
 	if (name) {
 		if (g_strrstr(name, address))
@@ -735,8 +738,7 @@
 {
 	const char *adapter = NULL, *name = NULL;
 	gchar *device, *text;
-
-	dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+ 	dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
 				G_TYPE_STRING, &adapter, G_TYPE_INVALID);
 
 	dbus_g_proxy_call(object, "GetRemoteName", NULL,
@@ -752,6 +754,9 @@
 		device = g_strdup(address);
 
 	text = g_strdup_printf(_("Removed bonding with %s"), device);
+    mcs_handle_t *cfgfile = aud_cfg_db_open();
+    aud_cfg_db_set_string(cfgfile,"BLUETOOTH_PLUGIN","bonded","no");
+    aud_cfg_db_close(cfgfile);
 
 	g_free(device);
     printf("bonding removed\n");
--- a/src/bluetooth/bluetooth.c	Sat Aug 16 01:37:42 2008 +0200
+++ b/src/bluetooth/bluetooth.c	Sat Aug 16 21:46:08 2008 +0300
@@ -44,7 +44,7 @@
 void discover_devices(void);
 void disconnect_dbus_signals(void);
 /*static void show_restart_dialog(void); */
-static void remove_bonding();
+static void remove_bonding(gchar* device);
 GeneralPlugin bluetooth_gp =
 {
     .description = "Bluetooth audio support",
@@ -61,7 +61,19 @@
     audio_devices = NULL;
     bus = NULL;
     obj = NULL;
+    gchar* bonded_addr="zz";
     discover_devices();
+    mcs_handle_t *cfgfile ;
+    cfgfile = aud_cfg_db_open();
+    if(!aud_cfg_db_get_string(cfgfile, "BLUETOOTH_PLUGIN", "bonded",
+				  &bonded_addr))
+        return;
+    if(bonded_addr!=NULL && g_strcmp0(bonded_addr,"no")!=0)
+        {
+             remove_bonding(bonded_addr);
+        }
+    aud_cfg_db_close(cfgfile);
+
 }
 
 void bluetooth_cleanup ( void )
@@ -72,7 +84,7 @@
         close_window();
         config =0;
     }
-    remove_bonding();
+    remove_bonding(bonded_dev);
     if(discover_finish == 2) {
         dbus_g_connection_flush (bus);
         dbus_g_connection_unref(bus);
@@ -127,10 +139,11 @@
     audio_devices = NULL;
     //g_list_free(current_device);
 }
-static void remove_bonding()
+static void remove_bonding(gchar *device)
 {
+    printf("remove_bonding call\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_call(obj,"RemoveBonding",NULL,G_TYPE_STRING,bonded_dev,G_TYPE_INVALID,G_TYPE_INVALID); 
+    dbus_g_proxy_call(obj,"RemoveBonding",NULL,G_TYPE_STRING,device,G_TYPE_INVALID,G_TYPE_INVALID); 
 
 }
 void refresh_call(void)
@@ -151,22 +164,21 @@
 
 gpointer connect_call_th(void)
 {
-
     //I will have to enable the audio service if necessary 
-
-    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);
     run_agents();
+    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_call(obj,"CreateBonding",NULL,G_TYPE_STRING,current_address,G_TYPE_INVALID,G_TYPE_INVALID); 
-    return NULL;
+
+return NULL;
 }
+
 void connect_call(void)
-{   close_call();
+{ 
+    close_call();
     close_window();
     show_scan(1);
-    remove_bonding();
     current_address = g_strdup(((DeviceData*)(selected_dev->data))->address);
     connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; 
-
 }
 
 
@@ -226,7 +238,7 @@
     printf("play callback\n");
     close_window();
     aud_output_plugin_cleanup();
-    audacious_drct_stop();
+//    audacious_drct_stop();
     audacious_drct_play();