From ff1dc2218bb7a5b3fd8539d2da2c2b5168d6faf3 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 1 Jun 2018 11:20:13 +0900 Subject: [PATCH 01/16] Remove unused dbus path and interface Change-Id: I5fcfd3a6d6c86dad94522e09ceaf224ddd73c3d9 Signed-off-by: pr.jung --- src/libgdbus/dbus-system.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 126e12a..9e1af14 100755 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -92,18 +92,12 @@ #define DEVICED_INTERFACE_SDE DEVICED_INTERFACE_NAME".sde" #define DEVICED_PATH_ODE DEVICED_OBJECT_PATH"/Ode" #define DEVICED_INTERFACE_ODE DEVICED_INTERFACE_NAME".ode" -/* Lowmem service: get critical low status operations about Lowmem */ -#define DEVICED_PATH_LOWMEM DEVICED_OBJECT_PATH"/Lowmem" -#define DEVICED_INTERFACE_LOWMEM DEVICED_INTERFACE_NAME".lowmem" /* Poweroff service: get power off status operations about Poweroff */ #define DEVICED_PATH_POWEROFF DEVICED_OBJECT_PATH"/PowerOff" #define DEVICED_INTERFACE_POWEROFF DEVICED_INTERFACE_NAME".PowerOff" /* Led service: play/stop led operations about led */ #define DEVICED_PATH_LED DEVICED_OBJECT_PATH"/Led" #define DEVICED_INTERFACE_LED DEVICED_INTERFACE_NAME".Led" -/* MMC service: mount/unmount/format mmc operations about mmc */ -#define DEVICED_PATH_MMC DEVICED_OBJECT_PATH"/Mmc" -#define DEVICED_INTERFACE_MMC DEVICED_INTERFACE_NAME".Mmc" /* Process service: operations about process */ #define DEVICED_PATH_PROCESS DEVICED_OBJECT_PATH"/Process" #define DEVICED_INTERFACE_PROCESS DEVICED_INTERFACE_NAME".Process" -- 2.7.4 From 16ad14d131c8a35f24af060f9ac042f1575c1677 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 21 Jun 2018 16:42:48 +0900 Subject: [PATCH 02/16] Add dbus_handle_method_async_pairs_with_reply dbus_handle_method_async_pairs() is just for no reply and used in deviced and storaged. However, the function has been abnormally used and caused dbus error by unmatched signature between deviced, storaged and system-popup. So, it was replaced by dbus_handle_method_async_with_reply_var(). Change-Id: I5452bdb80dd52e72cc4364ff0ce1cf86490d9822 Signed-off-by: lokilee73 --- src/libgdbus/dbus-system.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/libgdbus/dbus-system.h | 12 ++++++++ 2 files changed, 80 insertions(+) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index de0f02d..79c97e6 100755 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -2287,6 +2287,74 @@ out: free(data); } +int dbus_handle_method_async_pairs_with_reply(const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args, + dbus_pending_cb cb, + int timeout_msec, + void *data) +{ + dbus_handle_s *dh = NULL; + pending_call_data *pdata = NULL; + GVariantBuilder *builder; + char *key, *value; + GVariant *param; + int ret = 0; + + if (!dest || !path || !iface || !method) { + _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); + return -1; + } + + if (timeout_msec < -1) { + _E("wrong timeout %d", timeout_msec); + return -1; + } + + dh = _dbus_handle_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); + return -EPERM; + } + + // dict + builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); + + for (int i = 0 ; i < num ; i = i + 2) { + key = va_arg(args, char *); + value = va_arg(args, char *); + _I("key(%s), value(%s)", key, value); + g_variant_builder_add(builder, "{ss}", key, value); + } + + param = g_variant_new("(a{ss})", builder); + g_variant_builder_unref(builder); + + if (cb) { + pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); + if (!pdata) { + ret = -ENOMEM; + goto err; + } + + pdata->func = cb; + pdata->data = data; + } + g_dbus_connection_call(dh->conn, dest, path, iface, method, + param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout_msec, NULL, + (GAsyncReadyCallback)_cb_pending, + pdata); + + return ret; +err: + if (param) + g_variant_unref(param); + return ret; +} + int dbus_handle_method_async_with_reply(const char *dest, const char *path, const char *iface, diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 9e1af14..9553be5 100755 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -368,9 +368,11 @@ int dbus_handle_method_sync_timeout(const char *dest, const char *path, int dbus_handle_method_sync_pairs(const char *dest, const char *path, const char *interface, const char *method, int num, va_list args); + int dbus_handle_method_async_pairs(const char *dest, const char *path, const char *interface, const char *method, int num, va_list args); + int dbus_handle_method_async(const char *dest, const char *path, const char *interface, const char *method, const char *sig, const char *param[]); @@ -399,6 +401,16 @@ int dbus_handle_method_async_with_reply_var(const char *dest, int timeout_msec, void *data); +int dbus_handle_method_async_pairs_with_reply(const char *dest, + const char *path, + const char *iface, + const char *method, + int num, + va_list args, + dbus_pending_cb cb, + int timeout_msec, + void *data); + int check_systemd_active(void); /** -- 2.7.4 From 18728faa2781c56b67d94eb3f0d7fb72a618185b Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 18 Jul 2018 20:15:29 +0900 Subject: [PATCH 03/16] libgdbus: replace gdbus proxy call with g_dbus_connection_call Replace g_dbus_proxy_call_with_unix_fd_list_sync with g_dbus_connection_call_with_unix_fd_list_sync. gdbus proxy is heavy operation - it makes multiple dbus calls to maintain proxy feature. This functionality is not needed to exchange fd list each other by libgdbus. Change-Id: I5f7b87614eddfd1a79d7aa82332c97dcc5cc6069 Signed-off-by: sanghyeok.oh --- src/libgdbus/dbus-system.c | 55 ++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 79c97e6..42f061b 100755 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1796,7 +1796,6 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, GVariant * var = NULL; GVariant * ret = NULL; dbus_handle_s *dh = NULL; - GDBusProxy *proxy = NULL; GUnixFDList *g_infdlist = NULL; GUnixFDList *g_outfdlist = NULL; @@ -1818,18 +1817,6 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, if (signature && param) var = _append_variant(signature, param); - proxy = g_dbus_proxy_new_sync(dh->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dest, path, iface, NULL, &err); - if (!proxy) { - if (err) { - _E("failed to proxy_new_sync(%s)\n", err->message); - g_error_free(err); - } else { - _E("failed to proxy_new_sync\n"); - if (var) - g_variant_unref(var); - } - } - /* append fd */ if (in_fdlist) { g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); @@ -1841,14 +1828,18 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, //if (g_unix_fd_list_append(g_infdlist, in_fdlist[0], &err) < 0) { } - ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, method, var, G_DBUS_CALL_FLAGS_NONE, -1, - g_infdlist, &g_outfdlist, NULL, &err); + ret = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, + dest, path, iface, method, var, + NULL, G_DBUS_CALL_FLAGS_NONE, + -1, + g_infdlist, &g_outfdlist, + NULL, &err); if (!ret || err) { if (err) { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:%s", err->message); + _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:%s", err->message); g_error_free(err); } else { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:"); + _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:"); if (var) g_variant_unref(var); if (g_infdlist) @@ -1869,8 +1860,6 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, out: if (g_outfdlist) g_object_unref(g_outfdlist); - if (proxy) - g_object_unref(proxy); return ret; } @@ -1888,7 +1877,6 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *d GError *err = NULL; GVariant * ret = NULL; dbus_handle_s *dh = NULL; - GDBusProxy *proxy = NULL; GUnixFDList *g_infdlist = NULL; GUnixFDList *g_outfdlist = NULL; @@ -1907,19 +1895,6 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *d return NULL; } - proxy = g_dbus_proxy_new_sync(dh->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dest, path, iface, NULL, &err); - if (!proxy) { - if (err) { - _E("failed to proxy_new_sync(%s)\n", err->message); - g_error_free(err); - } else { - _E("failed to proxy_new_sync\n"); - if (param) - g_variant_unref(param); - } - goto out; - } - /* append fd */ if (in_fdlist) { g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); @@ -1932,14 +1907,18 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *d } /* send message */ - ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, method, param, G_DBUS_CALL_FLAGS_NONE, -1, - g_infdlist, &g_outfdlist, NULL, &err); + ret = g_dbus_connection_call_with_unix_fd_list_sync(dh->conn, + dest, path, iface, method, param, + NULL, G_DBUS_CALL_FLAGS_NONE, + -1, + g_infdlist, &g_outfdlist, + NULL, &err); if (!ret || err) { if (err) { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:%s", err->message); + _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:%s", err->message); g_error_free(err); } else { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:"); + _E("failed to g_dbus_connection_call_with_unix_fd_list_sync:"); if (param) g_variant_unref(param); if (g_infdlist) @@ -1958,8 +1937,6 @@ GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *d out: if (g_outfdlist) g_object_unref(g_outfdlist); - if (proxy) - g_object_unref(proxy); return ret; } -- 2.7.4 From 6c85d1797b58fd01515228a8ac77183b86c585d9 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Dec 2018 11:29:12 +0900 Subject: [PATCH 04/16] Remove executable flag from non-executable files Change-Id: I1633ca1ff4238a4e2c833dfeb52fb751e7f88a64 Signed-off-by: lokilee73 --- src/libgdbus/dbus-system.c | 0 src/libgdbus/dbus-system.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/libgdbus/dbus-system.c mode change 100755 => 100644 src/libgdbus/dbus-system.h diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c old mode 100755 new mode 100644 diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h old mode 100755 new mode 100644 -- 2.7.4 From a0b1925ad8a64d305be20231a6fe11d259622245 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 3 Jan 2019 20:15:17 +0900 Subject: [PATCH 05/16] sensitivity: add deviced dbus node info Change-Id: I5a7c4fa14e5f2a8125b5cbddbb40c5ba2ee09d65 Signed-off-by: sanghyeok.oh --- src/libgdbus/dbus-system.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 9553be5..a9df43f 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -140,6 +140,9 @@ #define DEVICED_PATH_TZIP DEVICED_OBJECT_PATH"/Tzip" #define DEVICED_INTERFACE_TZIP DEVICED_INTERFACE_NAME".Tzip" +#define DEVICED_PATH_TOUCH DEVICED_OBJECT_PATH"/Touch" +#define DEVICED_INTERFACE_TOUCH DEVICED_INTERFACE_NAME".Touch" + /******************************************************************************* * -- 2.7.4 From 1d185d66e7b0f5ff6230285cd71f2bb1fe3d839c Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 10 Jan 2019 21:48:35 +0900 Subject: [PATCH 06/16] libgdbus: add api to start or stop systemd unit Change-Id: Iaa17cc32cff1b763c5ed89ddc69582f9b70e535a Signed-off-by: sanghyeok.oh --- packaging/libsyscommon.spec | 1 + src/Makefile.am | 92 --------- src/libgdbus/CMakeLists.txt | 2 + src/libgdbus/dbus-system.c | 207 ++++++++++++++++++- src/libgdbus/dbus-system.h | 17 ++ src/libgdbus/dbus-systemd.c | 481 ++++++++++++++++++++++++++++++++++++++++++++ src/libgdbus/dbus-systemd.h | 46 +++++ 7 files changed, 744 insertions(+), 102 deletions(-) delete mode 100644 src/Makefile.am create mode 100644 src/libgdbus/dbus-systemd.c create mode 100644 src/libgdbus/dbus-systemd.h diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 3dc79ff..fb7114f 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -77,4 +77,5 @@ touch debugsources.list %license LICENSE.Apache-2.0 %{_libdir}/libgdbus.so %{_includedir}/libgdbus/dbus-system.h +%{_includedir}/libgdbus/dbus-systemd.h %{_libdir}/pkgconfig/libgdbus.pc diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index bbee945..0000000 --- a/src/Makefile.am +++ /dev/null @@ -1,92 +0,0 @@ -AUTOMAKE_OPTIONS = color-tests parallel-tests - -pkgconfiglibdir=$(libdir)/pkgconfig - -CLEANFILES = -EXTRA_DIST = - -lib_LTLIBRARIES = -noinst_LTLIBRARIES = -noinst_DATA = -pkgconfiglib_DATA = - -check_PROGRAMS = -check_DATA = -tests= -#noinst_PROGRAMS = $(tests) -#check_PROGRAMS += $(tests) -#TESTS = $(tests) - -DEFAULT_CFLAGS = \ - $(OUR_CFLAGS) - -DEFAULT_LDFLAGS = \ - $(OUR_LDFLAGS) - -AM_CPPFLAGS = \ - -include $(top_builddir)/config.h \ - $(DEFAULT_CFLAGS) - -AM_CFLAGS = $(DEFAULT_CFLAGS) -AM_LDFLAGS = $(DEFAULT_LDFLAGS) - -INSTALL_EXEC_HOOKS = -UNINSTALL_EXEC_HOOKS = - -# ------------------------------------------------------------------------------ -pkgconfiglib_DATA += \ - libgdbus/libgdbus.pc - -EXTRA_DIST += \ - libgdbus/libgdbus.pc.in - -CLEANFILES += \ - libgdbus/libgdbus.pc - -libgdbus_pkgincludedir=$(includedir)/libgdbus -libgdbus_pkginclude_HEADERS = - -libgdbus_pkginclude_HEADERS += \ - libgdbus/dbus-system.h - -lib_LTLIBRARIES += \ - libgdbus.la - -libgdbus_la_SOURCES = \ - libgdbus/dbus-system.c - -libgdbus_la_CFLAGS = \ - $(AM_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GIO_UNIX_CFLAGS) \ - $(GIO_CFLAGS) - -libgdbus_la_LIBADD = \ - -lrt \ - $(GIO_LIBS) \ - $(GIO_UNIX_LIBS) - -# ------------------------------------------------------------------------------ -substitutions = \ - '|PACKAGE_VERSION=$(PACKAGE_VERSION)|' \ - '|PACKAGE_NAME=$(PACKAGE_NAME)|' \ - '|PACKAGE_URL=$(PACKAGE_URL)|' \ - '|LIBGDBUS_PC_REQUIRES=$(LIBGDBUS_PC_REQUIRES)|' \ - '|LIBGDBUS_PC_CFLAGS=$(LIBGDBUS_PC_CFLAGS)|' \ - '|LIBGDBUS_PC_LIBS=$(LIBGDBUS_PC_LIBS)|' \ - '|includedir=$(includedir)|' \ - '|VERSION=$(VERSION)|' - -SED_PROCESS = \ - $(AM_V_GEN)$(MKDIR_P) $(dir $@) && \ - $(SED) $(subst '|,-e 's|@,$(subst =,\@|,$(subst |',|g',$(substitutions)))) \ - < $< > $@ - -%.pc: %.pc.in - $(SED_PROCESS) - -%.c: %.gperf - $(AM_V_at)$(MKDIR_P) $(dir $@) - $(AM_V_GPERF)$(GPERF) < $< > $@ - -install-exec-hook: $(INSTALL_EXEC_HOOKS) diff --git a/src/libgdbus/CMakeLists.txt b/src/libgdbus/CMakeLists.txt index 327ea2b..06f1bc2 100644 --- a/src/libgdbus/CMakeLists.txt +++ b/src/libgdbus/CMakeLists.txt @@ -9,9 +9,11 @@ SET(VERSION 4.1) SET(libgdbus_SRCS dbus-system.c + dbus-systemd.c ) SET(HEADERS dbus-system.h + dbus-systemd.h ) # CHECK PKG diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 42f061b..e59da08 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -697,21 +697,20 @@ static int _check_brace(const char * expr) return -1; if (expr[i] == ')') { - if (ch == '(') { + if (ch == '(') --qucnt; - } else + else return -1; } else if (expr[i] == '}') { - if (ch == '{') { + if (ch == '{') --qucnt; - } else + else return -1; } else return -1; - if (qucnt == 0) { + if (qucnt == 0) return i + 1; - } } } @@ -1231,9 +1230,9 @@ int dbus_handle_unregister_dbus_object(dbus_handle_h handle, const char *obj_pat dbus_object_handle_s *oh = NULL; int ret = 0; - if (!obj_path) { + if (!obj_path) return -1; - } + if (!dh) { dh = _dbus_handle_get_default_connection(); if (!dh) { @@ -1507,6 +1506,195 @@ void unsubscribe_dbus_signal(dbus_handle_h handle, guint id) g_dbus_connection_signal_unsubscribe(dh->conn, id); } +static void _signal_reply_sync_cb(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + sig_ctx *ctx = data; + if (!ctx) { + _E("user data is null"); + assert(0); + } + + ctx->param = g_variant_ref(param); + ctx->quit_reason = CTX_QUIT_NORMAL; + + if (ctx->timeout_src) { + g_source_destroy(ctx->timeout_src); + ctx->timeout_src = NULL; + } + g_main_loop_quit(ctx->loop); +} + +sig_ctx *dbus_handle_new_signal_ctx(void) +{ + sig_ctx *ctx; + + ctx = (sig_ctx *)malloc(sizeof(sig_ctx)); + if (!ctx) { + _E("failed to alloc mem"); + return NULL; + } + + ctx->sig_id = 0; + + ctx->context = g_main_context_new(); + if (!ctx->context) { + _E("failed to alloc context"); + free(ctx); + return NULL; + } + ctx->loop = g_main_loop_new(ctx->context, FALSE); + if (!ctx->loop) { + _E("failed to alloc main loop"); + g_main_context_unref(ctx->context); + free(ctx); + return NULL; + } + ctx->timeout_src = NULL; + ctx->param = NULL; + ctx->quit_reason = 0; + ctx->user_data = NULL; + + return ctx; +} + +void dbus_handle_free_signal_ctx(sig_ctx *ctx) +{ + if (!ctx) + return ; + + if (ctx->param) { + g_variant_unref(ctx->param); + ctx->param = NULL; + } + if (ctx->sig_id) { + unsubscribe_dbus_signal(NULL, ctx->sig_id); + ctx->sig_id = 0; + } + if (ctx->timeout_src) { + g_source_destroy(ctx->timeout_src); + ctx->timeout_src = NULL; + } + if (ctx->context) { + g_main_context_pop_thread_default(ctx->context); + g_main_context_unref(ctx->context); + ctx->context = NULL; + } + if (ctx->loop) { + g_main_loop_unref(ctx->loop); + ctx->loop = NULL; + } + free(ctx); +} + +static gboolean _cb_ctx_timeout(gpointer user_data) +{ + sig_ctx *ctx = user_data; + + if (!ctx) { + _E("user_data is null"); + return FALSE; + } + + ctx->quit_reason = CTX_QUIT_TIMEOUT; + /* if cb return FALSE, source will be destroyed */ + ctx->timeout_src = NULL; + + unsubscribe_dbus_signal(NULL, ctx->sig_id); + ctx->sig_id = 0; + + g_main_loop_quit(ctx->loop); + + return FALSE; +} + +#define CTX_MAX_TIMEOUT 25000 + +int dbus_handle_signal_ctx_add_timeout(sig_ctx *ctx, int timeout_msec) +{ + GSource *src = NULL; + guint id = 0; + + if (!ctx) + return -EINVAL; + if (timeout_msec < -1) + return -EINVAL; + + if (timeout_msec == -1 || timeout_msec >= CTX_MAX_TIMEOUT) + timeout_msec = CTX_MAX_TIMEOUT; + + src = g_timeout_source_new(timeout_msec); + if (!src) + return -ENOMEM; + + g_source_set_callback(src, _cb_ctx_timeout, ctx, NULL); + g_source_attach(src, ctx->context); + + ctx->timeout_src = src; + + return 0; +} + +guint subscribe_dbus_signal_ctx(dbus_handle_h handle, sig_ctx *ctx, + const char *sender, const char *path, + const char *iface, const char *name, + GDBusSignalCallback _cb) +{ + dcl_dbus_handle(); + + if (!ctx) { + _E("wrong param ctx is null"); + return 0; + } + + if (!dh) { + dh = _dbus_handle_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", + (int)dbus_handle_get_default_bus_type()); + return 0; + } + } + + if (!dh->conn) { + _E("connection is null. check bus status"); + return 0; + } + + if (!_cb) + _cb = _signal_reply_sync_cb; + + /* change context before subscribe */ + g_main_context_push_thread_default(ctx->context); + + ctx->sig_id = g_dbus_connection_signal_subscribe(dh->conn, + sender, iface, name, path, NULL, + G_DBUS_SIGNAL_FLAGS_NONE, _cb, + (void*)ctx, NULL); + + if (!ctx->sig_id) + _E("failed to subscribe signal"); + + return ctx->sig_id; +} + +int dbus_handle_signal_ctx_wait(sig_ctx *ctx) +{ + if (!ctx || !ctx->loop) + return -EINVAL; + + g_main_loop_run(ctx->loop); + + _D("quit g_main_loop"); + + return ctx->quit_reason; +} + int _check_type_string_is_container(const char *signature) { if (!signature) @@ -1574,9 +1762,8 @@ static GVariant* _append_variant(const char *signature, const char *param[]) snprintf(container, sizeof(container) - 1, "(%s)", signature); sig = container; } - if (!g_variant_type_is_container(G_VARIANT_TYPE(sig))) { + if (!g_variant_type_is_container(G_VARIANT_TYPE(sig))) _E("signature (%s) is not container type", signature); - } builder = g_variant_builder_new(G_VARIANT_TYPE(sig)); len = strlen(sig); diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index a9df43f..ef5ba75 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -481,6 +481,23 @@ int dbus_handle_register_dbus_object_all(dbus_handle_h handle); guint subscribe_dbus_signal(dbus_handle_h handle, const char *path, const char *iface, const char *name, GDBusSignalCallback cb, void *data, destroy_notified free_func); void unsubscribe_dbus_signal(dbus_handle_h handle, guint id); +enum ctx_quit_reason {CTX_QUIT_UNKNOWN, CTX_QUIT_NORMAL, CTX_QUIT_TIMEOUT}; + +typedef struct { + guint sig_id; + GMainContext *context; + GMainLoop *loop; + GSource *timeout_src; + GVariant *param; + enum ctx_quit_reason quit_reason; + void *user_data; +} sig_ctx; + +sig_ctx *dbus_handle_new_signal_ctx(void); +void dbus_handle_free_signal_ctx(sig_ctx *ctx); +guint subscribe_dbus_signal_ctx(dbus_handle_h handle, sig_ctx *ctx, const char *sender, const char *path, const char *iface, const char *name, GDBusSignalCallback cb); +int dbus_handle_signal_ctx_add_timeout(sig_ctx *ctx, int timeout); + GVariant *dbus_handle_make_simple_array(const char *sig, int *param); int dbus_handle_broadcast_dbus_signal(const char *path, const char *iface, const char *name, const char *signature, const char *param[]); diff --git a/src/libgdbus/dbus-systemd.c b/src/libgdbus/dbus-systemd.c new file mode 100644 index 0000000..998468d --- /dev/null +++ b/src/libgdbus/dbus-systemd.c @@ -0,0 +1,481 @@ +/* + * libsyscommon + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "shared/log.h" + +#define SYSTEMD_DBUS_SERVICE "org.freedesktop.systemd1" +#define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" +#define SYSTEMD_DBUS_UNIT_PATH "/org/freedesktop/systemd1/unit/" + +#define SYSTEMD_DBUS_MANAGER_IFACE "org.freedesktop.systemd1.Manager" +#define SYSTEMD_DBUS_UNIT_IFACE "org.freedesktop.systemd1.Unit" +#define SYSTEMD_DBUS_SERVICE_IFACE "org.freedesktop.systemd1.Service" +#define SYSTEMD_DBUS_TARGET_IFACE "org.freedesktop.systemd1.Target" + +#define DBUS_IFACE_DBUS_PROPERTIES "org.freedesktop.DBus.Properties" + +#define SUFFIX_SERVICE ".service" +#define SUFFIX_SOCKET ".socket" +#define SUFFIX_BUSNAME ".busname" +#define SUFFIX_TARGET ".target" +#define SUFFIX_DEVICE ".device" +#define SUFFIX_MOUNT ".mount" +#define SUFFIX_SWAP ".swap" +#define SUFFIX_TIMER ".timer" +#define SUFFIX_PATH ".path" +#define SUFFIX_SLICE ".slice" +#define SUFFIX_SCOPE ".scope" + +#define UNIT_NAME_MAX 256 + +typedef struct { + char *job_id; + char *unit_name; +} unitinfo; + +static void _cb_JobRemoved(GDBusConnection *conn, + const char *sender, + const char *path, + const char *iface, + const char *name, + GVariant *param, + gpointer data) +{ + sig_ctx *ctx = data; + gchar *job_id = NULL; + gchar *unit_name = NULL; + unitinfo *uinfo = NULL; + + if (!ctx) { + _E("User data ctx is null"); + return ; + } + + uinfo = ctx->user_data; + if (!uinfo) { + _E("User_data uinfo is null"); + return ; + } + if (!dh_get_param_from_var(param, "(uoss)", NULL, &job_id, &unit_name, NULL)) { + _E("Failed to get param"); + return ; + } + if (strcmp(uinfo->job_id, job_id) || strcmp(uinfo->unit_name, unit_name)) { + _E("Not matched: job_id:%s, unit_name:%s", job_id, unit_name); + goto err; + } + + /* otherwise, if matched signal, quit loop */ + + ctx->quit_reason = CTX_QUIT_NORMAL; + if (ctx->timeout_src) { + g_source_destroy(ctx->timeout_src); + ctx->timeout_src = NULL; + } + + g_main_loop_quit(ctx->loop); + +err: + g_free(job_id); + g_free(unit_name); +} + +static int _systemd_control_unit_sync(const char *method, const char *name, int timeout_msec) +{ + GVariant *reply = NULL; + gchar *objpath = NULL; + int ret = 0; + sig_ctx *ctx = NULL; + gchar *unit_name = NULL; + unitinfo uinfo; + int quit_reason; + + ctx = dbus_handle_new_signal_ctx(); + if (!ctx) + return -ENOMEM; + + _I("Starting: %s %s", method, name); + + /* synchronous siganl subscriptsion */ + ret = subscribe_dbus_signal_ctx(NULL, ctx, SYSTEMD_DBUS_SERVICE, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_IFACE_MANAGER, "JobRemoved", _cb_JobRemoved); + if (ret == 0) { + ret = -1; + goto finish; + } + + reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + SYSTEMD_DBUS_PATH, + SYSTEMD_DBUS_MANAGER_IFACE, + method, + g_variant_new("(ss)", name, "replace")); + if (!reply || !dh_get_param_from_var(reply, "(o)", &objpath)) { + _E("fail (%s): no message", method); + ret = -EBADMSG; + goto finish; + } + + uinfo.job_id = objpath; + uinfo.unit_name = name; + ctx->user_data = &uinfo; + + /* set timeout */ + ret = dbus_handle_signal_ctx_add_timeout(ctx, timeout_msec); + if (ret < 0) { + _E("Failed to set timeout, %d", ret); + goto finish; + } + + /* run loop and wait signal callback */ + quit_reason = dbus_handle_signal_ctx_wait(ctx); + if (quit_reason != CTX_QUIT_NORMAL) { + ret = -1; + _E("Failed to receive JobRemoved signal %d", quit_reason); + goto finish; + } + + _I("Finished: %s %s", method, name); + +finish: + if (unit_name) + g_free(unit_name); + + if (reply) + g_variant_unref(reply); + g_free(objpath); + + dbus_handle_free_signal_ctx(ctx); + + return ret; +} + +static int _systemd_control_unit_async(const char *method, const char *name) +{ + GVariant *reply = NULL; + gchar *objpath = NULL; + int ret = 0; + + _I("Starting: %s %s", method, name); + + reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + SYSTEMD_DBUS_PATH, + SYSTEMD_DBUS_MANAGER_IFACE, + method, + g_variant_new("(ss)", name, "replace")); + + if (!reply || !dh_get_param_from_var(reply, "(o)", &objpath)) { + _E("fail (%s): no message", method); + ret = -EBADMSG; + goto finish; + } + + _I("Finished: %s %s", method, name); +finish: + if (reply) + g_variant_unref(reply); + g_free(objpath); + + return ret; +} + +static int _has_suffix(const char *service_name, const char *suffix) +{ + int index = 0; + + if (!service_name || !suffix) + return FALSE; + + index = strlen(service_name) - strlen(suffix); + if (index <= 0) + return FALSE; + + if (strcmp(service_name + index, suffix) == 0) + return TRUE; + return FALSE; +} + +static int _change_suffix(const char *name, const char *suffix, char **new_name) +{ + char *buf = NULL; + char *ext = NULL; + unsigned int len = 0; + int ret = 0; + + if (!name || !suffix || !new_name) { + _E("Wrong param name:%s, suffix:%s, new_name:%s", name, suffix, new_name); + return -EINVAL; + } + + ext = strrchr(name, '.'); + if (ext == name) { + _E("Wrong file name %s", name); + return -EINVAL; + } + + /* if ext is same as suffix */ + if (ext && strcmp(ext, suffix) == 0) { + *new_name = strdup(name); + return 0; + } + + /* otherwise, make new unit name */ + if (ext) + len = ext - name; + else + len = strlen(name); + + /* check max len */ + if ((len + strlen(suffix)) >= UNIT_NAME_MAX) { + _E("Name is too long:%d", (len + strlen(suffix))); + return -ENAMETOOLONG; + } + + buf = (char *)malloc(sizeof(char) * (len + strlen(suffix) + 1)); + if (!buf) { + _E("Failed to alloc mem"); + return -ENOMEM; + } + + ret = snprintf(buf, len + 1, "%s", name); + if (ret < 0) { + ret = -errno; + _E("Failed to snprintf %d", ret); + goto err; + } + ret = snprintf(buf + len, strlen(suffix) + 1, "%s", suffix); + if (ret < 0) { + ret = -errno; + _E("Failed to snprintf %d", ret); + goto err; + } + + *new_name = buf; + + return 0; + +err: + free(buf); + return ret; +} + +/* +_systemd_start_unit_internal + +Start or Stop systemd unit. + 1) synchronous + - Send StartUnit/StopUnit Method call(sync) + reply:(o):/org/freedesktop/systemd1/job/[jobid] + - Wait JobRemoved signal from systemd + (uoss):(uint32 [jobid], objectpath '/org/freedesktop/systemd1/job/[jobid]', '[unit name]', '[result]') + 2) asynchronous + - Send StartUnit/StopUnit Method call(sync) + +@param name: unit name +@param suffix: (nullable): change extension of unit name, or %NULL +@param timeout_msec: the timeout in milliseconds, -1 to use the default +@param method: method name, "StartUnit" or "StopUnit" +@param sync: %TRUE +Returns: the exit status +*/ +static int _systemd_start_unit_internal(const char *name, const char *suffix, + int timeout_msec, const char *method, int sync) +{ + unsigned int len = 0; + char *new_name = NULL; + int ret = 0; + + if (!name || !method) { + _E("Wrong param name %s, method %s", name, method); + return -EINVAL; + } + if (timeout_msec < -1) { + _E("wrong timeout. timeout(>=0 or -1)"); + return -EINVAL; + } + + if (suffix) { + ret = _change_suffix(name, suffix, &new_name); + if (ret < 0) + return ret; + name = new_name; + } else { + if (strlen(name) > UNIT_NAME_MAX) { + _E("Invalid name length %d(>%d)", strlen(name), UNIT_NAME_MAX); + return -EINVAL; + } + } + + if (sync) + ret = _systemd_control_unit_sync(method, name, timeout_msec); + else + ret = _systemd_control_unit_async(method, name); + + if (new_name) + free(new_name); + + return ret; +} + +int systemd_start_unit_sync(const char *name, const char *suffix, int timeout_msec) +{ + return _systemd_start_unit_internal(name, suffix, timeout_msec, "StartUnit", TRUE); +} + +int systemd_stop_unit_sync(const char *name, const char *suffix, int timeout_msec) +{ + return _systemd_start_unit_internal(name, suffix, timeout_msec, "StopUnit", TRUE); +} + +int systemd_start_unit_async(const char *name, const char *suffix) +{ + return _systemd_start_unit_internal(name, suffix, -1, "StartUnit", FALSE); +} + +int systemd_stop_unit_async(const char *name, const char *suffix) +{ + return _systemd_start_unit_internal(name, suffix, -1, "StopUnit", FALSE); +} + +#define SYSTEMD_UNIT_ESCAPE_CHAR ".-" + +static char *systemd_get_unit_dbus_path(const char *unit) +{ + char *path = NULL; + int i; + size_t p, k, prefix_len, unit_len; + size_t path_len, len, escape; + + if (!unit) + return NULL; + unit_len = strlen(unit); + + for (escape = 0, p = 0; p < unit_len; escape++) { + k = strcspn(unit + p, SYSTEMD_UNIT_ESCAPE_CHAR); + if (p + k >= unit_len) + break; + p += k+1; + } + + prefix_len = strlen(SYSTEMD_DBUS_UNIT_PATH); + /* assume we try to get object path of foo-bar.service then + * the object path will be + * "/org/freedesktop/systemd1/unit/foo_2dbar_2eservice\n". In + * this case we can find two escape characters, one of escape + * char('-') is changed to three of char("_2d"). So the total + * length will be: */ + /* (PREFIX) + (unit - escape + 3*escape) + NULL */ + path_len = prefix_len + (unit_len - escape) + + (escape * 3 * sizeof(char)) + 1; + path = (char *)calloc(path_len, sizeof(char)); + if (!path) + return NULL; + + strncpy(path, SYSTEMD_DBUS_UNIT_PATH, prefix_len); + for (i = 0, p = 0; i <= escape; i++) { + k = strcspn(unit + p, SYSTEMD_UNIT_ESCAPE_CHAR); + strncpy(path + prefix_len, unit + p, k); + if (k < strlen(unit + p)) { + len = path_len - (prefix_len + k); + snprintf(path + prefix_len + k, len, + "_%x", *(unit + p + k) & 0xff); + prefix_len += k + 3; + p += k+1; + } + } + + return path; +} + +GVariant *systemd_get_manager_property(const char *property) +{ + GVariant *reply = NULL; + GVariant *val = NULL; + + if (!property) + return NULL; + + reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + SYSTEMD_DBUS_PATH, + DBUS_IFACE_DBUS_PROPERTIES, + "Get", + g_variant_new("(ss)", SYSTEMD_DBUS_MANAGER_IFACE, property)); + if (!reply || !dh_get_param_from_var(reply, "(v)", &val)) + _E("Failed to get variant"); + if (reply) + g_variant_unref(reply); + + return val; +} + +GVariant *systemd_get_unit_property(const char *unit, + const char *property) +{ + char *escaped; + GVariant *reply = NULL; + GVariant *val = NULL; + + if (!unit || !property) + return NULL; + + escaped = systemd_get_unit_dbus_path(unit); + + reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + escaped, + DBUS_IFACE_DBUS_PROPERTIES, + "Get", + g_variant_new("(ss)", SYSTEMD_DBUS_UNIT_IFACE, property)); + + if (!reply || !dh_get_param_from_var(reply, "(v)", &val)) + _E("Failed to get variant"); + if (reply) + g_variant_unref(reply); + free(escaped); + + return val; +} + +GVariant *systemd_get_service_property(const char *unit, + const char *property) +{ + char *escaped; + GVariant *reply = NULL; + GVariant *val = NULL; + + if (!unit || !property) + return NULL; + + escaped = systemd_get_unit_dbus_path(unit); + + reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST, + escaped, + DBUS_IFACE_DBUS_PROPERTIES, + "Get", + g_variant_new("(ss)", SYSTEMD_DBUS_SERVICE_IFACE, property)); + if (!reply || !dh_get_param_from_var(reply, "(v)", &val)) + _E("Failed to get variant"); + if (reply) + g_variant_unref(reply); + free(escaped); + return val; +} diff --git a/src/libgdbus/dbus-systemd.h b/src/libgdbus/dbus-systemd.h new file mode 100644 index 0000000..121bbf1 --- /dev/null +++ b/src/libgdbus/dbus-systemd.h @@ -0,0 +1,46 @@ +/* + * libsyscommon + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __DBUS_SYSTEMD_H__ +#define __DBUS_SYSTEMD_H__ + +#include "dbus-system.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int systemd_start_unit_sync(const char *name, const char *suffix, int timeout_msec); +int systemd_stop_unit_sync(const char *name, const char *suffix, int timeout_msec); + +int systemd_start_unit_async(const char *name, const char *suffix); +int systemd_stop_unit_async(const char *name, const char *suffix); + +GVariant *systemd_get_manager_property(const char *property); +GVariant *systemd_get_unit_property(const char *unit, + const char *property); +GVariant *systemd_get_service_property(const char *unit, + const char *property); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __DBUS_SYSTEMD_H__ */ + -- 2.7.4 From d078a5c04bec4502ccfa093eb4e59729a01efdf9 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 8 Feb 2019 15:57:05 +0900 Subject: [PATCH 07/16] Add dlog for debugging and fix build warnings Change-Id: Idad13056a15185a622f51283589af7bedf5734df Signed-off-by: lokilee73 --- packaging/libsyscommon.spec | 1 + src/libgdbus/CMakeLists.txt | 1 + src/libgdbus/dbus-system.c | 3 +-- src/libgdbus/dbus-system.h | 1 + src/libgdbus/dbus-systemd.c | 27 +++------------------------ 5 files changed, 7 insertions(+), 26 deletions(-) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index fb7114f..57175d4 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -12,6 +12,7 @@ Source1001: %{name}.manifest BuildRequires: pkgconfig(glib-2.0) >= 2.44 BuildRequires: pkgconfig(gio-2.0) >= 2.44 BuildRequires: pkgconfig(gio-unix-2.0) +BuildRequires: pkgconfig(dlog) BuildRequires: cmake Requires: /bin/cp diff --git a/src/libgdbus/CMakeLists.txt b/src/libgdbus/CMakeLists.txt index 06f1bc2..9baa020 100644 --- a/src/libgdbus/CMakeLists.txt +++ b/src/libgdbus/CMakeLists.txt @@ -21,6 +21,7 @@ INCLUDE(FindPkgConfig) pkg_check_modules(gdbus REQUIRED glib-2.0 gio-2.0 + dlog gio-unix-2.0) FOREACH(flag ${gdbus_CFLAGS}) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index e59da08..7ed53ba 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1557,7 +1557,7 @@ sig_ctx *dbus_handle_new_signal_ctx(void) } ctx->timeout_src = NULL; ctx->param = NULL; - ctx->quit_reason = 0; + ctx->quit_reason = CTX_QUIT_UNKNOWN; ctx->user_data = NULL; return ctx; @@ -1618,7 +1618,6 @@ static gboolean _cb_ctx_timeout(gpointer user_data) int dbus_handle_signal_ctx_add_timeout(sig_ctx *ctx, int timeout_msec) { GSource *src = NULL; - guint id = 0; if (!ctx) return -EINVAL; diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index ef5ba75..6cdec69 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -496,6 +496,7 @@ typedef struct { sig_ctx *dbus_handle_new_signal_ctx(void); void dbus_handle_free_signal_ctx(sig_ctx *ctx); guint subscribe_dbus_signal_ctx(dbus_handle_h handle, sig_ctx *ctx, const char *sender, const char *path, const char *iface, const char *name, GDBusSignalCallback cb); +int dbus_handle_signal_ctx_wait(sig_ctx *ctx); int dbus_handle_signal_ctx_add_timeout(sig_ctx *ctx, int timeout); GVariant *dbus_handle_make_simple_array(const char *sig, int *param); diff --git a/src/libgdbus/dbus-systemd.c b/src/libgdbus/dbus-systemd.c index 998468d..b06e2fa 100644 --- a/src/libgdbus/dbus-systemd.c +++ b/src/libgdbus/dbus-systemd.c @@ -51,8 +51,8 @@ #define UNIT_NAME_MAX 256 typedef struct { - char *job_id; - char *unit_name; + const char *job_id; + const char *unit_name; } unitinfo; static void _cb_JobRemoved(GDBusConnection *conn, @@ -108,7 +108,6 @@ static int _systemd_control_unit_sync(const char *method, const char *name, int gchar *objpath = NULL; int ret = 0; sig_ctx *ctx = NULL; - gchar *unit_name = NULL; unitinfo uinfo; int quit_reason; @@ -118,7 +117,7 @@ static int _systemd_control_unit_sync(const char *method, const char *name, int _I("Starting: %s %s", method, name); - /* synchronous siganl subscriptsion */ + /* synchronous signal subscription */ ret = subscribe_dbus_signal_ctx(NULL, ctx, SYSTEMD_DBUS_SERVICE, SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_IFACE_MANAGER, "JobRemoved", _cb_JobRemoved); if (ret == 0) { ret = -1; @@ -158,9 +157,6 @@ static int _systemd_control_unit_sync(const char *method, const char *name, int _I("Finished: %s %s", method, name); finish: - if (unit_name) - g_free(unit_name); - if (reply) g_variant_unref(reply); g_free(objpath); @@ -199,22 +195,6 @@ finish: return ret; } -static int _has_suffix(const char *service_name, const char *suffix) -{ - int index = 0; - - if (!service_name || !suffix) - return FALSE; - - index = strlen(service_name) - strlen(suffix); - if (index <= 0) - return FALSE; - - if (strcmp(service_name + index, suffix) == 0) - return TRUE; - return FALSE; -} - static int _change_suffix(const char *name, const char *suffix, char **new_name) { char *buf = NULL; @@ -301,7 +281,6 @@ Returns: the exit status static int _systemd_start_unit_internal(const char *name, const char *suffix, int timeout_msec, const char *method, int sync) { - unsigned int len = 0; char *new_name = NULL; int ret = 0; -- 2.7.4 From 912db021fc122671f2b5f85aec1c834c14f6e7bd Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 7 Jan 2019 15:30:33 +0900 Subject: [PATCH 08/16] Add Path and Interface for temperature Change-Id: Icd52d21d0fa90f6367e4354598dd37b02dcc4957 Signed-off-by: lokilee73 --- src/libgdbus/dbus-system.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 6cdec69..e7cf47a 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -140,9 +140,13 @@ #define DEVICED_PATH_TZIP DEVICED_OBJECT_PATH"/Tzip" #define DEVICED_INTERFACE_TZIP DEVICED_INTERFACE_NAME".Tzip" +/* Touch service */ #define DEVICED_PATH_TOUCH DEVICED_OBJECT_PATH"/Touch" #define DEVICED_INTERFACE_TOUCH DEVICED_INTERFACE_NAME".Touch" +/* Thermal service: operatioins about temperature */ +#define DEVICED_PATH_TEMPERATURE DEVICED_OBJECT_PATH"/Temperature" +#define DEVICED_INTERFACE_TEMPERATURE DEVICED_INTERFACE_NAME".temperature" /******************************************************************************* * -- 2.7.4 From 1dc58c9538e2005c108d6bf7671cd60fcd8d6827 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 27 Feb 2019 20:00:17 +0900 Subject: [PATCH 09/16] power: apply modified dbus spec Change-Id: I4008f782ffa43a08a67516df7f99a53421b97969 Signed-off-by: sanghyeok.oh --- src/libgdbus/dbus-system.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index e7cf47a..1dec188 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -81,9 +81,6 @@ /* Low Power service: start/stop low power mode */ #define DEVICED_PATH_LOWPOWER DEVICED_OBJECT_PATH"/LowPower" #define DEVICED_INTERFACE_LOWPOWER DEVICED_INTERFACE_NAME".lowpower" -/* Reboot service: request reboot operation */ -#define DEVICED_PATH_REBOOT DEVICED_OBJECT_PATH"/Reboot" -#define DEVICED_INTERFACE_REBOOT DEVICED_INTERFACE_NAME".reboot" /* Storage service: get storage size operatioins about storage */ #define DEVICED_PATH_STORAGE DEVICED_OBJECT_PATH"/Storage" #define DEVICED_INTERFACE_STORAGE DEVICED_INTERFACE_NAME".storage" @@ -92,7 +89,7 @@ #define DEVICED_INTERFACE_SDE DEVICED_INTERFACE_NAME".sde" #define DEVICED_PATH_ODE DEVICED_OBJECT_PATH"/Ode" #define DEVICED_INTERFACE_ODE DEVICED_INTERFACE_NAME".ode" -/* Poweroff service: get power off status operations about Poweroff */ +/* Poweroff service: request power off operation or get power off status operations about Poweroff(signal) */ #define DEVICED_PATH_POWEROFF DEVICED_OBJECT_PATH"/PowerOff" #define DEVICED_INTERFACE_POWEROFF DEVICED_INTERFACE_NAME".PowerOff" /* Led service: play/stop led operations about led */ -- 2.7.4 From b7753fc5b633a0dfec7295f038e51111315c3c34 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 22 Mar 2019 20:25:04 +0900 Subject: [PATCH 10/16] Add .gitignore Change-Id: I41c66209d6456a02079416c226c147720e244346 Signed-off-by: Hyotaek Shim --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9306ae6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cscope.files +cscope.out +tags -- 2.7.4 From 5733b3b5999a7c3f8d47ddea3d4b84c926d62434 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 22 Mar 2019 20:22:45 +0900 Subject: [PATCH 11/16] Rename systemd_start_unit_sync() to systemd_start_unit_wait_started() Change-Id: I2064b404c8ac562b7e952ca061b2159d0bc1876f Signed-off-by: Hyotaek Shim --- src/libgdbus/dbus-systemd.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/libgdbus/dbus-systemd.c b/src/libgdbus/dbus-systemd.c index b06e2fa..d77f733 100644 --- a/src/libgdbus/dbus-systemd.c +++ b/src/libgdbus/dbus-systemd.c @@ -102,7 +102,7 @@ err: g_free(unit_name); } -static int _systemd_control_unit_sync(const char *method, const char *name, int timeout_msec) +static int _systemd_control_unit_wait(const char *method, const char *name, int timeout_msec) { GVariant *reply = NULL; gchar *objpath = NULL; @@ -260,15 +260,15 @@ err: } /* -_systemd_start_unit_internal +_systemd_control_unit Start or Stop systemd unit. - 1) synchronous + 1) Wait for started/stopped - Send StartUnit/StopUnit Method call(sync) reply:(o):/org/freedesktop/systemd1/job/[jobid] - Wait JobRemoved signal from systemd (uoss):(uint32 [jobid], objectpath '/org/freedesktop/systemd1/job/[jobid]', '[unit name]', '[result]') - 2) asynchronous + 2) Asynchronous - Send StartUnit/StopUnit Method call(sync) @param name: unit name @@ -278,8 +278,8 @@ Start or Stop systemd unit. @param sync: %TRUE Returns: the exit status */ -static int _systemd_start_unit_internal(const char *name, const char *suffix, - int timeout_msec, const char *method, int sync) +static int _systemd_control_unit(const char *name, const char *suffix, + int timeout_msec, const char *method, int wait) { char *new_name = NULL; int ret = 0; @@ -305,8 +305,8 @@ static int _systemd_start_unit_internal(const char *name, const char *suffix, } } - if (sync) - ret = _systemd_control_unit_sync(method, name, timeout_msec); + if (wait) + ret = _systemd_control_unit_wait(method, name, timeout_msec); else ret = _systemd_control_unit_async(method, name); @@ -316,24 +316,24 @@ static int _systemd_start_unit_internal(const char *name, const char *suffix, return ret; } -int systemd_start_unit_sync(const char *name, const char *suffix, int timeout_msec) +int systemd_start_unit_wait_started(const char *name, const char *suffix, int timeout_msec) { - return _systemd_start_unit_internal(name, suffix, timeout_msec, "StartUnit", TRUE); + return _systemd_control_unit(name, suffix, timeout_msec, "StartUnit", TRUE); } -int systemd_stop_unit_sync(const char *name, const char *suffix, int timeout_msec) +int systemd_stop_unit_wait_stopped(const char *name, const char *suffix, int timeout_msec) { - return _systemd_start_unit_internal(name, suffix, timeout_msec, "StopUnit", TRUE); + return _systemd_control_unit(name, suffix, timeout_msec, "StopUnit", TRUE); } int systemd_start_unit_async(const char *name, const char *suffix) { - return _systemd_start_unit_internal(name, suffix, -1, "StartUnit", FALSE); + return _systemd_control_unit(name, suffix, -1, "StartUnit", FALSE); } int systemd_stop_unit_async(const char *name, const char *suffix) { - return _systemd_start_unit_internal(name, suffix, -1, "StopUnit", FALSE); + return _systemd_control_unit(name, suffix, -1, "StopUnit", FALSE); } #define SYSTEMD_UNIT_ESCAPE_CHAR ".-" -- 2.7.4 From 13e1de6e9bdef291c2389ed5478973347236c57c Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 25 Mar 2019 19:15:45 +0900 Subject: [PATCH 12/16] Rename systemd_stop_unit_sync() to systemd_stop_unit_wait_stopped() Change-Id: I5c8e321c84e7a54073d8830e7c810e1dae7e5210 Signed-off-by: Hyotaek Shim --- src/libgdbus/dbus-systemd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libgdbus/dbus-systemd.h b/src/libgdbus/dbus-systemd.h index 121bbf1..b10e4af 100644 --- a/src/libgdbus/dbus-systemd.h +++ b/src/libgdbus/dbus-systemd.h @@ -26,8 +26,8 @@ extern "C" { #endif -int systemd_start_unit_sync(const char *name, const char *suffix, int timeout_msec); -int systemd_stop_unit_sync(const char *name, const char *suffix, int timeout_msec); +int systemd_start_unit_wait_started(const char *name, const char *suffix, int timeout_msec); +int systemd_stop_unit_wait_stopped(const char *name, const char *suffix, int timeout_msec); int systemd_start_unit_async(const char *name, const char *suffix); int systemd_stop_unit_async(const char *name, const char *suffix); -- 2.7.4 From 62ae19bd3c8d067e8c4db2333f18af0f7130bc82 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 8 Apr 2019 17:33:17 +0900 Subject: [PATCH 13/16] Change library name to libsyscommon. - Add new function for systemd state Change-Id: Ie69b718918306fc55e6c801e4c8d0fcaa0ab79b0 Signed-off-by: Yunmi Ha --- CMakeLists.txt | 61 ++++++++++++++++++++++- src/libgdbus/libgdbus.pc.in => libsyscommon.pc.in | 10 ++-- packaging/libsyscommon.spec | 34 ++++++------- src/libgdbus/CMakeLists.txt | 58 --------------------- src/libsystemd/systemd-state.c | 60 ++++++++++++++++++++++ src/libsystemd/systemd-state.h | 35 +++++++++++++ 6 files changed, 174 insertions(+), 84 deletions(-) rename src/libgdbus/libgdbus.pc.in => libsyscommon.pc.in (54%) delete mode 100644 src/libgdbus/CMakeLists.txt create mode 100644 src/libsystemd/systemd-state.c create mode 100644 src/libsystemd/systemd-state.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 10850df..30c53c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,4 +2,63 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(libsyscommon C) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) -ADD_SUBDIRECTORY(src/libgdbus) \ No newline at end of file +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared) +# ADD_SUBDIRECTORY(src/libgdbus) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "${PREFIX}/include") +SET(VERSION 4.1) + +SET(libsyscommon_SRCS + src/libgdbus/dbus-system.c + src/libgdbus/dbus-systemd.c + src/libsystemd/systemd-state.c +) +SET(HEADERS + src/libgdbus/dbus-system.h + src/libgdbus/dbus-systemd.h + src/libsystemd/systemd-state.h +) + +# CHECK PKG +INCLUDE(FindPkgConfig) +pkg_check_modules(syscommon REQUIRED + glib-2.0 + gio-2.0 + dlog + gio-unix-2.0) + +FOREACH(flag ${syscommon_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +# LIBRARY +ADD_LIBRARY(${PROJECT_NAME} SHARED ${libsyscommon_SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${syscommon_LDFLAGS} "-ldl" pthread) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fPIC") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME syscommon) + +# INSTALL +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) + +# CONGIFURE FILE +FOREACH(flag ${syscommon_INCLUDE_DIRS}) + SET(SYSCOMMON_INCLUDEDIR "${SYSCOMMON_INCLUDEDIR} -I${flag}") +ENDFOREACH(flag) + +FOREACH(flag ${syscommon_LIBRARIES}) + SET(SYSCOMMON_LIBS "${SYSCOMMON_LIBS} -l${flag}") +ENDFOREACH(flag) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +# HEADER +FOREACH(hfile ${HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME}) +ENDFOREACH(hfile) diff --git a/src/libgdbus/libgdbus.pc.in b/libsyscommon.pc.in similarity index 54% rename from src/libgdbus/libgdbus.pc.in rename to libsyscommon.pc.in index 5616aac..8dda939 100644 --- a/src/libgdbus/libgdbus.pc.in +++ b/libsyscommon.pc.in @@ -9,9 +9,9 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: libgdbus -Description: Dbus library +Name: libsyscommon +Description: system common library Version: @VERSION@ -Requires.private: libgdbus -Cflags: -I${includedir} @GDBUS_INCLUDEDIR@ -Libs: -L${libdir} -lgdbus @GDBUS_LIBS@ +Requires.private: libsyscommon +Cflags: -I${includedir} @SYSCOMMON_INCLUDEDIR@ +Libs: -L${libdir} -lsyscommon @SYSCOMMON_LIBS@ diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 57175d4..5dfd090 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -21,24 +21,17 @@ Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig %description -System utility libraries. +System common utility libraries. -%package -n libgdbus -Summary: Dbus library +%package -n libsyscommon-devel +Summary: Header files for system common library License: Apache-2.0 - -%description -n libgdbus -Internal dbus library - -%package -n libgdbus-devel -Summary: Header files for dbus library -License: Apache-2.0 -Requires: libgdbus = %{version} +Requires: libsyscommon = %{version} Requires: pkgconfig(gio-2.0) Requires: pkgconfig(gio-unix-2.0) -%description -n libgdbus-devel -Development header files for dbus library. +%description -n libsyscommon-devel +Development header files for system common library. %prep %setup -q @@ -62,21 +55,22 @@ touch debugsources.list %postun -p /sbin/ldconfig -%files -n libgdbus +%files %defattr(-,root,root,-) %if 0%{?_with_tizen} %manifest %{name}.manifest %endif %license LICENSE.Apache-2.0 -%{_libdir}/libgdbus.so.* +%{_libdir}/libsyscommon.so.* -%files -n libgdbus-devel +%files -n libsyscommon-devel %defattr(-,root,root,-) %if 0%{?_with_tizen} %manifest %{name}.manifest %endif %license LICENSE.Apache-2.0 -%{_libdir}/libgdbus.so -%{_includedir}/libgdbus/dbus-system.h -%{_includedir}/libgdbus/dbus-systemd.h -%{_libdir}/pkgconfig/libgdbus.pc +%{_libdir}/libsyscommon.so +%{_includedir}/libsyscommon/dbus-system.h +%{_includedir}/libsyscommon/dbus-systemd.h +%{_includedir}/libsyscommon/systemd-state.h +%{_libdir}/pkgconfig/libsyscommon.pc diff --git a/src/libgdbus/CMakeLists.txt b/src/libgdbus/CMakeLists.txt deleted file mode 100644 index 9baa020..0000000 --- a/src/libgdbus/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(libgdbus C) - -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "${PREFIX}/bin") -SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include") -SET(VERSION 4.1) - -SET(libgdbus_SRCS - dbus-system.c - dbus-systemd.c -) -SET(HEADERS - dbus-system.h - dbus-systemd.h -) - -# CHECK PKG -INCLUDE(FindPkgConfig) -pkg_check_modules(gdbus REQUIRED - glib-2.0 - gio-2.0 - dlog - gio-unix-2.0) - -FOREACH(flag ${gdbus_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") - -# LIBRARY -ADD_LIBRARY(${PROJECT_NAME} SHARED ${libgdbus_SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gdbus_LDFLAGS} "-ldl" pthread) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fPIC") -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION}) -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME gdbus) - -# INSTALL -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) - -# CONGIFURE FILE -FOREACH(flag ${gdbus_INCLUDE_DIRS}) - SET(GDBUS_INCLUDEDIR "${GDBUS_INCLUDEDIR} -I${flag}") -ENDFOREACH(flag) - -FOREACH(flag ${gdbus_LIBRARIES}) - SET(GDBUS_LIBS "${GDBUS_LIBS} -l${flag}") -ENDFOREACH(flag) - -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -# HEADER -FOREACH(hfile ${HEADERS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME}) -ENDFOREACH(hfile) diff --git a/src/libsystemd/systemd-state.c b/src/libsystemd/systemd-state.c new file mode 100644 index 0000000..0a6c744 --- /dev/null +++ b/src/libsystemd/systemd-state.c @@ -0,0 +1,60 @@ +/* + * libsyscommon + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "shared/log.h" + +#define SYSTEMD_DBUS_METHOD_SYSTEM_STATE "SystemState" +#define SYSTEMD_STATE_RUNNING "running" +#define SYSTEMD_STATE_DEGRADED "degraded" + +int check_system_boot_finished(void) +{ + char *state = NULL; + int ret = 0; + size_t len; + GVariant *reply = NULL; + + reply = systemd_get_manager_property(SYSTEMD_DBUS_METHOD_SYSTEM_STATE); + if (!reply) { + _E("Failed to get system state: No reply"); + goto err; + } + if (!dh_get_param_from_var(reply, "s", &state)) { + _E("Failed to get system state(%s)", g_variant_get_type_string(reply)); + goto err; + } + + _I("System state=%s", state); + + len = strlen(state) + 1; + if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) || + !strncmp(state, SYSTEMD_STATE_DEGRADED, len)) + ret = 1; + else + ret = 0; + +err: + if (reply) + g_variant_unref(reply); + free(state); + + return ret; +} diff --git a/src/libsystemd/systemd-state.h b/src/libsystemd/systemd-state.h new file mode 100644 index 0000000..54b4217 --- /dev/null +++ b/src/libsystemd/systemd-state.h @@ -0,0 +1,35 @@ +/* + * libsyscommon + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __SYSTEMD_STATE_H__ +#define __SYSTEMD_STATE_H__ + +#include "dbus-systemd.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int check_system_boot_finished(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif __SYSTEMD_STATE_H__ -- 2.7.4 From 8579156d01d9fbabae9b893f97460ecaec1d5f2a Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 1 Jul 2019 15:36:44 +0900 Subject: [PATCH 14/16] Remove unused SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED Change-Id: I43f23baf7d8f159f76bc139889fceff7b8b0740a --- src/libgdbus/dbus-system.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 1dec188..af75e27 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -56,7 +56,6 @@ #define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" #define SYSTEMD_DBUS_DEST "org.freedesktop.systemd1" #define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_DEST ".Manager" -#define SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED "StartupFinished" /******************************************************************************* * -- 2.7.4 From 7fa4a7ab027f5a082aefdaaba0f3648f8b717610 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 30 Jul 2019 14:16:19 +0900 Subject: [PATCH 15/16] Change sensitivity interface to fix dbus error Change-Id: Iefbd48ad9031388c149b5584d93c7398e5dae3d6 Signed-off-by: lokilee73 --- src/libgdbus/dbus-system.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index af75e27..4c260e7 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -138,7 +138,7 @@ /* Touch service */ #define DEVICED_PATH_TOUCH DEVICED_OBJECT_PATH"/Touch" -#define DEVICED_INTERFACE_TOUCH DEVICED_INTERFACE_NAME".Touch" +#define DEVICED_INTERFACE_TOUCH DEVICED_INTERFACE_NAME".touch" /* Thermal service: operatioins about temperature */ #define DEVICED_PATH_TEMPERATURE DEVICED_OBJECT_PATH"/Temperature" -- 2.7.4 From 052ae076539ff8205f305a0e93de68d9d265942a Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 14 Aug 2019 16:52:22 +0900 Subject: [PATCH 16/16] libgdbus: modified to support unicast signal Change-Id: I36085cf3d0f4e8e0fd3d78abc259b758112e9720 Signed-off-by: sanghyeok.oh --- src/libgdbus/dbus-system.c | 33 +++------------------------------ src/libgdbus/dbus-system.h | 3 +-- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/libgdbus/dbus-system.c b/src/libgdbus/dbus-system.c index 7ed53ba..3e325e1 100644 --- a/src/libgdbus/dbus-system.c +++ b/src/libgdbus/dbus-system.c @@ -1813,35 +1813,8 @@ static GVariant* _append_variant(const char *signature, const char *param[]) return ret; } -int dbus_handle_broadcast_dbus_signal(const char *path, - const char *iface, - const char *name, - const char *signature, - const char *param[]) -{ - dbus_handle_s *dh = NULL; - GError *err = NULL; - gboolean ret = 0; - GVariant *var = NULL; - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - if (signature && param) - var = _append_variant(signature, param); - ret = g_dbus_connection_emit_signal(dh->conn, NULL, path, iface, name, var, &err); - if (err) { - _E("%d %s\n", ret, err ? err->message : NULL); - g_error_free(err); - } - - return ret; -} - -int dbus_handle_broadcast_dbus_signal_var(const char *path, +int dbus_handle_broadcast_dbus_signal(const char *dest, + const char *path, const char *iface, const char *name, GVariant *param) @@ -1856,7 +1829,7 @@ int dbus_handle_broadcast_dbus_signal_var(const char *path, return -1; } - ret = g_dbus_connection_emit_signal(dh->conn, NULL, path, iface, name, param, &err); + ret = g_dbus_connection_emit_signal(dh->conn, dest, path, iface, name, param, &err); if (err) { _E("%d %s\n", ret, err ? err->message : NULL); g_error_free(err); diff --git a/src/libgdbus/dbus-system.h b/src/libgdbus/dbus-system.h index 4c260e7..3478605 100644 --- a/src/libgdbus/dbus-system.h +++ b/src/libgdbus/dbus-system.h @@ -501,8 +501,7 @@ int dbus_handle_signal_ctx_add_timeout(sig_ctx *ctx, int timeout); GVariant *dbus_handle_make_simple_array(const char *sig, int *param); -int dbus_handle_broadcast_dbus_signal(const char *path, const char *iface, const char *name, const char *signature, const char *param[]); -int dbus_handle_broadcast_dbus_signal_var(const char *path, const char *iface, const char *name, GVariant *param); +int dbus_handle_broadcast_dbus_signal(const char *dest, const char *path, const char *iface, const char *name, GVariant *param); typedef struct { -- 2.7.4