1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.DBusInterfaceSkeleton;
26 
27 private import gio.DBusConnection;
28 private import gio.DBusInterfaceIF;
29 private import gio.DBusInterfaceInfo;
30 private import gio.DBusInterfaceT;
31 private import gio.DBusMethodInvocation;
32 private import gio.c.functions;
33 public  import gio.c.types;
34 private import glib.ErrorG;
35 private import glib.GException;
36 private import glib.ListG;
37 private import glib.Str;
38 private import glib.Variant;
39 private import gobject.ObjectG;
40 private import gobject.Signals;
41 public  import gtkc.giotypes;
42 private import std.algorithm;
43 
44 
45 /**
46  * Abstract base class for D-Bus interfaces on the service side.
47  *
48  * Since: 2.30
49  */
50 public class DBusInterfaceSkeleton : ObjectG, DBusInterfaceIF
51 {
52 	/** the main Gtk struct */
53 	protected GDBusInterfaceSkeleton* gDBusInterfaceSkeleton;
54 
55 	/** Get the main Gtk struct */
56 	public GDBusInterfaceSkeleton* getDBusInterfaceSkeletonStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return gDBusInterfaceSkeleton;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gDBusInterfaceSkeleton;
67 	}
68 
69 	protected override void setStruct(GObject* obj)
70 	{
71 		gDBusInterfaceSkeleton = cast(GDBusInterfaceSkeleton*)obj;
72 		super.setStruct(obj);
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GDBusInterfaceSkeleton* gDBusInterfaceSkeleton, bool ownedRef = false)
79 	{
80 		this.gDBusInterfaceSkeleton = gDBusInterfaceSkeleton;
81 		super(cast(GObject*)gDBusInterfaceSkeleton, ownedRef);
82 	}
83 
84 	// add the DBusInterface capabilities
85 	mixin DBusInterfaceT!(GDBusInterfaceSkeleton);
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return g_dbus_interface_skeleton_get_type();
92 	}
93 
94 	/**
95 	 * Exports @interface_ at @object_path on @connection.
96 	 *
97 	 * This can be called multiple times to export the same @interface_
98 	 * onto multiple connections however the @object_path provided must be
99 	 * the same for all connections.
100 	 *
101 	 * Use g_dbus_interface_skeleton_unexport() to unexport the object.
102 	 *
103 	 * Params:
104 	 *     connection = A #GDBusConnection to export @interface_ on.
105 	 *     objectPath = The path to export the interface at.
106 	 *
107 	 * Returns: %TRUE if the interface was exported on @connection, otherwise %FALSE with
108 	 *     @error set.
109 	 *
110 	 * Since: 2.30
111 	 *
112 	 * Throws: GException on failure.
113 	 */
114 	public bool expor(DBusConnection connection, string objectPath)
115 	{
116 		GError* err = null;
117 
118 		auto p = g_dbus_interface_skeleton_export(gDBusInterfaceSkeleton, (connection is null) ? null : connection.getDBusConnectionStruct(), Str.toStringz(objectPath), &err) != 0;
119 
120 		if (err !is null)
121 		{
122 			throw new GException( new ErrorG(err) );
123 		}
124 
125 		return p;
126 	}
127 
128 	/**
129 	 * If @interface_ has outstanding changes, request for these changes to be
130 	 * emitted immediately.
131 	 *
132 	 * For example, an exported D-Bus interface may queue up property
133 	 * changes and emit the
134 	 * `org.freedesktop.DBus.Properties::PropertiesChanged`
135 	 * signal later (e.g. in an idle handler). This technique is useful
136 	 * for collapsing multiple property changes into one.
137 	 *
138 	 * Since: 2.30
139 	 */
140 	public void flush()
141 	{
142 		g_dbus_interface_skeleton_flush(gDBusInterfaceSkeleton);
143 	}
144 
145 	/**
146 	 * Gets the first connection that @interface_ is exported on, if any.
147 	 *
148 	 * Returns: A #GDBusConnection or %NULL if @interface_ is
149 	 *     not exported anywhere. Do not free, the object belongs to @interface_.
150 	 *
151 	 * Since: 2.30
152 	 */
153 	public DBusConnection getConnection()
154 	{
155 		auto p = g_dbus_interface_skeleton_get_connection(gDBusInterfaceSkeleton);
156 
157 		if(p is null)
158 		{
159 			return null;
160 		}
161 
162 		return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) p);
163 	}
164 
165 	/**
166 	 * Gets a list of the connections that @interface_ is exported on.
167 	 *
168 	 * Returns: A list of
169 	 *     all the connections that @interface_ is exported on. The returned
170 	 *     list should be freed with g_list_free() after each element has
171 	 *     been freed with g_object_unref().
172 	 *
173 	 * Since: 2.32
174 	 */
175 	public ListG getConnections()
176 	{
177 		auto p = g_dbus_interface_skeleton_get_connections(gDBusInterfaceSkeleton);
178 
179 		if(p is null)
180 		{
181 			return null;
182 		}
183 
184 		return new ListG(cast(GList*) p, true);
185 	}
186 
187 	/**
188 	 * Gets the #GDBusInterfaceSkeletonFlags that describes what the behavior
189 	 * of @interface_
190 	 *
191 	 * Returns: One or more flags from the #GDBusInterfaceSkeletonFlags enumeration.
192 	 *
193 	 * Since: 2.30
194 	 */
195 	public GDBusInterfaceSkeletonFlags getFlags()
196 	{
197 		return g_dbus_interface_skeleton_get_flags(gDBusInterfaceSkeleton);
198 	}
199 
200 	/**
201 	 * Gets D-Bus introspection information for the D-Bus interface
202 	 * implemented by @interface_.
203 	 *
204 	 * Returns: A #GDBusInterfaceInfo (never %NULL). Do not free.
205 	 *
206 	 * Since: 2.30
207 	 */
208 	public DBusInterfaceInfo getInfo()
209 	{
210 		auto p = g_dbus_interface_skeleton_get_info(gDBusInterfaceSkeleton);
211 
212 		if(p is null)
213 		{
214 			return null;
215 		}
216 
217 		return ObjectG.getDObject!(DBusInterfaceInfo)(cast(GDBusInterfaceInfo*) p);
218 	}
219 
220 	/**
221 	 * Gets the object path that @interface_ is exported on, if any.
222 	 *
223 	 * Returns: A string owned by @interface_ or %NULL if @interface_ is not exported
224 	 *     anywhere. Do not free, the string belongs to @interface_.
225 	 *
226 	 * Since: 2.30
227 	 */
228 	public string getObjectPath()
229 	{
230 		return Str.toString(g_dbus_interface_skeleton_get_object_path(gDBusInterfaceSkeleton));
231 	}
232 
233 	/**
234 	 * Gets all D-Bus properties for @interface_.
235 	 *
236 	 * Returns: A #GVariant of type
237 	 *     ['a{sv}'][G-VARIANT-TYPE-VARDICT:CAPS].
238 	 *     Free with g_variant_unref().
239 	 *
240 	 * Since: 2.30
241 	 */
242 	public Variant getProperties()
243 	{
244 		auto p = g_dbus_interface_skeleton_get_properties(gDBusInterfaceSkeleton);
245 
246 		if(p is null)
247 		{
248 			return null;
249 		}
250 
251 		return new Variant(cast(GVariant*) p, true);
252 	}
253 
254 	/**
255 	 * Gets the interface vtable for the D-Bus interface implemented by
256 	 * @interface_. The returned function pointers should expect @interface_
257 	 * itself to be passed as @user_data.
258 	 *
259 	 * Returns: A #GDBusInterfaceVTable (never %NULL).
260 	 *
261 	 * Since: 2.30
262 	 */
263 	public GDBusInterfaceVTable* getVtable()
264 	{
265 		return g_dbus_interface_skeleton_get_vtable(gDBusInterfaceSkeleton);
266 	}
267 
268 	/**
269 	 * Checks if @interface_ is exported on @connection.
270 	 *
271 	 * Params:
272 	 *     connection = A #GDBusConnection.
273 	 *
274 	 * Returns: %TRUE if @interface_ is exported on @connection, %FALSE otherwise.
275 	 *
276 	 * Since: 2.32
277 	 */
278 	public bool hasConnection(DBusConnection connection)
279 	{
280 		return g_dbus_interface_skeleton_has_connection(gDBusInterfaceSkeleton, (connection is null) ? null : connection.getDBusConnectionStruct()) != 0;
281 	}
282 
283 	/**
284 	 * Sets flags describing what the behavior of @skeleton should be.
285 	 *
286 	 * Params:
287 	 *     flags = Flags from the #GDBusInterfaceSkeletonFlags enumeration.
288 	 *
289 	 * Since: 2.30
290 	 */
291 	public void setFlags(GDBusInterfaceSkeletonFlags flags)
292 	{
293 		g_dbus_interface_skeleton_set_flags(gDBusInterfaceSkeleton, flags);
294 	}
295 
296 	/**
297 	 * Stops exporting @interface_ on all connections it is exported on.
298 	 *
299 	 * To unexport @interface_ from only a single connection, use
300 	 * g_dbus_interface_skeleton_unexport_from_connection()
301 	 *
302 	 * Since: 2.30
303 	 */
304 	public void unexport()
305 	{
306 		g_dbus_interface_skeleton_unexport(gDBusInterfaceSkeleton);
307 	}
308 
309 	/**
310 	 * Stops exporting @interface_ on @connection.
311 	 *
312 	 * To stop exporting on all connections the interface is exported on,
313 	 * use g_dbus_interface_skeleton_unexport().
314 	 *
315 	 * Params:
316 	 *     connection = A #GDBusConnection.
317 	 *
318 	 * Since: 2.32
319 	 */
320 	public void unexportFromConnection(DBusConnection connection)
321 	{
322 		g_dbus_interface_skeleton_unexport_from_connection(gDBusInterfaceSkeleton, (connection is null) ? null : connection.getDBusConnectionStruct());
323 	}
324 
325 	protected class OnGAuthorizeMethodDelegateWrapper
326 	{
327 		bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg;
328 		gulong handlerId;
329 
330 		this(bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg)
331 		{
332 			this.dlg = dlg;
333 			onGAuthorizeMethodListeners ~= this;
334 		}
335 
336 		void remove(OnGAuthorizeMethodDelegateWrapper source)
337 		{
338 			foreach(index, wrapper; onGAuthorizeMethodListeners)
339 			{
340 				if (wrapper.handlerId == source.handlerId)
341 				{
342 					onGAuthorizeMethodListeners[index] = null;
343 					onGAuthorizeMethodListeners = std.algorithm.remove(onGAuthorizeMethodListeners, index);
344 					break;
345 				}
346 			}
347 		}
348 	}
349 	OnGAuthorizeMethodDelegateWrapper[] onGAuthorizeMethodListeners;
350 
351 	/**
352 	 * Emitted when a method is invoked by a remote caller and used to
353 	 * determine if the method call is authorized.
354 	 *
355 	 * Note that this signal is emitted in a thread dedicated to
356 	 * handling the method call so handlers are allowed to perform
357 	 * blocking IO. This means that it is appropriate to call e.g.
358 	 * [polkit_authority_check_authorization_sync()](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#polkit-authority-check-authorization-sync)
359 	 * with the
360 	 * [POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION](http://hal.freedesktop.org/docs/polkit/PolkitAuthority.html#POLKIT-CHECK-AUTHORIZATION-FLAGS-ALLOW-USER-INTERACTION:CAPS)
361 	 * flag set.
362 	 *
363 	 * If %FALSE is returned then no further handlers are run and the
364 	 * signal handler must take a reference to @invocation and finish
365 	 * handling the call (e.g. return an error via
366 	 * g_dbus_method_invocation_return_error()).
367 	 *
368 	 * Otherwise, if %TRUE is returned, signal emission continues. If no
369 	 * handlers return %FALSE, then the method is dispatched. If
370 	 * @interface has an enclosing #GDBusObjectSkeleton, then the
371 	 * #GDBusObjectSkeleton::authorize-method signal handlers run before
372 	 * the handlers for this signal.
373 	 *
374 	 * The default class handler just returns %TRUE.
375 	 *
376 	 * Please note that the common case is optimized: if no signals
377 	 * handlers are connected and the default class handler isn't
378 	 * overridden (for both @interface and the enclosing
379 	 * #GDBusObjectSkeleton, if any) and #GDBusInterfaceSkeleton:g-flags does
380 	 * not have the
381 	 * %G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD
382 	 * flags set, no dedicated thread is ever used and the call will be
383 	 * handled in the same thread as the object that @interface belongs
384 	 * to was exported in.
385 	 *
386 	 * Params:
387 	 *     invocation = A #GDBusMethodInvocation.
388 	 *
389 	 * Returns: %TRUE if the call is authorized, %FALSE otherwise.
390 	 *
391 	 * Since: 2.30
392 	 */
393 	gulong addOnGAuthorizeMethod(bool delegate(DBusMethodInvocation, DBusInterfaceSkeleton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
394 	{
395 		auto wrapper = new OnGAuthorizeMethodDelegateWrapper(dlg);
396 		wrapper.handlerId = Signals.connectData(
397 			this,
398 			"g-authorize-method",
399 			cast(GCallback)&callBackGAuthorizeMethod,
400 			cast(void*)wrapper,
401 			cast(GClosureNotify)&callBackGAuthorizeMethodDestroy,
402 			connectFlags);
403 		return wrapper.handlerId;
404 	}
405 
406 	extern(C) static int callBackGAuthorizeMethod(GDBusInterfaceSkeleton* dbusinterfaceskeletonStruct, GDBusMethodInvocation* invocation, OnGAuthorizeMethodDelegateWrapper wrapper)
407 	{
408 		return wrapper.dlg(ObjectG.getDObject!(DBusMethodInvocation)(invocation), wrapper.outer);
409 	}
410 
411 	extern(C) static void callBackGAuthorizeMethodDestroy(OnGAuthorizeMethodDelegateWrapper wrapper, GClosure* closure)
412 	{
413 		wrapper.remove(wrapper);
414 	}
415 }