daemon: add TaskBegin, TaskEnd, and PercentProgress
Closes: #260 Approved by: cgwalters
This commit is contained in:
parent
218804f22d
commit
582650e9c7
@ -51,6 +51,7 @@ librpmostreed_la_CFLAGS = \
|
||||
-DG_LOG_DOMAIN=\"rpm-ostreed\" \
|
||||
-I$(srcdir)/src/daemon \
|
||||
-I$(srcdir)/src/lib \
|
||||
-I$(srcdir)/src/libpriv \
|
||||
-I$(libglnx_srcpath) \
|
||||
$(NULL)
|
||||
|
||||
|
@ -41,6 +41,21 @@ librpmostreepriv_la_SOURCES = \
|
||||
src/libpriv/ostree-libarchive-input-stream.h \
|
||||
src/libpriv/rpmostree-ostree-libarchive-copynpaste.c \
|
||||
src/libpriv/rpmostree-ostree-libarchive-copynpaste.h \
|
||||
src/libpriv/rpmostree-output.c \
|
||||
src/libpriv/rpmostree-output.h \
|
||||
$(NULL)
|
||||
|
||||
librpmostreepriv_la_CFLAGS = \
|
||||
$(AM_CFLAGS) \
|
||||
-I$(srcdir)/src/libpriv \
|
||||
-I$(libglnx_srcpath) \
|
||||
-DPKGLIBDIR=\"$(pkglibdir)\" \
|
||||
$(PKGDEP_RPMOSTREE_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
librpmostreepriv_la_LIBADD = \
|
||||
$(AM_LDFLAGS) \
|
||||
$(PKGDEP_RPMOSTREE_LIBS) \
|
||||
libglnx.la \
|
||||
$(CAP_LIBS) \
|
||||
$(NULL)
|
||||
librpmostreepriv_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS)
|
||||
librpmostreepriv_la_LIBADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS) libglnx.la $(CAP_LIBS)
|
||||
|
@ -334,31 +334,29 @@ transaction_progress_free (TransactionProgress *self)
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
end_status_line (TransactionProgress *self)
|
||||
{
|
||||
gboolean ret = TRUE;
|
||||
|
||||
if (self->in_status_line)
|
||||
{
|
||||
glnx_console_unlock (&self->console);
|
||||
self->in_status_line = FALSE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
add_status_line (TransactionProgress *self,
|
||||
const char *line)
|
||||
const char *line,
|
||||
int percentage)
|
||||
{
|
||||
if (self->console.is_tty)
|
||||
{
|
||||
self->in_status_line = TRUE;
|
||||
glnx_console_text (line);
|
||||
}
|
||||
return TRUE;
|
||||
self->in_status_line = TRUE;
|
||||
if (!self->console.locked)
|
||||
glnx_console_lock (&self->console);
|
||||
if (percentage < 0)
|
||||
glnx_console_text (line);
|
||||
else
|
||||
glnx_console_progress_text_percent (line, percentage);
|
||||
}
|
||||
|
||||
|
||||
@ -384,18 +382,39 @@ on_transaction_progress (GDBusProxy *proxy,
|
||||
g_autoptr(GVariant) sig = NULL;
|
||||
sig = g_variant_get_child_value (parameters, 0);
|
||||
rpmostree_print_signatures (g_variant_ref (sig), " ");
|
||||
add_status_line (tp, "\n");
|
||||
add_status_line (tp, "\n", -1);
|
||||
}
|
||||
else if (g_strcmp0 (signal_name, "Message") == 0)
|
||||
{
|
||||
g_autofree gchar *message = NULL;
|
||||
|
||||
g_variant_get_child (parameters, 0, "s", &message);
|
||||
const gchar *message = NULL;
|
||||
g_variant_get_child (parameters, 0, "&s", &message);
|
||||
if (tp->in_status_line)
|
||||
add_status_line (tp, message);
|
||||
add_status_line (tp, message, -1);
|
||||
else
|
||||
g_print ("%s\n", message);
|
||||
}
|
||||
else if (g_strcmp0 (signal_name, "TaskBegin") == 0)
|
||||
{
|
||||
/* XXX: whenever libglnx implements a spinner, this would be appropriate
|
||||
* here. */
|
||||
const gchar *message = NULL;
|
||||
g_variant_get_child (parameters, 0, "&s", &message);
|
||||
g_print ("%s... ", message);
|
||||
}
|
||||
else if (g_strcmp0 (signal_name, "TaskEnd") == 0)
|
||||
{
|
||||
const gchar *message = NULL;
|
||||
g_variant_get_child (parameters, 0, "&s", &message);
|
||||
g_print ("%s\n", message);
|
||||
}
|
||||
else if (g_strcmp0 (signal_name, "PercentProgress") == 0)
|
||||
{
|
||||
const gchar *message = NULL;
|
||||
guint32 percentage;
|
||||
g_variant_get_child (parameters, 0, "&s", &message);
|
||||
g_variant_get_child (parameters, 1, "u", &percentage);
|
||||
add_status_line (tp, message, percentage);
|
||||
}
|
||||
else if (g_strcmp0 (signal_name, "DownloadProgress") == 0)
|
||||
{
|
||||
g_autofree gchar *line = NULL;
|
||||
@ -438,7 +457,7 @@ on_transaction_progress (GDBusProxy *proxy,
|
||||
requested,
|
||||
bytes_transferred,
|
||||
bytes_sec);
|
||||
add_status_line (tp, line);
|
||||
add_status_line (tp, line, -1);
|
||||
}
|
||||
else if (g_strcmp0 (signal_name, "ProgressEnd") == 0)
|
||||
{
|
||||
|
@ -191,11 +191,26 @@
|
||||
<arg name="error_message" type="s" direction="out"/>
|
||||
</signal>
|
||||
|
||||
<!-- For miscellaneous messages. -->
|
||||
<!-- For miscellaneous messages; line-buffered. -->
|
||||
<signal name="Message">
|
||||
<arg name="text" type="s" direction="out"/>
|
||||
</signal>
|
||||
|
||||
<!-- Tasks are notifications that work is being done. -->
|
||||
<signal name="TaskBegin">
|
||||
<arg name="text" type="s" direction="out"/>
|
||||
</signal>
|
||||
|
||||
<signal name="TaskEnd">
|
||||
<arg name="text" type="s" direction="out"/>
|
||||
</signal>
|
||||
|
||||
<!-- Generic percentage progress. -->
|
||||
<signal name="PercentProgress">
|
||||
<arg name="text" type="s" direction="out"/>
|
||||
<arg name="percentage" type="u" direction="out"/>
|
||||
</signal>
|
||||
|
||||
<signal name="DownloadProgress">
|
||||
<!-- time data, format is:
|
||||
start time, elapsed seconds
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "rpmostreed-transaction.h"
|
||||
#include "rpmostreed-transaction-monitor.h"
|
||||
|
||||
#include "rpmostree-output.h"
|
||||
|
||||
#include "libgsystem.h"
|
||||
#include <libglnx.h>
|
||||
#include <gio/gunixinputstream.h>
|
||||
@ -276,6 +278,42 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
sysroot_output_cb (RpmOstreeOutputType type, void *data, void *opaque)
|
||||
{
|
||||
RpmostreedSysroot *self = RPMOSTREED_SYSROOT (opaque);
|
||||
glnx_unref_object RpmostreedTransaction *transaction = NULL;
|
||||
|
||||
transaction =
|
||||
rpmostreed_transaction_monitor_ref_active_transaction (self->transaction_monitor);
|
||||
|
||||
if (!transaction)
|
||||
{
|
||||
rpmostree_output_default_handler (type, data, opaque);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case RPMOSTREE_OUTPUT_TASK_BEGIN:
|
||||
rpmostree_transaction_emit_task_begin (RPMOSTREE_TRANSACTION (transaction),
|
||||
((RpmOstreeOutputTaskBegin*)data)->text);
|
||||
break;
|
||||
case RPMOSTREE_OUTPUT_TASK_END:
|
||||
rpmostree_transaction_emit_task_end (RPMOSTREE_TRANSACTION (transaction),
|
||||
((RpmOstreeOutputTaskEnd*)data)->text);
|
||||
break;
|
||||
case RPMOSTREE_OUTPUT_PERCENT_PROGRESS:
|
||||
rpmostree_transaction_emit_percent_progress (RPMOSTREE_TRANSACTION (transaction),
|
||||
((RpmOstreeOutputPercentProgress*)data)->text,
|
||||
((RpmOstreeOutputPercentProgress*)data)->percentage);
|
||||
break;
|
||||
case RPMOSTREE_OUTPUT_PERCENT_PROGRESS_END:
|
||||
rpmostree_transaction_emit_progress_end (RPMOSTREE_TRANSACTION (transaction));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_create_osname (RPMOSTreeSysroot *object,
|
||||
GDBusMethodInvocation *invocation,
|
||||
@ -542,6 +580,8 @@ sysroot_finalize (GObject *object)
|
||||
if (self->stdout_source_id > 0)
|
||||
g_source_remove (self->stdout_source_id);
|
||||
|
||||
rpmostree_output_set_callback (NULL, NULL);
|
||||
|
||||
G_OBJECT_CLASS (rpmostreed_sysroot_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
@ -559,6 +599,8 @@ rpmostreed_sysroot_init (RpmostreedSysroot *self)
|
||||
self->monitor = NULL;
|
||||
|
||||
self->transaction_monitor = rpmostreed_transaction_monitor_new ();
|
||||
|
||||
rpmostree_output_set_callback (sysroot_output_cb, self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -32,7 +32,7 @@ GType rpmostreed_sysroot_get_type (void) G_GNUC_CONST;
|
||||
RpmostreedSysroot * rpmostreed_sysroot_get (void);
|
||||
|
||||
gboolean rpmostreed_sysroot_populate (RpmostreedSysroot *self,
|
||||
GCancellable *cancellable,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean rpmostreed_sysroot_reload (RpmostreedSysroot *self,
|
||||
GError **error);
|
||||
|
99
src/libpriv/rpmostree-output.c
Normal file
99
src/libpriv/rpmostree-output.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <ostree.h>
|
||||
#include <libglnx.h>
|
||||
|
||||
#include "rpmostree-output.h"
|
||||
|
||||
/* These are helper functions that automatically determine whether data should
|
||||
* be sent through an appropriate D-Bus signal or sent directly to the local
|
||||
* terminal. This is helpful in situations in which code may be executed both
|
||||
* from the daemon and daemon-less. */
|
||||
|
||||
static GLnxConsoleRef console;
|
||||
|
||||
void
|
||||
rpmostree_output_default_handler (RpmOstreeOutputType type,
|
||||
void *data,
|
||||
void *opaque)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case RPMOSTREE_OUTPUT_TASK_BEGIN:
|
||||
/* XXX: move to libglnx spinner once it's implemented */
|
||||
g_print ("%s... ", ((RpmOstreeOutputTaskBegin*)data)->text);
|
||||
break;
|
||||
case RPMOSTREE_OUTPUT_TASK_END:
|
||||
g_print ("%s\n", ((RpmOstreeOutputTaskEnd*)data)->text);
|
||||
break;
|
||||
case RPMOSTREE_OUTPUT_PERCENT_PROGRESS:
|
||||
if (!console.locked)
|
||||
glnx_console_lock (&console);
|
||||
glnx_console_progress_text_percent (
|
||||
((RpmOstreeOutputPercentProgress*)data)->text,
|
||||
((RpmOstreeOutputPercentProgress*)data)->percentage);
|
||||
break;
|
||||
case RPMOSTREE_OUTPUT_PERCENT_PROGRESS_END:
|
||||
if (console.locked)
|
||||
glnx_console_unlock (&console);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void (*active_cb)(RpmOstreeOutputType, void*, void*) =
|
||||
rpmostree_output_default_handler;
|
||||
|
||||
static void *active_cb_opaque;
|
||||
|
||||
void
|
||||
rpmostree_output_set_callback (void (*cb)(RpmOstreeOutputType, void*, void*),
|
||||
void* opaque)
|
||||
{
|
||||
active_cb = cb ?: rpmostree_output_default_handler;
|
||||
active_cb_opaque = opaque;
|
||||
}
|
||||
|
||||
void
|
||||
rpmostree_output_task_begin (const char *text)
|
||||
{
|
||||
RpmOstreeOutputTaskBegin task = { text };
|
||||
active_cb (RPMOSTREE_OUTPUT_TASK_BEGIN, &task, active_cb_opaque);
|
||||
}
|
||||
|
||||
void
|
||||
rpmostree_output_task_end (const char *text)
|
||||
{
|
||||
RpmOstreeOutputTaskEnd task = { text };
|
||||
active_cb (RPMOSTREE_OUTPUT_TASK_END, &task, active_cb_opaque);
|
||||
}
|
||||
|
||||
void
|
||||
rpmostree_output_percent_progress (const char *text, int percentage)
|
||||
{
|
||||
RpmOstreeOutputPercentProgress progress = { text, percentage };
|
||||
active_cb (RPMOSTREE_OUTPUT_PERCENT_PROGRESS, &progress, active_cb_opaque);
|
||||
}
|
||||
|
||||
void
|
||||
rpmostree_output_percent_progress_end (void)
|
||||
{
|
||||
active_cb (RPMOSTREE_OUTPUT_PERCENT_PROGRESS_END, NULL, active_cb_opaque);
|
||||
}
|
55
src/libpriv/rpmostree-output.h
Normal file
55
src/libpriv/rpmostree-output.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
RPMOSTREE_OUTPUT_TASK_BEGIN,
|
||||
RPMOSTREE_OUTPUT_TASK_END,
|
||||
RPMOSTREE_OUTPUT_PERCENT_PROGRESS,
|
||||
RPMOSTREE_OUTPUT_PERCENT_PROGRESS_END,
|
||||
} RpmOstreeOutputType;
|
||||
|
||||
void
|
||||
rpmostree_output_default_handler (RpmOstreeOutputType type, void *data, void *opaque);
|
||||
|
||||
void
|
||||
rpmostree_output_set_callback (void (*cb)(RpmOstreeOutputType, void*, void*), void*);
|
||||
|
||||
typedef struct {
|
||||
const char *text;
|
||||
} RpmOstreeOutputTaskBegin;
|
||||
|
||||
void
|
||||
rpmostree_output_task_begin (const char *text);
|
||||
|
||||
typedef RpmOstreeOutputTaskBegin RpmOstreeOutputTaskEnd;
|
||||
|
||||
void
|
||||
rpmostree_output_task_end (const char *text);
|
||||
|
||||
typedef struct {
|
||||
const char *text;
|
||||
guint32 percentage;
|
||||
} RpmOstreeOutputPercentProgress;
|
||||
|
||||
void
|
||||
rpmostree_output_percent_progress (const char *text, int percentage);
|
||||
|
||||
void
|
||||
rpmostree_output_percent_progress_end (void);
|
Loading…
Reference in New Issue
Block a user