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.DBusObjectManagerT;
26 
27 public  import gio.DBusInterface;
28 public  import gio.DBusInterfaceIF;
29 public  import gio.DBusObject;
30 public  import gio.DBusObjectIF;
31 public  import glib.ListG;
32 public  import glib.Str;
33 public  import gobject.ObjectG;
34 public  import gobject.Signals;
35 public  import gtkc.gdktypes;
36 public  import gtkc.gio;
37 public  import gtkc.giotypes;
38 public  import std.algorithm;
39 
40 
41 /**
42  * The #GDBusObjectManager type is the base type for service- and
43  * client-side implementations of the standardized
44  * [org.freedesktop.DBus.ObjectManager](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager)
45  * interface.
46  * 
47  * See #GDBusObjectManagerClient for the client-side implementation
48  * and #GDBusObjectManagerServer for the service-side implementation.
49  */
50 public template DBusObjectManagerT(TStruct)
51 {
52 	/** Get the main Gtk struct */
53 	public GDBusObjectManager* getDBusObjectManagerStruct()
54 	{
55 		return cast(GDBusObjectManager*)getStruct();
56 	}
57 
58 
59 	/**
60 	 * Gets the interface proxy for @interface_name at @object_path, if
61 	 * any.
62 	 *
63 	 * Params:
64 	 *     objectPath = Object path to lookup.
65 	 *     interfaceName = D-Bus interface name to lookup.
66 	 *
67 	 * Return: A #GDBusInterface instance or %NULL. Free
68 	 *     with g_object_unref().
69 	 *
70 	 * Since: 2.30
71 	 */
72 	public DBusInterfaceIF getInterface(string objectPath, string interfaceName)
73 	{
74 		auto p = g_dbus_object_manager_get_interface(getDBusObjectManagerStruct(), Str.toStringz(objectPath), Str.toStringz(interfaceName));
75 		
76 		if(p is null)
77 		{
78 			return null;
79 		}
80 		
81 		return ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(cast(GDBusInterface*) p, true);
82 	}
83 
84 	/**
85 	 * Gets the #GDBusObjectProxy at @object_path, if any.
86 	 *
87 	 * Params:
88 	 *     objectPath = Object path to lookup.
89 	 *
90 	 * Return: A #GDBusObject or %NULL. Free with
91 	 *     g_object_unref().
92 	 *
93 	 * Since: 2.30
94 	 */
95 	public DBusObjectIF getObject(string objectPath)
96 	{
97 		auto p = g_dbus_object_manager_get_object(getDBusObjectManagerStruct(), Str.toStringz(objectPath));
98 		
99 		if(p is null)
100 		{
101 			return null;
102 		}
103 		
104 		return ObjectG.getDObject!(DBusObject, DBusObjectIF)(cast(GDBusObject*) p, true);
105 	}
106 
107 	/**
108 	 * Gets the object path that @manager is for.
109 	 *
110 	 * Return: A string owned by @manager. Do not free.
111 	 *
112 	 * Since: 2.30
113 	 */
114 	public string getObjectPath()
115 	{
116 		return Str.toString(g_dbus_object_manager_get_object_path(getDBusObjectManagerStruct()));
117 	}
118 
119 	/**
120 	 * Gets all #GDBusObject objects known to @manager.
121 	 *
122 	 * Return: A list of
123 	 *     #GDBusObject objects. The returned list should be freed with
124 	 *     g_list_free() after each element has been freed with
125 	 *     g_object_unref().
126 	 *
127 	 * Since: 2.30
128 	 */
129 	public ListG getObjects()
130 	{
131 		auto p = g_dbus_object_manager_get_objects(getDBusObjectManagerStruct());
132 		
133 		if(p is null)
134 		{
135 			return null;
136 		}
137 		
138 		return new ListG(cast(GList*) p, true);
139 	}
140 
141 	protected class OnInterfaceAddedDelegateWrapper
142 	{
143 		void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg;
144 		gulong handlerId;
145 		ConnectFlags flags;
146 		this(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg, gulong handlerId, ConnectFlags flags)
147 		{
148 			this.dlg = dlg;
149 			this.handlerId = handlerId;
150 			this.flags = flags;
151 		}
152 	}
153 	protected OnInterfaceAddedDelegateWrapper[] onInterfaceAddedListeners;
154 
155 	/**
156 	 * Emitted when @interface is added to @object.
157 	 *
158 	 * This signal exists purely as a convenience to avoid having to
159 	 * connect signals to all objects managed by @manager.
160 	 *
161 	 * Params:
162 	 *     object = The #GDBusObject on which an interface was added.
163 	 *     iface = The #GDBusInterface that was added.
164 	 *
165 	 * Since: 2.30
166 	 */
167 	gulong addOnInterfaceAdded(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
168 	{
169 		onInterfaceAddedListeners ~= new OnInterfaceAddedDelegateWrapper(dlg, 0, connectFlags);
170 		onInterfaceAddedListeners[onInterfaceAddedListeners.length - 1].handlerId = Signals.connectData(
171 			this,
172 			"interface-added",
173 			cast(GCallback)&callBackInterfaceAdded,
174 			cast(void*)onInterfaceAddedListeners[onInterfaceAddedListeners.length - 1],
175 			cast(GClosureNotify)&callBackInterfaceAddedDestroy,
176 			connectFlags);
177 		return onInterfaceAddedListeners[onInterfaceAddedListeners.length - 1].handlerId;
178 	}
179 	
180 	extern(C) static void callBackInterfaceAdded(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object, GDBusInterface* iface,OnInterfaceAddedDelegateWrapper wrapper)
181 	{
182 		wrapper.dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), wrapper.outer);
183 	}
184 	
185 	extern(C) static void callBackInterfaceAddedDestroy(OnInterfaceAddedDelegateWrapper wrapper, GClosure* closure)
186 	{
187 		wrapper.outer.internalRemoveOnInterfaceAdded(wrapper);
188 	}
189 
190 	protected void internalRemoveOnInterfaceAdded(OnInterfaceAddedDelegateWrapper source)
191 	{
192 		foreach(index, wrapper; onInterfaceAddedListeners)
193 		{
194 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
195 			{
196 				onInterfaceAddedListeners[index] = null;
197 				onInterfaceAddedListeners = std.algorithm.remove(onInterfaceAddedListeners, index);
198 				break;
199 			}
200 		}
201 	}
202 	
203 
204 	protected class OnInterfaceRemovedDelegateWrapper
205 	{
206 		void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg;
207 		gulong handlerId;
208 		ConnectFlags flags;
209 		this(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg, gulong handlerId, ConnectFlags flags)
210 		{
211 			this.dlg = dlg;
212 			this.handlerId = handlerId;
213 			this.flags = flags;
214 		}
215 	}
216 	protected OnInterfaceRemovedDelegateWrapper[] onInterfaceRemovedListeners;
217 
218 	/**
219 	 * Emitted when @interface has been removed from @object.
220 	 *
221 	 * This signal exists purely as a convenience to avoid having to
222 	 * connect signals to all objects managed by @manager.
223 	 *
224 	 * Params:
225 	 *     object = The #GDBusObject on which an interface was removed.
226 	 *     iface = The #GDBusInterface that was removed.
227 	 *
228 	 * Since: 2.30
229 	 */
230 	gulong addOnInterfaceRemoved(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
231 	{
232 		onInterfaceRemovedListeners ~= new OnInterfaceRemovedDelegateWrapper(dlg, 0, connectFlags);
233 		onInterfaceRemovedListeners[onInterfaceRemovedListeners.length - 1].handlerId = Signals.connectData(
234 			this,
235 			"interface-removed",
236 			cast(GCallback)&callBackInterfaceRemoved,
237 			cast(void*)onInterfaceRemovedListeners[onInterfaceRemovedListeners.length - 1],
238 			cast(GClosureNotify)&callBackInterfaceRemovedDestroy,
239 			connectFlags);
240 		return onInterfaceRemovedListeners[onInterfaceRemovedListeners.length - 1].handlerId;
241 	}
242 	
243 	extern(C) static void callBackInterfaceRemoved(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object, GDBusInterface* iface,OnInterfaceRemovedDelegateWrapper wrapper)
244 	{
245 		wrapper.dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), wrapper.outer);
246 	}
247 	
248 	extern(C) static void callBackInterfaceRemovedDestroy(OnInterfaceRemovedDelegateWrapper wrapper, GClosure* closure)
249 	{
250 		wrapper.outer.internalRemoveOnInterfaceRemoved(wrapper);
251 	}
252 
253 	protected void internalRemoveOnInterfaceRemoved(OnInterfaceRemovedDelegateWrapper source)
254 	{
255 		foreach(index, wrapper; onInterfaceRemovedListeners)
256 		{
257 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
258 			{
259 				onInterfaceRemovedListeners[index] = null;
260 				onInterfaceRemovedListeners = std.algorithm.remove(onInterfaceRemovedListeners, index);
261 				break;
262 			}
263 		}
264 	}
265 	
266 
267 	protected class OnObjectAddedDelegateWrapper
268 	{
269 		void delegate(DBusObjectIF, DBusObjectManagerIF) dlg;
270 		gulong handlerId;
271 		ConnectFlags flags;
272 		this(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg, gulong handlerId, ConnectFlags flags)
273 		{
274 			this.dlg = dlg;
275 			this.handlerId = handlerId;
276 			this.flags = flags;
277 		}
278 	}
279 	protected OnObjectAddedDelegateWrapper[] onObjectAddedListeners;
280 
281 	/**
282 	 * Emitted when @object is added to @manager.
283 	 *
284 	 * Params:
285 	 *     object = The #GDBusObject that was added.
286 	 *
287 	 * Since: 2.30
288 	 */
289 	gulong addOnObjectAdded(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
290 	{
291 		onObjectAddedListeners ~= new OnObjectAddedDelegateWrapper(dlg, 0, connectFlags);
292 		onObjectAddedListeners[onObjectAddedListeners.length - 1].handlerId = Signals.connectData(
293 			this,
294 			"object-added",
295 			cast(GCallback)&callBackObjectAdded,
296 			cast(void*)onObjectAddedListeners[onObjectAddedListeners.length - 1],
297 			cast(GClosureNotify)&callBackObjectAddedDestroy,
298 			connectFlags);
299 		return onObjectAddedListeners[onObjectAddedListeners.length - 1].handlerId;
300 	}
301 	
302 	extern(C) static void callBackObjectAdded(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object,OnObjectAddedDelegateWrapper wrapper)
303 	{
304 		wrapper.dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), wrapper.outer);
305 	}
306 	
307 	extern(C) static void callBackObjectAddedDestroy(OnObjectAddedDelegateWrapper wrapper, GClosure* closure)
308 	{
309 		wrapper.outer.internalRemoveOnObjectAdded(wrapper);
310 	}
311 
312 	protected void internalRemoveOnObjectAdded(OnObjectAddedDelegateWrapper source)
313 	{
314 		foreach(index, wrapper; onObjectAddedListeners)
315 		{
316 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
317 			{
318 				onObjectAddedListeners[index] = null;
319 				onObjectAddedListeners = std.algorithm.remove(onObjectAddedListeners, index);
320 				break;
321 			}
322 		}
323 	}
324 	
325 
326 	protected class OnObjectRemovedDelegateWrapper
327 	{
328 		void delegate(DBusObjectIF, DBusObjectManagerIF) dlg;
329 		gulong handlerId;
330 		ConnectFlags flags;
331 		this(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg, gulong handlerId, ConnectFlags flags)
332 		{
333 			this.dlg = dlg;
334 			this.handlerId = handlerId;
335 			this.flags = flags;
336 		}
337 	}
338 	protected OnObjectRemovedDelegateWrapper[] onObjectRemovedListeners;
339 
340 	/**
341 	 * Emitted when @object is removed from @manager.
342 	 *
343 	 * Params:
344 	 *     object = The #GDBusObject that was removed.
345 	 *
346 	 * Since: 2.30
347 	 */
348 	gulong addOnObjectRemoved(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
349 	{
350 		onObjectRemovedListeners ~= new OnObjectRemovedDelegateWrapper(dlg, 0, connectFlags);
351 		onObjectRemovedListeners[onObjectRemovedListeners.length - 1].handlerId = Signals.connectData(
352 			this,
353 			"object-removed",
354 			cast(GCallback)&callBackObjectRemoved,
355 			cast(void*)onObjectRemovedListeners[onObjectRemovedListeners.length - 1],
356 			cast(GClosureNotify)&callBackObjectRemovedDestroy,
357 			connectFlags);
358 		return onObjectRemovedListeners[onObjectRemovedListeners.length - 1].handlerId;
359 	}
360 	
361 	extern(C) static void callBackObjectRemoved(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object,OnObjectRemovedDelegateWrapper wrapper)
362 	{
363 		wrapper.dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), wrapper.outer);
364 	}
365 	
366 	extern(C) static void callBackObjectRemovedDestroy(OnObjectRemovedDelegateWrapper wrapper, GClosure* closure)
367 	{
368 		wrapper.outer.internalRemoveOnObjectRemoved(wrapper);
369 	}
370 
371 	protected void internalRemoveOnObjectRemoved(OnObjectRemovedDelegateWrapper source)
372 	{
373 		foreach(index, wrapper; onObjectRemovedListeners)
374 		{
375 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
376 			{
377 				onObjectRemovedListeners[index] = null;
378 				onObjectRemovedListeners = std.algorithm.remove(onObjectRemovedListeners, index);
379 				break;
380 			}
381 		}
382 	}
383 	
384 }