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  = GSocketService.html
27  * outPack = gio
28  * outFile = SocketService
29  * strct   = GSocketService
30  * realStrct=
31  * ctorStrct=
32  * clss    = SocketService
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_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.SocketService;
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.SocketListener;
67 
68 /**
69  * Description
70  * A GSocketService is an object that represents a service that is
71  * provided to the network or over local sockets. When a new
72  * connection is made to the service the "incoming"
73  * signal is emitted.
74  * A GSocketService is a subclass of GSocketListener and you need
75  * to add the addresses you want to accept connections on to the
76  * with the GSocketListener APIs.
77  * There are two options for implementing a network service based on
78  * GSocketService. The first is to create the service using
79  * g_socket_service_new() and to connect to the "incoming"
80  * signal. The second is to subclass GSocketService and override the
81  * default signal handler implementation.
82  * In either case, the handler must immediately return, or else it
83  * will block additional incoming connections from being serviced.
84  * If you are interested in writing connection handlers that contain
85  * blocking code then see GThreadedSocketService.
86  * The socket service runs on the main loop in the main thread, and is
87  * not threadsafe in general. However, the calls to start and stop
88  * the service are threadsafe so these can be used from threads that
89  * handle incoming clients.
90  */
91 public class SocketService : SocketListener
92 {
93 	
94 	/** the main Gtk struct */
95 	protected GSocketService* gSocketService;
96 	
97 	
98 	public GSocketService* getSocketServiceStruct()
99 	{
100 		return gSocketService;
101 	}
102 	
103 	
104 	/** the main Gtk struct as a void* */
105 	protected override void* getStruct()
106 	{
107 		return cast(void*)gSocketService;
108 	}
109 	
110 	/**
111 	 * Sets our main struct and passes it to the parent class
112 	 */
113 	public this (GSocketService* gSocketService)
114 	{
115 		super(cast(GSocketListener*)gSocketService);
116 		this.gSocketService = gSocketService;
117 	}
118 	
119 	protected override void setStruct(GObject* obj)
120 	{
121 		super.setStruct(obj);
122 		gSocketService = cast(GSocketService*)obj;
123 	}
124 	
125 	/**
126 	 */
127 	int[string] connectedSignals;
128 	
129 	bool delegate(GSocketConnection*, GObject*, SocketService)[] onIncomingListeners;
130 	/**
131 	 * The ::incoming signal is emitted when a new incoming connection
132 	 * to service needs to be handled. The handler must initiate the
133 	 * handling of connection, but may not block; in essence,
134 	 * asynchronous operations must be used.
135 	 * TRUE to stop other handlers from being called
136 	 * Since 2.22
137 	 * See Also
138 	 * GThreadedSocketService, GSocketListener.
139 	 */
140 	void addOnIncoming(bool delegate(GSocketConnection*, GObject*, SocketService) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
141 	{
142 		if ( !("incoming" in connectedSignals) )
143 		{
144 			Signals.connectData(
145 			getStruct(),
146 			"incoming",
147 			cast(GCallback)&callBackIncoming,
148 			cast(void*)this,
149 			null,
150 			connectFlags);
151 			connectedSignals["incoming"] = 1;
152 		}
153 		onIncomingListeners ~= dlg;
154 	}
155 	extern(C) static gboolean callBackIncoming(GSocketService* serviceStruct, GSocketConnection* connection, GObject* sourceObject, SocketService _socketService)
156 	{
157 		foreach ( bool delegate(GSocketConnection*, GObject*, SocketService) dlg ; _socketService.onIncomingListeners )
158 		{
159 			if ( dlg(connection, sourceObject, _socketService) )
160 			{
161 				return 1;
162 			}
163 		}
164 		
165 		return 0;
166 	}
167 	
168 	
169 	/**
170 	 * Creates a new GSocketService with no sockets to listen for.
171 	 * New listeners can be added with e.g. g_socket_listener_add_address()
172 	 * or g_socket_listener_add_inet_port().
173 	 * Since 2.22
174 	 * Throws: ConstructionException GTK+ fails to create the object.
175 	 */
176 	public this ()
177 	{
178 		// GSocketService * g_socket_service_new (void);
179 		auto p = g_socket_service_new();
180 		if(p is null)
181 		{
182 			throw new ConstructionException("null returned by g_socket_service_new()");
183 		}
184 		this(cast(GSocketService*) p);
185 	}
186 	
187 	/**
188 	 * Starts the service, i.e. start accepting connections
189 	 * from the added sockets when the mainloop runs.
190 	 * This call is threadsafe, so it may be called from a thread
191 	 * handling an incomming client request.
192 	 * Since 2.22
193 	 */
194 	public void start()
195 	{
196 		// void g_socket_service_start (GSocketService *service);
197 		g_socket_service_start(gSocketService);
198 	}
199 	
200 	/**
201 	 * Stops the service, i.e. stops accepting connections
202 	 * from the added sockets when the mainloop runs.
203 	 * This call is threadsafe, so it may be called from a thread
204 	 * handling an incomming client request.
205 	 * Since 2.22
206 	 */
207 	public void stop()
208 	{
209 		// void g_socket_service_stop (GSocketService *service);
210 		g_socket_service_stop(gSocketService);
211 	}
212 	
213 	/**
214 	 * Check whether the service is active or not. An active
215 	 * service will accept new clients that connect, while
216 	 * a non-active service will let connecting clients queue
217 	 * up until the service is started.
218 	 * Since 2.22
219 	 * Signal Details
220 	 * The "incoming" signal
221 	 * gboolean user_function (GSocketService *service,
222 	 *  GSocketConnection *connection,
223 	 *  GObject *source_object,
224 	 *  gpointer user_data) : Run Last
225 	 * The ::incoming signal is emitted when a new incoming connection
226 	 * to service needs to be handled. The handler must initiate the
227 	 * handling of connection, but may not block; in essence,
228 	 * asynchronous operations must be used.
229 	 * Since 2.22
230 	 * Returns: TRUE if the service is active, FALSE otherwiseReturns: TRUE to stop other handlers from being called
231 	 */
232 	public int isActive()
233 	{
234 		// gboolean g_socket_service_is_active (GSocketService *service);
235 		return g_socket_service_is_active(gSocketService);
236 	}
237 }