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 g_variant_get_safe(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);
103 int dbus_handle_method_sync_var (const char *dest,
109 int dbus_handle_method_async_var (const char *dest,
115 int dbus_handle_method_async_with_reply_var (const char *dest,
124 GVariant *dbus_handle_method_sync_with_reply_var (const char *dest,
130 GVariant *dbus_handle_method_sync_with_reply_var_timeout (const char *dest,
137 gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation,
140 GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest,
151 guint subscribe_dbus_signal (dbus_handle_h handle,
155 GDBusSignalCallback cb,
157 destroy_notified free_func);
159 void unsubscribe_dbus_signal (dbus_handle_h handle,
162 int dbus_handle_emit_dbus_signal (const char *dest,
168 int dbus_handle_emit_dbus_signal_sync(const char *dest,
174 int dbus_handle_flush_sync(dbus_handle_h handle);
176 enum ctx_quit_reason {CTX_QUIT_UNKNOWN, CTX_QUIT_NORMAL, CTX_QUIT_TIMEOUT};
180 GMainContext *context;
182 GSource *timeout_src;
184 enum ctx_quit_reason quit_reason;
188 sig_ctx *dbus_handle_new_signal_ctx (void);
190 void dbus_handle_free_signal_ctx (sig_ctx *ctx);
192 guint subscribe_dbus_signal_ctx (dbus_handle_h handle,
198 GDBusSignalCallback cb);
200 int dbus_handle_signal_ctx_wait (sig_ctx *ctx);
202 int dbus_handle_signal_ctx_add_timeout (sig_ctx *ctx,
208 int dbus_connection_get_sender_pid (GDBusConnection *conn,
209 const char * sender);
211 int dbus_handle_get_sender_pid (dbus_handle_h handle,
212 const char * sender);
214 int dbus_handle_get_sender_credentials (dbus_handle_h handle,
216 GDBusCredentials *creds);
218 int dbus_handle_watch_name (const char *name,
219 GBusNameAppearedCallback name_appeared_handler,
220 GBusNameVanishedCallback name_vanished_handler,
222 GDestroyNotify user_data_free_func);
224 void dbus_handle_unwatch_name (guint id);
226 char** dbus_handle_get_owner_list (dbus_handle_h handle,
227 const char *bus_name);
229 void dbus_handle_check_owner_name (dbus_handle_h handle,
230 const char *owner_name);
232 int check_systemd_active (void);
234 GVariant *dbus_handle_make_simple_array (const char *sig,