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

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

Initial release

File size: 8.1 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.DBusServer;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.Cancellable;
26private import gio.DBusAuthObserver;
27private import gio.DBusConnection;
28private import gio.InitableIF;
29private import gio.InitableT;
30private import glib.ConstructionException;
31private import glib.ErrorG;
32private import glib.GException;
33private import glib.Str;
34private import gobject.ObjectG;
35private import gobject.Signals;
36private import std.algorithm;
37
38
39/**
40 * #GDBusServer is a helper for listening to and accepting D-Bus
41 * connections. This can be used to create a new D-Bus server, allowing two
42 * peers to use the D-Bus protocol for their own specialized communication.
43 * A server instance provided in this way will not perform message routing or
44 * implement the org.freedesktop.DBus interface.
45 *
46 * To just export an object on a well-known name on a message bus, such as the
47 * session or system bus, you should instead use g_bus_own_name().
48 *
49 * An example of peer-to-peer communication with G-DBus can be found
50 * in [gdbus-example-peer.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-peer.c).
51 *
52 * Since: 2.26
53 */
54public class DBusServer : ObjectG, InitableIF
55{
56        /** the main Gtk struct */
57        protected GDBusServer* gDBusServer;
58
59        /** Get the main Gtk struct */
60        public GDBusServer* getDBusServerStruct()
61        {
62                return gDBusServer;
63        }
64
65        /** the main Gtk struct as a void* */
66        protected override void* getStruct()
67        {
68                return cast(void*)gDBusServer;
69        }
70
71        protected override void setStruct(GObject* obj)
72        {
73                gDBusServer = cast(GDBusServer*)obj;
74                super.setStruct(obj);
75        }
76
77        /**
78         * Sets our main struct and passes it to the parent class.
79         */
80        public this (GDBusServer* gDBusServer, bool ownedRef = false)
81        {
82                this.gDBusServer = gDBusServer;
83                super(cast(GObject*)gDBusServer, ownedRef);
84        }
85
86        // add the Initable capabilities
87        mixin InitableT!(GDBusServer);
88
89
90        /** */
91        public static GType getType()
92        {
93                return g_dbus_server_get_type();
94        }
95
96        /**
97         * Creates a new D-Bus server that listens on the first address in
98         * @address that works.
99         *
100         * Once constructed, you can use g_dbus_server_get_client_address() to
101         * get a D-Bus address string that clients can use to connect.
102         *
103         * Connect to the #GDBusServer::new-connection signal to handle
104         * incoming connections.
105         *
106         * The returned #GDBusServer isn't active - you have to start it with
107         * g_dbus_server_start().
108         *
109         * #GDBusServer is used in this [example][gdbus-peer-to-peer].
110         *
111         * This is a synchronous failable constructor. See
112         * g_dbus_server_new() for the asynchronous version.
113         *
114         * Params:
115         *     address = A D-Bus address.
116         *     flags = Flags from the #GDBusServerFlags enumeration.
117         *     guid = A D-Bus GUID.
118         *     observer = A #GDBusAuthObserver or %NULL.
119         *     cancellable = A #GCancellable or %NULL.
120         *
121         * Returns: A #GDBusServer or %NULL if @error is set. Free with
122         *     g_object_unref().
123         *
124         * Since: 2.26
125         *
126         * Throws: GException on failure.
127         * Throws: ConstructionException GTK+ fails to create the object.
128         */
129        public this(string address, GDBusServerFlags flags, string guid, DBusAuthObserver observer, Cancellable cancellable)
130        {
131                GError* err = null;
132               
133                auto p = g_dbus_server_new_sync(Str.toStringz(address), flags, Str.toStringz(guid), (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
134               
135                if (err !is null)
136                {
137                        throw new GException( new ErrorG(err) );
138                }
139               
140                if(p is null)
141                {
142                        throw new ConstructionException("null returned by new_sync");
143                }
144               
145                this(cast(GDBusServer*) p, true);
146        }
147
148        /**
149         * Gets a D-Bus address string that can be used by clients to connect
150         * to @server.
151         *
152         * Returns: A D-Bus address string. Do not free, the string is owned
153         *     by @server.
154         *
155         * Since: 2.26
156         */
157        public string getClientAddress()
158        {
159                return Str.toString(g_dbus_server_get_client_address(gDBusServer));
160        }
161
162        /**
163         * Gets the flags for @server.
164         *
165         * Returns: A set of flags from the #GDBusServerFlags enumeration.
166         *
167         * Since: 2.26
168         */
169        public GDBusServerFlags getFlags()
170        {
171                return g_dbus_server_get_flags(gDBusServer);
172        }
173
174        /**
175         * Gets the GUID for @server.
176         *
177         * Returns: A D-Bus GUID. Do not free this string, it is owned by @server.
178         *
179         * Since: 2.26
180         */
181        public string getGuid()
182        {
183                return Str.toString(g_dbus_server_get_guid(gDBusServer));
184        }
185
186        /**
187         * Gets whether @server is active.
188         *
189         * Returns: %TRUE if server is active, %FALSE otherwise.
190         *
191         * Since: 2.26
192         */
193        public bool isActive()
194        {
195                return g_dbus_server_is_active(gDBusServer) != 0;
196        }
197
198        /**
199         * Starts @server.
200         *
201         * Since: 2.26
202         */
203        public void start()
204        {
205                g_dbus_server_start(gDBusServer);
206        }
207
208        /**
209         * Stops @server.
210         *
211         * Since: 2.26
212         */
213        public void stop()
214        {
215                g_dbus_server_stop(gDBusServer);
216        }
217
218        protected class OnNewConnectionDelegateWrapper
219        {
220                static OnNewConnectionDelegateWrapper[] listeners;
221                bool delegate(DBusConnection, DBusServer) dlg;
222                gulong handlerId;
223               
224                this(bool delegate(DBusConnection, DBusServer) dlg)
225                {
226                        this.dlg = dlg;
227                        this.listeners ~= this;
228                }
229               
230                void remove(OnNewConnectionDelegateWrapper source)
231                {
232                        foreach(index, wrapper; listeners)
233                        {
234                                if (wrapper.handlerId == source.handlerId)
235                                {
236                                        listeners[index] = null;
237                                        listeners = std.algorithm.remove(listeners, index);
238                                        break;
239                                }
240                        }
241                }
242        }
243
244        /**
245         * Emitted when a new authenticated connection has been made. Use
246         * g_dbus_connection_get_peer_credentials() to figure out what
247         * identity (if any), was authenticated.
248         *
249         * If you want to accept the connection, take a reference to the
250         * @connection object and return %TRUE. When you are done with the
251         * connection call g_dbus_connection_close() and give up your
252         * reference. Note that the other peer may disconnect at any time -
253         * a typical thing to do when accepting a connection is to listen to
254         * the #GDBusConnection::closed signal.
255         *
256         * If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD
257         * then the signal is emitted in a new thread dedicated to the
258         * connection. Otherwise the signal is emitted in the
259         * [thread-default main context][g-main-context-push-thread-default]
260         * of the thread that @server was constructed in.
261         *
262         * You are guaranteed that signal handlers for this signal runs
263         * before incoming messages on @connection are processed. This means
264         * that it's suitable to call g_dbus_connection_register_object() or
265         * similar from the signal handler.
266         *
267         * Params:
268         *     connection = A #GDBusConnection for the new connection.
269         *
270         * Returns: %TRUE to claim @connection, %FALSE to let other handlers
271         *     run.
272         *
273         * Since: 2.26
274         */
275        gulong addOnNewConnection(bool delegate(DBusConnection, DBusServer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
276        {
277                auto wrapper = new OnNewConnectionDelegateWrapper(dlg);
278                wrapper.handlerId = Signals.connectData(
279                        this,
280                        "new-connection",
281                        cast(GCallback)&callBackNewConnection,
282                        cast(void*)wrapper,
283                        cast(GClosureNotify)&callBackNewConnectionDestroy,
284                        connectFlags);
285                return wrapper.handlerId;
286        }
287       
288        extern(C) static int callBackNewConnection(GDBusServer* dbusserverStruct, GDBusConnection* connection, OnNewConnectionDelegateWrapper wrapper)
289        {
290                return wrapper.dlg(ObjectG.getDObject!(DBusConnection)(connection), wrapper.outer);
291        }
292       
293        extern(C) static void callBackNewConnectionDestroy(OnNewConnectionDelegateWrapper wrapper, GClosure* closure)
294        {
295                wrapper.remove(wrapper);
296        }
297}
Note: See TracBrowser for help on using the repository browser.