]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
29ddb38f LP |
2 | #ifndef foosdbusvtablehfoo |
3 | #define foosdbusvtablehfoo | |
4 | ||
5 | /*** | |
29ddb38f LP |
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 | ||
0095c454 LP |
20 | #include "_sd-common.h" |
21 | ||
22 | _SD_BEGIN_DECLARATIONS; | |
6695ed7a | 23 | |
29ddb38f LP |
24 | typedef struct sd_bus_vtable sd_bus_vtable; |
25 | ||
26 | #include "sd-bus.h" | |
27 | ||
28 | enum { | |
adacb957 LP |
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', | |
e0c0b07d | 34 | _SD_BUS_VTABLE_WRITABLE_PROPERTY = 'W' |
29ddb38f LP |
35 | }; |
36 | ||
37 | enum { | |
df98a87b LP |
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, | |
33702051 | 45 | SD_BUS_VTABLE_PROPERTY_EXPLICIT = 1ULL << 7, |
7a77d2a4 | 46 | SD_BUS_VTABLE_SENSITIVE = 1ULL << 8, /* covers both directions: method call + reply */ |
df98a87b | 47 | _SD_BUS_VTABLE_CAPABILITY_MASK = 0xFFFFULL << 40 |
29ddb38f LP |
48 | }; |
49 | ||
adacb957 LP |
50 | #define SD_BUS_VTABLE_CAPABILITY(x) ((uint64_t) (((x)+1) & 0xFFFF) << 40) |
51 | ||
856ad2a8 GC |
52 | enum { |
53 | _SD_BUS_VTABLE_PARAM_NAMES = 1 << 0, | |
54 | }; | |
55 | ||
8dd8a286 ZJS |
56 | extern const unsigned sd_bus_object_vtable_format; |
57 | ||
5238e957 BB |
58 | /* Note: unused areas in the sd_bus_vtable[] array must be initialized to 0. The structure contains an embedded |
59 | * union, and the compiler is NOT required to initialize the unused areas of the union when the rest of the | |
60 | * structure is initialized. Normally the array is defined as read-only data, in which case the linker places | |
61 | * it in the BSS section, which is always fully initialized, so this is not a concern. But if the array is | |
62 | * created on the stack or on the heap, care must be taken to initialize the unused areas, for examply by | |
8dd8a286 ZJS |
63 | * first memsetting the whole region to zero before filling the data in. */ |
64 | ||
29ddb38f LP |
65 | struct sd_bus_vtable { |
66 | /* Please do not initialize this structure directly, use the | |
67 | * macros below instead */ | |
68 | ||
adacb957 LP |
69 | uint8_t type:8; |
70 | uint64_t flags:56; | |
29ddb38f LP |
71 | union { |
72 | struct { | |
73 | size_t element_size; | |
856ad2a8 | 74 | uint64_t features; |
8dd8a286 | 75 | const unsigned *vtable_format_reference; |
29ddb38f LP |
76 | } start; |
77 | struct { | |
78 | const char *member; | |
79 | const char *signature; | |
80 | const char *result; | |
81 | sd_bus_message_handler_t handler; | |
09c8a7c6 | 82 | size_t offset; |
856ad2a8 | 83 | const char *names; |
29ddb38f LP |
84 | } method; |
85 | struct { | |
86 | const char *member; | |
87 | const char *signature; | |
856ad2a8 | 88 | const char *names; |
29ddb38f LP |
89 | } signal; |
90 | struct { | |
91 | const char *member; | |
92 | const char *signature; | |
93 | sd_bus_property_get_t get; | |
94 | sd_bus_property_set_t set; | |
95 | size_t offset; | |
96 | } property; | |
77a874a3 | 97 | } x; |
29ddb38f LP |
98 | }; |
99 | ||
100 | #define SD_BUS_VTABLE_START(_flags) \ | |
101 | { \ | |
102 | .type = _SD_BUS_VTABLE_START, \ | |
103 | .flags = _flags, \ | |
aa328850 KK |
104 | .x = { \ |
105 | .start = { \ | |
856ad2a8 | 106 | .element_size = sizeof(sd_bus_vtable), \ |
8dd8a286 ZJS |
107 | .features = _SD_BUS_VTABLE_PARAM_NAMES, \ |
108 | .vtable_format_reference = &sd_bus_object_vtable_format, \ | |
aa328850 KK |
109 | }, \ |
110 | }, \ | |
29ddb38f LP |
111 | } |
112 | ||
856ad2a8 GC |
113 | /* helper macro to format method and signal parameters, one at a time */ |
114 | #define SD_BUS_PARAM(x) #x "\0" | |
115 | ||
116 | #define SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, _in_names, _result, _out_names, _handler, _offset, _flags) \ | |
29ddb38f LP |
117 | { \ |
118 | .type = _SD_BUS_VTABLE_METHOD, \ | |
119 | .flags = _flags, \ | |
aa328850 KK |
120 | .x = { \ |
121 | .method = { \ | |
122 | .member = _member, \ | |
123 | .signature = _signature, \ | |
124 | .result = _result, \ | |
125 | .handler = _handler, \ | |
126 | .offset = _offset, \ | |
856ad2a8 | 127 | .names = _in_names _out_names, \ |
aa328850 KK |
128 | }, \ |
129 | }, \ | |
29ddb38f | 130 | } |
856ad2a8 GC |
131 | #define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \ |
132 | SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, "", _result, "", _handler, _offset, _flags) | |
133 | #define SD_BUS_METHOD_WITH_NAMES(_member, _signature, _in_names, _result, _out_names, _handler, _flags) \ | |
134 | SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, _in_names, _result, _out_names, _handler, 0, _flags) | |
09c8a7c6 | 135 | #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags) \ |
856ad2a8 | 136 | SD_BUS_METHOD_WITH_NAMES_OFFSET(_member, _signature, "", _result, "", _handler, 0, _flags) |
29ddb38f | 137 | |
856ad2a8 | 138 | #define SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, _out_names, _flags) \ |
29ddb38f LP |
139 | { \ |
140 | .type = _SD_BUS_VTABLE_SIGNAL, \ | |
141 | .flags = _flags, \ | |
aa328850 KK |
142 | .x = { \ |
143 | .signal = { \ | |
144 | .member = _member, \ | |
145 | .signature = _signature, \ | |
856ad2a8 | 146 | .names = _out_names, \ |
aa328850 KK |
147 | }, \ |
148 | }, \ | |
29ddb38f | 149 | } |
856ad2a8 GC |
150 | #define SD_BUS_SIGNAL(_member, _signature, _flags) \ |
151 | SD_BUS_SIGNAL_WITH_NAMES(_member, _signature, "", _flags) | |
29ddb38f | 152 | |
77a874a3 | 153 | #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \ |
29ddb38f LP |
154 | { \ |
155 | .type = _SD_BUS_VTABLE_PROPERTY, \ | |
156 | .flags = _flags, \ | |
aa328850 KK |
157 | .x = { \ |
158 | .property = { \ | |
159 | .member = _member, \ | |
160 | .signature = _signature, \ | |
161 | .get = _get, \ | |
cc9daff2 | 162 | .set = NULL, \ |
aa328850 KK |
163 | .offset = _offset, \ |
164 | }, \ | |
165 | }, \ | |
29ddb38f LP |
166 | } |
167 | ||
168 | #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \ | |
169 | { \ | |
170 | .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY, \ | |
171 | .flags = _flags, \ | |
aa328850 KK |
172 | .x = { \ |
173 | .property = { \ | |
174 | .member = _member, \ | |
175 | .signature = _signature, \ | |
176 | .get = _get, \ | |
177 | .set = _set, \ | |
178 | .offset = _offset, \ | |
179 | }, \ | |
180 | }, \ | |
29ddb38f LP |
181 | } |
182 | ||
183 | #define SD_BUS_VTABLE_END \ | |
184 | { \ | |
185 | .type = _SD_BUS_VTABLE_END, \ | |
cc9daff2 | 186 | .flags = 0, \ |
d579a56c | 187 | .x = { { 0 } }, \ |
29ddb38f LP |
188 | } |
189 | ||
0095c454 | 190 | _SD_END_DECLARATIONS; |
6695ed7a | 191 | |
29ddb38f | 192 | #endif |