annotate src/bluetooth/bluetooth.c @ 2857:59727b85a091

Restart dialog
author Paula Stanciu <paula.stanciu@gmail.com>
date Fri, 01 Aug 2008 23:18:21 +0300
parents 162766a69f12
children 528d19a2ea3d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2839
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
1 /*
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
2 * Audacious Bluetooth headset suport plugin
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
3 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
4 * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
5 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
6 * This program is free software; you can redistribute it and/or modify
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
7 * it under the terms of the GNU General Public License as published by
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
8 * the Free Software Foundation; under version 3 of the License.
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
9 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
10 * This program is distributed in the hope that it will be useful,
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
13 * GNU General Public License for more details.
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
14 *
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
15 * You should have received a copy of the GNU General Public License
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses>.
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
17 */
22a5075fc7f7 GPL Headers
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2838
diff changeset
18
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
19 #include <glib/gstdio.h>
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
20 #include <errno.h>
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
21 #include <string.h>
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
22 #include "bluetooth.h"
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
23 #include "marshal.h"
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
24 #include "gui.h"
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
25 #include "scan_gui.h"
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2756
diff changeset
26 #include "agent.h"
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
27 #define DEBUG 1
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
28 static gboolean plugin_active = FALSE,exiting=FALSE;
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
29 GList * current_device = NULL;
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
30 gint config = 0;
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
31 gint devices_no = 0;
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
32 GStaticMutex mutex = G_STATIC_MUTEX_INIT;
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
33 static gchar *current_address=NULL;
2845
d0cbf303869b removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2842
diff changeset
34 static GThread *connect_th;
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
35 void bluetooth_init ( void );
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
36 void bluetooth_cleanup ( void );
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
37 void bt_cfg(void);
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
38 void bt_about(void);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
39 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
40 static void discovery_started(DBusGProxy *object, gpointer user_data);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
41 static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
42 static void print_results(void);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
43 static void discovery_completed(DBusGProxy *object, gpointer user_data);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
44 void discover_devices(void);
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
45 void disconnect_dbus_signals(void);
2857
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
46 static void show_restart_dialog(void);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
47
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
48 GeneralPlugin bluetooth_gp =
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
49 {
2649
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
50 .description = "Bluetooth audio support",
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
51 .init = bluetooth_init,
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
52 .about = bt_about,
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
53 .configure = bt_cfg,
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
54 .cleanup = bluetooth_cleanup
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
55 };
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
56 GeneralPlugin *bluetooth_gplist[] = { &bluetooth_gp, NULL };
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
57 DECLARE_PLUGIN(bluetooth_gp, NULL, NULL, NULL, NULL, NULL, bluetooth_gplist, NULL, NULL)
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
58
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
59 void bluetooth_init ( void )
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
60 {
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
61 audio_devices = NULL;
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2756
diff changeset
62 bus = NULL;
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2756
diff changeset
63 obj = NULL;
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
64 discover_devices();
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
65 }
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
66
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
67 void bluetooth_cleanup ( void )
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
68 {
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
69 printf("bluetooth: exit\n");
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
70 if (config ==1 )
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
71 {
2756
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
72 close_window();
2732
1a27c497e526 indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2728
diff changeset
73 config =0;
2649
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
74 }
2732
1a27c497e526 indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2728
diff changeset
75 if(discover_finish == 2) {
1a27c497e526 indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2728
diff changeset
76 dbus_g_connection_flush (bus);
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
77 dbus_g_connection_unref(bus);
2732
1a27c497e526 indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2728
diff changeset
78 disconnect_dbus_signals();
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
79
2732
1a27c497e526 indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2728
diff changeset
80 }
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
81 }
2732
1a27c497e526 indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2728
diff changeset
82
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
83 void bt_about( void )
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
84 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
85 printf("about call\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
86 }
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
87
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
88 void bt_cfg(void)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
89 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
90 printf("bt_cfg\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
91 config =1;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
92 if(discover_finish == 2){
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
93 if (devices_no == 0){
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
94 printf("no devs!\n");
2847
671cdfc2d62d Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2846
diff changeset
95 show_scan(0);
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
96 show_no_devices();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
97 }else
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
98 results_ui();
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
99 }
2847
671cdfc2d62d Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2846
diff changeset
100 else show_scan(0);
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
101 printf("end of bt_cfg\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
102 }
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
103
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
104 void disconnect_dbus_signals()
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
105 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
106 dbus_g_proxy_disconnect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
107 dbus_g_proxy_disconnect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
108 dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
109 dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL);
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
110
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
111 }
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
112
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
113 void clean_devices_list()
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
114 {
2756
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
115 g_list_free(audio_devices);
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
116 dbus_g_connection_flush (bus);
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
117 dbus_g_connection_unref(bus);
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
118 audio_devices = NULL;
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
119 //g_list_free(current_device);
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
120 }
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
121
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
122 void refresh_call(void)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
123 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
124 printf("refresh function called\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
125 disconnect_dbus_signals();
2756
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
126 clean_devices_list();
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
127 if(discover_finish == 0 ||discover_finish== 2){
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
128 discover_finish = 0;
2756
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
129
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
130 discover_devices();
2756
d3d71539d675 rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2734
diff changeset
131 close_window();
2847
671cdfc2d62d Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2846
diff changeset
132 show_scan(0);
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
133 }
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
134 else
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
135 printf("Scanning please wait!\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
136 }
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
137
2845
d0cbf303869b removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2842
diff changeset
138 gpointer connect_call_th(void)
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
139 {
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
140
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
141 //I will have to enable the audio service if necessary
2838
22a2ffe86750 added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2756
diff changeset
142
2845
d0cbf303869b removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2842
diff changeset
143 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);
2841
9637eab5a3dd indentation
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2840
diff changeset
144 run_agents();
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
145 dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,current_address,G_TYPE_INVALID,G_TYPE_INVALID);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
146
2845
d0cbf303869b removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2842
diff changeset
147 }
d0cbf303869b removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2842
diff changeset
148 void connect_call(void)
d0cbf303869b removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2842
diff changeset
149 {
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
150 current_address = g_strdup(((DeviceData*)(selected_dev->data))->address);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
151 connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
152 close_call();
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
153 close_window();
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
154 show_scan(1);
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
155 }
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
156
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
157
2854
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
158 void play_call()
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
159 {
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
160
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
161 FILE *file;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
162 FILE *temp_file;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
163 gint prev=0;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
164 char line[128];
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
165 gchar *home;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
166 gchar *device_line;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
167 gchar *file_name="";
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
168 gchar *temp_file_name;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
169 int ret = EOF+1;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
170 home = g_get_home_dir();
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
171 file_name = g_strconcat(home,"/.asoundrc",NULL);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
172 temp_file_name = g_strconcat(home,"/temp_bt",NULL);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
173 file = fopen(file_name,"r");
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
174 temp_file = fopen(temp_file_name,"w");
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
175 /* hardcoded address TO REMOVE after testing */
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
176 // current_address = "00:0D:3C:B1:1C:7A";
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
177 device_line = g_strdup_printf("device %s\n",current_address);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
178 if ( file != NULL )
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
179 {
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
180 while ( fgets ( line, sizeof line, file ) != NULL )
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
181 {
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
182 if(!(strcmp(line,"pcm.audacious_bt {\n"))){
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
183 fputs(line,temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
184 fgets ( line, sizeof line, file ); /* type bluetooth */
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
185 fputs(line,temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
186 fgets ( line, sizeof line, file ); /* device MAC */
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
187 fputs(device_line,temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
188 prev = 1;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
189 } else
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
190 fputs(line,temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
191 }
2854
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
192
2855
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
193 fclose (file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
194 }
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
195 if(!prev){
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
196 fputs("pcm.audacious_bt{\n",temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
197 fputs("type bluetooth\n",temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
198 fputs(device_line,temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
199 fputs("}\n",temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
200 prev = 0;
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
201 }
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
202
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
203 fclose(temp_file);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
204 int err = rename(temp_file_name,file_name);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
205 printf("rename error : %d",err);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
206 perror("zz");
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
207 g_free(device_line);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
208 g_free(file_name);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
209 g_free(temp_file_name);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
210 mcs_handle_t *cfgfile = aud_cfg_db_open();
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
211 aud_cfg_db_set_string(cfgfile,"ALSA","pcm_device", "audacious_bt");
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
212 aud_cfg_db_close(cfgfile);
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
213
162766a69f12 bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2854
diff changeset
214 printf("play callback\n");
2857
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
215 close_window();
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
216 show_restart_dialog();
2854
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
217
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
218
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
219 }
2857
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
220 static void show_restart_dialog()
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
221 {
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
222 static GtkWidget *window = NULL;
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
223 GtkWidget *dialog;
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
224 dialog = gtk_message_dialog_new (GTK_WINDOW (window),
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
225 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
226 GTK_MESSAGE_INFO,
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
227 GTK_BUTTONS_OK,
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
228 "Please restart the player to apply the bluetooth audio settings!");
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
229 gtk_dialog_run (GTK_DIALOG (dialog));
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
230 gtk_widget_destroy (dialog);
59727b85a091 Restart dialog
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2855
diff changeset
231 }
2854
43557eb3180f playback
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2847
diff changeset
232
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
233 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
234 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
235 int found_in_list=FALSE;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
236 g_static_mutex_lock(&mutex);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
237 current_device = audio_devices;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
238 if((class & 0x200404)==0x200404)
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
239 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
240 while(current_device != NULL)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
241 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
242 if(g_str_equal(address,((DeviceData*)(current_device->data))->address))
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
243 {
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
244 found_in_list = TRUE;
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
245 break;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
246 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
247 current_device=g_list_next(current_device);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
248 }
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
249 if(!found_in_list)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
250 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
251 DeviceData *dev= g_new0(DeviceData, 1);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
252 dev->class = class;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
253 dev->address = g_strdup(address);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
254 dev->name = NULL;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
255 audio_devices=g_list_prepend(audio_devices, dev);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
256 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
257 }
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
258 g_static_mutex_unlock(&mutex);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
259 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
260
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
261 static void discovery_started(DBusGProxy *object, gpointer user_data)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
262 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
263 g_print("Signal: DiscoveryStarted()\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
264 discover_finish = 1;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
265 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
266
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
267 static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
268 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
269 g_static_mutex_lock(&mutex);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
270 current_device=audio_devices;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
271 while(current_device != NULL)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
272 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
273 if(g_str_equal(address,((DeviceData*)(current_device->data))->address))
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
274 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
275 ((DeviceData*)(current_device->data))->name=g_strdup(name);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
276 break;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
277 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
278 current_device=g_list_next(current_device);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
279 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
280 g_static_mutex_unlock(&mutex);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
281 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
282
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
283 static void print_results()
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
284 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
285 int i=0;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
286 g_print("Final Scan results:\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
287 devices_no = g_list_length(audio_devices);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
288 g_print("Number of audio devices: %d \n",devices_no);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
289 if(devices_no==0 ) {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
290 if(config ==1) show_no_devices();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
291 } else {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
292 current_device=audio_devices;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
293 while(current_device != NULL)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
294 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
295 g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i,
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
296 ((DeviceData*)(current_device->data))-> name,
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
297 ((DeviceData*)(current_device->data))-> class,
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
298 ((DeviceData*)(current_device->data))-> address);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
299 current_device=g_list_next(current_device);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
300 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
301 destroy_scan_window();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
302 if(config==1) {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
303 destroy_scan_window();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
304 results_ui();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
305 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
306 // refresh_tree();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
307 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
308 }
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
309
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
310
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
311
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
312 static void discovery_completed(DBusGProxy *object, gpointer user_data)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
313 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
314 g_print("Signal: DiscoveryCompleted()\n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
315 discover_finish =2;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
316 print_results();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
317 }
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
318
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
319
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
320
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
321 void discover_devices(void)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
322 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
323 GError *error = NULL;
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
324 // g_type_init();
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
325 g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
326 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
327 if (error != NULL)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
328 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
329 g_printerr("Connecting to system bus failed: %s\n", error->message);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
330 g_error_free(error);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
331 }
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
332 obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
333 printf("bluetooth plugin - start discovery \n");
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
334 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);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
335
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
336 dbus_g_proxy_add_signal(obj, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
337 dbus_g_proxy_connect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus, NULL);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
338
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
339 dbus_g_proxy_add_signal(obj, "DiscoveryStarted", G_TYPE_INVALID);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
340 dbus_g_proxy_connect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus, NULL);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
341
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
342 dbus_g_proxy_add_signal(obj, "DiscoveryCompleted", G_TYPE_INVALID);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
343 dbus_g_proxy_connect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus, NULL);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
344
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
345 dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
346
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
347 dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
348 dbus_g_proxy_connect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL, NULL);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
349
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
350 dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
351 if (error != NULL)
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
352 {
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
353 g_printerr("Failed to discover devices: %s\n", error->message);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
354 g_error_free(error);
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
355 }
2728
229647ca4942 added some UI stuff
paula@crocodil
parents: 2649
diff changeset
356
2734
8a102490a8c0 compilation fix
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2732
diff changeset
357 }