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