From 19a5ab01a0a2bb8318fe7d101574e8d46c5e8a03 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 22 Jan 2016 11:40:12 +0100 Subject: [PATCH] Add the MatrixClient::login-finished signal --- .gitignore | 1 + configure.ac | 1 + .../matrix-glib/matrix-glib-sections.txt | 1 + src/Makefile.am | 24 +++++++++++-- src/matrix-client.c | 36 +++++++++++++++++++ src/matrix-client.h | 4 +++ src/matrix-marshalers.list | 1 + 7 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/matrix-marshalers.list diff --git a/.gitignore b/.gitignore index 5e912d8..c86184f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ Makefile.in /GTAGS /src/matrix-version.h /src/matrix-enumtypes.[ch] +/src/matrix-marshalers.[ch] /docs/reference/matrix-glib/version.xml /docs/reference/matrix-glib/html/ /docs/reference/matrix-glib/xml/ diff --git a/configure.ac b/configure.ac index 367f277..65e3b01 100644 --- a/configure.ac +++ b/configure.ac @@ -51,6 +51,7 @@ GOBJECT_INTROSPECTION_CHECK([1.0]) PKG_PROG_PKG_CONFIG AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums]) +AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal]) PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.38]) PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.38]) diff --git a/docs/reference/matrix-glib/matrix-glib-sections.txt b/docs/reference/matrix-glib/matrix-glib-sections.txt index 6c846ec..390e436 100644 --- a/docs/reference/matrix-glib/matrix-glib-sections.txt +++ b/docs/reference/matrix-glib/matrix-glib-sections.txt @@ -3,6 +3,7 @@ MatrixClient MatrixClient MatrixClientInterface +matrix_client_login_finished matrix_client_register_with_password matrix_client_login_with_password matrix_client_logout diff --git a/src/Makefile.am b/src/Makefile.am index 96526df..77a84b8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,10 +4,10 @@ lib_LTLIBRARIES = libmatrix-glib-0.0.la bin_PROGRAMS = test-api-client INST_H_SRC_FILES = \ - matrix-client.h \ matrix-api.h \ matrix-api-types.h \ matrix-http-api.h \ + matrix-client.h \ $(NULL) INST_H_BUILT_FILES = \ @@ -21,13 +21,14 @@ matrix_enum_headers = \ $(NULL) libmatrix_glib_0_0_la_SOURCES = \ - matrix-client.c \ matrix-version.c \ matrix-api.c \ matrix-api-types.c \ matrix-http-api.c \ matrix-enumtypes.c \ utils.c \ + matrix-marshalers.c \ + matrix-client.c \ $(INST_H_SRC_FILES) \ $(INST_H_BUILT_FILES) \ $(NULL) @@ -36,7 +37,12 @@ libmatrix_glib_0_0_la_CFLAGS = $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) $(SOUP_CFLAGS) $ libmatrix_glib_0_0_la_LIBADD = $(GLIB_LIBS) $(GOBJECT_LIBS) $(SOUP_LIBS) $(JSON_LIBS) libmatrix_glib_0_0_la_DEPENDENCIES = -BUILT_SOURCES = matrix-enumtypes.c matrix-enumtypes.h +BUILT_SOURCES = \ + matrix-enumtypes.c \ + matrix-enumtypes.h \ + matrix-marshalers.c \ + matrix-marshalers.h \ + $(NULL) test_api_client_SOURCES = test-api-client.c $(libmatrix_glib_0_0_la_SOURCES) test_api_client_CFLAGS = $(libmatrix_glib_0_0_la_CFLAGS) @@ -46,6 +52,7 @@ CLEANFILES = $(BUILT_SOURCES) EXTRA_DIST = \ matrix-enumtypes.h.template \ matrix-enumtypes.c.template \ + matrix-marshalers.list \ $(INST_H_SRC_FILES) \ $(NULL) @@ -57,6 +64,17 @@ matrix-enumtypes.c: $(matrix_enum_headers) matrix-enumtypes.h matrix-enumtypes.c $(AM_V_GEN) $(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > $@.tmp \ && mv $@.tmp $@ +matrix-marshalers.h: matrix-marshalers.list + $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_matrix_marshal $(srcdir)/matrix-marshalers.list --header --valist-marshallers >> xgen-gmlh \ + && (cmp -s xgen-gmlh matrix-marshalers.h || cp xgen-gmlh matrix-marshalers.h) \ + && rm -f xgen-gmlh + +matrix-marshalers.c: matrix-marshalers.list + $(AM_V_GEN) (echo "#include \"matrix-marshalers.h\""; \ + $(GLIB_GENMARSHAL) --prefix=_matrix_marshal $(srcdir)/matrix-marshalers.list --body --valist-marshallers) >> xgen-gmlc \ + && cp xgen-gmlc matrix-marshalers.c \ + && rm -f xgen-gmlc + include $(INTROSPECTION_MAKEFILE) MatrixGlib-$(MATRIX_GLIB_API_VERSION).gir: libmatrix-glib-0.0.la Matrix_@MATRIX_GLIB_API_VERSION_U@_gir_FILES = $(INST_H_SRC_FILES) $(INST_H_BUILT_FILES) $(filter %.c,$(libmatrix_glib_0_0_la_SOURCES)) diff --git a/src/matrix-client.c b/src/matrix-client.c index 947b1f4..e092c03 100644 --- a/src/matrix-client.c +++ b/src/matrix-client.c @@ -17,6 +17,7 @@ */ #include "matrix-client.h" +#include "matrix-marshalers.h" /** * SECTION:matrix-client @@ -31,6 +32,7 @@ /** * MatrixClientInterface: + * @login_finished: signal is a sign of a finished login request * @login_with_password: virtual function for * matrix_client_login_with_password() * @register_with_password: virtual function for @@ -53,6 +55,25 @@ G_DEFINE_INTERFACE(MatrixClient, matrix_client, G_TYPE_OBJECT); static void matrix_client_default_init(MatrixClientInterface *iface) { + /** + * MatrixClient::login-finished: + * @client: a #MatrixClient + * @success: if %TRUE, login was successful + * + * This signal is a sign for a finished login request. + * + * Implementations of #MatrixClient are responsible for emitting + * this signal when they get a response for a login request. + * + * matrix_client_login_finished() is a convenience function for + * emitting #MatrixClient::login-finished. + */ + g_signal_new("login-finished", + MATRIX_TYPE_CLIENT, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(MatrixClientInterface, login_finished), + NULL, NULL, _matrix_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); } /** @@ -160,3 +181,18 @@ matrix_client_stop_polling(MatrixClient *client, MATRIX_CLIENT_GET_IFACE(client) ->stop_polling(client, cancel_ongoing, error); } + +/** + * matrix_client_login_finished: + * @client: a #MatrixClient + * @success: if %TRUE, login was successful + * + * Emits the #MatrixClient::login-finished signal. + */ +void +matrix_client_login_finished(MatrixClient *client, gboolean success) +{ + g_return_if_fail(MATRIX_IS_CLIENT(client)); + + g_signal_emit_by_name(client, "login-finished", success); +} diff --git a/src/matrix-client.h b/src/matrix-client.h index c13f8d4..eccac00 100644 --- a/src/matrix-client.h +++ b/src/matrix-client.h @@ -54,6 +54,8 @@ struct _MatrixClientInterface { void (*stop_polling)(MatrixClient *client, gboolean cancel_ongoing, GError **error); + + void (*login_finished)(MatrixClient *client, gboolean success); }; struct _MatrixClientClass { @@ -63,6 +65,8 @@ struct _MatrixClientClass { GType matrix_client_get_type(void) G_GNUC_CONST; +void matrix_client_login_finished(MatrixClient *client, gboolean success); + void matrix_client_login_with_password(MatrixClient *client, const gchar *username, const gchar *password, diff --git a/src/matrix-marshalers.list b/src/matrix-marshalers.list new file mode 100644 index 0000000..1ac3104 --- /dev/null +++ b/src/matrix-marshalers.list @@ -0,0 +1 @@ +VOID:BOOLEAN