From 4f630186d7f71bad200f9bc7ba271b966b3cb52a Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 28 Feb 2018 11:13:41 +0100 Subject: [PATCH] WIP: Add API methods for listing and fetching devices --- .../matrix-glib-sdk-sections.txt | 2 + src/matrix-api.c | 45 +++++++++++++++++++ src/matrix-api.h | 18 ++++++++ 3 files changed, 65 insertions(+) diff --git a/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt b/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt index 734d713..023da4b 100644 --- a/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt +++ b/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt @@ -74,6 +74,8 @@ matrix_api_get_turn_server matrix_api_media_download matrix_api_media_thumbnail matrix_api_media_upload +matrix_api_get_devices +matrix_api_get_device matrix_api_get_token matrix_api_set_token matrix_api_get_user_id diff --git a/src/matrix-api.c b/src/matrix-api.c index b443a65..9717b36 100644 --- a/src/matrix-api.c +++ b/src/matrix-api.c @@ -102,6 +102,8 @@ * @media_download: the virtual function pointer to matrix_api_media_download() * @media_thumbnail: the virtual function pointer to matrix_api_media_thumbnail() * @media_upload: the virtual function pointer to matrix_api_media_upload() + * @get_devices: the virtual function pointer to matrix_api_get_devices() + * @get_device: the virtual function pointer to matrix_api_get_device() * @get_token: the virtual function pointer to matrix_api_get_token() * @set_token: the virtual function pointer to matrix_api_set_token() * @get_user_id: the virtual function pointer to matrix_api_get_user_id() @@ -1975,6 +1977,49 @@ matrix_api_media_upload(MatrixAPI *matrix_api, MATRIX_API_GET_IFACE(matrix_api)->media_upload(matrix_api, callback, user_data, content_type, content, error); } +/** + * matrix_api_get_devices: + * @api: a #MatrixAPI + * @callback: a function to call when the request is finished + * @user_data: user data to be passed to @callback + * @error: (nullable): a #GError, or %NULL to ignore errors + * + * Get the list of devices for the current user. + */ +void +matrix_api_get_devices(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error) +{ + g_return_if_fail(api != NULL); + + MATRIX_API_GET_IFACE(api)->get_devices(api, callback, user_data, error); +} + +/** + * matrix_api_get_device: + * @api: a #MatrixAPI + * @device_id: a device ID + * @callback: a function to call when the request is finished + * @user_data: user data to be passed to @callback + * @error: (nullable): a #GError, or %NULL to ignore errors + * + * Get the details of the given device. + */ +void +matrix_api_get_device(MatrixAPI *api, + const gchar *device_id, + MatrixAPICallback callback, + gpointer user_data, + GError **error) +{ + g_return_if_fail(api != NULL); + g_return_if_fail(device_id != NULL); + + MATRIX_API_GET_IFACE(api)->get_device(api, device_id, callback, user_data, error); +} + /** * matrix_api_get_token: * @api: a #MatrixAPI diff --git a/src/matrix-api.h b/src/matrix-api.h index 0a45751..944b738 100644 --- a/src/matrix-api.h +++ b/src/matrix-api.h @@ -476,6 +476,15 @@ struct _MatrixAPIInterface { const gchar *content_type, GByteArray *content, GError **error); + void (*get_devices)(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error); + void (*get_device)(MatrixAPI *api, + const gchar *device_id, + MatrixAPICallback callback, + gpointer user_data, + GError **error); const gchar *(*get_token)(MatrixAPI *api); void (*set_token)(MatrixAPI *api, const gchar *value); const gchar *(*get_user_id)(MatrixAPI *api); @@ -920,6 +929,15 @@ void matrix_api_media_upload(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, GError **error); +void matrix_api_get_devices(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error); +void matrix_api_get_device(MatrixAPI *api, + const gchar *device_id, + MatrixAPICallback callback, + gpointer user_data, + GError **error); const gchar *matrix_api_get_token(MatrixAPI *api); void matrix_api_set_token(MatrixAPI *api, const gchar *token); const gchar *matrix_api_get_user_id(MatrixAPI *api);