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