Remove unused gdbus APIs based on char string
[platform/core/system/libsyscommon.git] / src / libgdbus / dbus-system.h
1 /*
2  * libsyscommon
3  *
4  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 #ifndef __DBUS_SYSTEM_H__
20 #define __DBUS_SYSTEM_H__
21
22 #include <glib.h>
23 #include <gio/gio.h>
24 #include <glib-unix.h>
25 #include <gio/gunixfdlist.h>
26 #include <stdarg.h>
27 #include <assert.h>
28
29 #include "dbus-system-iface.h"
30
31 typedef struct {
32         const unsigned char *data;
33         int size;
34 } dbus_byte;
35
36
37 typedef void *dbus_handle_h;
38
39 typedef void *dbus_object_handle_h;
40
41 typedef struct {
42         const char *member;
43         const char *signature_in;
44         const char *signature_out;
45         GVariant *(*func)       (GDBusConnection *conn,
46                                 const gchar *sender,
47                                 const gchar *path,
48                                 const gchar *iface,
49                                 const gchar *name,
50                                 GVariant *param,
51                                 GDBusMethodInvocation *invocation,
52                                 gpointer user_data);
53 } dbus_method_s;
54
55 typedef struct {
56         dbus_object_handle_h oh;
57         const char *name;
58         const dbus_method_s *methods;
59         int nr_methods;
60 } dbus_interface_u;
61
62 typedef struct {
63         guint   pid;
64         guint   uid;
65         gchar  *unique_name;
66         gchar  *sec_label;
67 } GDBusCredentials;
68
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)
70
71 #define dbus_handle_new_g_variant_tuple() g_variant_new_tuple(NULL, 0)
72
73 typedef void (*destroy_notified)(void *data);
74
75 typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err);
76
77 typedef struct {
78         dbus_pending_cb func;
79         void *data;
80 } pending_call_data;
81
82 dbus_handle_h dbus_handle_get_connection        (GBusType bus_type,
83                                                 gboolean priv);
84
85 int dbus_handle_request_bus_name                (dbus_handle_h handle,
86                                                 const char *bus_name,
87                                                 GBusNameAcquiredCallback acquired_handler,
88                                                 GBusNameLostCallback lost_handler);
89
90 int dbus_handle_register_dbus_object            (dbus_handle_h handle,
91                                                 const char *obj_path,
92                                                 const dbus_interface_u *iface);
93
94 int dbus_handle_unregister_dbus_object          (dbus_handle_h handle,
95                                                 const char *obj_path);
96
97 int dbus_handle_add_dbus_object                 (dbus_handle_h handle,
98                                                 const char *obj_path,
99                                                 const dbus_interface_u *iface_u);
100
101 int dbus_handle_register_dbus_object_all        (dbus_handle_h handle);
102
103 int dbus_handle_method_sync_var                 (const char *dest,
104                                                 const char *path,
105                                                 const char *iface,
106                                                 const char *method,
107                                                 GVariant *param);
108
109 int dbus_handle_method_async_var                (const char *dest,
110                                                 const char *path,
111                                                 const char *iface,
112                                                 const char *method,
113                                                 GVariant *param);
114
115 int dbus_handle_method_async_with_reply_var     (const char *dest,
116                                                 const char *path,
117                                                 const char *iface,
118                                                 const char *method,
119                                                 GVariant *param,
120                                                 dbus_pending_cb cb,
121                                                 int timeout_msec,
122                                                 void *data);
123
124 GVariant *dbus_handle_method_sync_with_reply_var                (const char *dest,
125                                                                 const char *path,
126                                                                 const char *iface,
127                                                                 const char *method,
128                                                                 GVariant *var);
129
130 GVariant *dbus_handle_method_sync_with_reply_var_timeout        (const char *dest,
131                                                                 const char *path,
132                                                                 const char *iface,
133                                                                 const char *method,
134                                                                 GVariant *var,
135                                                                 int timeout);
136
137 gint* dbus_handle_get_unix_fd_list                              (GDBusMethodInvocation *invocation,
138                                                                 int *size);
139
140 GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest,
141                                                                 const char *path,
142                                                                 const char *iface,
143                                                                 const char *method,
144                                                                 GVariant *param,
145                                                                 int *in_fdlist,
146                                                                 int in_size,
147                                                                 int **out_fdlist,
148                                                                 int *out_size);
149
150
151 guint subscribe_dbus_signal                     (dbus_handle_h handle,
152                                                 const char *path,
153                                                 const char *iface,
154                                                 const char *name,
155                                                 GDBusSignalCallback cb,
156                                                 void *data,
157                                                 destroy_notified free_func);
158
159 void unsubscribe_dbus_signal                    (dbus_handle_h handle,
160                                                 guint id);
161
162 int dbus_handle_emit_dbus_signal                (const char *dest,
163                                                 const char *path,
164                                                 const char *iface,
165                                                 const char *name,
166                                                 GVariant *param);
167
168 int dbus_handle_emit_dbus_signal_sync(const char *dest,
169                                         const char *path,
170                                         const char *iface,
171                                         const char *name,
172                                         GVariant *param);
173
174 int dbus_handle_flush_sync(dbus_handle_h handle);
175
176 enum ctx_quit_reason {CTX_QUIT_UNKNOWN, CTX_QUIT_NORMAL, CTX_QUIT_TIMEOUT};
177
178 typedef struct {
179         guint sig_id;
180         GMainContext *context;
181         GMainLoop *loop;
182         GSource *timeout_src;
183         GVariant *param;
184         enum ctx_quit_reason quit_reason;
185         void *user_data;
186 } sig_ctx;
187
188 sig_ctx *dbus_handle_new_signal_ctx             (void);
189
190 void dbus_handle_free_signal_ctx                (sig_ctx *ctx);
191
192 guint subscribe_dbus_signal_ctx                 (dbus_handle_h handle,
193                                                 sig_ctx *ctx,
194                                                 const char *sender,
195                                                 const char *path,
196                                                 const char *iface,
197                                                 const char *name,
198                                                 GDBusSignalCallback cb);
199
200 int dbus_handle_signal_ctx_wait                 (sig_ctx *ctx);
201
202 int dbus_handle_signal_ctx_add_timeout          (sig_ctx *ctx,
203                                                 int timeout);
204
205
206
207
208 int dbus_connection_get_sender_pid              (GDBusConnection *conn,
209                                                 const char * sender);
210
211 int dbus_handle_get_sender_pid                  (dbus_handle_h handle,
212                                                 const char * sender);
213
214 int dbus_handle_get_sender_credentials          (dbus_handle_h handle,
215                                                 const char *name,
216                                                 GDBusCredentials *creds);
217
218 int dbus_handle_watch_name                      (const char *name,
219                                                 GBusNameAppearedCallback name_appeared_handler,
220                                                 GBusNameVanishedCallback name_vanished_handler,
221                                                 void *user_data,
222                                                 GDestroyNotify user_data_free_func);
223
224 void dbus_handle_unwatch_name                   (guint id);
225
226 char** dbus_handle_get_owner_list               (dbus_handle_h handle,
227                                                 const char *bus_name);
228
229 void dbus_handle_check_owner_name               (dbus_handle_h handle,
230                                                 const char *owner_name);
231
232 int check_systemd_active                        (void);
233
234 GVariant *dbus_handle_make_simple_array         (const char *sig,
235                                                 int *param);
236
237
238 #endif