From 88da04e0a0875227f3fb81d6a1699da67503d56a Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 4 Mar 2015 17:26:55 +0100 Subject: [PATCH] validate:report: Allow registering of issue types through the introspection Fixing annotations and make GstValidateIssue refcounted We break the ABI in that commit but I do not expect anyone to register issue type outside GstValidate yet. Add padding in the structures so we can avoid breaking the ABI again later. --- validate/gst/validate/gst-validate-report.c | 57 +++++++++++++++---- validate/gst/validate/gst-validate-report.h | 8 +++ validate/gst/validate/gst-validate-reporter.c | 7 +++ 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/validate/gst/validate/gst-validate-report.c b/validate/gst/validate/gst-validate-report.c index fecf7fb2de..9319cb9e67 100644 --- a/validate/gst/validate/gst-validate-report.c +++ b/validate/gst/validate/gst-validate-report.c @@ -64,12 +64,50 @@ G_DEFINE_BOXED_TYPE (GstValidateReport, gst_validate_report, (GBoxedCopyFunc) gst_validate_report_ref, (GBoxedFreeFunc) gst_validate_report_unref); +static GstValidateIssue * +gst_validate_issue_ref (GstValidateIssue * issue) +{ + g_return_val_if_fail (issue != NULL, NULL); + + g_atomic_int_inc (&issue->refcount); + + return issue; +} + +static void +gst_validate_issue_unref (GstValidateIssue * issue) +{ + if (G_UNLIKELY (g_atomic_int_dec_and_test (&issue->refcount))) { + g_free (issue->summary); + g_free (issue->description); + + /* We are using an string array for area and name */ + g_strfreev (&issue->area); + + g_slice_free (GstValidateIssue, issue); + } +} + + +G_DEFINE_BOXED_TYPE (GstValidateIssue, gst_validate_issue, + (GBoxedCopyFunc) gst_validate_issue_ref, + (GBoxedFreeFunc) gst_validate_issue_unref); + GstValidateIssueId gst_validate_issue_get_id (GstValidateIssue * issue) { return issue->issue_id; } +/** + * gst_validate_issue_new: + * @issue_id: The ID of the issue, should be a GQuark + * @summary: A summary of the issue + * @description: A more complete of what the issue is about + * @default_level: The level at which the issue will be reported by default + * + * Returns: (transfer full): The newly created #GstValidateIssue + */ GstValidateIssue * gst_validate_issue_new (GstValidateIssueId issue_id, const gchar * summary, const gchar * description, GstValidateReportLevel default_level) @@ -101,17 +139,12 @@ gst_validate_issue_set_default_level (GstValidateIssue * issue, issue->default_level = default_level; } -static void -gst_validate_issue_free (GstValidateIssue * issue) -{ - g_free (issue->summary); - g_free (issue->description); - - /* We are using an string array for area and name */ - g_strfreev (&issue->area); - g_slice_free (GstValidateIssue, issue); -} - +/** + * gst_validate_issue_register: + * @issue: (transfer none): The #GstValidateIssue to register + * + * Registers @issue in the issue type system + */ void gst_validate_issue_register (GstValidateIssue * issue) { @@ -131,7 +164,7 @@ gst_validate_report_load_issues (void) g_return_if_fail (_gst_validate_issues == NULL); _gst_validate_issues = g_hash_table_new_full (g_direct_hash, g_direct_equal, - NULL, (GDestroyNotify) gst_validate_issue_free); + NULL, (GDestroyNotify) gst_validate_issue_unref); REGISTER_VALIDATE_ISSUE (WARNING, BUFFER_BEFORE_SEGMENT, _("buffer was received before a segment"), diff --git a/validate/gst/validate/gst-validate-report.h b/validate/gst/validate/gst-validate-report.h index 93265fed08..d9cfeafa81 100644 --- a/validate/gst/validate/gst-validate-report.h +++ b/validate/gst/validate/gst-validate-report.h @@ -136,8 +136,14 @@ typedef struct { * issue. */ GstValidateReportLevel default_level; + gint refcount; + + gpointer _gst_reserved[GST_PADDING]; + } GstValidateIssue; +GType gst_validate_issue_get_type (void); + struct _GstValidateReport { gint refcount; @@ -168,6 +174,8 @@ struct _GstValidateReport { GList *repeated_reports; GstValidateReportingDetails reporting_level; + + gpointer _gst_reserved[GST_PADDING]; }; void gst_validate_report_add_message (GstValidateReport *report, diff --git a/validate/gst/validate/gst-validate-reporter.c b/validate/gst/validate/gst-validate-reporter.c index a5e9b013ce..0b5b8acc53 100644 --- a/validate/gst/validate/gst-validate-reporter.c +++ b/validate/gst/validate/gst-validate-reporter.c @@ -275,6 +275,13 @@ gst_validate_reporter_report_simple (GstValidateReporter * reporter, gst_validate_report (reporter, issue_id, message); } +/** + * gst_validate_reporter_set_name: + * @reporter: The reporter to set the name on + * @name: (transfer full): The name of the reporter + * + * Sets @ name on @reporter + */ void gst_validate_reporter_set_name (GstValidateReporter * reporter, gchar * name) {