chiark / gitweb /
sd-netlink: introduce api for new NL type NLA_FLAG
[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_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.start.element_size = sizeof(sd_bus_vtable),          \
91         }
92
93 #define SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags)   \
94         {                                                               \
95                 .type = _SD_BUS_VTABLE_METHOD,                          \
96                 .flags = _flags,                                        \
97                 .x.method.member = _member,                             \
98                 .x.method.signature = _signature,                       \
99                 .x.method.result = _result,                             \
100                 .x.method.handler = _handler,                           \
101                 .x.method.offset = _offset,                             \
102         }
103 #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags)   \
104         SD_BUS_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, 0, _flags)
105
106 #define SD_BUS_SIGNAL(_member, _signature, _flags)                      \
107         {                                                               \
108                 .type = _SD_BUS_VTABLE_SIGNAL,                          \
109                 .flags = _flags,                                        \
110                 .x.signal.member = _member,                             \
111                 .x.signal.signature = _signature,                       \
112         }
113
114 #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags)     \
115         {                                                               \
116                 .type = _SD_BUS_VTABLE_PROPERTY,                        \
117                 .flags = _flags,                                        \
118                 .x.property.member = _member,                           \
119                 .x.property.signature = _signature,                     \
120                 .x.property.get = _get,                                 \
121                 .x.property.offset = _offset,                           \
122         }
123
124 #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \
125         {                                                               \
126                 .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY,               \
127                 .flags = _flags,                                        \
128                 .x.property.member = _member,                           \
129                 .x.property.signature = _signature,                     \
130                 .x.property.get = _get,                                 \
131                 .x.property.set = _set,                                 \
132                 .x.property.offset = _offset,                           \
133         }
134
135 #define SD_BUS_VTABLE_END                                               \
136         {                                                               \
137                 .type = _SD_BUS_VTABLE_END,                             \
138         }
139
140 _SD_END_DECLARATIONS;
141
142 #endif