/** * hif_state_finalize: **/ static void hif_state_finalize (GObject *object) { HifState *state; g_return_if_fail (object != NULL); g_return_if_fail (HIF_IS_STATE (object)); state = HIF_STATE (object); /* no more locks */ hif_state_release_locks (state); hif_state_reset (state); g_free (state->priv->id); g_free (state->priv->action_hint); g_free (state->priv->step_data); g_free (state->priv->step_profile); if (state->priv->cancellable != NULL) g_object_unref (state->priv->cancellable); g_timer_destroy (state->priv->timer); g_free (state->priv->speed_data); g_ptr_array_unref (state->priv->lock_ids); g_object_unref (state->priv->lock); G_OBJECT_CLASS (hif_state_parent_class)->finalize (object); }
/** * hif_state_set_percentage: * @state: a #HifState instance. * @percentage: Percentage value between 0% and 100% * * Set a percentage manually. * NOTE: this must be above what was previously set, or it will be rejected. * * Returns: %TRUE if the signal was propagated, %FALSE otherwise * * Since: 0.1.0 **/ gboolean hif_state_set_percentage(HifState *state, guint percentage) { HifStatePrivate *priv = GET_PRIVATE(state); /* do we care */ if (!priv->report_progress) return TRUE; /* is it the same */ if (percentage == priv->last_percentage) return FALSE; /* is it invalid */ if (percentage > 100) { hif_state_print_parent_chain(state, 0); g_warning("percentage %i%% is invalid on %p!", percentage, state); return FALSE; } /* is it less */ if (percentage < priv->last_percentage) { if (priv->enable_profile) { hif_state_print_parent_chain(state, 0); g_warning("percentage should not go down from %i to %i on %p!", priv->last_percentage, percentage, state); } return FALSE; } /* we're done, so we're not preventing cancellation anymore */ if (percentage == 100 && !priv->allow_cancel) { g_debug("done, so allow cancel 1 for %p", state); hif_state_set_allow_cancel(state, TRUE); } /* automatically cancel any action */ if (percentage == 100 && priv->action != HIF_STATE_ACTION_UNKNOWN) hif_state_action_stop(state); /* speed no longer valid */ if (percentage == 100) hif_state_set_speed_internal(state, 0); /* release locks? */ if (percentage == 100) { if (!hif_state_release_locks(state)) return FALSE; } /* save */ priv->last_percentage = percentage; /* emit */ g_signal_emit(state, signals [SIGNAL_PERCENTAGE_CHANGED], 0, percentage); /* success */ return TRUE; }
/** * hif_state_reset: * @state: a #HifState instance. * * Resets the #HifState object to unset * * Returns: %TRUE for success, %FALSE otherwise * * Since: 0.1.0 **/ gboolean hif_state_reset(HifState *state) { HifStatePrivate *priv = GET_PRIVATE(state); g_return_val_if_fail(HIF_IS_STATE(state), FALSE); /* do we care */ if (!priv->report_progress) return TRUE; /* reset values */ priv->steps = 0; priv->current = 0; priv->last_percentage = 0; /* only use the timer if profiling; it's expensive */ if (priv->enable_profile) g_timer_start(priv->timer); /* disconnect client */ if (priv->percentage_child_id != 0) { g_signal_handler_disconnect(priv->child, priv->percentage_child_id); priv->percentage_child_id = 0; } if (priv->allow_cancel_child_id != 0) { g_signal_handler_disconnect(priv->child, priv->allow_cancel_child_id); priv->allow_cancel_child_id = 0; } if (priv->action_child_id != 0) { g_signal_handler_disconnect(priv->child, priv->action_child_id); priv->action_child_id = 0; } if (priv->package_progress_child_id != 0) { g_signal_handler_disconnect(priv->child, priv->package_progress_child_id); priv->package_progress_child_id = 0; } if (priv->notify_speed_child_id != 0) { g_signal_handler_disconnect(priv->child, priv->notify_speed_child_id); priv->notify_speed_child_id = 0; } /* unref child */ if (priv->child != NULL) { g_object_unref(priv->child); priv->child = NULL; } /* no more locks */ hif_state_release_locks(state); /* no more step data */ g_free(priv->step_data); g_free(priv->step_profile); priv->step_data = NULL; priv->step_profile = NULL; return TRUE; }
/** * hif_state_release_locks: * @state: a #HifState instance. * * Releases all locks used in the state. * * Returns: %TRUE for success, %FALSE otherwise * * Since: 0.1.0 **/ gboolean hif_state_release_locks(HifState *state) { HifStatePrivate *priv = GET_PRIVATE(state); guint i; guint lock_id; /* release children first */ if (priv->child != NULL) hif_state_release_locks(priv->child); /* release each one */ for (i = 0; i < priv->lock_ids->len; i++) { lock_id = GPOINTER_TO_UINT(g_ptr_array_index(priv->lock_ids, i)); g_debug("releasing lock %i", lock_id); if (!hif_lock_release(priv->lock, lock_id, NULL)) return FALSE; } g_ptr_array_set_size(priv->lock_ids, 0); return TRUE; }
/** * hif_state_set_percentage: **/ gboolean hif_state_set_percentage (HifState *state, guint percentage) { gboolean ret = FALSE; /* do we care */ if (!state->priv->report_progress) { ret = TRUE; goto out; } /* is it the same */ if (percentage == state->priv->last_percentage) goto out; /* is it invalid */ if (percentage > 100) { hif_state_print_parent_chain (state, 0); g_warning ("percentage %i%% is invalid on %p!", percentage, state); goto out; } /* is it less */ if (percentage < state->priv->last_percentage) { if (state->priv->enable_profile) { hif_state_print_parent_chain (state, 0); g_warning ("percentage should not go down from %i to %i on %p!", state->priv->last_percentage, percentage, state); } goto out; } /* we're done, so we're not preventing cancellation anymore */ if (percentage == 100 && !state->priv->allow_cancel) { g_debug ("done, so allow cancel 1 for %p", state); hif_state_set_allow_cancel (state, TRUE); } /* automatically cancel any action */ if (percentage == 100 && state->priv->action != PK_STATUS_ENUM_UNKNOWN) { g_debug ("done, so cancelling action %s", pk_status_enum_to_string (state->priv->action)); hif_state_action_stop (state); } /* speed no longer valid */ if (percentage == 100) hif_state_set_speed_internal (state, 0); /* release locks? */ if (percentage == 100) { ret = hif_state_release_locks (state); if (!ret) goto out; } /* save */ state->priv->last_percentage = percentage; /* emit */ g_signal_emit (state, signals [SIGNAL_PERCENTAGE_CHANGED], 0, percentage); /* success */ ret = TRUE; out: return ret; }