xeme/xeme

Parents 1df1994969c0
Children 1e81da6ffa54
Add a restart-requested signal to XemeInputStream and a method to emit it

This will be necessary as we move into feature negotiation when connecting to
servers.

Testing Done:
Ran the unit tests under valgrind.

Reviewed at https://reviews.imfreedom.org/r/2901/
--- a/xeme/tests/testinputstream.c Tue Dec 19 00:45:55 2023 -0600
+++ b/xeme/tests/testinputstream.c Sun Dec 31 23:02:19 2023 -0600
@@ -126,14 +126,47 @@
}
/******************************************************************************
+ * Restart Requested Test
+ *****************************************************************************/
+static void
+test_xeme_input_stream_restart_requested_cb(XemeInputStream *stream,
+ gpointer data)
+{
+ guint *counter = data;
+
+ g_assert_true(XEME_IS_INPUT_STREAM(stream));
+
+ *counter = *counter + 1;
+}
+
+static void
+test_xeme_input_stream_restart_requested(void) {
+ XemeInputStream *stream = NULL;
+ guint counter = 0;
+
+ stream = xeme_input_stream_new();
+ g_signal_connect(stream, "restart-requested",
+ G_CALLBACK(test_xeme_input_stream_restart_requested_cb),
+ &counter);
+
+ g_assert_cmpuint(counter, ==, 0);
+ xeme_input_stream_restart_requested(stream);
+ g_assert_cmpuint(counter, ==, 1);
+
+ g_assert_finalize_object(stream);
+}
+
+/******************************************************************************
* Main
*****************************************************************************/
int
main(int argc, char *argv[]) {
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/xeme/input_stream/start",
+ g_test_add_func("/xeme/input-stream/start",
test_xeme_input_stream_start);
+ g_test_add_func("/xeme/input-stream/restart-requested",
+ test_xeme_input_stream_restart_requested);
return g_test_run();
}
--- a/xeme/xemeinputstream.c Tue Dec 19 00:45:55 2023 -0600
+++ b/xeme/xemeinputstream.c Sun Dec 31 23:02:19 2023 -0600
@@ -23,6 +23,7 @@
enum {
SIG_CLOSED,
+ SIG_RESTART_REQUESTED,
N_SIGNALS,
};
static guint signals[N_SIGNALS];
@@ -243,14 +244,36 @@
*/
signals[SIG_CLOSED] = g_signal_new_class_handler(
"closed",
- G_OBJECT_CLASS_TYPE(klass),
- G_SIGNAL_RUN_LAST,
- NULL,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE,
- 0);
+ G_OBJECT_CLASS_TYPE(klass),
+ G_SIGNAL_RUN_LAST,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 0);
+
+ /**
+ * XemeInputStream::restart-requested:
+ *
+ * Emitted when the remote side has requested that the output stream be
+ * restarted.
+ *
+ * This is typically requested during feature negotiation which happens
+ * during the initial connection.
+ *
+ * Since: 0.1.0
+ */
+ signals[SIG_RESTART_REQUESTED] = g_signal_new_class_handler(
+ "restart-requested",
+ G_OBJECT_CLASS_TYPE(klass),
+ G_SIGNAL_RUN_LAST,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 0);
}
/******************************************************************************
@@ -295,3 +318,10 @@
return TRUE;
}
+
+void
+xeme_input_stream_restart_requested(XemeInputStream *stream) {
+ g_return_if_fail(XEME_IS_INPUT_STREAM(stream));
+
+ g_signal_emit(stream, signals[SIG_RESTART_REQUESTED], 0);
+}
--- a/xeme/xemeinputstream.h Tue Dec 19 00:45:55 2023 -0600
+++ b/xeme/xemeinputstream.h Sun Dec 31 23:02:19 2023 -0600
@@ -76,6 +76,24 @@
XEME_AVAILABLE_IN_0_1
gboolean xeme_input_stream_start(XemeInputStream *stream, GInputStream *input, GError **error);
+/**
+ * xeme_input_stream_restart_requested:
+ * @stream: The instance.
+ *
+ * Emits the [signal@InputStream::restart-requested] signal.
+ *
+ * This should be called when the remote side has requested that the output
+ * stream should be restarted. This typically happens during feature
+ * negotiation during the initial connection.
+ *
+ * This signal allows who ever is managing the streams to call
+ * [method@OutputStream.restart] on the output stream.
+ *
+ * Since: 0.1.0
+ */
+XEME_AVAILABLE_IN_0_1
+void xeme_input_stream_restart_requested(XemeInputStream *stream);
+
G_END_DECLS
#endif /* XEME_INPUT_STREAM_H */