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