Add api to apply font config system-wide 40/172440/2
authorWonki Kim <wonki_.kim@samsung.com>
Fri, 9 Mar 2018 08:46:36 +0000 (17:46 +0900)
committerWonki Kim <wonki_.kim@samsung.com>
Wed, 14 Mar 2018 05:23:04 +0000 (14:23 +0900)
there is socket comm logic running between setting app and efl_config daemon
to apply font config to system wide.

however system application have a logic that contains system dependency
so that this patch add api to replace the logic.

Change-Id: I804563c2aaf1b640386daa2f7488ddf13ede4538
Signed-off-by: Wonki Kim <wonki_.kim@samsung.com>
inc/CMakeLists.txt
inc/efl_extension_config.h [new file with mode: 0644]
packaging/efl-extension.spec
src/CMakeLists.txt
src/efl_extension_config.c [new file with mode: 0644]

index 234ceb49c5cef8d8e6c4216515d341407b0e5567..8abcd71a5de157592c99fd66f61d3df6c652702d 100644 (file)
@@ -1,5 +1,6 @@
 SET(UNIFIED_LIB_INCS
        efl_extension_events.h
+       efl_extension_config.h
 )
 SET(MOBILE_LIB_INCS
        mobile/eext_floatingbutton.h
diff --git a/inc/efl_extension_config.h b/inc/efl_extension_config.h
new file mode 100644 (file)
index 0000000..773f25a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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 __EFL_EXTENSION_CONFIG_H__
+#define __EFL_EXTENSION_CONFIG_H__
+
+#include <Elementary.h>
+
+#ifdef EAPI
+# undef EAPI
+#endif
+
+#ifdef _WIN32
+# ifdef EFL_EXTENSION_BUILD
+#  ifdef DLL_EXPORT
+#   define EAPI __declspec(dllexport)
+#  else
+#   define EAPI
+#  endif /* ! DLL_EXPORT */
+# else
+#  define EAPI __declspec(dllimport)
+# endif /* ! EFL_EXTENSION_BUILD */
+#else
+# ifdef __GNUC__
+#  if __GNUC__ >= 4
+#   define EAPI __attribute__ ((visibility("default")))
+#  else
+#   define EAPI
+#  endif
+# else
+#  define EAPI
+# endif
+#endif /* ! _WIN32 */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+EAPI Eina_Bool eext_config_font_set(char *name, int size);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __EFL_EXTENSION_CONFIG_H__ */
index 8ef16a4c3afabcae29bff1cc9ac675be9ea24b90..ed604c77879c09112b8a585d107c5b8a698304ea 100644 (file)
@@ -14,6 +14,8 @@ BuildRequires:  pkgconfig(ecore)
 BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(fontconfig)
 BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(libsystemd)
+
 BuildRequires:  cmake
 BuildRequires:  gettext
 BuildRequires:  pkgconfig(cairo)
index 315ba23839dd50521ab741ba24c395dbeef8d2b6..08da29b97a325d887a991ccc3cc30e9249ccc67e 100755 (executable)
@@ -3,6 +3,7 @@ add_definitions(-DEFL_EO_API_SUPPORT=1 -DEFL_BETA_API_SUPPORT=1)
 SET(UNIFIED_LIB_SRCS
        efl_extension.c
        efl_extension_events.c
+       efl_extension_config.c
        )
 SET(UNIFIED_EO_FILES
        )
@@ -90,6 +91,7 @@ ELSEIF(DEFINED WITH_WAYLAND)
                elementary
                cairo
                fontconfig
+               libsystemd
                )
 ELSEIF(DEFINED WIN32)
        message("Build on Windows")
diff --git a/src/efl_extension_config.c b/src/efl_extension_config.c
new file mode 100644 (file)
index 0000000..ad05647
--- /dev/null
@@ -0,0 +1,130 @@
+#include "efl_extension.h"
+#include "efl_extension_private.h"
+
+#include <systemd/sd-login.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/un.h>
+#include <fcntl.h>
+
+#define EFL_CONFIG_SOCK_PATH "/run/user_ext/%d/system_share"
+#define EFL_CONFIG_SOCKET_FILE ".efl-config.sock"
+
+Eina_Bool _is_in_system_session()
+{
+   int ret = 0;
+   char *slice = NULL;
+
+   ret = sd_pid_get_slice(getpid(), &slice);
+   if (0 <= ret && slice)
+     {
+        if (0 == strncmp(slice, "system.slice", strlen("system.slice")))
+          {
+             free(slice);
+             return EINA_TRUE;
+          }
+     }
+   else
+     {
+        ERR("sd_pid_get_slice() Fail(%d)", ret);
+     }
+
+   free(slice);
+   return EINA_FALSE;
+}
+
+Eina_Bool _get_active_uid(uid_t *uid)
+{
+   int active_user_count = 0;
+   uid_t *active_user_list = NULL;
+
+   active_user_count = sd_get_active_uids(&active_user_list);
+   /* the number of active users is 1 in tizen3.0 */
+   if (1 == active_user_count && active_user_list)
+     {
+        *uid = active_user_list[0];
+        INF("active uid = %d", *uid);
+     }
+   else
+     {
+        ERR("sd_get_active_uids() Fail(%d)", active_user_count);
+        free(active_user_list);
+        return EINA_FALSE;
+     }
+
+   return EINA_TRUE;
+}
+
+EAPI Eina_Bool
+eext_config_font_set(char *name, int size)
+{
+   int fd;
+   char sock_file[1024] = {0};
+   static char buf[1024] ={0};
+
+   uid_t active_uid = getuid();
+   Eina_Bool ret = EINA_FALSE;
+
+   if (_is_in_system_session() == EINA_TRUE)
+     {
+        if (_get_active_uid(&active_uid) == EINA_FALSE)
+          {
+             ERR("get active uid fail");
+             return EINA_FALSE;
+          }
+     }
+
+   snprintf(sock_file, sizeof(sock_file), EFL_CONFIG_SOCK_PATH"/%s",
+         active_uid,
+         EFL_CONFIG_SOCKET_FILE);
+
+   snprintf(buf, sizeof(buf), "font_name: %s, font_size: %d", name, size);
+
+   do
+     {
+        int r, size, flags;
+        struct sockaddr_un server_addr;
+
+        fd = socket(PF_UNIX, SOCK_STREAM, 0);
+        if (fd < 0)
+          {
+             ERR("socket[%d] error :%d", fd, errno);
+             break;
+          }
+
+        flags = fcntl(fd, F_GETFL, 0);
+        if (flags == -1)
+          flags = 0;
+        r = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+        if (0 != r)
+          ERR("fcntl fail : %d", errno);
+
+        bzero(&server_addr, sizeof(server_addr));
+        server_addr.sun_family = AF_UNIX;
+        snprintf(server_addr.sun_path, sizeof(server_addr.sun_path), "%s",
+                 sock_file);
+
+        r = connect(fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
+        if (r != 0)
+          {
+              ERR("connect error : %d, %d", r, errno);
+              close(fd);
+              break;
+           }
+
+         size = write(fd, buf, strlen(buf));
+         if (size <= 0)
+           {
+              ERR("write fail : %d", errno);
+           }
+         else
+           {
+              ret = EINA_TRUE;
+           }
+         close(fd);
+   } while (0);
+
+   return ret;
+}
+