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.ThreadedSocketService;
26 
27 private import gio.SocketConnection;
28 private import gio.SocketService;
29 private import gio.c.functions;
30 public  import gio.c.types;
31 private import glib.ConstructionException;
32 private import gobject.ObjectG;
33 private import gobject.Signals;
34 private import std.algorithm;
35 
36 
37 /**
38  * A #GThreadedSocketService is a simple subclass of #GSocketService
39  * that handles incoming connections by creating a worker thread and
40  * dispatching the connection to it by emitting the
41  * #GThreadedSocketService::run signal in the new thread.
42  * 
43  * The signal handler may perform blocking IO and need not return
44  * until the connection is closed.
45  * 
46  * The service is implemented using a thread pool, so there is a
47  * limited amount of threads available to serve incoming requests.
48  * The service automatically stops the #GSocketService from accepting
49  * new connections when all threads are busy.
50  * 
51  * As with #GSocketService, you may connect to #GThreadedSocketService::run,
52  * or subclass and override the default handler.
53  *
54  * Since: 2.22
55  */
56 public class ThreadedSocketService : SocketService
57 {
58 	/** the main Gtk struct */
59 	protected GThreadedSocketService* gThreadedSocketService;
60 
61 	/** Get the main Gtk struct */
62 	public GThreadedSocketService* getThreadedSocketServiceStruct(bool transferOwnership = false)
63 	{
64 		if (transferOwnership)
65 			ownedRef = false;
66 		return gThreadedSocketService;
67 	}
68 
69 	/** the main Gtk struct as a void* */
70 	protected override void* getStruct()
71 	{
72 		return cast(void*)gThreadedSocketService;
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GThreadedSocketService* gThreadedSocketService, bool ownedRef = false)
79 	{
80 		this.gThreadedSocketService = gThreadedSocketService;
81 		super(cast(GSocketService*)gThreadedSocketService, ownedRef);
82 	}
83 
84 
85 	/** */
86 	public static GType getType()
87 	{
88 		return g_threaded_socket_service_get_type();
89 	}
90 
91 	/**
92 	 * Creates a new #GThreadedSocketService with no listeners. Listeners
93 	 * must be added with one of the #GSocketListener "add" methods.
94 	 *
95 	 * Params:
96 	 *     maxThreads = the maximal number of threads to execute concurrently
97 	 *         handling incoming clients, -1 means no limit
98 	 *
99 	 * Returns: a new #GSocketService.
100 	 *
101 	 * Since: 2.22
102 	 *
103 	 * Throws: ConstructionException GTK+ fails to create the object.
104 	 */
105 	public this(int maxThreads)
106 	{
107 		auto __p = g_threaded_socket_service_new(maxThreads);
108 
109 		if(__p is null)
110 		{
111 			throw new ConstructionException("null returned by new");
112 		}
113 
114 		this(cast(GThreadedSocketService*) __p, true);
115 	}
116 
117 	/**
118 	 * The ::run signal is emitted in a worker thread in response to an
119 	 * incoming connection. This thread is dedicated to handling
120 	 * @connection and may perform blocking IO. The signal handler need
121 	 * not return until the connection is closed.
122 	 *
123 	 * Params:
124 	 *     connection = a new #GSocketConnection object.
125 	 *     sourceObject = the source_object passed to g_socket_listener_add_address().
126 	 *
127 	 * Returns: %TRUE to stop further signal handlers from being called
128 	 */
129 	gulong addOnRun(bool delegate(SocketConnection, ObjectG, ThreadedSocketService) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
130 	{
131 		return Signals.connect(this, "run", dlg, connectFlags ^ ConnectFlags.SWAPPED);
132 	}
133 }