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