comparison src/bluetooth/bluetooth.c @ 2889:6c53f9fa9029

Backed out changeset 59ff744e1e23
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 12 Aug 2008 20:29:49 +0300
parents 162766a69f12
children 5e97b55f87cf
comparison
equal deleted inserted replaced
2856:59ff744e1e23 2889:6c53f9fa9029
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses>. 16 * along with this program. If not, see <http://www.gnu.org/licenses>.
17 */ 17 */
18 18
19 #include <glib/gstdio.h>
20 #include <errno.h>
21 #include <string.h>
22 #include "bluetooth.h" 19 #include "bluetooth.h"
23 #include "marshal.h" 20 #include "marshal.h"
24 #include "gui.h" 21 #include "gui.h"
25 #include "scan_gui.h" 22 #include "scan_gui.h"
26 #include "agent.h" 23 #include "agent.h"
28 static gboolean plugin_active = FALSE,exiting=FALSE; 25 static gboolean plugin_active = FALSE,exiting=FALSE;
29 GList * current_device = NULL; 26 GList * current_device = NULL;
30 gint config = 0; 27 gint config = 0;
31 gint devices_no = 0; 28 gint devices_no = 0;
32 GStaticMutex mutex = G_STATIC_MUTEX_INIT; 29 GStaticMutex mutex = G_STATIC_MUTEX_INIT;
33 static gchar *current_address=NULL;
34 static GThread *connect_th; 30 static GThread *connect_th;
35 void bluetooth_init ( void ); 31 void bluetooth_init ( void );
36 void bluetooth_cleanup ( void ); 32 void bluetooth_cleanup ( void );
37 void bt_cfg(void); 33 void bt_cfg(void);
38 void bt_about(void); 34 void bt_about(void);
65 } 61 }
66 62
67 void bluetooth_cleanup ( void ) 63 void bluetooth_cleanup ( void )
68 { 64 {
69 printf("bluetooth: exit\n"); 65 printf("bluetooth: exit\n");
70 if (config ==1 ) 66 if (config ==1 ){
71 {
72 close_window(); 67 close_window();
73 config =0; 68 config =0;
74 } 69 }
75 if(discover_finish == 2) { 70 if(discover_finish == 2) {
76 dbus_g_connection_flush (bus); 71 dbus_g_connection_flush (bus);
108 dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus); 103 dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus);
109 dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL); 104 dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL);
110 105
111 } 106 }
112 107
113 void clean_devices_list() 108 void clean_devices_list(){
114 {
115 g_list_free(audio_devices); 109 g_list_free(audio_devices);
116 dbus_g_connection_flush (bus); 110 dbus_g_connection_flush (bus);
117 dbus_g_connection_unref(bus); 111 dbus_g_connection_unref(bus);
118 audio_devices = NULL; 112 audio_devices = NULL;
119 //g_list_free(current_device); 113 //g_list_free(current_device);
140 134
141 //I will have to enable the audio service if necessary 135 //I will have to enable the audio service if necessary
142 136
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); 137 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);
144 run_agents(); 138 run_agents();
145 dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,current_address,G_TYPE_INVALID,G_TYPE_INVALID); 139 dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,((DeviceData*)(selected_dev->data))->address,G_TYPE_INVALID,G_TYPE_INVALID);
146 140
147 } 141 }
148 void connect_call(void) 142 void connect_call(void)
149 { 143 {
150 current_address = g_strdup(((DeviceData*)(selected_dev->data))->address); 144 connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ;
151 connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; 145 close_call();
152 close_call(); 146 close_window();
153 close_window(); 147 show_scan(1);
154 show_scan(1);
155 }
156
157
158 void play_call()
159 {
160
161 FILE *file;
162 FILE *temp_file;
163 gint prev=0;
164 char line[128];
165 gchar *home;
166 gchar *device_line;
167 gchar *file_name="";
168 gchar *temp_file_name;
169 int ret = EOF+1;
170 home = g_get_home_dir();
171 file_name = g_strconcat(home,"/.asoundrc",NULL);
172 temp_file_name = g_strconcat(home,"/temp_bt",NULL);
173 file = fopen(file_name,"r");
174 temp_file = fopen(temp_file_name,"w");
175 /* hardcoded address TO REMOVE after testing */
176 // current_address = "00:0D:3C:B1:1C:7A";
177 device_line = g_strdup_printf("device %s\n",current_address);
178 if ( file != NULL )
179 {
180 while ( fgets ( line, sizeof line, file ) != NULL )
181 {
182 if(!(strcmp(line,"pcm.audacious_bt {\n"))){
183 fputs(line,temp_file);
184 fgets ( line, sizeof line, file ); /* type bluetooth */
185 fputs(line,temp_file);
186 fgets ( line, sizeof line, file ); /* device MAC */
187 fputs(device_line,temp_file);
188 prev = 1;
189 } else
190 fputs(line,temp_file);
191 }
192
193 fclose (file);
194 }
195 if(!prev){
196 fputs("pcm.audacious_bt{\n",temp_file);
197 fputs("type bluetooth\n",temp_file);
198 fputs(device_line,temp_file);
199 fputs("}\n",temp_file);
200 prev = 0;
201 }
202
203 fclose(temp_file);
204 int err = rename(temp_file_name,file_name);
205 printf("rename error : %d",err);
206 perror("zz");
207 g_free(device_line);
208 g_free(file_name);
209 g_free(temp_file_name);
210 mcs_handle_t *cfgfile = aud_cfg_db_open();
211 aud_cfg_db_set_string(cfgfile,"ALSA","pcm_device", "audacious_bt");
212 aud_cfg_db_close(cfgfile);
213
214 printf("play callback\n");
215
216
217 } 148 }
218 149
219 150
220 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data) 151 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data)
221 { 152 {