From 6c87ef41968b7107eb1ca1f189bdc8567b79011e Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 3 Sep 2020 20:13:48 +0900 Subject: [PATCH] Add dbus-send-receive-test package Change-Id: I52d092c6365e1933e3b176aaf1d2b6c856693b29 --- CMakeLists.txt | 1 + packaging/session-utils.spec | 20 ++- src/dbus-send-receive-test/CMakeLists.txt | 22 +++ .../dbus-send-receive-test.c | 157 ++++++++++++++++++ units/dbus-send-receive-test.conf | 12 ++ 5 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 src/dbus-send-receive-test/CMakeLists.txt create mode 100644 src/dbus-send-receive-test/dbus-send-receive-test.c create mode 100644 units/dbus-send-receive-test.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 36312fb..d5c16b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/packaging/session-utils.spec b/packaging/session-utils.spec index c8b34ab..694c973 100644 --- a/packaging/session-utils.spec +++ b/packaging/session-utils.spec @@ -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 index 0000000..5f38721 --- /dev/null +++ b/src/dbus-send-receive-test/CMakeLists.txt @@ -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 index 0000000..a679565 --- /dev/null +++ b/src/dbus-send-receive-test/dbus-send-receive-test.c @@ -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 +#include +#include + +#include +#include +#include + +#include + +#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 = "" + " " + " " + " " + " " + " " + " " + ""; + + 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 index 0000000..6962932 --- /dev/null +++ b/units/dbus-send-receive-test.conf @@ -0,0 +1,12 @@ + + + + + + + + + + + -- 2.34.1