1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include "bus-locator.h"
4 #include "macro.h"
5 
6 const BusLocator* const bus_home_mgr = &(BusLocator){
7         .destination = "org.freedesktop.home1",
8         .path = "/org/freedesktop/home1",
9         .interface = "org.freedesktop.home1.Manager",
10 };
11 
12 const BusLocator* const bus_import_mgr = &(BusLocator){
13         .destination ="org.freedesktop.import1",
14         .path = "/org/freedesktop/import1",
15         .interface = "org.freedesktop.import1.Manager"
16 };
17 
18 const BusLocator* const bus_locale = &(BusLocator){
19         .destination = "org.freedesktop.locale1",
20         .path = "/org/freedesktop/locale1",
21         .interface = "org.freedesktop.locale1"
22 };
23 
24 const BusLocator* const bus_login_mgr = &(BusLocator){
25         .destination = "org.freedesktop.login1",
26         .path = "/org/freedesktop/login1",
27         .interface = "org.freedesktop.login1.Manager"
28 };
29 
30 const BusLocator* const bus_machine_mgr = &(BusLocator){
31         .destination ="org.freedesktop.machine1",
32         .path = "/org/freedesktop/machine1",
33         .interface = "org.freedesktop.machine1.Manager"
34 };
35 
36 const BusLocator* const bus_network_mgr = &(BusLocator){
37         .destination = "org.freedesktop.network1",
38         .path = "/org/freedesktop/network1",
39         .interface = "org.freedesktop.network1.Manager"
40 };
41 
42 const BusLocator* const bus_portable_mgr = &(BusLocator){
43         .destination = "org.freedesktop.portable1",
44         .path = "/org/freedesktop/portable1",
45         .interface = "org.freedesktop.portable1.Manager"
46 };
47 
48 const BusLocator* const bus_resolve_mgr = &(BusLocator){
49         .destination = "org.freedesktop.resolve1",
50         .path = "/org/freedesktop/resolve1",
51         .interface = "org.freedesktop.resolve1.Manager"
52 };
53 
54 const BusLocator* const bus_systemd_mgr = &(BusLocator){
55         .destination = "org.freedesktop.systemd1",
56         .path = "/org/freedesktop/systemd1",
57         .interface = "org.freedesktop.systemd1.Manager"
58 };
59 
60 const BusLocator* const bus_timedate = &(BusLocator){
61         .destination = "org.freedesktop.timedate1",
62         .path = "/org/freedesktop/timedate1",
63         .interface = "org.freedesktop.timedate1"
64 };
65 
66 /* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface strings encapsulated
67  * within a single struct. */
bus_call_method_async(sd_bus * bus,sd_bus_slot ** slot,const BusLocator * locator,const char * member,sd_bus_message_handler_t callback,void * userdata,const char * types,...)68 int bus_call_method_async(
69                 sd_bus *bus,
70                 sd_bus_slot **slot,
71                 const BusLocator *locator,
72                 const char *member,
73                 sd_bus_message_handler_t callback,
74                 void *userdata,
75                 const char *types, ...) {
76 
77         va_list ap;
78         int r;
79 
80         assert(locator);
81 
82         va_start(ap, types);
83         r = sd_bus_call_method_asyncv(bus, slot, locator->destination, locator->path, locator->interface, member, callback, userdata, types, ap);
84         va_end(ap);
85 
86         return r;
87 }
88 
bus_call_method(sd_bus * bus,const BusLocator * locator,const char * member,sd_bus_error * error,sd_bus_message ** reply,const char * types,...)89 int bus_call_method(
90                 sd_bus *bus,
91                 const BusLocator *locator,
92                 const char *member,
93                 sd_bus_error *error,
94                 sd_bus_message **reply,
95                 const char *types, ...) {
96 
97         va_list ap;
98         int r;
99 
100         assert(locator);
101 
102         va_start(ap, types);
103         r = sd_bus_call_methodv(bus, locator->destination, locator->path, locator->interface, member, error, reply, types, ap);
104         va_end(ap);
105 
106         return r;
107 }
108 
bus_get_property(sd_bus * bus,const BusLocator * locator,const char * member,sd_bus_error * error,sd_bus_message ** reply,const char * type)109 int bus_get_property(
110                 sd_bus *bus,
111                 const BusLocator *locator,
112                 const char *member,
113                 sd_bus_error *error,
114                 sd_bus_message **reply,
115                 const char *type) {
116 
117         assert(locator);
118 
119         return sd_bus_get_property(bus, locator->destination, locator->path, locator->interface, member, error, reply, type);
120 }
121 
bus_get_property_trivial(sd_bus * bus,const BusLocator * locator,const char * member,sd_bus_error * error,char type,void * ptr)122 int bus_get_property_trivial(
123                 sd_bus *bus,
124                 const BusLocator *locator,
125                 const char *member,
126                 sd_bus_error *error,
127                 char type, void *ptr) {
128 
129         assert(locator);
130 
131         return sd_bus_get_property_trivial(bus, locator->destination, locator->path, locator->interface, member, error, type, ptr);
132 }
133 
bus_get_property_string(sd_bus * bus,const BusLocator * locator,const char * member,sd_bus_error * error,char ** ret)134 int bus_get_property_string(
135                 sd_bus *bus,
136                 const BusLocator *locator,
137                 const char *member,
138                 sd_bus_error *error,
139                 char **ret) {
140 
141         assert(locator);
142 
143         return sd_bus_get_property_string(bus, locator->destination, locator->path, locator->interface, member, error, ret);
144 }
145 
bus_get_property_strv(sd_bus * bus,const BusLocator * locator,const char * member,sd_bus_error * error,char *** ret)146 int bus_get_property_strv(
147                 sd_bus *bus,
148                 const BusLocator *locator,
149                 const char *member,
150                 sd_bus_error *error,
151                 char ***ret) {
152 
153         assert(locator);
154 
155         return sd_bus_get_property_strv(bus, locator->destination, locator->path, locator->interface, member, error, ret);
156 }
157 
bus_set_property(sd_bus * bus,const BusLocator * locator,const char * member,sd_bus_error * error,const char * type,...)158 int bus_set_property(
159                 sd_bus *bus,
160                 const BusLocator *locator,
161                 const char *member,
162                 sd_bus_error *error,
163                 const char *type, ...) {
164 
165         va_list ap;
166         int r;
167 
168         assert(locator);
169 
170         va_start(ap, type);
171         r = sd_bus_set_propertyv(bus, locator->destination, locator->path, locator->interface, member, error, type, ap);
172         va_end(ap);
173 
174         return r;
175 }
176 
bus_match_signal(sd_bus * bus,sd_bus_slot ** ret,const BusLocator * locator,const char * member,sd_bus_message_handler_t callback,void * userdata)177 int bus_match_signal(
178                 sd_bus *bus,
179                 sd_bus_slot **ret,
180                 const BusLocator *locator,
181                 const char *member,
182                 sd_bus_message_handler_t callback,
183                 void *userdata) {
184 
185         assert(locator);
186 
187         return sd_bus_match_signal(bus, ret, locator->destination, locator->path, locator->interface, member, callback, userdata);
188 }
189 
bus_match_signal_async(sd_bus * bus,sd_bus_slot ** ret,const BusLocator * locator,const char * member,sd_bus_message_handler_t callback,sd_bus_message_handler_t install_callback,void * userdata)190 int bus_match_signal_async(
191                 sd_bus *bus,
192                 sd_bus_slot **ret,
193                 const BusLocator *locator,
194                 const char *member,
195                 sd_bus_message_handler_t callback,
196                 sd_bus_message_handler_t install_callback,
197                 void *userdata) {
198 
199         assert(locator);
200 
201         return sd_bus_match_signal_async(bus, ret, locator->destination, locator->path, locator->interface, member, callback, install_callback, userdata);
202 }
203 
bus_message_new_method_call(sd_bus * bus,sd_bus_message ** m,const BusLocator * locator,const char * member)204 int bus_message_new_method_call(
205                 sd_bus *bus,
206                 sd_bus_message **m,
207                 const BusLocator *locator,
208                 const char *member) {
209 
210         assert(locator);
211 
212         return sd_bus_message_new_method_call(bus, m, locator->destination, locator->path, locator->interface, member);
213 }
214