1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
|
/*
* Copyright (C) 2017 Canonical Ltd.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 or version 3 of the License.
* See http://www.gnu.org/copyleft/lgpl.html the full text of the license.
*/
#include <string.h>
#include "snapd-change.h"
/**
* SECTION: snapd-change
* @short_description: Change progress
* @include: snapd-glib/snapd-glib.h
*
* A #SnapdChange contains information on how a request is progressing. Progress
* information is returned in a #SnapdProgressCallback.
*/
/**
* SnapdChange:
*
* #SnapdChange contains information on a current Snap transaction.
*
* Since: 1.5
*/
struct _SnapdChange {
GObject parent_instance;
gchar *id;
gchar *kind;
gchar *summary;
gchar *status;
GPtrArray *tasks;
gboolean ready;
GDateTime *spawn_time;
GDateTime *ready_time;
gchar *error;
SnapdChangeData *data;
};
enum {
PROP_ID = 1,
PROP_KIND,
PROP_SUMMARY,
PROP_STATUS,
PROP_TASKS,
PROP_READY,
PROP_SPAWN_TIME,
PROP_READY_TIME,
PROP_ERROR,
PROP_DATA,
PROP_LAST
};
G_DEFINE_TYPE(SnapdChange, snapd_change, G_TYPE_OBJECT)
/**
* snapd_change_get_id:
* @change: a #SnapdChange.
*
* Get the unique ID for this change.
*
* Returns: an ID.
*
* Since: 1.5
*/
const gchar *snapd_change_get_id(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->id;
}
/**
* snapd_change_get_kind:
* @change: a #SnapdChange.
*
* Gets the kind of change this is.
*
* Returns: the kind of change.
*
* Since: 1.5
*/
const gchar *snapd_change_get_kind(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->kind;
}
/**
* snapd_change_get_summary:
* @change: a #SnapdChange.
*
* Get a human readable description of the change.
*
* Returns: a string describing the change.
*
* Since: 1.5
*/
const gchar *snapd_change_get_summary(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->summary;
}
/**
* snapd_change_get_status:
* @change: a #SnapdChange.
*
* Get the status of the change.
*
* Returns: a status string.
*
* Since: 1.5
*/
const gchar *snapd_change_get_status(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->status;
}
/**
* snapd_change_get_tasks:
* @change: a #SnapdChange.
*
* Get the tasks that are in this change.
*
* Returns: (transfer none) (element-type SnapdTask): an array of #SnapdTask.
*
* Since: 1.5
*/
GPtrArray *snapd_change_get_tasks(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->tasks;
}
/**
* snapd_change_get_data:
* @change: a #SnapdChange.
*
* Get the data field for this change.
*
* Returns: (transfer none): a #SnapdChangeData object with all the data, or
* NULL if the field isn't defined
*
* Since: 1.65
*/
SnapdChangeData *snapd_change_get_data(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->data;
}
/**
* snapd_change_get_ready:
* @change: a #SnapdChange.
*
* Get if this change is completed.
*
* Returns: %TRUE if this change is complete.
*
* Since: 1.5
*/
gboolean snapd_change_get_ready(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), FALSE);
return self->ready;
}
/**
* snapd_change_get_spawn_time:
* @change: a #SnapdChange.
*
* Get the time this change started.
*
* Returns: (transfer none): a #GDateTime.
*
* Since: 1.5
*/
GDateTime *snapd_change_get_spawn_time(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->spawn_time;
}
/**
* snapd_change_get_ready_time:
* @change: a #SnapdChange.
*
* Get the time this task completed or %NULL if not yet completed.
*
* Returns: (transfer none) (allow-none): a #GDateTime or %NULL.
*
* Since: 1.5
*/
GDateTime *snapd_change_get_ready_time(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->ready_time;
}
/**
* snapd_change_get_error:
* @change: a #SnapdChange.
*
* Gets the error string associated with this change.
*
* Returns: (allow-none): an error string or %NULL.
*
* Since: 1.30
*/
const gchar *snapd_change_get_error(SnapdChange *self) {
g_return_val_if_fail(SNAPD_IS_CHANGE(self), NULL);
return self->error;
}
static void snapd_change_set_property(GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec) {
SnapdChange *self = SNAPD_CHANGE(object);
switch (prop_id) {
case PROP_ID:
g_free(self->id);
self->id = g_strdup(g_value_get_string(value));
break;
case PROP_KIND:
g_free(self->kind);
self->kind = g_strdup(g_value_get_string(value));
break;
case PROP_SUMMARY:
g_free(self->summary);
self->summary = g_strdup(g_value_get_string(value));
break;
case PROP_STATUS:
g_free(self->status);
self->status = g_strdup(g_value_get_string(value));
break;
case PROP_TASKS:
g_clear_pointer(&self->tasks, g_ptr_array_unref);
if (g_value_get_boxed(value) != NULL)
self->tasks = g_ptr_array_ref(g_value_get_boxed(value));
break;
case PROP_DATA:
g_clear_pointer(&self->data, g_object_unref);
if (g_value_get_object(value) != NULL)
self->data = g_object_ref(g_value_get_object(value));
break;
case PROP_READY:
self->ready = g_value_get_boolean(value);
break;
case PROP_SPAWN_TIME:
g_clear_pointer(&self->spawn_time, g_date_time_unref);
if (g_value_get_boxed(value) != NULL)
self->spawn_time = g_date_time_ref(g_value_get_boxed(value));
break;
case PROP_READY_TIME:
g_clear_pointer(&self->ready_time, g_date_time_unref);
if (g_value_get_boxed(value) != NULL)
self->ready_time = g_date_time_ref(g_value_get_boxed(value));
break;
case PROP_ERROR:
g_free(self->error);
self->error = g_strdup(g_value_get_string(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void snapd_change_get_property(GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec) {
SnapdChange *self = SNAPD_CHANGE(object);
switch (prop_id) {
case PROP_ID:
g_value_set_string(value, self->id);
break;
case PROP_KIND:
g_value_set_string(value, self->kind);
break;
case PROP_SUMMARY:
g_value_set_string(value, self->summary);
break;
case PROP_STATUS:
g_value_set_string(value, self->status);
break;
case PROP_TASKS:
g_value_set_boxed(value, self->tasks);
break;
case PROP_DATA:
g_value_set_object(value, self->data);
break;
case PROP_READY:
g_value_set_boolean(value, self->ready);
break;
case PROP_SPAWN_TIME:
g_value_set_boxed(value, self->spawn_time);
break;
case PROP_READY_TIME:
g_value_set_boxed(value, self->ready_time);
break;
case PROP_ERROR:
g_value_set_string(value, self->error);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void snapd_change_finalize(GObject *object) {
SnapdChange *self = SNAPD_CHANGE(object);
g_clear_pointer(&self->id, g_free);
g_clear_pointer(&self->kind, g_free);
g_clear_pointer(&self->summary, g_free);
g_clear_pointer(&self->status, g_free);
g_clear_pointer(&self->tasks, g_ptr_array_unref);
g_clear_pointer(&self->data, g_object_unref);
g_clear_pointer(&self->spawn_time, g_date_time_unref);
g_clear_pointer(&self->ready_time, g_date_time_unref);
g_clear_pointer(&self->error, g_free);
G_OBJECT_CLASS(snapd_change_parent_class)->finalize(object);
}
static void snapd_change_class_init(SnapdChangeClass *klass) {
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->set_property = snapd_change_set_property;
gobject_class->get_property = snapd_change_get_property;
gobject_class->finalize = snapd_change_finalize;
g_object_class_install_property(
gobject_class, PROP_ID,
g_param_spec_string("id", "id", "ID of change", NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_KIND,
g_param_spec_string("kind", "kind", "Kind of change", NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_SUMMARY,
g_param_spec_string("summary", "summary", "Summary of change", NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_STATUS,
g_param_spec_string("status", "status", "Status of change", NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_TASKS,
g_param_spec_boxed(
"tasks", "tasks", "Tasks in this change", G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_READY,
g_param_spec_boolean("ready", "ready", "TRUE when change complete", FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_SPAWN_TIME,
g_param_spec_boxed("spawn-time", "spawn-time", "Time this change started",
G_TYPE_DATE_TIME,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_READY_TIME,
g_param_spec_boxed("ready-time", "ready-time",
"Time this change completed", G_TYPE_DATE_TIME,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_ERROR,
g_param_spec_string(
"error", "error", "Error associated with change", NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
g_object_class_install_property(
gobject_class, PROP_DATA,
g_param_spec_object("data", "data", "Data field", SNAPD_TYPE_CHANGE_DATA,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
}
static void snapd_change_init(SnapdChange *self) {}
|