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.DBusInterfaceIF;
28 public  import gio.DBusObjectIF;
29 public  import gio.c.functions;
30 public  import gio.c.types;
31 public  import glib.ListG;
32 public  import glib.Str;
33 public  import gobject.ObjectG;
34 public  import gobject.Signals;
35 public  import gtkc.giotypes;
36 public  import std.algorithm;
37 
38 
39 /**
40  * The #GDBusObjectManager type is the base type for service- and
41  * client-side implementations of the standardized
42  * [org.freedesktop.DBus.ObjectManager](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager)
43  * interface.
44  * 
45  * See #GDBusObjectManagerClient for the client-side implementation
46  * and #GDBusObjectManagerServer for the service-side implementation.
47  */
48 public template DBusObjectManagerT(TStruct)
49 {
50 	/** Get the main Gtk struct */
51 	public GDBusObjectManager* getDBusObjectManagerStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
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 	 * Returns: 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!(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 	 * Returns: 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!(DBusObjectIF)(cast(GDBusObject*) p, true);
105 	}
106 
107 	/**
108 	 * Gets the object path that @manager is for.
109 	 *
110 	 * Returns: 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 	 * Returns: 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 
146 		this(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg)
147 		{
148 			this.dlg = dlg;
149 			onInterfaceAddedListeners ~= this;
150 		}
151 
152 		void remove(OnInterfaceAddedDelegateWrapper source)
153 		{
154 			foreach(index, wrapper; onInterfaceAddedListeners)
155 			{
156 				if (wrapper.handlerId == source.handlerId)
157 				{
158 					onInterfaceAddedListeners[index] = null;
159 					onInterfaceAddedListeners = std.algorithm.remove(onInterfaceAddedListeners, index);
160 					break;
161 				}
162 			}
163 		}
164 	}
165 	OnInterfaceAddedDelegateWrapper[] onInterfaceAddedListeners;
166 
167 	/**
168 	 * Emitted when @interface is added to @object.
169 	 *
170 	 * This signal exists purely as a convenience to avoid having to
171 	 * connect signals to all objects managed by @manager.
172 	 *
173 	 * Params:
174 	 *     object = The #GDBusObject on which an interface was added.
175 	 *     iface = The #GDBusInterface that was added.
176 	 *
177 	 * Since: 2.30
178 	 */
179 	gulong addOnInterfaceAdded(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
180 	{
181 		auto wrapper = new OnInterfaceAddedDelegateWrapper(dlg);
182 		wrapper.handlerId = Signals.connectData(
183 			this,
184 			"interface-added",
185 			cast(GCallback)&callBackInterfaceAdded,
186 			cast(void*)wrapper,
187 			cast(GClosureNotify)&callBackInterfaceAddedDestroy,
188 			connectFlags);
189 		return wrapper.handlerId;
190 	}
191 
192 	extern(C) static void callBackInterfaceAdded(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object, GDBusInterface* iface, OnInterfaceAddedDelegateWrapper wrapper)
193 	{
194 		wrapper.dlg(ObjectG.getDObject!(DBusObjectIF)(object), ObjectG.getDObject!(DBusInterfaceIF)(iface), wrapper.outer);
195 	}
196 
197 	extern(C) static void callBackInterfaceAddedDestroy(OnInterfaceAddedDelegateWrapper wrapper, GClosure* closure)
198 	{
199 		wrapper.remove(wrapper);
200 	}
201 
202 	protected class OnInterfaceRemovedDelegateWrapper
203 	{
204 		void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg;
205 		gulong handlerId;
206 
207 		this(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg)
208 		{
209 			this.dlg = dlg;
210 			onInterfaceRemovedListeners ~= this;
211 		}
212 
213 		void remove(OnInterfaceRemovedDelegateWrapper source)
214 		{
215 			foreach(index, wrapper; onInterfaceRemovedListeners)
216 			{
217 				if (wrapper.handlerId == source.handlerId)
218 				{
219 					onInterfaceRemovedListeners[index] = null;
220 					onInterfaceRemovedListeners = std.algorithm.remove(onInterfaceRemovedListeners, index);
221 					break;
222 				}
223 			}
224 		}
225 	}
226 	OnInterfaceRemovedDelegateWrapper[] onInterfaceRemovedListeners;
227 
228 	/**
229 	 * Emitted when @interface has been removed from @object.
230 	 *
231 	 * This signal exists purely as a convenience to avoid having to
232 	 * connect signals to all objects managed by @manager.
233 	 *
234 	 * Params:
235 	 *     object = The #GDBusObject on which an interface was removed.
236 	 *     iface = The #GDBusInterface that was removed.
237 	 *
238 	 * Since: 2.30
239 	 */
240 	gulong addOnInterfaceRemoved(void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
241 	{
242 		auto wrapper = new OnInterfaceRemovedDelegateWrapper(dlg);
243 		wrapper.handlerId = Signals.connectData(
244 			this,
245 			"interface-removed",
246 			cast(GCallback)&callBackInterfaceRemoved,
247 			cast(void*)wrapper,
248 			cast(GClosureNotify)&callBackInterfaceRemovedDestroy,
249 			connectFlags);
250 		return wrapper.handlerId;
251 	}
252 
253 	extern(C) static void callBackInterfaceRemoved(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object, GDBusInterface* iface, OnInterfaceRemovedDelegateWrapper wrapper)
254 	{
255 		wrapper.dlg(ObjectG.getDObject!(DBusObjectIF)(object), ObjectG.getDObject!(DBusInterfaceIF)(iface), wrapper.outer);
256 	}
257 
258 	extern(C) static void callBackInterfaceRemovedDestroy(OnInterfaceRemovedDelegateWrapper wrapper, GClosure* closure)
259 	{
260 		wrapper.remove(wrapper);
261 	}
262 
263 	protected class OnObjectAddedDelegateWrapper
264 	{
265 		void delegate(DBusObjectIF, DBusObjectManagerIF) dlg;
266 		gulong handlerId;
267 
268 		this(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg)
269 		{
270 			this.dlg = dlg;
271 			onObjectAddedListeners ~= this;
272 		}
273 
274 		void remove(OnObjectAddedDelegateWrapper source)
275 		{
276 			foreach(index, wrapper; onObjectAddedListeners)
277 			{
278 				if (wrapper.handlerId == source.handlerId)
279 				{
280 					onObjectAddedListeners[index] = null;
281 					onObjectAddedListeners = std.algorithm.remove(onObjectAddedListeners, index);
282 					break;
283 				}
284 			}
285 		}
286 	}
287 	OnObjectAddedDelegateWrapper[] onObjectAddedListeners;
288 
289 	/**
290 	 * Emitted when @object is added to @manager.
291 	 *
292 	 * Params:
293 	 *     object = The #GDBusObject that was added.
294 	 *
295 	 * Since: 2.30
296 	 */
297 	gulong addOnObjectAdded(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
298 	{
299 		auto wrapper = new OnObjectAddedDelegateWrapper(dlg);
300 		wrapper.handlerId = Signals.connectData(
301 			this,
302 			"object-added",
303 			cast(GCallback)&callBackObjectAdded,
304 			cast(void*)wrapper,
305 			cast(GClosureNotify)&callBackObjectAddedDestroy,
306 			connectFlags);
307 		return wrapper.handlerId;
308 	}
309 
310 	extern(C) static void callBackObjectAdded(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object, OnObjectAddedDelegateWrapper wrapper)
311 	{
312 		wrapper.dlg(ObjectG.getDObject!(DBusObjectIF)(object), wrapper.outer);
313 	}
314 
315 	extern(C) static void callBackObjectAddedDestroy(OnObjectAddedDelegateWrapper wrapper, GClosure* closure)
316 	{
317 		wrapper.remove(wrapper);
318 	}
319 
320 	protected class OnObjectRemovedDelegateWrapper
321 	{
322 		void delegate(DBusObjectIF, DBusObjectManagerIF) dlg;
323 		gulong handlerId;
324 
325 		this(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg)
326 		{
327 			this.dlg = dlg;
328 			onObjectRemovedListeners ~= this;
329 		}
330 
331 		void remove(OnObjectRemovedDelegateWrapper source)
332 		{
333 			foreach(index, wrapper; onObjectRemovedListeners)
334 			{
335 				if (wrapper.handlerId == source.handlerId)
336 				{
337 					onObjectRemovedListeners[index] = null;
338 					onObjectRemovedListeners = std.algorithm.remove(onObjectRemovedListeners, index);
339 					break;
340 				}
341 			}
342 		}
343 	}
344 	OnObjectRemovedDelegateWrapper[] onObjectRemovedListeners;
345 
346 	/**
347 	 * Emitted when @object is removed from @manager.
348 	 *
349 	 * Params:
350 	 *     object = The #GDBusObject that was removed.
351 	 *
352 	 * Since: 2.30
353 	 */
354 	gulong addOnObjectRemoved(void delegate(DBusObjectIF, DBusObjectManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
355 	{
356 		auto wrapper = new OnObjectRemovedDelegateWrapper(dlg);
357 		wrapper.handlerId = Signals.connectData(
358 			this,
359 			"object-removed",
360 			cast(GCallback)&callBackObjectRemoved,
361 			cast(void*)wrapper,
362 			cast(GClosureNotify)&callBackObjectRemovedDestroy,
363 			connectFlags);
364 		return wrapper.handlerId;
365 	}
366 
367 	extern(C) static void callBackObjectRemoved(GDBusObjectManager* dbusobjectmanagerStruct, GDBusObject* object, OnObjectRemovedDelegateWrapper wrapper)
368 	{
369 		wrapper.dlg(ObjectG.getDObject!(DBusObjectIF)(object), wrapper.outer);
370 	}
371 
372 	extern(C) static void callBackObjectRemovedDestroy(OnObjectRemovedDelegateWrapper wrapper, GClosure* closure)
373 	{
374 		wrapper.remove(wrapper);
375 	}
376 }