From 51b4c9c4d0fc39d73b98f1517f70b0c9b71b5633 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 6 Mar 2012 16:28:42 +0000 Subject: [PATCH 02/10] Move TpSvc* into the dbus library This requires moving tp_dbus_g_method_return_not_implemented and tp_svc_interface_set_dbus_properties_info into the core library, so do that too. --- telepathy-glib/Makefile.am | 2 + telepathy-glib/codegen.am | 12 ++- telepathy-glib/core-dbus.c | 102 +++++++++++++++++++++++ telepathy-glib/dbus-properties-mixin-internal.h | 33 +++++++ telepathy-glib/dbus-properties-mixin.c | 61 +------------- telepathy-glib/dbus.c | 15 ---- telepathy-glib/introspection.am | 1 + 7 files changed, 152 insertions(+), 74 deletions(-) create mode 100644 telepathy-glib/core-dbus.c create mode 100644 telepathy-glib/dbus-properties-mixin-internal.h diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 162afdd..b60e2ca 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -169,6 +169,7 @@ check-local: check-coding-style libtelepathy_glib_core_internal_la_LIBADD = $(ALL_LIBS) libtelepathy_glib_core_internal_la_SOURCES = \ + core-dbus.c \ errors.c \ $(NULL) @@ -259,6 +260,7 @@ libtelepathy_glib_main_internal_la_SOURCES = \ dbus-daemon.c \ dbus-internal.h \ dbus-properties-mixin.c \ + dbus-properties-mixin-internal.h \ dbus-tube-channel.c \ debug.c \ debug-sender.c \ diff --git a/telepathy-glib/codegen.am b/telepathy-glib/codegen.am index c613906..f9a8d75 100644 --- a/telepathy-glib/codegen.am +++ b/telepathy-glib/codegen.am @@ -62,6 +62,9 @@ nodist_geninclude_HEADERS = \ _gen/tp-cli-dbus-daemon.h \ _gen/tp-cli-generic.h \ _gen/tp-cli-protocol.h \ + $(NULL) + +nodist_gendbusinclude_HEADERS += \ _gen/tp-svc-account.h \ _gen/tp-svc-account-manager.h \ _gen/tp-svc-call-content.h \ @@ -78,7 +81,8 @@ nodist_geninclude_HEADERS = \ _gen/tp-svc-debug.h \ _gen/tp-svc-generic.h \ _gen/tp-svc-protocol.h \ - _gen/tp-svc-tls-cert.h + _gen/tp-svc-tls-cert.h \ + $(NULL) nodist_libtelepathy_glib_core_internal_la_SOURCES = \ _gen/genums.c \ @@ -108,6 +112,9 @@ nodist_libtelepathy_glib_main_internal_la_SOURCES = \ _gen/tp-cli-dbus-daemon-body.h \ _gen/tp-cli-generic-body.h \ _gen/tp-cli-protocol-body.h \ + $(NULL) + +nodist_libtelepathy_glib_dbus_internal_la_SOURCES += \ _gen/tp-svc-account.c \ _gen/tp-svc-account-manager.c \ _gen/tp-svc-call-content.c \ @@ -124,7 +131,8 @@ nodist_libtelepathy_glib_main_internal_la_SOURCES = \ _gen/tp-svc-debug.c \ _gen/tp-svc-generic.c \ _gen/tp-svc-protocol.c \ - _gen/tp-svc-tls-cert.c + _gen/tp-svc-tls-cert.c \ + $(NULL) nodist_libtelepathy_glib_reentrants_la_SOURCES = \ _gen/tp-cli-account-reentrant-body.h \ diff --git a/telepathy-glib/core-dbus.c b/telepathy-glib/core-dbus.c new file mode 100644 index 0000000..d3c778d --- /dev/null +++ b/telepathy-glib/core-dbus.c @@ -0,0 +1,102 @@ +/* + * core-dbus.c - minimal D-Bus utilities for generated code + * + * Copyright © 2005-2012 Collabora Ltd. + * Copyright © 2005-2008 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "telepathy-glib/dbus.h" +#include "telepathy-glib/dbus-properties-mixin-internal.h" +#include "telepathy-glib/errors.h" + +/** + * tp_dbus_g_method_return_not_implemented: (skip) + * @context: The D-Bus method invocation context + * + * Return the Telepathy error NotImplemented from the method invocation + * given by @context. + */ +void +tp_dbus_g_method_return_not_implemented (DBusGMethodInvocation *context) +{ + GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" }; + + dbus_g_method_return_error (context, &e); +} + +/* this is the core library, we don't have debug infrastructure yet */ +#define CRITICAL(format, ...) \ + g_log (G_LOG_DOMAIN "/properties", G_LOG_LEVEL_CRITICAL, "%s: " format, \ + G_STRFUNC, ##__VA_ARGS__) + +/** + * tp_svc_interface_set_dbus_properties_info: + * @g_interface: The #GType of a service interface + * @info: an interface description + * + * Declare that @g_interface implements the given D-Bus interface, with the + * given properties. This may only be called once per GInterface, usually from + * a section of its base_init function that only runs once. + * + * This is typically only used within generated code; there is normally no + * reason to call it manually. + * + * Since: 0.7.3 + */ +void +tp_svc_interface_set_dbus_properties_info (GType g_interface, + TpDBusPropertiesMixinIfaceInfo *info) +{ + GQuark q = g_quark_from_static_string ( + TP_SVC_INTERFACE_DBUS_PROPERTIES_MIXIN_QUARK_NAME); + TpDBusPropertiesMixinPropInfo *prop; + + g_return_if_fail (G_TYPE_IS_INTERFACE (g_interface)); + g_return_if_fail (g_type_get_qdata (g_interface, q) == NULL); + g_return_if_fail (info->dbus_interface != 0); + g_return_if_fail (info->props != NULL); + + for (prop = info->props; prop->name != 0; prop++) + { + g_return_if_fail (prop->flags != 0); + g_return_if_fail ( + (prop->flags & ~( TP_DBUS_PROPERTIES_MIXIN_FLAG_READ + | TP_DBUS_PROPERTIES_MIXIN_FLAG_WRITE + | TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_CHANGED + | TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_INVALIDATED + )) == 0); + + /* Check that at most one change-related flag is set. */ + if ((prop->flags & TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_CHANGED) && + (prop->flags & TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_INVALIDATED)) + { + CRITICAL ("at most one of EMITS_CHANGED and EMITS_INVALIDATED may be " + "specified for a property, but %s.%s has both", + g_quark_to_string (info->dbus_interface), + g_quark_to_string (prop->name)); + g_return_if_reached (); + } + + g_return_if_fail (prop->dbus_signature != NULL); + g_return_if_fail (prop->dbus_signature[0] != '\0'); + g_return_if_fail (prop->type != 0); + } + + g_type_set_qdata (g_interface, q, info); +} diff --git a/telepathy-glib/dbus-properties-mixin-internal.h b/telepathy-glib/dbus-properties-mixin-internal.h new file mode 100644 index 0000000..ee60c0e --- /dev/null +++ b/telepathy-glib/dbus-properties-mixin-internal.h @@ -0,0 +1,33 @@ +/* + * dbus-properties-mixin-internal.h - D-Bus core Properties + * Copyright © 2008-2012 Collabora Ltd. + * Copyright © 2008 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef TELEPATHY_GLIB_DBUS_PROPERTIES_MIXIN_INTERNAL_H +#define TELEPATHY_GLIB_DBUS_PROPERTIES_MIXIN_INTERNAL_H + +#include + +G_BEGIN_DECLS + +#define TP_SVC_INTERFACE_DBUS_PROPERTIES_MIXIN_QUARK_NAME \ + "tp_svc_interface_get_dbus_properties_info" + +G_END_DECLS + +#endif diff --git a/telepathy-glib/dbus-properties-mixin.c b/telepathy-glib/dbus-properties-mixin.c index fc4319f..2bc3f8c 100644 --- a/telepathy-glib/dbus-properties-mixin.c +++ b/telepathy-glib/dbus-properties-mixin.c @@ -26,6 +26,8 @@ #include #include +#include "telepathy-glib/dbus-properties-mixin-internal.h" + #define DEBUG_FLAG TP_DEBUG_PROPERTIES #include "telepathy-glib/debug-internal.h" @@ -132,68 +134,13 @@ _iface_prop_info_quark (void) static GQuark q = 0; if (G_UNLIKELY (q == 0)) - q = g_quark_from_static_string - ("tp_svc_interface_get_dbus_properties_info@TELEPATHY_GLIB_0.7.3"); + q = g_quark_from_static_string ( + TP_SVC_INTERFACE_DBUS_PROPERTIES_MIXIN_QUARK_NAME); return q; } /** - * tp_svc_interface_set_dbus_properties_info: - * @g_interface: The #GType of a service interface - * @info: an interface description - * - * Declare that @g_interface implements the given D-Bus interface, with the - * given properties. This may only be called once per GInterface, usually from - * a section of its base_init function that only runs once. - * - * This is typically only used within generated code; there is normally no - * reason to call it manually. - * - * Since: 0.7.3 - */ -void -tp_svc_interface_set_dbus_properties_info (GType g_interface, - TpDBusPropertiesMixinIfaceInfo *info) -{ - GQuark q = _iface_prop_info_quark (); - TpDBusPropertiesMixinPropInfo *prop; - - g_return_if_fail (G_TYPE_IS_INTERFACE (g_interface)); - g_return_if_fail (g_type_get_qdata (g_interface, q) == NULL); - g_return_if_fail (info->dbus_interface != 0); - g_return_if_fail (info->props != NULL); - - for (prop = info->props; prop->name != 0; prop++) - { - g_return_if_fail (prop->flags != 0); - g_return_if_fail ( - (prop->flags & ~( TP_DBUS_PROPERTIES_MIXIN_FLAG_READ - | TP_DBUS_PROPERTIES_MIXIN_FLAG_WRITE - | TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_CHANGED - | TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_INVALIDATED - )) == 0); - - /* Check that at most one change-related flag is set. */ - if ((prop->flags & TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_CHANGED) && - (prop->flags & TP_DBUS_PROPERTIES_MIXIN_FLAG_EMITS_INVALIDATED)) - { - CRITICAL ("at most one of EMITS_CHANGED and EMITS_INVALIDATED may be " - "specified for a property, but %s.%s has both", - g_quark_to_string (info->dbus_interface), - g_quark_to_string (prop->name)); - g_return_if_reached (); - } - - g_return_if_fail (prop->dbus_signature != NULL); - g_return_if_fail (prop->dbus_signature[0] != '\0'); - g_return_if_fail (prop->type != 0); - } - - g_type_set_qdata (g_interface, q, info); -} - -/** * tp_svc_interface_get_dbus_properties_info: (skip) * @g_interface: The #GType of a service interface * diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c index a47f66e..9286e74 100644 --- a/telepathy-glib/dbus.c +++ b/telepathy-glib/dbus.c @@ -82,21 +82,6 @@ */ /* (#define + static inline in dbus.h) */ -/** - * tp_dbus_g_method_return_not_implemented: (skip) - * @context: The D-Bus method invocation context - * - * Return the Telepathy error NotImplemented from the method invocation - * given by @context. - */ -void -tp_dbus_g_method_return_not_implemented (DBusGMethodInvocation *context) -{ - GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, "Not implemented" }; - - dbus_g_method_return_error (context, &e); -} - DBusGConnection * _tp_dbus_starter_bus_conn (GError **error) { diff --git a/telepathy-glib/introspection.am b/telepathy-glib/introspection.am index 987aebb..9bc3bba 100644 --- a/telepathy-glib/introspection.am +++ b/telepathy-glib/introspection.am @@ -14,6 +14,7 @@ INTROSPECTION_GIRS = TelepathyGLib-1.gir TelepathyGLibDBus-1.gir TelepathyGLib-1.gir: libtelepathy-glib-1.la libtelepathy-glib-1-core.la # /!\ Order matters, see https://bugzilla.gnome.org/show_bug.cgi?id=660629 TelepathyGLib_1_gir_FILES = \ + $(srcdir)/core-dbus.c \ $(srcdir)/proxy.c _gen/proxy-introspectable.h \ $(srcdir)/account.c $(srcdir)/account.h \ $(srcdir)/account-channel-request.c $(srcdir)/account-channel-request.h \ -- 1.7.9.1