chiark / gitweb /
bus: introduce "trusted" bus concept and encode access control in object vtables
[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         _SD_BUS_VTABLE_CHILDREN          = 'C',
41 };
42
43 enum {
44         SD_BUS_VTABLE_DEPRECATED               = 1ULL << 0,
45         SD_BUS_VTABLE_METHOD_NO_REPLY          = 1ULL << 1,
46         SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE    = 1ULL << 2,
47         SD_BUS_VTABLE_PROPERTY_INVALIDATE_ONLY = 1ULL << 3,
48         SD_BUS_VTABLE_UNPRIVILEGED             = 1ULL << 4,
49         _SD_BUS_VTABLE_CAPABILITY_MASK         = 0xFFFFULL << 40
50 };
51
52 #define SD_BUS_VTABLE_CAPABILITY(x) ((uint64_t) (((x)+1) & 0xFFFF) << 40)
53
54 struct sd_bus_vtable {
55         /* Please do not initialize this structure directly, use the
56          * macros below instead */
57
58         uint8_t type:8;
59         uint64_t flags:56;
60         union {
61                 struct {
62                         size_t element_size;
63                 } start;
64                 struct {
65                         const char *member;
66                         const char *signature;
67                         const char *result;
68                         sd_bus_message_handler_t handler;
69                 } method;
70                 struct {
71                         const char *member;
72                         const char *signature;
73                 } signal;
74                 struct {
75                         const char *member;
76                         const char *signature;
77                         sd_bus_property_get_t get;
78                         sd_bus_property_set_t set;
79                         size_t offset;
80                 } property;
81         } x;
82 };
83
84 #define SD_BUS_VTABLE_START(_flags)                                     \
85         {                                                               \
86                 .type = _SD_BUS_VTABLE_START,                           \
87                 .flags = _flags,                                        \
88                 .x.start.element_size = sizeof(sd_bus_vtable),          \
89         }
90
91 #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags)   \
92         {                                                               \
93                 .type = _SD_BUS_VTABLE_METHOD,                          \
94                 .flags = _flags,                                        \
95                 .x.method.member = _member,                             \
96                 .x.method.signature = _signature,                       \
97                 .x.method.result = _result,                             \
98                 .x.method.handler = _handler,                           \
99         }
100
101 #define SD_BUS_SIGNAL(_member, _signature, _flags)                      \
102         {                                                               \
103                 .type = _SD_BUS_VTABLE_SIGNAL,                          \
104                 .flags = _flags,                                        \
105                 .x.signal.member = _member,                             \
106                 .x.signal.signature = _signature,                       \
107         }
108
109 #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags)     \
110         {                                                               \
111                 .type = _SD_BUS_VTABLE_PROPERTY,                        \
112                 .flags = _flags,                                        \
113                 .x.property.member = _member,                           \
114                 .x.property.signature = _signature,                     \
115                 .x.property.get = _get,                                 \
116                 .x.property.offset = _offset,                           \
117         }
118
119 #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \
120         {                                                               \
121                 .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY,               \
122                 .flags = _flags,                                        \
123                 .x.property.member = _member,                           \
124                 .x.property.signature = _signature,                     \
125                 .x.property.get = _get,                                 \
126                 .x.property.set = _set,                                 \
127                 .x.property.offset = _offset,                           \
128         }
129
130 #define SD_BUS_VTABLE_END                                               \
131         {                                                               \
132                 .type = _SD_BUS_VTABLE_END,                             \
133         }
134
135 _SD_END_DECLARATIONS;
136
137 #endif