[vte/vte-0-34] [stream] Add API to get start-of-page offsets



commit 480e1ae1cb9e343663896a19df31060f3bffb7b5
Author: Behdad Esfahbod <behdad behdad org>
Date:   Sun Sep 29 19:39:00 2013 -0400

    [stream] Add API to get start-of-page offsets
    
    For previous behavior of the _vte_stream_head() api, add
    index=0 to the new function.

 src/ring.c           |    8 ++++----
 src/vtestream-base.h |    8 +++++---
 src/vtestream-file.h |    4 ++--
 src/vtestream.h      |    7 ++++++-
 4 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/src/ring.c b/src/ring.c
index 6183724..9345164 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -124,8 +124,8 @@ _vte_ring_freeze_row (VteRing *ring, gulong position, const VteRowData *row)
 
        _vte_debug_print (VTE_DEBUG_RING, "Freezing row %lu.\n", position);
 
-       record.text_start_offset = _vte_stream_head (ring->text_stream);
-       record.attr_start_offset = _vte_stream_head (ring->attr_stream);
+       record.text_start_offset = _vte_stream_head (ring->text_stream, 0);
+       record.attr_start_offset = _vte_stream_head (ring->attr_stream, 0);
 
        g_string_set_size (buffer, 0);
        for (i = 0, cell = row->cells; i < row->len; i++, cell++) {
@@ -199,11 +199,11 @@ _vte_ring_thaw_row (VteRing *ring, gulong position, VteRowData *row, gboolean do
 
        if (!_vte_ring_read_row_record (ring, &records[0], position))
                return;
-       if ((position + 1) * sizeof (records[0]) < _vte_stream_head (ring->row_stream)) {
+       if ((position + 1) * sizeof (records[0]) < _vte_stream_head (ring->row_stream, 0)) {
                if (!_vte_ring_read_row_record (ring, &records[1], position + 1))
                        return;
        } else
-               records[1].text_start_offset = _vte_stream_head (ring->text_stream);
+               records[1].text_start_offset = _vte_stream_head (ring->text_stream, 0);
 
        g_string_set_size (buffer, records[1].text_start_offset - records[0].text_start_offset);
        if (!_vte_stream_read (ring->text_stream, records[0].text_start_offset, buffer->str, buffer->len))
diff --git a/src/vtestream-base.h b/src/vtestream-base.h
index cc7c9f0..dee5ff6 100644
--- a/src/vtestream-base.h
+++ b/src/vtestream-base.h
@@ -37,7 +37,7 @@ typedef struct _VteStreamClass {
        gboolean (*read) (VteStream *stream, gsize offset, char *data, gsize len);
        void (*truncate) (VteStream *stream, gsize offset);
        void (*new_page) (VteStream *stream);
-       gsize (*head) (VteStream *stream);
+       gsize (*head) (VteStream *stream, guint index);
        gboolean (*write_contents) (VteStream *stream, GOutputStream *output,
                                    gsize start_offset,
                                    GCancellable *cancellable, GError **error);
@@ -90,9 +90,11 @@ _vte_stream_new_page (VteStream *stream)
 }
 
 gsize
-_vte_stream_head (VteStream *stream)
+_vte_stream_head (VteStream *stream, guint index)
 {
-       return VTE_STREAM_GET_CLASS (stream)->head (stream);
+       g_assert (index < 3);
+
+       return VTE_STREAM_GET_CLASS (stream)->head (stream, index);
 }
 
 gboolean
diff --git a/src/vtestream-file.h b/src/vtestream-file.h
index f5624d1..c47b0b6 100644
--- a/src/vtestream-file.h
+++ b/src/vtestream-file.h
@@ -281,11 +281,11 @@ _vte_file_stream_new_page (VteStream *astream)
 }
 
 static gsize
-_vte_file_stream_head (VteStream *astream)
+_vte_file_stream_head (VteStream *astream, guint index)
 {
        VteFileStream *stream = (VteFileStream *) astream;
 
-       return stream->head;
+       return index == 0 ? stream->head : stream->offset[index - 1];
 }
 
 static gboolean
diff --git a/src/vtestream.h b/src/vtestream.h
index 29f4fc6..7b36e1f 100644
--- a/src/vtestream.h
+++ b/src/vtestream.h
@@ -33,7 +33,12 @@ void _vte_stream_append (VteStream *stream, const char *data, gsize len);
 gboolean _vte_stream_read (VteStream *stream, gsize offset, char *data, gsize len);
 void _vte_stream_truncate (VteStream *stream, gsize offset);
 void _vte_stream_new_page (VteStream *stream);
-gsize _vte_stream_head (VteStream *stream);
+/* The stream has two pages at each time.  This function returns three positions:
+ * - index == 0 -> position of writing head,
+ * - index == 1 -> start of current page,
+ * - index == 2 -> start of previous page (ie. last offset available in stream)
+ */
+gsize _vte_stream_head (VteStream *stream, guint index);
 gboolean _vte_stream_write_contents (VteStream *stream, GOutputStream *output,
                                     gsize start_offset,
                                     GCancellable *cancellable, GError **error);


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