| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "list.h" |
| 5 |
#include "machine-forward.h" |
| 6 |
#include "pidref.h" |
| 7 |
|
| 8 |
#define OPERATIONS_MAX 64 |
| 9 |
|
| 10 |
typedef struct Operation { |
| 11 |
Manager *manager; |
| 12 |
Machine *machine; |
| 13 |
PidRef pidref; |
| 14 |
|
| 15 |
/* only one of these two fields should be set */ |
| 16 |
sd_varlink *link; |
| 17 |
sd_bus_message *message; |
| 18 |
|
| 19 |
int errno_fd; |
| 20 |
int extra_fd; |
| 21 |
sd_event_source *event_source; |
| 22 |
int (*done)(Operation *o, int ret, sd_bus_error *error); |
| 23 |
LIST_FIELDS(Operation, operations); |
| 24 |
LIST_FIELDS(Operation, operations_by_machine); |
| 25 |
} Operation; |
| 26 |
|
| 27 |
int operation_new(Manager *manager, Machine *machine, PidRef *child, int errno_fd, Operation **ret); |
| 28 |
Operation *operation_free(Operation *o); |
| 29 |
|
| 30 |
void operation_attach_bus_reply(Operation *op, sd_bus_message *message); |
| 31 |
void operation_attach_varlink_reply(Operation *op, sd_varlink *link); |
| 32 |
|
| 33 |
static inline int operation_new_with_bus_reply( |
| 34 |
Manager *manager, |
| 35 |
Machine *machine, |
| 36 |
PidRef *child, |
| 37 |
sd_bus_message *message, |
| 38 |
int errno_fd, |
| 39 |
Operation **ret) { |
| 40 |
|
| 41 |
Operation *op; |
| 42 |
int r; |
| 43 |
|
| 44 |
r = operation_new(manager, machine, child, errno_fd, &op); |
| 45 |
if (r < 0) |
| 46 |
return r; |
| 47 |
|
| 48 |
operation_attach_bus_reply(op, message); |
| 49 |
|
| 50 |
if (ret) |
| 51 |
*ret = op; |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
static inline int operation_new_with_varlink_reply( |
| 57 |
Manager *manager, |
| 58 |
Machine *machine, |
| 59 |
PidRef *child, |
| 60 |
sd_varlink *link, |
| 61 |
int errno_fd, |
| 62 |
Operation **ret) { |
| 63 |
|
| 64 |
Operation *op; |
| 65 |
int r; |
| 66 |
|
| 67 |
r = operation_new(manager, machine, child, errno_fd, &op); |
| 68 |
if (r < 0) |
| 69 |
return r; |
| 70 |
|
| 71 |
operation_attach_varlink_reply(op, link); |
| 72 |
|
| 73 |
if (ret) |
| 74 |
*ret = op; |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |