From 0c456e6a7cd3e11f7c017a4aee2994f4985b3d05 Mon Sep 17 00:00:00 2001 From: Wonkeun Oh Date: Mon, 10 Jul 2017 16:22:16 +0900 Subject: [PATCH] Added On-demand launch feature using the socket_activation Change-Id: I0961165568f1d75131ce918af30cde6f7ec7088b --- configure.ac | 5 ++ ism/extras/wayland_immodule/wayland_imcontext.c | 63 +++++++++++++++++++++++++ ism/src/Makefile.am | 4 +- ism/src/scim_socket.cpp | 44 +++++++++++++++++ ism/src/scim_socket.h | 5 ++ packaging/isf.spec | 1 + 6 files changed, 121 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 515406e..58313fa 100644 --- a/configure.ac +++ b/configure.ac @@ -368,6 +368,11 @@ AC_ARG_ENABLE(include-libwebsocket, enable_libwebsocket=no, enable_libwebsocket=yes) +# Check systemd library +PKG_CHECK_MODULES(SYSTEMD, [libsystemd], + [ISF_HAS_SYSTEMD=yes], + [ISF_HAS_SYSTEMD=no]) + if test "$ISF_HAS_VCONF" = "yes"; then AC_DEFINE(HAVE_VCONF,1,[Have VConf functions.]) fi diff --git a/ism/extras/wayland_immodule/wayland_imcontext.c b/ism/extras/wayland_immodule/wayland_imcontext.c index 5babf4a..95289cb 100644 --- a/ism/extras/wayland_immodule/wayland_imcontext.c +++ b/ism/extras/wayland_immodule/wayland_imcontext.c @@ -32,6 +32,14 @@ #ifdef HAVE_VCONF #include #endif +#include +#include +#include +#include +#include +#include +#include + #include "isf_debug.h" #include "wayland_imcontext.h" #include "tizen_profile.h" @@ -56,6 +64,7 @@ #define VCONFKEY_AUTOPERIOD_ALLOW_BOOL "file/private/isf/autoperiod_allow" #define VCONFKEY_AUTOCAPITAL_ALLOW_BOOL "file/private/isf/autocapital_allow" +#define SOCK_PATH "/run/.isf/scim-panel-socket" typedef enum { INPUT_LANG_URDU, @@ -2506,6 +2515,56 @@ keyboard_mode_changed_cb (keynode_t *key, void* data) } #endif +#ifdef SOCKET_ACTIVATION +static int activate_socket () { + int s; + struct sockaddr_un svr; + int len; + int r; + int cnt = 5; + int flag; + + LOGD("socket_activate start"); + s = socket(AF_UNIX, SOCK_STREAM, 0); + if (s == -1) { + LOGW("socket error"); + return -1; + } + + flag = fcntl(s, F_GETFL, NULL); + flag |= O_NONBLOCK; + fcntl(s, F_SETFL, flag); + + svr.sun_family = AF_UNIX; + strcpy(svr.sun_path, SOCK_PATH); + len = sizeof(svr); + + r = connect(s, (struct sockaddr *)&svr, len); + if (r == -1) { + LOGD("connect error"); + close(s); + return -1; + } + + while (cnt > 0) { + struct timeval s1; + + gettimeofday(&s1, NULL); + LOGD("%d %06d\n", (int)s1.tv_sec, (int)s1.tv_usec); + + r = send(s, (const void *)&s1, sizeof(s1), 0); + if (r == -1) { + LOGW("send error"); + break; + } + cnt--; + } + + close(s); + return 0; +} +#endif + void wayland_im_initialize () { register_key_handler (); @@ -2706,6 +2765,10 @@ wayland_im_context_focus_in(Ecore_IMF_Context *ctx) ecore_imf_context_input_panel_enabled_get(ctx), ecore_imf_context_input_panel_show_on_demand_get (ctx)); +#ifdef SOCKET_ACTIVATION + activate_socket (); +#endif + if (!set_focus(ctx)) { LOGW("ctx : %p. Fail to set focus!", ctx); return; diff --git a/ism/src/Makefile.am b/ism/src/Makefile.am index 3356d47..c1d7afd 100644 --- a/ism/src/Makefile.am +++ b/ism/src/Makefile.am @@ -179,7 +179,8 @@ libscim@SCIM_EPOCH@_la_CXXFLAGS = @EVAS_CFLAGS@ \ @TZPLATFORM_CONFIG_CFLAGS@ \ @PKGMGR_INFO_CFLAGS@ \ @VCONF_CFLAGS@ \ - @GLIB_CFLAGS@ + @GLIB_CFLAGS@ \ + @SYSTEMD_CFLAGS@ libscim@SCIM_EPOCH@_la_LDFLAGS = -version-info $(SCIM_CURRENT):$(SCIM_REVISION):$(SCIM_AGE) \ -export-dynamic \ @@ -196,6 +197,7 @@ libscim@SCIM_EPOCH@_la_LDFLAGS = -version-info $(SCIM_CURRENT):$(SCIM_REVISION) @PKGMGR_INFO_LIBS@ \ @VCONF_LIBS@ \ @GLIB_LIBS@ \ + @SYSTEMD_LIBS@ \ -lstdc++ libscim@SCIM_EPOCH@_la_LIBADD = libltdlc.la libprofile.la diff --git a/ism/src/scim_socket.cpp b/ism/src/scim_socket.cpp index 3abae3a..8b12e2d 100644 --- a/ism/src/scim_socket.cpp +++ b/ism/src/scim_socket.cpp @@ -60,6 +60,7 @@ #include "scim_private.h" #include "scim.h" +#include #ifdef LOG_TAG # undef LOG_TAG @@ -741,6 +742,34 @@ public: return ret >= 0; } + bool sd_socket (SocketFamily family, const SocketAddress &addr) { + int ret, n; + char pid[10]; + + snprintf(pid, sizeof(pid), "%d", getpid()); + setenv("LISTEN_PID", pid, 1); + n = sd_listen_fds (0); + if (n > 1) { + SCIM_DEBUG_SOCKET (1) << "Socket: Too many file descriptors received.\n"; + return false; + } else if (n == 1) { + m_no_close = false; + m_binded = true; + m_err = 0; + m_family = family; + m_address = addr; + ret = SD_LISTEN_FDS_START + 0; + int flag = fcntl (ret, F_GETFD, 0); + fcntl (ret, F_SETFD, flag|FD_CLOEXEC); + m_id = ret; + } else { + LOGW("No sd socket!!"); + SCIM_DEBUG_SOCKET (1) << "%d returned.\n" << n; + return false; + } + return true; + } + void close () { if (m_id < 0) return; @@ -923,6 +952,12 @@ Socket::create (SocketFamily family) return m_impl->create (family); } +bool +Socket::sd_socket (SocketFamily family, const SocketAddress &addr) +{ + return m_impl->sd_socket (family, addr); +} + void Socket::close () { @@ -994,6 +1029,15 @@ SocketServer::create (const SocketAddress &address) FD_SET (m_impl->max_fd, &(m_impl->active_fds)); m_impl->err = 0; return true; +#ifdef SOCKET_ACTIVATION + } else if (Socket::sd_socket (family, address)) { + m_impl->created = true; + m_impl->max_fd = Socket::get_id (); + FD_ZERO (&(m_impl->active_fds)); + FD_SET (m_impl->max_fd, &(m_impl->active_fds)); + m_impl->err = 0; + return true; +#endif } m_impl->err = Socket::get_error_number (); Socket::close (); diff --git a/ism/src/scim_socket.h b/ism/src/scim_socket.h index 3cb9250..171cbd2 100644 --- a/ism/src/scim_socket.h +++ b/ism/src/scim_socket.h @@ -328,6 +328,11 @@ protected: bool create (SocketFamily family); /** + * @brief Create an activation socket. + */ + bool sd_socket (SocketFamily family, const SocketAddress &addr); + + /** * @brief Close the socket. */ void close (); diff --git a/packaging/isf.spec b/packaging/isf.spec index e71defc..94ff73a 100644 --- a/packaging/isf.spec +++ b/packaging/isf.spec @@ -44,6 +44,7 @@ BuildRequires: pkgconfig(cynara-creds-socket) BuildRequires: pkgconfig(cynara-session) BuildRequires: pkgconfig(capi-appfw-package-manager) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(notification) Requires(postun): /sbin/ldconfig Requires: org.tizen.isf-kbd-mode-changer -- 2.7.4