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  * Conversion parameters:
26  * inFile  = GDBusServer.html
27  * outPack = gio
28  * outFile = DBusServer
29  * strct   = GDBusServer
30  * realStrct=
31  * ctorStrct=
32  * clss    = DBusServer
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- InitableIF
40  * prefixes:
41  * 	- g_dbus_server_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- gio.Cancellable
51  * 	- gio.DBusAuthObserver
52  * 	- gio.InitableT
53  * 	- gio.InitableIF
54  * structWrap:
55  * 	- GCancellable* -> Cancellable
56  * 	- GDBusAuthObserver* -> DBusAuthObserver
57  * module aliases:
58  * local aliases:
59  * overrides:
60  */
61 
62 module gio.DBusServer;
63 
64 public  import gtkc.giotypes;
65 
66 private import gtkc.gio;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 private import gobject.Signals;
71 public  import gtkc.gdktypes;
72 
73 private import glib.Str;
74 private import glib.ErrorG;
75 private import glib.GException;
76 private import gio.Cancellable;
77 private import gio.DBusAuthObserver;
78 private import gio.InitableT;
79 private import gio.InitableIF;
80 
81 
82 
83 private import gobject.ObjectG;
84 
85 /**
86  * GDBusServer is a helper for listening to and accepting D-Bus
87  * connections. This can be used to create a new D-Bus server, allowing two
88  * peers to use the D-Bus protocol for their own specialized communication.
89  * A server instance provided in this way will not perform message routing or
90  * implement the org.freedesktop.DBus interface.
91  *
92  * To just export an object on a well-known name on a message bus, such as the
93  * session or system bus, you should instead use g_bus_own_name().
94  *
95  * $(DDOC_COMMENT example)
96  */
97 public class DBusServer : ObjectG, InitableIF
98 {
99 	
100 	/** the main Gtk struct */
101 	protected GDBusServer* gDBusServer;
102 	
103 	
104 	public GDBusServer* getDBusServerStruct()
105 	{
106 		return gDBusServer;
107 	}
108 	
109 	
110 	/** the main Gtk struct as a void* */
111 	protected override void* getStruct()
112 	{
113 		return cast(void*)gDBusServer;
114 	}
115 	
116 	/**
117 	 * Sets our main struct and passes it to the parent class
118 	 */
119 	public this (GDBusServer* gDBusServer)
120 	{
121 		super(cast(GObject*)gDBusServer);
122 		this.gDBusServer = gDBusServer;
123 	}
124 	
125 	protected override void setStruct(GObject* obj)
126 	{
127 		super.setStruct(obj);
128 		gDBusServer = cast(GDBusServer*)obj;
129 	}
130 	
131 	// add the Initable capabilities
132 	mixin InitableT!(GDBusServer);
133 	
134 	/**
135 	 */
136 	int[string] connectedSignals;
137 	
138 	bool delegate(GDBusConnection*, DBusServer)[] onNewConnectionListeners;
139 	/**
140 	 * Emitted when a new authenticated connection has been made. Use
141 	 * g_dbus_connection_get_peer_credentials() to figure out what
142 	 * identity (if any), was authenticated.
143 	 * If you want to accept the connection, take a reference to the
144 	 * connection object and return TRUE. When you are done with the
145 	 * connection call g_dbus_connection_close() and give up your
146 	 * reference. Note that the other peer may disconnect at any time -
147 	 * a typical thing to do when accepting a connection is to listen to
148 	 * the "closed" signal.
149 	 * If "flags" contains G_DBUS_SERVER_FLAGS_RUN_IN_THREAD
150 	 * then the signal is emitted in a new thread dedicated to the
151 	 * connection. Otherwise the signal is emitted in the thread-default main
152 	 * loop of the thread that server was constructed in.
153 	 * You are guaranteed that signal handlers for this signal runs
154 	 * before incoming messages on connection are processed. This means
155 	 * that it's suitable to call g_dbus_connection_register_object() or
156 	 * similar from the signal handler.
157 	 * TRUE to claim connection, FALSE to let other handlers
158 	 * run.
159 	 * Since 2.26
160 	 */
161 	void addOnNewConnection(bool delegate(GDBusConnection*, DBusServer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
162 	{
163 		if ( !("new-connection" in connectedSignals) )
164 		{
165 			Signals.connectData(
166 			getStruct(),
167 			"new-connection",
168 			cast(GCallback)&callBackNewConnection,
169 			cast(void*)this,
170 			null,
171 			connectFlags);
172 			connectedSignals["new-connection"] = 1;
173 		}
174 		onNewConnectionListeners ~= dlg;
175 	}
176 	extern(C) static gboolean callBackNewConnection(GDBusServer* serverStruct, GDBusConnection* connection, DBusServer _dBusServer)
177 	{
178 		foreach ( bool delegate(GDBusConnection*, DBusServer) dlg ; _dBusServer.onNewConnectionListeners )
179 		{
180 			if ( dlg(connection, _dBusServer) )
181 			{
182 				return 1;
183 			}
184 		}
185 		
186 		return 0;
187 	}
188 	
189 	
190 	/**
191 	 * Creates a new D-Bus server that listens on the first address in
192 	 * address that works.
193 	 * Once constructed, you can use g_dbus_server_get_client_address() to
194 	 * get a D-Bus address string that clients can use to connect.
195 	 * Connect to the "new-connection" signal to handle
196 	 * incoming connections.
197 	 * The returned GDBusServer isn't active - you have to start it with
198 	 * g_dbus_server_start().
199 	 * See Example 10, “D-Bus peer-to-peer example” for how GDBusServer can
200 	 * be used.
201 	 * This is a synchronous failable constructor. See
202 	 * g_dbus_server_new() for the asynchronous version.
203 	 * Since 2.26
204 	 * Params:
205 	 * address = A D-Bus address.
206 	 * flags = Flags from the GDBusServerFlags enumeration.
207 	 * guid = A D-Bus GUID.
208 	 * observer = A GDBusAuthObserver or NULL. [allow-none]
209 	 * cancellable = A GCancellable or NULL. [allow-none]
210 	 * Throws: GException on failure.
211 	 * Throws: ConstructionException GTK+ fails to create the object.
212 	 */
213 	public this (string address, GDBusServerFlags flags, string guid, DBusAuthObserver observer, Cancellable cancellable)
214 	{
215 		// GDBusServer * g_dbus_server_new_sync (const gchar *address,  GDBusServerFlags flags,  const gchar *guid,  GDBusAuthObserver *observer,  GCancellable *cancellable,  GError **error);
216 		GError* err = null;
217 		
218 		auto p = g_dbus_server_new_sync(Str.toStringz(address), flags, Str.toStringz(guid), (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
219 		
220 		if (err !is null)
221 		{
222 			throw new GException( new ErrorG(err) );
223 		}
224 		
225 		if(p is null)
226 		{
227 			throw new ConstructionException("null returned by g_dbus_server_new_sync(Str.toStringz(address), flags, Str.toStringz(guid), (observer is null) ? null : observer.getDBusAuthObserverStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err)");
228 		}
229 		this(cast(GDBusServer*) p);
230 	}
231 	
232 	/**
233 	 * Starts server.
234 	 * Since 2.26
235 	 */
236 	public void start()
237 	{
238 		// void g_dbus_server_start (GDBusServer *server);
239 		g_dbus_server_start(gDBusServer);
240 	}
241 	
242 	/**
243 	 * Stops server.
244 	 * Since 2.26
245 	 */
246 	public void stop()
247 	{
248 		// void g_dbus_server_stop (GDBusServer *server);
249 		g_dbus_server_stop(gDBusServer);
250 	}
251 	
252 	/**
253 	 * Gets whether server is active.
254 	 * Since 2.26
255 	 * Returns: TRUE if server is active, FALSE otherwise.
256 	 */
257 	public int isActive()
258 	{
259 		// gboolean g_dbus_server_is_active (GDBusServer *server);
260 		return g_dbus_server_is_active(gDBusServer);
261 	}
262 	
263 	/**
264 	 * Gets the GUID for server.
265 	 * Since 2.26
266 	 * Returns: A D-Bus GUID. Do not free this string, it is owned by server.
267 	 */
268 	public string getGuid()
269 	{
270 		// const gchar * g_dbus_server_get_guid (GDBusServer *server);
271 		return Str.toString(g_dbus_server_get_guid(gDBusServer));
272 	}
273 	
274 	/**
275 	 * Gets the flags for server.
276 	 * Since 2.26
277 	 * Returns: A set of flags from the GDBusServerFlags enumeration.
278 	 */
279 	public GDBusServerFlags getFlags()
280 	{
281 		// GDBusServerFlags g_dbus_server_get_flags (GDBusServer *server);
282 		return g_dbus_server_get_flags(gDBusServer);
283 	}
284 	
285 	/**
286 	 * Gets a D-Bus address string that can be used by clients to connect
287 	 * to server.
288 	 * Since 2.26
289 	 * Returns: A D-Bus address string. Do not free, the string is owned by server.
290 	 */
291 	public string getClientAddress()
292 	{
293 		// const gchar * g_dbus_server_get_client_address (GDBusServer *server);
294 		return Str.toString(g_dbus_server_get_client_address(gDBusServer));
295 	}
296 }