annotate src/bluetooth/bluetooth.c @ 2649:d891ba4be5a5

fixed crash when prefs window was closed while scanning
author Paula Stanciu <paula.stanciu@gmail.com>
date Sun, 25 May 2008 23:04:33 +0300
parents 6cc858a726b8
children 229647ca4942
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
1 #include <dbus/dbus.h>
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
2 #include <dbus/dbus-glib.h>
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
3 #include <glib-object.h>
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
4 #include <stdio.h>
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
5 #include "bluetooth.h"
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
6 #include "marshal.h"
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
7 #include "gui.h"
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
8
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
9 #define DEBUG 1
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
10 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
11 GList * current_device = NULL;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
12 DBusGConnection * bus = NULL;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
13 gint discover_finish =0;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
14 GStaticMutex mutex = G_STATIC_MUTEX_INIT;
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
15
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
16 void bluetooth_init ( void );
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
17 void bluetooth_cleanup ( void );
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
18 void bt_cfg(void);
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
19 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
20 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
21 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
22 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
23 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
24 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
25 void discover_devices(void);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
26
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
27
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
28
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
29 GeneralPlugin bluetooth_gp =
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
30 {
2649
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
31 .description = "Bluetooth audio support",
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
32 .init = bluetooth_init,
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
33 .about = bt_about,
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
34 .configure = bt_cfg,
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
35 .cleanup = bluetooth_cleanup
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
36 };
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
37 GeneralPlugin *bluetooth_gplist[] = { &bluetooth_gp, NULL };
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
38 DECLARE_PLUGIN(bluetooth_gp, NULL, NULL, NULL, NULL, NULL, bluetooth_gplist, NULL, NULL)
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
39 void bluetooth_init ( void )
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
40 {
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
41 audio_devices = NULL;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
42 discover_devices();
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
43 }
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
44
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
45 void bluetooth_cleanup ( void )
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
46 {
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
47 printf("bluetooth: exit\n");
2649
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
48 if(discover_finish == 2) {
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
49 dbus_g_connection_flush (bus);
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
50 dbus_g_connection_unref(bus);
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
51 }
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
52
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
53 }
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
54 /*void bt_cfg( void )
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
55 {
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
56
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
57 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
58 */
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
59 void bt_about( void )
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
60 {
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
61
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
62 }
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
63
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
64
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
65 void refresh_call(void){
2649
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
66 if(discover_finish == 0 ||discover_finish== 2)
2648
6cc858a726b8 added the marshal files
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2646
diff changeset
67 discover_devices();
6cc858a726b8 added the marshal files
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2646
diff changeset
68 else
6cc858a726b8 added the marshal files
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2646
diff changeset
69 printf("Scanning please wait!\n");
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
70 printf("refresh function called\n");
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
71 }
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
72
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
73 void connect_call(void){
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
74 printf("connect function \n");
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
75 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
76
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
77
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
78 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
79 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
80 int found_in_list=FALSE;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
81 g_static_mutex_lock(&mutex);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
82 current_device = audio_devices;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
83 if((class & 0x200404)==0x200404)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
84 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
85
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
86 while(current_device != NULL)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
87 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
88 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
89 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
90 found_in_list = TRUE;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
91 break;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
92 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
93 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
94 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
95 if(!found_in_list)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
96 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
97 DeviceData *dev= g_new0(DeviceData, 1);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
98 dev->class = class;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
99 dev->address = g_strdup(address);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
100 dev->name = NULL;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
101 audio_devices=g_list_prepend(audio_devices, dev);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
102
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
103 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
104 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
105 g_static_mutex_unlock(&mutex);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
106 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
107
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
108 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
109 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
110 g_print("Signal: DiscoveryStarted()\n");
2648
6cc858a726b8 added the marshal files
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2646
diff changeset
111 discover_finish = 1;
2644
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
112 }
6fd8ca4b7b17 add bluetooth plugin
Paula Stanciu <paula.stanciu@gmail.com>
parents:
diff changeset
113
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
114 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
115 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
116 g_static_mutex_lock(&mutex);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
117 current_device=audio_devices;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
118 while(current_device != NULL)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
119 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
120 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
121 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
122 ((DeviceData*)(current_device->data))->name=g_strdup(name);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
123 break;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
124 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
125 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
126 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
127 g_static_mutex_unlock(&mutex);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
128 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
129 static void print_results()
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
130 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
131 int i=0;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
132 g_print("Final Scan results:\n");
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
133 g_print("Number of audio devices: %d \n",g_list_length(audio_devices));
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
134 current_device=audio_devices;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
135 while(current_device != NULL)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
136 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
137 g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i,
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
138 ((DeviceData*)(current_device->data))-> name,
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
139 ((DeviceData*)(current_device->data))-> class,
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
140 ((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
141
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
142 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
143 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
144
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
145 refresh_tree();
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
146 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
147
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
148 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
149 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
150 g_print("Signal: DiscoveryCompleted()\n");
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
151 print_results();
2649
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
152 discover_finish =2;
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
153 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
154
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
155
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
156 void discover_devices(void){
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
157 GError *error = NULL;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
158 DBusGProxy * obj = NULL;
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
159 g_type_init();
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
160 g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
161
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
162 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
163 if (error != NULL)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
164 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
165 g_printerr("Connecting to system bus failed: %s\n", error->message);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
166 g_error_free(error);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
167 exit(EXIT_FAILURE);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
168 }
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
169 obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter");
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
170
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
171 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);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
172 dbus_g_proxy_add_signal(obj, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
173 dbus_g_proxy_connect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus, NULL);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
174
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
175 dbus_g_proxy_add_signal(obj, "DiscoveryStarted", G_TYPE_INVALID);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
176 dbus_g_proxy_connect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus, NULL);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
177
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
178 dbus_g_proxy_add_signal(obj, "DiscoveryCompleted", G_TYPE_INVALID);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
179 dbus_g_proxy_connect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus, NULL);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
180
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
181 dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
182 dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
183 dbus_g_proxy_connect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL, NULL);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
184
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
185 dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
186 if (error != NULL)
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
187 {
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
188 g_printerr("Failed to discover devices: %s\n", error->message);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
189 g_error_free(error);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
190 exit(EXIT_FAILURE);
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
191 }
2649
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
192 dbus_g_connection_flush (bus);
d891ba4be5a5 fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2648
diff changeset
193 dbus_g_connection_unref(bus);
2646
7fbff3287a56 added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents: 2644
diff changeset
194 }