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