From b5de83be3c30642180d84602926abb4b986a508e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 21 Nov 2017 14:12:14 +0100 Subject: [PATCH] Port MatrixEventCallHangup to C --- .gitignore | 1 - src/Makefile.am | 3 +- src/matrix-event-call-hangup.c | 73 +++++++++++++++++++ ...hangup.vala => matrix-event-call-hangup.h} | 38 +++++----- src/matrix-event-types.c | 1 + vapi/c-api.vapi | 9 +++ 6 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 src/matrix-event-call-hangup.c rename src/{matrix-event-call-hangup.vala => matrix-event-call-hangup.h} (55%) diff --git a/.gitignore b/.gitignore index ed1862d..16589d0 100644 --- a/.gitignore +++ b/.gitignore @@ -62,5 +62,4 @@ Makefile.in /src/matrix-event-room-third-party-invite.c /src/matrix-event-call-invite.c /src/matrix-event-call-candidates.c -/src/matrix-event-call-hangup.c /src/matrix-glib-0.0.pc diff --git a/src/Makefile.am b/src/Makefile.am index b06d608..2c90cfd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,7 +30,6 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-room-third-party-invite.vala \ matrix-event-call-invite.vala \ matrix-event-call-candidates.vala \ - matrix-event-call-hangup.vala \ $(NULL) AM_CPPFLAGS += \ @@ -89,6 +88,7 @@ INST_H_SRC_FILES = \ matrix-event-base.h \ matrix-event-call-base.h \ matrix-event-call-answer.h \ + matrix-event-call-hangup.h \ matrix-message-base.h \ matrix-message-text.h \ matrix-message-location.h \ @@ -138,6 +138,7 @@ libmatrix_glib_0_0_la_SOURCES = \ matrix-event-base.c \ matrix-event-call-base.c \ matrix-event-call-answer.c \ + matrix-event-call-hangup.c \ matrix-message-base.c \ matrix-message-text.c \ matrix-message-location.c \ diff --git a/src/matrix-event-call-hangup.c b/src/matrix-event-call-hangup.c new file mode 100644 index 0000000..6419a23 --- /dev/null +++ b/src/matrix-event-call-hangup.c @@ -0,0 +1,73 @@ +/* + * 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-event-call-hangup.h" + +/** + * SECTION:matrix-event-call-hangup + * @short_description: event to signal that a calling party has hung up the line + * + * This event is sent by either party to signal their termination of the call. This can be + * sent either once the call has has been established or before to abort the call. + */ + +/** + * MatrixEventCallHangup: + * + */ +G_DEFINE_TYPE(MatrixEventCallHangup, matrix_event_call_hangup, MATRIX_EVENT_TYPE_CALL); + +static void +matrix_event_call_hangup_real_from_json(MatrixEventBase *matrix_event_base, JsonNode *json_data, GError **error) +{ + g_return_if_fail(json_data != NULL); + + MATRIX_EVENT_BASE_CLASS(matrix_event_call_hangup_parent_class)->from_json(matrix_event_base, json_data, error); +} + +static void +matrix_event_call_hangup_real_to_json(MatrixEventBase *matrix_event_base, JsonNode *json_data, GError **error) +{ + g_return_if_fail(json_data != NULL); + + MATRIX_EVENT_BASE_CLASS(matrix_event_call_hangup_parent_class)->to_json(matrix_event_base, json_data, error); +} + +/** + * matrix_event_call_hangup_new: + * + * Create a new #MatrixEventCallHangup object. + * + * Returns: (transfer full): a new #MatrixEventCallHangup object + */ +MatrixEventCallHangup * +matrix_event_call_hangup_new(void) +{ + return (MatrixEventCallHangup *)matrix_event_call_construct(MATRIX_EVENT_TYPE_CALL_HANGUP); +} + +static void +matrix_event_call_hangup_class_init(MatrixEventCallHangupClass *klass) +{ + ((MatrixEventBaseClass *)klass)->from_json = matrix_event_call_hangup_real_from_json; + ((MatrixEventBaseClass *)klass)->to_json = matrix_event_call_hangup_real_to_json; +} + +static void +matrix_event_call_hangup_init(MatrixEventCallHangup *matrix_event_call_hangup) +{} diff --git a/src/matrix-event-call-hangup.vala b/src/matrix-event-call-hangup.h similarity index 55% rename from src/matrix-event-call-hangup.vala rename to src/matrix-event-call-hangup.h index 9b099fb..f9d46b7 100644 --- a/src/matrix-event-call-hangup.vala +++ b/src/matrix-event-call-hangup.h @@ -16,23 +16,23 @@ * . */ -/** - * Sent by either party to signal their termination of the call. This - * can be sent either once the call has has been established or before - * to abort the call. - */ -public class Matrix.Event.CallHangup : Matrix.Event.Call { - protected override void - from_json(Json.Node json_data) - throws Matrix.Error - { - base.from_json(json_data); - } +#ifndef __MATRIX_GLIB_SDK_EVENT_CALL_HANGUP_H__ +# define __MATRIX_GLIB_SDK_EVENT_CALL_HANGUP_H__ - protected override void - to_json(Json.Node json_data) - throws Matrix.Error - { - base.to_json(json_data); - } -} +# include +# include "matrix-event-call-base.h" + +G_BEGIN_DECLS + +# define MATRIX_EVENT_TYPE_CALL_HANGUP matrix_event_call_hangup_get_type() +G_DECLARE_DERIVABLE_TYPE(MatrixEventCallHangup, matrix_event_call_hangup, MATRIX_EVENT, CALL_HANGUP, MatrixEventCall) + +struct _MatrixEventCallHangupClass { + MatrixEventCallClass parent_class; +}; + +MatrixEventCallHangup* matrix_event_call_hangup_new (void); + +G_END_DECLS + +#endif /* __MATRIX_GLIB_SDK_EVENT_CALL_HANGUP_H__ */ diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index d700f5a..17ed87c 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -31,6 +31,7 @@ #include "matrix-event-room-history-visibility.h" #include "matrix-event-room-join-rules.h" #include "matrix-event-call-answer.h" +#include "matrix-event-call-hangup.h" #include "matrix-message-text.h" #include "matrix-message-location.h" diff --git a/vapi/c-api.vapi b/vapi/c-api.vapi index 0d8ddbb..095f5f8 100644 --- a/vapi/c-api.vapi +++ b/vapi/c-api.vapi @@ -752,6 +752,15 @@ namespace Matrix { protected override void to_json(Json.Node json_data) throws Matrix.Error; } + + [CCode (cheader_filename = "matrix-event-call-hangup.h")] + public class CallHangup : Call { + protected override void from_json(Json.Node json_data) + throws Matrix.Error; + + protected override void to_json(Json.Node json_data) + throws Matrix.Error; + } } [CCode (gir_namespace = "MatrixMessage", gir_version = "0.0")]