1 /* GNIO - GLib Network Layer of GIO
3 * Copyright (C) 2008 Christian Kellner
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.
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.
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.
20 * Author: Christian Kellner <gicmo@gnome.org>
26 #include "ginetsocketaddress.h"
28 G_DEFINE_TYPE (GInetSocketAddress, g_inet_socket_address, G_TYPE_SOCKET_ADDRESS);
36 struct _GInetSocketAddressPrivate {
37 GInetAddress *address;
42 g_inet_socket_address_finalize (GObject *object)
44 GInetSocketAddress *address G_GNUC_UNUSED = G_INET_SOCKET_ADDRESS (object);
46 if (G_OBJECT_CLASS (g_inet_socket_address_parent_class)->finalize)
47 (*G_OBJECT_CLASS (g_inet_socket_address_parent_class)->finalize) (object);
51 g_inet_socket_address_dispose (GObject *object)
53 GInetSocketAddress *address G_GNUC_UNUSED = G_INET_SOCKET_ADDRESS (object);
55 if (G_OBJECT_CLASS (g_inet_socket_address_parent_class)->dispose)
56 (*G_OBJECT_CLASS (g_inet_socket_address_parent_class)->dispose) (object);
60 g_inet_socket_address_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
62 GInetSocketAddress *address = G_INET_SOCKET_ADDRESS (object);
67 g_value_set_object (value, address->priv->address);
71 g_value_set_uint (value, address->priv->port);
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
80 g_inet_socket_address_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
82 GInetSocketAddress *address = G_INET_SOCKET_ADDRESS (object);
87 address->priv->address = G_INET_ADDRESS (g_value_get_object (value));
91 address->priv->port = (guint16) g_value_get_uint (value);
96 g_inet_socket_address_class_init (GInetSocketAddressClass *klass)
98 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
100 g_type_class_add_private (klass, sizeof (GInetSocketAddressPrivate));
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;
107 g_object_class_install_property (gobject_class, PROP_ADDRESS,
108 g_param_spec_object ("address",
112 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
114 g_object_class_install_property (gobject_class, PROP_PORT,
115 g_param_spec_uint ("port",
121 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
125 g_inet_socket_address_init (GInetSocketAddress *address)
127 address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
128 G_TYPE_INET_SOCKET_ADDRESS,
129 GInetSocketAddressPrivate);
134 g_inet_socket_address_new (GInetAddress *address, guint16 port)
141 g_inet_socket_address_get_address (GInetSocketAddress *sockaddr)
143 g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (sockaddr), NULL);
145 return sockaddr->priv->address;
149 g_inet_socket_address_get_port (GInetSocketAddress *sockaddr)
151 g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (sockaddr), 0);
153 return sockaddr->priv->port;