| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-bus.h" /* IWYU pragma: keep */ |
| 5 |
|
| 6 |
#include "shared-forward.h" |
| 7 |
|
| 8 |
int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 9 |
int bus_property_set_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *reterr_error); |
| 10 |
int bus_property_get_tristate(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 11 |
int bus_property_get_id128(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 12 |
|
| 13 |
#define bus_property_get_usec ((sd_bus_property_get_t) NULL) |
| 14 |
#define bus_property_set_usec ((sd_bus_property_set_t) NULL) |
| 15 |
|
| 16 |
assert_cc(sizeof(int) == sizeof(int32_t)); |
| 17 |
#define bus_property_get_int ((sd_bus_property_get_t) NULL) |
| 18 |
|
| 19 |
assert_cc(sizeof(unsigned) == sizeof(uint32_t)); |
| 20 |
#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL) |
| 21 |
|
| 22 |
/* On 64-bit machines we can use the default serializer for size_t and |
| 23 |
* friends, otherwise we need to cast this manually */ |
| 24 |
#if __SIZEOF_SIZE_T__ == 8 |
| 25 |
#define bus_property_get_size ((sd_bus_property_get_t) NULL) |
| 26 |
#else |
| 27 |
int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 28 |
#endif |
| 29 |
|
| 30 |
#if __SIZEOF_LONG__ == 8 |
| 31 |
#define bus_property_get_long ((sd_bus_property_get_t) NULL) |
| 32 |
#define bus_property_get_ulong ((sd_bus_property_get_t) NULL) |
| 33 |
#else |
| 34 |
int bus_property_get_long(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 35 |
int bus_property_get_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 36 |
#endif |
| 37 |
|
| 38 |
/* uid_t and friends on Linux 32 bit. This means we can just use the |
| 39 |
* default serializer for 32-bit unsigned, for serializing it, and map |
| 40 |
* it to NULL here */ |
| 41 |
assert_cc(sizeof(uid_t) == sizeof(uint32_t)); |
| 42 |
#define bus_property_get_uid ((sd_bus_property_get_t) NULL) |
| 43 |
|
| 44 |
assert_cc(sizeof(gid_t) == sizeof(uint32_t)); |
| 45 |
#define bus_property_get_gid ((sd_bus_property_get_t) NULL) |
| 46 |
|
| 47 |
assert_cc(sizeof(pid_t) == sizeof(uint32_t)); |
| 48 |
#define bus_property_get_pid ((sd_bus_property_get_t) NULL) |
| 49 |
|
| 50 |
assert_cc(sizeof(mode_t) == sizeof(uint32_t)); |
| 51 |
#define bus_property_get_mode ((sd_bus_property_get_t) NULL) |
| 52 |
|
| 53 |
int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 54 |
|
| 55 |
int bus_property_get_string_set(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 56 |
|
| 57 |
int bus_property_get_pidfdid(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 58 |
|
| 59 |
#define BUS_DEFINE_PROPERTY_GET_GLOBAL(function, bus_type, val) \ |
| 60 |
int function(sd_bus *bus, \ |
| 61 |
const char *path, \ |
| 62 |
const char *interface, \ |
| 63 |
const char *property, \ |
| 64 |
sd_bus_message *reply, \ |
| 65 |
void *userdata, \ |
| 66 |
sd_bus_error *reterr_error) { \ |
| 67 |
\ |
| 68 |
assert(bus); \ |
| 69 |
assert(reply); \ |
| 70 |
\ |
| 71 |
return sd_bus_message_append(reply, bus_type, val); \ |
| 72 |
} |
| 73 |
|
| 74 |
#define BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, get2) \ |
| 75 |
int function(sd_bus *bus, \ |
| 76 |
const char *path, \ |
| 77 |
const char *interface, \ |
| 78 |
const char *property, \ |
| 79 |
sd_bus_message *reply, \ |
| 80 |
void *userdata, \ |
| 81 |
sd_bus_error *reterr_error) { \ |
| 82 |
\ |
| 83 |
data_type *data = ASSERT_PTR(userdata); \ |
| 84 |
\ |
| 85 |
assert(bus); \ |
| 86 |
assert(reply); \ |
| 87 |
\ |
| 88 |
return sd_bus_message_append(reply, bus_type, \ |
| 89 |
get2(get1(data))); \ |
| 90 |
} |
| 91 |
|
| 92 |
#define ident(x) (x) |
| 93 |
#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1) \ |
| 94 |
BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, ident) |
| 95 |
|
| 96 |
#define ref(x) (*(x)) |
| 97 |
#define BUS_DEFINE_PROPERTY_GET_REF(function, bus_type, data_type, get) \ |
| 98 |
BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, ref, get) |
| 99 |
|
| 100 |
#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \ |
| 101 |
BUS_DEFINE_PROPERTY_GET_REF(function, "s", type, name##_to_string) |
| 102 |
|
| 103 |
#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \ |
| 104 |
SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \ |
| 105 |
SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags)) |
| 106 |
|
| 107 |
/* For deprecated properties. */ |
| 108 |
int bus_property_get_bool_false(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 109 |
int bus_property_get_bool_true(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 110 |
int bus_property_get_uint64_0(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |
| 111 |
int bus_property_get_uint64_max(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error); |