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