Debian Codegraph @

src/libsysprof/sysprof-diagnostic.c

raw
1 /* sysprof-diagnostic.c
2 *
3 * Copyright 2023 Christian Hergert <[email protected]>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include "config.h"
22
23 #include "sysprof-diagnostic-private.h"
24
25 struct _SysprofDiagnostic
26 {
27 GObject parent_instance;
28 GRefString *domain;
29 char *message;
30 guint fatal : 1;
31 };
32
33 enum {
34 PROP_0,
35 PROP_DOMAIN,
36 PROP_MESSAGE,
37 PROP_FATAL,
38 N_PROPS
39 };
40
41 G_DEFINE_FINAL_TYPE (SysprofDiagnostic, sysprof_diagnostic, G_TYPE_OBJECT)
42
43 static GParamSpec *properties [N_PROPS];
44
45 static void
46 sysprof_diagnostic_finalize (GObject *object)
47 {
48 SysprofDiagnostic *self = (SysprofDiagnostic *)object;
49
50 g_clear_pointer (&self->domain, g_free);
51 g_clear_pointer (&self->message, g_free);
52
53 G_OBJECT_CLASS (sysprof_diagnostic_parent_class)->finalize (object);
54 }
55
56 static void
57 sysprof_diagnostic_get_property (GObject *object,
58 guint prop_id,
59 GValue *value,
60 GParamSpec *pspec)
61 {
62 SysprofDiagnostic *self = SYSPROF_DIAGNOSTIC (object);
63
64 switch (prop_id)
65 {
66 case PROP_DOMAIN:
67 g_value_set_string (value, self->domain);
68 break;
69
70 case PROP_MESSAGE:
71 g_value_set_string (value, self->message);
72 break;
73
74 case PROP_FATAL:
75 g_value_set_boolean (value, self->fatal);
76 break;
77
78 default:
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
80 }
81 }
82
83 static void
84 sysprof_diagnostic_class_init (SysprofDiagnosticClass *klass)
85 {
86 GObjectClass *object_class = G_OBJECT_CLASS (klass);
87
88 object_class->finalize = sysprof_diagnostic_finalize;
89 object_class->get_property = sysprof_diagnostic_get_property;
90
91 properties [PROP_DOMAIN] =
92 g_param_spec_string ("domain", NULL, NULL,
93 NULL,
94 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
95
96 properties [PROP_MESSAGE] =
97 g_param_spec_string ("message", NULL, NULL,
98 NULL,
99 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
100
101 properties [PROP_FATAL] =
102 g_param_spec_boolean ("fatal", NULL, NULL,
103 FALSE,
104 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
105
106 g_object_class_install_properties (object_class, N_PROPS, properties);
107 }
108
109 static void
110 sysprof_diagnostic_init (SysprofDiagnostic *self)
111 {
112 }
113
114 const char *
115 sysprof_diagnostic_get_domain (SysprofDiagnostic *self)
116 {
117 g_return_val_if_fail (SYSPROF_IS_DIAGNOSTIC (self), NULL);
118
119 return self->domain;
120 }
121
122 const char *
123 sysprof_diagnostic_get_message (SysprofDiagnostic *self)
124 {
125 g_return_val_if_fail (SYSPROF_IS_DIAGNOSTIC (self), NULL);
126
127 return self->message;
128 }
129
130 gboolean
131 sysprof_diagnostic_get_fatal (SysprofDiagnostic *self)
132 {
133 g_return_val_if_fail (SYSPROF_IS_DIAGNOSTIC (self), FALSE);
134
135 return self->fatal;
136 }
137
138 SysprofDiagnostic *
139 _sysprof_diagnostic_new (char *domain,
140 char *message,
141 gboolean fatal)
142 {
143 SysprofDiagnostic *self;
144
145 self = g_object_new (SYSPROF_TYPE_DIAGNOSTIC, NULL);
146 self->message = message;
147 self->domain = domain;
148 self->fatal = !!fatal;
149
150 return self;
151 }