Skip to content

Commit

Permalink
pk-offline: Add flags to D-Bus invoking methods
Browse files Browse the repository at this point in the history
That's currently to be able to set whether the method should be
interactive or not. The old functions call the methods as non-interactive.

Closes PackageKit#504
  • Loading branch information
mcrha authored and hughsie committed Sep 15, 2021
1 parent f484808 commit dda4b01
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 9 deletions.
4 changes: 2 additions & 2 deletions client/pk-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2283,14 +2283,14 @@ main (int argc, char *argv[])
} else if (strcmp (mode, "offline-trigger") == 0) {

run_mainloop = FALSE;
ret = pk_offline_trigger (PK_OFFLINE_ACTION_REBOOT, NULL, &error);
ret = pk_offline_trigger_with_flags (PK_OFFLINE_ACTION_REBOOT, PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error);
if (!ret)
ctx->retval = error->code;

} else if (strcmp (mode, "offline-cancel") == 0) {

run_mainloop = FALSE;
ret = pk_offline_cancel (NULL, &error);
ret = pk_offline_cancel_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error);
if (!ret)
ctx->retval = error->code;

Expand Down
4 changes: 4 additions & 0 deletions docs/api/PackageKit-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,13 @@ pk_offline_get_action_monitor
pk_offline_get_results
pk_offline_get_results_mtime
pk_offline_cancel
pk_offline_cancel_with_flags
pk_offline_clear_results
pk_offline_clear_results_with_flags
pk_offline_trigger
pk_offline_trigger_with_flags
pk_offline_trigger_upgrade
pk_offline_trigger_upgrade_with_flags
</SECTION>

<SECTION>
Expand Down
104 changes: 99 additions & 5 deletions lib/packagekit-glib2/pk-offline.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,49 @@ pk_offline_action_from_string (const gchar *action)
return PK_OFFLINE_ACTION_UNKNOWN;
}

static GDBusCallFlags
pk_offline_flags_to_gdbus_call_flags (PkOfflineFlags flags)
{
if ((flags & PK_OFFLINE_FLAGS_INTERACTIVE) != 0)
return G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION;
return G_DBUS_CALL_FLAGS_NONE;
}

/**
* pk_offline_cancel:
* @cancellable: A #GCancellable or %NULL
* @error: A #GError or %NULL
*
* Cancels the offline operation that has been scheduled. If there is no
* scheduled offline operation then this method returns with success.
* The function always allows user interaction. To change the behavior,
* use pk_offline_cancel_with_flags().
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 0.9.6
**/
gboolean
pk_offline_cancel (GCancellable *cancellable, GError **error)
{
return pk_offline_cancel_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error);
}

/**
* pk_offline_cancel_with_flags:
* @flags: bit-or of #PkOfflineFlags
* @cancellable: A #GCancellable or %NULL
* @error: A #GError or %NULL
*
* Cancels the offline operation that has been scheduled. If there is no
* scheduled offline operation then this method returns with success.
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 1.2.5
**/
gboolean
pk_offline_cancel_with_flags (PkOfflineFlags flags, GCancellable *cancellable, GError **error)
{
g_autoptr(GDBusConnection) connection = NULL;
g_autoptr(GVariant) res = NULL;
Expand All @@ -125,7 +154,7 @@ pk_offline_cancel (GCancellable *cancellable, GError **error)
"Cancel",
NULL,
NULL,
G_DBUS_CALL_FLAGS_NONE,
pk_offline_flags_to_gdbus_call_flags (flags),
-1,
cancellable,
error);
Expand All @@ -139,15 +168,36 @@ pk_offline_cancel (GCancellable *cancellable, GError **error)
* @cancellable: A #GCancellable or %NULL
* @error: A #GError or %NULL
*
* Crears the last offline operation report, which may be success or failure.
* Clears the last offline operation report, which may be success or failure.
* If the report does not exist then this method returns success.
* The function always allows user interaction. To change the behavior,
* use pk_offline_clear_results_with_flags().
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 0.9.6
**/
gboolean
pk_offline_clear_results (GCancellable *cancellable, GError **error)
{
return pk_offline_clear_results_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error);
}

/**
* pk_offline_clear_results_with_flags:
* @flags: bit-or of #PkOfflineFlags
* @cancellable: A #GCancellable or %NULL
* @error: A #GError or %NULL
*
* Clears the last offline operation report, which may be success or failure.
* If the report does not exist then this method returns success.
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 1.2.5
**/
gboolean
pk_offline_clear_results_with_flags (PkOfflineFlags flags, GCancellable *cancellable, GError **error)
{
g_autoptr(GDBusConnection) connection = NULL;
g_autoptr(GVariant) res = NULL;
Expand All @@ -164,7 +214,7 @@ pk_offline_clear_results (GCancellable *cancellable, GError **error)
"ClearResults",
NULL,
NULL,
G_DBUS_CALL_FLAGS_NONE,
pk_offline_flags_to_gdbus_call_flags (flags),
-1,
cancellable,
error);
Expand All @@ -181,13 +231,35 @@ pk_offline_clear_results (GCancellable *cancellable, GError **error)
*
* Triggers the offline update so that the next reboot will perform the
* pending transaction.
* The function always allows user interaction. To change the behavior,
* use pk_offline_trigger_with_flags().
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 0.9.6
**/
gboolean
pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError **error)
{
return pk_offline_trigger_with_flags (action, PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error);
}

/**
* pk_offline_trigger_with_flags:
* @action: a #PkOfflineAction, e.g. %PK_OFFLINE_ACTION_REBOOT
* @flags: bit-or of #PkOfflineFlags
* @cancellable: A #GCancellable or %NULL
* @error: A #GError or %NULL
*
* Triggers the offline update so that the next reboot will perform the
* pending transaction.
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 1.2.5
**/
gboolean
pk_offline_trigger_with_flags (PkOfflineAction action, PkOfflineFlags flags, GCancellable *cancellable, GError **error)
{
const gchar *tmp;
g_autoptr(GDBusConnection) connection = NULL;
Expand All @@ -206,7 +278,7 @@ pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError **
"Trigger",
g_variant_new ("(s)", tmp),
NULL,
G_DBUS_CALL_FLAGS_NONE,
pk_offline_flags_to_gdbus_call_flags (flags),
-1,
cancellable,
error);
Expand All @@ -223,13 +295,35 @@ pk_offline_trigger (PkOfflineAction action, GCancellable *cancellable, GError **
*
* Triggers the offline system upgrade so that the next reboot will perform the
* pending transaction.
* The function always allows user interaction. To change the behavior,
* use pk_offline_trigger_upgrade_with_flags().
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 1.0.12
**/
gboolean
pk_offline_trigger_upgrade (PkOfflineAction action, GCancellable *cancellable, GError **error)
{
return pk_offline_trigger_upgrade_with_flags (action, PK_OFFLINE_FLAGS_INTERACTIVE, cancellable, error);
}

/**
* pk_offline_trigger_upgrade_with_flags:
* @action: a #PkOfflineAction, e.g. %PK_OFFLINE_ACTION_REBOOT
* @flags: bit-or of #PkOfflineFlags
* @cancellable: A #GCancellable or %NULL
* @error: A #GError or %NULL
*
* Triggers the offline system upgrade so that the next reboot will perform the
* pending transaction.
*
* Return value: %TRUE for success, else %FALSE and @error set
*
* Since: 1.2.5
**/
gboolean
pk_offline_trigger_upgrade_with_flags (PkOfflineAction action, PkOfflineFlags flags, GCancellable *cancellable, GError **error)
{
const gchar *tmp;
g_autoptr(GDBusConnection) connection = NULL;
Expand All @@ -248,7 +342,7 @@ pk_offline_trigger_upgrade (PkOfflineAction action, GCancellable *cancellable, G
"TriggerUpgrade",
g_variant_new ("(s)", tmp),
NULL,
G_DBUS_CALL_FLAGS_NONE,
pk_offline_flags_to_gdbus_call_flags (flags),
-1,
cancellable,
error);
Expand Down
31 changes: 31 additions & 0 deletions lib/packagekit-glib2/pk-offline.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ typedef enum
PK_OFFLINE_ERROR_LAST
} PkOfflineError;

/**
* PkOfflineFlags:
* @PK_OFFLINE_FLAGS_NONE: No specific flag
* @PK_OFFLINE_FLAGS_INTERACTIVE: Run the action in an interactive mode, allowing polkit authentication dialogs
*
* Flags to be used for the method invocations.
*
* Since: 1.2.5
*/
typedef enum
{
PK_OFFLINE_FLAGS_NONE = 0,
PK_OFFLINE_FLAGS_INTERACTIVE = 1 << 0
} PkOfflineFlags;

GQuark pk_offline_error_quark (void);
const gchar *pk_offline_action_to_string (PkOfflineAction action);
PkOfflineAction pk_offline_action_from_string (const gchar *action);
Expand All @@ -92,14 +107,30 @@ PkResults *pk_offline_get_results (GError **error);
guint64 pk_offline_get_results_mtime (GError **error);
gboolean pk_offline_cancel (GCancellable *cancellable,
GError **error);
gboolean pk_offline_cancel_with_flags (PkOfflineFlags flags,
GCancellable *cancellable,
GError **error);
gboolean pk_offline_clear_results (GCancellable *cancellable,
GError **error);
gboolean pk_offline_clear_results_with_flags
(PkOfflineFlags flags,
GCancellable *cancellable,
GError **error);
gboolean pk_offline_trigger (PkOfflineAction action,
GCancellable *cancellable,
GError **error);
gboolean pk_offline_trigger_with_flags (PkOfflineAction action,
PkOfflineFlags flags,
GCancellable *cancellable,
GError **error);
gboolean pk_offline_trigger_upgrade (PkOfflineAction action,
GCancellable *cancellable,
GError **error);
gboolean pk_offline_trigger_upgrade_with_flags
(PkOfflineAction action,
PkOfflineFlags flags,
GCancellable *cancellable,
GError **error);

G_END_DECLS

Expand Down
4 changes: 2 additions & 2 deletions lib/packagekit-glib2/pk-test-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pk_test_offline_func (void)
g_assert_cmpstr (data, ==, "powertop;1.8-1.fc8;i386;fedora");

/* trigger */
ret = pk_offline_trigger (PK_OFFLINE_ACTION_REBOOT, NULL, &error);
ret = pk_offline_trigger_with_flags (PK_OFFLINE_ACTION_REBOOT, PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error);
g_assert_no_error (error);
g_assert (ret);
g_assert (g_file_test (PK_OFFLINE_PREPARED_FILENAME, G_FILE_TEST_EXISTS));
Expand All @@ -163,7 +163,7 @@ pk_test_offline_func (void)
g_assert (!g_file_test (PK_OFFLINE_RESULTS_FILENAME, G_FILE_TEST_EXISTS));

/* cancel the trigger */
ret = pk_offline_cancel (NULL, &error);
ret = pk_offline_cancel_with_flags (PK_OFFLINE_FLAGS_INTERACTIVE, NULL, &error);
g_assert_no_error (error);
g_assert (ret);
g_assert (g_file_test (PK_OFFLINE_PREPARED_FILENAME, G_FILE_TEST_EXISTS));
Expand Down

0 comments on commit dda4b01

Please sign in to comment.