[Telepathy-commits] [telepathy-mission-control/master] Rewrite GError-to-string function
Alberto Mardegan
alberto.mardegan at nokia.com
Fri Feb 27 00:09:49 PST 2009
Use the GError enum types to build the error strings.
---
src/mcd-account-requests.c | 5 ++-
src/mcd-dispatcher.c | 5 ++-
src/mcd-misc.c | 74 +++++++++++--------------------------------
src/mcd-misc.h | 2 +-
4 files changed, 26 insertions(+), 60 deletions(-)
diff --git a/src/mcd-account-requests.c b/src/mcd-account-requests.c
index 4789644..555280e 100644
--- a/src/mcd-account-requests.c
+++ b/src/mcd-account-requests.c
@@ -122,15 +122,16 @@ on_channel_status_changed (McdChannel *channel, McdChannelStatus status,
if (status == MCD_CHANNEL_STATUS_FAILED)
{
- const gchar *err_string;
+ gchar *err_string;
error = mcd_channel_get_error (channel);
g_warning ("Channel request %s failed, error: %s",
_mcd_channel_get_request_path (channel), error->message);
- err_string = _mcd_get_error_string (error);
+ err_string = _mcd_build_error_string (error);
mc_svc_account_interface_channelrequests_emit_failed (account,
_mcd_channel_get_request_path (channel),
err_string, error->message);
+ g_free (err_string);
g_object_unref (channel);
}
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 8ba8ac1..11cd76e 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -2923,13 +2923,14 @@ on_request_status_changed (McdChannel *channel, McdChannelStatus status,
if (status == MCD_CHANNEL_STATUS_FAILED)
{
const GError *error;
- const gchar *err_string;
+ gchar *err_string;
error = mcd_channel_get_error (channel);
- err_string = _mcd_get_error_string (error);
+ err_string = _mcd_build_error_string (error);
/* no callback, as we don't really care */
mc_cli_client_handler_call_remove_failed_request
(rrd->handler, -1, rrd->request_path, err_string, error->message,
NULL, NULL, NULL, NULL);
+ g_free (err_string);
}
/* we don't need the McdRemoveRequestData anymore */
diff --git a/src/mcd-misc.c b/src/mcd-misc.c
index 5ec5102..356e1f5 100644
--- a/src/mcd-misc.c
+++ b/src/mcd-misc.c
@@ -104,68 +104,32 @@ _mcd_deepcopy_asv (GHashTable *asv)
return copy;
}
-const gchar *
-_mcd_get_error_string (const GError *error)
+gchar *
+_mcd_build_error_string (const GError *error)
{
+ GEnumValue *value;
+ GEnumClass *klass;
+ const gchar *prefix;
+
if (error->domain == TP_ERRORS)
{
- switch (error->code)
- {
- case TP_ERROR_NETWORK_ERROR:
- return TP_ERROR_PREFIX ".NetworkError";
- case TP_ERROR_NOT_IMPLEMENTED:
- return TP_ERROR_PREFIX ".NotImplemented";
- case TP_ERROR_INVALID_ARGUMENT:
- return TP_ERROR_PREFIX ".InvalidArgument";
- case TP_ERROR_NOT_AVAILABLE:
- return TP_ERROR_PREFIX ".NotAvailable";
- case TP_ERROR_PERMISSION_DENIED:
- return TP_ERROR_PREFIX ".PermissionDenied";
- case TP_ERROR_DISCONNECTED:
- return TP_ERROR_PREFIX ".Disconnected";
- case TP_ERROR_INVALID_HANDLE:
- return TP_ERROR_PREFIX ".InvalidHandle";
- case TP_ERROR_CHANNEL_BANNED:
- return TP_ERROR_PREFIX ".Banned";
- case TP_ERROR_CHANNEL_FULL:
- return TP_ERROR_PREFIX ".Full";
- case TP_ERROR_CHANNEL_INVITE_ONLY:
- return TP_ERROR_PREFIX ".InviteOnly";
- }
+ klass = g_type_class_ref (TP_TYPE_ERROR);
+ prefix = TP_ERROR_PREFIX;
}
else if (error->domain == MC_ERROR)
{
- switch (error->code)
- {
- case MC_DISCONNECTED_ERROR:
- return MC_ERROR_PREFIX ".Disconnected";
- case MC_INVALID_HANDLE_ERROR:
- return MC_ERROR_PREFIX ".InvalidHandle";
- case MC_NO_MATCHING_CONNECTION_ERROR:
- return MC_ERROR_PREFIX ".NoMatchingConnection";
- case MC_INVALID_ACCOUNT_ERROR:
- return MC_ERROR_PREFIX ".InvalidAccount";
- case MC_PRESENCE_FAILURE_ERROR:
- return MC_ERROR_PREFIX ".PresenceFailure";
- case MC_NO_ACCOUNTS_ERROR:
- return MC_ERROR_PREFIX ".NoAccounts";
- case MC_NETWORK_ERROR:
- return MC_ERROR_PREFIX ".Network";
- case MC_CONTACT_DOES_NOT_SUPPORT_VOICE_ERROR:
- return MC_ERROR_PREFIX ".ContactDoesNotSupportVoice";
- case MC_LOWMEM_ERROR:
- return MC_ERROR_PREFIX ".Lowmem";
- case MC_CHANNEL_REQUEST_GENERIC_ERROR:
- return MC_ERROR_PREFIX ".Generic";
- case MC_CHANNEL_BANNED_ERROR:
- return MC_ERROR_PREFIX ".ChannelBanned";
- case MC_CHANNEL_FULL_ERROR:
- return MC_ERROR_PREFIX ".ChannelFull";
- case MC_CHANNEL_INVITE_ONLY_ERROR:
- return MC_ERROR_PREFIX ".ChannelInviteOnly";
- }
+ klass = g_type_class_ref (MC_TYPE_ERROR);
+ prefix = MC_ERROR_PREFIX;
}
- return NULL;
+ else
+ return NULL;
+ value = g_enum_get_value (klass, error->code);
+ g_type_class_unref (klass);
+
+ if (G_LIKELY (value && value->value_nick))
+ return g_strconcat (prefix, ".", value->value_nick, NULL);
+ else
+ return NULL;
}
GType
diff --git a/src/mcd-misc.h b/src/mcd-misc.h
index bbdc4b7..4f261f4 100644
--- a/src/mcd-misc.h
+++ b/src/mcd-misc.h
@@ -41,7 +41,7 @@ void _mcd_xdg_data_subdir_foreach (const gchar *subdir,
GHashTable *_mcd_deepcopy_asv (GHashTable *asv);
-const gchar *_mcd_get_error_string (const GError *error);
+gchar *_mcd_build_error_string (const GError *error);
typedef void (*McdReadyCb) (gpointer object, const GError *error,
gpointer user_data);
--
1.5.6.5
More information about the telepathy-commits
mailing list