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