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 = GThreadedSocketService.html 27 * outPack = gio 28 * outFile = ThreadedSocketService 29 * strct = GThreadedSocketService 30 * realStrct= 31 * ctorStrct=GSocketService 32 * clss = ThreadedSocketService 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_threaded_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.ThreadedSocketService; 53 54 public import gtkc.giotypes; 55 56 private import gtkc.gio; 57 private import glib.ConstructionException; 58 private import gobject.ObjectG; 59 60 private import gobject.Signals; 61 public import gtkc.gdktypes; 62 63 64 private import gio.SocketService; 65 66 /** 67 * A GThreadedSocketService is a simple subclass of GSocketService 68 * that handles incoming connections by creating a worker thread and 69 * dispatching the connection to it by emitting the 70 * "run" signal in the new thread. 71 * 72 * The signal handler may perform blocking IO and need not return 73 * until the connection is closed. 74 * 75 * The service is implemented using a thread pool, so there is a 76 * limited amount of threads available to serve incoming requests. 77 * The service automatically stops the GSocketService from accepting 78 * new connections when all threads are busy. 79 * 80 * As with GSocketService, you may connect to "run", 81 * or subclass and override the default handler. 82 */ 83 public class ThreadedSocketService : SocketService 84 { 85 86 /** the main Gtk struct */ 87 protected GThreadedSocketService* gThreadedSocketService; 88 89 90 /** Get the main Gtk struct */ 91 public GThreadedSocketService* getThreadedSocketServiceStruct() 92 { 93 return gThreadedSocketService; 94 } 95 96 97 /** the main Gtk struct as a void* */ 98 protected override void* getStruct() 99 { 100 return cast(void*)gThreadedSocketService; 101 } 102 103 /** 104 * Sets our main struct and passes it to the parent class 105 */ 106 public this (GThreadedSocketService* gThreadedSocketService) 107 { 108 super(cast(GSocketService*)gThreadedSocketService); 109 this.gThreadedSocketService = gThreadedSocketService; 110 } 111 112 protected override void setStruct(GObject* obj) 113 { 114 super.setStruct(obj); 115 gThreadedSocketService = cast(GThreadedSocketService*)obj; 116 } 117 118 /** 119 */ 120 int[string] connectedSignals; 121 122 bool delegate(GSocketConnection*, GObject*, ThreadedSocketService)[] onRunListeners; 123 /** 124 * The ::run signal is emitted in a worker thread in response to an 125 * incoming connection. This thread is dedicated to handling 126 * connection and may perform blocking IO. The signal handler need 127 * not return until the connection is closed. 128 * TRUE to stop further signal handlers from being called 129 * See Also 130 * GSocketService. 131 */ 132 void addOnRun(bool delegate(GSocketConnection*, GObject*, ThreadedSocketService) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 133 { 134 if ( !("run" in connectedSignals) ) 135 { 136 Signals.connectData( 137 getStruct(), 138 "run", 139 cast(GCallback)&callBackRun, 140 cast(void*)this, 141 null, 142 connectFlags); 143 connectedSignals["run"] = 1; 144 } 145 onRunListeners ~= dlg; 146 } 147 extern(C) static gboolean callBackRun(GThreadedSocketService* serviceStruct, GSocketConnection* connection, GObject* sourceObject, ThreadedSocketService _threadedSocketService) 148 { 149 foreach ( bool delegate(GSocketConnection*, GObject*, ThreadedSocketService) dlg ; _threadedSocketService.onRunListeners ) 150 { 151 if ( dlg(connection, sourceObject, _threadedSocketService) ) 152 { 153 return 1; 154 } 155 } 156 157 return 0; 158 } 159 160 161 /** 162 * Creates a new GThreadedSocketService with no listeners. Listeners 163 * must be added with one of the GSocketListener "add" methods. 164 * Since 2.22 165 * Params: 166 * maxThreads = the maximal number of threads to execute concurrently 167 * handling incoming clients, -1 means no limit 168 * Throws: ConstructionException GTK+ fails to create the object. 169 */ 170 public this (int maxThreads) 171 { 172 // GSocketService * g_threaded_socket_service_new (int max_threads); 173 auto p = g_threaded_socket_service_new(maxThreads); 174 if(p is null) 175 { 176 throw new ConstructionException("null returned by g_threaded_socket_service_new(maxThreads)"); 177 } 178 this(cast(GThreadedSocketService*) p); 179 } 180 }