system-server: Add system-server config/module to support system-service 84/324884/5
authorSangYoun Kwak <sy.kwak@samsung.com>
Thu, 22 May 2025 05:08:20 +0000 (14:08 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 29 May 2025 12:12:15 +0000 (21:12 +0900)
To make sensord 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 sensord.spec. Below are the generated config and module files:
 * config: /usr/share/united-service/system-server/conf/system-server-sensord.service
 * module: /usr/share/united-service/system-server/mod/libsystem-server-sensord.so

Also, if the flag 'enable_system_server' is 1, then the files below will
be excluded from the generated package since sensord should be not run
as separated service:
 * /usr/bin/sensord
 * /usr/lib/systemd/system/sensord.service
 * /usr/lib/systemd/system/sensord.socket
 * /usr/lib/systemd/system/multi-user.target.wants/sensord.service
 * /usr/lib/systemd/system/sockets.target.wants/sensord.socket

Change-Id: Ice9359893b61e18078516347df59533c37be1715
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
CMakeLists.txt
packaging/sensord.spec
packaging/system-server-sensord.service [new file with mode: 0644]
src/server/CMakeLists.txt
src/server/system_server_sensord.cpp [new file with mode: 0644]

index 106caf3c47ba60a32063b720daefd468077f9cff..785232e85747bc0f43549669b4c1f77082f13c98 100644 (file)
@@ -31,3 +31,8 @@ INSTALL(
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor
        FILES_MATCHING PATTERN "*.h"
 )
+
+IF(${ENABLE_SYSTEM_SERVER})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/system-server-sensord.service
+       DESTINATION ${SYSTEM_SERVER_DIR}/conf)
+ENDIF()
index 189f4b934a4145cc6ba61f1de6a30ef998c991c3..5028bb06fa8b51ce16b4b8552f7c9284c6008ca9 100644 (file)
@@ -1,3 +1,6 @@
+%define enable_system_server 0
+%define _system_server_dir %{_datadir}/united-service/system-server
+
 Name:       sensord
 Summary:    Sensor daemon
 Version:    4.0.54
@@ -21,6 +24,11 @@ BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-session)
 BuildRequires:  pkgconfig(hal-api-sensor)
 BuildRequires:  pkgconfig(hal-api-common)
+%if %{enable_system_server}
+BuildRequires:  pkgconfig(bundle)
+BuildRequires:  pkgconfig(tizen-core)
+BuildRequires:  pkgconfig(united-service)
+%endif
 
 Provides:   %{name}-profile_mobile = %{version}-%{release}
 Provides:   %{name}-profile_wearable = %{version}-%{release}
@@ -71,7 +79,14 @@ Sensor functional testing
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 
-%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DCMAKE_HAL_LIBDIR_PREFIX=%{_hal_libdir}
+%cmake . \
+       -DMAJORVER=${MAJORVER} \
+       -DFULLVER=%{version} \
+       -DCMAKE_HAL_LIBDIR_PREFIX=%{_hal_libdir} \
+%if %{enable_system_server}
+       -DSYSTEM_SERVER_DIR=%{_system_server_dir} \
+%endif
+       -DENABLE_SYSTEM_SERVER=%{enable_system_server}
 make %{?_smp_mflags}
 
 %install
@@ -79,15 +94,16 @@ make %{?_smp_mflags}
 
 mkdir -p %{buildroot}%{_unitdir}
 
+%if "%{enable_system_server}" != "1"
 install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}
 install -m 0644 %SOURCE2 %{buildroot}%{_unitdir}
+%install_service multi-user.target.wants sensord.service
+%install_service sockets.target.wants sensord.socket
+%endif
 
 mkdir -p %{buildroot}%{_sysconfdir}/sensord
 install -m 644 conf/auto_rotation.conf   %{buildroot}/etc/sensord/auto_rotation.conf
 
-%install_service multi-user.target.wants sensord.service
-%install_service sockets.target.wants sensord.socket
-
 ln -s libsensor.so.%{version} %{buildroot}/%{_libdir}/libsensor.so.2
 ln -s libsensor.so.%{version} %{buildroot}/%{_libdir}/libsensor.so.1
 
@@ -106,11 +122,16 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall
 %{_libdir}/libsensord-shared.so
 %{_libdir}/sensor/fusion/libsensor-fusion.so
 %{_libdir}/sensor/physical/libsensor-physical.so
+%if %{enable_system_server}
+%{_system_server_dir}/mod/libsystem-server-sensord.so
+%{_system_server_dir}/conf/system-server-sensord.service
+%else
 %{_bindir}/sensord
 %{_unitdir}/sensord.service
 %{_unitdir}/sensord.socket
 %{_unitdir}/multi-user.target.wants/sensord.service
 %{_unitdir}/sockets.target.wants/sensord.socket
+%endif
 %config %{_sysconfdir}/sensord/auto_rotation.conf
 %license LICENSE.APLv2
 
diff --git a/packaging/system-server-sensord.service b/packaging/system-server-sensord.service
new file mode 100644 (file)
index 0000000..85c598e
--- /dev/null
@@ -0,0 +1,7 @@
+[United-Service]
+Description=sensord plugin for system-server
+Name=system-server-sensord
+Type=notify
+Mode=normal
+Path=/usr/share/united-service/system-server/mod/libsystem-server-sensord.so
+Priority=1
index 4b38e0598167177df840690d0229a09ac7d7688d..753383fc5377d9b962cf6f1096b352c7e6407631 100644 (file)
@@ -3,6 +3,10 @@ PROJECT(sensord CXX)
 
 SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd cynara-client cynara-creds-socket cynara-session vconf hal-api-sensor hal-api-common")
 
+IF(${ENABLE_SYSTEM_SERVER})
+SET(DEPENDENTS "${DEPENDENTS} bundle tizen-core united-service")
+ENDIF()
+
 INCLUDE(FindPkgConfig)
 PKG_CHECK_MODULES(SERVER_PKGS REQUIRED ${DEPENDENTS})
 
@@ -25,7 +29,16 @@ INCLUDE_DIRECTORIES(
 )
 
 FILE(GLOB SERVER_SRCS *.cpp)
+
+IF(${ENABLE_SYSTEM_SERVER})
+ADD_LIBRARY("system-server-sensord" SHARED ${SENSOR_SRCS} ${SERVER_SRCS})
+TARGET_LINK_LIBRARIES("system-server-sensord" ${SERVER_PKGS_LDFLAGS} ${CMAKE_DL_LIBS} "sensord-shared")
+TARGET_LINK_LIBRARIES("system-server-sensord" PUBLIC "-lpthread -ldl")
+INSTALL(TARGETS "system-server-sensord" DESTINATION ${SYSTEM_SERVER_DIR}/mod COMPONENT RuntimeLibraries)
+ELSE()
+LIST(REMOVE_ITEM SERVER_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/system_server_sensord.cpp")
 ADD_EXECUTABLE(${PROJECT_NAME} ${SENSOR_SRCS} ${SERVER_SRCS})
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SERVER_PKGS_LDFLAGS} ${CMAKE_DL_LIBS} "sensord-shared")
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
+ENDIF()
diff --git a/src/server/system_server_sensord.cpp b/src/server/system_server_sensord.cpp
new file mode 100644 (file)
index 0000000..dc67e7b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * sensord
+ *
+ * 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 <sensor_log.h>
+
+#include "sensord.h"
+
+static void system_server_create_callback(service_h service, void *user_data)
+{
+       _I("Create sensord for system-server");
+       sensord_init();
+}
+
+static void system_server_destroy_callback(service_h service, void *user_data)
+{
+       _I("Destroy sensord for system-server");
+       sensord_exit();
+}
+
+static void system_server_message_callback(service_h service,
+               const char *sender, bundle *envelope, void *user_data)
+{
+       _I("Message from sender(%s)", sender);
+}
+
+extern "C"
+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 sensord");
+
+       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;
+}
+
+extern "C"
+void USD_MOD_SHUTDOWN(const char *name)
+{
+       _I("Shutdown sensord");
+
+       service_unregister(name);
+}