[glib] GLocalFileOutputStream: Implement GFileDescriptorBased



commit 28f90db1edf938c04f0b5c8a2f54f8add50db234
Author: Christian Kellner <gicmo gnome org>
Date:   Sun Feb 7 17:18:06 2010 +0100

    GLocalFileOutputStream: Implement GFileDescriptorBased
    
    Also convert GLocalFileIOStream to use the new interface to obtain
    the file descriptor.

 gio/glocalfileiostream.c     |    3 ++-
 gio/glocalfileoutputstream.c |   30 +++++++++++++++++++++++-------
 gio/glocalfileoutputstream.h |    1 -
 3 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/gio/glocalfileiostream.c b/gio/glocalfileiostream.c
index cb08061..e1f295c 100644
--- a/gio/glocalfileiostream.c
+++ b/gio/glocalfileiostream.c
@@ -27,6 +27,7 @@
 #include "glibintl.h"
 #include "gioerror.h"
 #include "gcancellable.h"
+#include "gfiledescriptorbased.h"
 #include "glocalfileiostream.h"
 #include "glocalfileinputstream.h"
 #include "glocalfileinfo.h"
@@ -58,7 +59,7 @@ _g_local_file_io_stream_new (GLocalFileOutputStream *output_stream)
   stream = g_object_new (G_TYPE_LOCAL_FILE_IO_STREAM, NULL);
   stream->output_stream = g_object_ref (output_stream);
   _g_local_file_output_stream_set_do_close (output_stream, FALSE);
-  fd = _g_local_file_output_stream_get_fd (output_stream);
+  fd = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (output_stream));
   stream->input_stream = (GInputStream *)_g_local_file_input_stream_new (fd);
   _g_local_file_input_stream_set_do_close (G_LOCAL_FILE_INPUT_STREAM (stream->input_stream),
 					   FALSE);
diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c
index 7ab8a08..f870d7b 100644
--- a/gio/glocalfileoutputstream.c
+++ b/gio/glocalfileoutputstream.c
@@ -36,6 +36,7 @@
 #include "glibintl.h"
 #include "gioerror.h"
 #include "gcancellable.h"
+#include "gfiledescriptorbased.h"
 #include "glocalfileoutputstream.h"
 #include "glocalfileinfo.h"
 
@@ -55,8 +56,12 @@
 
 #include "gioalias.h"
 
+static void       g_file_descriptor_based_iface_init   (GFileDescriptorBasedIface *iface);
 #define g_local_file_output_stream_get_type _g_local_file_output_stream_get_type
-G_DEFINE_TYPE (GLocalFileOutputStream, g_local_file_output_stream, G_TYPE_FILE_OUTPUT_STREAM);
+G_DEFINE_TYPE_WITH_CODE (GLocalFileOutputStream, g_local_file_output_stream, G_TYPE_FILE_OUTPUT_STREAM,
+			 G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED,
+						g_file_descriptor_based_iface_init));
+
 
 /* Some of the file replacement code was based on the code from gedit,
  * relicenced to LGPL with permissions from the authors.
@@ -99,6 +104,7 @@ static gboolean   g_local_file_output_stream_truncate     (GFileOutputStream  *s
 							   goffset             size,
 							   GCancellable       *cancellable,
 							   GError            **error);
+static int        g_local_file_output_stream_get_fd       (GFileDescriptorBased *stream);
 
 static void
 g_local_file_output_stream_finalize (GObject *object)
@@ -115,6 +121,7 @@ g_local_file_output_stream_finalize (GObject *object)
   G_OBJECT_CLASS (g_local_file_output_stream_parent_class)->finalize (object);
 }
 
+
 static void
 g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass)
 {
@@ -138,6 +145,12 @@ g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass)
 }
 
 static void
+g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface)
+{
+  iface->get_fd = g_local_file_output_stream_get_fd;
+}
+
+static void
 g_local_file_output_stream_init (GLocalFileOutputStream *stream)
 {
   stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (stream,
@@ -146,12 +159,6 @@ g_local_file_output_stream_init (GLocalFileOutputStream *stream)
   stream->priv->do_close = TRUE;
 }
 
-int
-_g_local_file_output_stream_get_fd (GLocalFileOutputStream *out)
-{
-  return out->priv->fd;
-}
-
 static gssize
 g_local_file_output_stream_write (GOutputStream  *stream,
 				  const void     *buffer,
@@ -1151,3 +1158,12 @@ _g_local_file_output_stream_replace (const char        *filename,
   
   return G_FILE_OUTPUT_STREAM (stream);
 }
+
+static int
+g_local_file_output_stream_get_fd (GFileDescriptorBased *fd_based)
+{
+  GLocalFileOutputStream *stream = G_LOCAL_FILE_OUTPUT_STREAM (fd_based);
+
+  return stream->priv->fd;
+}
+
diff --git a/gio/glocalfileoutputstream.h b/gio/glocalfileoutputstream.h
index 5f08d13..a8ec736 100644
--- a/gio/glocalfileoutputstream.h
+++ b/gio/glocalfileoutputstream.h
@@ -53,7 +53,6 @@ struct _GLocalFileOutputStreamClass
 
 GType               _g_local_file_output_stream_get_type (void) G_GNUC_CONST;
 
-int      _g_local_file_output_stream_get_fd       (GLocalFileOutputStream *out);
 void     _g_local_file_output_stream_set_do_close (GLocalFileOutputStream *out,
 						   gboolean do_close);
 gboolean _g_local_file_output_stream_really_close (GLocalFileOutputStream *out,



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