Debian Codegraph @

src/libsysprof/sysprof-document-log.c

raw
1 /* sysprof-document-log.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 <glib/gi18n.h>
24
25 #include "sysprof-document-frame-private.h"
26 #include "sysprof-document-log.h"
27
28 struct _SysprofDocumentLog
29 {
30 SysprofDocumentFrame parent_instance;
31 };
32
33 struct _SysprofDocumentLogClass
34 {
35 SysprofDocumentFrameClass parent_class;
36 };
37
38 enum {
39 PROP_0,
40 PROP_DOMAIN,
41 PROP_MESSAGE,
42 PROP_SEVERITY,
43 N_PROPS
44 };
45
46 G_DEFINE_FINAL_TYPE (SysprofDocumentLog, sysprof_document_log, SYSPROF_TYPE_DOCUMENT_FRAME)
47
48 static GParamSpec *properties [N_PROPS];
49
50 static void
51 sysprof_document_log_get_property (GObject *object,
52 guint prop_id,
53 GValue *value,
54 GParamSpec *pspec)
55 {
56 SysprofDocumentLog *self = SYSPROF_DOCUMENT_LOG (object);
57
58 switch (prop_id)
59 {
60 case PROP_SEVERITY:
61 g_value_set_uint (value, sysprof_document_log_get_severity (self));
62 break;
63
64 case PROP_MESSAGE:
65 g_value_set_string (value, sysprof_document_log_get_message (self));
66 break;
67
68 case PROP_DOMAIN:
69 g_value_set_string (value, sysprof_document_log_get_domain (self));
70 break;
71
72 default:
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
74 }
75 }
76
77 static void
78 sysprof_document_log_class_init (SysprofDocumentLogClass *klass)
79 {
80 GObjectClass *object_class = G_OBJECT_CLASS (klass);
81 SysprofDocumentFrameClass *document_frame_class = SYSPROF_DOCUMENT_FRAME_CLASS (klass);
82
83 object_class->get_property = sysprof_document_log_get_property;
84
85 document_frame_class->type_name = N_("Log");
86
87 properties [PROP_SEVERITY] =
88 g_param_spec_uint ("severity", NULL, NULL,
89 0, G_MAXUINT16, 0,
90 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
91
92 properties [PROP_DOMAIN] =
93 g_param_spec_string ("domain", NULL, NULL,
94 NULL,
95 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
96
97 properties [PROP_MESSAGE] =
98 g_param_spec_string ("message", NULL, NULL,
99 NULL,
100 (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
101
102 g_object_class_install_properties (object_class, N_PROPS, properties);
103 }
104
105 static void
106 sysprof_document_log_init (SysprofDocumentLog *self)
107 {
108 }
109
110 GLogLevelFlags
111 sysprof_document_log_get_severity (SysprofDocumentLog *self)
112 {
113 const SysprofCaptureLog *log;
114
115 g_return_val_if_fail (SYSPROF_IS_DOCUMENT_LOG (self), 0);
116
117 log = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureLog);
118
119 return SYSPROF_DOCUMENT_FRAME_UINT16 (self, log->severity);
120 }
121
122 const char *
123 sysprof_document_log_get_message (SysprofDocumentLog *self)
124 {
125 const SysprofCaptureLog *log;
126
127 g_return_val_if_fail (SYSPROF_IS_DOCUMENT_LOG (self), 0);
128
129 log = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureLog);
130
131 return SYSPROF_DOCUMENT_FRAME_CSTRING (self, log->message);
132 }
133
134 const char *
135 sysprof_document_log_get_domain (SysprofDocumentLog *self)
136 {
137 const SysprofCaptureLog *log;
138
139 g_return_val_if_fail (SYSPROF_IS_DOCUMENT_LOG (self), 0);
140
141 log = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureLog);
142
143 return SYSPROF_DOCUMENT_FRAME_CSTRING (self, log->domain);
144 }