core: gdbus: Add new gdbus function to send broadcast signal 64/174364/5
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 20 Mar 2018 07:59:34 +0000 (16:59 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 5 Apr 2018 09:50:49 +0000 (18:50 +0900)
Add new following new function in order to send broadcast signal
through d-bus interface:
- int pass_gdbus_send_broadcast_signal(char *path, char *interface,
char *method, GVariant *arg)

Change-Id: I4e08a984f234fb4557e94f446e2d0aea86afc768
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
include/pass/gdbus-util.h
src/core/gdbus-util.c

index 306e859083ae93dc66b7f98fcfdca6c3cd8b9964..f6be0b9d9c576e75193bb5429290775618d66481 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef __GDBUS_UTIL_H__
 #define __GDBUS_UTIL_H__
 
+#include <glib.h>
 #include <gio/gio.h>
 #include <stdbool.h>
 
@@ -51,6 +52,9 @@ int pass_gdbus_connect_signal(gpointer instance, int num_signals,
                struct pass_gdbus_signal_info *signal_infos);
 void pass_gdbus_disconnect_signal(gpointer instance, int num_signals,
                struct pass_gdbus_signal_info *signal_infos);
+int pass_gdbus_send_broadcast_signal(char *path, char *interface,
+               char *method, GVariant *arg);
+
 SystemPassCore *pass_gdbus_get_instance_core(void);
 void pass_gdbus_put_instance_core(SystemPassCore **instance);
 SystemPassPmqos *pass_gdbus_get_instance_pmqos(void);
index 42d21b83749b590c601bf6913aa33f4ab293d5a4..6a672db4611e38013e7521f0069e09068ebc25bc 100644 (file)
@@ -188,6 +188,45 @@ void pass_gdbus_disconnect_signal(gpointer instance, int num_signals,
        }
 }
 
+int pass_gdbus_send_broadcast_signal(char *path, char *interface, char *method,
+                                       GVariant *arg)
+{
+       GDBusMessage *message = NULL;
+       GError *err = NULL;
+       int ret;
+
+       if (!path || !interface || !method || !arg) {
+               _E("invalid parameter\n");
+               return -EINVAL;
+       }
+
+       if (!g_dbus_sys_conn) {
+               _E("cannot get the dbus connection to system message bus\n");
+               return -ENOSYS;
+       }
+
+       /* Make the dbus message to send broadcast signal */
+       message = g_dbus_message_new_signal(path, interface, method);
+       if (!message) {
+               _E("failed to allocate new %s.%s signal", interface, method);
+               return -EPERM;
+       }
+       g_dbus_message_set_body(message, arg);
+
+       /* Send broadcast signal */
+       ret = g_dbus_connection_send_message(g_dbus_sys_conn, message,
+                               G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
+       if (!ret) {
+               _E("failed to broadcast [%s][%d]", method, arg);
+               g_object_unref(message);
+               return -ECOMM;
+       }
+
+       g_object_unref(message);
+
+       return 0;
+}
+
 static void put_instance(gpointer *instance)
 {
        g_object_unref(*instance);