source: appstream-generator/build/girepo/gio/DBusProxy.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 32.6 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.DBusProxy;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.AsyncInitableIF;
26private import gio.AsyncInitableT;
27private import gio.AsyncResultIF;
28private import gio.Cancellable;
29private import gio.DBusConnection;
30private import gio.DBusInterfaceIF;
31private import gio.DBusInterfaceInfo;
32private import gio.DBusInterfaceT;
33private import gio.InitableIF;
34private import gio.InitableT;
35private import gio.UnixFDList;
36private import glib.ConstructionException;
37private import glib.ErrorG;
38private import glib.GException;
39private import glib.Str;
40private import glib.Variant;
41private import gobject.ObjectG;
42private import gobject.Signals;
43private import std.algorithm;
44
45
46/**
47 * #GDBusProxy is a base class used for proxies to access a D-Bus
48 * interface on a remote object. A #GDBusProxy can be constructed for
49 * both well-known and unique names.
50 *
51 * By default, #GDBusProxy will cache all properties (and listen to
52 * changes) of the remote object, and proxy all signals that gets
53 * emitted. This behaviour can be changed by passing suitable
54 * #GDBusProxyFlags when the proxy is created. If the proxy is for a
55 * well-known name, the property cache is flushed when the name owner
56 * vanishes and reloaded when a name owner appears.
57 *
58 * If a #GDBusProxy is used for a well-known name, the owner of the
59 * name is tracked and can be read from
60 * #GDBusProxy:g-name-owner. Connect to the #GObject::notify signal to
61 * get notified of changes. Additionally, only signals and property
62 * changes emitted from the current name owner are considered and
63 * calls are always sent to the current name owner. This avoids a
64 * number of race conditions when the name is lost by one owner and
65 * claimed by another. However, if no name owner currently exists,
66 * then calls will be sent to the well-known name which may result in
67 * the message bus launching an owner (unless
68 * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START is set).
69 *
70 * The generic #GDBusProxy::g-properties-changed and
71 * #GDBusProxy::g-signal signals are not very convenient to work with.
72 * Therefore, the recommended way of working with proxies is to subclass
73 * #GDBusProxy, and have more natural properties and signals in your derived
74 * class. This [example][gdbus-example-gdbus-codegen] shows how this can
75 * easily be done using the [gdbus-codegen][gdbus-codegen] tool.
76 *
77 * A #GDBusProxy instance can be used from multiple threads but note
78 * that all signals (e.g. #GDBusProxy::g-signal, #GDBusProxy::g-properties-changed
79 * and #GObject::notify) are emitted in the
80 * [thread-default main context][g-main-context-push-thread-default]
81 * of the thread where the instance was constructed.
82 *
83 * An example using a proxy for a well-known name can be found in
84 * [gdbus-example-watch-proxy.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-watch-proxy.c)
85 *
86 * Since: 2.26
87 */
88public class DBusProxy : ObjectG, AsyncInitableIF, DBusInterfaceIF, InitableIF
89{
90        /** the main Gtk struct */
91        protected GDBusProxy* gDBusProxy;
92
93        /** Get the main Gtk struct */
94        public GDBusProxy* getDBusProxyStruct()
95        {
96                return gDBusProxy;
97        }
98
99        /** the main Gtk struct as a void* */
100        protected override void* getStruct()
101        {
102                return cast(void*)gDBusProxy;
103        }
104
105        protected override void setStruct(GObject* obj)
106        {
107                gDBusProxy = cast(GDBusProxy*)obj;
108                super.setStruct(obj);
109        }
110
111        /**
112         * Sets our main struct and passes it to the parent class.
113         */
114        public this (GDBusProxy* gDBusProxy, bool ownedRef = false)
115        {
116                this.gDBusProxy = gDBusProxy;
117                super(cast(GObject*)gDBusProxy, ownedRef);
118        }
119
120        // add the AsyncInitable capabilities
121        mixin AsyncInitableT!(GDBusProxy);
122
123        // add the DBusInterface capabilities
124        mixin DBusInterfaceT!(GDBusProxy);
125
126        // add the Initable capabilities
127        mixin InitableT!(GDBusProxy);
128
129        /**
130         * Finishes creating a GDBusProxy.
131         *
132         * Params:
133         *     res    = A GAsyncResult obtained from the GAsyncReadyCallback
134         *              function passed to g_dbus_proxy_new().
135         *     forBus = If true finish an address.
136         *
137         * Throws: GException on failure.
138         * Throws: ConstructionException GTK+ fails to create the object.
139         *
140         * Since: 2.26
141         */
142        public this (AsyncResultIF res, bool forBus = false)
143        {
144                GError* err = null;
145                GDBusProxy* p;
146               
147                if ( forBus )
148                {
149                        p = g_dbus_proxy_new_for_bus_finish((res is null) ? null : res.getAsyncResultStruct(), &err);
150                }
151                else
152                {
153                        p = g_dbus_proxy_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err);
154                }
155               
156                if (err !is null)
157                {
158                        throw new GException( new ErrorG(err) );
159                }
160               
161                if(p is null)
162                {
163                        throw new ConstructionException("null returned by g_dbus_proxy_new_finish((res is null) ? null : res.getAsyncResultStruct(), &err)");
164                }
165                this(p, true);
166        }
167
168        /**
169         */
170
171        /** */
172        public static GType getType()
173        {
174                return g_dbus_proxy_get_type();
175        }
176
177        /**
178         * Like g_dbus_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.
179         *
180         * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
181         *
182         * Params:
183         *     busType = A #GBusType.
184         *     flags = Flags used when constructing the proxy.
185         *     info = A #GDBusInterfaceInfo specifying the minimal interface
186         *         that @proxy conforms to or %NULL.
187         *     name = A bus name (well-known or unique).
188         *     objectPath = An object path.
189         *     interfaceName = A D-Bus interface name.
190         *     cancellable = A #GCancellable or %NULL.
191         *
192         * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
193         *
194         * Since: 2.26
195         *
196         * Throws: GException on failure.
197         * Throws: ConstructionException GTK+ fails to create the object.
198         */
199        public this(GBusType busType, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable)
200        {
201                GError* err = null;
202               
203                auto p = g_dbus_proxy_new_for_bus_sync(busType, flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
204               
205                if (err !is null)
206                {
207                        throw new GException( new ErrorG(err) );
208                }
209               
210                if(p is null)
211                {
212                        throw new ConstructionException("null returned by new_for_bus_sync");
213                }
214               
215                this(cast(GDBusProxy*) p, true);
216        }
217
218        /**
219         * Creates a proxy for accessing @interface_name on the remote object
220         * at @object_path owned by @name at @connection and synchronously
221         * loads D-Bus properties unless the
222         * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used.
223         *
224         * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
225         * match rules for signals. Connect to the #GDBusProxy::g-signal signal
226         * to handle signals from the remote object.
227         *
228         * If @name is a well-known name and the
229         * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION
230         * flags aren't set and no name owner currently exists, the message bus
231         * will be requested to launch a name owner for the name.
232         *
233         * This is a synchronous failable constructor. See g_dbus_proxy_new()
234         * and g_dbus_proxy_new_finish() for the asynchronous version.
235         *
236         * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
237         *
238         * Params:
239         *     connection = A #GDBusConnection.
240         *     flags = Flags used when constructing the proxy.
241         *     info = A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
242         *     name = A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
243         *     objectPath = An object path.
244         *     interfaceName = A D-Bus interface name.
245         *     cancellable = A #GCancellable or %NULL.
246         *
247         * Returns: A #GDBusProxy or %NULL if error is set. Free with g_object_unref().
248         *
249         * Since: 2.26
250         *
251         * Throws: GException on failure.
252         * Throws: ConstructionException GTK+ fails to create the object.
253         */
254        public this(DBusConnection connection, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable)
255        {
256                GError* err = null;
257               
258                auto p = g_dbus_proxy_new_sync((connection is null) ? null : connection.getDBusConnectionStruct(), flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
259               
260                if (err !is null)
261                {
262                        throw new GException( new ErrorG(err) );
263                }
264               
265                if(p is null)
266                {
267                        throw new ConstructionException("null returned by new_sync");
268                }
269               
270                this(cast(GDBusProxy*) p, true);
271        }
272
273        /**
274         * Creates a proxy for accessing @interface_name on the remote object
275         * at @object_path owned by @name at @connection and asynchronously
276         * loads D-Bus properties unless the
277         * %G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. Connect to
278         * the #GDBusProxy::g-properties-changed signal to get notified about
279         * property changes.
280         *
281         * If the %G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS flag is not set, also sets up
282         * match rules for signals. Connect to the #GDBusProxy::g-signal signal
283         * to handle signals from the remote object.
284         *
285         * If @name is a well-known name and the
286         * %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START and %G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION
287         * flags aren't set and no name owner currently exists, the message bus
288         * will be requested to launch a name owner for the name.
289         *
290         * This is a failable asynchronous constructor - when the proxy is
291         * ready, @callback will be invoked and you can use
292         * g_dbus_proxy_new_finish() to get the result.
293         *
294         * See g_dbus_proxy_new_sync() and for a synchronous version of this constructor.
295         *
296         * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
297         *
298         * Params:
299         *     connection = A #GDBusConnection.
300         *     flags = Flags used when constructing the proxy.
301         *     info = A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
302         *     name = A bus name (well-known or unique) or %NULL if @connection is not a message bus connection.
303         *     objectPath = An object path.
304         *     interfaceName = A D-Bus interface name.
305         *     cancellable = A #GCancellable or %NULL.
306         *     callback = Callback function to invoke when the proxy is ready.
307         *     userData = User data to pass to @callback.
308         *
309         * Since: 2.26
310         */
311        public static void newProxy(DBusConnection connection, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
312        {
313                g_dbus_proxy_new((connection is null) ? null : connection.getDBusConnectionStruct(), flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
314        }
315
316        /**
317         * Like g_dbus_proxy_new() but takes a #GBusType instead of a #GDBusConnection.
318         *
319         * #GDBusProxy is used in this [example][gdbus-wellknown-proxy].
320         *
321         * Params:
322         *     busType = A #GBusType.
323         *     flags = Flags used when constructing the proxy.
324         *     info = A #GDBusInterfaceInfo specifying the minimal interface that @proxy conforms to or %NULL.
325         *     name = A bus name (well-known or unique).
326         *     objectPath = An object path.
327         *     interfaceName = A D-Bus interface name.
328         *     cancellable = A #GCancellable or %NULL.
329         *     callback = Callback function to invoke when the proxy is ready.
330         *     userData = User data to pass to @callback.
331         *
332         * Since: 2.26
333         */
334        public static void newForBus(GBusType busType, GDBusProxyFlags flags, DBusInterfaceInfo info, string name, string objectPath, string interfaceName, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
335        {
336                g_dbus_proxy_new_for_bus(busType, flags, (info is null) ? null : info.getDBusInterfaceInfoStruct(), Str.toStringz(name), Str.toStringz(objectPath), Str.toStringz(interfaceName), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
337        }
338
339        /**
340         * Asynchronously invokes the @method_name method on @proxy.
341         *
342         * If @method_name contains any dots, then @name is split into interface and
343         * method name parts. This allows using @proxy for invoking methods on
344         * other interfaces.
345         *
346         * If the #GDBusConnection associated with @proxy is closed then
347         * the operation will fail with %G_IO_ERROR_CLOSED. If
348         * @cancellable is canceled, the operation will fail with
349         * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
350         * compatible with the D-Bus protocol, the operation fails with
351         * %G_IO_ERROR_INVALID_ARGUMENT.
352         *
353         * If the @parameters #GVariant is floating, it is consumed. This allows
354         * convenient 'inline' use of g_variant_new(), e.g.:
355         * |[<!-- language="C" -->
356         * g_dbus_proxy_call (proxy,
357         * "TwoStrings",
358         * g_variant_new ("(ss)",
359         * "Thing One",
360         * "Thing Two"),
361         * G_DBUS_CALL_FLAGS_NONE,
362         * -1,
363         * NULL,
364         * (GAsyncReadyCallback) two_strings_done,
365         * &data);
366         * ]|
367         *
368         * If @proxy has an expected interface (see
369         * #GDBusProxy:g-interface-info) and @method_name is referenced by it,
370         * then the return value is checked against the return type.
371         *
372         * This is an asynchronous method. When the operation is finished,
373         * @callback will be invoked in the
374         * [thread-default main context][g-main-context-push-thread-default]
375         * of the thread you are calling this method from.
376         * You can then call g_dbus_proxy_call_finish() to get the result of
377         * the operation. See g_dbus_proxy_call_sync() for the synchronous
378         * version of this method.
379         *
380         * If @callback is %NULL then the D-Bus method call message will be sent with
381         * the %G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED flag set.
382         *
383         * Params:
384         *     methodName = Name of method to invoke.
385         *     parameters = A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
386         *     flags = Flags from the #GDBusCallFlags enumeration.
387         *     timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning
388         *         "infinite") or -1 to use the proxy default timeout.
389         *     cancellable = A #GCancellable or %NULL.
390         *     callback = A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
391         *         care about the result of the method invocation.
392         *     userData = The data to pass to @callback.
393         *
394         * Since: 2.26
395         */
396        public void call(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
397        {
398                g_dbus_proxy_call(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
399        }
400
401        /**
402         * Finishes an operation started with g_dbus_proxy_call().
403         *
404         * Params:
405         *     res = A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call().
406         *
407         * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
408         *     return values. Free with g_variant_unref().
409         *
410         * Since: 2.26
411         *
412         * Throws: GException on failure.
413         */
414        public Variant callFinish(AsyncResultIF res)
415        {
416                GError* err = null;
417               
418                auto p = g_dbus_proxy_call_finish(gDBusProxy, (res is null) ? null : res.getAsyncResultStruct(), &err);
419               
420                if (err !is null)
421                {
422                        throw new GException( new ErrorG(err) );
423                }
424               
425                if(p is null)
426                {
427                        return null;
428                }
429               
430                return new Variant(cast(GVariant*) p, true);
431        }
432
433        /**
434         * Synchronously invokes the @method_name method on @proxy.
435         *
436         * If @method_name contains any dots, then @name is split into interface and
437         * method name parts. This allows using @proxy for invoking methods on
438         * other interfaces.
439         *
440         * If the #GDBusConnection associated with @proxy is disconnected then
441         * the operation will fail with %G_IO_ERROR_CLOSED. If
442         * @cancellable is canceled, the operation will fail with
443         * %G_IO_ERROR_CANCELLED. If @parameters contains a value not
444         * compatible with the D-Bus protocol, the operation fails with
445         * %G_IO_ERROR_INVALID_ARGUMENT.
446         *
447         * If the @parameters #GVariant is floating, it is consumed. This allows
448         * convenient 'inline' use of g_variant_new(), e.g.:
449         * |[<!-- language="C" -->
450         * g_dbus_proxy_call_sync (proxy,
451         * "TwoStrings",
452         * g_variant_new ("(ss)",
453         * "Thing One",
454         * "Thing Two"),
455         * G_DBUS_CALL_FLAGS_NONE,
456         * -1,
457         * NULL,
458         * &error);
459         * ]|
460         *
461         * The calling thread is blocked until a reply is received. See
462         * g_dbus_proxy_call() for the asynchronous version of this
463         * method.
464         *
465         * If @proxy has an expected interface (see
466         * #GDBusProxy:g-interface-info) and @method_name is referenced by it,
467         * then the return value is checked against the return type.
468         *
469         * Params:
470         *     methodName = Name of method to invoke.
471         *     parameters = A #GVariant tuple with parameters for the signal
472         *         or %NULL if not passing parameters.
473         *     flags = Flags from the #GDBusCallFlags enumeration.
474         *     timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning
475         *         "infinite") or -1 to use the proxy default timeout.
476         *     cancellable = A #GCancellable or %NULL.
477         *
478         * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
479         *     return values. Free with g_variant_unref().
480         *
481         * Since: 2.26
482         *
483         * Throws: GException on failure.
484         */
485        public Variant callSync(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, Cancellable cancellable)
486        {
487                GError* err = null;
488               
489                auto p = g_dbus_proxy_call_sync(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
490               
491                if (err !is null)
492                {
493                        throw new GException( new ErrorG(err) );
494                }
495               
496                if(p is null)
497                {
498                        return null;
499                }
500               
501                return new Variant(cast(GVariant*) p, true);
502        }
503
504        /**
505         * Like g_dbus_proxy_call() but also takes a #GUnixFDList object.
506         *
507         * This method is only available on UNIX.
508         *
509         * Params:
510         *     methodName = Name of method to invoke.
511         *     parameters = A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
512         *     flags = Flags from the #GDBusCallFlags enumeration.
513         *     timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning
514         *         "infinite") or -1 to use the proxy default timeout.
515         *     fdList = A #GUnixFDList or %NULL.
516         *     cancellable = A #GCancellable or %NULL.
517         *     callback = A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
518         *         care about the result of the method invocation.
519         *     userData = The data to pass to @callback.
520         *
521         * Since: 2.30
522         */
523        public void callWithUnixFdList(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, UnixFDList fdList, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
524        {
525                g_dbus_proxy_call_with_unix_fd_list(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (fdList is null) ? null : fdList.getUnixFDListStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
526        }
527
528        /**
529         * Finishes an operation started with g_dbus_proxy_call_with_unix_fd_list().
530         *
531         * Params:
532         *     outFdList = Return location for a #GUnixFDList or %NULL.
533         *     res = A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_proxy_call_with_unix_fd_list().
534         *
535         * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
536         *     return values. Free with g_variant_unref().
537         *
538         * Since: 2.30
539         *
540         * Throws: GException on failure.
541         */
542        public Variant callWithUnixFdListFinish(out UnixFDList outFdList, AsyncResultIF res)
543        {
544                GUnixFDList* outoutFdList = null;
545                GError* err = null;
546               
547                auto p = g_dbus_proxy_call_with_unix_fd_list_finish(gDBusProxy, &outoutFdList, (res is null) ? null : res.getAsyncResultStruct(), &err);
548               
549                if (err !is null)
550                {
551                        throw new GException( new ErrorG(err) );
552                }
553               
554                outFdList = ObjectG.getDObject!(UnixFDList)(outoutFdList);
555               
556                if(p is null)
557                {
558                        return null;
559                }
560               
561                return new Variant(cast(GVariant*) p, true);
562        }
563
564        /**
565         * Like g_dbus_proxy_call_sync() but also takes and returns #GUnixFDList objects.
566         *
567         * This method is only available on UNIX.
568         *
569         * Params:
570         *     methodName = Name of method to invoke.
571         *     parameters = A #GVariant tuple with parameters for the signal
572         *         or %NULL if not passing parameters.
573         *     flags = Flags from the #GDBusCallFlags enumeration.
574         *     timeoutMsec = The timeout in milliseconds (with %G_MAXINT meaning
575         *         "infinite") or -1 to use the proxy default timeout.
576         *     fdList = A #GUnixFDList or %NULL.
577         *     outFdList = Return location for a #GUnixFDList or %NULL.
578         *     cancellable = A #GCancellable or %NULL.
579         *
580         * Returns: %NULL if @error is set. Otherwise a #GVariant tuple with
581         *     return values. Free with g_variant_unref().
582         *
583         * Since: 2.30
584         *
585         * Throws: GException on failure.
586         */
587        public Variant callWithUnixFdListSync(string methodName, Variant parameters, GDBusCallFlags flags, int timeoutMsec, UnixFDList fdList, out UnixFDList outFdList, Cancellable cancellable)
588        {
589                GUnixFDList* outoutFdList = null;
590                GError* err = null;
591               
592                auto p = g_dbus_proxy_call_with_unix_fd_list_sync(gDBusProxy, Str.toStringz(methodName), (parameters is null) ? null : parameters.getVariantStruct(), flags, timeoutMsec, (fdList is null) ? null : fdList.getUnixFDListStruct(), &outoutFdList, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
593               
594                if (err !is null)
595                {
596                        throw new GException( new ErrorG(err) );
597                }
598               
599                outFdList = ObjectG.getDObject!(UnixFDList)(outoutFdList);
600               
601                if(p is null)
602                {
603                        return null;
604                }
605               
606                return new Variant(cast(GVariant*) p, true);
607        }
608
609        /**
610         * Looks up the value for a property from the cache. This call does no
611         * blocking IO.
612         *
613         * If @proxy has an expected interface (see
614         * #GDBusProxy:g-interface-info) and @property_name is referenced by
615         * it, then @value is checked against the type of the property.
616         *
617         * Params:
618         *     propertyName = Property name.
619         *
620         * Returns: A reference to the #GVariant instance that holds the value
621         *     for @property_name or %NULL if the value is not in the cache. The
622         *     returned reference must be freed with g_variant_unref().
623         *
624         * Since: 2.26
625         */
626        public Variant getCachedProperty(string propertyName)
627        {
628                auto p = g_dbus_proxy_get_cached_property(gDBusProxy, Str.toStringz(propertyName));
629               
630                if(p is null)
631                {
632                        return null;
633                }
634               
635                return new Variant(cast(GVariant*) p, true);
636        }
637
638        /**
639         * Gets the names of all cached properties on @proxy.
640         *
641         * Returns: A %NULL-terminated array of strings or %NULL if
642         *     @proxy has no cached properties. Free the returned array with
643         *     g_strfreev().
644         *
645         * Since: 2.26
646         */
647        public string[] getCachedPropertyNames()
648        {
649                auto retStr = g_dbus_proxy_get_cached_property_names(gDBusProxy);
650               
651                scope(exit) Str.freeStringArray(retStr);
652                return Str.toStringArray(retStr);
653        }
654
655        /**
656         * Gets the connection @proxy is for.
657         *
658         * Returns: A #GDBusConnection owned by @proxy. Do not free.
659         *
660         * Since: 2.26
661         */
662        public DBusConnection getConnection()
663        {
664                auto p = g_dbus_proxy_get_connection(gDBusProxy);
665               
666                if(p is null)
667                {
668                        return null;
669                }
670               
671                return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p);
672        }
673
674        /**
675         * Gets the timeout to use if -1 (specifying default timeout) is
676         * passed as @timeout_msec in the g_dbus_proxy_call() and
677         * g_dbus_proxy_call_sync() functions.
678         *
679         * See the #GDBusProxy:g-default-timeout property for more details.
680         *
681         * Returns: Timeout to use for @proxy.
682         *
683         * Since: 2.26
684         */
685        public int getDefaultTimeout()
686        {
687                return g_dbus_proxy_get_default_timeout(gDBusProxy);
688        }
689
690        /**
691         * Gets the flags that @proxy was constructed with.
692         *
693         * Returns: Flags from the #GDBusProxyFlags enumeration.
694         *
695         * Since: 2.26
696         */
697        public GDBusProxyFlags getFlags()
698        {
699                return g_dbus_proxy_get_flags(gDBusProxy);
700        }
701
702        /**
703         * Returns the #GDBusInterfaceInfo, if any, specifying the interface
704         * that @proxy conforms to. See the #GDBusProxy:g-interface-info
705         * property for more details.
706         *
707         * Returns: A #GDBusInterfaceInfo or %NULL. Do not unref the returned
708         *     object, it is owned by @proxy.
709         *
710         * Since: 2.26
711         */
712        public DBusInterfaceInfo getInterfaceInfo()
713        {
714                auto p = g_dbus_proxy_get_interface_info(gDBusProxy);
715               
716                if(p is null)
717                {
718                        return null;
719                }
720               
721                return ObjectG.getDObject!(DBusInterfaceInfo)(cast(GDBusInterfaceInfo*) p, true);
722        }
723
724        /**
725         * Gets the D-Bus interface name @proxy is for.
726         *
727         * Returns: A string owned by @proxy. Do not free.
728         *
729         * Since: 2.26
730         */
731        public string getInterfaceName()
732        {
733                return Str.toString(g_dbus_proxy_get_interface_name(gDBusProxy));
734        }
735
736        /**
737         * Gets the name that @proxy was constructed for.
738         *
739         * Returns: A string owned by @proxy. Do not free.
740         *
741         * Since: 2.26
742         */
743        public string getName()
744        {
745                return Str.toString(g_dbus_proxy_get_name(gDBusProxy));
746        }
747
748        /**
749         * The unique name that owns the name that @proxy is for or %NULL if
750         * no-one currently owns that name. You may connect to the
751         * #GObject::notify signal to track changes to the
752         * #GDBusProxy:g-name-owner property.
753         *
754         * Returns: The name owner or %NULL if no name owner exists. Free with g_free().
755         *
756         * Since: 2.26
757         */
758        public string getNameOwner()
759        {
760                auto retStr = g_dbus_proxy_get_name_owner(gDBusProxy);
761               
762                scope(exit) Str.freeString(retStr);
763                return Str.toString(retStr);
764        }
765
766        /**
767         * Gets the object path @proxy is for.
768         *
769         * Returns: A string owned by @proxy. Do not free.
770         *
771         * Since: 2.26
772         */
773        public string getObjectPath()
774        {
775                return Str.toString(g_dbus_proxy_get_object_path(gDBusProxy));
776        }
777
778        /**
779         * If @value is not %NULL, sets the cached value for the property with
780         * name @property_name to the value in @value.
781         *
782         * If @value is %NULL, then the cached value is removed from the
783         * property cache.
784         *
785         * If @proxy has an expected interface (see
786         * #GDBusProxy:g-interface-info) and @property_name is referenced by
787         * it, then @value is checked against the type of the property.
788         *
789         * If the @value #GVariant is floating, it is consumed. This allows
790         * convenient 'inline' use of g_variant_new(), e.g.
791         * |[<!-- language="C" -->
792         * g_dbus_proxy_set_cached_property (proxy,
793         * "SomeProperty",
794         * g_variant_new ("(si)",
795         * "A String",
796         * 42));
797         * ]|
798         *
799         * Normally you will not need to use this method since @proxy
800         * is tracking changes using the
801         * `org.freedesktop.DBus.Properties.PropertiesChanged`
802         * D-Bus signal. However, for performance reasons an object may
803         * decide to not use this signal for some properties and instead
804         * use a proprietary out-of-band mechanism to transmit changes.
805         *
806         * As a concrete example, consider an object with a property
807         * `ChatroomParticipants` which is an array of strings. Instead of
808         * transmitting the same (long) array every time the property changes,
809         * it is more efficient to only transmit the delta using e.g. signals
810         * `ChatroomParticipantJoined(String name)` and
811         * `ChatroomParticipantParted(String name)`.
812         *
813         * Params:
814         *     propertyName = Property name.
815         *     value = Value for the property or %NULL to remove it from the cache.
816         *
817         * Since: 2.26
818         */
819        public void setCachedProperty(string propertyName, Variant value)
820        {
821                g_dbus_proxy_set_cached_property(gDBusProxy, Str.toStringz(propertyName), (value is null) ? null : value.getVariantStruct());
822        }
823
824        /**
825         * Sets the timeout to use if -1 (specifying default timeout) is
826         * passed as @timeout_msec in the g_dbus_proxy_call() and
827         * g_dbus_proxy_call_sync() functions.
828         *
829         * See the #GDBusProxy:g-default-timeout property for more details.
830         *
831         * Params:
832         *     timeoutMsec = Timeout in milliseconds.
833         *
834         * Since: 2.26
835         */
836        public void setDefaultTimeout(int timeoutMsec)
837        {
838                g_dbus_proxy_set_default_timeout(gDBusProxy, timeoutMsec);
839        }
840
841        /**
842         * Ensure that interactions with @proxy conform to the given
843         * interface. See the #GDBusProxy:g-interface-info property for more
844         * details.
845         *
846         * Params:
847         *     info = Minimum interface this proxy conforms to or %NULL to unset.
848         *
849         * Since: 2.26
850         */
851        public void setInterfaceInfo(DBusInterfaceInfo info)
852        {
853                g_dbus_proxy_set_interface_info(gDBusProxy, (info is null) ? null : info.getDBusInterfaceInfoStruct());
854        }
855
856        protected class OnGPropertiesChangedDelegateWrapper
857        {
858                static OnGPropertiesChangedDelegateWrapper[] listeners;
859                void delegate(Variant, string[], DBusProxy) dlg;
860                gulong handlerId;
861               
862                this(void delegate(Variant, string[], DBusProxy) dlg)
863                {
864                        this.dlg = dlg;
865                        this.listeners ~= this;
866                }
867               
868                void remove(OnGPropertiesChangedDelegateWrapper source)
869                {
870                        foreach(index, wrapper; listeners)
871                        {
872                                if (wrapper.handlerId == source.handlerId)
873                                {
874                                        listeners[index] = null;
875                                        listeners = std.algorithm.remove(listeners, index);
876                                        break;
877                                }
878                        }
879                }
880        }
881
882        /**
883         * Emitted when one or more D-Bus properties on @proxy changes. The
884         * local cache has already been updated when this signal fires. Note
885         * that both @changed_properties and @invalidated_properties are
886         * guaranteed to never be %NULL (either may be empty though).
887         *
888         * If the proxy has the flag
889         * %G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES set, then
890         * @invalidated_properties will always be empty.
891         *
892         * This signal corresponds to the
893         * `PropertiesChanged` D-Bus signal on the
894         * `org.freedesktop.DBus.Properties` interface.
895         *
896         * Params:
897         *     changedProperties = A #GVariant containing the properties that changed
898         *     invalidatedProperties = A %NULL terminated array of properties that was invalidated
899         *
900         * Since: 2.26
901         */
902        gulong addOnGPropertiesChanged(void delegate(Variant, string[], DBusProxy) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
903        {
904                auto wrapper = new OnGPropertiesChangedDelegateWrapper(dlg);
905                wrapper.handlerId = Signals.connectData(
906                        this,
907                        "g-properties-changed",
908                        cast(GCallback)&callBackGPropertiesChanged,
909                        cast(void*)wrapper,
910                        cast(GClosureNotify)&callBackGPropertiesChangedDestroy,
911                        connectFlags);
912                return wrapper.handlerId;
913        }
914       
915        extern(C) static void callBackGPropertiesChanged(GDBusProxy* dbusproxyStruct, GVariant* changedProperties, char** invalidatedProperties, OnGPropertiesChangedDelegateWrapper wrapper)
916        {
917                wrapper.dlg(new Variant(changedProperties), Str.toStringArray(invalidatedProperties), wrapper.outer);
918        }
919       
920        extern(C) static void callBackGPropertiesChangedDestroy(OnGPropertiesChangedDelegateWrapper wrapper, GClosure* closure)
921        {
922                wrapper.remove(wrapper);
923        }
924
925        protected class OnGSignalDelegateWrapper
926        {
927                static OnGSignalDelegateWrapper[] listeners;
928                void delegate(string, string, Variant, DBusProxy) dlg;
929                gulong handlerId;
930               
931                this(void delegate(string, string, Variant, DBusProxy) dlg)
932                {
933                        this.dlg = dlg;
934                        this.listeners ~= this;
935                }
936               
937                void remove(OnGSignalDelegateWrapper source)
938                {
939                        foreach(index, wrapper; listeners)
940                        {
941                                if (wrapper.handlerId == source.handlerId)
942                                {
943                                        listeners[index] = null;
944                                        listeners = std.algorithm.remove(listeners, index);
945                                        break;
946                                }
947                        }
948                }
949        }
950
951        /**
952         * Emitted when a signal from the remote object and interface that @proxy is for, has been received.
953         *
954         * Params:
955         *     senderName = The sender of the signal or %NULL if the connection is not a bus connection.
956         *     signalName = The name of the signal.
957         *     parameters = A #GVariant tuple with parameters for the signal.
958         *
959         * Since: 2.26
960         */
961        gulong addOnGSignal(void delegate(string, string, Variant, DBusProxy) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
962        {
963                auto wrapper = new OnGSignalDelegateWrapper(dlg);
964                wrapper.handlerId = Signals.connectData(
965                        this,
966                        "g-signal",
967                        cast(GCallback)&callBackGSignal,
968                        cast(void*)wrapper,
969                        cast(GClosureNotify)&callBackGSignalDestroy,
970                        connectFlags);
971                return wrapper.handlerId;
972        }
973       
974        extern(C) static void callBackGSignal(GDBusProxy* dbusproxyStruct, char* senderName, char* signalName, GVariant* parameters, OnGSignalDelegateWrapper wrapper)
975        {
976                wrapper.dlg(Str.toString(senderName), Str.toString(signalName), new Variant(parameters), wrapper.outer);
977        }
978       
979        extern(C) static void callBackGSignalDestroy(OnGSignalDelegateWrapper wrapper, GClosure* closure)
980        {
981                wrapper.remove(wrapper);
982        }
983}
Note: See TracBrowser for help on using the repository browser.