GLocalFileOutputStream: Implement GFileDescriptorBased

Also convert GLocalFileIOStream to use the new interface to obtain
the file descriptor.
This commit is contained in:
Christian Kellner 2010-02-07 17:18:06 +01:00
parent 670f6210ce
commit 28f90db1ed
3 changed files with 25 additions and 9 deletions

View File

@ -27,6 +27,7 @@
#include "glibintl.h" #include "glibintl.h"
#include "gioerror.h" #include "gioerror.h"
#include "gcancellable.h" #include "gcancellable.h"
#include "gfiledescriptorbased.h"
#include "glocalfileiostream.h" #include "glocalfileiostream.h"
#include "glocalfileinputstream.h" #include "glocalfileinputstream.h"
#include "glocalfileinfo.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 = g_object_new (G_TYPE_LOCAL_FILE_IO_STREAM, NULL);
stream->output_stream = g_object_ref (output_stream); stream->output_stream = g_object_ref (output_stream);
_g_local_file_output_stream_set_do_close (output_stream, FALSE); _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); 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), _g_local_file_input_stream_set_do_close (G_LOCAL_FILE_INPUT_STREAM (stream->input_stream),
FALSE); FALSE);

View File

@ -36,6 +36,7 @@
#include "glibintl.h" #include "glibintl.h"
#include "gioerror.h" #include "gioerror.h"
#include "gcancellable.h" #include "gcancellable.h"
#include "gfiledescriptorbased.h"
#include "glocalfileoutputstream.h" #include "glocalfileoutputstream.h"
#include "glocalfileinfo.h" #include "glocalfileinfo.h"
@ -55,8 +56,12 @@
#include "gioalias.h" #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 #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, /* Some of the file replacement code was based on the code from gedit,
* relicenced to LGPL with permissions from the authors. * relicenced to LGPL with permissions from the authors.
@ -99,6 +104,7 @@ static gboolean g_local_file_output_stream_truncate (GFileOutputStream *s
goffset size, goffset size,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
static int g_local_file_output_stream_get_fd (GFileDescriptorBased *stream);
static void static void
g_local_file_output_stream_finalize (GObject *object) 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); G_OBJECT_CLASS (g_local_file_output_stream_parent_class)->finalize (object);
} }
static void static void
g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass) g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass)
{ {
@ -137,6 +144,12 @@ g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass)
file_stream_class->truncate_fn = g_local_file_output_stream_truncate; file_stream_class->truncate_fn = g_local_file_output_stream_truncate;
} }
static void
g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface)
{
iface->get_fd = g_local_file_output_stream_get_fd;
}
static void static void
g_local_file_output_stream_init (GLocalFileOutputStream *stream) g_local_file_output_stream_init (GLocalFileOutputStream *stream)
{ {
@ -146,12 +159,6 @@ g_local_file_output_stream_init (GLocalFileOutputStream *stream)
stream->priv->do_close = TRUE; stream->priv->do_close = TRUE;
} }
int
_g_local_file_output_stream_get_fd (GLocalFileOutputStream *out)
{
return out->priv->fd;
}
static gssize static gssize
g_local_file_output_stream_write (GOutputStream *stream, g_local_file_output_stream_write (GOutputStream *stream,
const void *buffer, const void *buffer,
@ -1151,3 +1158,12 @@ _g_local_file_output_stream_replace (const char *filename,
return G_FILE_OUTPUT_STREAM (stream); 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;
}

View File

@ -53,7 +53,6 @@ struct _GLocalFileOutputStreamClass
GType _g_local_file_output_stream_get_type (void) G_GNUC_CONST; 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, void _g_local_file_output_stream_set_do_close (GLocalFileOutputStream *out,
gboolean do_close); gboolean do_close);
gboolean _g_local_file_output_stream_really_close (GLocalFileOutputStream *out, gboolean _g_local_file_output_stream_really_close (GLocalFileOutputStream *out,