4898399873deb0ad55f5e97f8a128ee93fa59961
[cascardo/gnio.git] / gnio / gtcpclient.c
1 /* GNIO - GLib Network Layer of GIO
2  *
3  * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Authors: Christian Kellner <gicmo@gnome.org>
21  *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
22  */
23
24 #include <config.h>
25 #include <glib.h>
26 #include <gio/gio.h>
27 #include <gio/gasynchelper.h>
28
29 #include <string.h>
30 #include <errno.h>
31
32 #include "ginetaddress.h"
33 #include "ginet4address.h"
34 #include "ginet6address.h"
35 #include "gsocket.h"
36 #include "gtcpclient.h"
37 #include "gnioerror.h"
38 #include "ginetsocketaddress.h"
39
40 G_DEFINE_TYPE (GTcpClient, g_tcp_client, G_TYPE_OBJECT);
41
42 enum
43 {
44   PROP_0,
45   PROP_ADDRESS
46 };
47
48 struct _GTcpClientPrivate
49 {
50   GSocketAddress *address;
51 };
52
53 static void
54 g_tcp_client_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
55 {
56   GTcpClient *client = G_TCP_CLIENT (object);
57
58   switch (prop_id)
59     {
60       case PROP_ADDRESS:
61         g_value_set_object (value, client->priv->address);
62         break;
63
64       default:
65         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
66     }
67 }
68
69 static void
70 g_tcp_client_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
71 {
72   GTcpClient *client = G_TCP_CLIENT (object);
73
74   switch (prop_id)
75     {
76       default:
77         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
78     }
79 }
80
81 static void
82 g_tcp_client_finalize (GObject *object)
83 {
84   GTcpClient *client = G_TCP_CLIENT (object);
85
86   if (G_OBJECT_CLASS (g_tcp_client_parent_class)->finalize)
87     (*G_OBJECT_CLASS (g_tcp_client_parent_class)->finalize) (object);
88 }
89
90 static void
91 g_tcp_client_dispose (GObject *object)
92 {
93   GTcpClient *client = G_TCP_CLIENT (object);
94
95   if (G_OBJECT_CLASS (g_tcp_client_parent_class)->dispose)
96     (*G_OBJECT_CLASS (g_tcp_client_parent_class)->dispose) (object);
97 }
98
99 static void
100 g_tcp_client_class_init (GTcpClientClass *klass)
101 {
102   GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
103
104   g_type_class_add_private (klass, sizeof (GTcpClientPrivate));
105
106   gobject_class->finalize = g_tcp_client_finalize;
107   gobject_class->dispose = g_tcp_client_dispose;
108   gobject_class->set_property = g_tcp_client_set_property;
109   gobject_class->get_property = g_tcp_client_get_property;
110
111   g_object_class_install_property (gobject_class, PROP_ADDRESS,
112                                    g_param_spec_object ("address",
113                                                         "address",
114                                                         "the remote address the socket will connect to",
115                                                         G_TYPE_SOCKET_ADDRESS,
116                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
117 }
118
119 static void
120 g_tcp_client_init (GTcpClient *client)
121 {
122   client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client, G_TYPE_TCP_CLIENT, GTcpClientPrivate);
123 }
124
125 GTcpClient *
126 g_tcp_client_new (const gchar *hostname,
127                   gushort      port)
128 {
129   return NULL;
130 }
131
132 GTcpClient *
133 g_tcp_client_new_with_address (GInetSocketAddress *address)
134 {
135   return NULL;
136 }
137
138 gboolean
139 g_tcp_client_connect (GTcpClient    *client,
140                       GCancellable  *cancellable,
141                       GError       **error)
142 {
143   return FALSE;
144 }
145
146 typedef struct {
147   GAsyncReadyCallback  callback;
148   GCancellable        *cancellable;
149   gpointer             user_data;
150   GTcpClient          *client;
151   gchar                address_buffer[256];
152   gsize                address_length;
153 } ConnectData;
154
155 static gboolean
156 connect_callback (ConnectData *data,
157                   GIOCondition condition,
158                   gint fd)
159 {
160   return FALSE;
161 }
162
163 void
164 g_tcp_client_connect_async (GTcpClient          *client,
165                             GCancellable        *cancellable,
166                             GAsyncReadyCallback  callback,
167                             gpointer             user_data)
168 {
169
170 }
171
172 gboolean
173 g_tcp_client_connect_finish (GTcpClient    *client,
174                              GAsyncResult  *result,
175                              GError       **error)
176 {
177   GSimpleAsyncResult *simple;
178
179   g_return_val_if_fail (G_IS_TCP_CLIENT (client), FALSE);
180
181   simple = G_SIMPLE_ASYNC_RESULT (result);
182
183   if (g_simple_async_result_propagate_error (simple, error))
184     return FALSE;
185
186   g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_tcp_client_connect_async);
187
188   return TRUE;
189 }
190
191 void
192 g_tcp_client_close (GTcpClient *tcp_client)
193 {
194   g_return_if_fail (G_IS_TCP_CLIENT (tcp_client));
195 }