]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemd/sd-bus-vtable.h
Merge pull request #11827 from keszybz/pkgconfig-variables
[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 enum {
52 _SD_BUS_VTABLE_PARAM_NAMES = 1 << 0,
53 };
54
55 struct sd_bus_vtable {
56 /* Please do not initialize this structure directly, use the
57 * macros below instead */
58
59 uint8_t type:8;
60 uint64_t flags:56;
61 union {
62 struct {
63 size_t element_size;
64 uint64_t features;
65 } start;
66 struct {
67 const char *member;
68 const char *signature;
69 const char *result;
70 sd_bus_message_handler_t handler;
71 size_t offset;
72 const char *names;
73 } method;
74 struct {
75 const char *member;
76 const char *signature;
77 const char *names;
78 } signal;
79 struct {
80 const char *member;
81 const char *signature;
82 sd_bus_property_get_t get;
83 sd_bus_property_set_t set;
84 size_t offset;
85 } property;
86 } x;
87 };
88
89 #define SD_BUS_VTABLE_START(_flags) \
90 { \
91 .type = _SD_BUS_VTABLE_START, \
92 .flags = _flags, \
93 .x = { \
94 .start = { \
95 .element_size = sizeof(sd_bus_vtable), \
96 .features = _SD_BUS_VTABLE_PARAM_NAMES \
97 }, \
98 }, \
99 }
100
101 /* helper macro to format method and signal parameters, one at a time */
102 #define SD_BUS_PARAM(x) #x "\0"
103
104 #define SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, _in_names, _result, _out_names, _handler, _offset, _flags) \
105 { \
106 .type = _SD_BUS_VTABLE_METHOD, \
107 .flags = _flags, \
108 .x = { \
109 .method = { \
110 .member = _member, \
111 .signature = _signature, \
112 .result = _result, \
113 .handler = _handler, \
114 .offset = _offset, \
115 .names = _in_names _out_names, \
116 }, \
117 }, \
118 }
119 #define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \
120 SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, "", _result, "", _handler, _offset, _flags)
121 #define SD_BUS_METHOD_WITH_NAMES(_member, _signature, _in_names, _result, _out_names, _handler, _flags) \
122 SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, _in_names, _result, _out_names, _handler, 0, _flags)
123 #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags) \
124 SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, "", _result, "", _handler, 0, _flags)
125
126 #define SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, _out_names, _flags) \
127 { \
128 .type = _SD_BUS_VTABLE_SIGNAL, \
129 .flags = _flags, \
130 .x = { \
131 .signal = { \
132 .member = _member, \
133 .signature = _signature, \
134 .names = _out_names, \
135 }, \
136 }, \
137 }
138 #define SD_BUS_SIGNAL(_member, _signature, _flags) \
139 SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, "", _flags)
140
141 #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \
142 { \
143 .type = _SD_BUS_VTABLE_PROPERTY, \
144 .flags = _flags, \
145 .x = { \
146 .property = { \
147 .member = _member, \
148 .signature = _signature, \
149 .get = _get, \
150 .set = NULL, \
151 .offset = _offset, \
152 }, \
153 }, \
154 }
155
156 #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \
157 { \
158 .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \
159 .flags = _flags, \
160 .x = { \
161 .property = { \
162 .member = _member, \
163 .signature = _signature, \
164 .get = _get, \
165 .set = _set, \
166 .offset = _offset, \
167 }, \
168 }, \
169 }
170
171 #define SD_BUS_VTABLE_END \
172 { \
173 .type = _SD_BUS_VTABLE_END, \
174 .flags = 0, \
175 .x = { { 0 } }, \
176 }
177
178 _SD_END_DECLARATIONS;
179
180 #endif