[glibmm] Added Glib::Bytes and Gio::InputStream::read_bytes().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Added Glib::Bytes and Gio::InputStream::read_bytes().
- Date: Tue, 10 Jul 2012 09:08:30 +0000 (UTC)
commit 2d760935013ed77eec2b225643536af0d37d175e
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Jul 10 11:08:22 2012 +0200
Added Glib::Bytes and Gio::InputStream::read_bytes().
* glib/src/bytes.[hg|ccg]:
* glib/src/filelist.am:
* tools/m4/convert_glib.m4: Added a simple GBytes wrapper.
* gio/src/inputstream.[hg|ccg]: Added read_bytes(), read_bytes_async()
and read_bytes_finish() using the new Glib::Bytes type.
ChangeLog | 10 ++++++
gio/src/inputstream.ccg | 32 ++++++++++++++++++++
gio/src/inputstream.hg | 20 +++++++++++++
glib/src/bytes.ccg | 27 +++++++++++++++++
glib/src/bytes.hg | 72 ++++++++++++++++++++++++++++++++++++++++++++++
glib/src/filelist.am | 1 +
tools/m4/convert_glib.m4 | 6 +++-
7 files changed, 167 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 22af6e2..dd6a4b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2012-07-10 Murray Cumming <murrayc murrayc com>
+ Added Glib::Bytes and Gio::InputStream::read_bytes().
+
+ * glib/src/bytes.[hg|ccg]:
+ * glib/src/filelist.am:
+ * tools/m4/convert_glib.m4: Added a simple GBytes wrapper.
+ * gio/src/inputstream.[hg|ccg]: Added read_bytes(), read_bytes_async()
+ and read_bytes_finish() using the new Glib::Bytes type.
+
+2012-07-10 Murray Cumming <murrayc murrayc com>
+
Gio::DBus::Connection: Add get_last_serial().
* gio/src/dbusconnection.hg: Wrap g_dbus_connection_get_last_serial().
diff --git a/gio/src/inputstream.ccg b/gio/src/inputstream.ccg
index 8cdd3ff..b2eb22d 100644
--- a/gio/src/inputstream.ccg
+++ b/gio/src/inputstream.ccg
@@ -100,6 +100,38 @@ InputStream::read_async(void* buffer, gsize count, const SlotAsyncReady& slot, i
slot_copy);
}
+void
+InputStream::read_bytes_async(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_bytes_async(gobj(),
+ count,
+ io_priority,
+ Glib::unwrap(cancellable),
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
+void
+InputStream::read_bytes_async(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_bytes_async(gobj(),
+ count,
+ io_priority,
+ 0,
+ &SignalProxy_async_callback,
+ slot_copy);
+}
+
void
InputStream::skip_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 c370fdd..89fefd4 100644
--- a/gio/src/inputstream.hg
+++ b/gio/src/inputstream.hg
@@ -19,6 +19,7 @@
#include <glibmm/object.h>
#include <glibmm/priorities.h>
+#include <glibmm/bytes.h>
#include <giomm/asyncresult.h>
#include <giomm/cancellable.h>
@@ -98,6 +99,25 @@ public:
//TODO: bool read_all(std::string& buffer, gsize count, gsize& bytes_read, const Glib::RefPtr<Cancellable>& cancellable);
//TODO: bool read_all(std::string& buffer, gsize count, gsize& bytes_read)
+
+ _WRAP_METHOD(Glib::RefPtr<Glib::Bytes> read_bytes(gsize count, const Glib::RefPtr<Cancellable>& cancellable), g_input_stream_read_bytes, errthrow)
+
+ //TODO: Documentation.
+ /**
+ * @newin{2,34}
+ */
+ void read_bytes_async(gsize count, const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable, int io_priority = Glib::PRIORITY_DEFAULT);
+
+ /**
+ * @newin{2,34}
+ */
+ void read_bytes_async(gsize count, const SlotAsyncReady& slot, int io_priority = Glib::PRIORITY_DEFAULT);
+ _IGNORE(g_input_stream_read_bytes_async)
+
+ _WRAP_METHOD(Glib::RefPtr<Glib::Bytes> read_bytes_finish(const Glib::RefPtr<AsyncResult>& result), g_input_stream_read_bytes_finish, errthrow)
+
+
+
_WRAP_METHOD(gssize skip(gsize count, const Glib::RefPtr<Cancellable>& cancellable),
g_input_stream_skip,
errthrow)
diff --git a/glib/src/bytes.ccg b/glib/src/bytes.ccg
new file mode 100644
index 0000000..ae7270a
--- /dev/null
+++ b/glib/src/bytes.ccg
@@ -0,0 +1,27 @@
+/* Copyright (C) 2012 The glibmm Development Team
+ *
+ * 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; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Lesser 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, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+namespace Glib
+{
+
+Glib::RefPtr<Glib::Bytes> Bytes::create(gconstpointer data, gsize size)
+{
+ GBytes* bytes= g_bytes_new(data, size);
+ return Glib::wrap(bytes);
+}
+
+} // namespace Glib
diff --git a/glib/src/bytes.hg b/glib/src/bytes.hg
new file mode 100644
index 0000000..424347a
--- /dev/null
+++ b/glib/src/bytes.hg
@@ -0,0 +1,72 @@
+/* Copyright (C) 2012 The glibmm Development Team
+ *
+ * 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; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Lesser 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, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+_DEFS(glibmm,glib)
+
+#include <glibmmconfig.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+#include <glibmm/error.h>
+#include <glibmm/arrayhandle.h>
+#include <glib.h>
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+typedef struct _GBytes GBytes;
+#endif
+
+namespace Glib
+{
+
+
+//Note: The documentation is a reduced version of the C documentation,
+//because this class is only really useful with other C types that we don't bother to wrap.
+//We only wrap it because it is used in the InputStream API.
+
+/** A simple refcounted data type representing an immutable byte sequence
+ * from an unspecified origin.
+ *
+ * The purpose of a the Bytes class is to keep the memory region that it holds
+ * alive for as long as anyone holds a reference to the bytes. When
+ * the last reference count is dropped, the memory is released. Multiple
+ * unrelated callers can use byte data in the Bytes object without coordinating
+ * their activities, resting assured that the byte data will not change or
+ * move while they hold a reference.
+ *
+ * A Bytes object can come from many different origins that may have
+ * different procedures for freeing the memory region. Examples are
+ * memory from g_malloc(), from memory slices, from a GMappedFile or
+ * memory from other allocators.
+ *
+ * @newin{2,34}
+ */
+class Bytes
+{
+ _CLASS_OPAQUE_REFCOUNTED(Bytes, GBytes, NONE, g_bytes_ref, g_bytes_unref)
+ _IGNORE(g_bytes_ref, g_bytes_unref)
+public:
+
+ static Glib::RefPtr<Glib::Bytes> create(gconstpointer data, gsize size);
+
+ _WRAP_METHOD(gconstpointer get_data(gsize& size) const, g_bytes_get_data)
+ _WRAP_METHOD(gsize get_size() const, g_bytes_get_size)
+
+ _WRAP_METHOD(static guint hash(gconstpointer bytes), g_bytes_hash)
+ _WRAP_METHOD(static bool equal(gconstpointer bytes1, gconstpointer bytes2), g_bytes_equal)
+ _WRAP_METHOD(static gint compare(gconstpointer bytes1, gconstpointer bytes2), g_bytes_compare)
+};
+
+} // namespace Glib
diff --git a/glib/src/filelist.am b/glib/src/filelist.am
index 06c6baf..64b8b60 100644
--- a/glib/src/filelist.am
+++ b/glib/src/filelist.am
@@ -17,6 +17,7 @@ glibmm_files_defs = \
# Note that all of thread.hg is deprecated
glibmm_files_hg = \
balancedtree.hg \
+ bytes.hg \
checksum.hg \
convert.hg \
date.hg \
diff --git a/tools/m4/convert_glib.m4 b/tools/m4/convert_glib.m4
index 55de647..70c9d2a 100644
--- a/tools/m4/convert_glib.m4
+++ b/tools/m4/convert_glib.m4
@@ -122,6 +122,10 @@ dnl OptionGroup
_CONVERSION(`OptionGroup&',`GOptionGroup*',`($3).gobj()')
#_CONVERSION(`GOptionGroup*',`OptionGroup',`Glib::wrap(($3), true /* take_copy */)')
+dnl Bytes
+_CONVERSION(`GBytes*',`Glib::RefPtr<Glib::Bytes>',`Glib::wrap($3)')
+_CONVERSION(`GBytes*',`Glib::RefPtr<const Glib::Bytes>',`Glib::wrap($3)')
+
dnl Regex
_CONVERSION(`GRegex*',`Glib::RefPtr<Regex>',`Glib::wrap($3)')
_CONVERSION(`GRegex*',`Glib::RefPtr<const Regex>',`Glib::wrap($3)')
@@ -147,5 +151,5 @@ _CONVERSION(`const Glib::VariantType&',`const GVariantType*',`($3).gobj()')
_CONVERSION(`const GVariantType*',`VariantType',`Glib::wrap(const_cast<GVariantType*>($3), true)')
_CONVERSION(`GVariantType*',`VariantType',`Glib::wrap(($3), true)')
-dnl Misillaneous
+dnl Miscellaneous
_CONVERSION(`gint64&',`gint64*',`&($3)')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]