| 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 = GSocketConnection.html |
|---|
| 27 |
* outPack = gio |
|---|
| 28 |
* outFile = SocketConnection |
|---|
| 29 |
* strct = GSocketConnection |
|---|
| 30 |
* realStrct= |
|---|
| 31 |
* ctorStrct= |
|---|
| 32 |
* clss = SocketConnection |
|---|
| 33 |
* interf = |
|---|
| 34 |
* class Code: No |
|---|
| 35 |
* interface Code: No |
|---|
| 36 |
* template for: |
|---|
| 37 |
* extend = |
|---|
| 38 |
* implements: |
|---|
| 39 |
* prefixes: |
|---|
| 40 |
* - g_socket_connection_ |
|---|
| 41 |
* omit structs: |
|---|
| 42 |
* omit prefixes: |
|---|
| 43 |
* - g_tcp_connection_ |
|---|
| 44 |
* - g_unix_connection_ |
|---|
| 45 |
* omit code: |
|---|
| 46 |
* omit signals: |
|---|
| 47 |
* imports: |
|---|
| 48 |
* - glib.ErrorG |
|---|
| 49 |
* - glib.GException |
|---|
| 50 |
* - gio.Socket |
|---|
| 51 |
* - gio.SocketAddress |
|---|
| 52 |
* structWrap: |
|---|
| 53 |
* - GSocket* -> Socket |
|---|
| 54 |
* - GSocketAddress* -> SocketAddress |
|---|
| 55 |
* - GSocketConnection* -> SocketConnection |
|---|
| 56 |
* module aliases: |
|---|
| 57 |
* local aliases: |
|---|
| 58 |
* overrides: |
|---|
| 59 |
*/ |
|---|
| 60 |
|
|---|
| 61 |
module gio.SocketConnection; |
|---|
| 62 |
|
|---|
| 63 |
public import gtkc.giotypes; |
|---|
| 64 |
|
|---|
| 65 |
private import gtkc.gio; |
|---|
| 66 |
private import glib.ConstructionException; |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
private import glib.ErrorG; |
|---|
| 70 |
private import glib.GException; |
|---|
| 71 |
private import gio.Socket; |
|---|
| 72 |
private import gio.SocketAddress; |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
private import gio.IOStream; |
|---|
| 77 |
|
|---|
| 78 |
/** |
|---|
| 79 |
* Description |
|---|
| 80 |
* GSocketConnection is a GIOStream for a connected socket. They |
|---|
| 81 |
* can be created either by GSocketClient when connecting to a host, |
|---|
| 82 |
* or by GSocketListener when accepting a new client. |
|---|
| 83 |
* The type of the GSocketConnection object returned from these calls |
|---|
| 84 |
* depends on the type of the underlying socket that is in use. For |
|---|
| 85 |
* instance, for a TCP/IP connection it will be a GTcpConnection. |
|---|
| 86 |
* Chosing what type of object to construct is done with the socket |
|---|
| 87 |
* connection factory, and it is possible for 3rd parties to register |
|---|
| 88 |
* custom socket connection types for specific combination of socket |
|---|
| 89 |
* family/type/protocol using g_socket_connection_factory_register_type(). |
|---|
| 90 |
*/ |
|---|
| 91 |
public class SocketConnection : IOStream |
|---|
| 92 |
{ |
|---|
| 93 |
|
|---|
| 94 |
/** the main Gtk struct */ |
|---|
| 95 |
protected GSocketConnection* gSocketConnection; |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
public GSocketConnection* getSocketConnectionStruct() |
|---|
| 99 |
{ |
|---|
| 100 |
return gSocketConnection; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
/** the main Gtk struct as a void* */ |
|---|
| 105 |
protected override void* getStruct() |
|---|
| 106 |
{ |
|---|
| 107 |
return cast(void*)gSocketConnection; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
/** |
|---|
| 111 |
* Sets our main struct and passes it to the parent class |
|---|
| 112 |
*/ |
|---|
| 113 |
public this (GSocketConnection* gSocketConnection) |
|---|
| 114 |
{ |
|---|
| 115 |
if(gSocketConnection is null) |
|---|
| 116 |
{ |
|---|
| 117 |
this = null; |
|---|
| 118 |
return; |
|---|
| 119 |
} |
|---|
| 120 |
//Check if there already is a D object for this gtk struct |
|---|
| 121 |
void* ptr = getDObject(cast(GObject*)gSocketConnection); |
|---|
| 122 |
if( ptr !is null ) |
|---|
| 123 |
{ |
|---|
| 124 |
this = cast(SocketConnection)ptr; |
|---|
| 125 |
return; |
|---|
| 126 |
} |
|---|
| 127 |
super(cast(GIOStream*)gSocketConnection); |
|---|
| 128 |
this.gSocketConnection = gSocketConnection; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
protected override void setStruct(GObject* obj) |
|---|
| 132 |
{ |
|---|
| 133 |
super.setStruct(obj); |
|---|
| 134 |
gSocketConnection = cast(GSocketConnection*)obj; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
/** |
|---|
| 138 |
*/ |
|---|
| 139 |
|
|---|
| 140 |
/** |
|---|
| 141 |
* Try to get the local address of a socket connection. |
|---|
| 142 |
* Since 2.22 |
|---|
| 143 |
* Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref(). [transfer full] |
|---|
| 144 |
* Throws: GException on failure. |
|---|
| 145 |
*/ |
|---|
| 146 |
public SocketAddress getLocalAddress() |
|---|
| 147 |
{ |
|---|
| 148 |
// GSocketAddress * g_socket_connection_get_local_address (GSocketConnection *connection, GError **error); |
|---|
| 149 |
GError* err = null; |
|---|
| 150 |
|
|---|
| 151 |
auto p = g_socket_connection_get_local_address(gSocketConnection, &err); |
|---|
| 152 |
|
|---|
| 153 |
if (err !is null) |
|---|
| 154 |
{ |
|---|
| 155 |
throw new GException( new ErrorG(err) ); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
if(p is null) |
|---|
| 159 |
{ |
|---|
| 160 |
return null; |
|---|
| 161 |
} |
|---|
| 162 |
return new SocketAddress(cast(GSocketAddress*) p); |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
/** |
|---|
| 166 |
* Try to get the remote address of a socket connection. |
|---|
| 167 |
* Since 2.22 |
|---|
| 168 |
* Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref(). [transfer full] |
|---|
| 169 |
* Throws: GException on failure. |
|---|
| 170 |
*/ |
|---|
| 171 |
public SocketAddress getRemoteAddress() |
|---|
| 172 |
{ |
|---|
| 173 |
// GSocketAddress * g_socket_connection_get_remote_address (GSocketConnection *connection, GError **error); |
|---|
| 174 |
GError* err = null; |
|---|
| 175 |
|
|---|
| 176 |
auto p = g_socket_connection_get_remote_address(gSocketConnection, &err); |
|---|
| 177 |
|
|---|
| 178 |
if (err !is null) |
|---|
| 179 |
{ |
|---|
| 180 |
throw new GException( new ErrorG(err) ); |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
if(p is null) |
|---|
| 184 |
{ |
|---|
| 185 |
return null; |
|---|
| 186 |
} |
|---|
| 187 |
return new SocketAddress(cast(GSocketAddress*) p); |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
/** |
|---|
| 191 |
* Gets the underlying GSocket object of the connection. |
|---|
| 192 |
* This can be useful if you want to do something unusual on it |
|---|
| 193 |
* not supported by the GSocketConnection APIs. |
|---|
| 194 |
* Since 2.22 |
|---|
| 195 |
* Returns: a GSocketAddress or NULL on error. [transfer none] |
|---|
| 196 |
*/ |
|---|
| 197 |
public Socket getSocket() |
|---|
| 198 |
{ |
|---|
| 199 |
// GSocket * g_socket_connection_get_socket (GSocketConnection *connection); |
|---|
| 200 |
auto p = g_socket_connection_get_socket(gSocketConnection); |
|---|
| 201 |
if(p is null) |
|---|
| 202 |
{ |
|---|
| 203 |
return null; |
|---|
| 204 |
} |
|---|
| 205 |
return new Socket(cast(GSocket*) p); |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
/** |
|---|
| 209 |
* Creates a GSocketConnection subclass of the right type for |
|---|
| 210 |
* socket. |
|---|
| 211 |
* Since 2.22 |
|---|
| 212 |
* Params: |
|---|
| 213 |
* socket = a GSocket |
|---|
| 214 |
* Returns: a GSocketConnection. [transfer full] |
|---|
| 215 |
*/ |
|---|
| 216 |
public static SocketConnection factoryCreateConnection(Socket socket) |
|---|
| 217 |
{ |
|---|
| 218 |
// GSocketConnection * g_socket_connection_factory_create_connection (GSocket *socket); |
|---|
| 219 |
auto p = g_socket_connection_factory_create_connection((socket is null) ? null : socket.getSocketStruct()); |
|---|
| 220 |
if(p is null) |
|---|
| 221 |
{ |
|---|
| 222 |
return null; |
|---|
| 223 |
} |
|---|
| 224 |
return new SocketConnection(cast(GSocketConnection*) p); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
/** |
|---|
| 228 |
* Looks up the GType to be used when creating socket connections on |
|---|
| 229 |
* sockets with the specified family,type and protocol_id. |
|---|
| 230 |
* If no type is registered, the GSocketConnection base type is returned. |
|---|
| 231 |
* Since 2.22 |
|---|
| 232 |
* Params: |
|---|
| 233 |
* family = a GSocketFamily |
|---|
| 234 |
* type = a GSocketType |
|---|
| 235 |
* protocolId = a protocol id |
|---|
| 236 |
* Returns: a GType |
|---|
| 237 |
*/ |
|---|
| 238 |
public static GType factoryLookupType(GSocketFamily family, GSocketType type, int protocolId) |
|---|
| 239 |
{ |
|---|
| 240 |
// GType g_socket_connection_factory_lookup_type (GSocketFamily family, GSocketType type, gint protocol_id); |
|---|
| 241 |
return g_socket_connection_factory_lookup_type(family, type, protocolId); |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
/** |
|---|
| 245 |
* Looks up the GType to be used when creating socket connections on |
|---|
| 246 |
* sockets with the specified family,type and protocol. |
|---|
| 247 |
* If no type is registered, the GSocketConnection base type is returned. |
|---|
| 248 |
* Since 2.22 |
|---|
| 249 |
* Params: |
|---|
| 250 |
* gType = a GType, inheriting from G_TYPE_SOCKET_CONNECTION |
|---|
| 251 |
* family = a GSocketFamily |
|---|
| 252 |
* type = a GSocketType |
|---|
| 253 |
* protocol = a protocol id |
|---|
| 254 |
*/ |
|---|
| 255 |
public static void factoryRegisterType(GType gType, GSocketFamily family, GSocketType type, int protocol) |
|---|
| 256 |
{ |
|---|
| 257 |
// void g_socket_connection_factory_register_type (GType g_type, GSocketFamily family, GSocketType type, gint protocol); |
|---|
| 258 |
g_socket_connection_factory_register_type(gType, family, type, protocol); |
|---|
| 259 |
} |
|---|
| 260 |
} |
|---|