1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2013 Samsung Electronics
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: Michal Eljasiewicz <m.eljasiewic@samsung.com>
21 * Author: Lukasz Skalski <l.skalski@samsung.com>
25 #include "gkdbusconnection.h"
26 #include "gunixconnection.h"
29 * SECTION:gkdbusconnection
30 * @short_description: A kdbus connection
32 * @see_also: #GIOStream, #GKdbusClient
34 * #GKdbusConnection is a #GIOStream for a connected kdbus bus.
37 #define g_kdbus_connection_get_type _g_kdbus_connection_get_type
38 G_DEFINE_TYPE (GKdbusConnection, g_kdbus_connection, G_TYPE_IO_STREAM);
40 struct _GKdbusConnectionPrivate
48 * g_kdbus_connection_new:
52 _g_kdbus_connection_new (void)
54 return g_object_new(G_TYPE_KDBUS_CONNECTION,NULL);
59 * g_kdbus_connection_connect:
63 _g_kdbus_connection_connect (GKdbusConnection *connection,
65 GCancellable *cancellable,
68 g_return_val_if_fail (G_IS_KDBUS_CONNECTION (connection), FALSE);
70 return _g_kdbus_open (connection->priv->kdbus,address,error);
75 * g_kdbus_connection_constructed:
79 g_kdbus_connection_constructed (GObject *object)
81 GKdbusConnection *connection = G_KDBUS_CONNECTION (object);
83 g_assert (connection->priv->kdbus != NULL);
88 * g_kdbus_connection_finalize:
92 g_kdbus_connection_finalize (GObject *object)
94 GKdbusConnection *connection = G_KDBUS_CONNECTION (object);
96 g_object_unref (connection->priv->kdbus);
98 G_OBJECT_CLASS (g_kdbus_connection_parent_class)->finalize (object);
103 * g_kdbus_connection_dispose:
107 g_kdbus_connection_dispose (GObject *object)
109 GKdbusConnection *connection = G_KDBUS_CONNECTION (object);
111 connection->priv->in_dispose = TRUE;
113 G_OBJECT_CLASS (g_kdbus_connection_parent_class)
116 connection->priv->in_dispose = FALSE;
121 * g_kdbus_connection_close:
125 g_kdbus_connection_close (GIOStream *stream,
126 GCancellable *cancellable,
129 GKdbusConnection *connection = G_KDBUS_CONNECTION (stream);
131 if (connection->priv->in_dispose)
134 return _g_kdbus_close (connection->priv->kdbus, error);
139 * g_kdbus_connection_close_async:
143 g_kdbus_connection_close_async (GIOStream *stream,
145 GCancellable *cancellable,
146 GAsyncReadyCallback callback,
150 GIOStreamClass *class;
153 class = G_IO_STREAM_GET_CLASS (stream);
155 task = g_task_new (stream, cancellable, callback, user_data);
158 if (class->close_fn &&
159 !class->close_fn (stream, cancellable, &error))
160 g_task_return_error (task, error);
162 g_task_return_boolean (task, TRUE);
164 g_object_unref (task);
169 * g_kdbus_connection_close_finish:
173 g_kdbus_connection_close_finish (GIOStream *stream,
174 GAsyncResult *result,
177 return g_task_propagate_boolean (G_TASK (result), error);
182 * g_kdbus_connection_class_init:
186 g_kdbus_connection_class_init (GKdbusConnectionClass *klass)
188 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
189 GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
191 g_type_class_add_private (klass, sizeof (GKdbusConnectionPrivate));
193 gobject_class->constructed = g_kdbus_connection_constructed;
194 gobject_class->finalize = g_kdbus_connection_finalize;
195 gobject_class->dispose = g_kdbus_connection_dispose;
197 stream_class->close_fn = g_kdbus_connection_close;
198 stream_class->close_async = g_kdbus_connection_close_async;
199 stream_class->close_finish = g_kdbus_connection_close_finish;
204 * g_kdbus_connection_init:
208 g_kdbus_connection_init (GKdbusConnection *connection)
210 connection->priv = G_TYPE_INSTANCE_GET_PRIVATE (connection,
211 G_TYPE_KDBUS_CONNECTION,
212 GKdbusConnectionPrivate);
213 connection->priv->kdbus = g_object_new(G_TYPE_KDBUS,NULL);
218 * g_kdbus_connection_get_kdbus:
222 _g_kdbus_connection_get_kdbus (GKdbusConnection *connection)
224 g_return_val_if_fail (G_IS_KDBUS_CONNECTION (connection), NULL);
226 return connection->priv->kdbus;