/** * hif_state_action_start: **/ gboolean hif_state_action_start (HifState *state, PkStatusEnum action, const gchar *action_hint) { g_return_val_if_fail (HIF_IS_STATE (state), FALSE); /* ignore this */ if (action == PK_STATUS_ENUM_UNKNOWN) { g_warning ("cannot set action PK_STATUS_ENUM_UNKNOWN"); return FALSE; } /* is different? */ if (state->priv->action == action && g_strcmp0 (action_hint, state->priv->action_hint) == 0) return FALSE; /* remember for stop */ state->priv->last_action = state->priv->action; /* save hint */ g_free (state->priv->action_hint); state->priv->action_hint = g_strdup (action_hint); /* save */ state->priv->action = action; /* just emit */ g_signal_emit (state, signals [SIGNAL_ACTION_CHANGED], 0, action, action_hint); return TRUE; }
/** * hif_state_set_cancellable: **/ void hif_state_set_cancellable (HifState *state, GCancellable *cancellable) { g_return_if_fail (HIF_IS_STATE (state)); g_return_if_fail (state->priv->cancellable == NULL); state->priv->cancellable = g_object_ref (cancellable); }
/** * hif_state_set_speed: **/ void hif_state_set_speed (HifState *state, guint64 speed) { guint i; guint64 sum = 0; guint sum_cnt = 0; g_return_if_fail (HIF_IS_STATE (state)); /* move the data down one entry */ for (i=HIF_STATE_SPEED_SMOOTHING_ITEMS-1; i > 0; i--) state->priv->speed_data[i] = state->priv->speed_data[i-1]; state->priv->speed_data[0] = speed; /* get the average */ for (i = 0; i < HIF_STATE_SPEED_SMOOTHING_ITEMS; i++) { if (state->priv->speed_data[i] > 0) { sum += state->priv->speed_data[i]; sum_cnt++; } } if (sum_cnt > 0) sum /= sum_cnt; hif_state_set_speed_internal (state, sum); }
/** * 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_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_set_package_progress: **/ void hif_state_set_package_progress (HifState *state, const gchar *package_id, PkStatusEnum action, guint percentage) { g_return_if_fail (HIF_IS_STATE (state)); g_return_if_fail (package_id != NULL); g_return_if_fail (action != PK_STATUS_ENUM_UNKNOWN); g_return_if_fail (percentage <= 100); /* just emit */ g_signal_emit (state, signals [SIGNAL_PACKAGE_PROGRESS_CHANGED], 0, package_id, action, percentage); }
/** * hif_state_set_allow_cancel: **/ void hif_state_set_allow_cancel (HifState *state, gboolean allow_cancel) { g_return_if_fail (HIF_IS_STATE (state)); state->priv->allow_cancel_changed_state = TRUE; /* quick optimisation that saves lots of signals */ if (state->priv->allow_cancel == allow_cancel) return; state->priv->allow_cancel = allow_cancel; /* just emit if both this and child is okay */ g_signal_emit (state, signals [SIGNAL_ALLOW_CANCEL_CHANGED], 0, state->priv->allow_cancel && state->priv->allow_cancel_child); }
/** * hif_state_action_stop: **/ gboolean hif_state_action_stop (HifState *state) { g_return_val_if_fail (HIF_IS_STATE (state), FALSE); /* nothing ever set */ if (state->priv->action == PK_STATUS_ENUM_UNKNOWN) { g_debug ("cannot unset action PK_STATUS_ENUM_UNKNOWN"); return FALSE; } /* pop and reset */ state->priv->action = state->priv->last_action; state->priv->last_action = PK_STATUS_ENUM_UNKNOWN; if (state->priv->action_hint != NULL) { g_free (state->priv->action_hint); state->priv->action_hint = NULL; } /* just emit */ g_signal_emit (state, signals [SIGNAL_ACTION_CHANGED], 0, state->priv->action, NULL); return TRUE; }
/** * hif_state_set_report_progress: **/ void hif_state_set_report_progress (HifState *state, gboolean report_progress) { g_return_if_fail (HIF_IS_STATE (state)); state->priv->report_progress = report_progress; }
/** * hif_state_get_child: **/ HifState * hif_state_get_child (HifState *state) { HifState *child = NULL; g_return_val_if_fail (HIF_IS_STATE (state), NULL); /* do we care */ if (!state->priv->report_progress) { child = state; goto out; } /* already set child */ if (state->priv->child != NULL) { g_signal_handler_disconnect (state->priv->child, state->priv->percentage_child_id); g_signal_handler_disconnect (state->priv->child, state->priv->allow_cancel_child_id); g_signal_handler_disconnect (state->priv->child, state->priv->action_child_id); g_signal_handler_disconnect (state->priv->child, state->priv->package_progress_child_id); g_signal_handler_disconnect (state->priv->child, state->priv->notify_speed_child_id); g_object_unref (state->priv->child); } /* connect up signals */ child = hif_state_new (); child->priv->parent = state; /* do not ref! */ state->priv->child = child; state->priv->percentage_child_id = g_signal_connect (child, "percentage-changed", G_CALLBACK (hif_state_child_percentage_changed_cb), state); state->priv->allow_cancel_child_id = g_signal_connect (child, "allow-cancel-changed", G_CALLBACK (hif_state_child_allow_cancel_changed_cb), state); state->priv->action_child_id = g_signal_connect (child, "action-changed", G_CALLBACK (hif_state_child_action_changed_cb), state); state->priv->package_progress_child_id = g_signal_connect (child, "package-progress-changed", G_CALLBACK (hif_state_child_package_progress_changed_cb), state); state->priv->notify_speed_child_id = g_signal_connect (child, "notify::speed", G_CALLBACK (hif_state_child_notify_speed_cb), state); /* reset child */ child->priv->current = 0; child->priv->last_percentage = 0; /* save so we can recover after child has done */ child->priv->action = state->priv->action; state->priv->child_action = state->priv->action; /* set cancellable, creating if required */ if (state->priv->cancellable == NULL) state->priv->cancellable = g_cancellable_new (); hif_state_set_cancellable (child, state->priv->cancellable); /* set the profile state */ hif_state_set_enable_profile (child, state->priv->enable_profile); out: return child; }
/** * hif_state_get_action: **/ PkStatusEnum hif_state_get_action (HifState *state) { g_return_val_if_fail (HIF_IS_STATE (state), PK_STATUS_ENUM_UNKNOWN); return state->priv->action; }
/** * hif_state_get_action_hint: **/ const gchar * hif_state_get_action_hint (HifState *state) { g_return_val_if_fail (HIF_IS_STATE (state), NULL); return state->priv->action_hint; }
/** * hif_state_get_speed: **/ guint64 hif_state_get_speed (HifState *state) { g_return_val_if_fail (HIF_IS_STATE (state), 0); return state->priv->speed; }
/** * hif_state_get_allow_cancel: **/ gboolean hif_state_get_allow_cancel (HifState *state) { g_return_val_if_fail (HIF_IS_STATE (state), FALSE); return state->priv->allow_cancel && state->priv->allow_cancel_child; }
/** * hif_state_get_cancellable: **/ GCancellable * hif_state_get_cancellable (HifState *state) { g_return_val_if_fail (HIF_IS_STATE (state), NULL); return state->priv->cancellable; }
/** * hif_state_set_enable_profile: **/ void hif_state_set_enable_profile (HifState *state, gboolean enable_profile) { g_return_if_fail (HIF_IS_STATE (state)); state->priv->enable_profile = enable_profile; }