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