diff --git a/ChangeLog b/ChangeLog index 7ae78056aa..5e6e9c2024 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2004-10-08 John (J5) Palmieri + + * info-daemon/NWManagerInfo.h + - (struct NetworkManagerInfo): add shutdown_timeout GSource + + * info-daemon/NWManagerInfoDbus.c + - (shutdown_callback): new function + - (nmi_dbus_filter): Create a 30 second timeout until shutdown + if NetworkManager goes away. Kill the timeout + if NetworkManager restarts before the 30 seconds + are up. + - (nmi_dbus_service_init): + - call gtk_main_quit if NetworkManager is not running + - add filters to monitor dbus service creations and + deletions + 2004-10-08 John (J5) Palmieri * panel-applet/NMWirelessApplet.c @@ -8,7 +24,7 @@ * panel-applet/NMWirelessAppletDbus.c - (nmwa_dbus_filter): changed exit to gtk_main_quit () - * panel-applet/NWManagerInfo.c + * info-daemon/NWManagerInfo.c - (main): Terminated the notification_icon_cmd array with a NULL 2004-10-08 Hendrik Brandt diff --git a/info-daemon/NetworkManagerInfo.h b/info-daemon/NetworkManagerInfo.h index a171945c57..81a90354ca 100644 --- a/info-daemon/NetworkManagerInfo.h +++ b/info-daemon/NetworkManagerInfo.h @@ -48,6 +48,8 @@ struct NMIAppInfo GtkWidget *notification_icon; */ GPid notification_icon_pid; + + GSource *shutdown_timeout; }; typedef struct NMIAppInfo NMIAppInfo; diff --git a/info-daemon/NetworkManagerInfoDbus.c b/info-daemon/NetworkManagerInfoDbus.c index 8965903bf9..5c235bacf4 100644 --- a/info-daemon/NetworkManagerInfoDbus.c +++ b/info-daemon/NetworkManagerInfoDbus.c @@ -550,7 +550,11 @@ void nmi_dbus_nmi_unregister_handler (DBusConnection *connection, void *user_dat /* do nothing */ } - +gboolean shutdown_callback (gpointer data) +{ + gtk_main_quit (); + return FALSE; +} static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data) { @@ -568,6 +572,55 @@ static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessag appeared = TRUE; else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "WirelessNetworkDisappeared")) disappeared = TRUE; + else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceDeleted")) + { + char *service; + DBusError error; + + dbus_error_init (&error); + if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_INVALID)) + { + if (strcmp (service, NM_DBUS_SERVICE) == 0) + { + if (info->shutdown_timeout != NULL) + g_source_destroy (info->shutdown_timeout); + + info->shutdown_timeout = g_timeout_source_new (30000); + if (info->shutdown_timeout != NULL) + { + g_source_set_callback (info->shutdown_timeout, + shutdown_callback, + info, + NULL); + + g_source_attach (info->shutdown_timeout, NULL); + } + } + } + + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + } + else if (dbus_message_is_signal (message, DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, "ServiceCreated")) + { + char *service; + DBusError error; + + dbus_error_init (&error); + if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_INVALID)) + { + if (strcmp (service, NM_DBUS_SERVICE) == 0 && + info->shutdown_timeout != NULL) + { + g_source_destroy (info->shutdown_timeout); + info->shutdown_timeout = NULL; + } + } + + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + + } if (appeared || disappeared) { @@ -594,6 +647,26 @@ static DBusHandlerResult nmi_dbus_filter (DBusConnection *connection, DBusMessag } +/* + * nmwa_dbus_nm_is_running + * + * Ask dbus whether or not NetworkManager is running + * + */ +static gboolean nmi_dbus_nm_is_running (DBusConnection *connection) +{ + DBusError error; + gboolean exists; + + g_return_val_if_fail (connection != NULL, FALSE); + + dbus_error_init (&error); + exists = dbus_bus_service_exists (connection, NM_DBUS_SERVICE, &error); + if (dbus_error_is_set (&error)) + dbus_error_free (&error); + return (exists); +} + /* * nmi_dbus_service_init * @@ -614,6 +687,9 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info) return (-1); } + if (!nmi_dbus_nm_is_running (dbus_connection)) + return (-1); + if (!dbus_connection_register_object_path (dbus_connection, NMI_DBUS_PATH, &nmi_vtable, info)) { syslog (LOG_ERR, "nmi_dbus_service_init() could not register a handler for NetworkManagerInfo. Not enough memory?"); @@ -635,5 +711,16 @@ int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info) return (-1); } + dbus_bus_add_match(dbus_connection, + "type='signal'," + "interface='" DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "'," + "sender='" DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "'", + &dbus_error); + if (dbus_error_is_set (&dbus_error)) + { + dbus_error_free (&dbus_error); + return (-1); + } + return (0); }