[glibmm] InputStream: Add read_all_async() and read_all_finish().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] InputStream: Add read_all_async() and read_all_finish().
- Date: Tue, 3 Mar 2015 08:44:31 +0000 (UTC)
commit 143d7588b492edbf336f0df79716d52137b31e10
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Mar 3 09:42:03 2015 +0100
InputStream: Add read_all_async() and read_all_finish().
gio/src/inputstream.ccg | 36 +++++++++++++++++++++++
gio/src/inputstream.hg | 74 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+), 0 deletions(-)
---
diff --git a/gio/src/inputstream.ccg b/gio/src/inputstream.ccg
index d82ca18..82d0c13 100644
--- a/gio/src/inputstream.ccg
+++ b/gio/src/inputstream.ccg
@@ -59,6 +59,42 @@ InputStream::read_async(void* buffer, gsize count, const SlotAsyncReady& slot, i
slot_copy);
}
+
+void
+InputStream::read_all_async(void* buffer, gsize count, const SlotAsyncReady& slot, const
Glib::RefPtr<Cancellable>& cancellable, int io_priority)
+{
+ // Create a copy of the slot.
+ // A pointer to it will be passed through the callback's data parameter
+ // and deleted in the callback.
+ SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+ g_input_stream_read_all_async(gobj(),
+ buffer,
+ count,
+ io_priority,
+ Glib::unwrap(cancellable),
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
+void
+InputStream::read_all_async(void* buffer, gsize count, const SlotAsyncReady& slot, int io_priority)
+{
+ // Create a copy of the slot.
+ // A pointer to it will be passed through the callback's data parameter
+ // and deleted in the callback.
+ SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+ g_input_stream_read_all_async(gobj(),
+ buffer,
+ count,
+ io_priority,
+ 0,
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
+
void
InputStream::read_bytes_async(gsize count, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>&
cancellable, int io_priority)
{
diff --git a/gio/src/inputstream.hg b/gio/src/inputstream.hg
index 64c53c4..446e901 100644
--- a/gio/src/inputstream.hg
+++ b/gio/src/inputstream.hg
@@ -205,6 +205,80 @@ public:
g_input_stream_read_finish,
errthrow)
+
+ /** Request an asynchronous read of @a count bytes from the stream into the buffer
+ * starting at @a buffer. This is the asynchronous equivalent of read_all().
+ *
+ * When the operation is finished @a slot will be called.
+ * You can then call read_all_finish() to get the result of the
+ * operation.
+ *
+ * During an async request no other sync and async calls are allowed, and will
+ * result in Gio::Error with PENDING being thrown.
+ *
+ * A value of @a count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.
+ *
+ * On success, the number of bytes read into the buffer will be passed to the
+ * @a slot callback. It is not an error if this is not the same as the requested size, as it
+ * can happen e.g. near the end of a file, but generally we try to read
+ * as many bytes as requested. Zero is returned on end of file
+ * (or if @a count is zero), but never otherwise.
+ *
+ * Any outstanding i/o request with higher priority (lower numerical value) will
+ * be executed before an outstanding request with lower priority. Default
+ * priority is PRIORITY_DEFAULT.
+ *
+ * The asyncronous methods have a default fallback that uses threads to implement
+ * asynchronicity, so they are optional for inheriting classes. However, if you
+ * override one you must override all.
+ *
+ * @param buffer A buffer to read data into (which should be at least count bytes long).
+ * @param count The number of bytes that will be read from the stream.
+ * @param slot Callback to call when the request is satisfied.
+ * @param cancellable A Cancellable object.
+ * @param io_priority The I/O priority of the request.
+ */
+ void read_all_async(void* buffer, gsize count, const SlotAsyncReady& slot, const
Glib::RefPtr<Cancellable>& cancellable, int io_priority = Glib::PRIORITY_DEFAULT);
+
+ /** Request an asynchronous read of @a count bytes from the stream into the buffer
+ * starting at @a buffer. This is the asynchronous equivalent of read_all().
+ *
+ * When the operation is finished @a slot will be called.
+ * You can then call read_all_finish() to get the result of the
+ * operation.
+ *
+ * During an async request no other sync and async calls are allowed, and will
+ * result in a Gio::Error with PENDING being thrown.
+ *
+ * A value of @a count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.
+ *
+ * On success, the number of bytes read into the buffer will be passed to the
+ * @a slot callback. It is not an error if this is not the same as the requested size, as it
+ * can happen e.g. near the end of a file, but generally we try to read
+ * as many bytes as requested. Zero is returned on end of file
+ * (or if @a count is zero), but never otherwise.
+ *
+ * Any outstanding i/o request with higher priority (lower numerical value) will
+ * be executed before an outstanding request with lower priority. Default
+ * priority is PRIORITY_DEFAULT.
+ *
+ * The asyncronous methods have a default fallback that uses threads to implement
+ * asynchronicity, so they are optional for inheriting classes. However, if you
+ * override one you must override all.
+ *
+ * @param buffer A buffer to read data into (which should be at least count bytes long).
+ * @param count The number of bytes that will be read from the stream.
+ * @param slot Callback to call when the request is satisfied.
+ * @param io_priority The I/O priority of the request.
+ */
+ void read_all_async(void* buffer, gsize count, const SlotAsyncReady& slot, int io_priority =
Glib::PRIORITY_DEFAULT);
+ _IGNORE(g_input_stream_read_all_async)
+
+ _WRAP_METHOD(bool read_all_finish(const Glib::RefPtr<AsyncResult>& result, gsize& bytes_read),
+ g_input_stream_read_all_finish,
+ errthrow)
+
+
//TODO: Use std::size_type instead of gsize?
/** Request an asynchronous skip of @a count bytes from the stream into the buffer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]