root/trunk/src/gio/ThreadedSocketService.d

Revision 951, 5.3 kB (checked in by Mike Wey, 2 weeks ago)

Merge github pull request 7.

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