Debian Codegraph @

lib/packagekit-glib2/pk-require-restart.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2009 Richard Hughes <[email protected]>
4 *
5 * Licensed under the GNU Lesser General Public License Version 2.1
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * SECTION:pk-require-restart
24 * @short_description: RequireRestart object
25 *
26 * This GObject represents a requirement of restart from a transaction.
27 * These objects represent single items of data from the transaction, and are
28 * often present in lists (#PkResults) or just refcounted in client programs.
29 */
30
31 #include "config.h"
32
33 #include <glib-object.h>
34
35 #include <packagekit-glib2/pk-require-restart.h>
36 #include <packagekit-glib2/pk-enum.h>
37 #include <packagekit-glib2/pk-enum-types.h>
38
39 static void pk_require_restart_finalize (GObject *object);
40
41 /**
42 * PkRequireRestartPrivate:
43 *
44 * Private #PkRequireRestart data
45 **/
46 struct _PkRequireRestartPrivate
47 {
48 PkRestartEnum restart;
49 gchar *package_id;
50 };
51
52 enum {
53 PROP_0,
54 PROP_RESTART,
55 PROP_PACKAGE_ID,
56 PROP_LAST
57 };
58
59 G_DEFINE_TYPE_WITH_PRIVATE (PkRequireRestart, pk_require_restart, PK_TYPE_SOURCE)
60 #define GET_PRIVATE(o) (pk_require_restart_get_instance_private (o))
61
62 /*
63 * pk_require_restart_get_property:
64 **/
65 static void
66 pk_require_restart_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
67 {
68 PkRequireRestart *require_restart = PK_REQUIRE_RESTART (object);
69 PkRequireRestartPrivate *priv = GET_PRIVATE(require_restart);
70
71 switch (prop_id) {
72 case PROP_RESTART:
73 g_value_set_enum (value, priv->restart);
74 break;
75 case PROP_PACKAGE_ID:
76 g_value_set_string (value, priv->package_id);
77 break;
78 default:
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
80 break;
81 }
82 }
83
84 /*
85 * pk_require_restart_set_property:
86 **/
87 static void
88 pk_require_restart_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
89 {
90 PkRequireRestart *require_restart = PK_REQUIRE_RESTART (object);
91 PkRequireRestartPrivate *priv = GET_PRIVATE(require_restart);
92
93 switch (prop_id) {
94 case PROP_RESTART:
95 priv->restart = g_value_get_enum (value);
96 break;
97 case PROP_PACKAGE_ID:
98 g_free (priv->package_id);
99 priv->package_id = g_value_dup_string (value);
100 break;
101 default:
102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
103 break;
104 }
105 }
106
107 /*
108 * pk_require_restart_class_init:
109 **/
110 static void
111 pk_require_restart_class_init (PkRequireRestartClass *klass)
112 {
113 GParamSpec *pspec;
114 GObjectClass *object_class = G_OBJECT_CLASS (klass);
115 object_class->finalize = pk_require_restart_finalize;
116 object_class->get_property = pk_require_restart_get_property;
117 object_class->set_property = pk_require_restart_set_property;
118
119 /**
120 * PkRequireRestart:restart:
121 *
122 * Since: 0.5.4
123 */
124 pspec = g_param_spec_enum ("restart", NULL, NULL,
125 PK_TYPE_RESTART_ENUM, PK_RESTART_ENUM_UNKNOWN,
126 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
127 g_object_class_install_property (object_class, PROP_RESTART, pspec);
128
129 /**
130 * PkRequireRestart:package-id:
131 *
132 * Since: 0.5.4
133 */
134 pspec = g_param_spec_string ("package-id", NULL, NULL,
135 NULL,
136 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
137 g_object_class_install_property (object_class, PROP_PACKAGE_ID, pspec);
138 }
139
140 /*
141 * pk_require_restart_init:
142 **/
143 static void
144 pk_require_restart_init (PkRequireRestart *require_restart)
145 {
146 require_restart->priv = GET_PRIVATE(require_restart);
147 }
148
149 /*
150 * pk_require_restart_finalize:
151 **/
152 static void
153 pk_require_restart_finalize (GObject *object)
154 {
155 PkRequireRestart *require_restart = PK_REQUIRE_RESTART (object);
156 PkRequireRestartPrivate *priv = GET_PRIVATE(require_restart);
157
158 g_clear_pointer (&priv->package_id, g_free);
159
160 G_OBJECT_CLASS (pk_require_restart_parent_class)->finalize (object);
161 }
162
163 /**
164 * pk_require_restart_new:
165 *
166 * Return value: a new #PkRequireRestart object.
167 *
168 * Since: 0.5.4
169 **/
170 PkRequireRestart *
171 pk_require_restart_new (void)
172 {
173 PkRequireRestart *require_restart;
174 require_restart = g_object_new (PK_TYPE_REQUIRE_RESTART, NULL);
175 return PK_REQUIRE_RESTART (require_restart);
176 }