system-server: Add system-server config/module to support system-service 48/325248/5
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 5 Jun 2025 07:25:13 +0000 (16:25 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 10 Jun 2025 05:42:32 +0000 (14:42 +0900)
To make deviced can be run on system-server, config and module files will be
generated if the flag 'enable_system_server' is defined as 1
in the deviced.spec file.

Change-Id: I424a513d9e97c42b34b5a6ac515c0012fb6443b9
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
CMakeLists.txt
packaging/deviced.spec
packaging/system-server-deviced.service [new file with mode: 0644]
src/core/system-server-deviced.c [new file with mode: 0644]

index 945829b367620823797fe9bf9d4e4823f0a9d247..d24f70ae25f1d3ecaa8b443c917f6dadf9e7a163 100644 (file)
@@ -78,6 +78,10 @@ SET(SRCS
        src/time/time-handler.c
 )
 
+IF(${ENABLE_SYSTEM_SERVER})
+       SET(SRCS ${SRCS} src/core/system-server-deviced.c)
+ENDIF()
+
 IF(DISPLAY_MODULE STREQUAL on)
        ADD_SOURCE(src/display DISPLAY_SRCS)
        SET(SRCS ${SRCS} ${DISPLAY_SRCS})
@@ -197,6 +201,10 @@ SET(PKG_MODULES
        argos_watchdog
 )
 
+IF(${ENABLE_SYSTEM_SERVER})
+       SET(PKG_MODULES "${PKG_MODULES} bundle tizen-core united-service")
+ENDIF()
+
 IF(DISPLAY_MODULE STREQUAL on)
        SET(PKG_MODULES ${PKG_MODULES} libinput capi-system-sensor)
 ENDIF()
@@ -247,10 +255,19 @@ ADD_DEFINITIONS("-DDEBUG")
 # Build libdeviced-common-private.so
 ADD_SUBDIRECTORY(src/shared)
 
-ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
 SET(deviced_LDFLAGS ${REQUIRED_PKGS_LDFLAGS})
+
+IF(${ENABLE_SYSTEM_SERVER})
+ADD_LIBRARY("system-server-deviced" SHARED ${SRCS})
+TARGET_LINK_LIBRARIES("system-server-deviced" ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private)
+TARGET_LINK_LIBRARIES("system-server-deviced" PUBLIC "-lpthread")
+INSTALL(TARGETS "system-server-deviced" DESTINATION ${SYSTEM_SERVER_DIR}/mod COMPONENT RuntimeLibraries)
+ELSE()
+LIST(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/system-server-deviced.c")
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private)
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+ENDIF()
 
 INSTALL(DIRECTORY DESTINATION ${MAKE_INSTALL_PREFIX}${DD_PLUGIN_PATH})
 
@@ -316,9 +333,14 @@ ENDIF()
 CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/org.tizen.system.deviced.conf       DESTINATION /etc/dbus-1/system.d)
+IF(${ENABLE_SYSTEM_SERVER})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/system-server-deviced.service
+       DESTINATION ${SYSTEM_SERVER_DIR}/conf)
+ELSE()
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/org.tizen.system.deviced.service DESTINATION /usr/share/dbus-1/system-services)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced.service                  DESTINATION /usr/lib/systemd/system)
+ENDIF()
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/org.tizen.system.deviced.conf       DESTINATION /etc/dbus-1/system.d)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-ffs-test-daemon.service DESTINATION /usr/lib/systemd/system)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-test.socket             DESTINATION /usr/lib/systemd/system)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/strs                             DESTINATION /etc/mtp-responder-dummy)
index be19af1ee6009c64b2a41995eec928a37b037f6d..a741b4961ebadd3dde681b775295bd1c8b917cfa 100644 (file)
@@ -1,3 +1,6 @@
+%define enable_system_server 0
+%define _system_server_dir %{_datadir}/united-service/system-server
+
 # display, extcon, power, usb are always enabled
 
 #Just For debugging
@@ -48,6 +51,11 @@ BuildRequires:  pkgconfig(cmocka)
 BuildRequires:  pkgconfig(gtest)
 BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(security-manager)
+%if %{enable_system_server}
+BuildRequires:  pkgconfig(bundle)
+BuildRequires:  pkgconfig(tizen-core)
+BuildRequires:  pkgconfig(united-service)
+%endif
 
 Requires: %{name}-tools = %{version}-%{release}
 %{?systemd_requires}
@@ -177,6 +185,10 @@ It can test resource-driver and plugin backend call test for deviced.
        -DDEVICE_BOARD_MODULE=on \
        -DDEVICE_INPUT_MODULE=on \
        -DCRITICAL_LOG_MODULE=on \
+%if %{enable_system_server}
+       -DSYSTEM_SERVER_DIR=%{_system_server_dir} \
+%endif
+       -DENABLE_SYSTEM_SERVER=%{enable_system_server} \
        #eol
 
 %build
@@ -198,7 +210,9 @@ sed -ie s,"##PLUGIN_LIB_DIR##,$DD_PLUGIN_PATH,g" isu/usr-lib-deviced.mount
 rm -rf %{buildroot}
 %make_install
 
+%if "%{enable_system_server}" != "1"
 %install_service multi-user.target.wants deviced.service
+%endif
 # usb_module condition is removed because it is always on
 %if %{?sdb_prestart} == on
 %install_service basic.target.wants sdb-prestart.service
@@ -279,11 +293,16 @@ mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so
 %manifest %{name}.manifest
 %license LICENSE.Apache-2.0
 %license LICENSE.MIT
-%{_bindir}/deviced
 %{_libdir}/libdeviced-common-private.so
+%if %{enable_system_server}
+%{_system_server_dir}/mod/libsystem-server-deviced.so
+%{_system_server_dir}/conf/system-server-deviced.service
+%else
+%{_bindir}/deviced
 %{_unitdir}/multi-user.target.wants/deviced.service
 %{_unitdir}/deviced.service
 %{_datadir}/dbus-1/system-services/org.tizen.system.deviced.service
+%endif
 %dir %{plugindir}
 %if %{?sdb_prestart} == on
 %{_unitdir}/sdb-prestart.service
diff --git a/packaging/system-server-deviced.service b/packaging/system-server-deviced.service
new file mode 100644 (file)
index 0000000..4354af3
--- /dev/null
@@ -0,0 +1,7 @@
+[United-Service]
+Description=deviced plugin for system-server
+Name=system-server-deviced
+Type=notify
+Mode=normal
+Path=/usr/share/united-service/system-server/mod/libsystem-server-deviced.so
+Priority=1
\ No newline at end of file
diff --git a/src/core/system-server-deviced.c b/src/core/system-server-deviced.c
new file mode 100644 (file)
index 0000000..79a38ae
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2025 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 <service.h>
+
+#include "core/log.h"
+#include "core/deviced.h"
+
+static void system_server_create_callback(service_h service, void *user_data)
+{
+       _I("Create deviced for system-server");
+       deviced_init(NULL);
+}
+
+static void system_server_destroy_callback(service_h service, void *user_data)
+{
+       _I("Destroy deviced for system-server");
+       deviced_exit(NULL);
+}
+
+static void system_server_message_callback(service_h service,
+               const char *sender, bundle *envelope, void *user_data)
+{
+       _I("Message from sender(%s)", sender);
+}
+
+__attribute__ ((visibility("default")))
+int USD_MOD_INIT(const char *name)
+{
+       int ret = 0;
+       service_lifecycle_callback_s system_server_callback = {
+               .create = system_server_create_callback,
+               .destroy = system_server_destroy_callback,
+               .message = system_server_message_callback,
+       };
+
+       _I("Start deviced");
+
+       ret = service_register(name, &system_server_callback, NULL);
+       if (ret != SERVICE_ERROR_NONE) {
+               _E("Failed to create service: name(%s), ret(%d)", name, ret);
+               return ret;
+       }
+
+       return SERVICE_ERROR_NONE;
+}
+
+__attribute__ ((visibility("default")))
+void USD_MOD_SHUTDOWN(const char *name)
+{
+       _I("Shutdown deviced");
+
+       service_unregister(name);
+}
\ No newline at end of file