]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/systemd/sd-bus-vtable.h
Merge pull request #712 from daurnimator/577-sd_bus-vtable-methods-do-not-have-offset
[thirdparty/systemd.git] / src / systemd / sd-bus-vtable.h
CommitLineData
29ddb38f
LP
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
0095c454
LP
25#include "_sd-common.h"
26
27_SD_BEGIN_DECLARATIONS;
6695ed7a 28
29ddb38f
LP
29typedef struct sd_bus_vtable sd_bus_vtable;
30
31#include "sd-bus.h"
32
33enum {
adacb957
LP
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',
29ddb38f 39 _SD_BUS_VTABLE_WRITABLE_PROPERTY = 'W',
29ddb38f
LP
40};
41
42enum {
df98a87b
LP
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
29ddb38f
LP
51};
52
adacb957
LP
53#define SD_BUS_VTABLE_CAPABILITY(x) ((uint64_t) (((x)+1) & 0xFFFF) << 40)
54
29ddb38f
LP
55struct sd_bus_vtable {
56 /* Please do not initialize this structure directly, use the
57 * macros below instead */
58
adacb957
LP
59 uint8_t type:8;
60 uint64_t flags:56;
29ddb38f
LP
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;
09c8a7c6 70 size_t offset;
29ddb38f
LP
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;
77a874a3 83 } x;
29ddb38f
LP
84};
85
86#define SD_BUS_VTABLE_START(_flags) \
87 { \
88 .type = _SD_BUS_VTABLE_START, \
89 .flags = _flags, \
77a874a3 90 .x.start.element_size = sizeof(sd_bus_vtable), \
29ddb38f
LP
91 }
92
09c8a7c6 93#define SD_BUS_VTABLE_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, _offset, _flags) \
29ddb38f
LP
94 { \
95 .type = _SD_BUS_VTABLE_METHOD, \
96 .flags = _flags, \
77a874a3
LP
97 .x.method.member = _member, \
98 .x.method.signature = _signature, \
99 .x.method.result = _result, \
100 .x.method.handler = _handler, \
09c8a7c6 101 .x.method.offset = _offset, \
29ddb38f 102 }
09c8a7c6 103#define SD_BUS_METHOD(_member, _signature, _result, _handler, _flags) \
104 SD_BUS_VTABLE_METHOD_WITH_OFFSET(_member, _signature, _result, _handler, 0, _flags)
29ddb38f
LP
105
106#define SD_BUS_SIGNAL(_member, _signature, _flags) \
107 { \
108 .type = _SD_BUS_VTABLE_SIGNAL, \
109 .flags = _flags, \
77a874a3
LP
110 .x.signal.member = _member, \
111 .x.signal.signature = _signature, \
29ddb38f
LP
112 }
113
77a874a3 114#define SD_BUS_PROPERTY(_member, _signature, _get, _offset, _flags) \
29ddb38f
LP
115 { \
116 .type = _SD_BUS_VTABLE_PROPERTY, \
117 .flags = _flags, \
77a874a3
LP
118 .x.property.member = _member, \
119 .x.property.signature = _signature, \
120 .x.property.get = _get, \
121 .x.property.offset = _offset, \
29ddb38f
LP
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, \
77a874a3
LP
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, \
29ddb38f
LP
133 }
134
135#define SD_BUS_VTABLE_END \
136 { \
137 .type = _SD_BUS_VTABLE_END, \
138 }
139
0095c454 140_SD_END_DECLARATIONS;
6695ed7a 141
29ddb38f 142#endif