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.DBusServer; 26 27 private import gio.Cancellable; 28 private import gio.DBusAuthObserver; 29 private import gio.DBusConnection; 30 private import gio.InitableIF; 31 private import gio.InitableT; 32 private import gio.c.functions; 33 public import gio.c.types; 34 private import glib.ConstructionException; 35 private import glib.ErrorG; 36 private import glib.GException; 37 private import glib.Str; 38 private import gobject.ObjectG; 39 private import gobject.Signals; 40 public import gtkc.giotypes; 41 private import std.algorithm; 42 43 44 /** 45 * #GDBusServer is a helper for listening to and accepting D-Bus 46 * connections. This can be used to create a new D-Bus server, allowing two 47 * peers to use the D-Bus protocol for their own specialized communication. 48 * A server instance provided in this way will not perform message routing or 49 * implement the org.freedesktop.DBus interface. 50 * 51 * To just export an object on a well-known name on a message bus, such as the 52 * session or system bus, you should instead use g_bus_own_name(). 53 * 54 * An example of peer-to-peer communication with G-DBus can be found 55 * in [gdbus-example-peer.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-peer.c). 56 * 57 * Note that a minimal #GDBusServer will accept connections from any 58 * peer. In many use-cases it will be necessary to add a #GDBusAuthObserver 59 * that only accepts connections that have successfully authenticated 60 * as the same user that is running the #GDBusServer. 61 * 62 * Since: 2.26 63 */ 64 public class DBusServer : ObjectG, InitableIF 65 { 66 /** the main Gtk struct */ 67 protected GDBusServer* gDBusServer; 68 69 /** Get the main Gtk struct */ 70 public GDBusServer* getDBusServerStruct(bool transferOwnership = false) 71 { 72 if (transferOwnership) 73 ownedRef = false; 74 return gDBusServer; 75 } 76 77 /** the main Gtk struct as a void* */ 78 protected override void* getStruct() 79 { 80 return cast(void*)gDBusServer; 81 } 82 83 /** 84 * Sets our main struct and passes it to the parent class. 85 */ 86 public this (GDBusServer* gDBusServer, bool ownedRef = false) 87 { 88 this.gDBusServer = gDBusServer; 89 super(cast(GObject*)gDBusServer, ownedRef); 90 } 91 92 // add the Initable capabilities 93 mixin InitableT!(GDBusServer); 94 95 96 /** */ 97 public static GType getType() 98 { 99 return g_dbus_server_get_type(); 100 } 101 102 /** 103 * Creates a new D-Bus server that listens on the first address in 104 * @address that works. 105 * 106 * Once constructed, you can use g_dbus_server_get_client_address() to 107 * get a D-Bus address string that clients can use to connect. 108 * 109 * To have control over the available authentication mechanisms and 110 * the users that are authorized to connect, it is strongly recommended 111 * to provide a non-%NULL #GDBusAuthObserver. 112 * 113 * Connect to the #GDBusServer::new-connection signal to handle 114 * incoming connections. 115 * 116 * The returned #GDBusServer isn't active - you have to start it with 117 * g_dbus_server_start(). 118 * 119 * #GDBusServer is used in this [example][gdbus-peer-to-peer]. 120 * 121 * This is a synchronous failable constructor. There is currently no 122 * asynchronous version. 123 * 124 * Params: 125 * address = A D-Bus address. 126 * flags = Flags from the #GDBusServerFlags enumeration. 127 * guid = A D-Bus GUID. 128 * observer = A #GDBusAuthObserver or %NULL. 129 * cancellable = A #GCancellable or %NULL. 130 * 131 * Returns: A #GDBusServer or %NULL if @error is set. Free with 132 * g_object_unref(). 133 * 134 * Since: 2.26 135 * 136 * Throws: GException on failure. 137 * Throws: ConstructionException GTK+ fails to create the object. 138 */ 139 public this(string address, GDBusServerFlags flags, string guid, DBusAuthObserver observer, Cancellable cancellable) 140 { 141 GError* err = null; 142 143 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); 144 145 if (err !is null) 146 { 147 throw new GException( new ErrorG(err) ); 148 } 149 150 if(__p is null) 151 { 152 throw new ConstructionException("null returned by new_sync"); 153 } 154 155 this(cast(GDBusServer*) __p, true); 156 } 157 158 /** 159 * Gets a 160 * [D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses) 161 * string that can be used by clients to connect to @server. 162 * 163 * Returns: A D-Bus address string. Do not free, the string is owned 164 * by @server. 165 * 166 * Since: 2.26 167 */ 168 public string getClientAddress() 169 { 170 return Str.toString(g_dbus_server_get_client_address(gDBusServer)); 171 } 172 173 /** 174 * Gets the flags for @server. 175 * 176 * Returns: A set of flags from the #GDBusServerFlags enumeration. 177 * 178 * Since: 2.26 179 */ 180 public GDBusServerFlags getFlags() 181 { 182 return g_dbus_server_get_flags(gDBusServer); 183 } 184 185 /** 186 * Gets the GUID for @server. 187 * 188 * Returns: A D-Bus GUID. Do not free this string, it is owned by @server. 189 * 190 * Since: 2.26 191 */ 192 public string getGuid() 193 { 194 return Str.toString(g_dbus_server_get_guid(gDBusServer)); 195 } 196 197 /** 198 * Gets whether @server is active. 199 * 200 * Returns: %TRUE if server is active, %FALSE otherwise. 201 * 202 * Since: 2.26 203 */ 204 public bool isActive() 205 { 206 return g_dbus_server_is_active(gDBusServer) != 0; 207 } 208 209 /** 210 * Starts @server. 211 * 212 * Since: 2.26 213 */ 214 public void start() 215 { 216 g_dbus_server_start(gDBusServer); 217 } 218 219 /** 220 * Stops @server. 221 * 222 * Since: 2.26 223 */ 224 public void stop() 225 { 226 g_dbus_server_stop(gDBusServer); 227 } 228 229 /** 230 * Emitted when a new authenticated connection has been made. Use 231 * g_dbus_connection_get_peer_credentials() to figure out what 232 * identity (if any), was authenticated. 233 * 234 * If you want to accept the connection, take a reference to the 235 * @connection object and return %TRUE. When you are done with the 236 * connection call g_dbus_connection_close() and give up your 237 * reference. Note that the other peer may disconnect at any time - 238 * a typical thing to do when accepting a connection is to listen to 239 * the #GDBusConnection::closed signal. 240 * 241 * If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD 242 * then the signal is emitted in a new thread dedicated to the 243 * connection. Otherwise the signal is emitted in the 244 * [thread-default main context][g-main-context-push-thread-default] 245 * of the thread that @server was constructed in. 246 * 247 * You are guaranteed that signal handlers for this signal runs 248 * before incoming messages on @connection are processed. This means 249 * that it's suitable to call g_dbus_connection_register_object() or 250 * similar from the signal handler. 251 * 252 * Params: 253 * connection = A #GDBusConnection for the new connection. 254 * 255 * Returns: %TRUE to claim @connection, %FALSE to let other handlers 256 * run. 257 * 258 * Since: 2.26 259 */ 260 gulong addOnNewConnection(bool delegate(DBusConnection, DBusServer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 261 { 262 return Signals.connect(this, "new-connection", dlg, connectFlags ^ ConnectFlags.SWAPPED); 263 } 264 }