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