Add dbus-send-receive-test package 59/243159/3 submit/tizen/20200903.111639
authorINSUN PYO <insun.pyo@samsung.com>
Thu, 3 Sep 2020 11:13:48 +0000 (20:13 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Thu, 3 Sep 2020 11:15:20 +0000 (20:15 +0900)
Change-Id: I52d092c6365e1933e3b176aaf1d2b6c856693b29

CMakeLists.txt
packaging/session-utils.spec
src/dbus-send-receive-test/CMakeLists.txt [new file with mode: 0644]
src/dbus-send-receive-test/dbus-send-receive-test.c [new file with mode: 0644]
units/dbus-send-receive-test.conf [new file with mode: 0644]

index 36312fba8c793072caad0cdc196b45f298869688..d5c16b45008db3939c86349517add3fa3a580246 100644 (file)
@@ -4,3 +4,4 @@ PROJECT(session-utils C)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
 ADD_SUBDIRECTORY(src/dbus-activation-stop-test)
+ADD_SUBDIRECTORY(src/dbus-send-receive-test)
index c8b34abedf365cf614b9ca9f229775d532236143..694c9739fcc7386750c5631ebe069275b7d56d07 100644 (file)
@@ -32,6 +32,14 @@ Summary: dbus activation stop test.
 This package provices the test code of dbus activation stopping.
 
 
+###############################################################################
+%package -n dbus-send-receive-test
+Summary: dbus send and receive test.
+
+%description -n dbus-send-receive-test
+This package provices the test code of dbus send and receive.
+
+
 ###############################################################################
 %prep
 %setup -q
@@ -57,6 +65,9 @@ mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d
 install -m 644 units/dbus-activation-stop-test.service %{buildroot}%{_unitdir}/
 install -m 644 units/dbus-activation-stop-test.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/
 
+mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d
+install -m 644 units/dbus-send-receive-test.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/
+
 
 ###############################################################################
 %files
@@ -73,10 +84,17 @@ install -m 644 units/dbus-activation-stop-test.conf %{buildroot}%{_sysconfdir}/d
 %{_unitdir}/dbus-activation-stop-test.service
 
 
+###############################################################################
+%files -n dbus-send-receive-test
+%license LICENSE.Apache-2.0
+%manifest session-utils.manifest
+%config %{_sysconfdir}/dbus-1/system.d/dbus-send-receive-test.conf
+%{_bindir}/dbus-send-receive-test
+
+
 ###############################################################################
 %files -n g-debug-fatal-warnings
 %license LICENSE.Apache-2.0
 %manifest session-utils.manifest
 /etc/systemd/user.conf.d/g-debug-fatal-warnings.conf
 /etc/systemd/system.conf.d/g-debug-fatal-warnings.conf
-
diff --git a/src/dbus-send-receive-test/CMakeLists.txt b/src/dbus-send-receive-test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5f38721
--- /dev/null
@@ -0,0 +1,22 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(dbus-send-receive-test C)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+  glib-2.0
+  gio-2.0
+  libsystemd
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+
+ADD_EXECUTABLE(${PROJECT_NAME} dbus-send-receive-test.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -pie)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin
+               PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+               GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
diff --git a/src/dbus-send-receive-test/dbus-send-receive-test.c b/src/dbus-send-receive-test/dbus-send-receive-test.c
new file mode 100644 (file)
index 0000000..a679565
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2016 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 <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib-unix.h>
+
+#include <systemd/sd-daemon.h>
+
+#define NAME "org.tizen.dbus-send-receive-test"
+#define PATH "/org/tizen/dbustest"
+#define INTERFACE "org.tizen.dbustest"
+#define METHOD "send"
+
+static void name_acquire(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       fprintf (stderr, "name acquire : %s\n", name);
+}
+
+static void name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       fprintf (stderr, "name lost : %s\n", name);
+}
+
+static void method_call_handler (GDBusConnection *connection,
+                                                                const gchar *sender,
+                                                                const gchar *object_path,
+                                                                const gchar *interface_name,
+                                                                const gchar *method_name,
+                                                                GVariant *parameters,
+                                                                GDBusMethodInvocation *invocation,
+                                                                gpointer user_data)
+{
+       gint input;
+
+       g_variant_get(parameters, "(i)", &input);
+       printf ("%s:%d\n", method_name, input);
+
+       g_dbus_method_invocation_return_value (invocation, g_variant_new("(i)", input));
+}
+
+static const GDBusInterfaceVTable vtable =
+{
+       method_call_handler
+};
+
+static int dbus_server()
+{
+       int owner_id;
+       GError *error = NULL;
+       GMainLoop *mainloop;
+       guint registration_id;
+       GDBusConnection *conn = NULL;
+       GDBusNodeInfo *introspection_data;
+
+       gchar *xml = "<node>"
+               "  <interface name= 'org.tizen.dbustest'>"
+               "    <method name= 'send'>"
+               "      <arg type= 'i' name= 'input' direction= 'in'/>"
+               "      <arg type= 'i' name= 'result' direction= 'out'/>"
+               "    </method>"
+               "  </interface>"
+               "</node>";
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (!conn || error) {
+               fprintf (stderr, "failed to get system bus\n");
+               return -1;
+       }
+
+       introspection_data = g_dbus_node_info_new_for_xml (xml, NULL);
+       if (!introspection_data) {
+               fprintf (stderr, "g_dbus_node_info_new_for_xml fails\n");
+               return -1;
+       }
+
+       registration_id = g_dbus_connection_register_object (conn, PATH, introspection_data->interfaces[0], &vtable, NULL, NULL, NULL);
+       if (registration_id == 0) {
+               fprintf (stderr, "g_dbus_connection_register_object fails\n");
+               return -1;
+       }
+
+       owner_id = g_bus_own_name_on_connection(conn, "org.tizen.dbus-send-receive-test", G_BUS_NAME_OWNER_FLAGS_NONE, name_acquire, name_lost, NULL, NULL);
+       if (owner_id == 0) {
+               fprintf (stderr, "g_bus_own_name_on_connection fails\n");
+               return -1;
+       }
+
+       mainloop = g_main_loop_new(NULL, FALSE);
+       g_main_loop_run(mainloop);
+
+       g_bus_unown_name (owner_id);
+       g_dbus_node_info_unref (introspection_data);
+       g_main_loop_unref(mainloop);
+
+       return 0;
+}
+
+static int dbus_client()
+{
+       gint result;
+       GError *error = NULL;
+       GVariant *reply;
+       GDBusConnection *conn;
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (!conn || error) {
+               fprintf (stderr, "failed to get system bus\n");
+               return -1;
+       }
+
+       reply = g_dbus_connection_call_sync(conn, NAME, PATH, INTERFACE, METHOD, g_variant_new("(i)", 1), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (!reply || error) {
+               fprintf (stderr, "g_dbus_connection_call_sync fails\n");
+               return -1;
+       }
+
+       g_variant_get (reply, "(i)", &result);
+       printf ("reply %d\n", result);
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+
+       if (argc != 2) {
+               printf ("Usage %s [server|client]\n", argv[0]);
+               exit (0);
+       }
+
+       if (strcmp(argv[1], "server") == 0)
+               return dbus_server();
+
+       if (strcmp(argv[1], "client") == 0)
+               return dbus_client();
+
+       return 0;
+}
diff --git a/units/dbus-send-receive-test.conf b/units/dbus-send-receive-test.conf
new file mode 100644 (file)
index 0000000..6962932
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="org.tizen.dbus-send-receive-test"/>
+        <allow send_destination="org.tizen.dbus-send-receive-test"/>
+    </policy>
+    <policy context="default">
+        <deny own="org.tizen.dbus-send-receive-test"/>
+        <deny send_destination="org.tizen.dbus-send-receive-test"/>
+    </policy>
+</busconfig>