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