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.DBusObjectSkeleton;
26 
27 private import gio.DBusInterfaceSkeleton;
28 private import gio.DBusMethodInvocation;
29 private import gio.DBusObjectIF;
30 private import gio.DBusObjectT;
31 private import glib.ConstructionException;
32 private import glib.Str;
33 private import gobject.ObjectG;
34 private import gobject.Signals;
35 public  import gtkc.gdktypes;
36 private import gtkc.gio;
37 public  import gtkc.giotypes;
38 private import std.algorithm;
39 
40 
41 /**
42  * A #GDBusObjectSkeleton instance is essentially a group of D-Bus
43  * interfaces. The set of exported interfaces on the object may be
44  * dynamic and change at runtime.
45  * 
46  * This type is intended to be used with #GDBusObjectManager.
47  *
48  * Since: 2.30
49  */
50 public class DBusObjectSkeleton : ObjectG, DBusObjectIF
51 {
52 	/** the main Gtk struct */
53 	protected GDBusObjectSkeleton* gDBusObjectSkeleton;
54 
55 	/** Get the main Gtk struct */
56 	public GDBusObjectSkeleton* getDBusObjectSkeletonStruct()
57 	{
58 		return gDBusObjectSkeleton;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)gDBusObjectSkeleton;
65 	}
66 
67 	protected override void setStruct(GObject* obj)
68 	{
69 		gDBusObjectSkeleton = cast(GDBusObjectSkeleton*)obj;
70 		super.setStruct(obj);
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GDBusObjectSkeleton* gDBusObjectSkeleton, bool ownedRef = false)
77 	{
78 		this.gDBusObjectSkeleton = gDBusObjectSkeleton;
79 		super(cast(GObject*)gDBusObjectSkeleton, ownedRef);
80 	}
81 
82 	// add the DBusObject capabilities
83 	mixin DBusObjectT!(GDBusObjectSkeleton);
84 
85 
86 	/** */
87 	public static GType getType()
88 	{
89 		return g_dbus_object_skeleton_get_type();
90 	}
91 
92 	/**
93 	 * Creates a new #GDBusObjectSkeleton.
94 	 *
95 	 * Params:
96 	 *     objectPath = An object path.
97 	 *
98 	 * Return: A #GDBusObjectSkeleton. Free with g_object_unref().
99 	 *
100 	 * Since: 2.30
101 	 *
102 	 * Throws: ConstructionException GTK+ fails to create the object.
103 	 */
104 	public this(string objectPath)
105 	{
106 		auto p = g_dbus_object_skeleton_new(Str.toStringz(objectPath));
107 		
108 		if(p is null)
109 		{
110 			throw new ConstructionException("null returned by new");
111 		}
112 		
113 		this(cast(GDBusObjectSkeleton*) p, true);
114 	}
115 
116 	/**
117 	 * Adds @interface_ to @object.
118 	 *
119 	 * If @object already contains a #GDBusInterfaceSkeleton with the same
120 	 * interface name, it is removed before @interface_ is added.
121 	 *
122 	 * Note that @object takes its own reference on @interface_ and holds
123 	 * it until removed.
124 	 *
125 	 * Params:
126 	 *     iface = A #GDBusInterfaceSkeleton.
127 	 *
128 	 * Since: 2.30
129 	 */
130 	public void addInterface(DBusInterfaceSkeleton iface)
131 	{
132 		g_dbus_object_skeleton_add_interface(gDBusObjectSkeleton, (iface is null) ? null : iface.getDBusInterfaceSkeletonStruct());
133 	}
134 
135 	/**
136 	 * This method simply calls g_dbus_interface_skeleton_flush() on all
137 	 * interfaces belonging to @object. See that method for when flushing
138 	 * is useful.
139 	 *
140 	 * Since: 2.30
141 	 */
142 	public void flush()
143 	{
144 		g_dbus_object_skeleton_flush(gDBusObjectSkeleton);
145 	}
146 
147 	/**
148 	 * Removes @interface_ from @object.
149 	 *
150 	 * Params:
151 	 *     iface = A #GDBusInterfaceSkeleton.
152 	 *
153 	 * Since: 2.30
154 	 */
155 	public void removeInterface(DBusInterfaceSkeleton iface)
156 	{
157 		g_dbus_object_skeleton_remove_interface(gDBusObjectSkeleton, (iface is null) ? null : iface.getDBusInterfaceSkeletonStruct());
158 	}
159 
160 	/**
161 	 * Removes the #GDBusInterface with @interface_name from @object.
162 	 *
163 	 * If no D-Bus interface of the given interface exists, this function
164 	 * does nothing.
165 	 *
166 	 * Params:
167 	 *     interfaceName = A D-Bus interface name.
168 	 *
169 	 * Since: 2.30
170 	 */
171 	public void removeInterfaceByName(string interfaceName)
172 	{
173 		g_dbus_object_skeleton_remove_interface_by_name(gDBusObjectSkeleton, Str.toStringz(interfaceName));
174 	}
175 
176 	/**
177 	 * Sets the object path for @object.
178 	 *
179 	 * Params:
180 	 *     objectPath = A valid D-Bus object path.
181 	 *
182 	 * Since: 2.30
183 	 */
184 	public void setObjectPath(string objectPath)
185 	{
186 		g_dbus_object_skeleton_set_object_path(gDBusObjectSkeleton, Str.toStringz(objectPath));
187 	}
188 
189 	protected class OnAuthorizeMethodDelegateWrapper
190 	{
191 		bool delegate(DBusInterfaceSkeleton, DBusMethodInvocation, DBusObjectSkeleton) dlg;
192 		gulong handlerId;
193 		ConnectFlags flags;
194 		this(bool delegate(DBusInterfaceSkeleton, DBusMethodInvocation, DBusObjectSkeleton) dlg, gulong handlerId, ConnectFlags flags)
195 		{
196 			this.dlg = dlg;
197 			this.handlerId = handlerId;
198 			this.flags = flags;
199 		}
200 	}
201 	protected OnAuthorizeMethodDelegateWrapper[] onAuthorizeMethodListeners;
202 
203 	/**
204 	 * Emitted when a method is invoked by a remote caller and used to
205 	 * determine if the method call is authorized.
206 	 *
207 	 * This signal is like #GDBusInterfaceSkeleton's
208 	 * #GDBusInterfaceSkeleton::g-authorize-method signal,
209 	 * except that it is for the enclosing object.
210 	 *
211 	 * The default class handler just returns %TRUE.
212 	 *
213 	 * Params:
214 	 *     iface = The #GDBusInterfaceSkeleton that @invocation is for.
215 	 *     invocation = A #GDBusMethodInvocation.
216 	 *
217 	 * Return: %TRUE if the call is authorized, %FALSE otherwise.
218 	 *
219 	 * Since: 2.30
220 	 */
221 	gulong addOnAuthorizeMethod(bool delegate(DBusInterfaceSkeleton, DBusMethodInvocation, DBusObjectSkeleton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
222 	{
223 		onAuthorizeMethodListeners ~= new OnAuthorizeMethodDelegateWrapper(dlg, 0, connectFlags);
224 		onAuthorizeMethodListeners[onAuthorizeMethodListeners.length - 1].handlerId = Signals.connectData(
225 			this,
226 			"authorize-method",
227 			cast(GCallback)&callBackAuthorizeMethod,
228 			cast(void*)onAuthorizeMethodListeners[onAuthorizeMethodListeners.length - 1],
229 			cast(GClosureNotify)&callBackAuthorizeMethodDestroy,
230 			connectFlags);
231 		return onAuthorizeMethodListeners[onAuthorizeMethodListeners.length - 1].handlerId;
232 	}
233 	
234 	extern(C) static int callBackAuthorizeMethod(GDBusObjectSkeleton* dbusobjectskeletonStruct, GDBusInterfaceSkeleton* iface, GDBusMethodInvocation* invocation,OnAuthorizeMethodDelegateWrapper wrapper)
235 	{
236 		return wrapper.dlg(ObjectG.getDObject!(DBusInterfaceSkeleton)(iface), ObjectG.getDObject!(DBusMethodInvocation)(invocation), wrapper.outer);
237 	}
238 	
239 	extern(C) static void callBackAuthorizeMethodDestroy(OnAuthorizeMethodDelegateWrapper wrapper, GClosure* closure)
240 	{
241 		wrapper.outer.internalRemoveOnAuthorizeMethod(wrapper);
242 	}
243 
244 	protected void internalRemoveOnAuthorizeMethod(OnAuthorizeMethodDelegateWrapper source)
245 	{
246 		foreach(index, wrapper; onAuthorizeMethodListeners)
247 		{
248 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
249 			{
250 				onAuthorizeMethodListeners[index] = null;
251 				onAuthorizeMethodListeners = std.algorithm.remove(onAuthorizeMethodListeners, index);
252 				break;
253 			}
254 		}
255 	}
256 	
257 }