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