dbus service/client: fix DBus error handling
server did not call dbus_g_error_domain_register() so the remote exception names weren't transmitted. Fixes #2067
This commit is contained in:
parent
d9dbc31904
commit
10f21f5cff
|
@ -23,11 +23,10 @@
|
|||
#include <glib.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
enum SyncevoDBusError{
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR = 1,
|
||||
SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER = 2,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS = 3,
|
||||
};
|
||||
#define SYNCEVO_DBUS_ERROR_GENERIC_ERROR "org.Moblin.SyncEvolution.GenericError"
|
||||
#define SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER "org.Moblin.SyncEvolution.NoSuchServer"
|
||||
#define SYNCEVO_DBUS_ERROR_MISSING_ARGS "org.Moblin.SyncEvolution.MissingArgs"
|
||||
#define SYNCEVO_DBUS_ERROR_INVALID_CALL "org.Moblin.SyncEvolution.InvalidCall"
|
||||
|
||||
#define SYNCEVO_SOURCE_TYPE (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID))
|
||||
typedef GValueArray SyncevoSource;
|
||||
|
|
|
@ -518,9 +518,14 @@ sync_clicked_cb (GtkButton *btn, app_data *data)
|
|||
if (data->syncing) {
|
||||
syncevo_service_abort_sync (data->service, data->current_service->name, &error);
|
||||
if (error) {
|
||||
/* FIXME: this can happen if the server has shutdown and the sync is no longer
|
||||
in progress*/
|
||||
add_error_info (data, _("Failed to cancel sync"), error->message);
|
||||
if (error->code == DBUS_GERROR_REMOTE_EXCEPTION &&
|
||||
dbus_g_error_has_name (error, SYNCEVO_DBUS_ERROR_INVALID_CALL)) {
|
||||
|
||||
/* sync is no longer in progress for some reason */
|
||||
add_error_info (data, _("Failed to cancel: sync was no longer in progress"), error->message);
|
||||
set_sync_progress (data, 1.0 , "");
|
||||
set_app_state (data, SYNC_UI_STATE_SERVER_OK);
|
||||
}
|
||||
g_error_free (error);
|
||||
return;
|
||||
} else {
|
||||
|
@ -584,15 +589,29 @@ sync_clicked_cb (GtkButton *btn, app_data *data)
|
|||
sources,
|
||||
&error);
|
||||
if (error) {
|
||||
add_error_info (data, _("Failed to start SyncEvolution sync"), error->message);
|
||||
g_error_free (error);
|
||||
if (error->code == DBUS_GERROR_REMOTE_EXCEPTION &&
|
||||
dbus_g_error_has_name (error, SYNCEVO_DBUS_ERROR_INVALID_CALL)) {
|
||||
|
||||
/* stop updates of "last synced" */
|
||||
if (data->last_sync_src_id > 0)
|
||||
g_source_remove (data->last_sync_src_id);
|
||||
set_app_state (data, SYNC_UI_STATE_SYNCING);
|
||||
set_sync_progress (data, sync_progress_clicked, _(""));
|
||||
|
||||
add_error_info (data, _("A sync is already in progress"), error->message);
|
||||
} else {
|
||||
add_error_info (data, _("Failed to start sync"), error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
set_sync_progress (data, sync_progress_clicked, _("Starting sync"));
|
||||
/* stop updates of "last synced" */
|
||||
if (data->last_sync_src_id > 0)
|
||||
g_source_remove (data->last_sync_src_id);
|
||||
set_sync_progress (data, sync_progress_clicked, _("Starting sync"));
|
||||
set_app_state (data, SYNC_UI_STATE_SYNCING);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1201,8 +1220,9 @@ static void
|
|||
get_server_config_cb (SyncevoService *service, GPtrArray *options, GError *error, app_data *data)
|
||||
{
|
||||
if (error) {
|
||||
/* don't warn if server has disappeared -- probably just command line use */
|
||||
if (error->code != SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER) {
|
||||
/* just warn if current server has disappeared -- probably just command line use */
|
||||
if (error->code == DBUS_GERROR_REMOTE_EXCEPTION &&
|
||||
dbus_g_error_has_name (error, SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER)) {
|
||||
add_error_info (data,
|
||||
_("Failed to get server configuration from SyncEvolution"),
|
||||
error->message);
|
||||
|
|
|
@ -47,13 +47,41 @@ static gboolean syncevo_remove_server_config (SyncevoDBusServer *obj, char *serv
|
|||
static gboolean syncevo_get_sync_reports (SyncevoDBusServer *obj, char *server, int count, GPtrArray **reports, GError **error);
|
||||
#include "syncevo-dbus-glue.h"
|
||||
|
||||
/* TODO move errors and the helper structs to a somewhere shared with client library */
|
||||
enum SyncevoDBusError{
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR = 1,
|
||||
SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER = 2,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS = 3,
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
SYNCEVO_DBUS_ERROR_INVALID_CALL, /* abort called when not syncing, or sync called when already syncing */
|
||||
};
|
||||
|
||||
static GQuark syncevo_dbus_error_quark(void)
|
||||
{
|
||||
static GQuark quark = 0;
|
||||
if (!quark)
|
||||
quark = g_quark_from_static_string("syncevo-dbus-server");
|
||||
return quark;
|
||||
}
|
||||
#define SYNCEVO_DBUS_ERROR (syncevo_dbus_error_quark())
|
||||
|
||||
static GType
|
||||
syncevo_dbus_error_get_type (void)
|
||||
{
|
||||
static GType etype = 0;
|
||||
if (G_UNLIKELY (etype == 0)) {
|
||||
static const GEnumValue values[] = {
|
||||
{ SYNCEVO_DBUS_ERROR_GENERIC_ERROR, "SYNCEVO_DBUS_ERROR_GENERIC_ERROR", "GenericError" },
|
||||
{ SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER, "SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER", "NoSuchServer" },
|
||||
{ SYNCEVO_DBUS_ERROR_MISSING_ARGS, "SYNCEVO_DBUS_ERROR_MISSING_ARGS", "MissingArgs" },
|
||||
{ SYNCEVO_DBUS_ERROR_INVALID_CALL, "SYNCEVO_DBUS_ERROR_INVALID_CALL", "InvalidCall" },
|
||||
{ 0 }
|
||||
};
|
||||
etype = g_enum_register_static ("SyncevoDBusError", values);
|
||||
}
|
||||
return etype;
|
||||
}
|
||||
#define SYNCEVO_DBUS_ERROR_TYPE (syncevo_dbus_error_get_type ())
|
||||
|
||||
|
||||
#define SYNCEVO_SOURCE_TYPE (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID))
|
||||
typedef GValueArray SyncevoSource;
|
||||
#define SYNCEVO_OPTION_TYPE (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID))
|
||||
|
@ -485,13 +513,13 @@ syncevo_start_sync (SyncevoDBusServer *obj,
|
|||
GError **error)
|
||||
{
|
||||
if (obj->server) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR,
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_INVALID_CALL,
|
||||
"Sync already in progress. Concurrent syncs are currently not supported");
|
||||
return FALSE;
|
||||
}
|
||||
if (!server) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"Server argument must be set");
|
||||
return FALSE;
|
||||
|
@ -523,15 +551,15 @@ syncevo_abort_sync (SyncevoDBusServer *obj,
|
|||
GError **error)
|
||||
{
|
||||
if (!server) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"Server variable must be set");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((!obj->server) || strcmp (server, obj->server) != 0) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR,
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_INVALID_CALL,
|
||||
"Not syncing server '%s'", server);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -547,7 +575,7 @@ syncevo_set_password (SyncevoDBusServer *obj,
|
|||
char *password,
|
||||
GError **error)
|
||||
{
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR,
|
||||
"SetPassword not supported yet");
|
||||
|
||||
|
@ -562,7 +590,7 @@ syncevo_get_servers (SyncevoDBusServer *obj,
|
|||
GError **error)
|
||||
{
|
||||
if (!servers) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"servers argument must be set");
|
||||
return FALSE;
|
||||
|
@ -598,7 +626,7 @@ syncevo_get_templates (SyncevoDBusServer *obj,
|
|||
GError **error)
|
||||
{
|
||||
if (!templates) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"templates argument must be set");
|
||||
return FALSE;
|
||||
|
@ -634,7 +662,7 @@ syncevo_get_template_config (SyncevoDBusServer *obj,
|
|||
SyncevoOption *option;
|
||||
|
||||
if (!templ || !options) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"Template and options arguments must be given");
|
||||
return FALSE;
|
||||
|
@ -644,7 +672,7 @@ syncevo_get_template_config (SyncevoDBusServer *obj,
|
|||
|
||||
boost::shared_ptr<EvolutionSyncConfig> config (EvolutionSyncConfig::createServerTemplate (string (templ)));
|
||||
if (!config.get()) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER,
|
||||
"No template '%s' found", templ);
|
||||
return FALSE;
|
||||
|
@ -687,7 +715,7 @@ syncevo_get_server_config (SyncevoDBusServer *obj,
|
|||
SyncevoOption *option;
|
||||
|
||||
if (!server || !options) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"Server and options arguments must be given");
|
||||
return FALSE;
|
||||
|
@ -700,7 +728,7 @@ syncevo_get_server_config (SyncevoDBusServer *obj,
|
|||
if (!from->exists()) {
|
||||
from = EvolutionSyncConfig::createServerTemplate( string (server));
|
||||
if (!from.get()) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER,
|
||||
"No server or template '%s' found", server);
|
||||
return FALSE;
|
||||
|
@ -752,14 +780,14 @@ syncevo_set_server_config (SyncevoDBusServer *obj,
|
|||
int i;
|
||||
|
||||
if (!server || !options) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"Server and options parameters must be given");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (obj->server) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR,
|
||||
"GetServers is currently not supported when a sync is in progress");
|
||||
return FALSE;
|
||||
|
@ -816,14 +844,14 @@ syncevo_remove_server_config (SyncevoDBusServer *obj,
|
|||
GError **error)
|
||||
{
|
||||
if (!server) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"Server argument must be given");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (obj->server) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_GENERIC_ERROR,
|
||||
"RemoveServerConfig is not supported when a sync is in progress");
|
||||
return FALSE;
|
||||
|
@ -831,7 +859,7 @@ syncevo_remove_server_config (SyncevoDBusServer *obj,
|
|||
|
||||
boost::shared_ptr<EvolutionSyncConfig> config(new EvolutionSyncConfig (string (server)));
|
||||
if (!config->exists()) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_NO_SUCH_SERVER,
|
||||
"No server '%s' found", server);
|
||||
return FALSE;
|
||||
|
@ -851,14 +879,14 @@ syncevo_get_sync_reports (SyncevoDBusServer *obj,
|
|||
GError **error)
|
||||
{
|
||||
if (!server) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"Server argument must be given");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!reports) {
|
||||
*error = g_error_new (g_quark_from_static_string ("syncevo-dbus-server"),
|
||||
*error = g_error_new (SYNCEVO_DBUS_ERROR,
|
||||
SYNCEVO_DBUS_ERROR_MISSING_ARGS,
|
||||
"reports argument must be given");
|
||||
return FALSE;
|
||||
|
@ -984,6 +1012,9 @@ syncevo_dbus_server_class_init(SyncevoDBusServerClass *klass)
|
|||
|
||||
/* dbus_glib_syncevo_object_info is provided in the generated glue file */
|
||||
dbus_g_object_type_install_info (SYNCEVO_TYPE_DBUS_SERVER, &dbus_glib_syncevo_object_info);
|
||||
|
||||
/* register error domain so clients get proper error names with dbus_g_error_get_name() */
|
||||
dbus_g_error_domain_register (SYNCEVO_DBUS_ERROR, NULL, SYNCEVO_DBUS_ERROR_TYPE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue