| 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 = GSocketService.html |
|---|
| 27 |
* outPack = gio |
|---|
| 28 |
* outFile = SocketService |
|---|
| 29 |
* strct = GSocketService |
|---|
| 30 |
* realStrct= |
|---|
| 31 |
* ctorStrct= |
|---|
| 32 |
* clss = SocketService |
|---|
| 33 |
* interf = |
|---|
| 34 |
* class Code: No |
|---|
| 35 |
* interface Code: No |
|---|
| 36 |
* template for: |
|---|
| 37 |
* extend = |
|---|
| 38 |
* implements: |
|---|
| 39 |
* prefixes: |
|---|
| 40 |
* - g_socket_service_ |
|---|
| 41 |
* omit structs: |
|---|
| 42 |
* omit prefixes: |
|---|
| 43 |
* omit code: |
|---|
| 44 |
* omit signals: |
|---|
| 45 |
* imports: |
|---|
| 46 |
* structWrap: |
|---|
| 47 |
* module aliases: |
|---|
| 48 |
* local aliases: |
|---|
| 49 |
* overrides: |
|---|
| 50 |
*/ |
|---|
| 51 |
|
|---|
| 52 |
module gio.SocketService; |
|---|
| 53 |
|
|---|
| 54 |
public import gtkc.giotypes; |
|---|
| 55 |
|
|---|
| 56 |
private import gtkc.gio; |
|---|
| 57 |
private import glib.ConstructionException; |
|---|
| 58 |
|
|---|
| 59 |
private import gobject.Signals; |
|---|
| 60 |
public import gtkc.gdktypes; |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
private import gio.SocketListener; |
|---|
| 66 |
|
|---|
| 67 |
/** |
|---|
| 68 |
* Description |
|---|
| 69 |
* A GSocketService is an object that represents a service that is |
|---|
| 70 |
* provided to the network or over local sockets. When a new |
|---|
| 71 |
* connection is made to the service the "incoming" |
|---|
| 72 |
* signal is emitted. |
|---|
| 73 |
* A GSocketService is a subclass of GSocketListener and you need |
|---|
| 74 |
* to add the addresses you want to accept connections on to the |
|---|
| 75 |
* with the GSocketListener APIs. |
|---|
| 76 |
* There are two options for implementing a network service based on |
|---|
| 77 |
* GSocketService. The first is to create the service using |
|---|
| 78 |
* g_socket_service_new() and to connect to the "incoming" |
|---|
| 79 |
* signal. The second is to subclass GSocketService and override the |
|---|
| 80 |
* default signal handler implementation. |
|---|
| 81 |
* In either case, the handler must immediately return, or else it |
|---|
| 82 |
* will block additional incoming connections from being serviced. |
|---|
| 83 |
* If you are interested in writing connection handlers that contain |
|---|
| 84 |
* blocking code then see GThreadedSocketService. |
|---|
| 85 |
* The socket service runs on the main loop in the main thread, and is |
|---|
| 86 |
* not threadsafe in general. However, the calls to start and stop |
|---|
| 87 |
* the service are threadsafe so these can be used from threads that |
|---|
| 88 |
* handle incoming clients. |
|---|
| 89 |
*/ |
|---|
| 90 |
public class SocketService : SocketListener |
|---|
| 91 |
{ |
|---|
| 92 |
|
|---|
| 93 |
/** the main Gtk struct */ |
|---|
| 94 |
protected GSocketService* gSocketService; |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
public GSocketService* getSocketServiceStruct() |
|---|
| 98 |
{ |
|---|
| 99 |
return gSocketService; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
/** the main Gtk struct as a void* */ |
|---|
| 104 |
protected override void* getStruct() |
|---|
| 105 |
{ |
|---|
| 106 |
return cast(void*)gSocketService; |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
/** |
|---|
| 110 |
* Sets our main struct and passes it to the parent class |
|---|
| 111 |
*/ |
|---|
| 112 |
public this (GSocketService* gSocketService) |
|---|
| 113 |
{ |
|---|
| 114 |
if(gSocketService 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*)gSocketService); |
|---|
| 121 |
if( ptr !is null ) |
|---|
| 122 |
{ |
|---|
| 123 |
this = cast(SocketService)ptr; |
|---|
| 124 |
return; |
|---|
| 125 |
} |
|---|
| 126 |
super(cast(GSocketListener*)gSocketService); |
|---|
| 127 |
this.gSocketService = gSocketService; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
protected override void setStruct(GObject* obj) |
|---|
| 131 |
{ |
|---|
| 132 |
super.setStruct(obj); |
|---|
| 133 |
gSocketService = cast(GSocketService*)obj; |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
/** |
|---|
| 137 |
*/ |
|---|
| 138 |
int[string] connectedSignals; |
|---|
| 139 |
|
|---|
| 140 |
bool delegate(GSocketConnection*, GObject*, SocketService)[] onIncomingListeners; |
|---|
| 141 |
/** |
|---|
| 142 |
* The ::incoming signal is emitted when a new incoming connection |
|---|
| 143 |
* to service needs to be handled. The handler must initiate the |
|---|
| 144 |
* handling of connection, but may not block; in essence, |
|---|
| 145 |
* asynchronous operations must be used. |
|---|
| 146 |
* TRUE to stop other handlers from being called |
|---|
| 147 |
* Since 2.22 |
|---|
| 148 |
* See Also |
|---|
| 149 |
* GThreadedSocketService, GSocketListener. |
|---|
| 150 |
*/ |
|---|
| 151 |
void addOnIncoming(bool delegate(GSocketConnection*, GObject*, SocketService) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) |
|---|
| 152 |
{ |
|---|
| 153 |
if ( !("incoming" in connectedSignals) ) |
|---|
| 154 |
{ |
|---|
| 155 |
Signals.connectData( |
|---|
| 156 |
getStruct(), |
|---|
| 157 |
"incoming", |
|---|
| 158 |
cast(GCallback)&callBackIncoming, |
|---|
| 159 |
cast(void*)this, |
|---|
| 160 |
null, |
|---|
| 161 |
connectFlags); |
|---|
| 162 |
connectedSignals["incoming"] = 1; |
|---|
| 163 |
} |
|---|
| 164 |
onIncomingListeners ~= dlg; |
|---|
| 165 |
} |
|---|
| 166 |
extern(C) static gboolean callBackIncoming(GSocketService* serviceStruct, GSocketConnection* connection, GObject* sourceObject, SocketService socketService) |
|---|
| 167 |
{ |
|---|
| 168 |
foreach ( bool delegate(GSocketConnection*, GObject*, SocketService) dlg ; socketService.onIncomingListeners ) |
|---|
| 169 |
{ |
|---|
| 170 |
if ( dlg(connection, sourceObject, socketService) ) |
|---|
| 171 |
{ |
|---|
| 172 |
return 1; |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
return 0; |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
/** |
|---|
| 181 |
* Creates a new GSocketService with no sockets to listen for. |
|---|
| 182 |
* New listeners can be added with e.g. g_socket_listener_add_address() |
|---|
| 183 |
* or g_socket_listener_add_inet_port(). |
|---|
| 184 |
* Since 2.22 |
|---|
| 185 |
* Throws: ConstructionException GTK+ fails to create the object. |
|---|
| 186 |
*/ |
|---|
| 187 |
public this () |
|---|
| 188 |
{ |
|---|
| 189 |
// GSocketService * g_socket_service_new (void); |
|---|
| 190 |
auto p = g_socket_service_new(); |
|---|
| 191 |
if(p is null) |
|---|
| 192 |
{ |
|---|
| 193 |
throw new ConstructionException("null returned by g_socket_service_new()"); |
|---|
| 194 |
} |
|---|
| 195 |
this(cast(GSocketService*) p); |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
/** |
|---|
| 199 |
* Starts the service, i.e. start accepting connections |
|---|
| 200 |
* from the added sockets when the mainloop runs. |
|---|
| 201 |
* This call is threadsafe, so it may be called from a thread |
|---|
| 202 |
* handling an incomming client request. |
|---|
| 203 |
* Since 2.22 |
|---|
| 204 |
*/ |
|---|
| 205 |
public void start() |
|---|
| 206 |
{ |
|---|
| 207 |
// void g_socket_service_start (GSocketService *service); |
|---|
| 208 |
g_socket_service_start(gSocketService); |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
/** |
|---|
| 212 |
* Stops the service, i.e. stops accepting connections |
|---|
| 213 |
* from the added sockets when the mainloop runs. |
|---|
| 214 |
* This call is threadsafe, so it may be called from a thread |
|---|
| 215 |
* handling an incomming client request. |
|---|
| 216 |
* Since 2.22 |
|---|
| 217 |
*/ |
|---|
| 218 |
public void stop() |
|---|
| 219 |
{ |
|---|
| 220 |
// void g_socket_service_stop (GSocketService *service); |
|---|
| 221 |
g_socket_service_stop(gSocketService); |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
/** |
|---|
| 225 |
* Check whether the service is active or not. An active |
|---|
| 226 |
* service will accept new clients that connect, while |
|---|
| 227 |
* a non-active service will let connecting clients queue |
|---|
| 228 |
* up until the service is started. |
|---|
| 229 |
* Since 2.22 |
|---|
| 230 |
* Signal Details |
|---|
| 231 |
* The "incoming" signal |
|---|
| 232 |
* gboolean user_function (GSocketService *service, |
|---|
| 233 |
* GSocketConnection *connection, |
|---|
| 234 |
* GObject *source_object, |
|---|
| 235 |
* gpointer user_data) : Run Last |
|---|
| 236 |
* The ::incoming signal is emitted when a new incoming connection |
|---|
| 237 |
* to service needs to be handled. The handler must initiate the |
|---|
| 238 |
* handling of connection, but may not block; in essence, |
|---|
| 239 |
* asynchronous operations must be used. |
|---|
| 240 |
* Since 2.22 |
|---|
| 241 |
* Returns: TRUE if the service is active, FALSE otherwiseReturns: TRUE to stop other handlers from being called |
|---|
| 242 |
*/ |
|---|
| 243 |
public int isActive() |
|---|
| 244 |
{ |
|---|
| 245 |
// gboolean g_socket_service_is_active (GSocketService *service); |
|---|
| 246 |
return g_socket_service_is_active(gSocketService); |
|---|
| 247 |
} |
|---|
| 248 |
} |
|---|