Mercurial > audlegacy-plugins
annotate src/bluetooth/bluetooth.c @ 2646:7fbff3287a56
added device discovery in the plugin's prefs window
| author | Paula Stanciu <paula.stanciu@gmail.com> |
|---|---|
| date | Sun, 25 May 2008 21:29:07 +0300 |
| parents | 6fd8ca4b7b17 |
| children | 6cc858a726b8 |
| 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 | 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 | 9 #define DEBUG 1 |
| 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 | 15 |
| 16 void bluetooth_init ( void ); | |
| 17 void bluetooth_cleanup ( void ); | |
| 18 void bt_cfg(void); | |
| 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 | 29 GeneralPlugin bluetooth_gp = |
| 30 { | |
| 31 .description = "Bluetooth audio suport", | |
| 32 .init = bluetooth_init, | |
| 33 .about = bt_about, | |
| 34 .configure = bt_cfg, | |
| 35 .cleanup = bluetooth_cleanup | |
| 36 }; | |
| 37 GeneralPlugin *bluetooth_gplist[] = { &bluetooth_gp, NULL }; | |
| 38 DECLARE_PLUGIN(bluetooth_gp, NULL, NULL, NULL, NULL, NULL, bluetooth_gplist, NULL, NULL) | |
| 39 void bluetooth_init ( void ) | |
| 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 | 43 } |
| 44 | |
| 45 void bluetooth_cleanup ( void ) | |
| 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"); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
48 dbus_g_connection_flush (bus); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
49 dbus_g_connection_unref(bus); |
| 2644 | 50 |
| 51 } | |
| 52 /*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
|
53 { |
| 2644 | 54 |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
55 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
56 */ |
| 2644 | 57 void bt_about( void ) |
| 58 { | |
| 59 | |
| 60 } | |
| 61 | |
| 62 | |
| 63 void refresh_call(void){ | |
|
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 | 65 printf("refresh function called\n"); |
| 66 } | |
| 67 | |
| 68 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
|
69 printf("connect function \n"); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
70 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
71 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
72 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
73 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
|
74 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
75 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
|
76 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
|
77 current_device = audio_devices; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
78 if((class & 0x200404)==0x200404) |
|
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 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
81 while(current_device != NULL) |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
82 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
83 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
|
84 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
85 found_in_list = TRUE; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
86 break; |
|
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 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
|
89 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
90 if(!found_in_list) |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
91 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
92 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
|
93 dev->class = class; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
94 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
|
95 dev->name = NULL; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
96 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
|
97 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
98 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
99 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
100 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
|
101 } |
|
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 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
|
104 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
105 g_print("Signal: DiscoveryStarted()\n"); |
| 2644 | 106 } |
| 107 | |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
108 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
|
109 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
110 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
|
111 current_device=audio_devices; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
112 while(current_device != NULL) |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
113 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
114 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
|
115 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
116 ((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
|
117 break; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
118 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
119 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
|
120 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
121 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
|
122 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
123 static void print_results() |
|
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 int i=0; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
126 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
|
127 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
|
128 current_device=audio_devices; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
129 while(current_device != NULL) |
|
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 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
|
132 ((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
|
133 ((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
|
134 ((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
|
135 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
136 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
|
137 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
138 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
139 refresh_tree(); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
140 } |
|
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 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
|
143 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
144 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
|
145 print_results(); |
|
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 } |
|
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 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
151 void discover_devices(void){ |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
152 GError *error = NULL; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
153 DBusGProxy * obj = NULL; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
154 g_type_init(); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
155 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
|
156 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
157 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
|
158 if (error != NULL) |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
159 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
160 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
|
161 g_error_free(error); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
162 exit(EXIT_FAILURE); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
163 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
164 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
|
165 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
170 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
|
171 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
|
172 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
173 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
|
174 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
|
175 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
180 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
|
181 if (error != NULL) |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
182 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
183 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
|
184 g_error_free(error); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
185 exit(EXIT_FAILURE); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
186 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
187 // / dbus_g_connection_flush (bus); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
188 // dbus_g_connection_unref(bus); |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
189 } |
