manager: Introduce manager_get_progress() helper
This commit is contained in:
+1
-23
@@ -67,6 +67,7 @@ static BUS_DEFINE_PROPERTY_GET(property_get_default_timeout_abort_usec, "t", Man
|
||||
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_device, "s", watchdog_get_device());
|
||||
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_last_ping_realtime, "t", watchdog_get_last_ping(CLOCK_REALTIME));
|
||||
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_last_ping_monotonic, "t", watchdog_get_last_ping(CLOCK_MONOTONIC));
|
||||
static BUS_DEFINE_PROPERTY_GET(property_get_progress, "d", Manager, manager_get_progress);
|
||||
|
||||
static int property_get_virtualization(
|
||||
sd_bus *bus,
|
||||
@@ -207,29 +208,6 @@ static int property_set_log_level(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int property_get_progress(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Manager *m = ASSERT_PTR(userdata);
|
||||
double d;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
if (MANAGER_IS_FINISHED(m))
|
||||
d = 1.0;
|
||||
else
|
||||
d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
|
||||
|
||||
return sd_bus_message_append(reply, "d", d);
|
||||
}
|
||||
|
||||
static int property_get_environment(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
|
||||
@@ -866,6 +866,15 @@ void manager_set_switching_root(Manager *m, bool switching_root) {
|
||||
m->switching_root = MANAGER_IS_SYSTEM(m) && switching_root;
|
||||
}
|
||||
|
||||
double manager_get_progress(Manager *m) {
|
||||
assert(m);
|
||||
|
||||
if (MANAGER_IS_FINISHED(m) || m->n_installed_jobs == 0)
|
||||
return 1.0;
|
||||
|
||||
return 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
|
||||
}
|
||||
|
||||
static int compare_job_priority(const void *a, const void *b) {
|
||||
const Job *x = a, *y = b;
|
||||
|
||||
|
||||
@@ -592,6 +592,8 @@ void manager_override_show_status(Manager *m, ShowStatus mode, const char *reaso
|
||||
void manager_set_first_boot(Manager *m, bool b);
|
||||
void manager_set_switching_root(Manager *m, bool switching_root);
|
||||
|
||||
double manager_get_progress(Manager *m);
|
||||
|
||||
void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) _printf_(4,5);
|
||||
|
||||
Set *manager_get_units_requiring_mounts_for(Manager *m, const char *path);
|
||||
|
||||
Reference in New Issue
Block a user