]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemd/sd-bus-vtable.h
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / src / systemd / sd-bus-vtable.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #ifndef foosdbusvtablehfoo
3 #define foosdbusvtablehfoo
4
5 /***
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include "_sd-common.h"
21
22 _SD_BEGIN_DECLARATIONS;
23
24 typedef struct sd_bus_vtable sd_bus_vtable;
25
26 #include "sd-bus.h"
27
28 enum {
29 _SD_BUS_VTABLE_START = '<',
30 _SD_BUS_VTABLE_END = '>',
31 _SD_BUS_VTABLE_METHOD = 'M',
32 _SD_BUS_VTABLE_SIGNAL = 'S',
33 _SD_BUS_VTABLE_PROPERTY = 'P',
34 _SD_BUS_VTABLE_WRITABLE_PROPERTY = 'W'
35 };
36
37 enum {
38 SD_BUS_VTABLE_DEPRECATED = 1ULL << 0,
39 SD_BUS_VTABLE_HIDDEN = 1ULL << 1,
40 SD_BUS_VTABLE_UNPRIVILEGED = 1ULL << 2,
41 SD_BUS_VTABLE_METHOD_NO_REPLY = 1ULL << 3,
42 SD_BUS_VTABLE_PROPERTY_CONST = 1ULL << 4,
43 SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE = 1ULL << 5,
44 SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION = 1ULL << 6,
45 SD_BUS_VTABLE_PROPERTY_EXPLICIT = 1ULL << 7,
46 _SD_BUS_VTABLE_CAPABILITY_MASK = 0xFFFFULL << 40
47 };
48
49 #define SD_BUS_VTABLE_CAPABILITY(x) ((uint64_t) (((x)+1) & 0xFFFF) << 40)
50
51 struct sd_bus_vtable {
52 /* Please do not initialize this structure directly, use the
53 * macros below instead */
54
55 uint8_t type:8;
56 uint64_t flags:56;
57 union {
58 struct {
59 size_t element_size;
60 } start;
61 struct {
62 const char *member;
63 const char *signature;
64 const char *result;
65 sd_bus_message_handler_t handler;
66 size_t offset;
67 } method;
68 struct {
69 const char *member;
70 const char *signature;
71 } signal;
72 struct {
73 const char *member;
74 const char *signature;
75 sd_bus_property_get_t get;
76 sd_bus_property_set_t set;
77 size_t offset;
78 } property;
79 } x;
80 };
81
82 #define SD_BUS_VTABLE_START(_flags) \
83 { \
84 .type = _SD_BUS_VTABLE_START, \
85 .flags = _flags, \
86 .x = { \
87 .start = { \
88 .element_size = sizeof(sd_bus_vtable) \
89 }, \
90 }, \
91 }
92
93 #define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \
94 { \
95 .type = _SD_BUS_VTABLE_METHOD, \
96 .flags = _flags, \
97 .x = { \
98 .method = { \
99 .member = _member, \
100 .signature = _signature, \
101 .result = _result, \
102 .handler = _handler, \
103 .offset = _offset, \
104 }, \
105 }, \
106 }
107 #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags) \
108 SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, 0, _flags)
109
110 #define SD_BUS_SIGNAL(_member, _signature, _flags) \
111 { \
112 .type = _SD_BUS_VTABLE_SIGNAL, \
113 .flags = _flags, \
114 .x = { \
115 .signal = { \
116 .member = _member, \
117 .signature = _signature, \
118 }, \
119 }, \
120 }
121
122 #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \
123 { \
124 .type = _SD_BUS_VTABLE_PROPERTY, \
125 .flags = _flags, \
126 .x = { \
127 .property = { \
128 .member = _member, \
129 .signature = _signature, \
130 .get = _get, \
131 .set = NULL, \
132 .offset = _offset, \
133 }, \
134 }, \
135 }
136
137 #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \
138 { \
139 .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \
140 .flags = _flags, \
141 .x = { \
142 .property = { \
143 .member = _member, \
144 .signature = _signature, \
145 .get = _get, \
146 .set = _set, \
147 .offset = _offset, \
148 }, \
149 }, \
150 }
151
152 #define SD_BUS_VTABLE_END \
153 { \
154 .type = _SD_BUS_VTABLE_END, \
155 .flags = 0, \
156 .x = { { 0 } }, \
157 }
158
159 _SD_END_DECLARATIONS;
160
161 #endif