Debian Codegraph @

src/goabackend/goaserviceconfig.c

raw symbols SCIP
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /*
3 * Copyright © 2024 GNOME Foundation Inc.
4 * Contributor: Andy Holmes <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "config.h"
21
22 #include <glib-object.h>
23
24 #include "goaserviceconfig.h"
25
26 typedef struct
27 {
28 GObject parent_instance;
29
30 char *service;
31 } GoaServiceConfigPrivate;
32
33 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GoaServiceConfig, goa_service_config, G_TYPE_OBJECT)
34
35 typedef enum
36 {
37 PROP_SERVICE = 1,
38 } GoaServiceConfigProperty;
39
40 static GParamSpec *properties[PROP_SERVICE + 1] = { NULL, };
41
42 /* ---------------------------------------------------------------------------------------------------- */
43
44 static void
45 goa_service_config_finalize (GObject *object)
46 {
47 GoaServiceConfig *self = GOA_SERVICE_CONFIG (object);
48 GoaServiceConfigPrivate *priv = goa_service_config_get_instance_private (self);
49
50 g_clear_pointer (&priv->service, g_free);
51
52 G_OBJECT_CLASS (goa_service_config_parent_class)->finalize (object);
53 }
54
55 static void
56 goa_service_config_get_property (GObject *object,
57 guint prop_id,
58 GValue *value,
59 GParamSpec *pspec)
60 {
61 GoaServiceConfig *self = GOA_SERVICE_CONFIG (object);
62 GoaServiceConfigPrivate *priv = goa_service_config_get_instance_private (self);
63
64 switch ((GoaServiceConfigProperty) prop_id)
65 {
66 case PROP_SERVICE:
67 g_value_set_string (value, priv->service);
68 break;
69
70 default:
71 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
72 break;
73 }
74 }
75
76 static void
77 goa_service_config_set_property (GObject *object,
78 guint prop_id,
79 const GValue *value,
80 GParamSpec *pspec)
81 {
82 GoaServiceConfig *self = GOA_SERVICE_CONFIG (object);
83 GoaServiceConfigPrivate *priv = goa_service_config_get_instance_private (self);
84
85 switch ((GoaServiceConfigProperty) prop_id)
86 {
87 case PROP_SERVICE:
88 g_assert (priv->service == NULL);
89 priv->service = g_value_dup_string (value);
90 break;
91
92 default:
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
94 break;
95 }
96 }
97
98 /* ---------------------------------------------------------------------------------------------------- */
99
100 static void
101 goa_service_config_init (GoaServiceConfig *self)
102 {
103 }
104
105 static void
106 goa_service_config_class_init (GoaServiceConfigClass *klass)
107 {
108 GObjectClass *object_class = G_OBJECT_CLASS (klass);
109
110 object_class->finalize = goa_service_config_finalize;
111 object_class->get_property = goa_service_config_get_property;
112 object_class->set_property = goa_service_config_set_property;
113
114 /**
115 * GoaServiceProvider:service: (getter get_service)
116 *
117 * The service type name, such as `imap` or `caldav`.
118 */
119 properties[PROP_SERVICE] =
120 g_param_spec_string ("service", NULL, NULL,
121 "unknown",
122 (G_PARAM_READWRITE |
123 G_PARAM_CONSTRUCT_ONLY |
124 G_PARAM_STATIC_STRINGS |
125 G_PARAM_EXPLICIT_NOTIFY));
126
127 g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
128 }
129
130 /* ---------------------------------------------------------------------------------------------------- */
131
132 /**
133 * goa_service_config_get_service: (get-property service)
134 * @config: a `GoaServiceConfig`
135 *
136 * Get the service type of @config, or "unknown" if not set.
137 *
138 * Returns: (transfer none) (not nullable): a service type
139 */
140 const char *
141 goa_service_config_get_service (GoaServiceConfig *config)
142 {
143 GoaServiceConfigPrivate *priv = goa_service_config_get_instance_private (config);
144
145 g_return_val_if_fail (GOA_IS_SERVICE_CONFIG (config), "unknown");
146
147 return priv->service;
148 }
149