[PATCH] Improved Gnome client initialization error handling.

1. It no longer segfaults when sflphoned isn't available.
2. User is provided with GUI error dialog.

There are still many places that suppress DBus errors and just log them without
any GUI indication, this patch is just a beginning to show how things should be.
This commit is contained in:
Marat Radchenko
2010-12-15 12:57:00 -05:00
committed by Pierre-Luc Bacon
parent 71247e6467
commit 5e98ca7a1e
5 changed files with 84 additions and 91 deletions

View File

@ -313,38 +313,35 @@ void sflphone_fill_account_list (void)
sflphone_fill_codec_list ();
}
gboolean sflphone_init()
gboolean sflphone_init (GError **error)
{
if (!dbus_connect ()) {
main_window_error_message (_ ("Unable to connect to the SFLphone server.\nMake sure the daemon is running."));
if (!dbus_connect (error))
return FALSE;
} else {
dbus_register (getpid(), "Gtk+ Client");
// Init icons factory
init_icon_factory ();
if (!dbus_register (getpid (), "Gtk+ Client", error))
return FALSE;
current_calls = calltab_init (FALSE, CURRENT_CALLS);
contacts = calltab_init (TRUE, CONTACTS);
history = calltab_init (TRUE, HISTORY);
// Init icons factory
init_icon_factory ();
account_list_init ();
codec_capabilities_load ();
conferencelist_init ();
current_calls = calltab_init (FALSE, CURRENT_CALLS);
contacts = calltab_init (TRUE, CONTACTS);
history = calltab_init (TRUE, HISTORY);
// Fetch the configured accounts
sflphone_fill_account_list ();
account_list_init ();
codec_capabilities_load ();
conferencelist_init ();
// Fetch the ip2ip profile
sflphone_fill_ip2ip_profile();
// Fetch the configured accounts
sflphone_fill_account_list ();
// Fetch the conference list
// sflphone_fill_conference_list();
// Fetch the ip2ip profile
sflphone_fill_ip2ip_profile();
return TRUE;
}
// Fetch the conference list
// sflphone_fill_conference_list();
return TRUE;
}
void sflphone_fill_ip2ip_profile (void)

View File

@ -82,14 +82,16 @@ void codec_capabilities_load (void)
// This is a global list inherited by all accounts
codecs = (gchar**) dbus_codec_list ();
// Add the codecs in the list
for (pl=codecs; *codecs; codecs++) {
if (codecs != NULL) {
// Add the codecs in the list
for (pl=codecs; *codecs; codecs++) {
codec_t *c;
payload = atoi (*codecs);
specs = (gchar **) dbus_codec_details (payload);
codec_create_new_with_specs (payload, specs, TRUE, &c);
g_queue_push_tail (codecsCapabilities, (gpointer*) c);
codec_t *c;
payload = atoi (*codecs);
specs = (gchar **) dbus_codec_details (payload);
codec_create_new_with_specs (payload, specs, TRUE, &c);
g_queue_push_tail (codecsCapabilities, (gpointer*) c);
}
}
// If we didn't load any codecs, problem ...
@ -98,7 +100,7 @@ void codec_capabilities_load (void)
// Error message
ERROR ("No audio codecs found");
dbus_unregister (getpid());
exit (0);
exit (1);
}
}

View File

@ -511,23 +511,17 @@ error_alert (DBusGProxy *proxy UNUSED, int errCode, void * foo UNUSED)
}
gboolean
dbus_connect()
dbus_connect (GError **error)
{
GError *error = NULL;
connection = NULL;
instanceProxy = NULL;
g_type_init();
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
if (error) {
ERROR ("Failed to open connection to bus: %s",
error->message);
g_error_free (error);
if (connection == NULL)
return FALSE;
}
/* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
@ -545,11 +539,7 @@ dbus_connect()
callManagerProxy = dbus_g_proxy_new_for_name (connection,
"org.sflphone.SFLphone", "/org/sflphone/SFLphone/CallManager",
"org.sflphone.SFLphone.CallManager");
if (callManagerProxy == NULL) {
ERROR ("Failed to get proxy to CallManagers");
return FALSE;
}
g_assert (callManagerProxy != NULL);
DEBUG ("DBus connected to CallManager");
/* STRING STRING STRING Marshaller */
@ -687,11 +677,7 @@ dbus_connect()
configurationManagerProxy = dbus_g_proxy_new_for_name (connection,
"org.sflphone.SFLphone", "/org/sflphone/SFLphone/ConfigurationManager",
"org.sflphone.SFLphone.ConfigurationManager");
if (!configurationManagerProxy) {
ERROR ("Failed to get proxy to ConfigurationManager");
return FALSE;
}
g_assert (configurationManagerProxy != NULL);
DEBUG ("DBus connected to ConfigurationManager");
dbus_g_proxy_add_signal (configurationManagerProxy, "accountsChanged",
@ -1171,18 +1157,10 @@ dbus_start_tone (const int start, const guint type)
}
}
void
dbus_register (int pid, gchar * name)
gboolean
dbus_register (int pid, gchar *name, GError **error)
{
GError *error = NULL;
org_sflphone_SFLphone_Instance_register (instanceProxy, pid, name, &error);
if (error) {
ERROR ("Failed to call register() on instanceProxy: %s",
error->message);
g_error_free (error);
}
return org_sflphone_SFLphone_Instance_register (instanceProxy, pid, name, error);
}
void
@ -1874,7 +1852,7 @@ dbus_get_addressbook_list (void)
{
GError *error = NULL;
gchar** array;
gchar** array = NULL;
org_sflphone_SFLphone_ConfigurationManager_get_addressbook_list (
configurationManagerProxy, &array, &error);

View File

@ -50,7 +50,7 @@
* Try to connect to DBus services
* @return TRUE if connection succeeded, FALSE otherwise
*/
gboolean dbus_connect ();
gboolean dbus_connect (GError **error);
/**
* Unreferences the proxies
@ -417,8 +417,9 @@ void dbus_start_tone (const int start , const guint type);
* Manage the instances of clients connected to the server
* @param pid The pid of the processus client
* @param name The string description of the client. Here : GTK+ Client
* @param error return location for a GError or NULL
*/
void dbus_register (int pid, gchar * name);
gboolean dbus_register (int pid, gchar * name, GError **error);
/**
* Instance - Send unregistration request to dbus services

View File

@ -47,6 +47,7 @@
int
main (int argc, char *argv[])
{
GError *error = NULL;
// Handle logging
int i;
@ -89,42 +90,56 @@ main (int argc, char *argv[])
GNOME_PROGRAM_STANDARD_PROPERTIES,
NULL) ;
if (sflphone_init ()) {
if (!sflphone_init (&error)) {
gchar *markup;
if (eel_gconf_get_integer (SHOW_STATUSICON))
show_status_icon ();
ERROR (error->message);
markup = g_markup_printf_escaped (
_ ("Unable to initialize.\nMake sure the daemon is running.\nError: %s"),
error->message);
create_main_window ();
main_window_error_message (markup);
if (eel_gconf_get_integer (SHOW_STATUSICON) && eel_gconf_get_integer (START_HIDDEN)) {
gtk_widget_hide (GTK_WIDGET (get_main_window()));
set_minimized (TRUE);
}
g_free (markup);
g_error_free (error);
status_bar_display_account ();
// Load the history
sflphone_fill_history ();
// Get the active calls and conferences at startup
sflphone_fill_call_list ();
sflphone_fill_conference_list ();
// Update the GUI
update_actions ();
shortcuts_initialize_bindings();
/* start the main loop */
gtk_main ();
goto OUT;
}
gdk_threads_leave ();
if (eel_gconf_get_integer (SHOW_STATUSICON))
show_status_icon ();
create_main_window ();
if (eel_gconf_get_integer (SHOW_STATUSICON) && eel_gconf_get_integer (START_HIDDEN)) {
gtk_widget_hide (GTK_WIDGET (get_main_window()));
set_minimized (TRUE);
}
status_bar_display_account ();
// Load the history
sflphone_fill_history ();
// Get the active calls and conferences at startup
sflphone_fill_call_list ();
sflphone_fill_conference_list ();
// Update the GUI
update_actions ();
shortcuts_initialize_bindings();
/* start the main loop */
gtk_main ();
shortcuts_destroy_bindings();
return 0;
OUT:
gdk_threads_leave ();
return error != NULL;
}
/** @mainpage SFLphone GTK+ Client Documentation