[svn-commits] dcb: trunk r448 - /trunk/chan_mobile.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Sep 16 06:28:55 CDT 2007


Author: dcb
Date: Sun Sep 16 06:28:54 2007
New Revision: 448

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=448
Log:
Fixup module unloading when only headset in use

Modified:
    trunk/chan_mobile.c

Modified: trunk/chan_mobile.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/chan_mobile.c?view=diff&rev=448&r1=447&r2=448
==============================================================================
--- trunk/chan_mobile.c (original)
+++ trunk/chan_mobile.c Sun Sep 16 06:28:54 2007
@@ -117,7 +117,7 @@
 	int hci_socket;					/* device descriptor */
 	char id[31];					/* the 'name' from mobile.conf */
 	bdaddr_t addr;					/* adddress of adapter */
-	unsigned int inuse:1;			/* are we in use ? */
+	unsigned int inuse:1;				/* are we in use ? */
 	int sco_socket;
 	AST_LIST_ENTRY(adapter_pvt) entry;
 };
@@ -187,7 +187,7 @@
 static struct ast_cli_entry mbl_cli[] = {
 	{{"mobile", "show", "devices", NULL}, do_show_devices, "Show Bluetooth Cell / Mobile devices", show_usage},
 	{{"mobile", "search", NULL}, do_search_devices, "Search for Bluetooth Cell / Mobile devices", search_usage},
-	{{"mobile", "rfcomm", NULL}, do_send_rfcomm, "Send commands to the rfcomm port for debugging", rfcomm_usage}
+	{{"mobile", "rfcomm", NULL}, do_send_rfcomm, "Send commands to the rfcomm port for debugging", rfcomm_usage},
 };
 
 /* App stuff */
@@ -764,8 +764,9 @@
 		io_need = DEVICE_FRAME_SIZE - pvt->io_save_len;
 		memcpy(pvt->io_save_buf + pvt->io_save_len, frame->data, io_need);
 		sco_write(pvt->sco_socket, pvt->io_save_buf, DEVICE_FRAME_SIZE);
-		if ((r = sco_read(pvt->sco_socket, buf, DEVICE_FRAME_SIZE)))
+		if ((r = sco_read(pvt->sco_socket, buf, DEVICE_FRAME_SIZE))) {
 			sco_write(pvt->io_pipe[1], buf, r);
+		}
 	}
 	
 	num_frames = (frame->datalen - io_need) / DEVICE_FRAME_SIZE;
@@ -773,8 +774,9 @@
 
 	for (i=0; i<num_frames; i++) {
 		sco_write(pvt->sco_socket, pfr, DEVICE_FRAME_SIZE);
-		if ((r = sco_read(pvt->sco_socket, buf, DEVICE_FRAME_SIZE)))
+		if ((r = sco_read(pvt->sco_socket, buf, DEVICE_FRAME_SIZE))) {
 			sco_write(pvt->io_pipe[1], buf, r);
+		}
 		pfr += DEVICE_FRAME_SIZE;
 	}
 
@@ -1285,7 +1287,6 @@
 					pvt->state = MBL_STATE_PREIDLE;
 				} else if (strstr(buf, "ERROR")) {
 					pvt->has_sms = 0;
-					ast_log(LOG_NOTICE, "Device %s has no bluetooth SMS capability.\n", pvt->id);
 					pvt->state = MBL_STATE_PREIDLE;
 				}
 				break;
@@ -1500,21 +1501,24 @@
 
 	}
 
-	close(pvt->rfcomm_socket);
-	close(pvt->sco_socket);
+	if (pvt->rfcomm_socket > -1)
+		close(pvt->rfcomm_socket);
+	if (pvt->sco_socket > -1)
+		close(pvt->sco_socket);
 	pvt->sco_socket = -1;
 	pvt->connected = 0;
 	pvt->monitor_thread = AST_PTHREADT_NULL;
 	
 	pthread_cancel(pvt->sco_listener_thread);
 	pthread_join(pvt->sco_listener_thread, NULL);
+	pvt->sco_listener_thread = AST_PTHREADT_NULL;
 	
 	close(pvt->adapter->sco_socket);
 	
 	manager_event(EVENT_FLAG_SYSTEM, "MobileStatus", "Status: Disconnect\r\nDevice: %s\r\n", pvt->id);
 
 	pvt->adapter->inuse = 0;
-	
+
 	return NULL;
 
 }
@@ -1586,8 +1590,10 @@
 
 	}
 
-	close(pvt->rfcomm_socket);
-	close(pvt->sco_socket);
+	if (pvt->rfcomm_socket > -1)
+		close(pvt->rfcomm_socket);
+	if (pvt->sco_socket > -1)
+		close(pvt->sco_socket);
 	pvt->sco_socket = -1;
 	pvt->connected = 0;
 	pvt->monitor_thread = AST_PTHREADT_NULL;
@@ -1844,6 +1850,7 @@
 					pvt->rfcomm_buf[0] = 0x00;
 					pvt->sco_socket = -1;
 					pvt->monitor_thread = AST_PTHREADT_NULL;
+					pvt->sco_listener_thread = AST_PTHREADT_NULL;
 					pvt->owner = NULL;
 					pvt->no_callsetup = 0;
 					pvt->has_sms = 0;
@@ -1894,11 +1901,6 @@
 		pthread_join(discovery_thread, NULL);
 	}
 	
-	/* Unregister the CLI & APP */
-	ast_cli_unregister_multiple(mbl_cli, sizeof(mbl_cli) / sizeof(mbl_cli[0]));
-	ast_unregister_application(app_mblstatus);
-	ast_unregister_application(app_mblsendsms);
-
 	/* Destroy the device list */
 	while ((pvt = AST_LIST_REMOVE_HEAD(&devices, entry))) {
 		if (pvt->monitor_thread != AST_PTHREADT_NULL) {
@@ -1930,6 +1932,11 @@
 
 	if (sdp_session)
 		sdp_close(sdp_session);
+
+	/* Unregister the CLI & APP */
+	ast_cli_unregister_multiple(mbl_cli, sizeof(mbl_cli) / sizeof(mbl_cli[0]));
+	ast_unregister_application(app_mblstatus);
+	ast_unregister_application(app_mblsendsms);
 
 	return 0;
 




More information about the svn-commits mailing list