First set of changes for windows
[cascardo/gnio.git] / gnio / ginetsocketaddress.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
27 #include "ginetsocketaddress.h"
28
29 G_DEFINE_TYPE (GInetSocketAddress, g_inet_socket_address, G_TYPE_SOCKET_ADDRESS);
30
31 enum {
32   PROP_0,
33   PROP_ADDRESS,
34   PROP_PORT
35 };
36
37 struct _GInetSocketAddressPrivate {
38   GInetAddress *address;
39   guint16       port;
40 };
41
42 static void
43 g_inet_socket_address_finalize (GObject *object)
44 {
45   GInetSocketAddress *address G_GNUC_UNUSED = G_INET_SOCKET_ADDRESS (object);
46
47   if (G_OBJECT_CLASS (g_inet_socket_address_parent_class)->finalize)
48     (*G_OBJECT_CLASS (g_inet_socket_address_parent_class)->finalize) (object);
49 }
50
51 static void
52 g_inet_socket_address_dispose (GObject *object)
53 {
54   GInetSocketAddress *address G_GNUC_UNUSED = G_INET_SOCKET_ADDRESS (object);
55
56   if (G_OBJECT_CLASS (g_inet_socket_address_parent_class)->dispose)
57     (*G_OBJECT_CLASS (g_inet_socket_address_parent_class)->dispose) (object);
58 }
59
60 static void
61 g_inet_socket_address_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
62 {
63   GInetSocketAddress *address = G_INET_SOCKET_ADDRESS (object);
64
65   switch (prop_id)
66     {
67       case PROP_ADDRESS:
68         g_value_set_object (value, address->priv->address);
69         break;
70
71       case PROP_PORT:
72         g_value_set_uint (value, address->priv->port);
73         break;
74
75       default:
76         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
77     }
78 }
79
80 static void
81 g_inet_socket_address_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
82 {
83   GInetSocketAddress *address = G_INET_SOCKET_ADDRESS (object);
84
85   switch (prop_id)
86     {
87       case PROP_ADDRESS:
88         address->priv->address = G_INET_ADDRESS (g_value_get_object (value));
89         break;
90
91       case PROP_PORT:
92         address->priv->port = (guint16) g_value_get_uint (value);
93     }
94 }
95
96 static void
97 g_inet_socket_address_class_init (GInetSocketAddressClass *klass)
98 {
99   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
100
101   g_type_class_add_private (klass, sizeof (GInetSocketAddressPrivate));
102
103   gobject_class->finalize = g_inet_socket_address_finalize;
104   gobject_class->dispose = g_inet_socket_address_dispose;
105   gobject_class->set_property = g_inet_socket_address_set_property;
106   gobject_class->get_property = g_inet_socket_address_get_property;
107
108   g_object_class_install_property (gobject_class, PROP_ADDRESS,
109                                    g_param_spec_object ("address",
110                                                         "address",
111                                                         "address",
112                                                         G_TYPE_INET_ADDRESS,
113                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
114
115   g_object_class_install_property (gobject_class, PROP_PORT,
116                                    g_param_spec_uint ("port",
117                                                       "port",
118                                                       "port",
119                                                       0,
120                                                       65535,
121                                                       0,
122                                                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
123 }
124
125 static void
126 g_inet_socket_address_init (GInetSocketAddress *address)
127 {
128   address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
129                                                G_TYPE_INET_SOCKET_ADDRESS,
130                                                GInetSocketAddressPrivate);
131 }
132
133
134 GInetSocketAddress *
135 g_inet_socket_address_new (GInetAddress *address, guint16 port)
136 {
137   return NULL;
138 }
139
140
141 GInetAddress *
142 g_inet_socket_address_get_address (GInetSocketAddress *sockaddr)
143 {
144   g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (sockaddr), NULL);
145
146   return sockaddr->priv->address;
147 }
148
149 guint16 
150 g_inet_socket_address_get_port (GInetSocketAddress *sockaddr)
151 {
152   g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (sockaddr), 0);
153
154   return sockaddr->priv->port;
155 }
156