linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] [DBUS PATCH] Disconnect
@ 2005-11-07 12:01 Claudio Takahasi
  2005-11-08 16:29 ` [Bluez-devel] " Claudio Takahasi
  0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-11-07 12:01 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

Hi,

Here is patch do handle the dbus system "Disconnect" signal.

When the signal is received, a timer is started to try reconnect to
the system bus each 5sec.


Regards,
Claudio.
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: disconnect.patch --]
[-- Type: text/x-patch, Size: 4237 bytes --]

--- bluez-utils-cvs.orig/hcid/dbus.c	2005-11-07 08:04:29.000000000 -0200
+++ bluez-utils-cvs-hcid/hcid/dbus.c	2005-11-07 08:54:30.000000000 -0200
@@ -28,10 +28,12 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
+#include <signal.h>
 #include <string.h>
 #include <syslog.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
@@ -50,6 +52,8 @@
 #define TIMEOUT				(30 * 1000)	/* 30 seconds */
 #define MAX_PATH_LENGTH			64
 #define MAX_CONN_NUMBER			10
+#define DBUS_RECONNECT_TIMER		5000000 /* 5 sec */
+
 
 #define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
 #define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -890,18 +894,18 @@
 	connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
 
 	if (dbus_error_is_set(&error)) {
-		syslog(LOG_ERR, "Can't open system message bus connection: %s",
-								error.message);
+		syslog(LOG_ERR, "dbus_bus_get: %s", error.message);
 		dbus_error_free(&error);
 		return FALSE;
 	}
 
+	dbus_connection_set_exit_on_disconnect(connection, FALSE);
+
 	dbus_bus_request_name(connection, BASE_INTERFACE,
 				DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &error);
 
 	if (dbus_error_is_set(&error)) {
-		syslog(LOG_ERR, "Can't get system message bus name: %s",
-								error.message);
+		syslog(LOG_ERR, "dbus_bus_request_name: %s", error.message);
 		dbus_error_free(&error);
 		return FALSE;
 	}
@@ -1155,6 +1159,84 @@
 
 /*****************************************************************
  *  
+ *    Section reserved to re-connection timer
+ *     
+ ******************************************************************/
+void reconnect_timer_handler(int signum)
+{
+	struct hci_dev_list_req *dl = NULL;
+	struct hci_dev_req *dr;
+	int sk;
+	int i;
+
+	if (hcid_dbus_init() == FALSE) 
+		return;
+
+	/* stop the timer */
+	sigaction(SIGALRM, NULL, NULL);
+	setitimer(ITIMER_REAL, NULL, NULL);
+
+	/* register the device based paths */
+
+	/* Create and bind HCI socket */
+	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+	if (sk < 0) {
+		syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
+		return;
+	}
+
+	if (!(dl = malloc(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(uint16_t)))) {
+		syslog(LOG_INFO, "Can't allocate devlist buffer: %s (%d)",
+		       strerror(errno), errno);
+		return;
+	}
+	dl->dev_num = HCI_MAX_DEV;
+	dr = dl->dev_req;
+
+	if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
+		syslog(LOG_INFO, "Can't get device list: %s (%d)",
+		       strerror(errno), errno);
+		goto failed;
+	}
+
+	/* reset the default device */
+	default_dev = -1;
+
+	for (i = 0; i < dl->dev_num; i++, dr++) {
+
+		hcid_dbus_register_device(dr->dev_id);
+
+		if (hci_test_bit(HCI_UP, &dr->dev_opt))
+			hcid_dbus_dev_up(dr->dev_id);
+	}
+failed:
+	if (dl)
+		free(dl);
+
+}
+
+void reconnect_timer_start(void)
+{
+	struct sigaction sa;
+	struct itimerval timer;
+
+	memset (&sa, 0, sizeof (sa));
+	sa.sa_handler = &reconnect_timer_handler;
+	sigaction(SIGALRM, &sa, NULL);
+
+	/* expire after X  msec... */
+	timer.it_value.tv_sec = 0;
+	timer.it_value.tv_usec = DBUS_RECONNECT_TIMER;
+
+	/* ... and every x msec after that. */
+	timer.it_interval.tv_sec = 0;
+	timer.it_interval.tv_usec = DBUS_RECONNECT_TIMER;
+
+	setitimer(ITIMER_REAL, &timer, NULL);
+}
+
+/*****************************************************************
+ *  
  *  Section reserved to HCI D-Bus services 
  *  
  *****************************************************************/
@@ -1173,9 +1255,14 @@
 	iface = dbus_message_get_interface(msg);
 	method = dbus_message_get_member(msg);
 
-	if (strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) {
-		if (strcmp(method, "Disconnected") == 0)
-			ret = DBUS_HANDLER_RESULT_HANDLED;
+	if ((strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) && 
+	    (strcmp(method, "Disconnected") == 0)) {
+		syslog(LOG_ERR, "Got disconnected from the system message bus");
+		dbus_connection_dispatch(conn);
+		dbus_connection_close(conn);
+		dbus_connection_unref(conn);
+		reconnect_timer_start();
+		ret = DBUS_HANDLER_RESULT_HANDLED;
 	} else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
 		if (strcmp(method, "NameOwnerChanged") == 0)
 			ret = DBUS_HANDLER_RESULT_HANDLED;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bluez-devel] Re: [DBUS PATCH] Disconnect
  2005-11-07 12:01 [Bluez-devel] [DBUS PATCH] Disconnect Claudio Takahasi
@ 2005-11-08 16:29 ` Claudio Takahasi
  2005-11-08 22:22   ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-11-08 16:29 UTC (permalink / raw)
  To: bluez-devel

Hi Marcel,

Do you have any comments about this patch?

In order to see how it works restart the dbus-daemon
$/etc/init.d/dbus-1 stop
$/etc/init.d/dbus-1 start


Regards,
Claudio.

On 11/7/05, Claudio Takahasi <cktakahasi@gmail.com> wrote:
> Hi,
>
> Here is patch do handle the dbus system "Disconnect" signal.
>
> When the signal is received, a timer is started to try reconnect to
> the system bus each 5sec.
>
>
> Regards,
> Claudio.
> --
> ---------------------------------------------------------
> Claudio Takahasi
> Instituto Nokia de Tecnologia - INdT
>
>
>


--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Bluez-devel] Re: [DBUS PATCH] Disconnect
  2005-11-08 16:29 ` [Bluez-devel] " Claudio Takahasi
@ 2005-11-08 22:22   ` Marcel Holtmann
  2005-11-08 23:11     ` Johan Hedberg
  0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2005-11-08 22:22 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> Do you have any comments about this patch?

not yet, still looking at it.

Johan, any comments from you?

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Bluez-devel] Re: [DBUS PATCH] Disconnect
  2005-11-08 22:22   ` Marcel Holtmann
@ 2005-11-08 23:11     ` Johan Hedberg
  2005-11-09 13:14       ` Claudio Takahasi
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Hedberg @ 2005-11-08 23:11 UTC (permalink / raw)
  To: bluez-devel

On Tue, Nov 08, 2005, Marcel Holtmann wrote:
> > Do you have any comments about this patch?
> 
> not yet, still looking at it.
> 
> Johan, any comments from you?

Not really, except that it seems to work ;-)

At least after a quick read-through the patch looks ok.

Johan


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Bluez-devel] Re: [DBUS PATCH] Disconnect
  2005-11-08 23:11     ` Johan Hedberg
@ 2005-11-09 13:14       ` Claudio Takahasi
  2005-11-09 15:52         ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-11-09 13:14 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1176 bytes --]

Hi Marcel,

If the first "disconnect" patch is not integrated yet, please ignore
it. It was missing close the HCI socket :)  and I changed some code
style.

Regards,
Claudio.


On 11/8/05, Johan Hedberg <johan.hedberg@nokia.com> wrote:
> On Tue, Nov 08, 2005, Marcel Holtmann wrote:
> > > Do you have any comments about this patch?
> >
> > not yet, still looking at it.
> >
> > Johan, any comments from you?
>
> Not really, except that it seems to work ;-)
>
> At least after a quick read-through the patch looks ok.
>
> Johan
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: disconnect_02.patch --]
[-- Type: text/x-patch, Size: 4215 bytes --]

--- bluez-utils-cvs.orig/hcid/dbus.c	2005-11-09 09:38:04.000000000 -0200
+++ bluez-utils-cvs-hcid-disconn/hcid/dbus.c	2005-11-09 10:04:53.000000000 -0200
@@ -28,10 +28,12 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
+#include <signal.h>
 #include <string.h>
 #include <syslog.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
@@ -50,6 +52,8 @@
 #define TIMEOUT				(30 * 1000)	/* 30 seconds */
 #define MAX_PATH_LENGTH			64
 #define MAX_CONN_NUMBER			10
+#define DBUS_RECONNECT_TIMER		5000000 /* 5 sec */
+
 
 #define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
 #define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -892,18 +896,18 @@
 	connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
 
 	if (dbus_error_is_set(&error)) {
-		syslog(LOG_ERR, "Can't open system message bus connection: %s",
-								error.message);
+		syslog(LOG_ERR, "dbus_bus_get: %s", error.message);
 		dbus_error_free(&error);
 		return FALSE;
 	}
 
+	dbus_connection_set_exit_on_disconnect(connection, FALSE);
+
 	dbus_bus_request_name(connection, BASE_INTERFACE,
 				DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &error);
 
 	if (dbus_error_is_set(&error)) {
-		syslog(LOG_ERR, "Can't get system message bus name: %s",
-								error.message);
+		syslog(LOG_ERR, "dbus_bus_request_name: %s", error.message);
 		dbus_error_free(&error);
 		return FALSE;
 	}
@@ -1157,6 +1161,88 @@
 
 /*****************************************************************
  *  
+ *    Section reserved to re-connection timer
+ *     
+ ******************************************************************/
+void reconnect_timer_handler(int signum)
+{
+	struct hci_dev_list_req *dl = NULL;
+	struct hci_dev_req *dr;
+	int sk;
+	int i;
+
+	if (hcid_dbus_init() == FALSE) 
+		return;
+
+	/* stop the timer */
+	sigaction(SIGALRM, NULL, NULL);
+	setitimer(ITIMER_REAL, NULL, NULL);
+
+	/* register the device based paths */
+
+	/* Create and bind HCI socket */
+	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+	if (sk < 0) {
+		syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
+		return;
+	}
+
+	dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+	if (!dl) {
+		syslog(LOG_ERR, "Can't allocate memory");
+		goto failed;
+	}
+
+	dl->dev_num = HCI_MAX_DEV;
+	dr = dl->dev_req;
+
+	if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
+		syslog(LOG_INFO, "Can't get device list: %s (%d)",
+		       strerror(errno), errno);
+		goto failed;
+	}
+
+	/* reset the default device */
+	default_dev = -1;
+
+	for (i = 0; i < dl->dev_num; i++, dr++) {
+
+		hcid_dbus_register_device(dr->dev_id);
+
+		if (hci_test_bit(HCI_UP, &dr->dev_opt))
+			hcid_dbus_dev_up(dr->dev_id);
+	}
+failed:
+	if (sk >= 0)
+		close(sk);
+
+	if (dl)
+		free(dl);
+
+}
+
+void reconnect_timer_start(void)
+{
+	struct sigaction sa;
+	struct itimerval timer;
+
+	memset (&sa, 0, sizeof (sa));
+	sa.sa_handler = &reconnect_timer_handler;
+	sigaction(SIGALRM, &sa, NULL);
+
+	/* expire after X  msec... */
+	timer.it_value.tv_sec = 0;
+	timer.it_value.tv_usec = DBUS_RECONNECT_TIMER;
+
+	/* ... and every x msec after that. */
+	timer.it_interval.tv_sec = 0;
+	timer.it_interval.tv_usec = DBUS_RECONNECT_TIMER;
+
+	setitimer(ITIMER_REAL, &timer, NULL);
+}
+
+/*****************************************************************
+ *  
  *  Section reserved to HCI D-Bus services 
  *  
  *****************************************************************/
@@ -1175,9 +1261,14 @@
 	iface = dbus_message_get_interface(msg);
 	method = dbus_message_get_member(msg);
 
-	if (strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) {
-		if (strcmp(method, "Disconnected") == 0)
-			ret = DBUS_HANDLER_RESULT_HANDLED;
+	if ((strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) && 
+	    (strcmp(method, "Disconnected") == 0)) {
+		syslog(LOG_ERR, "Got disconnected from the system message bus");
+		dbus_connection_dispatch(conn);
+		dbus_connection_close(conn);
+		dbus_connection_unref(conn);
+		reconnect_timer_start();
+		ret = DBUS_HANDLER_RESULT_HANDLED;
 	} else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
 		if (strcmp(method, "NameOwnerChanged") == 0)
 			ret = DBUS_HANDLER_RESULT_HANDLED;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Bluez-devel] Re: [DBUS PATCH] Disconnect
  2005-11-09 13:14       ` Claudio Takahasi
@ 2005-11-09 15:52         ` Marcel Holtmann
  2005-11-09 16:36           ` Claudio Takahasi
  0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2005-11-09 15:52 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> If the first "disconnect" patch is not integrated yet, please ignore
> it. It was missing close the HCI socket :)  and I changed some code
> style.

please redo this patch, because I am not fully happy with it. The
DBUS_RECONNECT_TIME should be defined (5 * 1000 * 1000) to make it easy
for people to change it. The compile will optimize this away anyhow.

Please don't change any error messages to repeat the function name. This
is not helpful if you are really looking for problems. Using grep inside
the source to find a error message is really helpful.

Can't reconnect_timer_handler() and reconnect_timer_start() be static?

Check your whitespace. There is no need to have useless whitespaces at
the end of a line. If an if-statement is over multiple lines we still
use tabes and we are not trying to align it with anything of the line
above. In fact we use two tabs to indent more then the actual code
inside the statement. See the rest of the file for examples.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Bluez-devel] Re: [DBUS PATCH] Disconnect
  2005-11-09 15:52         ` Marcel Holtmann
@ 2005-11-09 16:36           ` Claudio Takahasi
  2005-11-09 22:55             ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-11-09 16:36 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1826 bytes --]

Hi Marcel,

your suggestions were done.

Regards,
Claudio.

On 11/9/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > If the first "disconnect" patch is not integrated yet, please ignore
> > it. It was missing close the HCI socket :)  and I changed some code
> > style.
>
> please redo this patch, because I am not fully happy with it. The
> DBUS_RECONNECT_TIME should be defined (5 * 1000 * 1000) to make it easy
> for people to change it. The compile will optimize this away anyhow.
>
> Please don't change any error messages to repeat the function name. This
> is not helpful if you are really looking for problems. Using grep inside
> the source to find a error message is really helpful.
>
> Can't reconnect_timer_handler() and reconnect_timer_start() be static?
>
> Check your whitespace. There is no need to have useless whitespaces at
> the end of a line. If an if-statement is over multiple lines we still
> use tabes and we are not trying to align it with anything of the line
> above. In fact we use two tabs to indent more then the actual code
> inside the statement. See the rest of the file for examples.
>
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>


--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: disconnect_03.patch --]
[-- Type: text/x-patch, Size: 3657 bytes --]

--- bluez-utils-cvs.orig/hcid/dbus.c	2005-11-09 09:38:04.000000000 -0200
+++ bluez-utils-cvs-hcid-disconn/hcid/dbus.c	2005-11-09 13:25:31.000000000 -0200
@@ -28,10 +28,12 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
+#include <signal.h>
 #include <string.h>
 #include <syslog.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
@@ -50,6 +52,8 @@
 #define TIMEOUT				(30 * 1000)	/* 30 seconds */
 #define MAX_PATH_LENGTH			64
 #define MAX_CONN_NUMBER			10
+#define DBUS_RECONNECT_TIMER		(5 * 1000 * 1000) /* 5 sec */
+
 
 #define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
 #define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -898,6 +902,8 @@
 		return FALSE;
 	}
 
+	dbus_connection_set_exit_on_disconnect(connection, FALSE);
+
 	dbus_bus_request_name(connection, BASE_INTERFACE,
 				DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &error);
 
@@ -1156,6 +1162,88 @@
 }
 
 /*****************************************************************
+ *
+ *	Section reserved to re-connection timer
+ *
+ *****************************************************************/
+static void reconnect_timer_handler(int signum)
+{
+	struct hci_dev_list_req *dl = NULL;
+	struct hci_dev_req *dr;
+	int sk;
+	int i;
+
+	if (hcid_dbus_init() == FALSE)
+		return;
+
+	/* stop the timer */
+	sigaction(SIGALRM, NULL, NULL);
+	setitimer(ITIMER_REAL, NULL, NULL);
+
+	/* register the device based paths */
+
+	/* Create and bind HCI socket */
+	sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+	if (sk < 0) {
+		syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
+		return;
+	}
+
+	dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+	if (!dl) {
+		syslog(LOG_ERR, "Can't allocate memory");
+		goto failed;
+	}
+
+	dl->dev_num = HCI_MAX_DEV;
+	dr = dl->dev_req;
+
+	if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
+		syslog(LOG_INFO, "Can't get device list: %s (%d)",
+		       strerror(errno), errno);
+		goto failed;
+	}
+
+	/* reset the default device */
+	default_dev = -1;
+
+	for (i = 0; i < dl->dev_num; i++, dr++) {
+
+		hcid_dbus_register_device(dr->dev_id);
+
+		if (hci_test_bit(HCI_UP, &dr->dev_opt))
+			hcid_dbus_dev_up(dr->dev_id);
+	}
+failed:
+	if (sk >= 0)
+		close(sk);
+
+	if (dl)
+		free(dl);
+
+}
+
+static void reconnect_timer_start(void)
+{
+	struct sigaction sa;
+	struct itimerval timer;
+
+	memset (&sa, 0, sizeof (sa));
+	sa.sa_handler = &reconnect_timer_handler;
+	sigaction(SIGALRM, &sa, NULL);
+
+	/* expire after X  msec... */
+	timer.it_value.tv_sec = 0;
+	timer.it_value.tv_usec = DBUS_RECONNECT_TIMER;
+
+	/* ... and every x msec after that. */
+	timer.it_interval.tv_sec = 0;
+	timer.it_interval.tv_usec = DBUS_RECONNECT_TIMER;
+
+	setitimer(ITIMER_REAL, &timer, NULL);
+}
+
+/*****************************************************************
  *  
  *  Section reserved to HCI D-Bus services 
  *  
@@ -1175,9 +1263,14 @@
 	iface = dbus_message_get_interface(msg);
 	method = dbus_message_get_member(msg);
 
-	if (strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) {
-		if (strcmp(method, "Disconnected") == 0)
-			ret = DBUS_HANDLER_RESULT_HANDLED;
+	if ((strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) &&
+			(strcmp(method, "Disconnected") == 0)) {
+		syslog(LOG_ERR, "Got disconnected from the system message bus");
+		dbus_connection_dispatch(conn);
+		dbus_connection_close(conn);
+		dbus_connection_unref(conn);
+		reconnect_timer_start();
+		ret = DBUS_HANDLER_RESULT_HANDLED;
 	} else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
 		if (strcmp(method, "NameOwnerChanged") == 0)
 			ret = DBUS_HANDLER_RESULT_HANDLED;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Bluez-devel] Re: [DBUS PATCH] Disconnect
  2005-11-09 16:36           ` Claudio Takahasi
@ 2005-11-09 22:55             ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2005-11-09 22:55 UTC (permalink / raw)
  To: bluez-devel

Hi Claudio,

> your suggestions were done.

thanks for the the patch. It is in the CVS now.

Regards

Marcel




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-11-09 22:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-07 12:01 [Bluez-devel] [DBUS PATCH] Disconnect Claudio Takahasi
2005-11-08 16:29 ` [Bluez-devel] " Claudio Takahasi
2005-11-08 22:22   ` Marcel Holtmann
2005-11-08 23:11     ` Johan Hedberg
2005-11-09 13:14       ` Claudio Takahasi
2005-11-09 15:52         ` Marcel Holtmann
2005-11-09 16:36           ` Claudio Takahasi
2005-11-09 22:55             ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).