summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Barisione <marco@barisione.org>2011-08-02 14:36:06 +0100
committerMarco Barisione <marco@barisione.org>2011-08-03 14:28:13 +0100
commitdc03988d9d55d02a941c2c89fdaa4324f1b3f18c (patch)
tree0f15f058f2ae3c47d734b273be8b98afb2dd2eff
parent461cc42da79bbc77d24a13577deed477440b3493 (diff)
wocky-test-stream: allow to get notified directly whenever data is read
The callback passed to wocky_test_stream_set_direct_read_callback() is called whenever data is read by-passing all the other layers on top.
-rw-r--r--tests/wocky-test-stream.c16
-rw-r--r--tests/wocky-test-stream.h6
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/wocky-test-stream.c b/tests/wocky-test-stream.c
index b416c10..80e4df7 100644
--- a/tests/wocky-test-stream.c
+++ b/tests/wocky-test-stream.c
@@ -74,6 +74,8 @@ typedef struct {
GError *read_error /* no, this is not a coding style violation */;
gboolean dispose_has_run;
WockyTestStreamReadMode mode;
+ WockyTestStreamDirectReadCb direct_read_cb;
+ gpointer direct_read_user_data;
gboolean corked;
} WockyTestInputStream;
@@ -298,6 +300,9 @@ wocky_test_input_stream_read (GInputStream *stream, void *buffer, gsize count,
} while (self->mode != WOCK_TEST_STREAM_READ_EXACT
&& written < count && self->out_array != NULL);
+ if (self->direct_read_cb != NULL)
+ self->direct_read_cb (buffer, written, self->direct_read_user_data);
+
return written;
}
@@ -646,6 +651,17 @@ wocky_test_stream_cork (GInputStream *stream,
}
void
+wocky_test_stream_set_direct_read_callback (GInputStream *stream,
+ WockyTestStreamDirectReadCb cb,
+ gpointer user_data)
+{
+ WockyTestInputStream *tstream = WOCKY_TEST_INPUT_STREAM (stream);
+
+ tstream->direct_read_cb = cb;
+ tstream->direct_read_user_data = user_data;
+}
+
+void
wocky_test_stream_set_write_mode (GOutputStream *stream,
WockyTestStreamWriteMode mode)
{
diff --git a/tests/wocky-test-stream.h b/tests/wocky-test-stream.h
index 3c3e77a..0735d84 100644
--- a/tests/wocky-test-stream.h
+++ b/tests/wocky-test-stream.h
@@ -93,6 +93,12 @@ void wocky_test_stream_set_mode (GInputStream *stream,
void wocky_test_stream_set_write_mode (GOutputStream *stream,
WockyTestStreamWriteMode mode);
+typedef void (*WockyTestStreamDirectReadCb) (const gchar *buff, gsize len,
+ gpointer user_data);
+
+void wocky_test_stream_set_direct_read_callback (GInputStream *stream,
+ WockyTestStreamDirectReadCb cb, gpointer user_data);
+
G_END_DECLS
#endif /* #ifndef __WOCKY_TEST_STREAM_H__*/