importd: convert to the new scheme
This commit is contained in:
+83
-84
@@ -8,6 +8,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-log-control-api.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "def.h"
|
||||
#include "fd-util.h"
|
||||
@@ -1117,6 +1118,73 @@ static int property_get_progress(
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, transfer_type, TransferType);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_verify, import_verify, ImportVerify);
|
||||
|
||||
static int transfer_object_find(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
void *userdata,
|
||||
void **found,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Manager *m = userdata;
|
||||
Transfer *t;
|
||||
const char *p;
|
||||
uint32_t id;
|
||||
int r;
|
||||
|
||||
assert(bus);
|
||||
assert(path);
|
||||
assert(interface);
|
||||
assert(found);
|
||||
assert(m);
|
||||
|
||||
p = startswith(path, "/org/freedesktop/import1/transfer/_");
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
r = safe_atou32(p, &id);
|
||||
if (r < 0 || id == 0)
|
||||
return 0;
|
||||
|
||||
t = hashmap_get(m->transfers, UINT32_TO_PTR(id));
|
||||
if (!t)
|
||||
return 0;
|
||||
|
||||
*found = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int transfer_node_enumerator(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
void *userdata,
|
||||
char ***nodes,
|
||||
sd_bus_error *error) {
|
||||
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
Manager *m = userdata;
|
||||
Transfer *t;
|
||||
unsigned k = 0;
|
||||
Iterator i;
|
||||
|
||||
l = new0(char*, hashmap_size(m->transfers) + 1);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
HASHMAP_FOREACH(t, m->transfers, i) {
|
||||
|
||||
l[k] = strdup(t->object_path);
|
||||
if (!l[k])
|
||||
return -ENOMEM;
|
||||
|
||||
k++;
|
||||
}
|
||||
|
||||
*nodes = TAKE_PTR(l);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const sd_bus_vtable transfer_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
|
||||
@@ -1138,6 +1206,13 @@ static const sd_bus_vtable transfer_vtable[] = {
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
static const BusObjectImplementation transfer_object = {
|
||||
"/org/freedesktop/import1/transfer",
|
||||
"org.freedesktop.import1.Transfer",
|
||||
.fallback_vtables = BUS_FALLBACK_VTABLES({transfer_vtable, transfer_object_find}),
|
||||
.node_enumerator = transfer_node_enumerator,
|
||||
};
|
||||
|
||||
static const sd_bus_vtable manager_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
|
||||
@@ -1244,97 +1319,21 @@ static const sd_bus_vtable manager_vtable[] = {
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
static int transfer_object_find(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
void *userdata,
|
||||
void **found,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Manager *m = userdata;
|
||||
Transfer *t;
|
||||
const char *p;
|
||||
uint32_t id;
|
||||
int r;
|
||||
|
||||
assert(bus);
|
||||
assert(path);
|
||||
assert(interface);
|
||||
assert(found);
|
||||
assert(m);
|
||||
|
||||
p = startswith(path, "/org/freedesktop/import1/transfer/_");
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
r = safe_atou32(p, &id);
|
||||
if (r < 0 || id == 0)
|
||||
return 0;
|
||||
|
||||
t = hashmap_get(m->transfers, UINT32_TO_PTR(id));
|
||||
if (!t)
|
||||
return 0;
|
||||
|
||||
*found = t;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int transfer_node_enumerator(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
void *userdata,
|
||||
char ***nodes,
|
||||
sd_bus_error *error) {
|
||||
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
Manager *m = userdata;
|
||||
Transfer *t;
|
||||
unsigned k = 0;
|
||||
Iterator i;
|
||||
|
||||
l = new0(char*, hashmap_size(m->transfers) + 1);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
HASHMAP_FOREACH(t, m->transfers, i) {
|
||||
|
||||
l[k] = strdup(t->object_path);
|
||||
if (!l[k])
|
||||
return -ENOMEM;
|
||||
|
||||
k++;
|
||||
}
|
||||
|
||||
*nodes = TAKE_PTR(l);
|
||||
|
||||
return 1;
|
||||
}
|
||||
static const BusObjectImplementation manager_object = {
|
||||
"/org/freedesktop/import1",
|
||||
"org.freedesktop.import1.Manager",
|
||||
.vtables = BUS_VTABLES(manager_vtable),
|
||||
.children = BUS_IMPLEMENTATIONS(&transfer_object),
|
||||
};
|
||||
|
||||
static int manager_add_bus_objects(Manager *m) {
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
|
||||
r = sd_bus_add_object_vtable(m->bus, NULL,
|
||||
"/org/freedesktop/import1",
|
||||
"org.freedesktop.import1.Manager",
|
||||
manager_vtable, m);
|
||||
r = bus_add_implementation(m->bus, &manager_object, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register object: %m");
|
||||
|
||||
r = sd_bus_add_fallback_vtable(m->bus, NULL,
|
||||
"/org/freedesktop/import1/transfer",
|
||||
"org.freedesktop.import1.Transfer",
|
||||
transfer_vtable, transfer_object_find, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register object: %m");
|
||||
|
||||
r = sd_bus_add_node_enumerator(m->bus, NULL,
|
||||
"/org/freedesktop/import1/transfer",
|
||||
transfer_node_enumerator, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add transfer enumerator: %m");
|
||||
return r;
|
||||
|
||||
r = bus_log_control_api_register(m->bus);
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user