2011-04-08 22:57:31 +02:00
# -*- Mode: Python -*-
2018-01-15 16:58:10 +01:00
# coding=utf-8
2011-04-08 22:57:31 +02:00
2011-04-15 14:33:30 +02:00
# GDBus - GLib D-Bus Library
#
2018-11-23 10:13:17 +01:00
# Copyright (C) 2008-2018 Red Hat, Inc.
2018-01-04 09:56:59 +01:00
# Copyright (C) 2018 Iñigo Martínez <inigomartinez@gmail.com>
2011-04-15 14:33:30 +02:00
#
# 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
2017-01-05 14:44:41 +01:00
# version 2.1 of the License, or (at your option) any later version.
2011-04-15 14:33:30 +02:00
#
# 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
2014-01-23 12:58:29 +01:00
# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
2011-04-15 14:33:30 +02:00
#
# Author: David Zeuthen <davidz@redhat.com>
2011-04-08 22:57:31 +02:00
import sys
2011-08-23 17:37:35 +02:00
from . import config
2011-08-23 07:35:01 +02:00
from . import utils
from . import dbustypes
2018-01-12 08:55:36 +01:00
from . utils import print_error
2011-04-08 22:57:31 +02:00
2018-01-03 10:26:12 +01:00
LICENSE_STR = ''' /*
2019-12-02 15:07:25 +01:00
* This file is generated by gdbus - codegen , do not modify it .
2018-01-03 10:26:12 +01:00
*
* The license of this code is the same as for the D - Bus interface description
2019-12-02 15:07:25 +01:00
* it was derived from . Note that it links to GLib , so must comply with the
* LGPL linking clauses .
2018-01-03 10:26:12 +01:00
* / \n '''
2018-01-04 09:56:59 +01:00
def generate_namespace ( namespace ) :
ns = namespace
if len ( namespace ) > 0 :
if utils . is_ugly_case ( namespace ) :
ns = namespace . replace ( ' _ ' , ' ' )
ns_upper = namespace . upper ( ) + ' _ '
ns_lower = namespace . lower ( ) + ' _ '
else :
ns_upper = utils . camel_case_to_uscore ( namespace ) . upper ( ) + ' _ '
ns_lower = utils . camel_case_to_uscore ( namespace ) . lower ( ) + ' _ '
else :
ns_upper = ' '
ns_lower = ' '
2011-04-08 22:57:31 +02:00
2018-01-04 09:56:59 +01:00
return ( ns , ns_upper , ns_lower )
2019-10-29 16:01:39 +01:00
def generate_header_guard ( header_name ) :
# There might be more characters that are safe to use than these, but lets
# stay conservative.
safe_valid_chars = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
return ' ' . join ( map ( lambda c : c if c in safe_valid_chars else ' _ ' ,
header_name . upper ( ) ) )
2018-01-04 09:56:59 +01:00
class HeaderCodeGenerator :
def __init__ ( self , ifaces , namespace , generate_objmanager ,
2018-04-23 16:54:08 +02:00
generate_autocleanup , header_name , input_files_basenames ,
2020-04-17 12:01:54 +02:00
use_pragma , glib_min_required ,
symbol_decorator , symbol_decorator_header , outfile ) :
2018-01-04 09:56:59 +01:00
self . ifaces = ifaces
self . namespace , self . ns_upper , self . ns_lower = generate_namespace ( namespace )
2011-04-12 17:50:34 +02:00
self . generate_objmanager = generate_objmanager
2016-05-04 00:11:09 +02:00
self . generate_autocleanup = generate_autocleanup
2019-10-29 16:01:39 +01:00
self . header_guard = generate_header_guard ( header_name )
2018-04-23 16:54:08 +02:00
self . input_files_basenames = input_files_basenames
2018-01-03 17:01:30 +01:00
self . use_pragma = use_pragma
2020-01-27 11:11:46 +01:00
self . glib_min_required = glib_min_required
2020-04-17 12:01:54 +02:00
self . symbol_decorator = symbol_decorator
self . symbol_decorator_header = symbol_decorator_header
2018-01-04 09:56:59 +01:00
self . outfile = outfile
2011-04-08 22:57:31 +02:00
# ----------------------------------------------------------------------------------------------------
2018-01-03 17:10:54 +01:00
def generate_header_preamble ( self ) :
2018-04-23 16:54:08 +02:00
basenames = ' , ' . join ( self . input_files_basenames )
self . outfile . write ( LICENSE_STR . format ( config . VERSION , basenames ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2018-01-03 17:01:30 +01:00
if self . use_pragma :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #pragma once \n ' )
2018-01-03 17:01:30 +01:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #ifndef __ {!s} __ \n ' . format ( self . header_guard ) )
self . outfile . write ( ' #define __ {!s} __ \n ' . format ( self . header_guard ) )
2018-01-03 17:01:30 +01:00
2020-04-17 12:01:54 +02:00
if self . symbol_decorator_header is not None :
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #include " %s " \n ' % self . symbol_decorator_header )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #include <gio/gio.h> \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' G_BEGIN_DECLS \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# ----------------------------------------------------------------------------------------------------
def declare_types ( self ) :
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* ------------------------------------------------------------------------ */ \n ' )
self . outfile . write ( ' /* Declarations for %s */ \n ' % i . name )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# First the GInterface
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #define %s TYPE_ %s ( %s _get_type ()) \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . 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 . outfile . 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 . outfile . write ( ' #define %s %s _GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %s TYPE_ %s , %s Iface)) \n ' % ( i . ns_upper , i . name_upper , i . ns_upper , i . name_upper , i . camel_name ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ; \n ' % ( i . camel_name ) )
self . outfile . write ( ' typedef struct _ %s %s ; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' typedef struct _ %s Iface %s Iface; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s Iface \n ' % ( i . camel_name ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' GTypeInterface parent_iface; \n ' )
2011-04-12 22:17:28 +02:00
function_pointers = { }
2011-08-23 18:46:32 +02:00
# vfuncs for methods
2011-04-08 22:57:31 +02:00
if len ( i . methods ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
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 ' % ( )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2011-07-21 22:03:27 +02:00
value + = ' , \n GUnixFDList *fd_list '
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2011-09-21 13:41:10 +02:00
value + = ' , \n %s arg_ %s ' % ( a . ctype_in , a . name )
2011-04-12 22:17:28 +02:00
value + = ' ); \n \n '
function_pointers [ key ] = value
2011-08-23 18:46:32 +02:00
# vfuncs for signals
2011-04-08 22:57:31 +02:00
if len ( i . signals ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
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-09-21 13:41:10 +02:00
value + = ' , \n %s arg_ %s ' % ( a . ctype_in , a . name )
2011-04-12 22:17:28 +02:00
value + = ' ); \n \n '
function_pointers [ key ] = value
2011-08-23 18:46:32 +02:00
# vfuncs for properties
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-08-23 18:46:32 +02:00
for p in i . properties :
key = ( p . since , ' _prop_get_ %s ' % p . name_lower )
value = ' %s (*get_ %s ) ( %s *object); \n \n ' % ( p . arg . ctype_in , p . name_lower , i . camel_name )
function_pointers [ key ] = value
2011-04-12 22:17:28 +02:00
# 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
2012-06-14 08:20:17 +02:00
for key in sorted ( function_pointers . keys ( ) , key = utils . version_cmp_key ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ' % function_pointers [ key ] )
2011-04-12 22:17:28 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2016-05-04 00:11:09 +02:00
if self . generate_autocleanup == ' all ' :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #if GLIB_CHECK_VERSION(2, 44, 0) \n ' )
self . outfile . write ( ' G_DEFINE_AUTOPTR_CLEANUP_FUNC ( %s , g_object_unref) \n ' % ( i . camel_name ) )
self . outfile . write ( ' #endif \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GType %s _get_type (void) G_GNUC_CONST; \n ' % ( i . name_lower ) )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GDBusInterfaceInfo * %s _interface_info (void); \n ' % ( i . name_lower ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' guint %s _override_properties (GObjectClass *klass, guint property_id_begin); \n ' % ( i . name_lower ) )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# Then method call completion functions
if len ( i . methods ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* D-Bus method call completion functions: */ \n ' )
2011-04-08 22:57:31 +02:00
for m in i . methods :
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if m . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' void %s _complete_ %s ( \n '
' %s *object, \n '
' GDBusMethodInvocation *invocation ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList *fd_list ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . outfile . write ( ' ); \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# Then signal emission functions
if len ( i . signals ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* D-Bus signal emissions functions: */ \n ' )
2011-04-08 22:57:31 +02:00
for s in i . signals :
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if s . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' void %s _emit_ %s ( \n '
' %s *object ' % ( i . name_lower , s . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s arg_ %s ' % ( a . ctype_in , a . name ) )
self . outfile . write ( ' ); \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# Then method call declarations
if len ( i . methods ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* D-Bus method calls: */ \n ' )
2011-04-08 22:57:31 +02:00
for m in i . methods :
# async begin
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if m . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' void %s _call_ %s ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s arg_ %s ' % ( a . ctype_in , a . name ) )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' , \n GDBusCallFlags call_flags '
' , \n gint timeout_msec ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList *fd_list ' )
self . outfile . write ( ' , \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data); \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# async finish
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if m . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' gboolean %s _call_ %s _finish ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList **out_fd_list ' )
self . outfile . write ( ' , \n '
' GAsyncResult *res, \n '
' GError **error); \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# sync
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if m . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' gboolean %s _call_ %s _sync ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s arg_ %s ' % ( a . ctype_in , a . name ) )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' , \n GDBusCallFlags call_flags '
' , \n gint timeout_msec ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList *fd_list ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList **out_fd_list ' )
self . outfile . write ( ' , \n '
' GCancellable *cancellable, \n '
' GError **error); \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# Then the property accessor declarations
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* D-Bus property accessors: */ \n ' )
2011-04-08 22:57:31 +02:00
for p in i . properties :
# getter
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if p . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' %s %s _get_ %s ( %s *object); \n ' % ( p . arg . ctype_in , i . name_lower , p . name_lower , i . camel_name ) )
2011-08-23 18:46:32 +02:00
if p . arg . free_func != None :
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-08-23 18:46:32 +02:00
if p . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' %s %s _dup_ %s ( %s *object); \n ' % ( p . arg . ctype_in_dup , i . name_lower , p . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
# setter
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if p . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' void %s _set_ %s ( %s *object, %s value); \n ' % ( i . name_lower , p . name_lower , i . camel_name , p . arg . ctype_in , ) )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# Then the proxy
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* ---- */ \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s TYPE_ %s _PROXY ( %s _proxy_get_type ()) \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . 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 . outfile . 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 . outfile . 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 . outfile . 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 . outfile . 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 . outfile . write ( ' \n ' )
self . outfile . write ( ' typedef struct _ %s Proxy %s Proxy; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' typedef struct _ %s ProxyClass %s ProxyClass; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' typedef struct _ %s ProxyPrivate %s ProxyPrivate; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s Proxy \n ' % ( i . camel_name ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' /*< private >*/ \n ' )
self . outfile . write ( ' GDBusProxy parent_instance; \n ' )
self . outfile . write ( ' %s ProxyPrivate *priv; \n ' % ( i . camel_name ) )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ProxyClass \n ' % ( i . camel_name ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' GDBusProxyClass parent_class; \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GType %s _proxy_get_type (void) G_GNUC_CONST; \n ' % ( i . name_lower ) )
self . outfile . write ( ' \n ' )
2016-05-04 00:11:09 +02:00
if self . generate_autocleanup in ( ' objects ' , ' all ' ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #if GLIB_CHECK_VERSION(2, 44, 0) \n ' )
self . outfile . write ( ' G_DEFINE_AUTOPTR_CLEANUP_FUNC ( %s Proxy, g_object_unref) \n ' % ( i . camel_name ) )
self . outfile . write ( ' #endif \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . 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 ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' %s * %s _proxy_new_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( i . camel_name , i . name_lower ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . 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 . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . 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 ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' %s * %s _proxy_new_for_bus_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( i . camel_name , i . name_lower ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . 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 . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
2011-04-13 22:33:51 +02:00
# Then the skeleton
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* ---- */ \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s TYPE_ %s _SKELETON ( %s _skeleton_get_type ()) \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . 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 . outfile . 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 . outfile . 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 . outfile . 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 . outfile . 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 ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' typedef struct _ %s Skeleton %s Skeleton; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' typedef struct _ %s SkeletonClass %s SkeletonClass; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' typedef struct _ %s SkeletonPrivate %s SkeletonPrivate; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s Skeleton \n ' % ( i . camel_name ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' /*< private >*/ \n ' )
self . outfile . write ( ' GDBusInterfaceSkeleton parent_instance; \n ' )
self . outfile . write ( ' %s SkeletonPrivate *priv; \n ' % ( i . camel_name ) )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s SkeletonClass \n ' % ( i . camel_name ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' GDBusInterfaceSkeletonClass parent_class; \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GType %s _skeleton_get_type (void) G_GNUC_CONST; \n ' % ( i . name_lower ) )
self . outfile . write ( ' \n ' )
2016-05-04 00:11:09 +02:00
if self . generate_autocleanup in ( ' objects ' , ' all ' ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #if GLIB_CHECK_VERSION(2, 44, 0) \n ' )
self . outfile . write ( ' G_DEFINE_AUTOPTR_CLEANUP_FUNC ( %s Skeleton, g_object_unref) \n ' % ( i . camel_name ) )
self . outfile . write ( ' #endif \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-15 18:56:07 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' %s * %s _skeleton_new (void); \n ' % ( i . camel_name , i . name_lower ) )
2011-04-08 22:57:31 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
2011-04-25 15:29:18 +02:00
# Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
2011-04-12 17:50:34 +02:00
if self . generate_objmanager :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* ---- */ \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s TYPE_OBJECT ( %s object_get_type ()) \n ' % ( self . ns_upper , self . ns_lower ) )
self . outfile . write ( ' #define %s OBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %s TYPE_OBJECT, %s Object)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' #define %s IS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %s TYPE_OBJECT)) \n ' % ( self . ns_upper , self . ns_upper ) )
self . outfile . write ( ' #define %s OBJECT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %s TYPE_OBJECT, %s Object)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s Object; \n ' % ( self . namespace ) )
self . outfile . write ( ' typedef struct _ %s Object %s Object; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' typedef struct _ %s ObjectIface %s ObjectIface; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ObjectIface \n ' % ( self . namespace ) )
self . outfile . write ( ' { \n '
' GTypeInterface parent_iface; \n '
' }; \n '
' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GType %s object_get_type (void) G_GNUC_CONST; \n '
' \n '
% ( self . ns_lower ) )
2018-10-26 12:16:13 +02:00
if self . generate_autocleanup == ' all ' :
self . outfile . write ( ' #if GLIB_CHECK_VERSION(2, 44, 0) \n ' )
self . outfile . write ( ' G_DEFINE_AUTOPTR_CLEANUP_FUNC ( %s Object, g_object_unref) \n ' % ( self . namespace ) )
self . outfile . write ( ' #endif \n ' )
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
for i in self . ifaces :
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-25 15:29:18 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' %s * %s object_get_ %s ( %s Object *object); \n '
% ( i . camel_name , self . ns_lower , i . name_upper . lower ( ) , self . namespace ) )
2011-04-25 15:29:18 +02:00
for i in self . ifaces :
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-25 15:29:18 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' %s * %s object_peek_ %s ( %s Object *object); \n '
% ( i . camel_name , self . ns_lower , i . name_upper . lower ( ) , self . namespace ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s TYPE_OBJECT_PROXY ( %s object_proxy_get_type ()) \n ' % ( self . ns_upper , self . ns_lower ) )
self . outfile . write ( ' #define %s OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %s TYPE_OBJECT_PROXY, %s ObjectProxy)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' #define %s OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %s TYPE_OBJECT_PROXY, %s ObjectProxyClass)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' #define %s OBJECT_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %s TYPE_OBJECT_PROXY, %s ObjectProxyClass)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' #define %s IS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %s TYPE_OBJECT_PROXY)) \n ' % ( self . ns_upper , self . ns_upper ) )
self . outfile . write ( ' #define %s IS_OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %s TYPE_OBJECT_PROXY)) \n ' % ( self . ns_upper , self . ns_upper ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' typedef struct _ %s ObjectProxy %s ObjectProxy; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' typedef struct _ %s ObjectProxyClass %s ObjectProxyClass; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' typedef struct _ %s ObjectProxyPrivate %s ObjectProxyPrivate; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ObjectProxy \n ' % ( self . namespace ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' /*< private >*/ \n ' )
self . outfile . write ( ' GDBusObjectProxy parent_instance; \n ' )
self . outfile . write ( ' %s ObjectProxyPrivate *priv; \n ' % ( self . namespace ) )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ObjectProxyClass \n ' % ( self . namespace ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' GDBusObjectProxyClass parent_class; \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GType %s object_proxy_get_type (void) G_GNUC_CONST; \n ' % ( self . ns_lower ) )
self . outfile . write ( ' \n ' )
2016-05-04 00:11:09 +02:00
if self . generate_autocleanup in ( ' objects ' , ' all ' ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #if GLIB_CHECK_VERSION(2, 44, 0) \n ' )
self . outfile . write ( ' G_DEFINE_AUTOPTR_CLEANUP_FUNC ( %s ObjectProxy, g_object_unref) \n ' % ( self . namespace ) )
self . outfile . write ( ' #endif \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ObjectProxy * %s object_proxy_new (GDBusConnection *connection, const gchar *object_path); \n ' % ( self . namespace , self . ns_lower ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s TYPE_OBJECT_SKELETON ( %s object_skeleton_get_type ()) \n ' % ( self . ns_upper , self . ns_lower ) )
self . outfile . write ( ' #define %s OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %s TYPE_OBJECT_SKELETON, %s ObjectSkeleton)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' #define %s OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %s TYPE_OBJECT_SKELETON, %s ObjectSkeletonClass)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' #define %s OBJECT_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %s TYPE_OBJECT_SKELETON, %s ObjectSkeletonClass)) \n ' % ( self . ns_upper , self . ns_upper , self . namespace ) )
self . outfile . write ( ' #define %s IS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %s TYPE_OBJECT_SKELETON)) \n ' % ( self . ns_upper , self . ns_upper ) )
self . outfile . write ( ' #define %s IS_OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %s TYPE_OBJECT_SKELETON)) \n ' % ( self . ns_upper , self . ns_upper ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' typedef struct _ %s ObjectSkeleton %s ObjectSkeleton; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' typedef struct _ %s ObjectSkeletonClass %s ObjectSkeletonClass; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' typedef struct _ %s ObjectSkeletonPrivate %s ObjectSkeletonPrivate; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ObjectSkeleton \n ' % ( self . namespace ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' /*< private >*/ \n ' )
self . outfile . write ( ' GDBusObjectSkeleton parent_instance; \n ' )
self . outfile . write ( ' %s ObjectSkeletonPrivate *priv; \n ' % ( self . namespace ) )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ObjectSkeletonClass \n ' % ( self . namespace ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' GDBusObjectSkeletonClass parent_class; \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GType %s object_skeleton_get_type (void) G_GNUC_CONST; \n ' % ( self . ns_lower ) )
self . outfile . write ( ' \n ' )
2016-05-04 00:11:09 +02:00
if self . generate_autocleanup in ( ' objects ' , ' all ' ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #if GLIB_CHECK_VERSION(2, 44, 0) \n ' )
self . outfile . write ( ' G_DEFINE_AUTOPTR_CLEANUP_FUNC ( %s ObjectSkeleton, g_object_unref) \n ' % ( self . namespace ) )
self . outfile . write ( ' #endif \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ObjectSkeleton * %s object_skeleton_new (const gchar *object_path); \n '
% ( self . namespace , self . ns_lower ) )
2011-04-25 15:29:18 +02:00
for i in self . ifaces :
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2011-04-25 15:29:18 +02:00
if i . deprecated :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_DEPRECATED ' )
self . outfile . write ( ' void %s object_skeleton_set_ %s ( %s ObjectSkeleton *object, %s *interface_); \n '
% ( self . ns_lower , i . name_upper . lower ( ) , self . namespace , i . camel_name ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' /* ---- */ \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s TYPE_OBJECT_MANAGER_CLIENT ( %s object_manager_client_get_type ()) \n ' % ( self . ns_upper , self . ns_lower ) )
self . outfile . 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 . outfile . 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 . outfile . 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 . outfile . 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 . outfile . 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 . outfile . write ( ' \n ' )
self . outfile . write ( ' typedef struct _ %s ObjectManagerClient %s ObjectManagerClient; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' typedef struct _ %s ObjectManagerClientClass %s ObjectManagerClientClass; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' typedef struct _ %s ObjectManagerClientPrivate %s ObjectManagerClientPrivate; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ObjectManagerClient \n ' % ( self . namespace ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' /*< private >*/ \n ' )
self . outfile . write ( ' GDBusObjectManagerClient parent_instance; \n ' )
self . outfile . write ( ' %s ObjectManagerClientPrivate *priv; \n ' % ( self . namespace ) )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ObjectManagerClientClass \n ' % ( self . namespace ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' GDBusObjectManagerClientClass parent_class; \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2016-05-04 00:11:09 +02:00
if self . generate_autocleanup in ( ' objects ' , ' all ' ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' #if GLIB_CHECK_VERSION(2, 44, 0) \n ' )
self . outfile . write ( ' G_DEFINE_AUTOPTR_CLEANUP_FUNC ( %s ObjectManagerClient, g_object_unref) \n ' % ( self . namespace ) )
self . outfile . write ( ' #endif \n ' )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GType %s object_manager_client_get_type (void) G_GNUC_CONST; \n ' % ( self . ns_lower ) )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . 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 ) )
self . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . 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 ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GDBusObjectManager * %s object_manager_client_new_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( self . ns_lower ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . 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 . outfile . write ( ' \n ' )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . 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 ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' GDBusObjectManager * %s object_manager_client_new_for_bus_finish ( \n '
' GAsyncResult *res, \n '
' GError **error); \n '
% ( self . ns_lower ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator is not None :
self . outfile . write ( ' %s \n ' % self . symbol_decorator )
2018-01-04 09:56:59 +01:00
self . outfile . 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 . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# ----------------------------------------------------------------------------------------------------
2018-01-03 17:10:54 +01:00
def generate_header_postamble ( self ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' G_END_DECLS \n ' )
2018-01-03 17:01:30 +01:00
if not self . use_pragma :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #endif /* __ {!s} __ */ \n ' . format ( self . header_guard ) )
2011-04-08 22:57:31 +02:00
# ----------------------------------------------------------------------------------------------------
2018-01-04 09:56:59 +01:00
def generate ( self ) :
self . generate_header_preamble ( )
self . declare_types ( )
self . generate_header_postamble ( )
2018-01-03 17:10:54 +01:00
2018-01-04 09:56:59 +01:00
# ----------------------------------------------------------------------------------------------------
2018-01-03 17:10:54 +01:00
2018-04-17 15:10:07 +02:00
class InterfaceInfoHeaderCodeGenerator :
2020-04-17 12:01:54 +02:00
def __init__ ( self , ifaces , namespace , header_name , input_files_basenames , use_pragma ,
glib_min_required , symbol_decorator , symbol_decorator_header , outfile ) :
2018-04-17 15:10:07 +02:00
self . ifaces = ifaces
self . namespace , self . ns_upper , self . ns_lower = generate_namespace ( namespace )
2019-10-29 16:01:39 +01:00
self . header_guard = generate_header_guard ( header_name )
gdbus-codegen: make --interface-info-{header,body} not crash
Since 1217b1bc4f242c14d6eabbee0c688c320eab2e4d, LICENSE_STR has taken two
parameters, not one. Without this change, running either mode fails
with a traceback like:
Traceback (most recent call last):
File "../gdbus-codegen", line 55, in <module>
sys.exit(codegen_main.codegen_main())
File ".../codegen_main.py", line 294, in codegen_main
gen.generate()
File ".../codegen.py", line 896, in generate
self.generate_body_preamble()
File ".../codegen.py", line 682, in generate_body_preamble
self.outfile.write(LICENSE_STR.format(config.VERSION))
IndexError: tuple index out of range
8916874ee6f3ff0f887dbe1eda55c23c2c0097ee, which introduced these flags,
was actually merged after that commit, but I assume it was written
beforehand.
2018-12-05 22:32:05 +01:00
self . input_files_basenames = input_files_basenames
2018-04-17 15:10:07 +02:00
self . use_pragma = use_pragma
2020-01-27 11:11:46 +01:00
self . glib_min_required = glib_min_required
2020-04-17 12:01:54 +02:00
self . symbol_decorator = symbol_decorator
if self . symbol_decorator is None :
self . symbol_decorator = ' '
self . symbol_decorator_header = symbol_decorator_header
2018-04-17 15:10:07 +02:00
self . outfile = outfile
# ----------------------------------------------------------------------------------------------------
def generate_header_preamble ( self ) :
gdbus-codegen: make --interface-info-{header,body} not crash
Since 1217b1bc4f242c14d6eabbee0c688c320eab2e4d, LICENSE_STR has taken two
parameters, not one. Without this change, running either mode fails
with a traceback like:
Traceback (most recent call last):
File "../gdbus-codegen", line 55, in <module>
sys.exit(codegen_main.codegen_main())
File ".../codegen_main.py", line 294, in codegen_main
gen.generate()
File ".../codegen.py", line 896, in generate
self.generate_body_preamble()
File ".../codegen.py", line 682, in generate_body_preamble
self.outfile.write(LICENSE_STR.format(config.VERSION))
IndexError: tuple index out of range
8916874ee6f3ff0f887dbe1eda55c23c2c0097ee, which introduced these flags,
was actually merged after that commit, but I assume it was written
beforehand.
2018-12-05 22:32:05 +01:00
basenames = ' , ' . join ( self . input_files_basenames )
self . outfile . write ( LICENSE_STR . format ( config . VERSION , basenames ) )
2018-04-17 15:10:07 +02:00
self . outfile . write ( ' \n ' )
if self . use_pragma :
self . outfile . write ( ' #pragma once \n ' )
else :
self . outfile . write ( ' #ifndef __ {!s} __ \n ' . format ( self . header_guard ) )
self . outfile . write ( ' #define __ {!s} __ \n ' . format ( self . header_guard ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decorator_header is not None :
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #include " %s " \n ' % self . symbol_decorator_header )
2018-04-17 15:10:07 +02:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #include <gio/gio.h> \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' G_BEGIN_DECLS \n ' )
self . outfile . write ( ' \n ' )
# ----------------------------------------------------------------------------------------------------
def declare_infos ( self ) :
for i in self . ifaces :
2020-04-17 12:01:54 +02:00
self . outfile . write ( ' extern %s const GDBusInterfaceInfo %s _interface; \n ' %
( self . symbol_decorator , i . name_lower ) )
2018-04-17 15:10:07 +02:00
# ----------------------------------------------------------------------------------------------------
def generate_header_postamble ( self ) :
self . outfile . write ( ' \n ' )
self . outfile . write ( ' G_END_DECLS \n ' )
if not self . use_pragma :
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #endif /* __ {!s} __ */ \n ' . format ( self . header_guard ) )
# ----------------------------------------------------------------------------------------------------
def generate ( self ) :
self . generate_header_preamble ( )
self . declare_infos ( )
self . generate_header_postamble ( )
# ----------------------------------------------------------------------------------------------------
class InterfaceInfoBodyCodeGenerator :
2020-04-17 12:01:54 +02:00
def __init__ ( self , ifaces , namespace , header_name , input_files_basenames ,
glib_min_required , symbol_decoration_define , outfile ) :
2018-04-17 15:10:07 +02:00
self . ifaces = ifaces
self . namespace , self . ns_upper , self . ns_lower = generate_namespace ( namespace )
self . header_name = header_name
gdbus-codegen: make --interface-info-{header,body} not crash
Since 1217b1bc4f242c14d6eabbee0c688c320eab2e4d, LICENSE_STR has taken two
parameters, not one. Without this change, running either mode fails
with a traceback like:
Traceback (most recent call last):
File "../gdbus-codegen", line 55, in <module>
sys.exit(codegen_main.codegen_main())
File ".../codegen_main.py", line 294, in codegen_main
gen.generate()
File ".../codegen.py", line 896, in generate
self.generate_body_preamble()
File ".../codegen.py", line 682, in generate_body_preamble
self.outfile.write(LICENSE_STR.format(config.VERSION))
IndexError: tuple index out of range
8916874ee6f3ff0f887dbe1eda55c23c2c0097ee, which introduced these flags,
was actually merged after that commit, but I assume it was written
beforehand.
2018-12-05 22:32:05 +01:00
self . input_files_basenames = input_files_basenames
2020-01-27 11:11:46 +01:00
self . glib_min_required = glib_min_required
2020-04-17 12:01:54 +02:00
self . symbol_decoration_define = symbol_decoration_define
2018-04-17 15:10:07 +02:00
self . outfile = outfile
# ----------------------------------------------------------------------------------------------------
def generate_body_preamble ( self ) :
gdbus-codegen: make --interface-info-{header,body} not crash
Since 1217b1bc4f242c14d6eabbee0c688c320eab2e4d, LICENSE_STR has taken two
parameters, not one. Without this change, running either mode fails
with a traceback like:
Traceback (most recent call last):
File "../gdbus-codegen", line 55, in <module>
sys.exit(codegen_main.codegen_main())
File ".../codegen_main.py", line 294, in codegen_main
gen.generate()
File ".../codegen.py", line 896, in generate
self.generate_body_preamble()
File ".../codegen.py", line 682, in generate_body_preamble
self.outfile.write(LICENSE_STR.format(config.VERSION))
IndexError: tuple index out of range
8916874ee6f3ff0f887dbe1eda55c23c2c0097ee, which introduced these flags,
was actually merged after that commit, but I assume it was written
beforehand.
2018-12-05 22:32:05 +01:00
basenames = ' , ' . join ( self . input_files_basenames )
self . outfile . write ( LICENSE_STR . format ( config . VERSION , basenames ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decoration_define is not None :
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s \n ' % self . symbol_decoration_define )
2018-04-17 15:10:07 +02:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #ifdef HAVE_CONFIG_H \n '
' # include " config.h " \n '
' #endif \n '
' \n '
' #include " %s " \n '
' \n '
' #include <string.h> \n '
% ( self . header_name ) )
self . outfile . write ( ' \n ' )
# ----------------------------------------------------------------------------------------------------
def generate_array ( self , array_name_lower , element_type , elements ) :
self . outfile . write ( ' const %s * const %s [] = \n ' % ( element_type , array_name_lower ) )
self . outfile . write ( ' { \n ' )
2018-12-06 18:28:09 +01:00
for ( _ , name ) in elements :
2018-04-17 15:10:07 +02:00
self . outfile . write ( ' & %s , \n ' % name )
self . outfile . write ( ' NULL, \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
def define_annotations ( self , array_name_lower , annotations ) :
if len ( annotations ) == 0 :
return
annotation_pointers = [ ]
for a in annotations :
# Skip internal annotations.
if a . key . startswith ( ' org.gtk.GDBus ' ) :
continue
self . define_annotations ( ' %s __ %s _annotations ' % ( array_name_lower , a . key_lower ) , a . annotations )
self . outfile . write ( ' const GDBusAnnotationInfo %s __ %s _annotation = \n ' % ( array_name_lower , a . key_lower ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' -1, /* ref count */ \n ' )
self . outfile . write ( ' (gchar *) " %s " , \n ' % a . key )
self . outfile . write ( ' (gchar *) " %s " , \n ' % a . value )
if len ( a . annotations ) > 0 :
self . outfile . write ( ' (GDBusAnnotationInfo **) %s __ %s _annotations, \n ' % ( array_name_lower , a . key_lower ) )
else :
self . outfile . write ( ' NULL, /* no annotations */ \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
key = ( a . since , ' %s __ %s _annotation ' % ( array_name_lower , a . key_lower ) )
annotation_pointers . append ( key )
self . generate_array ( array_name_lower , ' GDBusAnnotationInfo ' ,
annotation_pointers )
def define_args ( self , array_name_lower , args ) :
if len ( args ) == 0 :
return
arg_pointers = [ ]
for a in args :
self . define_annotations ( ' %s __ %s _arg_annotations ' % ( array_name_lower , a . name ) , a . annotations )
self . outfile . write ( ' const GDBusArgInfo %s __ %s _arg = \n ' % ( array_name_lower , a . name ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' -1, /* ref count */ \n ' )
self . outfile . write ( ' (gchar *) " %s " , \n ' % a . name )
self . outfile . write ( ' (gchar *) " %s " , \n ' % a . signature )
if len ( a . annotations ) > 0 :
self . outfile . write ( ' (GDBusAnnotationInfo **) %s __ %s _arg_annotations, \n ' % ( array_name_lower , a . name ) )
else :
self . outfile . write ( ' NULL, /* no annotations */ \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
key = ( a . since , ' %s __ %s _arg ' % ( array_name_lower , a . name ) )
arg_pointers . append ( key )
self . generate_array ( array_name_lower , ' GDBusArgInfo ' , arg_pointers )
def define_infos ( self ) :
for i in self . ifaces :
self . outfile . write ( ' /* ------------------------------------------------------------------------ */ \n ' )
self . outfile . write ( ' /* Definitions for %s */ \n ' % i . name )
self . outfile . write ( ' \n ' )
# GDBusMethodInfos.
if len ( i . methods ) > 0 :
method_pointers = [ ]
for m in i . methods :
self . define_args ( ' %s _interface__ %s _method_in_args ' % ( i . name_lower , m . name_lower ) , m . in_args )
self . define_args ( ' %s _interface__ %s _method_out_args ' % ( i . name_lower , m . name_lower ) , m . out_args )
self . define_annotations ( ' %s _interface__ %s _method_annotations ' % ( i . name_lower , m . name_lower ) , m . annotations )
self . outfile . write ( ' const GDBusMethodInfo %s _interface__ %s _method = \n ' % ( i . name_lower , m . name_lower ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' -1, /* ref count */ \n ' )
self . outfile . write ( ' (gchar *) " %s " , \n ' % m . name )
if len ( m . in_args ) > 0 :
self . outfile . write ( ' (GDBusArgInfo **) %s _interface__ %s _method_in_args, \n ' % ( i . name_lower , m . name_lower ) )
else :
self . outfile . write ( ' NULL, /* no in args */ \n ' )
if len ( m . out_args ) > 0 :
self . outfile . write ( ' (GDBusArgInfo **) %s _interface__ %s _method_out_args, \n ' % ( i . name_lower , m . name_lower ) )
else :
self . outfile . write ( ' NULL, /* no out args */ \n ' )
if len ( m . annotations ) > 0 :
self . outfile . write ( ' (GDBusAnnotationInfo **) %s _interface__ %s _method_annotations, \n ' % ( i . name_lower , m . name_lower ) )
else :
self . outfile . write ( ' NULL, /* no annotations */ \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
key = ( m . since , ' %s _interface__ %s _method ' % ( i . name_lower , m . name_lower ) )
method_pointers . append ( key )
self . generate_array ( ' %s _interface_methods ' % i . name_lower ,
' GDBusMethodInfo ' , method_pointers )
# GDBusSignalInfos.
if len ( i . signals ) > 0 :
signal_pointers = [ ]
for s in i . signals :
self . define_args ( ' %s _interface__ %s _signal_args ' % ( i . name_lower , s . name_lower ) , s . args )
self . define_annotations ( ' %s _interface__ %s _signal_annotations ' % ( i . name_lower , s . name_lower ) , s . annotations )
self . outfile . write ( ' const GDBusSignalInfo %s _interface__ %s _signal = \n ' % ( i . name_lower , s . name_lower ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' -1, /* ref count */ \n ' )
self . outfile . write ( ' (gchar *) " %s " , \n ' % s . name )
if len ( s . args ) > 0 :
self . outfile . write ( ' (GDBusArgInfo **) %s _interface__ %s _signal_args, \n ' % ( i . name_lower , s . name_lower ) )
else :
self . outfile . write ( ' NULL, /* no args */ \n ' )
if len ( s . annotations ) > 0 :
self . outfile . write ( ' (GDBusAnnotationInfo **) %s _interface__ %s _signal_annotations, \n ' % ( i . name_lower , s . name_lower ) )
else :
self . outfile . write ( ' NULL, /* no annotations */ \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2019-03-13 14:13:24 +01:00
key = ( s . since , ' %s _interface__ %s _signal ' % ( i . name_lower , s . name_lower ) )
2018-04-17 15:10:07 +02:00
signal_pointers . append ( key )
self . generate_array ( ' %s _interface_signals ' % i . name_lower ,
' GDBusSignalInfo ' , signal_pointers )
# GDBusPropertyInfos.
if len ( i . properties ) > 0 :
property_pointers = [ ]
for p in i . properties :
if p . readable and p . writable :
flags = ' G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE '
elif p . readable :
flags = ' G_DBUS_PROPERTY_INFO_FLAGS_READABLE '
elif p . writable :
flags = ' G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE '
else :
flags = ' G_DBUS_PROPERTY_INFO_FLAGS_NONE '
self . define_annotations ( ' %s _interface__ %s _property_annotations ' % ( i . name_lower , p . name_lower ) , p . annotations )
self . outfile . write ( ' const GDBusPropertyInfo %s _interface__ %s _property = \n ' % ( i . name_lower , p . name_lower ) )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' -1, /* ref count */ \n ' )
self . outfile . write ( ' (gchar *) " %s " , \n ' % p . name )
self . outfile . write ( ' (gchar *) " %s " , \n ' % p . signature )
self . outfile . write ( ' %s , \n ' % flags )
if len ( p . annotations ) > 0 :
self . outfile . write ( ' (GDBusAnnotationInfo **) %s _interface__ %s _property_annotations, \n ' % ( i . name_lower , p . name_lower ) )
else :
self . outfile . write ( ' NULL, /* no annotations */ \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
2019-03-13 14:13:24 +01:00
key = ( p . since , ' %s _interface__ %s _property ' % ( i . name_lower , p . name_lower ) )
2018-04-17 15:10:07 +02:00
property_pointers . append ( key )
self . generate_array ( ' %s _interface_properties ' % i . name_lower ,
' GDBusPropertyInfo ' , property_pointers )
# Finally the GDBusInterfaceInfo.
self . define_annotations ( ' %s _interface_annotations ' % i . name_lower ,
i . annotations )
self . outfile . write ( ' const GDBusInterfaceInfo %s _interface = \n ' % i . name_lower )
self . outfile . write ( ' { \n ' )
self . outfile . write ( ' -1, /* ref count */ \n ' )
self . outfile . write ( ' (gchar *) " %s " , \n ' % i . name )
if len ( i . methods ) > 0 :
self . outfile . write ( ' (GDBusMethodInfo **) %s _interface_methods, \n ' % i . name_lower )
else :
self . outfile . write ( ' NULL, /* no methods */ \n ' )
if len ( i . signals ) > 0 :
self . outfile . write ( ' (GDBusSignalInfo **) %s _interface_signals, \n ' % i . name_lower )
else :
self . outfile . write ( ' NULL, /* no signals */ \n ' )
if len ( i . properties ) > 0 :
self . outfile . write ( ' (GDBusPropertyInfo **) %s _interface_properties, \n ' % i . name_lower )
else :
self . outfile . write ( ' NULL, /* no properties */ \n ' )
if len ( i . annotations ) > 0 :
self . outfile . write ( ' (GDBusAnnotationInfo **) %s _interface_annotations, \n ' % i . name_lower )
else :
self . outfile . write ( ' NULL, /* no annotations */ \n ' )
self . outfile . write ( ' }; \n ' )
self . outfile . write ( ' \n ' )
# ----------------------------------------------------------------------------------------------------
def generate ( self ) :
self . generate_body_preamble ( )
self . define_infos ( )
# ----------------------------------------------------------------------------------------------------
2018-01-04 09:56:59 +01:00
class CodeGenerator :
def __init__ ( self , ifaces , namespace , generate_objmanager , header_name ,
2020-04-17 12:01:54 +02:00
input_files_basenames , docbook_gen , glib_min_required ,
symbol_decoration_define , outfile ) :
2018-01-04 09:56:59 +01:00
self . ifaces = ifaces
self . namespace , self . ns_upper , self . ns_lower = generate_namespace ( namespace )
self . generate_objmanager = generate_objmanager
self . header_name = header_name
2018-04-23 16:54:08 +02:00
self . input_files_basenames = input_files_basenames
2018-01-04 09:56:59 +01:00
self . docbook_gen = docbook_gen
2020-01-27 11:11:46 +01:00
self . glib_min_required = glib_min_required
2020-04-17 12:01:54 +02:00
self . symbol_decoration_define = symbol_decoration_define
2018-01-04 09:56:59 +01:00
self . outfile = outfile
2018-01-03 17:10:54 +01:00
2018-01-04 09:56:59 +01:00
# ----------------------------------------------------------------------------------------------------
2018-01-03 17:10:54 +01:00
2018-01-04 09:56:59 +01:00
def generate_body_preamble ( self ) :
2018-04-23 16:54:08 +02:00
basenames = ' , ' . join ( self . input_files_basenames )
self . outfile . write ( LICENSE_STR . format ( config . VERSION , basenames ) )
2020-04-17 12:01:54 +02:00
if self . symbol_decoration_define is not None :
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #define %s \n ' % self . symbol_decoration_define )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' #ifdef HAVE_CONFIG_H \n '
' # include " config.h " \n '
' #endif \n '
' \n '
' #include " %s " \n '
' \n '
' #include <string.h> \n '
% ( self . header_name ) )
self . outfile . write ( ' #ifdef G_OS_UNIX \n '
' # include <gio/gunixfdlist.h> \n '
' #endif \n '
' \n ' )
self . outfile . write ( ' typedef struct \n '
' { \n '
' GDBusArgInfo parent_struct; \n '
' gboolean use_gvariant; \n '
' } _ExtendedGDBusArgInfo; \n '
' \n ' )
self . outfile . write ( ' typedef struct \n '
' { \n '
' GDBusMethodInfo parent_struct; \n '
' const gchar *signal_name; \n '
' gboolean pass_fdlist; \n '
' } _ExtendedGDBusMethodInfo; \n '
' \n ' )
self . outfile . write ( ' typedef struct \n '
' { \n '
' GDBusSignalInfo parent_struct; \n '
' const gchar *signal_name; \n '
' } _ExtendedGDBusSignalInfo; \n '
' \n ' )
self . outfile . write ( ' typedef struct \n '
' { \n '
' GDBusPropertyInfo parent_struct; \n '
' const gchar *hyphen_name; \n '
2018-12-13 12:06:02 +01:00
' guint use_gvariant : 1; \n '
' guint emits_changed_signal : 1; \n '
2018-01-04 09:56:59 +01:00
' } _ExtendedGDBusPropertyInfo; \n '
' \n ' )
self . outfile . write ( ' typedef struct \n '
' { \n '
' GDBusInterfaceInfo parent_struct; \n '
' const gchar *hyphen_name; \n '
' } _ExtendedGDBusInterfaceInfo; \n '
' \n ' )
self . outfile . write ( ' typedef struct \n '
' { \n '
' const _ExtendedGDBusPropertyInfo *info; \n '
' guint prop_id; \n '
' GValue orig_value; /* the value before the change */ \n '
' } ChangedProperty; \n '
' \n '
' static void \n '
' _changed_property_free (ChangedProperty *data) \n '
' { \n '
' g_value_unset (&data->orig_value); \n '
' g_free (data); \n '
' } \n '
' \n ' )
self . outfile . 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 . outfile . write ( ' static gboolean \n '
' _g_variant_equal0 (GVariant *a, GVariant *b) \n '
' { \n '
' gboolean ret = FALSE; \n '
' if (a == NULL && b == NULL) \n '
' { \n '
' ret = TRUE; \n '
' goto out; \n '
' } \n '
' if (a == NULL || b == NULL) \n '
' goto out; \n '
' ret = g_variant_equal (a, b); \n '
' out: \n '
' return ret; \n '
' } \n '
' \n ' )
2018-01-03 17:10:54 +01:00
# simplified - only supports the types we use
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' G_GNUC_UNUSED 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 '
' { \n '
' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */ \n '
' gdouble da = g_value_get_double (a); \n '
' gdouble db = g_value_get_double (b); \n '
' ret = memcmp (&da, &db, sizeof (gdouble)) == 0; \n '
' } \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 ' )
2018-01-03 17:10:54 +01:00
2011-04-08 22:57:31 +02:00
def generate_annotations ( self , prefix , annotations ) :
2018-07-12 23:40:50 +02:00
if annotations is None :
2011-04-08 22:57:31 +02:00
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
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static const GDBusAnnotationInfo %s _ %d = \n '
' { \n '
' -1, \n '
' (gchar *) " %s " , \n '
' (gchar *) " %s " , \n ' % ( prefix , n , a . key , a . value ) )
2011-04-08 22:57:31 +02:00
if len ( a . annotations ) == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusAnnotationInfo **) & %s _ %d _pointers \n ' % ( prefix , n ) )
self . outfile . write ( ' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
n + = 1
if n > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static const GDBusAnnotationInfo * const %s _pointers[] = \n '
' { \n ' % ( prefix ) )
2011-04-08 22:57:31 +02:00
m = 0 ;
for a in annotations :
if a . key . startswith ( ' org.gtk.GDBus ' ) :
continue
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' & %s _ %d , \n ' % ( prefix , m ) )
2011-04-08 22:57:31 +02:00
m + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n '
' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
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 )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static const _ExtendedGDBusArgInfo %s _ %s = \n '
' { \n '
' { \n '
' -1, \n '
' (gchar *) " %s " , \n '
' (gchar *) " %s " , \n ' % ( prefix , a . name , a . name , a . signature ) )
2011-04-08 22:57:31 +02:00
if num_anno == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusAnnotationInfo **) & %s _arg_ %s _annotation_info_pointers \n ' % ( prefix , a . name ) )
self . outfile . write ( ' }, \n ' )
2011-04-08 22:57:31 +02:00
if not utils . lookup_annotation ( a . annotations , ' org.gtk.GDBus.C.ForceGVariant ' ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' FALSE \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' TRUE \n ' )
self . outfile . write ( ' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
if len ( args ) > 0 :
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' static const GDBusArgInfo * const %s _pointers[] = \n '
2011-04-08 22:57:31 +02:00
' { \n ' % ( prefix ) )
for a in args :
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' & %s _ %s .parent_struct, \n ' % ( prefix , a . name ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n '
' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
def generate_introspection_for_interface ( self , i ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* ---- Introspection data for %s ---- */ \n '
' \n ' % ( i . name ) )
2011-04-08 22:57:31 +02:00
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 )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static const _ExtendedGDBusMethodInfo _ %s _method_info_ %s = \n '
' { \n '
' { \n '
' -1, \n '
' (gchar *) " %s " , \n ' % ( i . name_lower , m . name_lower , m . name ) )
2011-04-08 22:57:31 +02:00
if len ( m . in_args ) == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL, \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusArgInfo **) &_ %s _method_info_ %s _IN_ARG_pointers, \n ' % ( i . name_lower , m . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( m . out_args ) == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL, \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusArgInfo **) &_ %s _method_info_ %s _OUT_ARG_pointers, \n ' % ( i . name_lower , m . name_lower ) )
2011-04-08 22:57:31 +02:00
if num_anno == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusAnnotationInfo **) &_ %s _method_ %s _annotation_info_pointers \n ' % ( i . name_lower , m . name_lower ) )
self . outfile . write ( ' }, \n '
' " handle- %s " , \n '
' %s \n '
2019-09-02 07:54:37 +02:00
% ( m . name_hyphen , ' TRUE ' if m . unix_fd else ' FALSE ' ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' }; \n '
' \n ' )
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' static const GDBusMethodInfo * const _ %s _method_info_pointers[] = \n '
2018-01-04 09:56:59 +01:00
' { \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
for m in i . methods :
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' &_ %s _method_info_ %s .parent_struct, \n ' % ( i . name_lower , m . name_lower ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n '
' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# ---
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 )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static const _ExtendedGDBusSignalInfo _ %s _signal_info_ %s = \n '
' { \n '
' { \n '
' -1, \n '
' (gchar *) " %s " , \n ' % ( i . name_lower , s . name_lower , s . name ) )
2011-04-08 22:57:31 +02:00
if len ( s . args ) == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL, \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusArgInfo **) &_ %s _signal_info_ %s _ARG_pointers, \n ' % ( i . name_lower , s . name_lower ) )
2011-04-08 22:57:31 +02:00
if num_anno == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusAnnotationInfo **) &_ %s _signal_ %s _annotation_info_pointers \n ' % ( i . name_lower , s . name_lower ) )
self . outfile . write ( ' }, \n '
' " %s " \n '
% ( s . name_hyphen ) )
self . outfile . write ( ' }; \n '
' \n ' )
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' static const GDBusSignalInfo * const _ %s _signal_info_pointers[] = \n '
2018-01-04 09:56:59 +01:00
' { \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
for s in i . signals :
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' &_ %s _signal_info_ %s .parent_struct, \n ' % ( i . name_lower , s . name_lower ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n '
' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# ---
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 )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static const _ExtendedGDBusPropertyInfo _ %s _property_info_ %s = \n '
' { \n '
' { \n '
' -1, \n '
' (gchar *) " %s " , \n '
' (gchar *) " %s " , \n '
' %s , \n ' % ( i . name_lower , p . name_lower , p . name , p . arg . signature , access ) )
2011-04-08 22:57:31 +02:00
if num_anno == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusAnnotationInfo **) &_ %s _property_ %s _annotation_info_pointers \n ' % ( i . name_lower , p . name_lower ) )
self . outfile . write ( ' }, \n '
' " %s " , \n '
% ( p . name_hyphen ) )
2011-04-08 22:57:31 +02:00
if not utils . lookup_annotation ( p . annotations , ' org.gtk.GDBus.C.ForceGVariant ' ) :
2018-12-13 12:06:02 +01:00
self . outfile . write ( ' FALSE, \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-12-13 12:06:02 +01:00
self . outfile . write ( ' TRUE, \n ' )
if p . emits_changed_signal :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' TRUE \n ' )
2018-12-13 12:06:02 +01:00
else :
self . outfile . write ( ' FALSE \n ' )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' static const GDBusPropertyInfo * const _ %s _property_info_pointers[] = \n '
2018-01-04 09:56:59 +01:00
' { \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
for p in i . properties :
2018-09-07 00:19:05 +02:00
self . outfile . write ( ' &_ %s _property_info_ %s .parent_struct, \n ' % ( i . name_lower , p . name_lower ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n '
' }; \n '
' \n ' )
2011-04-08 22:57:31 +02:00
num_anno = self . generate_annotations ( ' _ %s _annotation_info ' % ( i . name_lower ) , i . annotations )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static const _ExtendedGDBusInterfaceInfo _ %s _interface_info = \n '
' { \n '
' { \n '
' -1, \n '
' (gchar *) " %s " , \n ' % ( i . name_lower , i . name ) )
2011-04-08 22:57:31 +02:00
if len ( i . methods ) == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL, \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusMethodInfo **) &_ %s _method_info_pointers, \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( i . signals ) == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL, \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusSignalInfo **) &_ %s _signal_info_pointers, \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL, \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusPropertyInfo **) &_ %s _property_info_pointers, \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
if num_anno == 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' NULL \n ' )
2011-04-08 22:57:31 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' (GDBusAnnotationInfo **) &_ %s _annotation_info_pointers \n ' % ( i . name_lower ) )
self . outfile . write ( ' }, \n '
' " %s " , \n '
' }; \n '
' \n '
% ( i . name_hyphen ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \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 '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , i . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' GDBusInterfaceInfo * \n '
' %s _interface_info (void) \n '
' { \n '
' return (GDBusInterfaceInfo *) &_ %s _interface_info.parent_struct; \n '
' } \n '
' \n ' % ( i . name_lower , i . name_lower ) )
self . outfile . write ( self . docbook_gen . expand (
2011-08-23 18:46:32 +02:00
' /** \n '
' * %s _override_properties: \n '
2017-11-29 18:50:27 +01:00
' * @klass: The class structure for a #GObject derived class. \n '
2011-08-23 18:46:32 +02:00
' * @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 ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' guint \n '
' %s _override_properties (GObjectClass *klass, guint property_id_begin) \n '
' { \n ' % ( i . name_lower ) )
2011-08-23 18:46:32 +02:00
for p in i . properties :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_object_class_override_property (klass, property_id_begin++, " %s " ); \n ' % ( p . name_hyphen ) )
self . outfile . write ( ' return property_id_begin - 1; \n '
' } \n '
' \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# ----------------------------------------------------------------------------------------------------
def generate_interface ( self , i ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s : \n '
' * \n '
' * Abstract interface type for the D-Bus interface # %s . \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , i . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s Iface: \n '
' * @parent_iface: The parent interface. \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name ) , False ) )
2011-04-18 20:23:19 +02:00
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
2011-08-23 18:46:32 +02:00
if len ( i . properties ) > 0 :
for p in i . properties :
key = ( p . since , ' _prop_get_ %s ' % p . name_lower )
value = ' @get_ %s : ' % ( p . name_lower )
value + = ' Getter for the # %s : %s property. ' % ( i . camel_name , p . name_hyphen )
doc_bits [ key ] = value
2012-06-14 08:20:17 +02:00
for key in sorted ( doc_bits . keys ( ) , key = utils . version_cmp_key ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * %s \n ' % doc_bits [ key ] )
2012-06-14 08:20:17 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' * \n '
' * Virtual table for the D-Bus interface # %s . \n '
2011-05-24 06:27:43 +02:00
% ( i . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' typedef %s Iface %s Interface; \n ' % ( i . camel_name , i . camel_name ) )
self . outfile . write ( ' G_DEFINE_INTERFACE ( %s , %s , G_TYPE_OBJECT) \n ' % ( i . camel_name , i . name_lower ) )
self . outfile . write ( ' \n ' )
2013-03-24 17:11:49 +01:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _default_init ( %s Iface *iface) \n '
' { \n ' % ( i . name_lower , i . camel_name ) ) ;
2011-04-08 22:57:31 +02:00
if len ( i . methods ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* GObject signals for incoming D-Bus method calls: */ \n ' )
2011-04-08 22:57:31 +02:00
for m in i . methods :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s ::handle- %s : \n '
' * @object: A # %s . \n '
' * @invocation: A #GDBusMethodInvocation. \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , m . name_hyphen , i . camel_name ) , False ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @fd_list: (nullable): A #GUnixFDList or % NULL. \n ' )
2011-04-18 20:23:19 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @arg_ %s : Argument passed by remote caller. \n ' % ( a . name ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' * \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 '
2020-08-03 17:04:12 +02:00
' * Returns: %% G_DBUS_METHOD_INVOCATION_HANDLED or %% TRUE if the invocation was handled, %% G_DBUS_METHOD_INVOCATION_UNHANDLED or %% FALSE to let other signal handlers run. \n '
2011-05-24 06:27:43 +02:00
% ( i . name , m . name , i . name_lower , m . name_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . outfile , 2 )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2011-07-21 22:03:27 +02:00
extra_args = 2
else :
extra_args = 1
2018-01-04 09:56:59 +01:00
self . outfile . 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
' g_cclosure_marshal_generic, \n '
' G_TYPE_BOOLEAN, \n '
' %d , \n '
' G_TYPE_DBUS_METHOD_INVOCATION '
% ( m . name_hyphen , i . camel_name , m . name_lower , len ( m . in_args ) + extra_args ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , G_TYPE_UNIX_FD_LIST ' )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , %s ' % ( a . gtype ) )
self . outfile . write ( ' ); \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
if len ( i . signals ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* GObject signals for received D-Bus signals: */ \n ' )
2011-04-08 22:57:31 +02:00
for s in i . signals :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s :: %s : \n '
' * @object: A # %s . \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , s . name_hyphen , i . camel_name ) , False ) )
2011-04-18 20:23:19 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @arg_ %s : Argument. \n ' % ( a . name ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' * \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 '
2011-05-24 06:27:43 +02:00
% ( i . name , s . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( s , self . outfile , 2 )
self . outfile . 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
' g_cclosure_marshal_generic, \n '
' G_TYPE_NONE, \n '
' %d '
% ( s . name_hyphen , i . camel_name , s . name_lower , len ( s . args ) ) )
2011-04-08 22:57:31 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , %s ' % ( a . gtype ) )
self . outfile . write ( ' ); \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* GObject properties for D-Bus properties: */ \n ' )
2011-04-08 22:57:31 +02:00
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 :
2018-01-12 08:55:36 +01:00
print_error ( ' Cannot handle property " {} " that neither readable nor writable ' . format ( p . name ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s : %s : \n '
' * \n '
' * Represents the D-Bus property # %s : %s . \n '
' * \n '
' * %s \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , p . name_hyphen , i . name , p . name , hint ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( p , self . outfile , 2 )
self . outfile . write ( ' g_object_interface_install_property (iface, \n ' )
2011-04-08 22:57:31 +02:00
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-07-21 15:32:38 +02:00
elif p . arg . signature == ' ao ' :
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 :
2018-01-12 08:55:36 +01:00
print_error ( ' Unsupported gtype " {} " for GParamSpec ' . format ( p . arg . gtype ) )
2018-11-21 16:05:20 +01:00
flags = ' G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS '
if p . deprecated :
flags = ' G_PARAM_DEPRECATED | ' + flags
self . outfile . write ( ' %s , %s )); ' % ( s , flags ) ) ;
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# ----------------------------------------------------------------------------------------------------
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 :
2018-01-12 08:55:36 +01:00
print_error ( ' Cannot handle property " {} " that neither readable nor writable ' . format ( p . name ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
2011-08-23 18:46:32 +02:00
' * %s _get_ %s : (skip) \n '
2011-04-18 20:23:19 +02:00
' * @object: A # %s . \n '
' * \n '
' * Gets the value of the # %s : %s D-Bus property. \n '
' * \n '
' * %s \n '
' * \n '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , p . name_lower , i . camel_name , i . name , p . name , hint ) , False ) )
2011-08-23 18:46:32 +02:00
if p . arg . free_func != None :
2019-12-02 17:48:32 +01:00
self . outfile . write ( ' * The returned value is only valid until the property changes so on the client-side it is only safe to use this function on the thread where @object was constructed. Use %s _dup_ %s () if on another thread. \n '
2018-01-04 09:56:59 +01:00
' * \n '
2018-12-11 00:01:36 +01:00
' * Returns: (transfer none) (nullable): The property value or %% NULL if the property is not set. Do not free the returned value, it belongs to @object. \n '
2018-01-04 09:56:59 +01:00
% ( i . name_lower , p . name_lower ) )
2011-08-23 18:46:32 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * Returns: The property value. \n ' )
self . write_gtkdoc_deprecated_and_since_and_close ( p , self . outfile , 0 )
self . outfile . write ( ' %s \n '
' %s _get_ %s ( %s *object) \n '
' { \n ' % ( p . arg . ctype_in , i . name_lower , p . name_lower , i . camel_name ) )
self . outfile . write ( ' return %s %s _GET_IFACE (object)->get_ %s (object); \n ' % ( i . ns_upper , i . name_upper , p . name_lower ) )
self . outfile . write ( ' } \n ' )
self . outfile . write ( ' \n ' )
2011-08-23 18:46:32 +02:00
if p . arg . free_func != None :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-08-23 18:46:32 +02:00
' /** \n '
' * %s _dup_ %s : (skip) \n '
' * @object: A # %s . \n '
' * \n '
' * Gets a copy of the # %s : %s D-Bus property. \n '
' * \n '
' * %s \n '
' * \n '
2018-12-11 00:01:36 +01:00
' * Returns: (transfer full) (nullable): The property value or %% NULL if the property is not set. The returned value should be freed with %s (). \n '
2011-08-23 18:46:32 +02:00
% ( i . name_lower , p . name_lower , i . camel_name , i . name , p . name , hint , p . arg . free_func ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( p , self . outfile , 0 )
self . outfile . write ( ' %s \n '
' %s _dup_ %s ( %s *object) \n '
' { \n '
' %s value; \n ' % ( p . arg . ctype_in_dup , i . name_lower , p . name_lower , i . camel_name , p . arg . ctype_in_dup ) )
self . outfile . write ( ' g_object_get (G_OBJECT (object), " %s " , &value, NULL); \n ' % ( p . name_hyphen ) )
self . outfile . write ( ' return value; \n ' )
self . outfile . write ( ' } \n ' )
self . outfile . write ( ' \n ' )
2011-08-23 18:46:32 +02:00
2011-04-08 22:57:31 +02:00
# 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 :
2018-01-12 08:55:36 +01:00
print_error ( ' Cannot handle property " {} " that neither readable nor writable ' . format ( p . name ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
2011-08-23 18:46:32 +02:00
' * %s _set_ %s : (skip) \n '
2011-04-18 20:23:19 +02:00
' * @object: A # %s . \n '
' * @value: The value to set. \n '
' * \n '
' * Sets the # %s : %s D-Bus property to @value. \n '
' * \n '
' * %s \n '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , p . name_lower , i . camel_name , i . name , p . name , hint ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( p , self . outfile , 0 )
self . outfile . 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 . outfile . write ( ' g_object_set (G_OBJECT (object), " %s " , value, NULL); \n ' % ( p . name_hyphen ) )
self . outfile . write ( ' } \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# ---------------------------------------------------------------------------------------------------
def generate_signal_emitters ( self , i ) :
for s in i . signals :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s _emit_ %s : \n '
' * @object: A # %s . \n '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , s . name_lower , i . camel_name ) , False ) )
2011-04-18 20:23:19 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @arg_ %s : Argument to pass with the signal. \n ' % ( a . name ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' * \n '
' * Emits the # %s :: %s D-Bus signal. \n '
2011-05-24 06:27:43 +02:00
% ( i . name , s . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( s , self . outfile , 0 )
self . outfile . write ( ' void \n '
' %s _emit_ %s ( \n '
' %s *object ' % ( i . name_lower , s . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s arg_ %s ' % ( a . ctype_in , a . name ) )
self . outfile . write ( ' ) \n '
' { \n '
' g_signal_emit_by_name (object, " %s " ' % ( s . name_hyphen ) )
2011-04-08 22:57:31 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , arg_ %s ' % a . name )
self . outfile . write ( ' ); \n ' )
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# ---------------------------------------------------------------------------------------------------
def generate_method_calls ( self , i ) :
for m in i . methods :
# async begin
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /** \n '
' * %s _call_ %s : \n '
' * @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 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @arg_ %s : Argument to pass with the method invocation. \n ' % ( a . name ) )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' * @call_flags: Flags from the #GDBusCallFlags enumeration. If you want to allow interactive \n '
' authorization be sure to set %G _DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION. \n '
' * @timeout_msec: The timeout in milliseconds (with %G _MAXINT meaning " infinite " ) or \n '
' -1 to use the proxy default timeout. \n ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @fd_list: (nullable): A #GUnixFDList or % NULL. \n ' )
self . outfile . write ( self . docbook_gen . expand (
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2019-12-02 17:47:44 +01:00
' * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from (see g_main_context_push_thread_default()). \n '
2011-04-18 20:23:19 +02:00
' * 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 '
2011-05-24 06:27:43 +02:00
% ( i . name , m . name , i . name_lower , m . name_lower , i . name_lower , m . name_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . outfile , 0 )
self . outfile . write ( ' void \n '
' %s _call_ %s ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s arg_ %s ' % ( a . ctype_in , a . name ) )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' , \n GDBusCallFlags call_flags '
' , \n gint timeout_msec ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList *fd_list ' )
self . outfile . write ( ' , \n '
' GCancellable *cancellable, \n '
' GAsyncReadyCallback callback, \n '
' gpointer user_data) \n '
' { \n ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy), \n ' )
2011-07-21 22:03:27 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_dbus_proxy_call (G_DBUS_PROXY (proxy), \n ' )
self . outfile . write ( ' " %s " , \n '
' g_variant_new ( " ( ' % ( m . name ) )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ' % ( a . format_in ) )
self . outfile . write ( ' ) " ' )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n arg_ %s ' % ( a . name ) )
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' ), \n ' )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' call_flags, \n '
' timeout_msec, \n ' )
else :
self . outfile . write ( ' G_DBUS_CALL_FLAGS_NONE, \n '
' -1, \n ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' fd_list, \n ' )
self . outfile . write ( ' cancellable, \n '
' callback, \n '
' user_data); \n ' )
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# async finish
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /** \n '
' * %s _call_ %s _finish: \n '
' * @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 :
2018-12-11 00:01:36 +01:00
self . outfile . write ( ' * @out_ %s : (out) (optional) %s : Return location for return parameter or %% NULL to ignore. \n ' % ( a . name , ' ' + a . array_annotation if a . array_annotation else ' ' ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-12-11 00:01:36 +01:00
self . outfile . write ( ' * @out_fd_list: (out) (optional): Return location for a #GUnixFDList or % NULL to ignore. \n ' )
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' * @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 '
2020-06-12 15:02:30 +02:00
' * Returns: (skip): %% TRUE if the call succeeded, %% FALSE if @error is set. \n '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , m . name_lower , i . name_lower , m . name_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . outfile , 0 )
self . outfile . write ( ' gboolean \n '
' %s _call_ %s _finish ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList **out_fd_list ' )
self . outfile . write ( ' , \n '
' GAsyncResult *res, \n '
' GError **error) \n '
' { \n '
' GVariant *_ret; \n ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error); \n ' )
2011-07-21 22:03:27 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error); \n ' )
self . outfile . write ( ' if (_ret == NULL) \n '
' goto _out; \n ' )
self . outfile . write ( ' g_variant_get (_ret, \n '
' \" ( ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ' % ( a . format_out ) )
self . outfile . write ( ' ) " ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n out_ %s ' % ( a . name ) )
self . outfile . write ( ' ); \n '
' g_variant_unref (_ret); \n ' )
self . outfile . write ( ' _out: \n '
' return _ret != NULL; \n '
' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# sync
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /** \n '
' * %s _call_ %s _sync: \n '
' * @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 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @arg_ %s : Argument to pass with the method invocation. \n ' % ( a . name ) )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' * @call_flags: Flags from the #GDBusCallFlags enumeration. If you want to allow interactive \n '
' authorization be sure to set %G _DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION. \n '
' * @timeout_msec: The timeout in milliseconds (with %G _MAXINT meaning " infinite " ) or \n '
' -1 to use the proxy default timeout. \n ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @fd_list: (nullable): A #GUnixFDList or % NULL. \n ' )
2011-04-16 20:07:23 +02:00
for a in m . out_args :
2018-12-11 00:01:36 +01:00
self . outfile . write ( ' * @out_ %s : (out) (optional) %s : Return location for return parameter or %% NULL to ignore. \n ' % ( a . name , ' ' + a . array_annotation if a . array_annotation else ' ' ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @out_fd_list: (out): Return location for a #GUnixFDList or % NULL. \n ' )
self . outfile . write ( self . docbook_gen . expand (
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2020-06-12 15:02:30 +02:00
' * Returns: (skip): %% TRUE if the call succeeded, %% FALSE if @error is set. \n '
2011-05-24 06:27:43 +02:00
% ( i . name , m . name , i . name_lower , m . name_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . outfile , 0 )
self . outfile . write ( ' gboolean \n '
' %s _call_ %s _sync ( \n '
' %s *proxy ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s arg_ %s ' % ( a . ctype_in , a . name ) )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' , \n GDBusCallFlags call_flags '
' , \n gint timeout_msec ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList *fd_list ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s out_ %s ' % ( a . ctype_out , a . name ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList **out_fd_list ' )
self . outfile . write ( ' , \n '
' GCancellable *cancellable, \n '
' GError **error) \n '
' { \n '
' GVariant *_ret; \n ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy), \n ' )
2011-07-21 22:03:27 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy), \n ' )
self . outfile . write ( ' " %s " , \n '
' g_variant_new ( " ( ' % ( m . name ) )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ' % ( a . format_in ) )
self . outfile . write ( ' ) " ' )
2011-04-08 22:57:31 +02:00
for a in m . in_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n arg_ %s ' % ( a . name ) )
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' ), \n ' )
2020-01-31 13:23:22 +01:00
if self . glib_min_required > = ( 2 , 64 ) :
gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).
If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).
So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.
The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46
It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.
Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.
Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.
The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.
Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2019-11-25 20:51:13 +01:00
self . outfile . write ( ' call_flags, \n '
' timeout_msec, \n ' )
else :
self . outfile . write ( ' G_DBUS_CALL_FLAGS_NONE, \n '
' -1, \n ' )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' fd_list, \n '
' out_fd_list, \n ' )
self . outfile . write ( ' cancellable, \n '
' error); \n '
' if (_ret == NULL) \n '
' goto _out; \n ' )
self . outfile . write ( ' g_variant_get (_ret, \n '
' \" ( ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ' % ( a . format_out ) )
self . outfile . write ( ' ) " ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n out_ %s ' % ( a . name ) )
self . outfile . write ( ' ); \n '
' g_variant_unref (_ret); \n ' )
self . outfile . write ( ' _out: \n '
' return _ret != NULL; \n '
' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# ---------------------------------------------------------------------------------------------------
def generate_method_completers ( self , i ) :
for m in i . methods :
2018-01-04 09:56:59 +01:00
self . outfile . 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 ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @fd_list: (nullable): A #GUnixFDList or % NULL. \n ' )
2011-04-18 20:23:19 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' * @ %s : Parameter to return. \n ' % ( a . name ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' * \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 '
2011-05-24 06:27:43 +02:00
% ( i . name , m . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( m , self . outfile , 0 )
self . outfile . write ( ' void \n '
' %s _complete_ %s ( \n '
' %s *object, \n '
' GDBusMethodInvocation *invocation ' % ( i . name_lower , m . name_lower , i . camel_name ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n GUnixFDList *fd_list ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s %s ' % ( a . ctype_in , a . name ) )
self . outfile . write ( ' ) \n '
' { \n ' )
2011-04-08 22:57:31 +02:00
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_dbus_method_invocation_return_value_with_unix_fd_list (invocation, \n '
' g_variant_new ( " ( ' )
2011-07-21 22:03:27 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_dbus_method_invocation_return_value (invocation, \n '
' g_variant_new ( " ( ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ' % ( a . format_in ) )
self . outfile . write ( ' ) " ' )
2011-04-08 22:57:31 +02:00
for a in m . out_args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s ' % ( a . name ) )
2019-09-02 07:54:37 +02:00
if m . unix_fd :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' ), \n fd_list); \n ' )
2011-07-21 22:03:27 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' )); \n ' )
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# ---------------------------------------------------------------------------------------------------
def generate_proxy ( self , i ) :
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* ------------------------------------------------------------------------ */ \n '
' \n ' )
2011-04-18 20:23:19 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s Proxy: \n '
' * \n '
' * The # %s Proxy structure contains only private data and should only be accessed using the provided API. \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s ProxyClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s Proxy. \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s ProxyPrivate \n '
' { \n '
' GData *qdata; \n '
' }; \n '
' \n ' % i . camel_name )
self . outfile . write ( ' static void %s _proxy_iface_init ( %s Iface *iface); \n '
' \n ' % ( i . name_lower , i . camel_name ) )
self . outfile . write ( ' #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 \n ' )
self . outfile . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s Proxy, %s _proxy, G_TYPE_DBUS_PROXY, \n ' % ( i . camel_name , i . name_lower ) )
self . outfile . write ( ' G_ADD_PRIVATE ( %s Proxy) \n ' % ( i . camel_name ) )
self . outfile . write ( ' G_IMPLEMENT_INTERFACE ( %s TYPE_ %s , %s _proxy_iface_init)) \n \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . write ( ' #else \n ' )
self . outfile . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s Proxy, %s _proxy, G_TYPE_DBUS_PROXY, \n ' % ( i . camel_name , i . name_lower ) )
self . outfile . write ( ' G_IMPLEMENT_INTERFACE ( %s TYPE_ %s , %s _proxy_iface_init)) \n \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . write ( ' #endif \n ' )
2011-08-23 18:46:32 +02:00
# finalize
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _proxy_finalize (GObject *object) \n '
' { \n ' % ( i . name_lower ) )
self . outfile . write ( ' %s Proxy *proxy = %s %s _PROXY (object); \n ' % ( i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' g_datalist_clear (&proxy->priv->qdata); \n ' )
self . outfile . write ( ' G_OBJECT_CLASS ( %s _proxy_parent_class)->finalize (object); \n '
' } \n '
' \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
# 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
#
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _proxy_get_property (GObject *object, \n '
' guint prop_id, \n '
' GValue *value, \n '
' GParamSpec *pspec G_GNUC_UNUSED) \n '
' { \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' const _ExtendedGDBusPropertyInfo *info; \n '
' GVariant *variant; \n '
' g_assert (prop_id != 0 && prop_id - 1 < %d ); \n '
2018-09-07 00:19:05 +02:00
' info = (const _ExtendedGDBusPropertyInfo *) _ %s _property_info_pointers[prop_id - 1]; \n '
2018-01-04 09:56:59 +01:00
' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name); \n '
' if (info->use_gvariant) \n '
' { \n '
' g_value_set_variant (value, variant); \n '
' } \n '
' else \n '
' { \n '
# could be that we don't have the value in cache - in that case, we do
# nothing and the user gets the default value for the GType
' if (variant != NULL) \n '
' g_dbus_gvariant_to_gvalue (variant, value); \n '
' } \n '
' if (variant != NULL) \n '
' g_variant_unref (variant); \n '
% ( len ( i . properties ) , i . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _proxy_set_property_cb (GDBusProxy *proxy, \n '
' GAsyncResult *res, \n '
' gpointer user_data) \n '
' { \n ' % ( i . name_lower ) )
self . outfile . write ( ' const _ExtendedGDBusPropertyInfo *info = user_data; \n '
' GError *error; \n '
' GVariant *_ret; \n '
' error = NULL; \n '
' _ret = g_dbus_proxy_call_finish (proxy, res, &error); \n '
' if (!_ret) \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 '
' else \n '
' { \n '
' g_variant_unref (_ret); \n '
' } \n '
% ( i . name ) )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static void \n '
' %s _proxy_set_property (GObject *object, \n '
' guint prop_id, \n '
' const GValue *value, \n '
' GParamSpec *pspec G_GNUC_UNUSED) \n '
' { \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' const _ExtendedGDBusPropertyInfo *info; \n '
' GVariant *variant; \n '
' g_assert (prop_id != 0 && prop_id - 1 < %d ); \n '
2018-09-07 00:19:05 +02:00
' info = (const _ExtendedGDBusPropertyInfo *) _ %s _property_info_pointers[prop_id - 1]; \n '
2018-01-04 09:56:59 +01:00
' 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, (GDBusPropertyInfo *) &info->parent_struct); \n '
' g_variant_unref (variant); \n '
% ( len ( i . properties ) , i . name_lower , i . name , i . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# signal received
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _proxy_g_signal (GDBusProxy *proxy, \n '
' const gchar *sender_name G_GNUC_UNUSED, \n '
' const gchar *signal_name, \n '
' GVariant *parameters) \n '
' { \n ' % ( i . name_lower ) )
self . outfile . write ( ' _ExtendedGDBusSignalInfo *info; \n '
' GVariantIter iter; \n '
' GVariant *child; \n '
' GValue *paramv; \n '
' gsize num_params; \n '
' gsize n; \n '
' guint signal_id; \n ' ) ;
2011-04-08 22:57:31 +02:00
# Note: info could be NULL if we are talking to a newer version of the interface
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_ %s _interface_info.parent_struct, signal_name); \n '
' if (info == NULL) \n '
' return; \n '
% ( i . name_lower ) )
self . outfile . 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 . outfile . 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 . outfile . write ( ' signal_id = g_signal_lookup (info->signal_name, %s TYPE_ %s ); \n '
% ( i . ns_upper , i . name_upper ) )
self . outfile . write ( ' g_signal_emitv (paramv, signal_id, 0, NULL); \n ' )
self . outfile . write ( ' for (n = 0; n < num_params + 1; n++) \n '
' g_value_unset (¶mv[n]); \n '
' g_free (paramv); \n ' )
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# property changed
2018-01-04 09:56:59 +01:00
self . outfile . 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 ) )
2011-04-08 22:57:31 +02:00
# Note: info could be NULL if we are talking to a newer version of the interface
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s Proxy *proxy = %s %s _PROXY (_proxy); \n '
' 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.parent_struct, key); \n '
' g_datalist_remove_data (&proxy->priv->qdata, 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.parent_struct, invalidated_properties[n]); \n '
' g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]); \n '
' if (info != NULL) \n '
' g_object_notify (G_OBJECT (proxy), info->hyphen_name); \n '
' } \n '
' } \n '
' \n '
% ( i . camel_name , i . ns_upper , i . name_upper ,
i . name_lower , i . name_lower ) )
2011-08-23 18:46:32 +02:00
# property vfuncs
for p in i . properties :
nul_value = ' 0 '
if p . arg . free_func != None :
nul_value = ' NULL '
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static %s \n '
' %s _proxy_get_ %s ( %s *object) \n '
' { \n '
' %s Proxy *proxy = %s %s _PROXY (object); \n '
' GVariant *variant; \n '
' %s value = %s ; \n ' % ( p . arg . ctype_in , i . name_lower , p . name_lower , i . camel_name ,
i . camel_name , i . ns_upper , i . name_upper ,
p . arg . ctype_in , nul_value ) )
2011-08-23 18:46:32 +02:00
# For some property types, we have to free the returned
# value (or part of it, e.g. the container) because of how
# GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
# for details
#
free_container = False ;
2018-01-17 17:12:25 +01:00
if p . arg . gvariant_get == ' g_variant_get_strv ' or p . arg . gvariant_get == ' g_variant_get_objv ' or p . arg . gvariant_get == ' g_variant_get_bytestring_array ' :
2011-08-23 18:46:32 +02:00
free_container = True ;
2018-01-17 17:12:25 +01:00
# If already using an old value for strv, objv, bytestring_array (see below),
2011-08-23 18:46:32 +02:00
# then just return that... that way the result from multiple consecutive calls
# to the getter are valid as long as they're freed
#
if free_container :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' value = g_datalist_get_data (&proxy->priv->qdata, \" %s \" ); \n '
' if (value != NULL) \n '
' return value; \n '
% ( p . name ) )
self . outfile . write ( ' variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \" %s \" ); \n ' % ( p . name ) )
2011-08-23 18:46:32 +02:00
if p . arg . gtype == ' G_TYPE_VARIANT ' :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' value = variant; \n ' )
self . outfile . write ( ' if (variant != NULL) \n ' )
self . outfile . write ( ' g_variant_unref (variant); \n ' )
2011-08-23 18:46:32 +02:00
else :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' if (variant != NULL) \n '
' { \n ' )
2011-08-23 18:46:32 +02:00
extra_len = ' '
if p . arg . gvariant_get == ' g_variant_get_string ' or p . arg . gvariant_get == ' g_variant_get_strv ' or p . arg . gvariant_get == ' g_variant_get_objv ' or p . arg . gvariant_get == ' g_variant_get_bytestring_array ' :
extra_len = ' , NULL '
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' value = %s (variant %s ); \n ' % ( p . arg . gvariant_get , extra_len ) )
2011-08-23 18:46:32 +02:00
if free_container :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_datalist_set_data_full (&proxy->priv->qdata, \" %s \" , (gpointer) value, g_free); \n '
% ( p . name ) )
self . outfile . write ( ' g_variant_unref (variant); \n ' )
self . outfile . write ( ' } \n ' )
self . outfile . write ( ' return value; \n ' )
self . outfile . write ( ' } \n ' )
self . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _proxy_init ( %s Proxy *proxy) \n '
' { \n '
' #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 \n '
' proxy->priv = %s _proxy_get_instance_private (proxy); \n '
' #else \n '
' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %s TYPE_ %s _PROXY, %s ProxyPrivate); \n '
' #endif \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 ,
i . ns_upper , i . name_upper , i . camel_name ,
i . name_lower ) )
self . outfile . 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->finalize = %s _proxy_finalize; \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 , i . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s _override_properties (gobject_class, 1); \n \n ' % ( i . name_lower ) )
self . outfile . write ( ' #if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38 \n '
' g_type_class_add_private (klass, sizeof ( %s ProxyPrivate)); \n '
' #endif \n ' % ( i . camel_name ) )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static void \n '
' %s _proxy_iface_init ( %s Iface *iface) \n '
' { \n ' % ( i . name_lower , i . camel_name ) )
2011-08-23 18:46:32 +02:00
for p in i . properties :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' iface->get_ %s = %s _proxy_get_ %s ; \n ' % ( p . name_lower , i . name_lower , p . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
2011-08-23 18:46:32 +02:00
2011-04-08 22:57:31 +02:00
# constructors
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s _proxy_new: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusProxyFlags enumeration. \n '
2017-11-17 12:42:48 +01:00
' * @name: (nullable): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
2011-04-18 20:23:19 +02:00
' * @object_path: An object path. \n '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2019-12-02 17:47:44 +01:00
' * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from (see g_main_context_push_thread_default()). \n '
2011-04-18 20:23:19 +02:00
' * 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 '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , i . name , i . name_lower , i . name_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . 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 ) )
self . outfile . write ( ' /** \n '
' * %s _proxy_new_finish: \n '
' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s _proxy_new(). \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
' * 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 . outfile , 0 )
self . outfile . 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 ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s _proxy_new_sync: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusProxyFlags enumeration. \n '
2017-11-17 12:42:48 +01:00
' * @name: (nullable): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
2011-04-18 20:23:19 +02:00
' * @object_path: An object path. \n '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , i . name , i . name_lower , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . 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 . outfile . write ( ' \n ' )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \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 '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2019-12-02 17:47:44 +01:00
' * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from (see g_main_context_push_thread_default()). \n '
2011-04-18 20:23:19 +02:00
' * 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 '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , i . name_lower , i . name_lower , i . name_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . 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 ) )
self . outfile . write ( ' /** \n '
' * %s _proxy_new_for_bus_finish: \n '
' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s _proxy_new_for_bus(). \n '
' * @error: Return location for error or %% NULL \n '
' * \n '
' * 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 . outfile , 0 )
self . outfile . 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 ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \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 '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , i . name_lower , i . name_lower , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . 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 . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# ---------------------------------------------------------------------------------------------------
2011-04-13 22:33:51 +02:00
def generate_skeleton ( self , i ) :
2011-04-08 22:57:31 +02:00
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* ------------------------------------------------------------------------ */ \n '
' \n ' )
2011-04-08 22:57:31 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s Skeleton: \n '
' * \n '
' * The # %s Skeleton structure contains only private data and should only be accessed using the provided API. \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' \n ' )
2011-04-18 20:23:19 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s SkeletonClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s Skeleton. \n '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' struct _ %s SkeletonPrivate \n '
' { \n '
' GValue *properties; \n '
' GList *changed_properties; \n '
' GSource *changed_properties_idle_source; \n '
' GMainContext *context; \n '
' GMutex lock; \n '
' }; \n '
' \n ' % i . camel_name )
self . outfile . write ( ' static void \n '
' _ %s _skeleton_handle_method_call ( \n '
' GDBusConnection *connection G_GNUC_UNUSED, \n '
' const gchar *sender G_GNUC_UNUSED, \n '
' const gchar *object_path G_GNUC_UNUSED, \n '
' const gchar *interface_name, \n '
' const gchar *method_name, \n '
' GVariant *parameters, \n '
' GDBusMethodInvocation *invocation, \n '
' gpointer user_data) \n '
' { \n '
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
' _ExtendedGDBusMethodInfo *info; \n '
' GVariantIter iter; \n '
' GVariant *child; \n '
' GValue *paramv; \n '
' gsize num_params; \n '
' guint num_extra; \n '
' gsize n; \n '
' guint signal_id; \n '
' GValue return_value = G_VALUE_INIT; \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation); \n '
' g_assert (info != NULL); \n '
% ( ) )
self . outfile . write ( ' num_params = g_variant_n_children (parameters); \n '
' num_extra = info->pass_fdlist ? 3 : 2; '
' paramv = g_new0 (GValue, num_params + num_extra); \n '
' n = 0; \n '
' g_value_init (¶mv[n], %s TYPE_ %s ); \n '
' g_value_set_object (¶mv[n++], skeleton); \n '
' g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION); \n '
' g_value_set_object (¶mv[n++], invocation); \n '
' if (info->pass_fdlist) \n '
' { \n '
' #ifdef G_OS_UNIX \n '
' g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST); \n '
' g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation))); \n '
' #else \n '
' g_assert_not_reached (); \n '
' #endif \n '
' } \n '
% ( i . ns_upper , i . name_upper ) )
self . outfile . write ( ' g_variant_iter_init (&iter, parameters); \n '
' while ((child = g_variant_iter_next_value (&iter)) != NULL) \n '
' { \n '
' _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra]; \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 . outfile . write ( ' signal_id = g_signal_lookup (info->signal_name, %s TYPE_ %s ); \n '
% ( i . ns_upper , i . name_upper ) )
self . outfile . 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 . outfile . write ( ' for (n = 0; n < num_params + num_extra; n++) \n '
' g_value_unset (¶mv[n]); \n '
' g_free (paramv); \n ' )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static GVariant * \n '
' _ %s _skeleton_handle_get_property ( \n '
' GDBusConnection *connection G_GNUC_UNUSED, \n '
' const gchar *sender G_GNUC_UNUSED, \n '
' const gchar *object_path G_GNUC_UNUSED, \n '
' const gchar *interface_name G_GNUC_UNUSED, \n '
' const gchar *property_name, \n '
' GError **error, \n '
' gpointer user_data) \n '
' { \n '
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
' GValue value = G_VALUE_INIT; \n '
' GParamSpec *pspec; \n '
' _ExtendedGDBusPropertyInfo *info; \n '
' GVariant *ret; \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' ret = NULL; \n '
' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_ %s _interface_info.parent_struct, property_name); \n '
' g_assert (info != NULL); \n '
' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); \n '
' 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 '
' g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value); \n '
' 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 . outfile . write ( ' static gboolean \n '
' _ %s _skeleton_handle_set_property ( \n '
' GDBusConnection *connection G_GNUC_UNUSED, \n '
' const gchar *sender G_GNUC_UNUSED, \n '
' const gchar *object_path G_GNUC_UNUSED, \n '
' const gchar *interface_name G_GNUC_UNUSED, \n '
' const gchar *property_name, \n '
' GVariant *variant, \n '
' GError **error, \n '
' gpointer user_data) \n '
' { \n '
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
' GValue value = G_VALUE_INIT; \n '
' GParamSpec *pspec; \n '
' _ExtendedGDBusPropertyInfo *info; \n '
' gboolean ret; \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' ret = FALSE; \n '
' info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_ %s _interface_info.parent_struct, property_name); \n '
' g_assert (info != NULL); \n '
' pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name); \n '
' 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 '
' g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value); \n '
' g_value_unset (&value); \n '
' ret = TRUE; \n '
' } \n '
' return ret; \n '
' } \n '
' \n '
% ( i . name_lower ) )
self . outfile . write ( ' static const GDBusInterfaceVTable _ %s _skeleton_vtable = \n '
' { \n '
' _ %s _skeleton_handle_method_call, \n '
' _ %s _skeleton_handle_get_property, \n '
' _ %s _skeleton_handle_set_property, \n '
' {NULL} \n '
' }; \n '
' \n ' % ( i . name_lower , i . name_lower , i . name_lower , i . name_lower ) )
self . outfile . write ( ' static GDBusInterfaceInfo * \n '
' %s _skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED) \n '
' { \n '
' return %s _interface_info (); \n '
% ( i . name_lower , i . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static GDBusInterfaceVTable * \n '
' %s _skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED) \n '
' { \n '
' return (GDBusInterfaceVTable *) &_ %s _skeleton_vtable; \n '
% ( i . name_lower , i . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static GVariant * \n '
' %s _skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton) \n '
' { \n '
' %s Skeleton *skeleton = %s %s _SKELETON (_skeleton); \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' \n '
' GVariantBuilder builder; \n '
' guint n; \n '
' g_variant_builder_init (&builder, G_VARIANT_TYPE ( " a {sv} " )); \n '
' if (_ %s _interface_info.parent_struct.properties == NULL) \n '
' goto out; \n '
' for (n = 0; _ %s _interface_info.parent_struct.properties[n] != NULL; n++) \n '
' { \n '
' GDBusPropertyInfo *info = _ %s _interface_info.parent_struct.properties[n]; \n '
' if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) \n '
' { \n '
' GVariant *value; \n '
' 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 '
' if (value != NULL) \n '
' { \n '
' g_variant_take_ref (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 ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static gboolean _ %s _emit_changed (gpointer user_data); \n '
' \n '
% ( i . name_lower ) )
self . outfile . write ( ' static void \n '
' %s _skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton) \n '
' { \n '
% ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s Skeleton *skeleton = %s %s _SKELETON (_skeleton); \n '
' gboolean emit_changed = FALSE; \n '
' \n '
' g_mutex_lock (&skeleton->priv->lock); \n '
' if (skeleton->priv->changed_properties_idle_source != NULL) \n '
' { \n '
' g_source_destroy (skeleton->priv->changed_properties_idle_source); \n '
' skeleton->priv->changed_properties_idle_source = NULL; \n '
' emit_changed = TRUE; \n '
' } \n '
' g_mutex_unlock (&skeleton->priv->lock); \n '
' \n '
' if (emit_changed) \n '
' _ %s _emit_changed (skeleton); \n '
% ( i . camel_name , i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
for s in i . signals :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' _ %s _on_signal_ %s ( \n '
' %s *object ' % ( i . name_lower , s . name_lower , i . camel_name ) )
2011-04-08 22:57:31 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n %s arg_ %s ' % ( a . ctype_in , a . name ) )
self . outfile . write ( ' ) \n '
' { \n '
' %s Skeleton *skeleton = %s %s _SKELETON (object); \n \n '
' GList *connections, *l; \n '
' GVariant *signal_variant; \n '
' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton)); \n '
% ( i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' \n '
' signal_variant = g_variant_ref_sink (g_variant_new ( " ( ' )
2011-04-08 22:57:31 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ' % ( a . format_in ) )
self . outfile . write ( ' ) " ' )
2011-04-08 22:57:31 +02:00
for a in s . args :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' , \n arg_ %s ' % ( a . name ) )
self . outfile . write ( ' )); \n ' )
self . outfile . write ( ' for (l = connections; l != NULL; l = l->next) \n '
' { \n '
' GDBusConnection *connection = l->data; \n '
' g_dbus_connection_emit_signal (connection, \n '
' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), " %s " , " %s " , \n '
' signal_variant, NULL); \n '
' } \n '
% ( i . name , s . name ) )
self . outfile . write ( ' g_variant_unref (signal_variant); \n ' )
self . outfile . write ( ' g_list_free_full (connections, g_object_unref); \n ' )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static void %s _skeleton_iface_init ( %s Iface *iface); \n '
% ( i . name_lower , i . camel_name ) )
self . outfile . write ( ' #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 \n ' )
self . outfile . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s Skeleton, %s _skeleton, G_TYPE_DBUS_INTERFACE_SKELETON, \n ' % ( i . camel_name , i . name_lower ) )
self . outfile . write ( ' G_ADD_PRIVATE ( %s Skeleton) \n ' % ( i . camel_name ) )
self . outfile . write ( ' G_IMPLEMENT_INTERFACE ( %s TYPE_ %s , %s _skeleton_iface_init)) \n \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . write ( ' #else \n ' )
self . outfile . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s Skeleton, %s _skeleton, G_TYPE_DBUS_INTERFACE_SKELETON, \n ' % ( i . camel_name , i . name_lower ) )
self . outfile . write ( ' G_IMPLEMENT_INTERFACE ( %s TYPE_ %s , %s _skeleton_iface_init)) \n \n ' % ( i . ns_upper , i . name_upper , i . name_lower ) )
self . outfile . write ( ' #endif \n ' )
2011-04-08 22:57:31 +02:00
# finalize
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _skeleton_finalize (GObject *object) \n '
' { \n ' % ( i . name_lower ) )
self . outfile . 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 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' guint n; \n '
' for (n = 0; n < %d ; n++) \n '
' g_value_unset (&skeleton->priv->properties[n]); \n ' % ( len ( i . properties ) ) )
self . outfile . write ( ' g_free (skeleton->priv->properties); \n ' )
self . outfile . write ( ' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free); \n ' )
self . outfile . write ( ' if (skeleton->priv->changed_properties_idle_source != NULL) \n ' )
self . outfile . write ( ' g_source_destroy (skeleton->priv->changed_properties_idle_source); \n ' )
self . outfile . write ( ' g_main_context_unref (skeleton->priv->context); \n ' )
self . outfile . write ( ' g_mutex_clear (&skeleton->priv->lock); \n ' )
self . outfile . write ( ' G_OBJECT_CLASS ( %s _skeleton_parent_class)->finalize (object); \n '
' } \n '
' \n ' % ( i . name_lower ) )
2011-04-08 22:57:31 +02:00
# property accessors (TODO: generate PropertiesChanged signals in setter)
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _skeleton_get_property (GObject *object, \n '
' guint prop_id, \n '
' GValue *value, \n '
' GParamSpec *pspec G_GNUC_UNUSED) \n '
' { \n ' % ( i . name_lower ) )
self . outfile . write ( ' %s Skeleton *skeleton = %s %s _SKELETON (object); \n '
' g_assert (prop_id != 0 && prop_id - 1 < %d ); \n '
' g_mutex_lock (&skeleton->priv->lock); \n '
' g_value_copy (&skeleton->priv->properties[prop_id - 1], value); \n '
' g_mutex_unlock (&skeleton->priv->lock); \n '
% ( i . camel_name , i . ns_upper , i . name_upper , len ( i . properties ) ) )
self . outfile . write ( ' } \n '
' \n ' )
2011-05-15 17:45:37 +02:00
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
#
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static gboolean \n '
' _ %s _emit_changed (gpointer user_data) \n '
' { \n '
' %s Skeleton *skeleton = %s %s _SKELETON (user_data); \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' GList *l; \n '
' GVariantBuilder builder; \n '
' GVariantBuilder invalidated_builder; \n '
' guint num_changes; \n '
' \n '
' g_mutex_lock (&skeleton->priv->lock); \n '
' g_variant_builder_init (&builder, G_VARIANT_TYPE ( " a {sv} " )); \n '
' g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ( " as " )); \n '
' for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next) \n '
' { \n '
' ChangedProperty *cp = l->data; \n '
' GVariant *variant; \n '
' const GValue *cur_value; \n '
' \n '
' cur_value = &skeleton->priv->properties[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 '
' num_changes++; \n '
' } \n '
' } \n '
' if (num_changes > 0) \n '
' { \n '
' GList *connections, *ll; \n '
' GVariant *signal_variant; '
' \n '
' signal_variant = g_variant_ref_sink (g_variant_new ( " (sa {sv} as) " , " %s " , \n '
' &builder, &invalidated_builder)); \n '
' connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton)); \n '
' for (ll = connections; ll != NULL; ll = ll->next) \n '
' { \n '
' GDBusConnection *connection = ll->data; \n '
' \n '
' g_dbus_connection_emit_signal (connection, \n '
' NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), \n '
' " org.freedesktop.DBus.Properties " , \n '
' " PropertiesChanged " , \n '
' signal_variant, \n '
' NULL); \n '
' } \n '
' g_variant_unref (signal_variant); \n '
' g_list_free_full (connections, g_object_unref); \n '
' } \n '
' else \n '
' { \n '
' g_variant_builder_clear (&builder); \n '
' g_variant_builder_clear (&invalidated_builder); \n '
' } \n '
% ( i . name ) )
self . outfile . write ( ' g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free); \n ' )
self . outfile . write ( ' skeleton->priv->changed_properties = NULL; \n ' )
self . outfile . write ( ' skeleton->priv->changed_properties_idle_source = NULL; \n ' )
self . outfile . write ( ' g_mutex_unlock (&skeleton->priv->lock); \n ' )
self . outfile . write ( ' return FALSE; \n '
' } \n '
' \n ' )
2011-05-15 17:45:37 +02:00
# holding lock while being called
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' _ %s _schedule_emit_changed ( %s Skeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value) \n '
' { \n '
' ChangedProperty *cp; \n '
' GList *l; \n '
' cp = NULL; \n '
' for (l = skeleton->priv->changed_properties; l != NULL; l = l->next) \n '
' { \n '
' ChangedProperty *i_cp = l->data; \n '
' if (i_cp->info == info) \n '
' { \n '
' cp = i_cp; \n '
' break; \n '
' } \n '
' } \n '
% ( i . name_lower , i . camel_name ) )
self . outfile . write ( ' if (cp == NULL) \n '
' { \n '
' cp = g_new0 (ChangedProperty, 1); \n '
' cp->prop_id = prop_id; \n '
' cp->info = info; \n '
' skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp); \n '
' g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value)); \n '
' g_value_copy (orig_value, &cp->orig_value); \n '
' } \n '
' } \n '
' \n '
% ( ) )
2011-05-15 17:45:37 +02:00
# Postpone setting up the refresh source until the ::notify signal is emitted as
# this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
# This is useful when updating several properties from another thread than
# where the idle will be emitted from
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _skeleton_notify (GObject *object, \n '
' GParamSpec *pspec G_GNUC_UNUSED) \n '
' { \n '
' %s Skeleton *skeleton = %s %s _SKELETON (object); \n '
' g_mutex_lock (&skeleton->priv->lock); \n '
' if (skeleton->priv->changed_properties != NULL && \n '
' skeleton->priv->changed_properties_idle_source == NULL) \n '
' { \n '
' 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_set_name (skeleton->priv->changed_properties_idle_source, " [generated] _ %s _emit_changed " ); \n '
' g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context); \n '
' g_source_unref (skeleton->priv->changed_properties_idle_source); \n '
' } \n '
' g_mutex_unlock (&skeleton->priv->lock); \n '
' } \n '
' \n '
% ( i . name_lower , i . camel_name , i . ns_upper , i . name_upper , i . name_lower , i . name_lower ) )
self . outfile . write ( ' static void \n '
' %s _skeleton_set_property (GObject *object, \n '
' guint prop_id, \n '
' const GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n ' % ( i . name_lower ) )
2018-12-13 12:06:02 +01:00
self . outfile . write ( ' const _ExtendedGDBusPropertyInfo *info; \n '
' %s Skeleton *skeleton = %s %s _SKELETON (object); \n '
2018-01-04 09:56:59 +01:00
' g_assert (prop_id != 0 && prop_id - 1 < %d ); \n '
2018-12-13 12:06:02 +01:00
' info = (const _ExtendedGDBusPropertyInfo *) _ %s _property_info_pointers[prop_id - 1]; \n '
2018-01-04 09:56:59 +01:00
' g_mutex_lock (&skeleton->priv->lock); \n '
' g_object_freeze_notify (object); \n '
' if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1])) \n '
' { \n '
2018-12-13 12:06:02 +01:00
' if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL && \n '
' info->emits_changed_signal) \n '
' _ %s _schedule_emit_changed (skeleton, info, prop_id, &skeleton->priv->properties[prop_id - 1]); \n '
2018-01-04 09:56:59 +01:00
' g_value_copy (value, &skeleton->priv->properties[prop_id - 1]); \n '
' g_object_notify_by_pspec (object, pspec); \n '
' } \n '
' g_mutex_unlock (&skeleton->priv->lock); \n '
' g_object_thaw_notify (object); \n '
% ( i . camel_name , i . ns_upper , i . name_upper , len ( i . properties ) , i . name_lower , i . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static void \n '
' %s _skeleton_init ( %s Skeleton *skeleton) \n '
' { \n '
' #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38 \n '
' skeleton->priv = %s _skeleton_get_instance_private (skeleton); \n '
' #else \n '
' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %s TYPE_ %s _SKELETON, %s SkeletonPrivate); \n '
' #endif \n \n '
% ( i . name_lower , i . camel_name ,
i . name_lower ,
i . ns_upper , i . name_upper , i . camel_name ) )
self . outfile . write ( ' g_mutex_init (&skeleton->priv->lock); \n ' )
self . outfile . write ( ' skeleton->priv->context = g_main_context_ref_thread_default (); \n ' )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' skeleton->priv->properties = g_new0 (GValue, %d ); \n ' % ( len ( i . properties ) ) )
2011-04-08 22:57:31 +02:00
n = 0
for p in i . properties :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_value_init (&skeleton->priv->properties[ %d ], %s ); \n ' % ( n , p . arg . gtype ) )
2011-04-08 22:57:31 +02:00
n + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' } \n '
' \n ' )
2011-08-23 18:46:32 +02:00
# property vfuncs
n = 0
for p in i . properties :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static %s \n '
' %s _skeleton_get_ %s ( %s *object) \n '
' { \n '
% ( p . arg . ctype_in , i . name_lower , p . name_lower , i . camel_name ) )
self . outfile . write ( ' %s Skeleton *skeleton = %s %s _SKELETON (object); \n ' % ( i . camel_name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' %s value; \n '
' g_mutex_lock (&skeleton->priv->lock); \n '
' value = %s (&(skeleton->priv->properties[ %d ])); \n '
' g_mutex_unlock (&skeleton->priv->lock); \n '
% ( p . arg . ctype_in_g , p . arg . gvalue_get , n ) )
self . outfile . write ( ' return value; \n ' )
self . outfile . write ( ' } \n ' )
self . outfile . write ( ' \n ' )
2011-08-23 18:46:32 +02:00
n + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s _skeleton_class_init ( %s SkeletonClass *klass) \n '
' { \n '
' GObjectClass *gobject_class; \n '
' GDBusInterfaceSkeletonClass *skeleton_class; \n '
' \n '
' gobject_class = G_OBJECT_CLASS (klass); \n '
' gobject_class->finalize = %s _skeleton_finalize; \n '
% ( i . name_lower , i . camel_name , i . name_lower ) )
2011-04-08 22:57:31 +02:00
if len ( i . properties ) > 0 :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' gobject_class->get_property = %s _skeleton_get_property; \n '
' gobject_class->set_property = %s _skeleton_set_property; \n '
' gobject_class->notify = %s _skeleton_notify; \n '
' \n ' % ( i . name_lower , i . name_lower , i . name_lower ) )
self . outfile . write ( ' \n '
' %s _override_properties (gobject_class, 1); \n ' % ( i . name_lower ) )
self . outfile . write ( ' \n '
' skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass); \n ' ) ;
self . outfile . write ( ' skeleton_class->get_info = %s _skeleton_dbus_interface_get_info; \n ' % ( i . name_lower ) )
self . outfile . write ( ' skeleton_class->get_properties = %s _skeleton_dbus_interface_get_properties; \n ' % ( i . name_lower ) )
self . outfile . write ( ' skeleton_class->flush = %s _skeleton_dbus_interface_flush; \n ' % ( i . name_lower ) )
self . outfile . write ( ' skeleton_class->get_vtable = %s _skeleton_dbus_interface_get_vtable; \n ' % ( i . name_lower ) )
self . outfile . write ( ' \n '
' #if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38 \n '
' g_type_class_add_private (klass, sizeof ( %s SkeletonPrivate)); \n '
' #endif \n ' % ( i . camel_name ) )
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( ' static void \n '
' %s _skeleton_iface_init ( %s Iface *iface) \n '
' { \n '
% ( i . name_lower , i . camel_name ) )
2011-08-23 18:46:32 +02:00
for s in i . signals :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' iface-> %s = _ %s _on_signal_ %s ; \n '
% ( s . name_lower , i . name_lower , s . name_lower ) )
2011-08-23 18:46:32 +02:00
for p in i . properties :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' iface->get_ %s = %s _skeleton_get_ %s ; \n ' % ( p . name_lower , i . name_lower , p . name_lower ) )
self . outfile . write ( ' } \n '
' \n ' )
2011-08-23 18:46:32 +02:00
2011-04-08 22:57:31 +02:00
# constructors
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \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 '
2011-05-24 06:27:43 +02:00
% ( i . name_lower , i . name , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' %s * \n '
' %s _skeleton_new (void) \n '
' { \n '
' return %s %s (g_object_new ( %s TYPE_ %s _SKELETON, NULL)); \n '
' } \n '
' \n ' % ( i . camel_name , i . name_lower , i . ns_upper , i . name_upper , i . ns_upper , i . name_upper ) )
2011-04-08 22:57:31 +02:00
# ---------------------------------------------------------------------------------------------------
2011-04-25 15:29:18 +02:00
def generate_object ( self ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* ------------------------------------------------------------------------ \n '
' * Code for Object, ObjectProxy and ObjectSkeleton \n '
' * ------------------------------------------------------------------------ \n '
' */ \n '
' \n ' )
2011-04-25 15:29:18 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * SECTION: %s Object \n '
' * @title: %s Object \n '
' * @short_description: Specialized GDBusObject types \n '
' * \n '
' * This section contains the # %s Object, # %s ObjectProxy, and # %s ObjectSkeleton types which make it easier to work with objects implementing generated types for D-Bus interfaces. \n '
' */ \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace , self . namespace , self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s Object: \n '
' * \n '
' * The # %s Object type is a specialized container of interfaces. \n '
' */ \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s ObjectIface: \n '
' * @parent_iface: The parent interface. \n '
' * \n '
' * Virtual table for the # %s Object interface. \n '
' */ \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
self . outfile . write ( ' typedef %s ObjectIface %s ObjectInterface; \n ' % ( self . namespace , self . namespace ) )
self . outfile . write ( ' G_DEFINE_INTERFACE_WITH_CODE ( %s Object, %s object, G_TYPE_OBJECT, g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_DBUS_OBJECT);) \n ' % ( self . namespace , self . ns_lower ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' static void \n '
' %s object_default_init ( %s ObjectIface *iface) \n '
' { \n '
% ( self . ns_lower , self . namespace ) ) ;
2011-04-25 15:29:18 +02:00
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s Object: %s : \n '
' * \n '
' * The # %s instance corresponding to the D-Bus interface # %s , if any. \n '
' * \n '
' * Connect to the #GObject::notify signal to get informed of property changes. \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , i . name_hyphen , i . camel_name , i . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 2 )
2018-11-23 10:13:17 +01:00
flags = ' G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS '
if i . deprecated :
flags = ' G_PARAM_DEPRECATED | ' + flags
self . outfile . write ( ' g_object_interface_install_property (iface, g_param_spec_object ( " %s " , " %s " , " %s " , %s TYPE_ %s , %s )); \n '
2018-01-04 09:56:59 +01:00
' \n '
2018-11-23 10:13:17 +01:00
% ( i . name_hyphen , i . name_hyphen , i . name_hyphen , self . ns_upper , i . name_upper , flags ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' } \n '
' \n ' )
2011-04-25 15:29:18 +02:00
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s object_get_ %s : \n '
' * @object: A # %s Object. \n '
' * \n '
' * Gets the # %s instance for the D-Bus interface # %s on @object, if any. \n '
' * \n '
2018-12-11 00:01:36 +01:00
' * Returns: (transfer full) (nullable): A # %s that must be freed with g_object_unref() or %% NULL if @object does not implement the interface. \n '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , i . name_upper . lower ( ) , self . namespace , i . camel_name , i . name , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' %s * %s object_get_ %s ( %s Object *object) \n '
% ( i . camel_name , self . ns_lower , i . name_upper . lower ( ) , self . namespace ) )
self . outfile . write ( ' { \n '
' GDBusInterface *ret; \n '
' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), " %s " ); \n '
' if (ret == NULL) \n '
' return NULL; \n '
' return %s %s (ret); \n '
' } \n '
' \n '
% ( i . name , self . ns_upper , i . name_upper ) )
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s object_peek_ %s : (skip) \n '
' * @object: A # %s Object. \n '
' * \n '
2011-12-09 12:11:53 +01:00
' * Like %s object_get_ %s () but doesn \' t increase the reference count on the returned object. \n '
2011-04-25 15:29:18 +02:00
' * \n '
2019-12-02 17:48:32 +01:00
' * It is not safe to use the returned object if you are on another thread than the one where the #GDBusObjectManagerClient or #GDBusObjectManagerServer for @object is running. \n '
2011-04-25 15:29:18 +02:00
' * \n '
2018-12-11 00:01:36 +01:00
' * Returns: (transfer none) (nullable): A # %s or %% NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object. \n '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , i . name_upper . lower ( ) , self . namespace , self . ns_lower , i . name_upper . lower ( ) , i . camel_name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' %s * %s object_peek_ %s ( %s Object *object) \n '
% ( i . camel_name , self . ns_lower , i . name_upper . lower ( ) , self . namespace ) )
self . outfile . write ( ' { \n '
' GDBusInterface *ret; \n '
' ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), " %s " ); \n '
' if (ret == NULL) \n '
' return NULL; \n '
' g_object_unref (ret); \n '
' return %s %s (ret); \n '
' } \n '
' \n '
% ( i . name , self . ns_upper , i . name_upper ) )
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
# shared by ObjectProxy and ObjectSkeleton classes
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s object_notify (GDBusObject *object, GDBusInterface *interface) \n '
' { \n '
' _ExtendedGDBusInterfaceInfo *info = (_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface); \n '
' /* info can be NULL if the other end is using a D-Bus interface we don \' t know \n '
' * anything about, for example old generated code in this process talking to \n '
' * newer generated code in the other process. */ \n '
' if (info != NULL) \n '
' g_object_notify (G_OBJECT (object), info->hyphen_name); \n '
' } \n '
' \n '
% ( self . ns_lower ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s ObjectProxy: \n '
' * \n '
' * The # %s ObjectProxy structure contains only private data and should only be accessed using the provided API. \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s ObjectProxyClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s ObjectProxy. \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s object_proxy__ %s object_iface_init ( %s ObjectIface *iface G_GNUC_UNUSED) \n '
' { \n '
' } \n '
' \n '
% ( self . ns_lower , self . ns_lower , self . namespace ) )
self . outfile . write ( ' static void \n '
' %s object_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface) \n '
' { \n '
' iface->interface_added = %s object_notify; \n '
' iface->interface_removed = %s object_notify; \n '
' } \n '
' \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s ObjectProxy, %s object_proxy, G_TYPE_DBUS_OBJECT_PROXY, \n '
' G_IMPLEMENT_INTERFACE ( %s TYPE_OBJECT, %s object_proxy__ %s object_iface_init) \n '
' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %s object_proxy__g_dbus_object_iface_init)) \n '
' \n '
% ( self . namespace , self . ns_lower , self . ns_upper , self . ns_lower , self . ns_lower , self . ns_lower ) )
2011-04-25 15:29:18 +02:00
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s object_proxy_init ( %s ObjectProxy *object G_GNUC_UNUSED) \n '
' { \n '
' } \n '
' \n ' % ( self . ns_lower , self . namespace ) )
self . outfile . write ( ' static void \n '
' %s object_proxy_set_property (GObject *gobject, \n '
' guint prop_id, \n '
' const GValue *value G_GNUC_UNUSED, \n '
' GParamSpec *pspec) \n '
' { \n '
' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); \n '
% ( self . ns_lower ) )
self . outfile . write ( ' } \n '
' \n ' % ( ) )
self . outfile . write ( ' static void \n '
' %s object_proxy_get_property (GObject *gobject, \n '
' guint prop_id, \n '
' GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n '
' %s ObjectProxy *object = %s OBJECT_PROXY (gobject); \n '
' GDBusInterface *interface; \n '
' \n '
' switch (prop_id) \n '
' { \n '
% ( self . ns_lower , self . namespace , self . ns_upper ) )
2011-04-25 15:29:18 +02:00
n = 1
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' case %d : \n '
' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), " %s " ); \n '
' g_value_take_object (value, interface); \n '
' break; \n '
' \n '
% ( n , i . name ) )
2011-04-25 15:29:18 +02:00
n + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' default: \n '
' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); \n '
' break; \n '
' } \n '
' } \n '
' \n ' % ( ) )
self . outfile . write ( ' static void \n '
' %s object_proxy_class_init ( %s ObjectProxyClass *klass) \n '
' { \n '
' GObjectClass *gobject_class = G_OBJECT_CLASS (klass); \n '
' \n '
' gobject_class->set_property = %s object_proxy_set_property; \n '
' gobject_class->get_property = %s object_proxy_get_property; \n '
' \n '
% ( self . ns_lower , self . namespace , self . ns_lower , self . ns_lower ) )
2011-04-25 15:29:18 +02:00
n = 1
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_object_class_override_property (gobject_class, %d , " %s " ); '
' \n '
% ( n , i . name_hyphen ) )
2011-04-25 15:29:18 +02:00
n + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' } \n '
' \n ' )
2011-04-25 15:29:18 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s object_proxy_new: \n '
' * @connection: A #GDBusConnection. \n '
' * @object_path: An object path. \n '
' * \n '
' * Creates a new proxy object. \n '
' * \n '
' * Returns: (transfer full): The proxy object. \n '
' */ \n '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ObjectProxy * \n '
2011-04-25 15:29:18 +02:00
' %s object_proxy_new (GDBusConnection *connection, \n '
' const gchar *object_path) \n '
' { \n '
' g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); \n '
' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); \n '
2011-09-21 14:16:43 +02:00
' return %s OBJECT_PROXY (g_object_new ( %s TYPE_OBJECT_PROXY, " g-connection " , connection, " g-object-path " , object_path, NULL)); \n '
2011-04-25 15:29:18 +02:00
' } \n '
' \n ' % ( self . namespace , self . ns_lower , self . ns_upper , self . ns_upper ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s ObjectSkeleton: \n '
' * \n '
' * The # %s ObjectSkeleton structure contains only private data and should only be accessed using the provided API. \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . write ( ' \n ' )
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s ObjectSkeletonClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s ObjectSkeleton. \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s object_skeleton__ %s object_iface_init ( %s ObjectIface *iface G_GNUC_UNUSED) \n '
' { \n '
' } \n '
' \n '
% ( self . ns_lower , self . ns_lower , self . namespace ) )
self . outfile . write ( ' \n ' )
self . outfile . write ( ' static void \n '
' %s object_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface) \n '
' { \n '
' iface->interface_added = %s object_notify; \n '
' iface->interface_removed = %s object_notify; \n '
' } \n '
' \n '
% ( self . ns_lower , self . ns_lower , self . ns_lower ) )
self . outfile . write ( ' G_DEFINE_TYPE_WITH_CODE ( %s ObjectSkeleton, %s object_skeleton, G_TYPE_DBUS_OBJECT_SKELETON, \n '
' G_IMPLEMENT_INTERFACE ( %s TYPE_OBJECT, %s object_skeleton__ %s object_iface_init) \n '
' G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %s object_skeleton__g_dbus_object_iface_init)) \n '
' \n '
% ( self . namespace , self . ns_lower , self . ns_upper , self . ns_lower , self . ns_lower , self . ns_lower ) )
2011-04-25 15:29:18 +02:00
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s object_skeleton_init ( %s ObjectSkeleton *object G_GNUC_UNUSED) \n '
' { \n '
' } \n '
' \n ' % ( self . ns_lower , self . namespace ) )
self . outfile . write ( ' static void \n '
' %s object_skeleton_set_property (GObject *gobject, \n '
' guint prop_id, \n '
' const GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n '
' %s ObjectSkeleton *object = %s OBJECT_SKELETON (gobject); \n '
' GDBusInterfaceSkeleton *interface; \n '
' \n '
' switch (prop_id) \n '
' { \n '
% ( self . ns_lower , self . namespace , self . ns_upper ) )
2011-04-25 15:29:18 +02:00
n = 1
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' case %d : \n '
' interface = g_value_get_object (value); \n '
' if (interface != NULL) \n '
' { \n '
' g_warn_if_fail ( %s IS_ %s (interface)); \n '
' g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface); \n '
' } \n '
' else \n '
' { \n '
' g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), " %s " ); \n '
' } \n '
' break; \n '
' \n '
% ( n , self . ns_upper , i . name_upper , i . name ) )
2011-04-25 15:29:18 +02:00
n + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' default: \n '
2011-09-20 23:46:23 +02:00
' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); \n '
2011-04-25 15:29:18 +02:00
' break; \n '
' } \n '
' } \n '
' \n ' % ( ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s object_skeleton_get_property (GObject *gobject, \n '
' guint prop_id, \n '
' GValue *value, \n '
' GParamSpec *pspec) \n '
' { \n '
' %s ObjectSkeleton *object = %s OBJECT_SKELETON (gobject); \n '
' GDBusInterface *interface; \n '
' \n '
' switch (prop_id) \n '
' { \n '
% ( self . ns_lower , self . namespace , self . ns_upper ) )
2011-04-25 15:29:18 +02:00
n = 1
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' case %d : \n '
' interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), " %s " ); \n '
' g_value_take_object (value, interface); \n '
' break; \n '
' \n '
% ( n , i . name ) )
2011-04-25 15:29:18 +02:00
n + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' default: \n '
' G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); \n '
' break; \n '
' } \n '
' } \n '
' \n ' % ( ) )
self . outfile . write ( ' static void \n '
' %s object_skeleton_class_init ( %s ObjectSkeletonClass *klass) \n '
' { \n '
' GObjectClass *gobject_class = G_OBJECT_CLASS (klass); \n '
' \n '
' gobject_class->set_property = %s object_skeleton_set_property; \n '
' gobject_class->get_property = %s object_skeleton_get_property; \n '
' \n '
% ( self . ns_lower , self . namespace , self . ns_lower , self . ns_lower ) )
2011-04-25 15:29:18 +02:00
n = 1
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_object_class_override_property (gobject_class, %d , " %s " ); '
' \n '
% ( n , i . name_hyphen ) )
2011-04-25 15:29:18 +02:00
n + = 1
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' } \n '
' \n ' )
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s object_skeleton_new: \n '
' * @object_path: An object path. \n '
' * \n '
' * Creates a new skeleton object. \n '
' * \n '
' * Returns: (transfer full): The skeleton object. \n '
' */ \n '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' %s ObjectSkeleton * \n '
' %s object_skeleton_new (const gchar *object_path) \n '
' { \n '
' g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); \n '
' return %s OBJECT_SKELETON (g_object_new ( %s TYPE_OBJECT_SKELETON, " g-object-path " , object_path, NULL)); \n '
' } \n '
' \n ' % ( self . namespace , self . ns_lower , self . ns_upper , self . ns_upper ) )
2011-04-25 15:29:18 +02:00
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-25 15:29:18 +02:00
' /** \n '
' * %s object_skeleton_set_ %s : \n '
' * @object: A # %s ObjectSkeleton. \n '
2017-11-17 12:42:48 +01:00
' * @interface_: (nullable): A # %s or %% NULL to clear the interface. \n '
2011-04-25 15:29:18 +02:00
' * \n '
' * Sets the # %s instance for the D-Bus interface # %s on @object. \n '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , i . name_upper . lower ( ) , self . namespace , i . camel_name , i . camel_name , i . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . write_gtkdoc_deprecated_and_since_and_close ( i , self . outfile , 0 )
self . outfile . write ( ' void %s object_skeleton_set_ %s ( %s ObjectSkeleton *object, %s *interface_) \n '
% ( self . ns_lower , i . name_upper . lower ( ) , self . namespace , i . camel_name ) )
self . outfile . write ( ' { \n '
' g_object_set (G_OBJECT (object), " %s " , interface_, NULL); \n '
' } \n '
' \n '
% ( i . name_hyphen ) )
self . outfile . write ( ' \n ' )
2011-04-25 15:29:18 +02:00
2011-04-08 22:57:31 +02:00
def generate_object_manager_client ( self ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* ------------------------------------------------------------------------ \n '
' * Code for ObjectManager client \n '
' * ------------------------------------------------------------------------ \n '
' */ \n '
' \n ' )
2011-04-08 22:57:31 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-19 20:39:47 +02:00
' /** \n '
' * SECTION: %s ObjectManagerClient \n '
' * @title: %s ObjectManagerClient \n '
2011-04-25 15:29:18 +02:00
' * @short_description: Generated GDBusObjectManagerClient type \n '
2011-04-19 20:39:47 +02:00
' * \n '
' * This section contains a #GDBusObjectManagerClient that uses %s object_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. \n '
' */ \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace , self . ns_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-19 20:39:47 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-19 19:16:10 +02:00
' /** \n '
' * %s ObjectManagerClient: \n '
' * \n '
' * The # %s ObjectManagerClient structure contains only private data and should only be accessed using the provided API. \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . write ( ' \n ' )
2011-04-19 19:16:10 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-19 19:16:10 +02:00
' /** \n '
' * %s ObjectManagerClientClass: \n '
' * @parent_class: The parent class. \n '
' * \n '
' * Class structure for # %s ObjectManagerClient. \n '
2011-05-24 06:27:43 +02:00
% ( self . namespace , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . write ( ' \n ' )
2011-04-19 19:16:10 +02:00
2011-04-08 22:57:31 +02:00
# class boilerplate
2018-01-04 09:56:59 +01:00
self . outfile . 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
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' static void \n '
' %s object_manager_client_init ( %s ObjectManagerClient *manager G_GNUC_UNUSED) \n '
' { \n '
' } \n '
' \n ' % ( self . ns_lower , self . namespace ) )
self . outfile . write ( ' static void \n '
' %s object_manager_client_class_init ( %s ObjectManagerClientClass *klass G_GNUC_UNUSED) \n '
' { \n '
' } \n '
' \n ' % ( self . ns_lower , self . namespace ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s object_manager_client_get_proxy_type: \n '
' * @manager: A #GDBusObjectManagerClient. \n '
' * @object_path: The object path of the remote object (unused). \n '
2017-11-17 12:42:48 +01:00
' * @interface_name: (nullable): Interface name of the remote object or %% NULL to get the object proxy #GType. \n '
2011-04-18 20:23:19 +02:00
' * @user_data: User data (unused). \n '
' * \n '
2017-11-29 18:50:27 +01:00
' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy derived and #GDBusProxy derived types. \n '
2011-04-19 19:10:25 +02:00
' * \n '
2017-11-29 18:50:27 +01:00
' * Returns: A #GDBusProxy derived #GType if @interface_name is not %% NULL, otherwise the #GType for # %s ObjectProxy. \n '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . write ( ' GType \n '
' %s object_manager_client_get_proxy_type (GDBusObjectManagerClient *manager G_GNUC_UNUSED, const gchar *object_path G_GNUC_UNUSED, const gchar *interface_name, gpointer user_data G_GNUC_UNUSED) \n '
' { \n '
% ( self . ns_lower ) )
self . outfile . write ( ' static gsize once_init_value = 0; \n '
' static GHashTable *lookup_hash; \n '
' GType ret; \n '
' \n '
' if (interface_name == NULL) \n '
' return %s TYPE_OBJECT_PROXY; \n '
' if (g_once_init_enter (&once_init_value)) \n '
' { \n '
' lookup_hash = g_hash_table_new (g_str_hash, g_str_equal); \n '
% ( self . ns_upper ) )
2011-04-08 22:57:31 +02:00
for i in self . ifaces :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' g_hash_table_insert (lookup_hash, (gpointer) " %s " , GSIZE_TO_POINTER ( %s TYPE_ %s _PROXY)); \n '
% ( i . name , i . ns_upper , i . name_upper ) )
self . outfile . write ( ' g_once_init_leave (&once_init_value, 1); \n '
' } \n ' )
self . outfile . 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 . outfile . write ( ' return ret; \n '
' } \n '
' \n ' )
2011-04-08 22:57:31 +02:00
# constructors
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s object_manager_client_new: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. \n '
2017-11-17 12:42:48 +01:00
' * @name: (nullable): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
2011-04-18 20:23:19 +02:00
' * @object_path: An object path. \n '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2019-12-02 17:47:44 +01:00
' * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from (see g_main_context_push_thread_default()). \n '
2011-04-18 20:23:19 +02:00
' * 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 '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . ns_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . 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 '
' 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 '
' } \n '
' \n '
% ( self . ns_lower , self . ns_upper , self . ns_lower ) )
self . outfile . write ( ' /** \n '
' * %s object_manager_client_new_finish: \n '
' * @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 '
' * \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 ) )
self . outfile . write ( ' */ \n ' )
self . outfile . 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 ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \n '
' * %s object_manager_client_new_sync: \n '
' * @connection: A #GDBusConnection. \n '
' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration. \n '
2017-11-17 12:42:48 +01:00
' * @name: (nullable): A bus name (well-known or unique) or %% NULL if @connection is not a message bus connection. \n '
2011-04-18 20:23:19 +02:00
' * @object_path: An object path. \n '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . 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 '
' 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 '
' 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 . outfile . write ( ' \n ' )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \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 '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2019-12-02 17:47:44 +01:00
' * When the operation is finished, @callback will be invoked in the thread-default main loop of the thread you are calling this method from (see g_main_context_push_thread_default()). \n '
2011-04-18 20:23:19 +02:00
' * 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 '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . ns_lower ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . 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 '
' 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 '
' } \n '
' \n '
% ( self . ns_lower , self . ns_upper , self . ns_lower ) )
self . outfile . write ( ' /** \n '
' * %s object_manager_client_new_for_bus_finish: \n '
' * @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 '
' * \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 ) )
self . outfile . write ( ' */ \n ' )
self . outfile . 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 ) )
self . outfile . write ( self . docbook_gen . expand (
2011-04-18 20:23:19 +02:00
' /** \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 '
2017-11-17 12:42:48 +01:00
' * @cancellable: (nullable): A #GCancellable or %% NULL. \n '
2011-04-18 20:23:19 +02:00
' * @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 '
2011-05-24 06:27:43 +02:00
% ( self . ns_lower , self . ns_lower , self . ns_lower , self . namespace ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' */ \n ' )
self . outfile . 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 '
' 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 '
' 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 . outfile . write ( ' \n ' )
2011-04-08 22:57:31 +02:00
# ---------------------------------------------------------------------------------------------------
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 :
2018-01-12 08:55:36 +01:00
print_error ( ' Cannot handle object " {} " ' . format ( obj ) )
2011-04-18 20:23:19 +02:00
f . write ( self . docbook_gen . expand (
' %*s * \n '
' %*s * Deprecated: %s has been deprecated. \n '
2011-05-24 06:27:43 +02:00
% ( indent , ' ' , indent , ' ' , thing ) , False ) )
2011-04-18 20:23:19 +02:00
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 ) :
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' /* ------------------------------------------------------------------------ \n '
' * Code for interface %s \n '
' * ------------------------------------------------------------------------ \n '
' */ \n '
' \n ' % ( i . name ) )
2011-04-19 20:39:47 +02:00
2018-01-04 09:56:59 +01:00
self . outfile . write ( self . docbook_gen . expand (
2011-04-19 20:39:47 +02:00
' /** \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 '
2011-05-24 06:27:43 +02:00
% ( i . camel_name , i . camel_name , i . name , i . name ) , False ) )
2018-01-04 09:56:59 +01:00
self . outfile . write ( ' \n ' )
2011-04-19 20:39:47 +02:00
2011-04-08 22:57:31 +02:00
def generate ( self ) :
2018-01-03 17:10:54 +01:00
self . generate_body_preamble ( )
2011-04-08 22:57:31 +02:00
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 :
2011-04-25 15:29:18 +02:00
self . generate_object ( )
2011-04-12 17:50:34 +02:00
self . generate_object_manager_client ( )