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