/* sysprof-document-counter.c * * Copyright 2023 Christian Hergert * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * SPDX-License-Identifier: GPL-3.0-or-later */ #include "config.h" #include "sysprof-document-counter.h" struct _SysprofDocumentCounter { GObject parent_instance; GRefString *category; GRefString *description; GRefString *name; GArray *values; guint id; guint type; }; enum { PROP_0, PROP_CATEGORY, PROP_DESCRIPTION, PROP_ID, PROP_NAME, N_PROPS }; G_DEFINE_FINAL_TYPE (SysprofDocumentCounter, sysprof_document_counter, G_TYPE_OBJECT) static GParamSpec *properties [N_PROPS]; static void sysprof_document_counter_finalize (GObject *object) { SysprofDocumentCounter *self = (SysprofDocumentCounter *)object; g_clear_pointer (&self->category, g_ref_string_release); g_clear_pointer (&self->description, g_ref_string_release); g_clear_pointer (&self->name, g_ref_string_release); g_clear_pointer (&self->values, g_array_unref); G_OBJECT_CLASS (sysprof_document_counter_parent_class)->finalize (object); } static void sysprof_document_counter_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { SysprofDocumentCounter *self = SYSPROF_DOCUMENT_COUNTER (object); switch (prop_id) { case PROP_CATEGORY: g_value_set_string (value, sysprof_document_counter_get_category (self)); break; case PROP_DESCRIPTION: g_value_set_string (value, sysprof_document_counter_get_description (self)); break; case PROP_NAME: g_value_set_string (value, sysprof_document_counter_get_name (self)); break; case PROP_ID: g_value_set_uint (value, sysprof_document_counter_get_id (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } } static void sysprof_document_counter_class_init (SysprofDocumentCounterClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = sysprof_document_counter_finalize; object_class->get_property = sysprof_document_counter_get_property; properties [PROP_ID] = g_param_spec_uint ("id", NULL, NULL, 0, G_MAXUINT, 0, (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); properties [PROP_CATEGORY] = g_param_spec_string ("category", NULL, NULL, NULL, (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); properties [PROP_DESCRIPTION] = g_param_spec_string ("description", NULL, NULL, NULL, (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); properties [PROP_NAME] = g_param_spec_string ("name", NULL, NULL, NULL, (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_properties (object_class, N_PROPS, properties); } static void sysprof_document_counter_init (SysprofDocumentCounter *self) { } SysprofDocumentCounter * _sysprof_document_counter_new (guint id, guint type, GRefString *category, GRefString *name, GRefString *description, GArray *values) { SysprofDocumentCounter *self; self = g_object_new (SYSPROF_TYPE_DOCUMENT_COUNTER, NULL); self->id = id; self->type = type; self->category = category; self->name = name; self->description = description; self->values = values; return self; } const char * sysprof_document_counter_get_category (SysprofDocumentCounter *self) { g_return_val_if_fail (SYSPROF_IS_DOCUMENT_COUNTER (self), NULL); return self->category; } const char * sysprof_document_counter_get_description (SysprofDocumentCounter *self) { g_return_val_if_fail (SYSPROF_IS_DOCUMENT_COUNTER (self), NULL); return self->description; } const char * sysprof_document_counter_get_name (SysprofDocumentCounter *self) { g_return_val_if_fail (SYSPROF_IS_DOCUMENT_COUNTER (self), NULL); return self->name; } guint sysprof_document_counter_get_id (SysprofDocumentCounter *self) { g_return_val_if_fail (SYSPROF_IS_DOCUMENT_COUNTER (self), 0); return self->id; } GType sysprof_document_counter_get_value_type (SysprofDocumentCounter *self) { g_return_val_if_fail (SYSPROF_IS_DOCUMENT_COUNTER (self), G_TYPE_INVALID); if (self->type == SYSPROF_CAPTURE_COUNTER_INT64) return G_TYPE_INT64; if (self->type == SYSPROF_CAPTURE_COUNTER_DOUBLE) return G_TYPE_DOUBLE; return G_TYPE_INVALID; }