2011-04-08 22:57:31 +02:00
# -*- Mode: Python -*-
2011-04-15 14:33:30 +02:00
# GDBus - GLib D-Bus Library
#
# Copyright (C) 2008-2011 Red Hat, Inc.
#
# 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 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., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307, USA.
#
# Author: David Zeuthen <davidz@redhat.com>
2011-04-08 22:57:31 +02:00
import sys
import argparse
import config
import utils
import dbustypes
# ----------------------------------------------------------------------------------------------------
class CodeGenerator :
2011-04-18 20:23:19 +02:00
def __init__ ( self , ifaces , namespace , interface_prefix , generate_objmanager , docbook_gen , h , c ) :
self . docbook_gen = docbook_gen
2011-04-12 17:50:34 +02:00
self . generate_objmanager = generate_objmanager
2011-04-08 22:57:31 +02:00
self . ifaces = ifaces
self . h = h
self . c = c
self . namespace = namespace
if len ( namespace ) > 1 :
self . ns_upper = utils . camel_case_to_uscore ( namespace ) . upper ( ) + ' _ '
self . ns_lower = utils . camel_case_to_uscore ( namespace ) . lower ( ) + ' _ '
else :
self . ns_upper = ' '
self . ns_lower = ' '
self . interface_prefix = interface_prefix
self . header_guard = self . h . name . upper ( ) . replace ( ' . ' , ' _ ' ) . replace ( ' - ' , ' _ ' )
# ----------------------------------------------------------------------------------------------------
def generate_intro ( self ) :
self . c . write ( ' /* \n '
2011-04-15 14:40:52 +02:00
' * Generated by gdbus-codegen %s . DO NOT EDIT. \n '
2011-04-15 14:48:21 +02:00
' * \n '
' * The license of this code is the same as for the source it was derived from. \n '
2011-04-08 22:57:31 +02:00
' */ \n '
' \n '
% ( config . VERSION ) )
self . c . write ( ' #ifdef HAVE_CONFIG_H \n '
' # include " config.h " \n '
' #endif \n '
' \n '
' #include " %s " \n '
' \n ' % ( self . h . name ) )
self . c . write ( ' typedef struct \n '
' { \n '
' GDBusArgInfo parent_struct; \n '
' gboolean use_gvariant; \n '
' } _ExtendedGDBusArgInfo; \n '
' \n ' )
self . c . write ( ' typedef struct \n '
' { \n '
' GDBusMethodInfo parent_struct; \n '
' const gchar *signal_name; \n '
' } _ExtendedGDBusMethodInfo; \n '
' \n ' )
self . c . write ( ' typedef struct \n '
' { \n '
' GDBusSignalInfo parent_struct; \n '
' const gchar *signal_name; \n '
' } _ExtendedGDBusSignalInfo; \n '
' \n ' )
self . c . write ( ' typedef struct \n '
' { \n '
' GDBusPropertyInfo parent_struct; \n '
' const gchar *hyphen_name; \n '
' gboolean use_gvariant; \n '
' } _ExtendedGDBusPropertyInfo; \n '
' \n ' )
self . c . write ( ' typedef struct \n '
' { \n '
' const _ExtendedGDBusPropertyInfo *info; \n '
2011-04-15 21:53:28 +02:00
' guint prop_id; \n '
' GValue orig_value; /* the value before the change */ \n '
2011-04-08 22:57:31 +02:00
' } ChangedProperty; \n '
' \n '
' static void \n '
' _changed_property_free (ChangedProperty *data) \n '
' { \n '
2011-04-15 21:53:28 +02:00
' g_value_unset (&data->orig_value); \n '
2011-04-08 22:57:31 +02:00
' g_free (data); \n '
' } \n '
' \n ' )
self . c . write ( ' static gboolean \n '
' _g_strv_equal0 (gchar **a, gchar **b) \n '
' { \n '
' gboolean ret = FALSE; \n '
' guint n; \n '
' if (a == NULL && b == NULL) \n '
' { \n '
' ret = TRUE; \n '
' goto out; \n '
' } \n '
' if (a == NULL || b == NULL) \n '
' goto out; \n '
' if (g_strv_length (a) != g_strv_length (b)) \n '
' goto out; \n '
' for (n = 0; a[n] != NULL; n++) \n '
' if (g_strcmp0 (a[n], b[n]) != 0) \n '
' goto out; \n '
' ret = TRUE; \n '
' out: \n '
' return ret; \n '
' } \n '
' \n ' )
self . c . write ( ' static gboolean \n '
' _g_variant_equal0 (GVariant *a, GVariant *b) \n '
' { \n '
' gboolean ret = FALSE; \n '
' if (a == NULL && b == NULL) \n '
2011-04-15 19:51:10 +02:00
' { \n '
' ret = TRUE; \n '
' goto out; \n '
' } \n '
2011-04-08 22:57:31 +02:00
' if (a == NULL || b == NULL) \n '
' goto out; \n '
' ret = g_variant_equal (a, b); \n '
' out: \n '
' return ret; \n '
' } \n '
' \n ' )
# simplified - only supports the types we use
self . c . write ( ' static gboolean \n '
' _g_value_equal (const GValue *a, const GValue *b) \n '
' { \n '
' gboolean ret = FALSE; \n '
' g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b)); \n '
' switch (G_VALUE_TYPE (a)) \n '
' { \n '
' case G_TYPE_BOOLEAN: \n '
' ret = (g_value_get_boolean (a) == g_value_get_boolean (b)); \n '
' break; \n '
' case G_TYPE_UCHAR: \n '
' ret = (g_value_get_uchar (a) == g_value_get_uchar (b)); \n '
' break; \n '
' case G_TYPE_INT: \n '
' ret = (g_value_get_int (a) == g_value_get_int (b)); \n '
' break; \n '
' case G_TYPE_UINT: \n '
' ret = (g_value_get_uint (a) == g_value_get_uint (b)); \n '
' break; \n '
' case G_TYPE_INT64: \n '
' ret = (g_value_get_int64 (a) == g_value_get_int64 (b)); \n '
' break; \n '
' case G_TYPE_UINT64: \n '
' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b)); \n '
' break; \n '
' case G_TYPE_DOUBLE: \n '
' ret = (g_value_get_double (a) == g_value_get_double (b)); \n '
' break; \n '
' case G_TYPE_STRING: \n '
' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0); \n '
' break; \n '
' case G_TYPE_VARIANT: \n '
' ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b)); \n '
' break; \n '
' default: \n '
' if (G_VALUE_TYPE (a) == G_TYPE_STRV) \n '
' ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b)); \n '
' else \n '
' g_critical ( " _g_value_equal() does not handle type %s " , g_type_name (G_VALUE_TYPE (a))); \n '
' break; \n '
' } \n '
' return ret; \n '
' } \n '
' \n ' )
self . h . write ( ' /* \n '
2011-04-15 14:44:05 +02:00
' * Generated by gdbus-codegen %s . DO NOT EDIT. \n '
2011-04-15 14:48:21 +02:00
' * \n '
' * The license of this code is the same as for the source it was derived from. \n '
2011-04-08 22:57:31 +02:00
' */ \n '
' \n '
' #ifndef __ %s __ \n '
' #define __ %s __ \n '
' \n ' % ( config . VERSION , self . header_guard , self . header_guard ) )
self . h . write ( ' #include <gio/gio.h> \n '
' \n '
' G_BEGIN_DECLS \n '
' \n ' )
# ----------------------------------------------------------------------------------------------------
def declare_types ( self ) :
for i in self . ifaces :
self . h . write ( ' \n ' )
self . h . write ( ' /* ------------------------------------------------------------------------ */ \n ' )
self . h . write ( ' /* Declarations for %s */ \n ' % i . name )
self . h . write ( ' \n ' )
# First the GInterface
2011-04-16 20:07:23 +02:00
self . h . write ( ' #define %s TYPE_ %s ( %s _get_type ()) \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' #define %s %s (o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %s TYPE_ %s , %s )) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' #define %s IS_ %s (o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %s TYPE_ %s )) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper ) )
self . h . write ( ' #define %s %s _GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %s TYPE_ %s , %s )) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' \n ' )
self . h . write ( ' struct _ %s ; \n ' % ( i . camel_name ) )
self . h . write ( ' typedef struct _ %s %s ; \n ' % ( i . camel_name , i . camel_name ) )
self . h . write ( ' typedef struct _ %s Iface %s Iface; \n ' % ( i . camel_name , i . camel_name ) )
self . h . write ( ' \n ' )
self . h . write ( ' struct _ %s Iface \n ' % ( i . camel_name ) )
self . h . write ( ' { \n ' )
self . h . write ( ' GTypeInterface parent_iface; \n ' )
2011-04-12 22:17:28 +02:00
function_pointers = { }
2011-04-08 22:57:31 +02:00
if len ( i . methods ) > 0 :
self . h . write ( ' \n ' )
for m in i . methods :
2011-04-12 22:17:28 +02:00
key = ( m . since , ' _method_ %s ' % m . name_lower )
value = ' gboolean (*handle_ %s ) ( \n ' % ( m . name_lower )
value + = ' %s *object, \n ' % ( i . camel_name )
value + = ' GDBusMethodInvocation *invocation ' % ( )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2011-04-12 22:17:28 +02:00
value + = ' , \n %s %s ' % ( a . ctype_in , a . name )
value + = ' ); \n \n '
function_pointers [ key ] = value
2011-04-08 22:57:31 +02:00
if len ( i . signals ) > 0 :
self . h . write ( ' \n ' )
for s in i . signals :
2011-04-12 22:17:28 +02:00
key = ( s . since , ' _signal_ %s ' % s . name_lower )
value = ' void (* %s ) ( \n ' % ( s . name_lower )
value + = ' %s *object ' % ( i . camel_name )
2011-04-08 22:57:31 +02:00
for a in s . args :
2011-04-12 22:17:28 +02:00
value + = ' , \n %s %s ' % ( a . ctype_in , a . name )
value + = ' ); \n \n '
function_pointers [ key ] = value
# Sort according to @since tag, then name.. this ensures
# that the function pointers don't change order assuming
# judicious use of @since
#
# Also use a proper version comparison function so e.g.
# 10.0 comes after 2.0.
#
# See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
# for discussion
keys = function_pointers . keys ( )
if len ( keys ) > 0 :
2011-04-18 20:23:19 +02:00
keys . sort ( cmp = utils . my_version_cmp )
2011-04-12 22:17:28 +02:00
for key in keys :
self . h . write ( ' %s ' % function_pointers [ key ] )
2011-04-08 22:57:31 +02:00
self . h . write ( ' }; \n ' )
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' GType %s _get_type (void) G_GNUC_CONST; \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' \n ' )
self . h . write ( ' GDBusInterfaceInfo * %s _interface_info (void); \n ' % ( i . name_lower ) )
if len ( i . properties ) > 0 :
self . h . write ( ' guint %s _override_properties (GObjectClass *klass, guint property_id_begin); \n ' % ( i . name_lower ) )
self . h . write ( ' \n ' )
# Then method call completion functions
if len ( i . methods ) > 0 :
self . h . write ( ' \n ' )
self . h . write ( ' /* D-Bus method call completion functions: */ \n ' )
for m in i . methods :
2011-04-15 18:56:07 +02:00
if m . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' void %s _complete_ %s ( \n '
' %s *object, \n '
' GDBusMethodInvocation *invocation ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . out_args :
self . h . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . h . write ( ' ); \n ' )
self . h . write ( ' \n ' )
self . h . write ( ' \n ' )
# Then signal emission functions
if len ( i . signals ) > 0 :
self . h . write ( ' \n ' )
self . h . write ( ' /* D-Bus signal emissions functions: */ \n ' )
for s in i . signals :
2011-04-15 18:56:07 +02:00
if s . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' void %s _emit_ %s ( \n '
' %s *object ' % ( i . name_lower , s . name_lower , i . camel_name ) )
for a in s . args :
self . h . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . h . write ( ' ); \n ' )
self . h . write ( ' \n ' )
self . h . write ( ' \n ' )
# Then method call declarations
if len ( i . methods ) > 0 :
self . h . write ( ' \n ' )
self . h . write ( ' /* D-Bus method calls: */ \n ' )
for m in i . methods :
# async begin
2011-04-15 18:56:07 +02:00
if m . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' void %s _call_ %s ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . in_args :
self . h . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . h . write ( ' , \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data); \n ' )
self . h . write ( ' \n ' )
# async finish
2011-04-15 18:56:07 +02:00
if m . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' gboolean %s _call_ %s _finish ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . out_args :
self . h . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
self . h . write ( ' , \n '
' GAsyncResult *res, \n '
' GError **error); \n ' )
self . h . write ( ' \n ' )
# sync
2011-04-15 18:56:07 +02:00
if m . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' gboolean %s _call_ %s _sync ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . in_args :
self . h . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
for a in m . out_args :
self . h . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
self . h . write ( ' , \n '
' GCancellable *cancellable, \n '
' GError **error); \n ' )
self . h . write ( ' \n ' )
self . h . write ( ' \n ' )
# Then the property accessor declarations
if len ( i . properties ) > 0 :
self . h . write ( ' \n ' )
self . h . write ( ' /* D-Bus property accessors: */ \n ' )
for p in i . properties :
# getter
2011-04-15 18:56:07 +02:00
if p . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' %s %s _get_ %s ( %s *object); \n ' % ( p . arg . ctype_in , i . name_lower , p . name_lower , i . camel_name ) )
# setter
2011-04-15 18:56:07 +02:00
if p . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' void %s _set_ %s ( %s *object, %s value); \n ' % ( i . name_lower , p . name_lower , i . camel_name , p . arg . ctype_in , ) )
self . h . write ( ' \n ' )
# Then the proxy
self . h . write ( ' \n ' )
self . h . write ( ' /* ---- */ \n ' )
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' #define %s TYPE_ %s _PROXY ( %s _proxy_get_type ()) \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' #define %s %s _PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %s TYPE_ %s _PROXY, %s Proxy)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' #define %s %s _PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %s TYPE_ %s _PROXY, %s ProxyClass)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' #define %s %s _PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %s TYPE_ %s _PROXY, %s ProxyClass)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' #define %s IS_ %s _PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %s TYPE_ %s _PROXY)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper ) )
self . h . write ( ' #define %s IS_ %s _PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %s TYPE_ %s _PROXY)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper ) )
self . h . write ( ' \n ' )
self . h . write ( ' typedef struct _ %s Proxy %s Proxy; \n ' % ( i . camel_name , i . camel_name ) )
self . h . write ( ' typedef struct _ %s ProxyClass %s ProxyClass; \n ' % ( i . camel_name , i . camel_name ) )
self . h . write ( ' typedef struct _ %s ProxyPrivate %s ProxyPrivate; \n ' % ( i . camel_name , i . camel_name ) )
self . h . write ( ' \n ' )
self . h . write ( ' struct _ %s Proxy \n ' % ( i . camel_name ) )
self . h . write ( ' { \n ' )
self . h . write ( ' GDBusProxy parent_instance; \n ' )
self . h . write ( ' %s ProxyPrivate *priv; \n ' % ( i . camel_name ) )
self . h . write ( ' }; \n ' )
self . h . write ( ' \n ' )
self . h . write ( ' struct _ %s ProxyClass \n ' % ( i . camel_name ) )
self . h . write ( ' { \n ' )
self . h . write ( ' GDBusProxyClass parent_class; \n ' )
self . h . write ( ' }; \n ' )
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' GType %s _proxy_get_type (void) G_GNUC_CONST; \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' \n ' )
2011-04-15 18:56:07 +02:00
if i . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' void %s _proxy_new ( \n '
' GDBusConnection *connection, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data); \n '
% ( i . name_lower ) )
2011-04-15 18:56:07 +02:00
if i . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' %s * %s _proxy_new_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( i . camel_name , i . name_lower ) )
2011-04-15 18:56:07 +02:00
if i . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' %s * %s _proxy_new_sync ( \n '
' GDBusConnection *connection, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error); \n '
% ( i . camel_name , i . name_lower ) )
self . h . write ( ' \n ' )
2011-04-15 18:56:07 +02:00
if i . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' void %s _proxy_new_for_bus ( \n '
' GBusType bus_type, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data); \n '
% ( i . name_lower ) )
2011-04-15 18:56:07 +02:00
if i . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' %s * %s _proxy_new_for_bus_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( i . camel_name , i . name_lower ) )
2011-04-15 18:56:07 +02:00
if i . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' %s * %s _proxy_new_for_bus_sync ( \n '
' GBusType bus_type, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error); \n '
% ( i . camel_name , i . name_lower ) )
self . h . write ( ' \n ' )
# Interface proxy accessors
2011-04-20 15:00:16 +02:00
self . h . write ( self . docbook_gen . expand (
' /** \n '
' * %s GET_ %s : \n '
' * @object: A #GDBusObject. \n '
' * \n '
' * Gets the # %s instance corresponding to the D-Bus interface # %s , if any. \n '
' * \n '
' * This macro can be used on both the client-side (passing a #GDBusObjectProxy) or the service-side (passing a #GDBusObjectSkeleton). \n '
' * \n '
' * This macro is just C convenience - other languages will use g_dbus_object_get_interface() to achieve the same result. \n '
' * \n '
' * Returns: (transfer full): A # %s or %% NULL if @object does not have said interface. Free with g_object_unref(). \n '
% ( i . ns_upper , i . name_upper , i . camel_name , i . name , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . h , 0 )
2011-04-08 22:57:31 +02:00
self . h . write ( ' #define %s GET_ %s (object) (g_dbus_object_lookup_with_typecheck (G_DBUS_OBJECT (object), " %s " , %s TYPE_ %s )) \n ' % ( i . ns_upper , i . name_upper , i . name , i . ns_upper , i . name_upper ) )
2011-04-20 15:00:16 +02:00
self . h . write ( self . docbook_gen . expand (
' /** \n '
' * %s PEEK_ %s : \n '
' * @object: A #GDBusObject. \n '
' * \n '
' * Like the %s GET_ %s () macro but doesn \' t increase the reference count on the returned object. \n '
' * \n '
' * This macro can be used on both the client-side (passing a #GDBusObjectProxy) or the service-side (passing a #GDBusObjectSkeleton). \n '
' * \n '
' * This macro is just C convenience - other languages will use g_dbus_object_get_interface() to achieve the same result.. \n '
' * \n '
' * <warning>It is not safe to use the returned object if you are on another thread than where the #GDBusObjectManagerClient is running</warning> \n '
' * \n '
' * Returns: (transfer none): A # %s or %% NULL if @object does not have said interface. Do not free the returned object, it belongs to @object. \n '
% ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . h , 0 )
2011-04-08 22:57:31 +02:00
self . h . write ( ' #define %s PEEK_ %s (object) (g_dbus_object_peek_with_typecheck (G_DBUS_OBJECT (object), " %s " , %s TYPE_ %s )) \n ' % ( i . ns_upper , i . name_upper , i . name , i . ns_upper , i . name_upper ) )
self . h . write ( ' \n ' )
2011-04-13 22:33:51 +02:00
# Then the skeleton
2011-04-08 22:57:31 +02:00
self . h . write ( ' \n ' )
self . h . write ( ' /* ---- */ \n ' )
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' #define %s TYPE_ %s _SKELETON ( %s _skeleton_get_type ()) \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
2011-04-13 22:33:51 +02:00
self . h . write ( ' #define %s %s _SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %s TYPE_ %s _SKELETON, %s Skeleton)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' #define %s %s _SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %s TYPE_ %s _SKELETON, %s SkeletonClass)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' #define %s %s _SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %s TYPE_ %s _SKELETON, %s SkeletonClass)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . h . write ( ' #define %s IS_ %s _SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %s TYPE_ %s _SKELETON)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper ) )
self . h . write ( ' #define %s IS_ %s _SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %s TYPE_ %s _SKELETON)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' \n ' )
2011-04-13 22:33:51 +02:00
self . h . write ( ' typedef struct _ %s Skeleton %s Skeleton; \n ' % ( i . camel_name , i . camel_name ) )
self . h . write ( ' typedef struct _ %s SkeletonClass %s SkeletonClass; \n ' % ( i . camel_name , i . camel_name ) )
self . h . write ( ' typedef struct _ %s SkeletonPrivate %s SkeletonPrivate; \n ' % ( i . camel_name , i . camel_name ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' \n ' )
2011-04-13 22:33:51 +02:00
self . h . write ( ' struct _ %s Skeleton \n ' % ( i . camel_name ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' { \n ' )
2011-04-13 22:33:51 +02:00
self . h . write ( ' GDBusInterfaceSkeleton parent_instance; \n ' )
self . h . write ( ' %s SkeletonPrivate *priv; \n ' % ( i . camel_name ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' }; \n ' )
self . h . write ( ' \n ' )
2011-04-13 22:33:51 +02:00
self . h . write ( ' struct _ %s SkeletonClass \n ' % ( i . camel_name ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' { \n ' )
2011-04-13 22:33:51 +02:00
self . h . write ( ' GDBusInterfaceSkeletonClass parent_class; \n ' )
2011-04-08 22:57:31 +02:00
self . h . write ( ' }; \n ' )
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' GType %s _skeleton_get_type (void) G_GNUC_CONST; \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' \n ' )
2011-04-15 18:56:07 +02:00
if i . deprecated :
self . h . write ( ' G_GNUC_DEPRECATED ' )
2011-04-13 22:33:51 +02:00
self . h . write ( ' %s * %s _skeleton_new (void); \n ' % ( i . camel_name , i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . h . write ( ' \n ' )
# Finally, the proxy manager
2011-04-12 17:50:34 +02:00
if self . generate_objmanager :
self . h . write ( ' \n ' )
self . h . write ( ' /* ---- */ \n ' )
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' #define %s TYPE_OBJECT_MANAGER_CLIENT ( %s object_manager_client_get_type ()) \n ' % ( self . ns_upper , self . ns_lower ) )
2011-04-12 17:50:34 +02:00
self . h . write ( ' #define %s OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %s TYPE_OBJECT_MANAGER_CLIENT, %s ObjectManagerClient)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . h . write ( ' #define %s OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %s TYPE_OBJECT_MANAGER_CLIENT, %s ObjectManagerClientClass)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . h . write ( ' #define %s OBJECT_MANAGER_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %s TYPE_OBJECT_MANAGER_CLIENT, %s ObjectManagerClientClass)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . h . write ( ' #define %s IS_OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %s TYPE_OBJECT_MANAGER_CLIENT)) \n ' % ( self . ns_upper , self . ns_upper ) )
self . h . write ( ' #define %s IS_OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %s TYPE_OBJECT_MANAGER_CLIENT)) \n ' % ( self . ns_upper , self . ns_upper ) )
self . h . write ( ' \n ' )
self . h . write ( ' typedef struct _ %s ObjectManagerClient %s ObjectManagerClient; \n ' % ( self . namespace , self . namespace ) )
self . h . write ( ' typedef struct _ %s ObjectManagerClientClass %s ObjectManagerClientClass; \n ' % ( self . namespace , self . namespace ) )
self . h . write ( ' typedef struct _ %s ObjectManagerClientPrivate %s ObjectManagerClientPrivate; \n ' % ( self . namespace , self . namespace ) )
self . h . write ( ' \n ' )
self . h . write ( ' struct _ %s ObjectManagerClient \n ' % ( self . namespace ) )
self . h . write ( ' { \n ' )
self . h . write ( ' GDBusObjectManagerClient parent_instance; \n ' )
self . h . write ( ' %s ObjectManagerClientPrivate *priv; \n ' % ( self . namespace ) )
self . h . write ( ' }; \n ' )
self . h . write ( ' \n ' )
self . h . write ( ' struct _ %s ObjectManagerClientClass \n ' % ( self . namespace ) )
self . h . write ( ' { \n ' )
self . h . write ( ' GDBusObjectManagerClientClass parent_class; \n ' )
self . h . write ( ' }; \n ' )
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' GType %s object_manager_client_get_type (void) G_GNUC_CONST; \n ' % ( self . ns_lower ) )
2011-04-12 17:50:34 +02:00
self . h . write ( ' \n ' )
2011-04-16 20:07:23 +02:00
self . h . write ( ' GType %s object_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data); \n ' % ( self . ns_lower ) )
2011-04-12 17:50:34 +02:00
self . h . write ( ' \n ' )
self . h . write ( ' void %s object_manager_client_new ( \n '
' GDBusConnection *connection, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data); \n '
% ( self . ns_lower ) )
self . h . write ( ' GDBusObjectManager * %s object_manager_client_new_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( self . ns_lower ) )
self . h . write ( ' GDBusObjectManager * %s object_manager_client_new_sync ( \n '
' GDBusConnection *connection, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error); \n '
% ( self . ns_lower ) )
self . h . write ( ' \n ' )
self . h . write ( ' void %s object_manager_client_new_for_bus ( \n '
' GBusType bus_type, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data); \n '
% ( self . ns_lower ) )
self . h . write ( ' GDBusObjectManager * %s object_manager_client_new_for_bus_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( self . ns_lower ) )
self . h . write ( ' GDBusObjectManager * %s object_manager_client_new_for_bus_sync ( \n '
' GBusType bus_type, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error); \n '
% ( self . ns_lower ) )
self . h . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# ----------------------------------------------------------------------------------------------------
def generate_outro ( self ) :
self . h . write ( ' \n '
' G_END_DECLS \n '
' \n '
' #endif /* __ %s __ */ \n ' % ( self . header_guard ) )
# ----------------------------------------------------------------------------------------------------
def generate_annotations ( self , prefix , annotations ) :
if annotations == None :
return
n = 0
for a in annotations :
#self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
# skip internal annotations
if a . key . startswith ( ' org.gtk.GDBus ' ) :
continue
self . c . write ( ' static const GDBusAnnotationInfo %s _ %d = \n '
' { \n '
' -1, \n '
' " %s " , \n '
' " %s " , \n ' % ( prefix , n , a . key , a . value ) )
if len ( a . annotations ) == 0 :
self . c . write ( ' NULL \n ' )
else :
self . c . write ( ' (GDBusAnnotationInfo **) & %s _ %d _pointers \n ' % ( prefix , n ) )
self . c . write ( ' }; \n '
' \n ' )
n + = 1
if n > 0 :
self . c . write ( ' static const GDBusAnnotationInfo * const %s _pointers[] = \n '
' { \n ' % ( prefix ) )
m = 0 ;
for a in annotations :
if a . key . startswith ( ' org.gtk.GDBus ' ) :
continue
self . c . write ( ' & %s _ %d , \n ' % ( prefix , m ) )
m + = 1
self . c . write ( ' NULL \n '
' }; \n '
' \n ' )
return n
def generate_args ( self , prefix , args ) :
for a in args :
num_anno = self . generate_annotations ( ' %s _arg_ %s _annotation_info ' % ( prefix , a . name ) , a . annotations )
self . c . write ( ' static const _ExtendedGDBusArgInfo %s _ %s = \n '
' { \n '
' { \n '
' -1, \n '
' " %s " , \n '
' " %s " , \n ' % ( prefix , a . name , a . name , a . signature ) )
if num_anno == 0 :
self . c . write ( ' NULL \n ' )
else :
self . c . write ( ' (GDBusAnnotationInfo **) & %s _arg_ %s _annotation_info_pointers \n ' % ( prefix , a . name ) )
self . c . write ( ' }, \n ' )
if not utils . lookup_annotation ( a . annotations , ' org.gtk.GDBus.C.ForceGVariant ' ) :
self . c . write ( ' FALSE \n ' )
else :
self . c . write ( ' TRUE \n ' )
self . c . write ( ' }; \n '
' \n ' )
if len ( args ) > 0 :
self . c . write ( ' static const _ExtendedGDBusArgInfo * const %s _pointers[] = \n '
' { \n ' % ( prefix ) )
for a in args :
self . c . write ( ' & %s _ %s , \n ' % ( prefix , a . name ) )
self . c . write ( ' NULL \n '
' }; \n '
' \n ' )
def generate_introspection_for_interface ( self , i ) :
self . c . write ( ' /* ---- Introspection data for %s ---- */ \n '
' \n ' % ( i . name ) )
if len ( i . methods ) > 0 :
for m in i . methods :
self . generate_args ( ' _ %s _method_info_ %s _IN_ARG ' % ( i . name_lower , m . name_lower ) , m . in_args )
self . generate_args ( ' _ %s _method_info_ %s _OUT_ARG ' % ( i . name_lower , m . name_lower ) , m . out_args )
num_anno = self . generate_annotations ( ' _ %s _method_ %s _annotation_info ' % ( i . name_lower , m . name_lower ) , m . annotations )
self . c . write ( ' static const _ExtendedGDBusMethodInfo _ %s _method_info_ %s = \n '
' { \n '
' { \n '
' -1, \n '
' " %s " , \n ' % ( i . name_lower , m . name_lower , m . name ) )
if len ( m . in_args ) == 0 :
self . c . write ( ' NULL, \n ' )
else :
self . c . write ( ' (GDBusArgInfo **) &_ %s _method_info_ %s _IN_ARG_pointers, \n ' % ( i . name_lower , m . name_lower ) )
if len ( m . out_args ) == 0 :
self . c . write ( ' NULL, \n ' )
else :
self . c . write ( ' (GDBusArgInfo **) &_ %s _method_info_ %s _OUT_ARG_pointers, \n ' % ( i . name_lower , m . name_lower ) )
if num_anno == 0 :
self . c . write ( ' NULL \n ' )
else :
self . c . write ( ' (GDBusAnnotationInfo **) &_ %s _method_ %s _annotation_info_pointers \n ' % ( i . name_lower , m . name_lower ) )
self . c . write ( ' }, \n '
' " handle- %s " \n '
% ( m . name_hyphen ) )
self . c . write ( ' }; \n '
' \n ' )
self . c . write ( ' static const _ExtendedGDBusMethodInfo * const _ %s _method_info_pointers[] = \n '
' { \n ' % ( i . name_lower ) )
for m in i . methods :
self . c . write ( ' &_ %s _method_info_ %s , \n ' % ( i . name_lower , m . name_lower ) )
self . c . write ( ' NULL \n '
' }; \n '
' \n ' )
# ---
if len ( i . signals ) > 0 :
for s in i . signals :
self . generate_args ( ' _ %s _signal_info_ %s _ARG ' % ( i . name_lower , s . name_lower ) , s . args )
num_anno = self . generate_annotations ( ' _ %s _signal_ %s _annotation_info ' % ( i . name_lower , s . name_lower ) , s . annotations )
self . c . write ( ' static const _ExtendedGDBusSignalInfo _ %s _signal_info_ %s = \n '
' { \n '
' { \n '
' -1, \n '
' " %s " , \n ' % ( i . name_lower , s . name_lower , s . name ) )
if len ( s . args ) == 0 :
self . c . write ( ' NULL, \n ' )
else :
self . c . write ( ' (GDBusArgInfo **) &_ %s _signal_info_ %s _ARG_pointers, \n ' % ( i . name_lower , s . name_lower ) )
if num_anno == 0 :
self . c . write ( ' NULL \n ' )
else :
self . c . write ( ' (GDBusAnnotationInfo **) &_ %s _signal_ %s _annotation_info_pointers \n ' % ( i . name_lower , s . name_lower ) )
self . c . write ( ' }, \n '
' " %s " \n '
% ( s . name_hyphen ) )
self . c . write ( ' }; \n '
' \n ' )
self . c . write ( ' static const _ExtendedGDBusSignalInfo * const _ %s _signal_info_pointers[] = \n '
' { \n ' % ( i . name_lower ) )
for s in i . signals :
self . c . write ( ' &_ %s _signal_info_ %s , \n ' % ( i . name_lower , s . name_lower ) )
self . c . write ( ' NULL \n '
' }; \n '
' \n ' )
# ---
if len ( i . properties ) > 0 :
for p in i . properties :
if p . readable and p . writable :
access = ' G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE '
elif p . readable :
access = ' G_DBUS_PROPERTY_INFO_FLAGS_READABLE '
elif p . writable :
access = ' G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE '
else :
access = ' G_DBUS_PROPERTY_INFO_FLAGS_NONE '
num_anno = self . generate_annotations ( ' _ %s _property_ %s _annotation_info ' % ( i . name_lower , p . name_lower ) , p . annotations )
self . c . write ( ' static const _ExtendedGDBusPropertyInfo _ %s _property_info_ %s = \n '
' { \n '
' { \n '
' -1, \n '
' " %s " , \n '
' " %s " , \n '
' %s , \n ' % ( i . name_lower , p . name_lower , p . name , p . arg . signature , access ) )
if num_anno == 0 :
self . c . write ( ' NULL \n ' )
else :
self . c . write ( ' (GDBusAnnotationInfo **) &_ %s _property_ %s _annotation_info_pointers \n ' % ( i . name_lower , p . name_lower ) )
self . c . write ( ' }, \n '
' " %s " , \n '
% ( p . name_hyphen ) )
if not utils . lookup_annotation ( p . annotations , ' org.gtk.GDBus.C.ForceGVariant ' ) :
self . c . write ( ' FALSE \n ' )
else :
self . c . write ( ' TRUE \n ' )
self . c . write ( ' }; \n '
' \n ' )
self . c . write ( ' static const _ExtendedGDBusPropertyInfo * const _ %s _property_info_pointers[] = \n '
' { \n ' % ( i . name_lower ) )
for p in i . properties :
self . c . write ( ' &_ %s _property_info_ %s , \n ' % ( i . name_lower , p . name_lower ) )
self . c . write ( ' NULL \n '
' }; \n '
' \n ' )
num_anno = self . generate_annotations ( ' _ %s _annotation_info ' % ( i . name_lower ) , i . annotations )
self . c . write ( ' static const GDBusInterfaceInfo _ %s _interface_info = \n '
' { \n '
' -1, \n '
' " %s " , \n ' % ( i . name_lower , i . name ) )
if len ( i . methods ) == 0 :
self . c . write ( ' NULL, \n ' )
else :
self . c . write ( ' (GDBusMethodInfo **) &_ %s _method_info_pointers, \n ' % ( i . name_lower ) )
if len ( i . signals ) == 0 :
self . c . write ( ' NULL, \n ' )
else :
self . c . write ( ' (GDBusSignalInfo **) &_ %s _signal_info_pointers, \n ' % ( i . name_lower ) )
if len ( i . properties ) == 0 :
self . c . write ( ' NULL, \n ' )
else :
self . c . write ( ' (GDBusPropertyInfo **) &_ %s _property_info_pointers, \n ' % ( i . name_lower ) )
if num_anno == 0 :
self . c . write ( ' NULL \n ' )
else :
self . c . write ( ' (GDBusAnnotationInfo **) &_ %s _annotation_info_pointers \n ' % ( i . name_lower ) )
self . c . write ( ' }; \n '
' \n ' )
self . c . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _interface_info: \n '
' * \n '
' * Gets a machine-readable description of the # %s D-Bus interface. \n '
' * \n '
' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free. \n '
% ( i . name_lower , i . name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' GDBusInterfaceInfo * \n '
' %s _interface_info (void) \n '
' { \n '
' return (GDBusInterfaceInfo *) &_ %s _interface_info; \n '
' } \n '
' \n ' % ( i . name_lower , i . name_lower ) )
if len ( i . properties ) > 0 :
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _override_properties: \n '
' * @klass: The class structure for a #GObject<!-- -->-derived class. \n '
' * @property_id_begin: The property id to assign to the first overridden property. \n '
' * \n '
' * Overrides all #GObject properties in the # %s interface for a concrete class. \n '
' * The properties are overridden in the order they are defined. \n '
' * \n '
' * Returns: The last property id. \n '
% ( i . name_lower , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' guint \n '
' %s _override_properties (GObjectClass *klass, guint property_id_begin) \n '
' { \n ' % ( i . name_lower ) )
for p in i . properties :
self . c . write ( ' g_object_class_override_property (klass, property_id_begin++, " %s " ); \n ' % ( p . name_hyphen ) )
self . c . write ( ' return property_id_begin - 1; \n '
' } \n '
' \n ' )
self . c . write ( ' \n ' )
# ----------------------------------------------------------------------------------------------------
def generate_interface ( self , i ) :
self . c . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s : \n '
' * \n '
' * Abstract interface type for the D-Bus interface # %s . \n '
% ( i . camel_name , i . name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
self . c . write ( ' \n ' )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s Iface: \n '
' * @parent_iface: The parent interface. \n '
% ( i . camel_name ) ) )
doc_bits = { }
if len ( i . methods ) > 0 :
for m in i . methods :
key = ( m . since , ' _method_ %s ' % m . name_lower )
value = ' @handle_ %s : ' % ( m . name_lower )
value + = ' Handler for the # %s ::handle- %s signal. ' % ( i . camel_name , m . name_hyphen )
doc_bits [ key ] = value
if len ( i . signals ) > 0 :
for s in i . signals :
key = ( s . since , ' _signal_ %s ' % s . name_lower )
value = ' @ %s : ' % ( s . name_lower )
value + = ' Handler for the # %s :: %s signal. ' % ( i . camel_name , s . name_hyphen )
doc_bits [ key ] = value
keys = doc_bits . keys ( )
if len ( keys ) > 0 :
keys . sort ( cmp = utils . my_version_cmp )
for key in keys :
self . c . write ( ' * %s \n ' % doc_bits [ key ] )
self . c . write ( self . docbook_gen . expand (
' * \n '
' * Virtual table for the D-Bus interface # %s . \n '
% ( i . name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
self . c . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' static void \n '
' %s _default_init ( %s Iface *iface) \n '
' { \n ' % ( i . name_lower , i . camel_name ) ) ;
if len ( i . methods ) > 0 :
self . c . write ( ' /* GObject signals for incoming D-Bus method calls: */ \n ' )
for m in i . methods :
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s ::handle- %s : \n '
' * @object: A # %s . \n '
' * @invocation: A #GDBusMethodInvocation. \n '
% ( i . camel_name , m . name_hyphen , i . camel_name , ) ) )
for a in m . in_args :
self . c . write ( ' * @ %s : Argument passed by remote caller. \n ' % ( a . name ) )
self . c . write ( self . docbook_gen . expand (
' * \n '
' * Signal emitted when a remote caller is invoking the %s . %s () D-Bus method. \n '
' * \n '
' * If a signal handler returns %% TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call %s _complete_ %s () or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %% G_DBUS_ERROR_UNKNOWN_METHOD error is returned. \n '
' * \n '
' * Returns: %% TRUE if the invocation was handled, %% FALSE to let other signal handlers run. \n '
% ( i . name , m . name , i . name_lower , m . name_lower ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . c , 2 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' g_signal_new ( " handle- %s " , \n '
' G_TYPE_FROM_INTERFACE (iface), \n '
' G_SIGNAL_RUN_LAST, \n '
' G_STRUCT_OFFSET ( %s Iface, handle_ %s ), \n '
' g_signal_accumulator_true_handled, \n '
' NULL, \n ' # accu_data
2011-04-08 23:34:44 +02:00
' g_cclosure_marshal_generic, \n '
2011-04-08 22:57:31 +02:00
' G_TYPE_BOOLEAN, \n '
' %d , \n '
' G_TYPE_DBUS_METHOD_INVOCATION '
% ( m . name_hyphen , i . camel_name , m . name_lower , len ( m . in_args ) + 1 ) )
for a in m . in_args :
self . c . write ( ' , %s ' % ( a . gtype ) )
self . c . write ( ' ); \n ' )
self . c . write ( ' \n ' )
if len ( i . signals ) > 0 :
self . c . write ( ' /* GObject signals for received D-Bus signals: */ \n ' )
for s in i . signals :
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s :: %s : \n '
' * @object: A # %s . \n '
% ( i . camel_name , s . name_hyphen , i . camel_name , ) ) )
for a in s . args :
self . c . write ( ' * @ %s : Argument. \n ' % ( a . name ) )
self . c . write ( self . docbook_gen . expand (
' * \n '
' * On the client-side, this signal is emitted whenever the D-Bus signal # %s :: %s is received. \n '
' * \n '
' * On the service-side, this signal can be used with e.g. g_signal_emit_by_name() to make the object emit the D-Bus signal. \n '
% ( i . name , s . name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( s , self . c , 2 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' g_signal_new ( " %s " , \n '
' G_TYPE_FROM_INTERFACE (iface), \n '
' G_SIGNAL_RUN_LAST, \n '
' G_STRUCT_OFFSET ( %s Iface, %s ), \n '
' NULL, \n ' # accumulator
' NULL, \n ' # accu_data
2011-04-08 23:34:44 +02:00
' g_cclosure_marshal_generic, \n '
2011-04-08 22:57:31 +02:00
' G_TYPE_NONE, \n '
' %d '
% ( s . name_hyphen , i . camel_name , s . name_lower , len ( s . args ) ) )
for a in s . args :
self . c . write ( ' , %s ' % ( a . gtype ) )
self . c . write ( ' ); \n ' )
self . c . write ( ' \n ' )
if len ( i . properties ) > 0 :
self . c . write ( ' /* GObject properties for D-Bus properties: */ \n ' )
for p in i . properties :
2011-04-18 20:23:19 +02:00
if p . readable and p . writable :
hint = ' Since the D-Bus property for this #GObject property is both readable and writable, it is meaningful to both read from it and write to it on both the service- and client-side. '
elif p . readable :
hint = ' Since the D-Bus property for this #GObject property is readable but not writable, it is meaningful to read from it on both the client- and service-side. It is only meaningful, however, to write to it on the service-side. '
elif p . writable :
hint = ' Since the D-Bus property for this #GObject property is writable but not readable, it is meaningful to write to it on both the client- and service-side. It is only meaningful, however, to read from it on the service-side. '
else :
raise RuntimeError ( ' Cannot handle property %s that neither readable nor writable ' % ( p . name ) )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s : %s : \n '
' * \n '
' * Represents the D-Bus property # %s : %s . \n '
' * \n '
' * %s \n '
% ( i . camel_name , p . name_hyphen , i . name , p . name , hint ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( p , self . c , 2 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' g_object_interface_install_property (iface, \n ' )
if p . arg . gtype == ' G_TYPE_VARIANT ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_variant ( " %s " , " %s " , " %s " , G_VARIANT_TYPE ( " %s " ), NULL ' % ( p . name_hyphen , p . name , p . name , p . arg . signature )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' b ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_boolean ( " %s " , " %s " , " %s " , FALSE ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' y ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_uchar ( " %s " , " %s " , " %s " , 0, 255, 0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' n ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_int ( " %s " , " %s " , " %s " , G_MININT16, G_MAXINT16, 0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' q ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_uint ( " %s " , " %s " , " %s " , 0, G_MAXUINT16, 0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' i ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_int ( " %s " , " %s " , " %s " , G_MININT32, G_MAXINT32, 0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' u ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_uint ( " %s " , " %s " , " %s " , 0, G_MAXUINT32, 0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' x ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_int64 ( " %s " , " %s " , " %s " , G_MININT64, G_MAXINT64, 0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' t ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_uint64 ( " %s " , " %s " , " %s " , 0, G_MAXUINT64, 0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' d ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_double ( " %s " , " %s " , " %s " , -G_MAXDOUBLE, G_MAXDOUBLE, 0.0 ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' s ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_string ( " %s " , " %s " , " %s " , NULL ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' o ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_string ( " %s " , " %s " , " %s " , NULL ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' g ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_string ( " %s " , " %s " , " %s " , NULL ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' ay ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_string ( " %s " , " %s " , " %s " , NULL ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' as ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_boxed ( " %s " , " %s " , " %s " , G_TYPE_STRV ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
elif p . arg . signature == ' aay ' :
2011-04-19 19:42:28 +02:00
s = ' g_param_spec_boxed ( " %s " , " %s " , " %s " , G_TYPE_STRV ' % ( p . name_hyphen , p . name , p . name )
2011-04-08 22:57:31 +02:00
else :
raise RuntimeError ( ' Unsupported gtype %s for GParamSpec ' % ( p . arg . gtype ) )
self . c . write ( ' %s , G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); ' % s ) ;
self . c . write ( ' \n ' )
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' typedef %s Iface %s Interface; \n ' % ( i . camel_name , i . camel_name ) )
self . c . write ( ' G_DEFINE_INTERFACE ( %s , %s , G_TYPE_OBJECT); \n ' % ( i . camel_name , i . name_lower ) )
self . c . write ( ' \n ' )
# ----------------------------------------------------------------------------------------------------
def generate_property_accessors ( self , i ) :
for p in i . properties :
# getter
2011-04-18 20:23:19 +02:00
if p . readable and p . writable :
hint = ' Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side. '
elif p . readable :
hint = ' Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side. '
elif p . writable :
hint = ' Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side. '
else :
raise RuntimeError ( ' Cannot handle property %s that neither readable nor writable ' % ( p . name ) )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _get_ %s : \n '
' * @object: A # %s . \n '
' * \n '
' * Gets the value of the # %s : %s D-Bus property. \n '
' * \n '
' * %s \n '
' * \n '
' * Returns: (transfer none): The property value. \n '
% ( i . name_lower , p . name_lower , i . camel_name , i . name , p . name , hint ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( p , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' %s \n '
' %s _get_ %s ( %s *object) \n '
' { \n '
' %s value; \n ' % ( p . arg . ctype_in , i . name_lower , p . name_lower , i . camel_name , p . arg . ctype_in_g ) )
self . c . write ( ' g_object_get (G_OBJECT (object), " %s " , &value, NULL); \n ' % ( p . name_hyphen ) )
if p . arg . free_func :
self . c . write ( ' if (value != NULL) \n '
' g_object_set_data_full (G_OBJECT (object), " -x-memoizing- %s " , (gpointer) value, (GDestroyNotify) %s ); \n '
' else \n '
' g_object_set_data_full (G_OBJECT (object), " -x-memoizing- %s " , (gpointer) value, NULL); \n '
% ( p . name_hyphen , p . arg . free_func , p . name_hyphen ) )
self . c . write ( ' return value; \n ' )
self . c . write ( ' } \n ' )
self . c . write ( ' \n ' )
# setter
2011-04-18 20:23:19 +02:00
if p . readable and p . writable :
hint = ' Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side. '
elif p . readable :
hint = ' Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side. '
elif p . writable :
hint = ' Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side. '
else :
raise RuntimeError ( ' Cannot handle property %s that neither readable nor writable ' % ( p . name ) )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _set_ %s : \n '
' * @object: A # %s . \n '
' * @value: The value to set. \n '
' * \n '
' * Sets the # %s : %s D-Bus property to @value. \n '
' * \n '
' * %s \n '
% ( i . name_lower , p . name_lower , i . camel_name , i . name , p . name , hint ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( p , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s _set_ %s ( %s *object, %s value) \n '
' { \n ' % ( i . name_lower , p . name_lower , i . camel_name , p . arg . ctype_in , ) )
self . c . write ( ' g_object_set (G_OBJECT (object), " %s " , value, NULL); \n ' % ( p . name_hyphen ) )
self . c . write ( ' } \n ' )
self . c . write ( ' \n ' )
# ---------------------------------------------------------------------------------------------------
def generate_signal_emitters ( self , i ) :
for s in i . signals :
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _emit_ %s : \n '
' * @object: A # %s . \n '
% ( i . name_lower , s . name_lower , i . camel_name ) ) )
for a in s . args :
self . c . write ( ' * @ %s : Argument to pass with the signal. \n ' % ( a . name ) )
self . c . write ( self . docbook_gen . expand (
' * \n '
' * Emits the # %s :: %s D-Bus signal. \n '
% ( i . name , s . name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( s , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s _emit_ %s ( \n '
' %s *object ' % ( i . name_lower , s . name_lower , i . camel_name ) )
for a in s . args :
self . c . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . c . write ( ' ) \n '
' { \n '
' g_signal_emit_by_name (object, " %s " ' % ( s . name_hyphen ) )
for a in s . args :
self . c . write ( ' , %s ' % a . name )
self . c . write ( ' ); \n ' )
self . c . write ( ' } \n '
' \n ' )
# ---------------------------------------------------------------------------------------------------
def generate_method_calls ( self , i ) :
for m in i . methods :
# async begin
2011-04-16 20:07:23 +02:00
self . c . write ( ' /** \n '
' * %s _call_ %s : \n '
2011-04-18 20:23:19 +02:00
' * @proxy: A # %s Proxy. \n '
% ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-16 20:07:23 +02:00
for a in m . in_args :
2011-04-18 20:23:19 +02:00
self . c . write ( ' * @ %s : Argument to pass with the method invocation. \n ' % ( a . name ) )
self . c . write ( self . docbook_gen . expand (
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %% NULL. \n '
' * @user_data: User data to pass to @callback. \n '
' * \n '
' * Asynchronously invokes the %s . %s () D-Bus method on @proxy. \n '
' * When the operation is finished, @callback will be invoked in the <link linkend= " g-main-context-push-thread-default " >thread-default main loop</link> of the thread you are calling this method from. \n '
' * You can then call %s _call_ %s _finish() to get the result of the operation. \n '
' * \n '
' * See %s _call_ %s _sync() for the synchronous, blocking version of this method. \n '
% ( i . name , m . name , i . name_lower , m . name_lower , i . name_lower , m . name_lower ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s _call_ %s ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . in_args :
self . c . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . c . write ( ' , \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data) \n '
' { \n ' )
self . c . write ( ' g_dbus_proxy_call (G_DBUS_PROXY (proxy), \n '
' " %s " , \n '
' g_variant_new ( " ( ' % ( m . name ) )
for a in m . in_args :
self . c . write ( ' %s ' % ( a . format_in ) )
self . c . write ( ' ) " ' )
for a in m . in_args :
self . c . write ( ' , \n %s ' % ( a . name ) )
self . c . write ( ' ), \n '
' G_DBUS_CALL_FLAGS_NONE, \n '
' -1, \n '
' cancellable, \n '
' callback, \n '
' user_data); \n ' )
self . c . write ( ' } \n '
' \n ' )
# async finish
2011-04-16 20:07:23 +02:00
self . c . write ( ' /** \n '
' * %s _call_ %s _finish: \n '
2011-04-18 20:23:19 +02:00
' * @proxy: A # %s Proxy. \n '
% ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-16 20:07:23 +02:00
for a in m . out_args :
2011-04-18 20:23:19 +02:00
self . c . write ( ' * @out_ %s : (out): Return location for return parameter or %% NULL to ignore. \n ' % ( a . name ) )
self . c . write ( self . docbook_gen . expand (
' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s _call_ %s (). \n '
' * @error: Return location for error or %% NULL. \n '
' * \n '
' * Finishes an operation started with %s _call_ %s (). \n '
' * \n '
' * Returns: %% TRUE if the call succeded, %% FALSE if @error is set. \n '
% ( i . name_lower , m . name_lower , i . name_lower , m . name_lower ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' gboolean \n '
' %s _call_ %s _finish ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . out_args :
self . c . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
self . c . write ( ' , \n '
' GAsyncResult *res, \n '
' GError **error) \n '
' { \n '
' GVariant *_ret; \n '
' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); \n '
' if (_ret == NULL) \n '
' goto _out; \n ' )
self . c . write ( ' g_variant_get (_ret, \n '
' \" ( ' )
for a in m . out_args :
self . c . write ( ' %s ' % ( a . format_out ) )
self . c . write ( ' ) " ' )
for a in m . out_args :
self . c . write ( ' , \n out_ %s ' % ( a . name ) )
self . c . write ( ' ); \n '
' g_variant_unref (_ret); \n ' )
self . c . write ( ' _out: \n '
' return _ret != NULL; \n '
' } \n '
' \n ' )
# sync
2011-04-16 20:07:23 +02:00
self . c . write ( ' /** \n '
' * %s _call_ %s _sync: \n '
2011-04-18 20:23:19 +02:00
' * @proxy: A # %s Proxy. \n '
% ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-16 20:07:23 +02:00
for a in m . in_args :
2011-04-18 20:23:19 +02:00
self . c . write ( ' * @ %s : Argument to pass with the method invocation. \n ' % ( a . name ) )
2011-04-16 20:07:23 +02:00
for a in m . out_args :
2011-04-18 20:23:19 +02:00
self . c . write ( ' * @out_ %s : (out): Return location for return parameter or %% NULL to ignore. \n ' % ( a . name ) )
self . c . write ( self . docbook_gen . expand (
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @error: Return location for error or %% NULL. \n '
' * \n '
' * Synchronously invokes the %s . %s () D-Bus method on @proxy. The calling thread is blocked until a reply is received. \n '
' * \n '
' * See %s _call_ %s () for the asynchronous version of this method. \n '
' * \n '
' * Returns: %% TRUE if the call succeded, %% FALSE if @error is set. \n '
% ( i . name , m . name , i . name_lower , m . name_lower ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' gboolean \n '
' %s _call_ %s _sync ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . in_args :
self . c . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
for a in m . out_args :
self . c . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
self . c . write ( ' , \n '
' GCancellable *cancellable, \n '
' GError **error) \n '
' { \n '
' GVariant *_ret; \n ' )
self . c . write ( ' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), \n '
' " %s " , \n '
' g_variant_new ( " ( ' % ( m . name ) )
for a in m . in_args :
self . c . write ( ' %s ' % ( a . format_in ) )
self . c . write ( ' ) " ' )
for a in m . in_args :
self . c . write ( ' , \n %s ' % ( a . name ) )
self . c . write ( ' ), \n '
' G_DBUS_CALL_FLAGS_NONE, \n '
' -1, \n '
' cancellable, \n '
' error); \n '
' if (_ret == NULL) \n '
' goto _out; \n ' )
self . c . write ( ' g_variant_get (_ret, \n '
' \" ( ' )
for a in m . out_args :
self . c . write ( ' %s ' % ( a . format_out ) )
self . c . write ( ' ) " ' )
for a in m . out_args :
self . c . write ( ' , \n out_ %s ' % ( a . name ) )
self . c . write ( ' ); \n '
' g_variant_unref (_ret); \n ' )
self . c . write ( ' _out: \n '
' return _ret != NULL; \n '
' } \n '
' \n ' )
# ---------------------------------------------------------------------------------------------------
def generate_method_completers ( self , i ) :
for m in i . methods :
2011-04-18 20:23:19 +02:00
self . c . write ( ' /** \n '
' * %s _complete_ %s : \n '
' * @object: A # %s . \n '
' * @invocation: (transfer full): A #GDBusMethodInvocation. \n '
% ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . out_args :
self . c . write ( ' * @ %s : Parameter to return. \n ' % ( a . name ) )
self . c . write ( self . docbook_gen . expand (
' * \n '
' * Helper function used in service implementations to finish handling invocations of the %s . %s () D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar. \n '
' * \n '
' * This method will free @invocation, you cannot use it afterwards. \n '
% ( i . name , m . name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s _complete_ %s ( \n '
' %s *object, \n '
' GDBusMethodInvocation *invocation ' % ( i . name_lower , m . name_lower , i . camel_name ) )
for a in m . out_args :
self . c . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . c . write ( ' ) \n '
' { \n ' )
self . c . write ( ' g_dbus_method_invocation_return_value (invocation, \n '
' g_variant_new ( " ( ' )
for a in m . out_args :
self . c . write ( ' %s ' % ( a . format_in ) )
self . c . write ( ' ) " ' )
for a in m . out_args :
self . c . write ( ' , \n %s ' % ( a . name ) )
self . c . write ( ' )); \n '
' } \n '
' \n ' )
# ---------------------------------------------------------------------------------------------------
def generate_proxy ( self , i ) :
# class boilerplate
self . c . write ( ' /* ------------------------------------------------------------------------ */ \n '
' \n ' )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s Proxy: \n '
' * \n '
' * The # %s Proxy structure contains only private data and should only be accessed using the provided API. \n '
% ( i . camel_name , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
self . c . write ( ' \n ' )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s ProxyClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s Proxy. \n '
% ( i . camel_name , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
self . c . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' static void \n '
' %s _proxy_iface_init ( %s Iface *iface) \n '
' { \n '
' } \n '
' \n ' % ( i . name_lower , i . camel_name ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' #define %s _proxy_get_type %s _proxy_get_type \n ' % ( i . name_lower , i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . c . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s Proxy, %s _proxy, G_TYPE_DBUS_PROXY, \n ' % ( i . camel_name , i . name_lower ) )
self . c . write ( ' G_IMPLEMENT_INTERFACE ( %s TYPE_ %s , %s _proxy_iface_init)); \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . c . write ( ' #undef %s _proxy_get_type \n '
' \n ' % ( i . name_lower ) )
# property accessors
#
# Note that we are guaranteed that prop_id starts at 1 and is
# laid out in the same order as introspection data pointers
#
self . c . write ( ' static void \n '
' %s _proxy_get_property (GObject *object, \n '
' guint prop_id, \n '
' GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n ' % ( i . name_lower ) )
if len ( i . properties ) > 0 :
self . c . write ( ' const _ExtendedGDBusPropertyInfo *info; \n '
' GVariant *variant; \n '
' g_assert (prop_id - 1 >= 0 && prop_id - 1 < %d ); \n '
' info = _ %s _property_info_pointers[prop_id - 1]; \n '
' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name); \n '
' if (info->use_gvariant) \n '
' g_value_set_variant (value, variant); \n '
' else \n '
' g_dbus_gvariant_to_gvalue (variant, value); \n '
' if (variant != NULL) \n '
' g_variant_unref (variant); \n '
% ( len ( i . properties ) , i . name_lower ) )
self . c . write ( ' } \n '
' \n ' )
if len ( i . properties ) > 0 :
self . c . write ( ' static void \n '
' %s _proxy_set_property_cb (GDBusProxy *proxy, \n '
' GAsyncResult *res, \n '
' gpointer user_data) \n '
' { \n ' % ( i . name_lower ) )
self . c . write ( ' const _ExtendedGDBusPropertyInfo *info = user_data; \n '
' GError *error; \n '
' error = NULL; \n '
' if (!g_dbus_proxy_call_finish (proxy, res, &error)) \n '
' { \n '
' g_warning ( " Error setting property ` %% s \' on interface %s : %% s ( %% s, %% d) " , \n '
' info->parent_struct.name, \n '
' error->message, g_quark_to_string (error->domain), error->code); \n '
' g_error_free (error); \n '
' } \n '
% ( i . name ) )
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' static void \n '
' %s _proxy_set_property (GObject *object, \n '
' guint prop_id, \n '
' const GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n ' % ( i . name_lower ) )
if len ( i . properties ) > 0 :
self . c . write ( ' const _ExtendedGDBusPropertyInfo *info; \n '
' GVariant *variant; \n '
' g_assert (prop_id - 1 >= 0 && prop_id - 1 < %d ); \n '
' info = _ %s _property_info_pointers[prop_id - 1]; \n '
' variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature)); \n '
' g_dbus_proxy_call (G_DBUS_PROXY (object), \n '
' " org.freedesktop.DBus.Properties.Set " , \n '
' g_variant_new ( " (ssv) " , " %s " , info->parent_struct.name, variant), \n '
' G_DBUS_CALL_FLAGS_NONE, \n '
' -1, \n '
' NULL, (GAsyncReadyCallback) %s _proxy_set_property_cb, (gpointer) info); \n '
' g_variant_unref (variant); \n '
% ( len ( i . properties ) , i . name_lower , i . name , i . name_lower ) )
self . c . write ( ' } \n '
' \n ' )
# signal received
self . c . write ( ' static void \n '
' %s _proxy_g_signal (GDBusProxy *proxy, \n '
' const gchar *sender_name, \n '
' const gchar *signal_name, \n '
' GVariant *parameters) \n '
' { \n ' % ( i . name_lower ) )
self . c . write ( ' _ExtendedGDBusSignalInfo *info; \n '
' GVariantIter iter; \n '
' GVariant *child; \n '
' GValue *paramv; \n '
' guint num_params; \n '
' guint n; \n '
' guint signal_id; \n ' ) ;
# Note: info could be NULL if we are talking to a newer version of the interface
self . c . write ( ' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_ %s _interface_info, signal_name); \n '
' if (info == NULL) \n '
' return; \n '
% ( i . name_lower ) )
self . c . write ( ' num_params = g_variant_n_children (parameters); \n '
' paramv = g_new0 (GValue, num_params + 1); \n '
' g_value_init (¶mv[0], %s TYPE_ %s ); \n '
' g_value_set_object (¶mv[0], proxy); \n '
% ( i . ns_upper , i . name_upper ) )
self . c . write ( ' g_variant_iter_init (&iter, parameters); \n '
' n = 1; \n '
' while ((child = g_variant_iter_next_value (&iter)) != NULL) \n '
' { \n '
' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1]; \n '
' if (arg_info->use_gvariant) \n '
' { \n '
' g_value_init (¶mv[n], G_TYPE_VARIANT); \n '
' g_value_set_variant (¶mv[n], child); \n '
' n++; \n '
' } \n '
' else \n '
' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); \n '
' g_variant_unref (child); \n '
' } \n '
)
self . c . write ( ' signal_id = g_signal_lookup (info->signal_name, %s TYPE_ %s ); \n '
% ( i . ns_upper , i . name_upper ) )
self . c . write ( ' g_signal_emitv (paramv, signal_id, 0, NULL); \n ' )
self . c . write ( ' for (n = 0; n < num_params + 1; n++) \n '
' g_value_unset (¶mv[n]); \n '
' g_free (paramv); \n ' )
self . c . write ( ' } \n '
' \n ' )
# property changed
self . c . write ( ' static void \n '
' %s _proxy_g_properties_changed (GDBusProxy *proxy, \n '
' GVariant *changed_properties, \n '
' const gchar *const *invalidated_properties) \n '
' { \n ' % ( i . name_lower ) )
# Note: info could be NULL if we are talking to a newer version of the interface
self . c . write ( ' guint n; \n '
' const gchar *key; \n '
' GVariantIter *iter; \n '
' _ExtendedGDBusPropertyInfo *info; \n '
' g_variant_get (changed_properties, " a {sv} " , &iter); \n '
' while (g_variant_iter_next (iter, " { &sv} " , &key, NULL)) \n '
' { \n '
' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_ %s _interface_info, key); \n '
' if (info != NULL) \n '
' g_object_notify (G_OBJECT (proxy), info->hyphen_name); \n '
' } \n '
' g_variant_iter_free (iter); \n '
' for (n = 0; invalidated_properties[n] != NULL; n++) \n '
' { \n '
' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_ %s _interface_info, invalidated_properties[n]); \n '
' if (info != NULL) \n '
' g_object_notify (G_OBJECT (proxy), info->hyphen_name); \n '
' } \n '
' } \n '
' \n '
% ( i . name_lower , i . name_lower ) )
# class boilerplate
self . c . write ( ' static void \n '
' %s _proxy_init ( %s Proxy *proxy) \n '
' { \n '
' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s _interface_info ()); \n '
' } \n '
' \n ' % ( i . name_lower , i . camel_name , i . name_lower ) )
self . c . write ( ' static void \n '
' %s _proxy_class_init ( %s ProxyClass *klass) \n '
' { \n '
' GObjectClass *gobject_class; \n '
' GDBusProxyClass *proxy_class; \n '
' \n '
' gobject_class = G_OBJECT_CLASS (klass); \n '
' gobject_class->get_property = %s _proxy_get_property; \n '
' gobject_class->set_property = %s _proxy_set_property; \n '
' \n '
' proxy_class = G_DBUS_PROXY_CLASS (klass); \n '
' proxy_class->g_signal = %s _proxy_g_signal; \n '
' proxy_class->g_properties_changed = %s _proxy_g_properties_changed; \n '
' \n ' % ( i . name_lower , i . camel_name , i . name_lower , i . name_lower , i . name_lower , i . name_lower ) )
if len ( i . properties ) > 0 :
self . c . write ( ' \n '
' %s _override_properties (gobject_class, 1); \n ' % ( i . name_lower ) )
2011-04-18 20:23:19 +02:00
self . c . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# constructors
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _proxy_new: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusProxyFlags enumeration. \n '
' * @name: (allow-none): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @callback: A #GAsyncReadyCallback to call when the request is satisfied. \n '
' * @user_data: User data to pass to @callback. \n '
' * \n '
' * Asynchronously creates a proxy for the D-Bus interface # %s . See g_dbus_proxy_new() for more details. \n '
' * \n '
' * When the operation is finished, @callback will be invoked in the <link linkend= " g-main-context-push-thread-default " >thread-default main loop</link> of the thread you are calling this method from. \n '
' * You can then call %s _proxy_new_finish() to get the result of the operation. \n '
' * \n '
' * See %s _proxy_new_sync() for the synchronous, blocking version of this constructor. \n '
% ( i . name_lower , i . name , i . name_lower , i . name_lower ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s _proxy_new ( \n '
' GDBusConnection *connection, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data) \n '
' { \n '
' g_async_initable_new_async ( %s TYPE_ %s _PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, " g-flags " , flags, " g-name " , name, " g-connection " , connection, " g-object-path " , object_path, " g-interface-name " , " %s " , NULL); \n '
' } \n '
' \n '
% ( i . name_lower , i . ns_upper , i . name_upper , i . name ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' /** \n '
' * %s _proxy_new_finish: \n '
2011-04-18 20:23:19 +02:00
' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s _proxy_new(). \n '
' * @error: Return location for error or %% NULL \n '
2011-04-16 20:07:23 +02:00
' * \n '
2011-04-18 20:23:19 +02:00
' * Finishes an operation started with %s _proxy_new(). \n '
' * \n '
' * Returns: (transfer full) (type %s Proxy): The constructed proxy object or %% NULL if @error is set. \n '
% ( i . name_lower , i . name_lower , i . name_lower , i . camel_name ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' %s * \n '
' %s _proxy_new_finish ( \n '
' GAsyncResult *res, \n '
' GError **error) \n '
' { \n '
' GObject *ret; \n '
' GObject *source_object; \n '
' source_object = g_async_result_get_source_object (res); \n '
' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); \n '
' g_object_unref (source_object); \n '
' if (ret != NULL) \n '
' return %s %s (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( i . camel_name , i . name_lower , i . ns_upper , i . name_upper ) )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _proxy_new_sync: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusProxyFlags enumeration. \n '
' * @name: (allow-none): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
' * Synchronously creates a proxy for the D-Bus interface # %s . See g_dbus_proxy_new_sync() for more details. \n '
' * \n '
' * The calling thread is blocked until a reply is received. \n '
' * \n '
' * See %s _proxy_new() for the asynchronous version of this constructor. \n '
' * \n '
' * Returns: (transfer full) (type %s Proxy): The constructed proxy object or %% NULL if @error is set. \n '
% ( i . name_lower , i . name , i . name_lower , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' %s * \n '
' %s _proxy_new_sync ( \n '
' GDBusConnection *connection, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error) \n '
' { \n '
' GInitable *ret; \n '
' ret = g_initable_new ( %s TYPE_ %s _PROXY, cancellable, error, " g-flags " , flags, " g-name " , name, " g-connection " , connection, " g-object-path " , object_path, " g-interface-name " , " %s " , NULL); \n '
' if (ret != NULL) \n '
' return %s %s (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( i . camel_name , i . name_lower , i . ns_upper , i . name_upper , i . name , i . ns_upper , i . name_upper ) )
self . c . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _proxy_new_for_bus: \n '
' * @bus_type: A #GBusType. \n '
' * @flags: Flags from the #GDBusProxyFlags enumeration. \n '
' * @name: A bus name (well-known or unique). \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @callback: A #GAsyncReadyCallback to call when the request is satisfied. \n '
' * @user_data: User data to pass to @callback. \n '
' * \n '
' * Like %s _proxy_new() but takes a #GBusType instead of a #GDBusConnection. \n '
' * \n '
' * When the operation is finished, @callback will be invoked in the <link linkend= " g-main-context-push-thread-default " >thread-default main loop</link> of the thread you are calling this method from. \n '
' * You can then call %s _proxy_new_for_bus_finish() to get the result of the operation. \n '
' * \n '
' * See %s _proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor. \n '
% ( i . name_lower , i . name_lower , i . name_lower , i . name_lower ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s _proxy_new_for_bus ( \n '
' GBusType bus_type, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data) \n '
' { \n '
' g_async_initable_new_async ( %s TYPE_ %s _PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, " g-flags " , flags, " g-name " , name, " g-bus-type " , bus_type, " g-object-path " , object_path, " g-interface-name " , " %s " , NULL); \n '
' } \n '
' \n '
% ( i . name_lower , i . ns_upper , i . name_upper , i . name ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' /** \n '
' * %s _proxy_new_for_bus_finish: \n '
2011-04-18 20:23:19 +02:00
' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s _proxy_new_for_bus(). \n '
' * @error: Return location for error or %% NULL \n '
2011-04-16 20:07:23 +02:00
' * \n '
2011-04-18 20:23:19 +02:00
' * Finishes an operation started with %s _proxy_new_for_bus(). \n '
' * \n '
' * Returns: (transfer full) (type %s Proxy): The constructed proxy object or %% NULL if @error is set. \n '
% ( i . name_lower , i . name_lower , i . name_lower , i . camel_name ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' %s * \n '
' %s _proxy_new_for_bus_finish ( \n '
' GAsyncResult *res, \n '
' GError **error) \n '
' { \n '
' GObject *ret; \n '
' GObject *source_object; \n '
' source_object = g_async_result_get_source_object (res); \n '
' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); \n '
' g_object_unref (source_object); \n '
' if (ret != NULL) \n '
' return %s %s (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( i . camel_name , i . name_lower , i . ns_upper , i . name_upper ) )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _proxy_new_for_bus_sync: \n '
' * @bus_type: A #GBusType. \n '
' * @flags: Flags from the #GDBusProxyFlags enumeration. \n '
' * @name: A bus name (well-known or unique). \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
' * Like %s _proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection. \n '
' * \n '
' * The calling thread is blocked until a reply is received. \n '
' * \n '
' * See %s _proxy_new_for_bus() for the asynchronous version of this constructor. \n '
' * \n '
' * Returns: (transfer full) (type %s Proxy): The constructed proxy object or %% NULL if @error is set. \n '
% ( i . name_lower , i . name_lower , i . name_lower , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' %s * \n '
' %s _proxy_new_for_bus_sync ( \n '
' GBusType bus_type, \n '
' GDBusProxyFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error) \n '
' { \n '
' GInitable *ret; \n '
' ret = g_initable_new ( %s TYPE_ %s _PROXY, cancellable, error, " g-flags " , flags, " g-name " , name, " g-bus-type " , bus_type, " g-object-path " , object_path, " g-interface-name " , " %s " , NULL); \n '
' if (ret != NULL) \n '
' return %s %s (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( i . camel_name , i . name_lower , i . ns_upper , i . name_upper , i . name , i . ns_upper , i . name_upper ) )
self . c . write ( ' \n ' )
# ---------------------------------------------------------------------------------------------------
2011-04-13 22:33:51 +02:00
def generate_skeleton ( self , i ) :
2011-04-08 22:57:31 +02:00
# class boilerplate
self . c . write ( ' /* ------------------------------------------------------------------------ */ \n '
' \n ' )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s Skeleton: \n '
' * \n '
' * The # %s Skeleton structure contains only private data and should only be accessed using the provided API. \n '
% ( i . camel_name , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
self . c . write ( ' \n ' )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s SkeletonClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s Skeleton. \n '
% ( i . camel_name , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
self . c . write ( ' \n ' )
2011-04-13 22:33:51 +02:00
self . c . write ( ' struct _ %s SkeletonPrivate \n '
2011-04-08 22:57:31 +02:00
' { \n '
' GValueArray *properties; \n '
' GList *changed_properties; \n '
' GSource *changed_properties_idle_source; \n '
' GMainContext *context; \n '
' }; \n '
' \n ' % i . camel_name )
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' _ %s _skeleton_handle_method_call ( \n '
2011-04-08 22:57:31 +02:00
' GDBusConnection *connection, \n '
' const gchar *sender, \n '
' const gchar *object_path, \n '
' const gchar *interface_name, \n '
' const gchar *method_name, \n '
' GVariant *parameters, \n '
' GDBusMethodInvocation *invocation, \n '
' gpointer user_data) \n '
' { \n '
2011-04-13 22:33:51 +02:00
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
2011-04-08 22:57:31 +02:00
' _ExtendedGDBusMethodInfo *info; \n '
' GVariantIter iter; \n '
' GVariant *child; \n '
' GValue *paramv; \n '
' guint num_params; \n '
' guint n; \n '
' guint signal_id; \n '
' GValue return_value = {0} ; \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . c . write ( ' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation); \n '
' g_assert (info != NULL); \n '
% ( ) )
self . c . write ( ' num_params = g_variant_n_children (parameters); \n '
' paramv = g_new0 (GValue, num_params + 2); \n '
' g_value_init (¶mv[0], %s TYPE_ %s ); \n '
2011-04-13 22:33:51 +02:00
' g_value_set_object (¶mv[0], skeleton); \n '
2011-04-08 22:57:31 +02:00
' g_value_init (¶mv[1], G_TYPE_DBUS_METHOD_INVOCATION); \n '
' g_value_set_object (¶mv[1], invocation); \n '
% ( i . ns_upper , i . name_upper ) )
self . c . write ( ' g_variant_iter_init (&iter, parameters); \n '
' n = 2; \n '
' while ((child = g_variant_iter_next_value (&iter)) != NULL) \n '
' { \n '
' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - 2]; \n '
' if (arg_info->use_gvariant) \n '
' { \n '
' g_value_init (¶mv[n], G_TYPE_VARIANT); \n '
' g_value_set_variant (¶mv[n], child); \n '
' n++; \n '
' } \n '
' else \n '
' g_dbus_gvariant_to_gvalue (child, ¶mv[n++]); \n '
' g_variant_unref (child); \n '
' } \n '
)
self . c . write ( ' signal_id = g_signal_lookup (info->signal_name, %s TYPE_ %s ); \n '
% ( i . ns_upper , i . name_upper ) )
self . c . write ( ' g_value_init (&return_value, G_TYPE_BOOLEAN); \n '
' g_signal_emitv (paramv, signal_id, 0, &return_value); \n '
' if (!g_value_get_boolean (&return_value)) \n '
' g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, " Method %s is not implemented on interface %s " , method_name, interface_name); \n '
' g_value_unset (&return_value); \n '
)
self . c . write ( ' for (n = 0; n < num_params + 2; n++) \n '
' g_value_unset (¶mv[n]); \n '
' g_free (paramv); \n ' )
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' static GVariant * \n '
2011-04-13 22:33:51 +02:00
' _ %s _skeleton_handle_get_property ( \n '
2011-04-08 22:57:31 +02:00
' GDBusConnection *connection, \n '
' const gchar *sender, \n '
' const gchar *object_path, \n '
' const gchar *interface_name, \n '
' const gchar *property_name, \n '
' GError **error, \n '
' gpointer user_data) \n '
' { \n '
2011-04-13 22:33:51 +02:00
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
2011-04-08 22:57:31 +02:00
' GValue value = {0} ; \n '
' GParamSpec *pspec; \n '
' _ExtendedGDBusPropertyInfo *info; \n '
' GVariant *ret; \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . c . write ( ' ret = NULL; \n '
' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_ %s _interface_info, property_name); \n '
' g_assert (info != NULL); \n '
2011-04-13 22:33:51 +02:00
' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); \n '
2011-04-08 22:57:31 +02:00
' if (pspec == NULL) \n '
' { \n '
' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, " No property with name %% s " , property_name); \n '
' } \n '
' else \n '
' { \n '
' g_value_init (&value, pspec->value_type); \n '
2011-04-13 22:33:51 +02:00
' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value); \n '
2011-04-08 22:57:31 +02:00
' ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature)); \n '
' g_value_unset (&value); \n '
' } \n '
' return ret; \n '
' } \n '
' \n '
% ( i . name_lower ) )
self . c . write ( ' static gboolean \n '
2011-04-13 22:33:51 +02:00
' _ %s _skeleton_handle_set_property ( \n '
2011-04-08 22:57:31 +02:00
' GDBusConnection *connection, \n '
' const gchar *sender, \n '
' const gchar *object_path, \n '
' const gchar *interface_name, \n '
' const gchar *property_name, \n '
' GVariant *variant, \n '
' GError **error, \n '
' gpointer user_data) \n '
' { \n '
2011-04-13 22:33:51 +02:00
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
2011-04-08 22:57:31 +02:00
' GValue value = {0} ; \n '
' GParamSpec *pspec; \n '
' _ExtendedGDBusPropertyInfo *info; \n '
' gboolean ret; \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . c . write ( ' ret = FALSE; \n '
' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_ %s _interface_info, property_name); \n '
' g_assert (info != NULL); \n '
2011-04-13 22:33:51 +02:00
' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); \n '
2011-04-08 22:57:31 +02:00
' if (pspec == NULL) \n '
' { \n '
' g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, " No property with name %% s " , property_name); \n '
' } \n '
' else \n '
' { \n '
' if (info->use_gvariant) \n '
' g_value_set_variant (&value, variant); \n '
' else \n '
' g_dbus_gvariant_to_gvalue (variant, &value); \n '
2011-04-13 22:33:51 +02:00
' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value); \n '
2011-04-08 22:57:31 +02:00
' g_value_unset (&value); \n '
' ret = TRUE; \n '
' } \n '
' return ret; \n '
' } \n '
' \n '
% ( i . name_lower ) )
2011-04-13 22:33:51 +02:00
self . c . write ( ' static const GDBusInterfaceVTable _ %s _skeleton_vtable = \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-13 22:33:51 +02:00
' _ %s _skeleton_handle_method_call, \n '
' _ %s _skeleton_handle_get_property, \n '
' _ %s _skeleton_handle_set_property \n '
2011-04-08 22:57:31 +02:00
' }; \n '
' \n ' % ( i . name_lower , i . name_lower , i . name_lower , i . name_lower ) )
self . c . write ( ' static GDBusInterfaceInfo * \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton) \n '
2011-04-08 22:57:31 +02:00
' { \n '
' return %s _interface_info (); \n '
% ( i . name_lower , i . name_lower ) )
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' static GDBusInterfaceVTable * \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton) \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-13 22:33:51 +02:00
' return (GDBusInterfaceVTable *) &_ %s _skeleton_vtable; \n '
2011-04-08 22:57:31 +02:00
% ( i . name_lower , i . name_lower ) )
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' static GVariant * \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton) \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-13 22:33:51 +02:00
' %s Skeleton *skeleton = %s %s _SKELETON (_skeleton); \n '
2011-04-08 22:57:31 +02:00
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . c . write ( ' \n '
' GVariantBuilder builder; \n '
' guint n; \n '
' g_variant_builder_init (&builder, G_VARIANT_TYPE ( " a {sv} " )); \n '
' if (_ %s _interface_info.properties == NULL) \n '
' goto out; \n '
' for (n = 0; _ %s _interface_info.properties[n] != NULL; n++) \n '
' { \n '
' GDBusPropertyInfo *info = _ %s _interface_info.properties[n]; \n '
' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) \n '
' { \n '
' GVariant *value; \n '
2011-04-13 22:33:51 +02:00
' value = _ %s _skeleton_handle_get_property (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), " %s " , info->name, NULL, skeleton); \n '
2011-04-08 22:57:31 +02:00
' if (value != NULL) \n '
' { \n '
' if (g_variant_is_floating (value)) \n '
' g_variant_ref_sink (value); \n '
' g_variant_builder_add (&builder, " {sv} " , info->name, value); \n '
' g_variant_unref (value); \n '
' } \n '
' } \n '
' } \n '
' out: \n '
' return g_variant_builder_end (&builder); \n '
' } \n '
' \n '
% ( i . name_lower , i . name_lower , i . name_lower , i . name_lower , i . name ) )
if len ( i . properties ) > 0 :
self . c . write ( ' static gboolean _ %s _emit_changed (gpointer user_data); \n '
' \n '
% ( i . name_lower ) )
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton) \n '
2011-04-08 22:57:31 +02:00
' { \n '
% ( i . name_lower ) )
if len ( i . properties ) > 0 :
2011-04-13 22:33:51 +02:00
self . c . write ( ' %s Skeleton *skeleton = %s %s _SKELETON (_skeleton); \n '
' if (skeleton->priv->changed_properties_idle_source != NULL) \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-13 22:33:51 +02:00
' g_source_destroy (skeleton->priv->changed_properties_idle_source); \n '
' skeleton->priv->changed_properties_idle_source = NULL; \n '
' _ %s _emit_changed (skeleton); \n '
2011-04-08 22:57:31 +02:00
' } \n '
% ( i . camel_name , i . ns_upper , i . name_upper , i . name_lower ) )
self . c . write ( ' } \n '
' \n ' )
for s in i . signals :
self . c . write ( ' static void \n '
' _ %s _on_signal_ %s ( \n '
' %s *object ' % ( i . name_lower , s . name_lower , i . camel_name ) )
for a in s . args :
self . c . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . c . write ( ' ) \n '
' { \n '
2011-04-13 22:33:51 +02:00
' %s Skeleton *skeleton = %s %s _SKELETON (object); \n '
' GDBusConnection *connection = g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)); \n '
2011-04-08 22:57:31 +02:00
% ( i . camel_name , i . ns_upper , i . name_upper ) )
self . c . write ( ' if (connection == NULL) \n '
' return; \n '
' g_dbus_connection_emit_signal (connection, \n '
2011-04-13 22:33:51 +02:00
' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), " %s " , " %s " , \n '
2011-04-08 22:57:31 +02:00
' g_variant_new ( " ( '
% ( i . name , s . name ) )
for a in s . args :
self . c . write ( ' %s ' % ( a . format_in ) )
self . c . write ( ' ) " ' )
for a in s . args :
self . c . write ( ' , \n %s ' % ( a . name ) )
self . c . write ( ' ), NULL); \n ' )
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_iface_init ( %s Iface *iface) \n '
2011-04-08 22:57:31 +02:00
' { \n '
% ( i . name_lower , i . camel_name ) )
for s in i . signals :
self . c . write ( ' iface-> %s = _ %s _on_signal_ %s ; \n '
% ( s . name_lower , i . name_lower , s . name_lower ) )
self . c . write ( ' } \n '
' \n ' )
2011-04-16 20:07:23 +02:00
self . c . write ( ' #define %s _skeleton_get_type %s _skeleton_get_type \n ' % ( i . name_lower , i . name_lower ) )
2011-04-13 22:33:51 +02:00
self . c . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s Skeleton, %s _skeleton, G_TYPE_DBUS_INTERFACE_SKELETON, \n ' % ( i . camel_name , i . name_lower ) )
self . c . write ( ' G_IMPLEMENT_INTERFACE ( %s TYPE_ %s , %s _skeleton_iface_init)); \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . c . write ( ' #undef %s _skeleton_get_type \n '
2011-04-08 22:57:31 +02:00
' \n ' % ( i . name_lower ) )
# finalize
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_finalize (GObject *object) \n '
2011-04-08 22:57:31 +02:00
' { \n ' % ( i . name_lower ) )
2011-04-13 22:33:51 +02:00
self . c . write ( ' %s Skeleton *skeleton = %s %s _SKELETON (object); \n ' % ( i . camel_name , i . ns_upper , i . name_upper ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2011-04-13 22:33:51 +02:00
self . c . write ( ' g_value_array_free (skeleton->priv->properties); \n ' )
self . c . write ( ' g_list_foreach (skeleton->priv->changed_properties, (GFunc) _changed_property_free, NULL); \n ' )
self . c . write ( ' g_list_free (skeleton->priv->changed_properties); \n ' )
self . c . write ( ' if (skeleton->priv->changed_properties_idle_source != NULL) \n ' )
self . c . write ( ' g_source_destroy (skeleton->priv->changed_properties_idle_source); \n ' )
self . c . write ( ' if (skeleton->priv->context != NULL) \n ' )
self . c . write ( ' g_main_context_unref (skeleton->priv->context); \n ' )
self . c . write ( ' G_OBJECT_CLASS ( %s _skeleton_parent_class)->finalize (object); \n '
2011-04-08 22:57:31 +02:00
' } \n '
' \n ' % ( i . name_lower ) )
# property accessors (TODO: generate PropertiesChanged signals in setter)
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_get_property (GObject *object, \n '
2011-04-08 22:57:31 +02:00
' guint prop_id, \n '
' GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n ' % ( i . name_lower ) )
2011-04-13 22:33:51 +02:00
self . c . write ( ' %s Skeleton *skeleton = %s %s _SKELETON (object); \n '
2011-04-08 22:57:31 +02:00
' g_assert (prop_id - 1 >= 0 && prop_id - 1 < %d ); \n '
2011-04-13 22:33:51 +02:00
' g_value_copy (&skeleton->priv->properties->values[prop_id - 1], value); \n '
2011-04-08 22:57:31 +02:00
% ( i . camel_name , i . ns_upper , i . name_upper , len ( i . properties ) ) )
self . c . write ( ' } \n '
' \n ' )
if len ( i . properties ) > 0 :
2011-04-15 21:53:28 +02:00
# if property is already scheduled then re-use entry.. though it could be
# that the user did
#
# foo_set_prop_bar (object, "");
# foo_set_prop_bar (object, "blah");
#
# say, every update... In this case, where nothing happens, we obviously
# don't want a PropertiesChanged() event. We can easily check for this
# by comparing against the _original value_ recorded before the first
# change event. If the latest value is not different from the original
# one, we can simply ignore the ChangedProperty
#
2011-04-08 22:57:31 +02:00
self . c . write ( ' static gboolean \n '
' _ %s _emit_changed (gpointer user_data) \n '
' { \n '
2011-04-13 22:33:51 +02:00
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
2011-04-08 22:57:31 +02:00
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . c . write ( ' GList *l; \n '
' GVariantBuilder builder; \n '
' GVariantBuilder invalidated_builder; \n '
2011-04-15 22:11:43 +02:00
' guint num_changes; \n '
2011-04-08 22:57:31 +02:00
' g_variant_builder_init (&builder, G_VARIANT_TYPE ( " a {sv} " )); \n '
' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ( " as " )); \n '
2011-04-15 22:11:43 +02:00
' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next) \n '
2011-04-08 22:57:31 +02:00
' { \n '
' ChangedProperty *cp = l->data; \n '
' GVariant *variant; \n '
2011-04-15 21:53:28 +02:00
' const GValue *cur_value; \n '
' \n '
' cur_value = &skeleton->priv->properties->values[cp->prop_id - 1]; \n '
' if (!_g_value_equal (cur_value, &cp->orig_value)) \n '
' { \n '
' variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature)); \n '
' g_variant_builder_add (&builder, " {sv} " , cp->info->parent_struct.name, variant); \n '
' g_variant_unref (variant); \n '
2011-04-15 22:11:43 +02:00
' num_changes++; \n '
2011-04-15 21:53:28 +02:00
' } \n '
2011-04-08 22:57:31 +02:00
' } \n '
2011-04-15 22:11:43 +02:00
' if (num_changes > 0) \n '
' { \n '
' g_dbus_connection_emit_signal (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), \n '
' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), \n '
' " org.freedesktop.DBus.Properties " , \n '
' " PropertiesChanged " , \n '
' g_variant_new ( " (sa {sv} as) " , \n '
' " %s " , \n '
' &builder, &invalidated_builder), \n '
' NULL); \n '
' } \n '
' else \n '
' { \n '
' g_variant_builder_clear (&builder); \n '
' g_variant_builder_clear (&invalidated_builder); \n '
' } \n '
2011-04-08 22:57:31 +02:00
% ( i . name ) )
2011-04-13 22:33:51 +02:00
self . c . write ( ' g_list_foreach (skeleton->priv->changed_properties, (GFunc) _changed_property_free, NULL); \n ' )
self . c . write ( ' g_list_free (skeleton->priv->changed_properties); \n ' )
self . c . write ( ' skeleton->priv->changed_properties = NULL; \n ' )
self . c . write ( ' skeleton->priv->changed_properties_idle_source = NULL; \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' return FALSE; \n '
' } \n '
' \n ' )
self . c . write ( ' static void \n '
2011-04-15 21:53:28 +02:00
' _ %s _schedule_emit_changed ( %s Skeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value) \n '
2011-04-08 22:57:31 +02:00
' { \n '
' ChangedProperty *cp; \n '
' GList *l; \n '
' cp = NULL; \n '
2011-04-13 22:33:51 +02:00
' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next) \n '
2011-04-08 22:57:31 +02:00
' { \n '
' ChangedProperty *i_cp = l->data; \n '
' if (i_cp->info == info) \n '
' { \n '
' cp = i_cp; \n '
' break; \n '
' } \n '
' } \n '
2011-04-15 21:53:28 +02:00
% ( i . name_lower , i . camel_name ) )
self . c . write ( ' if (cp == NULL) \n '
2011-04-08 22:57:31 +02:00
' { \n '
' cp = g_new0 (ChangedProperty, 1); \n '
2011-04-15 21:53:28 +02:00
' cp->prop_id = prop_id; \n '
2011-04-08 22:57:31 +02:00
' cp->info = info; \n '
2011-04-13 22:33:51 +02:00
' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp); \n '
2011-04-15 21:53:28 +02:00
' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value)); \n '
' g_value_copy (orig_value, &cp->orig_value); \n '
2011-04-08 22:57:31 +02:00
' } \n '
2011-04-13 22:33:51 +02:00
' if (skeleton->priv->changed_properties_idle_source == NULL) \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-13 22:33:51 +02:00
' skeleton->priv->changed_properties_idle_source = g_idle_source_new (); \n '
' g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT); \n '
' g_source_set_callback (skeleton->priv->changed_properties_idle_source, _ %s _emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref); \n '
' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context); \n '
' g_source_unref (skeleton->priv->changed_properties_idle_source); \n '
2011-04-08 22:57:31 +02:00
' } \n '
' } \n '
' \n '
2011-04-15 21:53:28 +02:00
% ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_set_property (GObject *object, \n '
2011-04-08 22:57:31 +02:00
' guint prop_id, \n '
' const GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n ' % ( i . name_lower ) )
if len ( i . properties ) > 0 :
2011-04-13 22:33:51 +02:00
self . c . write ( ' %s Skeleton *skeleton = %s %s _SKELETON (object); \n '
2011-04-08 22:57:31 +02:00
' g_assert (prop_id - 1 >= 0 && prop_id - 1 < %d ); \n '
2011-04-13 22:33:51 +02:00
' if (!_g_value_equal (value, &skeleton->priv->properties->values[prop_id - 1])) \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-15 21:53:28 +02:00
' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL) \n '
' _ %s _schedule_emit_changed (skeleton, _ %s _property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties->values[prop_id - 1]); \n '
2011-04-13 22:33:51 +02:00
' g_value_copy (value, &skeleton->priv->properties->values[prop_id - 1]); \n '
2011-04-08 22:57:31 +02:00
' g_object_notify_by_pspec (object, pspec); \n '
' } \n '
% ( i . camel_name , i . ns_upper , i . name_upper , len ( i . properties ) , i . name_lower , i . name_lower ) )
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_init ( %s Skeleton *skeleton) \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-13 22:33:51 +02:00
' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %s TYPE_ %s _SKELETON, %s SkeletonPrivate); \n '
2011-04-08 22:57:31 +02:00
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper , i . camel_name ) )
2011-04-13 22:33:51 +02:00
self . c . write ( ' skeleton->priv->context = g_main_context_get_thread_default (); \n ' )
self . c . write ( ' if (skeleton->priv->context != NULL) \n ' )
self . c . write ( ' g_main_context_ref (skeleton->priv->context); \n ' )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2011-04-13 22:33:51 +02:00
self . c . write ( ' skeleton->priv->properties = g_value_array_new ( %d ); \n ' % ( len ( i . properties ) ) )
2011-04-08 22:57:31 +02:00
n = 0
for p in i . properties :
2011-04-13 22:33:51 +02:00
self . c . write ( ' g_value_array_append (skeleton->priv->properties, NULL); \n ' )
self . c . write ( ' g_value_init (&skeleton->priv->properties->values[ %d ], %s ); \n ' % ( n , p . arg . gtype ) )
2011-04-08 22:57:31 +02:00
n + = 1
self . c . write ( ' } \n '
' \n ' )
self . c . write ( ' static void \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_class_init ( %s SkeletonClass *klass) \n '
2011-04-08 22:57:31 +02:00
' { \n '
' GObjectClass *gobject_class; \n '
2011-04-13 22:33:51 +02:00
' GDBusInterfaceSkeletonClass *skeleton_class; \n '
2011-04-08 22:57:31 +02:00
' \n '
2011-04-13 22:33:51 +02:00
' g_type_class_add_private (klass, sizeof ( %s SkeletonPrivate)); \n '
2011-04-08 22:57:31 +02:00
' \n '
' gobject_class = G_OBJECT_CLASS (klass); \n '
2011-04-13 22:33:51 +02:00
' gobject_class->finalize = %s _skeleton_finalize; \n '
' gobject_class->get_property = %s _skeleton_get_property; \n '
' gobject_class->set_property = %s _skeleton_set_property; \n '
2011-04-08 22:57:31 +02:00
' \n ' % ( i . name_lower , i . camel_name , i . camel_name , i . name_lower , i . name_lower , i . name_lower ) )
if len ( i . properties ) > 0 :
self . c . write ( ' \n '
' %s _override_properties (gobject_class, 1); \n ' % ( i . name_lower ) )
self . c . write ( ' \n '
2011-04-13 22:33:51 +02:00
' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass); \n ' ) ;
self . c . write ( ' skeleton_class->get_info = %s _skeleton_dbus_interface_get_info; \n ' % ( i . name_lower ) )
self . c . write ( ' skeleton_class->get_properties = %s _skeleton_dbus_interface_get_properties; \n ' % ( i . name_lower ) )
self . c . write ( ' skeleton_class->flush = %s _skeleton_dbus_interface_flush; \n ' % ( i . name_lower ) )
self . c . write ( ' skeleton_class->get_vtable = %s _skeleton_dbus_interface_get_vtable; \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
self . c . write ( ' } \n '
' \n ' )
# constructors
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s _skeleton_new: \n '
' * \n '
' * Creates a skeleton object for the D-Bus interface # %s . \n '
' * \n '
' * Returns: (transfer full) (type %s Skeleton): The skeleton object. \n '
% ( i . name_lower , i . name , i . camel_name ) ) )
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . c , 0 )
2011-04-08 22:57:31 +02:00
self . c . write ( ' %s * \n '
2011-04-13 22:33:51 +02:00
' %s _skeleton_new (void) \n '
2011-04-08 22:57:31 +02:00
' { \n '
2011-04-13 22:33:51 +02:00
' return %s %s (g_object_new ( %s TYPE_ %s _SKELETON, NULL)); \n '
2011-04-08 22:57:31 +02:00
' } \n '
' \n ' % ( i . camel_name , i . name_lower , i . ns_upper , i . name_upper , i . ns_upper , i . name_upper ) )
# ---------------------------------------------------------------------------------------------------
def generate_object_manager_client ( self ) :
self . c . write ( ' /* ------------------------------------------------------------------------ \n '
2011-04-18 20:23:19 +02:00
' * Code for ObjectManager client \n '
2011-04-08 22:57:31 +02:00
' * ------------------------------------------------------------------------ \n '
' */ \n '
' \n ' )
2011-04-19 20:39:47 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * SECTION: %s ObjectManagerClient \n '
' * @title: %s ObjectManagerClient \n '
' * @short_description: Generated #GDBusObjectManagerClient subclass \n '
' * \n '
' * This section contains a #GDBusObjectManagerClient that uses %s object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. \n '
' */ \n '
% ( self . namespace , self . namespace , self . ns_lower ) ) )
self . c . write ( ' \n ' )
2011-04-19 19:16:10 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s ObjectManagerClient: \n '
' * \n '
' * The # %s ObjectManagerClient structure contains only private data and should only be accessed using the provided API. \n '
% ( self . namespace , self . namespace ) ) )
self . c . write ( ' */ \n ' )
self . c . write ( ' \n ' )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s ObjectManagerClientClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s ObjectManagerClient. \n '
% ( self . namespace , self . namespace ) ) )
self . c . write ( ' */ \n ' )
self . c . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# class boilerplate
2011-04-18 20:23:19 +02:00
self . c . write ( ' G_DEFINE_TYPE ( %s ObjectManagerClient, %s object_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT); \n '
' \n '
% ( self . namespace , self . ns_lower ) )
2011-04-08 22:57:31 +02:00
# class boilerplate
self . c . write ( ' static void \n '
' %s object_manager_client_init ( %s ObjectManagerClient *manager) \n '
' { \n '
' } \n '
' \n ' % ( self . ns_lower , self . namespace ) )
self . c . write ( ' static void \n '
' %s object_manager_client_class_init ( %s ObjectManagerClientClass *klass) \n '
' { \n '
' } \n '
' \n ' % ( self . ns_lower , self . namespace ) )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s object_manager_client_get_proxy_type: \n '
' * @manager: A #GDBusObjectManagerClient. \n '
' * @object_path: The object path of the remote object (unused). \n '
' * @interface_name: Interface name of the remote object. \n '
' * @user_data: User data (unused). \n '
' * \n '
2011-04-19 19:39:12 +02:00
' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusProxy<!-- -->-derived types. \n '
2011-04-19 19:10:25 +02:00
' * \n '
' * Returns: A #GDBusProxy<!-- -->-derived #GType. \n '
2011-04-18 20:23:19 +02:00
% ( self . ns_lower ) ) )
self . c . write ( ' */ \n ' )
2011-04-16 20:07:23 +02:00
self . c . write ( ' GType \n '
' %s object_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data) \n '
2011-04-08 22:57:31 +02:00
' { \n '
% ( self . ns_lower ) )
self . c . write ( ' static gsize once_init_value = 0; \n '
' static GHashTable *lookup_hash; \n '
' GType ret; \n '
' \n '
' if (g_once_init_enter (&once_init_value)) \n '
' { \n '
' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal); \n ' )
for i in self . ifaces :
self . c . write ( ' g_hash_table_insert (lookup_hash, " %s " , GSIZE_TO_POINTER ( %s TYPE_ %s _PROXY)); \n '
% ( i . name , i . ns_upper , i . name_upper ) )
self . c . write ( ' g_once_init_leave (&once_init_value, 1); \n '
' } \n ' )
self . c . write ( ' ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name)); \n '
' if (ret == (GType) 0) \n '
' ret = G_TYPE_DBUS_PROXY; \n ' )
self . c . write ( ' return ret; \n '
' } \n '
' \n ' )
# constructors
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s object_manager_client_new: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. \n '
' * @name: (allow-none): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @callback: A #GAsyncReadyCallback to call when the request is satisfied. \n '
' * @user_data: User data to pass to @callback. \n '
' * \n '
2011-04-19 19:39:12 +02:00
' * Asynchronously creates #GDBusObjectManagerClient using %s object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details. \n '
2011-04-18 20:23:19 +02:00
' * \n '
' * When the operation is finished, @callback will be invoked in the <link linkend= " g-main-context-push-thread-default " >thread-default main loop</link> of the thread you are calling this method from. \n '
' * You can then call %s object_manager_client_new_finish() to get the result of the operation. \n '
' * \n '
' * See %s object_manager_client_new_sync() for the synchronous, blocking version of this constructor. \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . ns_lower ) ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' */ \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s object_manager_client_new ( \n '
' GDBusConnection *connection, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data) \n '
' { \n '
2011-04-16 20:07:23 +02:00
' g_async_initable_new_async ( %s TYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, " flags " , flags, " name " , name, " connection " , connection, " object-path " , object_path, " get-proxy-type-func " , %s object_manager_client_get_proxy_type, NULL); \n '
2011-04-08 22:57:31 +02:00
' } \n '
' \n '
% ( self . ns_lower , self . ns_upper , self . ns_lower ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' /** \n '
' * %s object_manager_client_new_finish: \n '
2011-04-18 20:23:19 +02:00
' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s object_manager_client_new(). \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
' * Finishes an operation started with %s object_manager_client_new(). \n '
2011-04-16 20:07:23 +02:00
' * \n '
2011-04-18 20:23:19 +02:00
' * Returns: (transfer full) (type %s ObjectManagerClient): The constructed object manager client or %% NULL if @error is set. \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . namespace ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' */ \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' GDBusObjectManager * \n '
' %s object_manager_client_new_finish ( \n '
' GAsyncResult *res, \n '
' GError **error) \n '
' { \n '
' GObject *ret; \n '
' GObject *source_object; \n '
' source_object = g_async_result_get_source_object (res); \n '
' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); \n '
' g_object_unref (source_object); \n '
' if (ret != NULL) \n '
' return G_DBUS_OBJECT_MANAGER (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( self . ns_lower ) )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s object_manager_client_new_sync: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. \n '
' * @name: (allow-none): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
2011-04-19 19:39:12 +02:00
' * Synchronously creates #GDBusObjectManagerClient using %s object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new_sync() for more details. \n '
2011-04-18 20:23:19 +02:00
' * \n '
' * The calling thread is blocked until a reply is received. \n '
' * \n '
' * See %s object_manager_client_new() for the asynchronous version of this constructor. \n '
' * \n '
' * Returns: (transfer full) (type %s ObjectManagerClient): The constructed object manager client or %% NULL if @error is set. \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . namespace ) ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' */ \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' GDBusObjectManager * \n '
' %s object_manager_client_new_sync ( \n '
' GDBusConnection *connection, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error) \n '
' { \n '
' GInitable *ret; \n '
2011-04-16 20:07:23 +02:00
' ret = g_initable_new ( %s TYPE_OBJECT_MANAGER_CLIENT, cancellable, error, " flags " , flags, " name " , name, " connection " , connection, " object-path " , object_path, " get-proxy-type-func " , %s object_manager_client_get_proxy_type, NULL); \n '
2011-04-08 22:57:31 +02:00
' if (ret != NULL) \n '
' return G_DBUS_OBJECT_MANAGER (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( self . ns_lower , self . ns_upper , self . ns_lower ) )
self . c . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s object_manager_client_new_for_bus: \n '
' * @bus_type: A #GBusType. \n '
' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. \n '
' * @name: A bus name (well-known or unique). \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @callback: A #GAsyncReadyCallback to call when the request is satisfied. \n '
' * @user_data: User data to pass to @callback. \n '
' * \n '
' * Like %s object_manager_client_new() but takes a #GBusType instead of a #GDBusConnection. \n '
' * \n '
' * When the operation is finished, @callback will be invoked in the <link linkend= " g-main-context-push-thread-default " >thread-default main loop</link> of the thread you are calling this method from. \n '
' * You can then call %s object_manager_client_new_for_bus_finish() to get the result of the operation. \n '
' * \n '
' * See %s object_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor. \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . ns_lower ) ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' */ \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' void \n '
' %s object_manager_client_new_for_bus ( \n '
' GBusType bus_type, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data) \n '
' { \n '
2011-04-16 20:07:23 +02:00
' g_async_initable_new_async ( %s TYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, " flags " , flags, " name " , name, " bus-type " , bus_type, " object-path " , object_path, " get-proxy-type-func " , %s object_manager_client_get_proxy_type, NULL); \n '
2011-04-08 22:57:31 +02:00
' } \n '
' \n '
% ( self . ns_lower , self . ns_upper , self . ns_lower ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' /** \n '
' * %s object_manager_client_new_for_bus_finish: \n '
2011-04-18 20:23:19 +02:00
' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s object_manager_client_new_for_bus(). \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
' * Finishes an operation started with %s object_manager_client_new_for_bus(). \n '
2011-04-16 20:07:23 +02:00
' * \n '
2011-04-18 20:23:19 +02:00
' * Returns: (transfer full) (type %s ObjectManagerClient): The constructed object manager client or %% NULL if @error is set. \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . namespace ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' */ \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' GDBusObjectManager * \n '
' %s object_manager_client_new_for_bus_finish ( \n '
' GAsyncResult *res, \n '
' GError **error) \n '
' { \n '
' GObject *ret; \n '
' GObject *source_object; \n '
' source_object = g_async_result_get_source_object (res); \n '
' ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error); \n '
' g_object_unref (source_object); \n '
' if (ret != NULL) \n '
' return G_DBUS_OBJECT_MANAGER (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( self . ns_lower ) )
2011-04-18 20:23:19 +02:00
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * %s object_manager_client_new_for_bus_sync: \n '
' * @bus_type: A #GBusType. \n '
' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. \n '
' * @name: A bus name (well-known or unique). \n '
' * @object_path: An object path. \n '
' * @cancellable: (allow-none): A #GCancellable or %% NULL. \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
' * Like %s object_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection. \n '
' * \n '
' * The calling thread is blocked until a reply is received. \n '
' * \n '
' * See %s object_manager_client_new_for_bus() for the asynchronous version of this constructor. \n '
' * \n '
' * Returns: (transfer full) (type %s ObjectManagerClient): The constructed object manager client or %% NULL if @error is set. \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . namespace ) ) )
2011-04-16 20:07:23 +02:00
self . c . write ( ' */ \n ' )
2011-04-08 22:57:31 +02:00
self . c . write ( ' GDBusObjectManager * \n '
' %s object_manager_client_new_for_bus_sync ( \n '
' GBusType bus_type, \n '
' GDBusObjectManagerClientFlags flags, \n '
' const gchar *name, \n '
' const gchar *object_path, \n '
' GCancellable *cancellable, \n '
' GError **error) \n '
' { \n '
' GInitable *ret; \n '
2011-04-16 20:07:23 +02:00
' ret = g_initable_new ( %s TYPE_OBJECT_MANAGER_CLIENT, cancellable, error, " flags " , flags, " name " , name, " bus-type " , bus_type, " object-path " , object_path, " get-proxy-type-func " , %s object_manager_client_get_proxy_type, NULL); \n '
2011-04-08 22:57:31 +02:00
' if (ret != NULL) \n '
' return G_DBUS_OBJECT_MANAGER (ret); \n '
' else \n '
' return NULL; \n '
' } \n '
' \n '
% ( self . ns_lower , self . ns_upper , self . ns_lower ) )
self . c . write ( ' \n ' )
# ---------------------------------------------------------------------------------------------------
2011-04-18 20:23:19 +02:00
def write_gtkdoc_deprecated_and_since_and_close ( self , obj , f , indent ) :
if len ( obj . since ) > 0 :
f . write ( ' %*s * \n '
' %*s * Since: %s \n '
% ( indent , ' ' , indent , ' ' , obj . since ) )
if obj . deprecated :
if isinstance ( obj , dbustypes . Interface ) :
thing = ' The D-Bus interface '
elif isinstance ( obj , dbustypes . Method ) :
thing = ' The D-Bus method '
elif isinstance ( obj , dbustypes . Signal ) :
thing = ' The D-Bus signal '
elif isinstance ( obj , dbustypes . Property ) :
thing = ' The D-Bus property '
else :
raise RuntimeError ( ' Cannot handle object ' , obj )
f . write ( self . docbook_gen . expand (
' %*s * \n '
' %*s * Deprecated: %s has been deprecated. \n '
% ( indent , ' ' , indent , ' ' , thing ) ) )
f . write ( ' %*s */ \n ' % ( indent , ' ' ) )
# ---------------------------------------------------------------------------------------------------
2011-04-08 22:57:31 +02:00
2011-04-19 20:39:47 +02:00
def generate_interface_intro ( self , i ) :
self . c . write ( ' /* ------------------------------------------------------------------------ \n '
' * Code for interface %s \n '
' * ------------------------------------------------------------------------ \n '
' */ \n '
' \n ' % ( i . name ) )
self . c . write ( self . docbook_gen . expand (
' /** \n '
' * SECTION: %s \n '
' * @title: %s \n '
' * @short_description: Generated C code for the %s D-Bus interface \n '
' * \n '
' * This section contains code for working with the # %s D-Bus interface in C. \n '
' */ \n '
% ( i . camel_name , i . camel_name , i . name , i . name ) ) )
self . c . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
def generate ( self ) :
self . generate_intro ( )
self . declare_types ( )
for i in self . ifaces :
2011-04-19 20:39:47 +02:00
self . generate_interface_intro ( i )
2011-04-08 22:57:31 +02:00
self . generate_introspection_for_interface ( i )
self . generate_interface ( i )
self . generate_property_accessors ( i )
self . generate_signal_emitters ( i )
self . generate_method_calls ( i )
self . generate_method_completers ( i )
self . generate_proxy ( i )
2011-04-13 22:33:51 +02:00
self . generate_skeleton ( i )
2011-04-12 17:50:34 +02:00
if self . generate_objmanager :
self . generate_object_manager_client ( )
2011-04-08 22:57:31 +02:00
self . generate_outro ( )