From 955213605911f64fdf5b816dc12c66db49128287 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 15 Dec 2015 11:58:18 +0100 Subject: [PATCH] Add our own error quark --- .gitignore | 1 + .../matrix-glib/matrix-glib-sections.txt | 7 +++ src/Makefile.am | 26 +++++++- src/matrix-api.c | 30 ++++++++++ src/matrix-api.h | 13 ++++ src/matrix-enumtypes.c.template | 59 +++++++++++++++++++ src/matrix-enumtypes.h.template | 42 +++++++++++++ 7 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 src/matrix-enumtypes.c.template create mode 100644 src/matrix-enumtypes.h.template diff --git a/.gitignore b/.gitignore index 8475651..e81f5d2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ Makefile.in /GSYMS /GTAGS /src/matrix-version.h +/src/matrix-enumtypes.[ch] /docs/reference/matrix-glib/version.xml /docs/reference/matrix-glib/html/ /docs/reference/matrix-glib/xml/ diff --git a/docs/reference/matrix-glib/matrix-glib-sections.txt b/docs/reference/matrix-glib/matrix-glib-sections.txt index ac90e89..5de37d8 100644 --- a/docs/reference/matrix-glib/matrix-glib-sections.txt +++ b/docs/reference/matrix-glib/matrix-glib-sections.txt @@ -40,15 +40,22 @@ matrix_api_send_message matrix_api_send_message_event matrix_api_send_state_event matrix_api_set_membership + +MatrixAPIError +MATRIX_API_ERROR MatrixAPI MatrixAPIInterface +MATRIX_TYPE_API_ERROR +matrix_api_error_get_type MATRIX_TYPE_API MATRIX_API MATRIX_IS_API MATRIX_API_GET_IFACE MatrixApiPrivate matrix_api_get_type + +matrix_api_error_quark
diff --git a/src/Makefile.am b/src/Makefile.am index 6da1310..9ee1bf4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,13 +9,19 @@ INST_H_SRC_FILES = \ matrix-http-api.h \ $(NULL) -INST_H_BUILT_FILES = matrix-version.h +INST_H_BUILT_FILES = \ + matrix-version.h \ + matrix-enumtypes.h \ + $(NULL) + +matrix_enum_headers = matrix-api.h libmatrix_glib_0_0_la_SOURCES = \ matrix-client.c \ matrix-version.c \ matrix-api.c \ matrix-http-api.c \ + matrix-enumtypes.c \ $(INST_H_SRC_FILES) \ $(INST_H_BUILT_FILES) \ $(NULL) @@ -24,12 +30,26 @@ 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 + test_client_SOURCES = test-client.c $(libmatrix_glib_0_0_la_SOURCES) test_client_CFLAGS = $(libmatrix_glib_0_0_la_CFLAGS) test_client_LDADD = $(libmatrix_glib_0_0_la_LIBADD) -CLEANFILES = -EXTRA_DIST = $(INST_H_SRC_FILES) +CLEANFILES = $(BUILT_SOURCES) +EXTRA_DIST = \ + matrix-enumtypes.h.template \ + matrix-enumtypes.c.template \ + $(INST_H_SRC_FILES) \ + $(NULL) + +matrix-enumtypes.h: $(matrix_enum_headers) matrix-enumtypes.h.template + $(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \ + $@.tmp && mv $@.tmp $@ + +matrix-enumtypes.c: $(matrix_enum_headers) matrix-enumtypes.h matrix-enumtypes.c.template + $(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \ + $@.tmp && mv $@.tmp $@ include $(INTROSPECTION_MAKEFILE) MatrixGlib-$(MATRIX_GLIB_API_VERSION).gir: libmatrix-glib-0.0.la diff --git a/src/matrix-api.c b/src/matrix-api.c index 83223cf..90b8544 100644 --- a/src/matrix-api.c +++ b/src/matrix-api.c @@ -75,6 +75,36 @@ * A callback function to use with API calls. */ +/** + * MatrixAPIError: + * @MATRIX_API_ERROR_NONE: no error + * @MATRIX_API_ERROR_MISSING_TOKEN: authorization token is missing + * from the request + * @MATRIX_API_ERROR_FORBIDDEN: access was forbidden (e.g. due to a + * missing/invalid token, or using a bad + * password during login) + * @MATRIX_API_ERROR_UNKNOWN: an error unknown to the Matrix server + * @MATRIX_API_ERROR_UNKNOWN_ERROR: an error unknown to this library + * + * Value mappings from Matrix.org API error codes + * (e.g. M_MISSING_TOKEN). They should be set + * automatically by API calls, if the response contains an error code. + */ + +/** + * MATRIX_API_ERROR: + * + * Error domain for Matrix GLib SDK API. See #GError for more + * information on error domains. + */ + +/** + * matrix_api_error_quark: + * + * Gets the Matrix API error #GQuark + */ +G_DEFINE_QUARK(matrix-api-error-quark, matrix_api_error); + G_DEFINE_INTERFACE(MatrixAPI, matrix_api, G_TYPE_OBJECT); static void diff --git a/src/matrix-api.h b/src/matrix-api.h index c84c192..9ed6d52 100644 --- a/src/matrix-api.h +++ b/src/matrix-api.h @@ -24,6 +24,19 @@ G_BEGIN_DECLS +typedef enum { + MATRIX_API_ERROR_NONE, + MATRIX_API_ERROR_MISSING_TOKEN, + MATRIX_API_ERROR_FORBIDDEN, + MATRIX_API_ERROR_UNKNOWN, + /* Allow for a lot of Matrix.org defined codes + Do not define error codes after this! */ + MATRIX_API_ERROR_UNKNOWN_ERROR = 16384 +} MatrixAPIError; + +#define MATRIX_API_ERROR matrix_api_error_quark() +GQuark matrix_api_error_quark(void); + #define MATRIX_TYPE_API (matrix_api_get_type()) #define MATRIX_API(o) (G_TYPE_CHECK_INSTANCE_CAST((o), MATRIX_TYPE_API, MatrixAPI)) #define MATRIX_IS_API(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), MATRIX_TYPE_API)) diff --git a/src/matrix-enumtypes.c.template b/src/matrix-enumtypes.c.template new file mode 100644 index 0000000..82f02a8 --- /dev/null +++ b/src/matrix-enumtypes.c.template @@ -0,0 +1,59 @@ +/*** BEGIN file-header ***/ +/* + * 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-enumtypes.h" +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from @filename@ */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ + +GType +@enum_name@_get_type(void) +{ + static volatile gsize g_define_type_id__volatile = 0; + + if (g_once_init_enter(&g_define_type_id__volatile)) { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { + @VALUENAME@, + "@VALUENAME@", + "@valuenick@" + }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + {0, NULL, NULL} + }; + + GType g_define_type_id = g_@type@_register_static( + g_intern_static_string("@EnumName@"), + values); + g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} +/*** END value-tail ***/ diff --git a/src/matrix-enumtypes.h.template b/src/matrix-enumtypes.h.template new file mode 100644 index 0000000..0327afa --- /dev/null +++ b/src/matrix-enumtypes.h.template @@ -0,0 +1,42 @@ +/*** BEGIN file-header ***/ +/* + * 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_ENUMTYPES_H__ +#define __MATRIX_ENUMTYPES_H__ + +#include + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ + +#include "@filename@" +/*** END file-production ***/ + +/*** BEGIN value-header ***/ + +GType @enum_name@_get_type(void); +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ + +#endif /* __MATRIX_ENUMTYPES_H__ */ +/*** END file-tail ***/