From 2f366ee30d12973ba9f933a9df68280da52ab011 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 29 Jan 2016 17:00:13 +0100 Subject: [PATCH] Add the MATRIX_API_CALLBACK_PROTO convenience macro It can ease creating API callback function headers. --- .../matrix-glib/matrix-glib-sections.txt | 1 + src/matrix-api.c | 20 +++++++++++++++++++ src/matrix-api.h | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/docs/reference/matrix-glib/matrix-glib-sections.txt b/docs/reference/matrix-glib/matrix-glib-sections.txt index e5ac222..a5f3280 100644 --- a/docs/reference/matrix-glib/matrix-glib-sections.txt +++ b/docs/reference/matrix-glib/matrix-glib-sections.txt @@ -236,6 +236,7 @@ matrix_presence_event_get_type MatrixAPI MatrixAPIInterface MatrixAPICallback +MATRIX_API_CALLBACK_PROTO matrix_api_set_token diff --git a/src/matrix-api.c b/src/matrix-api.c index 44f9e93..0d6a088 100644 --- a/src/matrix-api.c +++ b/src/matrix-api.c @@ -120,6 +120,26 @@ * @raw_content will be set. */ +/** + * MATRIX_API_CALLBACK_PROTO: + * @name: the name of the function + * + * Convenience macro to define a #MatrixAPICallback function. The + * parameter names in the defined function will be the same as defined + * in #MatrixAPICallback. + * + * |[ + * // Use it for prototypes… + * MATRIX_API_CALLBACK_PROTO(my_fancy_callback); + * + * // …or for the implementation. + * MATRIX_API_CALLBACK_PROTO(my_fancy_callback) + * { + * do_callback_stuff(api, json_content); + * } + * ]| + */ + G_DEFINE_INTERFACE(MatrixAPI, matrix_api, G_TYPE_OBJECT); static void diff --git a/src/matrix-api.h b/src/matrix-api.h index f114e8c..1bd6f5e 100644 --- a/src/matrix-api.h +++ b/src/matrix-api.h @@ -41,6 +41,14 @@ typedef void (*MatrixAPICallback)(MatrixAPI *api, gpointer user_data, GError *err); +#define MATRIX_API_CALLBACK_PROTO(name) static void \ + name (MatrixAPI *api, \ + const gchar *content_type, \ + JsonNode *json_content, \ + GByteArray *raw_content, \ + gpointer user_data, \ + GError *error) + struct _MatrixAPIInterface { /*< private >*/ GTypeInterface g_iface;