4 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #ifndef __DBUS_SYSTEM_H__
20 #define __DBUS_SYSTEM_H__
24 #include <glib-unix.h>
25 #include <gio/gunixfdlist.h>
29 #include "dbus-system-iface.h"
32 const unsigned char *data;
37 typedef void *dbus_handle_h;
39 typedef void *dbus_object_handle_h;
43 const char *signature_in;
44 const char *signature_out;
45 GVariant *(*func) (GDBusConnection *conn,
51 GDBusMethodInvocation *invocation,
56 dbus_object_handle_h oh;
58 const dbus_method_s *methods;
69 #define dh_get_param_from_var(gvar, signature, ...) ((g_strcmp0(signature, g_variant_get_type_string(gvar)) == 0) ? g_variant_get(gvar, signature, __VA_ARGS__), TRUE : FALSE)
71 #define dbus_handle_new_g_variant_tuple() g_variant_new_tuple(NULL, 0)
73 typedef void (*destroy_notified)(void *data);
75 typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err);
82 dbus_handle_h dbus_handle_get_connection (GBusType bus_type,
85 int dbus_handle_request_bus_name (dbus_handle_h handle,
87 GBusNameAcquiredCallback acquired_handler,
88 GBusNameLostCallback lost_handler);
90 int dbus_handle_register_dbus_object (dbus_handle_h handle,
92 const dbus_interface_u *iface);
94 int dbus_handle_unregister_dbus_object (dbus_handle_h handle,
95 const char *obj_path);
97 int dbus_handle_add_dbus_object (dbus_handle_h handle,
99 const dbus_interface_u *iface_u);
101 int dbus_handle_register_dbus_object_all (dbus_handle_h handle);
104 int dbus_handle_method_sync (const char *dest,
106 const char *interface,
109 const char *param[]);
111 int dbus_handle_method_sync_var (const char *dest,
117 int dbus_handle_method_sync_timeout (const char *dest,
119 const char *interface,
125 int dbus_handle_method_sync_pairs (const char *dest,
127 const char *interface,
132 int dbus_handle_method_async_pairs (const char *dest,
134 const char *interface,
139 int dbus_handle_method_async (const char *dest,
141 const char *interface,
144 const char *param[]);
146 int dbus_handle_method_async_var (const char *dest,
152 int dbus_handle_method_async_with_reply (const char *dest,
156 const char *signature,
162 int dbus_handle_method_async_with_reply_var (const char *dest,
171 int dbus_handle_method_async_pairs_with_reply (const char *dest,
181 GVariant *dbus_handle_method_sync_with_reply_var (const char *dest,
187 GVariant *dbus_handle_method_sync_with_reply_var_timeout (const char *dest,
194 gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation,
197 GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply (const char *dest,
201 const char *signature,
208 GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest,
219 guint subscribe_dbus_signal (dbus_handle_h handle,
223 GDBusSignalCallback cb,
225 destroy_notified free_func);
227 void unsubscribe_dbus_signal (dbus_handle_h handle,
230 int dbus_handle_emit_dbus_signal (const char *dest,
236 int dbus_handle_emit_dbus_signal_sync(const char *dest,
242 int dbus_handle_flush_sync(dbus_handle_h handle);
244 enum ctx_quit_reason {CTX_QUIT_UNKNOWN, CTX_QUIT_NORMAL, CTX_QUIT_TIMEOUT};
248 GMainContext *context;
250 GSource *timeout_src;
252 enum ctx_quit_reason quit_reason;
256 sig_ctx *dbus_handle_new_signal_ctx (void);
258 void dbus_handle_free_signal_ctx (sig_ctx *ctx);
260 guint subscribe_dbus_signal_ctx (dbus_handle_h handle,
266 GDBusSignalCallback cb);
268 int dbus_handle_signal_ctx_wait (sig_ctx *ctx);
270 int dbus_handle_signal_ctx_add_timeout (sig_ctx *ctx,
276 int dbus_connection_get_sender_pid (GDBusConnection *conn,
277 const char * sender);
279 int dbus_handle_get_sender_pid (dbus_handle_h handle,
280 const char * sender);
282 int dbus_handle_get_sender_credentials (dbus_handle_h handle,
284 GDBusCredentials *creds);
286 int dbus_handle_watch_name (const char *name,
287 GBusNameAppearedCallback name_appeared_handler,
288 GBusNameVanishedCallback name_vanished_handler,
290 GDestroyNotify user_data_free_func);
292 void dbus_handle_unwatch_name (guint id);
294 char** dbus_handle_get_owner_list (dbus_handle_h handle,
295 const char *bus_name);
297 void dbus_handle_check_owner_name (dbus_handle_h handle,
298 const char *owner_name);
300 int check_systemd_active (void);
302 GVariant *dbus_handle_make_simple_array (const char *sig,