diff --git a/.gitignore b/.gitignore index b0df6f9..5682f20 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ Makefile.in /src/vala-stamp /src/matrix-glib.h /src/matrix-api.c +/src/matrix-client.c diff --git a/autogen.sh b/autogen.sh index eb7937e..7bb79a1 100755 --- a/autogen.sh +++ b/autogen.sh @@ -8,7 +8,7 @@ DIE=0 PKG_NAME="matrix-glib" (test -f "$srcdir/configure.ac" \ - && test -f "$srcdir/src/matrix-client.c") || { + && test -f "$srcdir/src/matrix-client.vala") || { echo -n "**Error**: Directory "\`$srcdir\'" does not look like the" echo " top-level $PKG_NAME directory" diff --git a/src/Makefile.am b/src/Makefile.am index 3ef395a..f0474ec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,7 @@ lib_LTLIBRARIES = libmatrix-glib-0.0.la # Vala source files libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-api.vala \ + matrix-client.vala \ $(NULL) AM_CPPFLAGS += \ @@ -72,7 +73,6 @@ bin_PROGRAMS = test-api-client INST_H_SRC_FILES = \ matrix-types.h \ matrix-http-api.h \ - matrix-client.h \ matrix-http-client.h \ $(NULL) @@ -87,14 +87,12 @@ matrix_enum_headers = \ libmatrix_glib_0_0_la_SOURCES = \ $(INST_H_BUILT_FILES) \ - matrix-marshalers.c \ $(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c) \ matrix-version.c \ matrix-types.c \ matrix-http-api.c \ matrix-enumtypes.c \ utils.c \ - matrix-client.c \ matrix-http-client.c \ $(INST_H_SRC_FILES) \ $(NULL) @@ -121,8 +119,6 @@ $(PUBLIC_HEADER): vala-stamp BUILT_SOURCES += \ matrix-enumtypes.c \ matrix-enumtypes.h \ - matrix-marshalers.c \ - matrix-marshalers.h \ $(NULL) test_api_client_SOURCES = test-api-client.c @@ -136,7 +132,6 @@ CLEANFILES += $(BUILT_SOURCES) EXTRA_DIST += \ matrix-enumtypes.h.template \ matrix-enumtypes.c.template \ - matrix-marshalers.list \ $(INST_H_SRC_FILES) \ $(NULL) @@ -150,29 +145,6 @@ matrix-enumtypes.c: $(matrix_enum_headers) matrix-enumtypes.h matrix-enumtypes.c $(filter-out %.template,$^) > $@.tmp \ && mv $@.tmp $@ -matrix-marshalers.h: stamp-matrix-marshalers - @true - -stamp-matrix-marshalers: 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 \ - && echo timestamp > $(@F) - -matrix-marshalers.c: matrix-marshalers.h - $(AM_V_GEN) (echo "#include \"matrix-marshalers.h\""; \ - echo "#undef G_ENABLE_DEBUG"; \ - $(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) Matrix-0.0.gir: libmatrix-glib-$(MATRIX_GLIB_API_VERSION).la diff --git a/src/matrix-client.c b/src/matrix-client.c deleted file mode 100644 index e092c03..0000000 --- a/src/matrix-client.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * This file is part of matrix-glib-sdk - * - * matrix-glib-sdk 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 3 of the License, or (at your option) any later version. - * - * matrix-glib-sdk 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 matrix-glib-sdk. If not, see - * . - */ - -#include "matrix-client.h" -#include "matrix-marshalers.h" - -/** - * SECTION:matrix-client - * @short_description: Base interface for communication with a Matrix.org server - * @title: MatrixClient - * @stability: Unstable - * @include: matrix-glib/matrix-client.h - * - * This is the base interface for client communication with a - * Matrix.org server. - */ - -/** - * 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 - * matrix_client_register_with_password() - * @logout: virtual function for matrix_client_logout() - * @begin_polling: virtual function for matrix_client_begin_polling() - * @stop_polling: virtual function for matrix_client_stop_polling() - * - * The interface vtable for #MatrixClient - */ - -/** - * MatrixClient: - * - * The MatrixClient object’s interface definition. - */ - -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); -} - -/** - * matrix_client_login_with_password: - * @client: a #MatrixClient - * @username: the username to login with - * @password: the password to use - * @error: a location for a #GError, or %NULL - * - * Authenticate with the Matrix.org server with a username and - * password. - */ -void -matrix_client_login_with_password(MatrixClient *client, - const gchar *username, - const gchar *password, - GError **error) -{ - g_return_if_fail(MATRIX_IS_CLIENT(client)); - - MATRIX_CLIENT_GET_IFACE(client) - ->login_with_password(client, username, password, error); -} - -/** - * matrix_client_register_with_password: - * @client: a #MatrixClient - * @username: (allow-none): the username to register. If omitted, the - * server will generate one - * @password: the password to use with the registration - * @error: a location for a #GError, or %NULL - * - * Register @username with the homeserver as a normal user. - * - * Upon success, the user is registered and authenticated. - * - * Implementations of #MatrixClient must emit - * MatrixClient::login-finished when a response arrives. - * - * If you want to register a different kind of user, use - * matrix_api_register_account(). - */ -void -matrix_client_register_with_password(MatrixClient *client, - const gchar *username, - const gchar *password, - GError **error) -{ - g_return_if_fail(MATRIX_IS_CLIENT(client)); - - MATRIX_CLIENT_GET_IFACE(client) - ->register_with_password(client, username, password, error); -} - -/** - * matrix_client_logout: - * @client: a #MatrixClient - * @error: a location for a #GError, or %NULL - * - * Logout from the homeserver. As Matrix.org doesn’t have such an - * option, this cancels all ongoing requests and clears the - * authentication data (e.g. tokens). - */ -void -matrix_client_logout(MatrixClient *client, GError **error) -{ - g_return_if_fail(MATRIX_IS_CLIENT(client)); - - MATRIX_CLIENT_GET_IFACE(client) - ->logout(client, error); -} - -/** - * matrix_client_begin_polling: - * @client: a #MatrixClient - * @error: a location for a #GError, or %NULL - * - * Begin polling the event stream. - */ -void -matrix_client_begin_polling(MatrixClient *client, GError **error) -{ - g_return_if_fail(MATRIX_IS_CLIENT(client)); - - MATRIX_CLIENT_GET_IFACE(client) - ->begin_polling(client, error); -} - -/** - * matrix_client_stop_polling: - * @client: a #MatrixClient - * @cancel_ongoing: if %TRUE, ongoing requests will be cancelled, too - * @error: a location for a #GError, or %NULL - * - * Stop polling the event stream. If @cancel_ongoing is %TRUE, ongoing - * requests will be cancelled, too. - */ -void -matrix_client_stop_polling(MatrixClient *client, - gboolean cancel_ongoing, - GError **error) -{ - g_return_if_fail(MATRIX_IS_CLIENT(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 deleted file mode 100644 index eccac00..0000000 --- a/src/matrix-client.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of matrix-glib-sdk - * - * matrix-glib-sdk 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 3 of the License, or (at your option) any later version. - * - * matrix-glib-sdk 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 matrix-glib-sdk. If not, see - * . - */ - -#ifndef __MATRIX_CLIENT_H__ -#define __MATRIX_CLIENT_H__ - -#include - -G_BEGIN_DECLS - -#define MATRIX_TYPE_CLIENT (matrix_client_get_type()) -#define MATRIX_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), MATRIX_TYPE_CLIENT, MatrixClient)) -#define MATRIX_IS_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), MATRIX_TYPE_CLIENT)) -#define MATRIX_CLIENT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), MATRIX_TYPE_CLIENT, MatrixClientInterface)) - -typedef struct _MatrixClientInterface MatrixClientInterface; -typedef struct _MatrixClient MatrixClient; - -struct _MatrixClientInterface { - /*< private >*/ - /* Parent instance structure */ - GTypeInterface g_iface; - - /*< public >*/ - /* Instance members */ - - /* Virtual table */ - void (*login_with_password)(MatrixClient *client, - const gchar *username, - const gchar *password, - GError **error); - void (*register_with_password)(MatrixClient *client, - const gchar *username, - const gchar *password, - GError **error); - void (*logout)(MatrixClient *client, GError **error); - - void (*begin_polling)(MatrixClient *client, GError **error); - void (*stop_polling)(MatrixClient *client, - gboolean cancel_ongoing, - GError **error); - - void (*login_finished)(MatrixClient *client, gboolean success); -}; - -struct _MatrixClientClass { - /* Parent class */ - GObjectClass parent_class; -}; - -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, - GError **error); -void matrix_client_register_with_password(MatrixClient *client, - const gchar *username, - const gchar *password, - GError **error); -void matrix_client_logout(MatrixClient *client, GError **error); - -void matrix_client_begin_polling(MatrixClient *client, GError **error); -void matrix_client_stop_polling(MatrixClient *client, - gboolean cancel_ongoing, - GError **error); - -G_END_DECLS - -#endif /* __MATRIX_CLIENT_H__ */ diff --git a/src/matrix-client.vala b/src/matrix-client.vala new file mode 100644 index 0000000..867f794 --- /dev/null +++ b/src/matrix-client.vala @@ -0,0 +1,106 @@ +/* + * This file is part of matrix-glib-sdk + * + * matrix-glib-sdk 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 3 of the License, or (at your option) any later version. + * + * matrix-glib-sdk 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 matrix-glib-sdk. If not, see + * . + */ + +/** + * Base interface for client communication with a Matrix.org + * homeserver + */ +public interface Matrix.Client : GLib.Object { + /** + * This signal is a sign for a finished login request. + * + * Implementations are responsible for emitting this signal when + * they get a response for a login request. + * + * @param success if %TRUE, login was successful + */ + public virtual signal void + login_finished(bool success) + {} + + /** + * Authenticate with the Matrix.org server with a username and + * password. + * + * @param username the username to login with + * @param password the password to use + */ + public abstract void + login_with_password(string username, + string password) + throws Matrix.Error; + + /** + * Register @username with the homeserver as a normal user. + * + * Upon success, the user is registered and authenticated. + * + * Implementations must emit the login-finished signal when a + * response arrives. + * + * This method registers a normal user account. If you want to + * register a different kind of user, use + * matrix_api_register_account(). + * + * @param username the username to register. If omitted, the + * server will generate one + * @param password the password to use with the registration + */ + public abstract void + register_with_password(string? username, + string password) + throws Matrix.Error; + + /** + * Logout from the homeserver. As Matrix.org doesn’t have such a + * concept, this cancels all ongoing requests and clears the + * authentication data (e.g. tokens). + */ + public abstract void + logout() + throws Matrix.Error; + + /** + * Begin polling the event stream. + */ + public abstract void + begin_polling() + throws Matrix.Error; + + /** + * Stop polling the event stream. If @param cancel_ongoing is + * {{{true}}}, ongoing requests will be cancelled, too. + * + * @param cancel_ongoing if {{{true}}}, ongoing requests will be + * cancelled, too + */ + public abstract void + stop_polling(bool cancel_ongoing) + throws Matrix.Error; + + /** + * Convenience function to emits the login-finished signal. + * + * @param success set to {{{true}}} if login was successful + */ + public void + emit_login_finished(bool success) + { + login_finished(success); + } +} diff --git a/src/matrix-http-client.c b/src/matrix-http-client.c index 308a97b..9604946 100644 --- a/src/matrix-http-client.c +++ b/src/matrix-http-client.c @@ -45,7 +45,7 @@ typedef struct _MatrixHTTPClientPrivate { guint event_timeout; } MatrixHTTPClientPrivate; -static void matrix_http_client_matrix_client_init(MatrixClientInterface *iface); +static void matrix_http_client_matrix_client_init(MatrixClientIface *iface); static void i_begin_polling(MatrixClient *client, GError **error); G_DEFINE_TYPE_WITH_CODE(MatrixHTTPClient, matrix_http_client, MATRIX_TYPE_HTTP_API, @@ -61,7 +61,7 @@ cb_login(MatrixAPI *api, GError *error, gpointer user_data) { - matrix_client_login_finished(MATRIX_CLIENT(api), (error == NULL)); + matrix_client_emit_login_finished(MATRIX_CLIENT(api), (error == NULL)); } static void @@ -100,7 +100,7 @@ cb_register_account(MatrixAPI *api, GError *error, gpointer user_data) { - matrix_client_login_finished(MATRIX_CLIENT(api), (error == NULL)); + matrix_client_emit_login_finished(MATRIX_CLIENT(api), (error == NULL)); } static void @@ -211,7 +211,7 @@ i_stop_polling(MatrixClient *client, gboolean cancel_ongoing, GError **error) } static void -matrix_http_client_matrix_client_init(MatrixClientInterface *iface) +matrix_http_client_matrix_client_init(MatrixClientIface *iface) { iface->login_with_password = i_login_with_password; iface->register_with_password = i_register_with_password; diff --git a/src/matrix-http-client.h b/src/matrix-http-client.h index d0ce11d..28c066f 100644 --- a/src/matrix-http-client.h +++ b/src/matrix-http-client.h @@ -20,7 +20,7 @@ #define __MATRIX_HTTP_CLIENT_H__ #include -#include "matrix-client.h" +#include "matrix-glib.h" #include "matrix-http-api.h" G_BEGIN_DECLS diff --git a/src/matrix-marshalers.list b/src/matrix-marshalers.list deleted file mode 100644 index 1ac3104..0000000 --- a/src/matrix-marshalers.list +++ /dev/null @@ -1 +0,0 @@ -VOID:BOOLEAN