mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
gwin32outputstream: cleanups to make the code more consistent
This commit is contained in:
parent
d5cb451c51
commit
73192b84f8
@ -34,7 +34,6 @@
|
||||
#include "gasynchelper.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
|
||||
/**
|
||||
* SECTION:gwin32outputstream
|
||||
* @short_description: Streaming output operations for Windows file handles
|
||||
@ -49,80 +48,23 @@
|
||||
* when using it.
|
||||
*/
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_HANDLE,
|
||||
PROP_CLOSE_HANDLE
|
||||
};
|
||||
|
||||
struct _GWin32OutputStreamPrivate {
|
||||
HANDLE handle;
|
||||
gboolean close_handle;
|
||||
gint fd;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_HANDLE,
|
||||
PROP_CLOSE_HANDLE,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
static GParamSpec *props[LAST_PROP];
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GWin32OutputStream, g_win32_output_stream, G_TYPE_OUTPUT_STREAM)
|
||||
|
||||
static void g_win32_output_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void g_win32_output_stream_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static gssize g_win32_output_stream_write (GOutputStream *stream,
|
||||
const void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static gboolean g_win32_output_stream_close (GOutputStream *stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
|
||||
static void
|
||||
g_win32_output_stream_class_init (GWin32OutputStreamClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass);
|
||||
|
||||
gobject_class->get_property = g_win32_output_stream_get_property;
|
||||
gobject_class->set_property = g_win32_output_stream_set_property;
|
||||
|
||||
stream_class->write_fn = g_win32_output_stream_write;
|
||||
stream_class->close_fn = g_win32_output_stream_close;
|
||||
|
||||
/**
|
||||
* GWin32OutputStream:handle:
|
||||
*
|
||||
* The file handle that the stream writes to.
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_HANDLE,
|
||||
g_param_spec_pointer ("handle",
|
||||
P_("File handle"),
|
||||
P_("The file handle to write to"),
|
||||
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
|
||||
|
||||
/**
|
||||
* GWin32OutputStream:close-handle:
|
||||
*
|
||||
* Whether to close the file handle when the stream is closed.
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CLOSE_HANDLE,
|
||||
g_param_spec_boolean ("close-handle",
|
||||
P_("Close file handle"),
|
||||
P_("Whether to close the file handle when the stream is closed"),
|
||||
TRUE,
|
||||
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
|
||||
}
|
||||
|
||||
static void
|
||||
g_win32_output_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
@ -170,106 +112,6 @@ g_win32_output_stream_get_property (GObject *object,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
g_win32_output_stream_init (GWin32OutputStream *win32_stream)
|
||||
{
|
||||
win32_stream->priv = g_win32_output_stream_get_instance_private (win32_stream);
|
||||
win32_stream->priv->handle = NULL;
|
||||
win32_stream->priv->close_handle = TRUE;
|
||||
win32_stream->priv->fd = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_new:
|
||||
* @handle: a Win32 file handle
|
||||
* @close_handle: %TRUE to close the handle when done
|
||||
*
|
||||
* Creates a new #GWin32OutputStream for the given @handle.
|
||||
*
|
||||
* If @close_handle, is %TRUE, the handle will be closed when the
|
||||
* output stream is destroyed.
|
||||
*
|
||||
* Returns: a new #GOutputStream
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
GOutputStream *
|
||||
g_win32_output_stream_new (void *handle,
|
||||
gboolean close_handle)
|
||||
{
|
||||
GWin32OutputStream *stream;
|
||||
|
||||
g_return_val_if_fail (handle != NULL, NULL);
|
||||
|
||||
stream = g_object_new (G_TYPE_WIN32_OUTPUT_STREAM,
|
||||
"handle", handle,
|
||||
"close-handle", close_handle,
|
||||
NULL);
|
||||
|
||||
return G_OUTPUT_STREAM (stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_set_close_handle:
|
||||
* @stream: a #GWin32OutputStream
|
||||
* @close_handle: %TRUE to close the handle when done
|
||||
*
|
||||
* Sets whether the handle of @stream shall be closed when the stream
|
||||
* is closed.
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
void
|
||||
g_win32_output_stream_set_close_handle (GWin32OutputStream *stream,
|
||||
gboolean close_handle)
|
||||
{
|
||||
g_return_if_fail (G_IS_WIN32_OUTPUT_STREAM (stream));
|
||||
|
||||
close_handle = close_handle != FALSE;
|
||||
if (stream->priv->close_handle != close_handle)
|
||||
{
|
||||
stream->priv->close_handle = close_handle;
|
||||
g_object_notify (G_OBJECT (stream), "close-handle");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_get_close_handle:
|
||||
* @stream: a #GWin32OutputStream
|
||||
*
|
||||
* Returns whether the handle of @stream will be closed when the
|
||||
* stream is closed.
|
||||
*
|
||||
* Returns: %TRUE if the handle is closed when done
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
gboolean
|
||||
g_win32_output_stream_get_close_handle (GWin32OutputStream *stream)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_WIN32_OUTPUT_STREAM (stream), FALSE);
|
||||
|
||||
return stream->priv->close_handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_get_handle:
|
||||
* @stream: a #GWin32OutputStream
|
||||
*
|
||||
* Return the Windows handle that the stream writes to.
|
||||
*
|
||||
* Returns: The handle descriptor of @stream
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
void *
|
||||
g_win32_output_stream_get_handle (GWin32OutputStream *stream)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_WIN32_OUTPUT_STREAM (stream), NULL);
|
||||
|
||||
return stream->priv->handle;
|
||||
}
|
||||
|
||||
static gssize
|
||||
g_win32_output_stream_write (GOutputStream *stream,
|
||||
const void *buffer,
|
||||
@ -381,9 +223,156 @@ g_win32_output_stream_close (GOutputStream *stream,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
g_win32_output_stream_class_init (GWin32OutputStreamClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass);
|
||||
|
||||
gobject_class->get_property = g_win32_output_stream_get_property;
|
||||
gobject_class->set_property = g_win32_output_stream_set_property;
|
||||
|
||||
stream_class->write_fn = g_win32_output_stream_write;
|
||||
stream_class->close_fn = g_win32_output_stream_close;
|
||||
|
||||
/**
|
||||
* GWin32OutputStream:handle:
|
||||
*
|
||||
* The file handle that the stream writes to.
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
props[PROP_HANDLE] =
|
||||
g_param_spec_pointer ("handle",
|
||||
P_("File handle"),
|
||||
P_("The file handle to write to"),
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* GWin32OutputStream:close-handle:
|
||||
*
|
||||
* Whether to close the file handle when the stream is closed.
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
props[PROP_CLOSE_HANDLE] =
|
||||
g_param_spec_boolean ("close-handle",
|
||||
P_("Close file handle"),
|
||||
P_("Whether to close the file handle when the stream is closed"),
|
||||
TRUE,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (gobject_class, LAST_PROP, props);
|
||||
}
|
||||
|
||||
static void
|
||||
g_win32_output_stream_init (GWin32OutputStream *win32_stream)
|
||||
{
|
||||
win32_stream->priv = g_win32_output_stream_get_instance_private (win32_stream);
|
||||
win32_stream->priv->handle = NULL;
|
||||
win32_stream->priv->close_handle = TRUE;
|
||||
win32_stream->priv->fd = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_new:
|
||||
* @handle: a Win32 file handle
|
||||
* @close_handle: %TRUE to close the handle when done
|
||||
*
|
||||
* Creates a new #GWin32OutputStream for the given @handle.
|
||||
*
|
||||
* If @close_handle, is %TRUE, the handle will be closed when the
|
||||
* output stream is destroyed.
|
||||
*
|
||||
* Returns: a new #GOutputStream
|
||||
*
|
||||
* Since: 2.26
|
||||
**/
|
||||
GOutputStream *
|
||||
g_win32_output_stream_new (void *handle,
|
||||
gboolean close_handle)
|
||||
{
|
||||
GWin32OutputStream *stream;
|
||||
|
||||
g_return_val_if_fail (handle != NULL, NULL);
|
||||
|
||||
stream = g_object_new (G_TYPE_WIN32_OUTPUT_STREAM,
|
||||
"handle", handle,
|
||||
"close-handle", close_handle,
|
||||
NULL);
|
||||
|
||||
return G_OUTPUT_STREAM (stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_set_close_handle:
|
||||
* @stream: a #GWin32OutputStream
|
||||
* @close_handle: %TRUE to close the handle when done
|
||||
*
|
||||
* Sets whether the handle of @stream shall be closed when the stream
|
||||
* is closed.
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
void
|
||||
g_win32_output_stream_set_close_handle (GWin32OutputStream *stream,
|
||||
gboolean close_handle)
|
||||
{
|
||||
g_return_if_fail (G_IS_WIN32_OUTPUT_STREAM (stream));
|
||||
|
||||
close_handle = close_handle != FALSE;
|
||||
if (stream->priv->close_handle != close_handle)
|
||||
{
|
||||
stream->priv->close_handle = close_handle;
|
||||
g_object_notify (G_OBJECT (stream), "close-handle");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_get_close_handle:
|
||||
* @stream: a #GWin32OutputStream
|
||||
*
|
||||
* Returns whether the handle of @stream will be closed when the
|
||||
* stream is closed.
|
||||
*
|
||||
* Returns: %TRUE if the handle is closed when done
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
gboolean
|
||||
g_win32_output_stream_get_close_handle (GWin32OutputStream *stream)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_WIN32_OUTPUT_STREAM (stream), FALSE);
|
||||
|
||||
return stream->priv->close_handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_win32_output_stream_get_handle:
|
||||
* @stream: a #GWin32OutputStream
|
||||
*
|
||||
* Return the Windows handle that the stream writes to.
|
||||
*
|
||||
* Returns: The handle descriptor of @stream
|
||||
*
|
||||
* Since: 2.26
|
||||
*/
|
||||
void *
|
||||
g_win32_output_stream_get_handle (GWin32OutputStream *stream)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_WIN32_OUTPUT_STREAM (stream), NULL);
|
||||
|
||||
return stream->priv->handle;
|
||||
}
|
||||
|
||||
GOutputStream *
|
||||
g_win32_output_stream_new_from_fd (gint fd,
|
||||
gboolean close_fd)
|
||||
gboolean close_fd)
|
||||
{
|
||||
GWin32OutputStream *win32_stream;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user