source: appstream-generator/build/girepo/gio/ThreadedSocketService.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 5.2 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.ThreadedSocketService;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.SocketConnection;
26private import gio.SocketService;
27private import glib.ConstructionException;
28private import gobject.ObjectG;
29private import gobject.Signals;
30private import std.algorithm;
31
32
33/**
34 * A #GThreadedSocketService is a simple subclass of #GSocketService
35 * that handles incoming connections by creating a worker thread and
36 * dispatching the connection to it by emitting the
37 * #GThreadedSocketService::run signal in the new thread.
38 *
39 * The signal handler may perform blocking IO and need not return
40 * until the connection is closed.
41 *
42 * The service is implemented using a thread pool, so there is a
43 * limited amount of threads available to serve incoming requests.
44 * The service automatically stops the #GSocketService from accepting
45 * new connections when all threads are busy.
46 *
47 * As with #GSocketService, you may connect to #GThreadedSocketService::run,
48 * or subclass and override the default handler.
49 *
50 * Since: 2.22
51 */
52public class ThreadedSocketService : SocketService
53{
54        /** the main Gtk struct */
55        protected GThreadedSocketService* gThreadedSocketService;
56
57        /** Get the main Gtk struct */
58        public GThreadedSocketService* getThreadedSocketServiceStruct()
59        {
60                return gThreadedSocketService;
61        }
62
63        /** the main Gtk struct as a void* */
64        protected override void* getStruct()
65        {
66                return cast(void*)gThreadedSocketService;
67        }
68
69        protected override void setStruct(GObject* obj)
70        {
71                gThreadedSocketService = cast(GThreadedSocketService*)obj;
72                super.setStruct(obj);
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        protected class OnRunDelegateWrapper
118        {
119                static OnRunDelegateWrapper[] listeners;
120                bool delegate(SocketConnection, ObjectG, ThreadedSocketService) dlg;
121                gulong handlerId;
122               
123                this(bool delegate(SocketConnection, ObjectG, ThreadedSocketService) dlg)
124                {
125                        this.dlg = dlg;
126                        this.listeners ~= this;
127                }
128               
129                void remove(OnRunDelegateWrapper source)
130                {
131                        foreach(index, wrapper; listeners)
132                        {
133                                if (wrapper.handlerId == source.handlerId)
134                                {
135                                        listeners[index] = null;
136                                        listeners = std.algorithm.remove(listeners, index);
137                                        break;
138                                }
139                        }
140                }
141        }
142
143        /**
144         * The ::run signal is emitted in a worker thread in response to an
145         * incoming connection. This thread is dedicated to handling
146         * @connection and may perform blocking IO. The signal handler need
147         * not return until the connection is closed.
148         *
149         * Params:
150         *     connection = a new #GSocketConnection object.
151         *     sourceObject = the source_object passed to g_socket_listener_add_address().
152         *
153         * Returns: %TRUE to stop further signal handlers from being called
154         */
155        gulong addOnRun(bool delegate(SocketConnection, ObjectG, ThreadedSocketService) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
156        {
157                auto wrapper = new OnRunDelegateWrapper(dlg);
158                wrapper.handlerId = Signals.connectData(
159                        this,
160                        "run",
161                        cast(GCallback)&callBackRun,
162                        cast(void*)wrapper,
163                        cast(GClosureNotify)&callBackRunDestroy,
164                        connectFlags);
165                return wrapper.handlerId;
166        }
167       
168        extern(C) static int callBackRun(GThreadedSocketService* threadedsocketserviceStruct, GSocketConnection* connection, GObject* sourceObject, OnRunDelegateWrapper wrapper)
169        {
170                return wrapper.dlg(ObjectG.getDObject!(SocketConnection)(connection), ObjectG.getDObject!(ObjectG)(sourceObject), wrapper.outer);
171        }
172       
173        extern(C) static void callBackRunDestroy(OnRunDelegateWrapper wrapper, GClosure* closure)
174        {
175                wrapper.remove(wrapper);
176        }
177}
Note: See TracBrowser for help on using the repository browser.