[Telepathy-commits] [telepathy-glib/master] fd.o #17588: stop generating the error enum, and hard-code the current one

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 30 03:18:17 PST 2009


Preserving ABI while generating enums from a specification that
doesn't explicitly guarantee order is error-prone, to say the least.
---
 telepathy-glib/Makefile.am |   12 ----
 telepathy-glib/errors.c    |  156 ++++++++++++++++++++++++++++++++++++++++----
 telepathy-glib/errors.h    |   44 +++++++++++--
 3 files changed, 183 insertions(+), 29 deletions(-)

diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am
index de8aa87..42f7bb8 100644
--- a/telepathy-glib/Makefile.am
+++ b/telepathy-glib/Makefile.am
@@ -153,7 +153,6 @@ nodist_libtelepathy_glib_internal_la_SOURCES = \
     _gen/signals-marshal.c \
     _gen/signals-marshal.h \
     _gen/signals-marshal.list \
-    _gen/telepathy-errors.c \
     _gen/tp-signals-marshal.list \
     _gen/interfaces-body.h \
     _gen/gtypes-body.h \
@@ -175,7 +174,6 @@ nodist_libtelepathy_glib_internal_la_SOURCES = \
 nodist_geninclude_HEADERS = \
     _gen/telepathy-enums.h \
     _gen/telepathy-interfaces.h \
-    _gen/telepathy-errors.h \
     _gen/gtypes.h \
     _gen/tp-cli-channel.h \
     _gen/tp-cli-connection.h \
@@ -307,16 +305,6 @@ _gen/interfaces-body.h _gen/telepathy-interfaces.h: _gen/stable-spec.xml \
 	$(PYTHON) $(tools_dir)/glib-interfaces-gen.py \
 		Tp _gen/interfaces-body.h _gen/telepathy-interfaces.h $<
 
-_gen/telepathy-errors.c: _gen/stable-spec.xml \
-	$(tools_dir)/glib-errors-enum-body-gen.py
-	$(PYTHON) $(tools_dir)/glib-errors-enum-body-gen.py \
-		$< > $@
-
-_gen/telepathy-errors.h: _gen/stable-spec.xml \
-	$(tools_dir)/glib-errors-enum-header-gen.py
-	$(PYTHON) $(tools_dir)/glib-errors-enum-header-gen.py \
-		$< > $@
-
 _gen/register-dbus-glib-marshallers-body.h: _gen/stable-spec.xml \
 	$(tools_dir)/glib-client-marshaller-gen.py
 	$(PYTHON) $(tools_dir)/glib-client-marshaller-gen.py $< _tp > $@
diff --git a/telepathy-glib/errors.c b/telepathy-glib/errors.c
index 37fcff9..92f33ca 100644
--- a/telepathy-glib/errors.c
+++ b/telepathy-glib/errors.c
@@ -1,7 +1,7 @@
 /*
- * telepathy-errors.c - Source for D-Bus error types used in telepathy
- * Copyright (C) 2005 Collabora Ltd.
- * Copyright (C) 2005 Nokia Corporation
+ * D-Bus error types used in telepathy
+ * Copyright (C) 2005-2009 Collabora Ltd.
+ * Copyright (C) 2005-2009 Nokia Corporation
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -38,6 +38,103 @@
  * The error domain for the D-Bus errors described in the Telepathy
  * specification. Error codes in this domain come from the #TpError
  * enumeration.
+ *
+ * This macro expands to a call to a function returning the Telepathy error
+ * domain. Since 0.7.17, this function automatically registers the domain with
+ * dbus-glib for server-side use (using dbus_g_error_domain_register()) when
+ * called.
+ */
+
+/**
+ * TP_TYPE_ERROR:
+ *
+ * The GType of the Telepathy error enumeration.
+ */
+
+/**
+ * TpError:
+ * @TP_ERROR_NETWORK_ERROR: org.freedesktop.Telepathy.Error.NetworkError:
+ *     Raised when there is an error reading from or writing to the network.
+ * @TP_ERROR_NOT_IMPLEMENTED: org.freedesktop.Telepathy.Error.NotImplemented:
+ *     Raised when the requested method, channel, etc is not available on this
+ *     connection.
+ * @TP_ERROR_INVALID_ARGUMENT: org.freedesktop.Telepathy.Error.InvalidArgument:
+ *     Raised when one of the provided arguments is invalid.
+ * @TP_ERROR_NOT_AVAILABLE: org.freedesktop.Telepathy.Error.NotAvailable:
+ *     Raised when the requested functionality is temporarily unavailable.
+ * @TP_ERROR_PERMISSION_DENIED: org.freedesktop.Telepathy.Error.PermissionDenied:
+ *     The user is not permitted to perform the requested operation.
+ * @TP_ERROR_DISCONNECTED: org.freedesktop.Telepathy.Error.Disconnected:
+ *     The connection is not currently connected and cannot be used.
+ *     This error may also be raised when operations are performed on a
+ *     Connection for which StatusChanged has signalled status Disconnected
+ *     for reason None.
+ * @TP_ERROR_INVALID_HANDLE: org.freedesktop.Telepathy.Error.InvalidHandle:
+ *     An identifier being converted to a handle was syntactically invalid,
+ *     or an invalid handle was used.
+ * @TP_ERROR_CHANNEL_BANNED: org.freedesktop.Telepathy.Error.Channel.Banned:
+ *     You are banned from the channel.
+ * @TP_ERROR_CHANNEL_FULL: org.freedesktop.Telepathy.Error.Channel.Full:
+ *     The channel is full.
+ * @TP_ERROR_CHANNEL_INVITE_ONLY: org.freedesktop.Telepathy.Error.Channel.InviteOnly:
+ *     The requested channel is invite-only.
+ * @TP_ERROR_NOT_YOURS: org.freedesktop.Telepathy.Error.NotYours:
+ *     The requested channel or other resource already exists, and another
+ *     client is responsible for it
+ * @TP_ERROR_CANCELLED: org.freedesktop.Telepathy.Error.Cancelled:
+ *     Raised by an ongoing request if it is cancelled by user request before
+ *     it has completed, or when operations are performed on an object which
+ *     the user has asked to close (for instance, a Connection where the user
+ *     has called Disconnect, or a Channel where the user has called Close).
+ * @TP_ERROR_AUTHENTICATION_FAILED: org.freedesktop.Telepathy.Error.AuthenticationFailed:
+ *     Raised when authentication with a service was unsuccessful.
+ * @TP_ERROR_ENCRYPTION_NOT_AVAILABLE: org.freedesktop.Telepathy.Error.EncryptionNotAvailable:
+ *     Raised if a user request insisted that encryption should be used,
+ *     but encryption was not actually available.
+ * @TP_ERROR_ENCRYPTION_ERROR: org.freedesktop.Telepathy.Error.EncryptionError:
+ *     Raised if encryption appears to be available, but could not actually be
+ *     used (for instance if SSL/TLS negotiation fails).
+ * @TP_ERROR_CERT_NOT_PROVIDED: org.freedesktop.Telepathy.Error.Cert.NotProvided:
+ *     Raised if the server did not provide a SSL/TLS certificate.
+ * @TP_ERROR_CERT_UNTRUSTED: org.freedesktop.Telepathy.Error.Cert.Untrusted:
+ *     Raised if the server provided a SSL/TLS certificate signed by an
+ *     untrusted certifying authority.
+ * @TP_ERROR_CERT_EXPIRED: org.freedesktop.Telepathy.Error.Cert.Expired:
+ *     Raised if the server provided an expired SSL/TLS certificate.
+ * @TP_ERROR_CERT_NOT_ACTIVATED: org.freedesktop.Telepathy.Error.Cert.NotActivated:
+ *     Raised if the server provided an SSL/TLS certificate that will become
+ *     valid at some point in the future.
+ * @TP_ERROR_CERT_FINGERPRINT_MISMATCH: org.freedesktop.Telepathy.Error.Cert.FingerprintMismatch:
+ *     Raised if the server provided an SSL/TLS certificate that did not have
+ *     the expected fingerprint.
+ * @TP_ERROR_CERT_HOSTNAME_MISMATCH: org.freedesktop.Telepathy.Error.Cert.HostnameMismatch:
+ *     Raised if the server provided an SSL/TLS certificate that did not
+ *     match its hostname.
+ * @TP_ERROR_CERT_SELF_SIGNED: org.freedesktop.Telepathy.Error.Cert.SelfSigned:
+ *     Raised if the server provided an SSL/TLS certificate that is
+ *     self-signed and untrusted.
+ * @TP_ERROR_CERT_INVALID: org.freedesktop.Telepathy.Error.Cert.Invalid:
+ *     Raised if the server provided an SSL/TLS certificate that is
+ *     unacceptable in some way that does not have a more specific error.
+ * @TP_ERROR_NOT_CAPABLE: org.freedesktop.Telepathy.Error.NotCapable:
+ *     Raised when requested functionality is unavailable due to a contact
+ *     not having the required capabilities.
+ * @TP_ERROR_OFFLINE: org.freedesktop.Telepathy.Error.Offline:
+ *     Raised when requested functionality is unavailable because a contact is
+ *     offline.
+ * @TP_ERROR_CHANNEL_KICKED: org.freedesktop.Telepathy.Error.Channel.Kicked:
+ *     Used to represent a user being ejected from a channel by another user,
+ *     for instance being kicked from a chatroom.
+ * @TP_ERROR_BUSY: org.freedesktop.Telepathy.Error.Busy:
+ *     Used to represent a user being removed from a channel because of a
+ *     "busy" indication.
+ * @TP_ERROR_NO_ANSWER: org.freedesktop.Telepathy.Error.NoAnswer:
+ *     Used to represent a user being removed from a channel because they did
+ *     not respond, e.g. to a StreamedMedia call.
+ * @TP_ERROR_DOES_NOT_EXIST: org.freedesktop.Telepathy.Error.DoesNotExist:
+ *     Raised when the requested user does not, in fact, exist.
+ *
+ * Enumerated type representing the Telepathy D-Bus errors.
  */
 
 /**
@@ -76,15 +173,6 @@ tp_g_set_error_unsupported_handle_type (guint type, GError **error)
       "unsupported handle type %u", type);
 }
 
-/**
- * tp_errors_quark:
- *
- * Return the Telepathy error domain. Since 0.7.17 this function
- * automatically registers the domain with dbus-glib for server-side use
- * (using dbus_g_error_domain_register()) when called.
- *
- * Returns: the Telepathy error domain.
- */
 GQuark
 tp_errors_quark (void)
 {
@@ -104,3 +192,47 @@ tp_errors_quark (void)
 
   return (GQuark) quark;
 }
+
+GType
+tp_error_get_type (void)
+{
+  static GType etype = 0;
+  if (G_UNLIKELY (etype == 0))
+    {
+      static const GEnumValue values[] = {
+        { TP_ERROR_NETWORK_ERROR, "TP_ERROR_NETWORK_ERROR", "NetworkError" },
+        { TP_ERROR_NOT_IMPLEMENTED, "TP_ERROR_NOT_IMPLEMENTED", "NotImplemented" },
+        { TP_ERROR_INVALID_ARGUMENT, "TP_ERROR_INVALID_ARGUMENT", "InvalidArgument" },
+        { TP_ERROR_NOT_AVAILABLE, "TP_ERROR_NOT_AVAILABLE", "NotAvailable" },
+        { TP_ERROR_PERMISSION_DENIED, "TP_ERROR_PERMISSION_DENIED", "PermissionDenied" },
+        { TP_ERROR_DISCONNECTED, "TP_ERROR_DISCONNECTED", "Disconnected" },
+        { TP_ERROR_INVALID_HANDLE, "TP_ERROR_INVALID_HANDLE", "InvalidHandle" },
+        { TP_ERROR_CHANNEL_BANNED, "TP_ERROR_CHANNEL_BANNED", "Channel.Banned" },
+        { TP_ERROR_CHANNEL_FULL, "TP_ERROR_CHANNEL_FULL", "Channel.Full" },
+        { TP_ERROR_CHANNEL_INVITE_ONLY, "TP_ERROR_CHANNEL_INVITE_ONLY", "Channel.InviteOnly" },
+        { TP_ERROR_NOT_YOURS, "TP_ERROR_NOT_YOURS", "NotYours" },
+        { TP_ERROR_CANCELLED, "TP_ERROR_CANCELLED", "Cancelled" },
+        { TP_ERROR_AUTHENTICATION_FAILED, "TP_ERROR_AUTHENTICATION_FAILED", "AuthenticationFailed" },
+        { TP_ERROR_ENCRYPTION_NOT_AVAILABLE, "TP_ERROR_ENCRYPTION_NOT_AVAILABLE", "EncryptionNotAvailable" },
+        { TP_ERROR_ENCRYPTION_ERROR, "TP_ERROR_ENCRYPTION_ERROR", "EncryptionError" },
+        { TP_ERROR_CERT_NOT_PROVIDED, "TP_ERROR_CERT_NOT_PROVIDED", "Cert.NotProvided" },
+        { TP_ERROR_CERT_UNTRUSTED, "TP_ERROR_CERT_UNTRUSTED", "Cert.Untrusted" },
+        { TP_ERROR_CERT_EXPIRED, "TP_ERROR_CERT_EXPIRED", "Cert.Expired" },
+        { TP_ERROR_CERT_NOT_ACTIVATED, "TP_ERROR_CERT_NOT_ACTIVATED", "Cert.NotActivated" },
+        { TP_ERROR_CERT_FINGERPRINT_MISMATCH, "TP_ERROR_CERT_FINGERPRINT_MISMATCH", "Cert.FingerprintMismatch" },
+        { TP_ERROR_CERT_HOSTNAME_MISMATCH, "TP_ERROR_CERT_HOSTNAME_MISMATCH", "Cert.HostnameMismatch" },
+        { TP_ERROR_CERT_SELF_SIGNED, "TP_ERROR_CERT_SELF_SIGNED", "Cert.SelfSigned" },
+        { TP_ERROR_CERT_INVALID, "TP_ERROR_CERT_INVALID", "Cert.Invalid" },
+        { TP_ERROR_NOT_CAPABLE, "TP_ERROR_NOT_CAPABLE", "NotCapable" },
+        { TP_ERROR_OFFLINE, "TP_ERROR_OFFLINE", "Offline" },
+        { TP_ERROR_CHANNEL_KICKED, "TP_ERROR_CHANNEL_KICKED", "Channel.Kicked" },
+        { TP_ERROR_BUSY, "TP_ERROR_BUSY", "Busy" },
+        { TP_ERROR_NO_ANSWER, "TP_ERROR_NO_ANSWER", "NoAnswer" },
+        { TP_ERROR_DOES_NOT_EXIST, "TP_ERROR_DOES_NOT_EXIST", "DoesNotExist" },
+        { 0 }
+      };
+
+      etype = g_enum_register_static ("TpError", values);
+    }
+  return etype;
+}
diff --git a/telepathy-glib/errors.h b/telepathy-glib/errors.h
index 7dd3866..671f7c7 100644
--- a/telepathy-glib/errors.h
+++ b/telepathy-glib/errors.h
@@ -1,7 +1,7 @@
 /*
- * tp-errors.h - Header for Telepathy error types
- * Copyright (C) 2005, 2007 Collabora Ltd.
- * Copyright (C) 2005, 2007 Nokia Corporation
+ * <telepathy-glib/errors.h> - Header for Telepathy error types
+ * Copyright (C) 2005-2009 Collabora Ltd.
+ * Copyright (C) 2005-2009 Nokia Corporation
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -23,8 +23,6 @@
 
 #include <glib-object.h>
 
-#include <telepathy-glib/_gen/telepathy-errors.h>
-
 G_BEGIN_DECLS
 
 GQuark tp_errors_quark (void);
@@ -36,6 +34,42 @@ GQuark tp_errors_quark (void);
 void tp_g_set_error_invalid_handle_type (guint type, GError **error);
 void tp_g_set_error_unsupported_handle_type (guint type, GError **error);
 
+#define TP_TYPE_ERROR (tp_error_get_type())
+
+GType tp_error_get_type (void);
+
+typedef enum {
+    TP_ERROR_NETWORK_ERROR,
+    TP_ERROR_NOT_IMPLEMENTED,
+    TP_ERROR_INVALID_ARGUMENT,
+    TP_ERROR_NOT_AVAILABLE,
+    TP_ERROR_PERMISSION_DENIED,
+    TP_ERROR_DISCONNECTED,
+    TP_ERROR_INVALID_HANDLE,
+    TP_ERROR_CHANNEL_BANNED,
+    TP_ERROR_CHANNEL_FULL,
+    TP_ERROR_CHANNEL_INVITE_ONLY,
+    TP_ERROR_NOT_YOURS,
+    TP_ERROR_CANCELLED,
+    TP_ERROR_AUTHENTICATION_FAILED,
+    TP_ERROR_ENCRYPTION_NOT_AVAILABLE,
+    TP_ERROR_ENCRYPTION_ERROR,
+    TP_ERROR_CERT_NOT_PROVIDED,
+    TP_ERROR_CERT_UNTRUSTED,
+    TP_ERROR_CERT_EXPIRED,
+    TP_ERROR_CERT_NOT_ACTIVATED,
+    TP_ERROR_CERT_FINGERPRINT_MISMATCH,
+    TP_ERROR_CERT_HOSTNAME_MISMATCH,
+    TP_ERROR_CERT_SELF_SIGNED,
+    TP_ERROR_CERT_INVALID,
+    TP_ERROR_NOT_CAPABLE,
+    TP_ERROR_OFFLINE,
+    TP_ERROR_CHANNEL_KICKED,
+    TP_ERROR_BUSY,
+    TP_ERROR_NO_ANSWER,
+    TP_ERROR_DOES_NOT_EXIST,
+} TpError;
+
 G_END_DECLS
 
 #endif
-- 
1.5.6.5




More information about the telepathy-commits mailing list