[evolution-data-server] CamelIMAPXStream: Add a "source" construct-only property.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] CamelIMAPXStream: Add a "source" construct-only property.
- Date: Thu, 30 Aug 2012 21:08:34 +0000 (UTC)
commit 34856da684e62ed39a04c7ccf56214d7fce1cdc7
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Aug 29 11:18:26 2012 -0400
CamelIMAPXStream: Add a "source" construct-only property.
Use camel_imapx_stream_ref_source() to access the source stream.
camel/camel-imapx-server.c | 13 +++-
camel/camel-imapx-stream.c | 120 +++++++++++++++++++++++++------
camel/camel-imapx-stream.h | 2 +-
docs/reference/camel/camel-sections.txt | 1 +
4 files changed, 111 insertions(+), 25 deletions(-)
---
diff --git a/camel/camel-imapx-server.c b/camel/camel-imapx-server.c
index 6a8fd4f..9dcdff7 100644
--- a/camel/camel-imapx-server.c
+++ b/camel/camel-imapx-server.c
@@ -5815,9 +5815,12 @@ imapx_parser_thread (gpointer d)
#ifndef G_OS_WIN32
if (is->is_process_stream) {
GPollFD fds[2] = { {0, 0, 0}, {0, 0, 0} };
+ CamelStream *source;
gint res;
- fds[0].fd = ((CamelStreamProcess *) is->stream->source)->sockfd;
+ source = camel_imapx_stream_ref_source (is->stream);
+
+ fds[0].fd = CAMEL_STREAM_PROCESS (source)->sockfd;
fds[0].events = G_IO_IN;
fds[1].fd = g_cancellable_get_fd (cancellable);
fds[1].events = G_IO_IN;
@@ -5829,6 +5832,8 @@ imapx_parser_thread (gpointer d)
else if (fds[0].revents & G_IO_IN)
parse_contents (is, cancellable, &local_error);
g_cancellable_release_fd (cancellable);
+
+ g_object_unref (source);
} else
#endif
{
@@ -6068,8 +6073,12 @@ imapx_disconnect (CamelIMAPXServer *is)
g_static_rec_mutex_lock (&is->ostream_lock);
if (is->stream) {
- if (camel_stream_close (is->stream->source, NULL, NULL) == -1)
+ CamelStream *source;
+
+ source = camel_imapx_stream_ref_source (is->stream);
+ if (camel_stream_close (source, NULL, NULL) == -1)
ret = FALSE;
+ g_object_unref (source);
g_object_unref (is->stream);
is->stream = NULL;
diff --git a/camel/camel-imapx-stream.c b/camel/camel-imapx-stream.c
index 1370d6a..7b69219 100644
--- a/camel/camel-imapx-stream.c
+++ b/camel/camel-imapx-stream.c
@@ -44,6 +44,8 @@
#define io(...) camel_imapx_debug(io, __VA_ARGS__)
struct _CamelIMAPXStreamPrivate {
+ CamelStream *source;
+
guchar *buf, *ptr, *end;
guint literal;
@@ -56,6 +58,11 @@ struct _CamelIMAPXStreamPrivate {
guint bufsize;
};
+enum {
+ PROP_0,
+ PROP_SOURCE
+};
+
G_DEFINE_TYPE (CamelIMAPXStream, camel_imapx_stream, CAMEL_TYPE_STREAM)
static gint
@@ -65,13 +72,14 @@ imapx_stream_fill (CamelIMAPXStream *is,
{
gint left = 0;
- if (is->source) {
+ if (is->priv->source != NULL) {
left = is->priv->end - is->priv->ptr;
memcpy (is->priv->buf, is->priv->ptr, left);
is->priv->end = is->priv->buf + left;
is->priv->ptr = is->priv->buf;
left = camel_stream_read (
- is->source, (gchar *) is->priv->end,
+ is->priv->source,
+ (gchar *) is->priv->end,
is->priv->bufsize - (is->priv->end - is->priv->buf),
cancellable, error);
if (left > 0) {
@@ -101,13 +109,58 @@ imapx_stream_fill (CamelIMAPXStream *is,
}
static void
+imapx_stream_set_source (CamelIMAPXStream *stream,
+ CamelStream *source)
+{
+ g_return_if_fail (CAMEL_IS_STREAM (source));
+ g_return_if_fail (stream->priv->source == NULL);
+
+ stream->priv->source = g_object_ref (source);
+}
+
+static void
+imapx_stream_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SOURCE:
+ imapx_stream_set_source (
+ CAMEL_IMAPX_STREAM (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+imapx_stream_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SOURCE:
+ g_value_take_object (
+ value,
+ camel_imapx_stream_ref_source (
+ CAMEL_IMAPX_STREAM (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
imapx_stream_dispose (GObject *object)
{
CamelIMAPXStream *stream = CAMEL_IMAPX_STREAM (object);
- if (stream->source != NULL) {
- g_object_unref (stream->source);
- stream->source = NULL;
+ if (stream->priv->source != NULL) {
+ g_object_unref (stream->priv->source);
+ stream->priv->source = NULL;
}
/* Chain up to parent's dispose() method. */
@@ -147,7 +200,9 @@ imapx_stream_read (CamelStream *stream,
is->priv->ptr += max;
} else {
max = MIN (is->priv->literal, n);
- max = camel_stream_read (is->source, buffer, max, cancellable, error);
+ max = camel_stream_read (
+ is->priv->source,
+ buffer, max, cancellable, error);
if (max <= 0)
return max;
}
@@ -174,7 +229,9 @@ imapx_stream_write (CamelStream *stream,
io (is->tagprefix, "camel_imapx_write: '%.*s'\n", (gint) n, buffer);
}
- return camel_stream_write (is->source, buffer, n, cancellable, error);
+ return camel_stream_write (
+ is->priv->source,
+ buffer, n, cancellable, error);
}
static gint
@@ -212,6 +269,8 @@ camel_imapx_stream_class_init (CamelIMAPXStreamClass *class)
g_type_class_add_private (class, sizeof (CamelIMAPXStreamPrivate));
object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = imapx_stream_set_property;
+ object_class->get_property = imapx_stream_get_property;
object_class->dispose = imapx_stream_dispose;
object_class->finalize = imapx_stream_finalize;
@@ -221,6 +280,18 @@ camel_imapx_stream_class_init (CamelIMAPXStreamClass *class)
stream_class->close = imapx_stream_close;
stream_class->flush = imapx_stream_flush;
stream_class->eos = imapx_stream_eos;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_SOURCE,
+ g_param_spec_object (
+ "source",
+ "Source",
+ "Source stream",
+ CAMEL_TYPE_STREAM,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -267,6 +338,19 @@ camel_imapx_stream_grow (CamelIMAPXStream *is,
*bufptr = is->priv->buf + (*bufptr - oldbuf);
}
+GQuark
+camel_imapx_error_quark (void)
+{
+ static GQuark quark = 0;
+
+ if (G_UNLIKELY (quark == 0)) {
+ const gchar *string = "camel-imapx-error-quark";
+ quark = g_quark_from_static_string (string);
+ }
+
+ return quark;
+}
+
/**
* camel_imapx_stream_new:
*
@@ -278,27 +362,19 @@ camel_imapx_stream_grow (CamelIMAPXStream *is,
CamelStream *
camel_imapx_stream_new (CamelStream *source)
{
- CamelIMAPXStream *is;
-
g_return_val_if_fail (CAMEL_IS_STREAM (source), NULL);
- is = g_object_new (CAMEL_TYPE_IMAPX_STREAM, NULL);
- is->source = g_object_ref (source);
-
- return (CamelStream *) is;
+ return g_object_new (
+ CAMEL_TYPE_IMAPX_STREAM,
+ "source", source, NULL);
}
-GQuark
-camel_imapx_error_quark (void)
+CamelStream *
+camel_imapx_stream_ref_source (CamelIMAPXStream *is)
{
- static GQuark quark = 0;
+ g_return_val_if_fail (CAMEL_IS_IMAPX_STREAM (is), NULL);
- if (G_UNLIKELY (quark == 0)) {
- const gchar *string = "camel-imapx-error-quark";
- quark = g_quark_from_static_string (string);
- }
-
- return quark;
+ return g_object_ref (is->priv->source);
}
/* Returns if there is any data buffered that is ready for processing */
diff --git a/camel/camel-imapx-stream.h b/camel/camel-imapx-stream.h
index b2e6610..a3b650a 100644
--- a/camel/camel-imapx-stream.h
+++ b/camel/camel-imapx-stream.h
@@ -70,7 +70,6 @@ struct _CamelIMAPXStream {
CamelStream parent;
CamelIMAPXStreamPrivate *priv;
- CamelStream *source;
gchar tagprefix; /* For debugging output */
};
@@ -81,6 +80,7 @@ struct _CamelIMAPXStreamClass {
GType camel_imapx_stream_get_type (void);
GQuark camel_imapx_error_quark (void) G_GNUC_CONST;
CamelStream * camel_imapx_stream_new (CamelStream *source);
+CamelStream * camel_imapx_stream_ref_source (CamelIMAPXStream *is);
gint camel_imapx_stream_buffered (CamelIMAPXStream *is);
camel_imapx_token_t
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index c9b3dcf..5a51e6b 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -978,6 +978,7 @@ camel_imapx_token_t
CamelIMAPXStream
camel_imapx_error_quark
camel_imapx_stream_new
+camel_imapx_stream_ref_source
camel_imapx_stream_buffered
camel_imapx_stream_token
camel_imapx_stream_ungettoken
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]