2
Copyright 2011 Canonical Ltd.
5
Conor Curran <conor.curran@canonical.com>
7
This program is free software: you can redistribute it and/or modify it
8
under the terms of the GNU General Public License version 3, as published
9
by the Free Software Foundation.
11
This program is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranties of
13
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
PURPOSE. See the GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License along
17
with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "apt-transaction.h"
23
#include "dbus-shared-names.h"
25
static void apt_transaction_investigate (AptTransaction* self);
26
static void apt_transaction_simulate_transaction_cb (GObject * obj,
29
static void apt_transaction_receive_signal (GDBusProxy * proxy,
32
GVariant * parameters,
34
static void apt_transaction_finish_proxy_setup (GObject *source_object,
38
struct _AptTransaction
40
GObject parent_instance;
42
GCancellable * proxy_cancel;
52
static guint signals[LAST_SIGNAL] = { 0 };
54
G_DEFINE_TYPE (AptTransaction, apt_transaction, G_TYPE_OBJECT);
57
apt_transaction_init (AptTransaction *self)
61
self->proxy_cancel = g_cancellable_new();
65
apt_transaction_finalize (GObject *object)
67
AptTransaction* self = APT_TRANSACTION(object);
68
g_signal_handlers_disconnect_by_func (G_OBJECT (self->proxy),
69
G_CALLBACK (apt_transaction_receive_signal),
71
if (self->proxy != NULL){
72
g_object_unref (self->proxy);
76
G_OBJECT_CLASS (apt_transaction_parent_class)->finalize (object);
80
apt_transaction_class_init (AptTransactionClass *klass)
82
GObjectClass* object_class = G_OBJECT_CLASS (klass);
83
object_class->finalize = apt_transaction_finalize;
85
signals[UPDATE] = g_signal_new("state-update",
86
G_TYPE_FROM_CLASS (klass),
90
g_cclosure_marshal_VOID__INT,
91
G_TYPE_NONE, 1, G_TYPE_INT);
94
// TODO: you don't need this additional helper
95
// Just GObject properties properly
97
apt_transaction_investigate (AptTransaction* self)
99
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
100
G_DBUS_PROXY_FLAGS_NONE,
104
"org.debian.apt.transaction",
106
apt_transaction_finish_proxy_setup,
111
apt_transaction_finish_proxy_setup (GObject *source_object,
115
g_return_if_fail (APT_IS_TRANSACTION (user_data));
116
AptTransaction* self = APT_TRANSACTION(user_data);
117
GError * error = NULL;
119
GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
121
if (self->proxy_cancel != NULL) {
122
g_object_unref(self->proxy_cancel);
123
self->proxy_cancel = NULL;
127
g_warning("Could not grab DBus proxy for %s: %s",
128
"org.debian.apt", error->message);
135
g_signal_connect (G_OBJECT(self->proxy),
137
G_CALLBACK (apt_transaction_receive_signal),
140
if (self->type == SIMULATION){
141
g_dbus_proxy_call (self->proxy,
144
G_DBUS_CALL_FLAGS_NONE,
147
apt_transaction_simulate_transaction_cb,
153
apt_transaction_receive_signal (GDBusProxy * proxy,
156
GVariant * parameters,
159
g_return_if_fail (APT_IS_TRANSACTION (user_data));
160
AptTransaction* self = APT_TRANSACTION(user_data);
161
AptState current_state = DONT_KNOW;
163
if (g_strcmp0(signal_name, "PropertyChanged") == 0)
165
gchar* prop_name= NULL;
166
GVariant* value = NULL;
167
g_variant_get (parameters, "(sv)", &prop_name, &value);
168
g_debug ("transaction prop update - prop = %s", prop_name);
170
if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) == TRUE){
172
g_variant_get (value, "s", &key);
173
g_debug ("transaction prop update - value = %s", key);
176
if (g_strcmp0 (prop_name, "Dependencies") == 0){
178
gchar** install = NULL;
179
gchar** reinstall = NULL;
180
gchar** remove = NULL;
181
gchar** purge = NULL;
182
gchar** upgrade = NULL;
183
gchar** downgrade = NULL;
185
g_variant_get (value, "(asasasasasasas)", &install,
186
&reinstall, &remove, &purge, &upgrade, &downgrade,
189
g_debug ("upgrade package length %i", g_strv_length(upgrade));
190
g_debug ("install package length %i", g_strv_length(install));
191
g_debug ("reinstall package length %i", g_strv_length(reinstall));
192
g_debug ("remove package length %i", g_strv_length(remove));
193
g_debug ("purge package length %i", g_strv_length(purge));
195
gboolean upgrade_needed = (g_strv_length(upgrade) > 1) ||
196
(g_strv_length(install) > 1) ||
197
(g_strv_length(reinstall) > 1) ||
198
(g_strv_length(remove) > 1) ||
199
(g_strv_length(purge) > 1);
200
if (upgrade_needed == TRUE){
201
current_state = UPDATES_AVAILABLE;
204
current_state = UP_TO_DATE;
207
if (self->type == REAL)
209
GVariant* role = g_dbus_proxy_get_cached_property (self->proxy,
211
if (g_variant_is_of_type (role, G_VARIANT_TYPE_STRING) == TRUE){
212
gchar* current_role = NULL;
213
g_variant_get (role, "s", ¤t_role);
214
//g_debug ("Current transaction role = %s", current_role);
215
if (g_strcmp0 (current_role, "role-commit-packages") == 0 ||
216
g_strcmp0 (current_role, "role-upgrade-system") == 0){
217
g_debug ("UPGRADE IN PROGRESS");
218
current_state = UPGRADE_IN_PROGRESS;
223
else if (g_strcmp0(signal_name, "Finished") == 0)
225
g_debug ("TRANSACTION Finished");
226
current_state = FINISHED;
228
// Finally send out the state update
229
if (current_state != DONT_KNOW){
238
apt_transaction_simulate_transaction_cb (GObject * obj,
242
GError * error = NULL;
244
g_warning ("unable to complete the simulate call");
245
g_error_free (error);
250
apt_transaction_get_transaction_type (AptTransaction* self)
255
AptTransaction* apt_transaction_new (gchar* transaction_id, TransactionType t)
257
AptTransaction* tr = g_object_new (APT_TYPE_TRANSACTION, NULL);
258
tr->id = transaction_id;
260
g_debug ("Apt transaction new id = %s", tr->id);
261
apt_transaction_investigate (tr);