]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/bus-get-properties.h
bus-util: introduce bus_property_get_tristate()
[thirdparty/systemd.git] / src / shared / bus-get-properties.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
40af3d02
LP
2#pragma once
3
4#include "sd-bus.h"
5
40af3d02
LP
6#include "macro.h"
7
8int 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 *error);
9int 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 *error);
ec1b4be8 10int 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 *error);
40af3d02
LP
11int 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 *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
16assert_cc(sizeof(int) == sizeof(int32_t));
17#define bus_property_get_int ((sd_bus_property_get_t) NULL)
18
19assert_cc(sizeof(unsigned) == sizeof(uint32_t));
20#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL)
21
22/* On 64bit 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
27int 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 *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
34int 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 *error);
35int 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 *error);
36#endif
37
38/* uid_t and friends on Linux 32 bit. This means we can just use the
39 * default serializer for 32bit unsigned, for serializing it, and map
40 * it to NULL here */
41assert_cc(sizeof(uid_t) == sizeof(uint32_t));
42#define bus_property_get_uid ((sd_bus_property_get_t) NULL)
43
44assert_cc(sizeof(gid_t) == sizeof(uint32_t));
45#define bus_property_get_gid ((sd_bus_property_get_t) NULL)
46
47assert_cc(sizeof(pid_t) == sizeof(uint32_t));
48#define bus_property_get_pid ((sd_bus_property_get_t) NULL)
49
50assert_cc(sizeof(mode_t) == sizeof(uint32_t));
51#define bus_property_get_mode ((sd_bus_property_get_t) NULL)
52
53int 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 *error);
54
55#define BUS_DEFINE_PROPERTY_GET_GLOBAL(function, bus_type, val) \
56 int function(sd_bus *bus, \
57 const char *path, \
58 const char *interface, \
59 const char *property, \
60 sd_bus_message *reply, \
61 void *userdata, \
62 sd_bus_error *error) { \
63 \
64 assert(bus); \
65 assert(reply); \
66 \
67 return sd_bus_message_append(reply, bus_type, val); \
68 }
69
70#define BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, get2) \
71 int function(sd_bus *bus, \
72 const char *path, \
73 const char *interface, \
74 const char *property, \
75 sd_bus_message *reply, \
76 void *userdata, \
77 sd_bus_error *error) { \
78 \
99534007 79 data_type *data = ASSERT_PTR(userdata); \
40af3d02
LP
80 \
81 assert(bus); \
82 assert(reply); \
40af3d02
LP
83 \
84 return sd_bus_message_append(reply, bus_type, \
85 get2(get1(data))); \
86 }
87
88#define ident(x) (x)
89#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1) \
90 BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, ident)
91
92#define ref(x) (*(x))
93#define BUS_DEFINE_PROPERTY_GET_REF(function, bus_type, data_type, get) \
94 BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, ref, get)
95
96#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \
97 BUS_DEFINE_PROPERTY_GET_REF(function, "s", type, name##_to_string)
98
99#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
100 SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
101 SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))