chiark / gitweb /
bus: properly return an error when we detect a method call timeout
[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_HIDDEN                   = 1ULL << 5,
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                 } method;
71                 struct {
72                         const char *member;
73                         const char *signature;
74                 } signal;
75                 struct {
76                         const char *member;
77                         const char *signature;
78                         sd_bus_property_get_t get;
79                         sd_bus_property_set_t set;
80                         size_t offset;
81                 } property;
82         } x;
83 };
84
85 #define SD_BUS_VTABLE_START(_flags)                                     \
86         {                                                               \
87                 .type = _SD_BUS_VTABLE_START,                           \
88                 .flags = _flags,                                        \
89                 .x.start.element_size = sizeof(sd_bus_vtable),          \
90         }
91
92 #define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags)   \
93         {                                                               \
94                 .type = _SD_BUS_VTABLE_METHOD,                          \
95                 .flags = _flags,                                        \
96                 .x.method.member = _member,                             \
97                 .x.method.signature = _signature,                       \
98                 .x.method.result = _result,                             \
99                 .x.method.handler = _handler,                           \
100         }
101
102 #define SD_BUS_SIGNAL(_member, _signature, _flags)                      \
103         {                                                               \
104                 .type = _SD_BUS_VTABLE_SIGNAL,                          \
105                 .flags = _flags,                                        \
106                 .x.signal.member = _member,                             \
107                 .x.signal.signature = _signature,                       \
108         }
109
110 #define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags)     \
111         {                                                               \
112                 .type = _SD_BUS_VTABLE_PROPERTY,                        \
113                 .flags = _flags,                                        \
114                 .x.property.member = _member,                           \
115                 .x.property.signature = _signature,                     \
116                 .x.property.get = _get,                                 \
117                 .x.property.offset = _offset,                           \
118         }
119
120 #define SD_BUS_WRITABLE_PROPERTY(_member, _signature, _get, _set, _offset, _flags) \
121         {                                                               \
122                 .type = _SD_BUS_VTABLE_WRITABLE_PROPERTY,               \
123                 .flags = _flags,                                        \
124                 .x.property.member = _member,                           \
125                 .x.property.signature = _signature,                     \
126                 .x.property.get = _get,                                 \
127                 .x.property.set = _set,                                 \
128                 .x.property.offset = _offset,                           \
129         }
130
131 #define SD_BUS_VTABLE_END                                               \
132         {                                                               \
133                 .type = _SD_BUS_VTABLE_END,                             \
134         }
135
136 _SD_END_DECLARATIONS;
137
138 #endif