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 * Description 87 * GDBusServer is a helper for listening to and accepting D-Bus 88 * connections. 89 * $(DDOC_COMMENT example) 90 */ 91 public class DBusServer : ObjectG, InitableIF 92 { 93 94 /** the main Gtk struct */ 95 protected GDBusServer* gDBusServer; 96 97 98 public GDBusServer* getDBusServerStruct() 99 { 100 return gDBusServer; 101 } 102 103 104 /** the main Gtk struct as a void* */ 105 protected override void* getStruct() 106 { 107 return cast(void*)gDBusServer; 108 } 109 110 /** 111 * Sets our main struct and passes it to the parent class 112 */ 113 public this (GDBusServer* gDBusServer) 114 { 115 super(cast(GObject*)gDBusServer); 116 this.gDBusServer = gDBusServer; 117 } 118 119 protected override void setStruct(GObject* obj) 120 { 121 super.setStruct(obj); 122 gDBusServer = cast(GDBusServer*)obj; 123 } 124 125 // add the Initable capabilities 126 mixin InitableT!(GDBusServer); 127 128 /** 129 */ 130 int[string] connectedSignals; 131 132 bool delegate(GDBusConnection*, DBusServer)[] onNewConnectionListeners; 133 /** 134 * Emitted when a new authenticated connection has been made. Use 135 * g_dbus_connection_get_peer_credentials() to figure out what 136 * identity (if any), was authenticated. 137 * If you want to accept the connection, take a reference to the 138 * connection object and return TRUE. When you are done with the 139 * connection call g_dbus_connection_close() and give up your 140 * reference. Note that the other peer may disconnect at any time - 141 * a typical thing to do when accepting a connection is to listen to 142 * the "closed" signal. 143 * If "flags" contains G_DBUS_SERVER_FLAGS_RUN_IN_THREAD 144 * then the signal is emitted in a new thread dedicated to the 145 * connection. Otherwise the signal is emitted in the thread-default main 146 * loop of the thread that server was constructed in. 147 * You are guaranteed that signal handlers for this signal runs 148 * before incoming messages on connection are processed. This means 149 * that it's suitable to call g_dbus_connection_register_object() or 150 * similar from the signal handler. 151 * TRUE to claim connection, FALSE to let other handlers 152 * run. 153 * Since 2.26 154 */ 155 void addOnNewConnection(bool delegate(GDBusConnection*, DBusServer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 156 { 157 if ( !("new-connection" in connectedSignals) ) 158 { 159 Signals.connectData( 160 getStruct(), 161 "new-connection", 162 cast(GCallback)&callBackNewConnection, 163 cast(void*)this, 164 null, 165 connectFlags); 166 connectedSignals["new-connection"] = 1; 167 } 168 onNewConnectionListeners ~= dlg; 169 } 170 extern(C) static gboolean callBackNewConnection(GDBusServer* serverStruct, GDBusConnection* connection, DBusServer _dBusServer) 171 { 172 foreach ( bool delegate(GDBusConnection*, DBusServer) dlg ; _dBusServer.onNewConnectionListeners ) 173 { 174 if ( dlg(connection, _dBusServer) ) 175 { 176 return 1; 177 } 178 } 179 180 return 0; 181 } 182 183 184 /** 185 * Creates a new D-Bus server that listens on the first address in 186 * address that works. 187 * Once constructed, you can use g_dbus_server_get_client_address() to 188 * get a D-Bus address string that clients can use to connect. 189 * Connect to the "new-connection" signal to handle 190 * incoming connections. 191 * The returned GDBusServer isn't active - you have to start it with 192 * g_dbus_server_start(). 193 * See Example 6, “D-Bus peer-to-peer example” for how GDBusServer can 194 * be used. 195 * This is a synchronous failable constructor. 196 * Since 2.26 197 * Params: 198 * address = A D-Bus address. 199 * flags = Flags from the GDBusServerFlags enumeration. 200 * guid = A D-Bus GUID. 201 * observer = A GDBusAuthObserver or NULL. 202 * cancellable = A GCancellable or NULL. 203 * Throws: GException on failure. 204 * Throws: ConstructionException GTK+ fails to create the object. 205 */ 206 public this (string address, GDBusServerFlags flags, string guid, DBusAuthObserver observer, Cancellable cancellable) 207 { 208 // GDBusServer * g_dbus_server_new_sync (const gchar *address, GDBusServerFlags flags, const gchar *guid, GDBusAuthObserver *observer, GCancellable *cancellable, GError **error); 209 GError* err = null; 210 211 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); 212 213 if (err !is null) 214 { 215 throw new GException( new ErrorG(err) ); 216 } 217 218 if(p is null) 219 { 220 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)"); 221 } 222 this(cast(GDBusServer*) p); 223 } 224 225 /** 226 * Starts server. 227 * Since 2.26 228 */ 229 public void start() 230 { 231 // void g_dbus_server_start (GDBusServer *server); 232 g_dbus_server_start(gDBusServer); 233 } 234 235 /** 236 * Stops server. 237 * Since 2.26 238 */ 239 public void stop() 240 { 241 // void g_dbus_server_stop (GDBusServer *server); 242 g_dbus_server_stop(gDBusServer); 243 } 244 245 /** 246 * Gets whether server is active. 247 * Since 2.26 248 * Returns: TRUE if server is active, FALSE otherwise. 249 */ 250 public int isActive() 251 { 252 // gboolean g_dbus_server_is_active (GDBusServer *server); 253 return g_dbus_server_is_active(gDBusServer); 254 } 255 256 /** 257 * Gets the GUID for server. 258 * Since 2.26 259 * Returns: A D-Bus GUID. Do not free this string, it is owned by server. 260 */ 261 public string getGuid() 262 { 263 // const gchar * g_dbus_server_get_guid (GDBusServer *server); 264 return Str.toString(g_dbus_server_get_guid(gDBusServer)); 265 } 266 267 /** 268 * Gets the flags for server. 269 * Since 2.26 270 * Returns: A set of flags from the GDBusServerFlags enumeration. 271 */ 272 public GDBusServerFlags getFlags() 273 { 274 // GDBusServerFlags g_dbus_server_get_flags (GDBusServer *server); 275 return g_dbus_server_get_flags(gDBusServer); 276 } 277 278 /** 279 * Gets a D-Bus address string that can be used by clients to connect 280 * to server. 281 * Since 2.26 282 * Returns: A D-Bus address string. Do not free, the string is owned by server. 283 */ 284 public string getClientAddress() 285 { 286 // const gchar * g_dbus_server_get_client_address (GDBusServer *server); 287 return Str.toString(g_dbus_server_get_client_address(gDBusServer)); 288 } 289 }