[evolution-data-server] Add CamelNullOutputStream.



commit a3657b8aa80c185f2b0e33e740c14346ecace6b5
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Jan 30 12:33:11 2014 -0500

    Add CamelNullOutputStream.
    
    GOutputStream subclass to eventually replace CamelStreamNull.

 camel/Makefile.am                       |    2 +
 camel/camel-null-output-stream.c        |  111 +++++++++++++++++++++++++++++++
 camel/camel-null-output-stream.h        |   71 ++++++++++++++++++++
 camel/camel.h                           |    1 +
 docs/reference/camel/camel-docs.sgml    |    5 +-
 docs/reference/camel/camel-sections.txt |   19 +++++
 docs/reference/camel/camel.types        |    1 +
 7 files changed, 208 insertions(+), 2 deletions(-)
---
diff --git a/camel/Makefile.am b/camel/Makefile.am
index edd4454..9643268 100644
--- a/camel/Makefile.am
+++ b/camel/Makefile.am
@@ -123,6 +123,7 @@ libcamel_1_2_la_SOURCES = \
        camel-network-service.c \
        camel-network-settings.c \
        camel-nntp-address.c \
+       camel-null-output-stream.c \
        camel-object-bag.c \
        camel-object.c \
        camel-offline-folder.c \
@@ -240,6 +241,7 @@ libcamelinclude_HEADERS = \
        camel-network-service.h \
        camel-network-settings.h \
        camel-nntp-address.h \
+       camel-null-output-stream.h \
        camel-object-bag.h \
        camel-object.h \
        camel-offline-folder.h \
diff --git a/camel/camel-null-output-stream.c b/camel/camel-null-output-stream.c
new file mode 100644
index 0000000..0aac1eb
--- /dev/null
+++ b/camel/camel-null-output-stream.c
@@ -0,0 +1,111 @@
+/*
+ * camel-null-output-stream.c
+ *
+ * This library is free software you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/**
+ * SECTION: camel-null-output-stream
+ * @short_description: Null output stream
+ * @include: camel/camel.h
+ * @see_also: #GOutputStream
+ *
+ * #CamelNullOutputStream is analogous to writing to /dev/null, except it
+ * counts the total number of bytes written to it.  This is primarily useful
+ * for determining the final size of some outgoing data, especially if using
+ * filters on the output stream.
+ **/
+
+#include "camel-null-output-stream.h"
+
+#define CAMEL_NULL_OUTPUT_STREAM_GET_PRIVATE(obj) \
+       (G_TYPE_INSTANCE_GET_PRIVATE \
+       ((obj), CAMEL_TYPE_NULL_OUTPUT_STREAM, CamelNullOutputStreamPrivate))
+
+struct _CamelNullOutputStreamPrivate {
+       gsize bytes_written;
+};
+
+G_DEFINE_TYPE (
+       CamelNullOutputStream,
+       camel_null_output_stream,
+       G_TYPE_OUTPUT_STREAM)
+
+static gssize
+null_output_stream_write (GOutputStream *stream,
+                          gconstpointer buffer,
+                          gsize count,
+                          GCancellable *cancellable,
+                          GError **error)
+{
+       CamelNullOutputStreamPrivate *priv;
+
+       priv = CAMEL_NULL_OUTPUT_STREAM_GET_PRIVATE (stream);
+
+       priv->bytes_written += count;
+
+       return count;
+}
+
+static void
+camel_null_output_stream_class_init (CamelNullOutputStreamClass *class)
+{
+       GOutputStreamClass *stream_class;
+
+       g_type_class_add_private (
+               class, sizeof (CamelNullOutputStreamPrivate));
+
+       stream_class = G_OUTPUT_STREAM_CLASS (class);
+       stream_class->write_fn = null_output_stream_write;
+}
+
+static void
+camel_null_output_stream_init (CamelNullOutputStream *null_stream)
+{
+       null_stream->priv = CAMEL_NULL_OUTPUT_STREAM_GET_PRIVATE (null_stream);
+}
+
+/**
+ * camel_null_output_stream_new:
+ *
+ * Creates a new "null" output stream.
+ *
+ * Returns: a new #GOutputStream
+ *
+ * Since: 3.12
+ **/
+GOutputStream *
+camel_null_output_stream_new (void)
+{
+       return g_object_new (CAMEL_TYPE_NULL_OUTPUT_STREAM, NULL);
+}
+
+/**
+ * camel_null_output_stream_get_bytes_written:
+ * @null_stream: a #CamelNullOutputStream
+ *
+ * Gets the total number of bytes written to @null_stream.
+ *
+ * Returns: total byte count
+ *
+ * Since: 3.12
+ **/
+gsize
+camel_null_output_stream_get_bytes_written (CamelNullOutputStream *null_stream)
+{
+       g_return_val_if_fail (CAMEL_IS_NULL_OUTPUT_STREAM (null_stream), 0);
+
+       return null_stream->priv->bytes_written;
+}
+
diff --git a/camel/camel-null-output-stream.h b/camel/camel-null-output-stream.h
new file mode 100644
index 0000000..b76b38b
--- /dev/null
+++ b/camel/camel-null-output-stream.h
@@ -0,0 +1,71 @@
+/*
+ * camel-null-output-stream.h
+ *
+ * This library is free software you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_NULL_OUTPUT_STREAM_H
+#define CAMEL_NULL_OUTPUT_STREAM_H
+
+#include <gio/gio.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_NULL_OUTPUT_STREAM \
+       (camel_null_output_stream_get_type ())
+#define CAMEL_NULL_OUTPUT_STREAM(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), CAMEL_TYPE_NULL_OUTPUT_STREAM, CamelNullOutputStream))
+#define CAMEL_NULL_OUTPUT_STREAM_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), CAMEL_TYPE_NULL_OUTPUT_STREAM, CamelNullOutputStreamClass))
+#define CAMEL_IS_NULL_OUTPUT_STREAM(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), CAMEL_TYPE_NULL_OUTPUT_STREAM))
+#define CAMEL_IS_NULL_OUTPUT_STREAM_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), CAMEL_TYPE_NULL_OUTPUT_STREAM))
+#define CAMEL_NULL_OUTPUT_STREAM_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), CAMEL_TYPE_NULL_OUTPUT_STREAM, CamelNullOutputStreamClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelNullOutputStream CamelNullOutputStream;
+typedef struct _CamelNullOutputStreamClass CamelNullOutputStreamClass;
+typedef struct _CamelNullOutputStreamPrivate CamelNullOutputStreamPrivate;
+
+struct _CamelNullOutputStream {
+       GOutputStream parent;
+       CamelNullOutputStreamPrivate *priv;
+};
+
+struct _CamelNullOutputStreamClass {
+       GOutputStreamClass parent_class;
+};
+
+GType          camel_null_output_stream_get_type
+                                       (void) G_GNUC_CONST;
+GOutputStream *        camel_null_output_stream_new
+                                       (void);
+gsize          camel_null_output_stream_get_bytes_written
+                                       (CamelNullOutputStream *null_stream);
+
+G_END_DECLS
+
+#endif /* CAMEL_NULL_OUTPUT_STREAM_H */
+
diff --git a/camel/camel.h b/camel/camel.h
index 52b1020..8ebf08d 100644
--- a/camel/camel.h
+++ b/camel/camel.h
@@ -88,6 +88,7 @@
 #include <camel/camel-net-utils.h>
 #include <camel/camel-network-service.h>
 #include <camel/camel-nntp-address.h>
+#include <camel/camel-null-output-stream.h>
 #include <camel/camel-object.h>
 #include <camel/camel-object-bag.h>
 #include <camel/camel-offline-folder.h>
diff --git a/docs/reference/camel/camel-docs.sgml b/docs/reference/camel/camel-docs.sgml
index 9b4f01f..080442a 100644
--- a/docs/reference/camel/camel-docs.sgml
+++ b/docs/reference/camel/camel-docs.sgml
@@ -52,13 +52,14 @@
       <xi:include href="xml/camel-stream-mem.xml"/>
       <xi:include href="xml/camel-stream-null.xml"/>
       <xi:include href="xml/camel-stream-process.xml"/>
+      <xi:include href="xml/camel-filter-input-stream.xml"/>
+      <xi:include href="xml/camel-filter-output-stream.xml"/>
+      <xi:include href="xml/camel-null-output-stream.xml"/>
     </chapter>
 
     <chapter id="Stream-Filters">
       <title>Stream Filters</title>
       <xi:include href="xml/camel-mime-filter.xml"/>
-      <xi:include href="xml/camel-filter-input-stream.xml"/>
-      <xi:include href="xml/camel-filter-output-stream.xml"/>
       <xi:include href="xml/camel-mime-filter-basic.xml"/>
       <xi:include href="xml/camel-mime-filter-bestenc.xml"/>
       <xi:include href="xml/camel-mime-filter-canon.xml"/>
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index a7af90e..8a53075 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -1462,6 +1462,25 @@ CamelNNTPAddressPrivate
 </SECTION>
 
 <SECTION>
+<FILE>camel-null-output-stream</FILE>
+<TITLE>CamelNullOutputStream</TITLE>
+CamelNullOutputStream
+camel_null_output_stream_new
+camel_null_output_stream_get_bytes_written
+<SUBSECTION Standard>
+CAMEL_NULL_OUTPUT_STREAM
+CAMEL_IS_NULL_OUTPUT_STREAM
+CAMEL_TYPE_NULL_OUTPUT_STREAM
+CAMEL_NULL_OUTPUT_STREAM_CLASS
+CAMEL_IS_NULL_OUTPUT_STREAM_CLASS
+CAMEL_NULL_OUTPUT_STREAM_GET_CLASS
+CamelNullOutputStreamClass
+camel_null_output_stream_get_type
+<SUBSECTION Private>
+CamelNullOutputStreamPrivate
+</SECTION>
+
+<SECTION>
 <FILE>camel-object</FILE>
 <TITLE>CamelObject</TITLE>
 CamelObject
diff --git a/docs/reference/camel/camel.types b/docs/reference/camel/camel.types
index 2e99086..96afd67 100644
--- a/docs/reference/camel/camel.types
+++ b/docs/reference/camel/camel.types
@@ -98,6 +98,7 @@ camel_multipart_signed_get_type
 camel_network_service_get_type
 camel_network_settings_get_type
 camel_nntp_address_get_type
+camel_null_output_stream_get_type
 camel_object_get_type
 camel_offline_folder_get_type
 camel_offline_settings_get_type


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]