From 4dcef9437244c835c833dbb514b05159f0d5a483 Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Tue, 30 Apr 2019 16:40:13 +0900 Subject: [PATCH] Add define to enable/disalbe on-demand service Change-Id: I85debe67908c010275ce03412271cea463d4ff72 --- packaging/capi-media-controller.spec | 28 ++++++++++++++++++++++++---- packaging/mediacontroller2.service | 14 ++++++++++++++ src/media_controller_ipc.c | 4 ++++ svc/CMakeLists.txt | 3 +++ svc/daemon/media_controller_main.c | 13 +++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) mode change 100755 => 100644 packaging/capi-media-controller.spec create mode 100755 packaging/mediacontroller2.service diff --git a/packaging/capi-media-controller.spec b/packaging/capi-media-controller.spec old mode 100755 new mode 100644 index 3821647..0c0b3fe --- a/packaging/capi-media-controller.spec +++ b/packaging/capi-media-controller.spec @@ -1,12 +1,13 @@ Name: capi-media-controller Summary: A media controller library in Tizen Native API -Version: 0.1.86 +Version: 0.1.87 Release: 1 Group: Multimedia/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: mediacontroller.service Source2: mediacontroller.socket +Source3: mediacontroller2.service BuildRequires: cmake BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(dlog) @@ -23,7 +24,8 @@ BuildRequires: pkgconfig(cynara-session) BuildRequires: pkgconfig(uuid) BuildRequires: pkgconfig(capi-appfw-app-control) -%define upgrade_script_path /usr/share/upgrade/scripts +# socket activation enable(1), disable(0) +%define on_demand 1 %description This package provides a media controller library in Tizen Native API @@ -59,7 +61,12 @@ export LDFLAGS+=" -lgcov" %endif MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \ +%if %{on_demand} + -DON_DEMAND_SOCKET_ACTIVATION=YES +%else + -DON_DEMAND_SOCKET_ACTIVATION=NO +%endif %__make %{?jobs:-j%jobs} @@ -69,12 +76,21 @@ rm -rf %{buildroot} # Daemon & socket activation mkdir -p %{buildroot}%{_unitdir} +%if %{on_demand} mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants +%else +mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants +%endif + # change +%if %{on_demand} install -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/mediacontroller.service install -m 644 %{SOURCE2} %{buildroot}%{_unitdir}/mediacontroller.socket ln -s ../mediacontroller.socket %{buildroot}%{_unitdir}/sockets.target.wants/mediacontroller.socket - +%else +install -m 644 %{SOURCE3} %{buildroot}%{_unitdir}/mediacontroller.service +ln -s ../mediacontroller.service %{buildroot}%{_unitdir}/multi-user.target.wants/mediacontroller.service +%endif %post @@ -91,8 +107,12 @@ ln -s ../mediacontroller.socket %{buildroot}%{_unitdir}/sockets.target.wants/med %defattr(-,root,root,-) %{_bindir}/mediacontroller %{_unitdir}/mediacontroller.service +%if %{on_demand} %{_unitdir}/mediacontroller.socket %{_unitdir}/sockets.target.wants/mediacontroller.socket +%else +%{_unitdir}/multi-user.target.wants/mediacontroller.service +%endif %license LICENSE.APLv2.0 %files devel diff --git a/packaging/mediacontroller2.service b/packaging/mediacontroller2.service new file mode 100755 index 0000000..247b794 --- /dev/null +++ b/packaging/mediacontroller2.service @@ -0,0 +1,14 @@ +[Unit] +Description=Media controller +Wants=wait-mount@opt-usr.service +After=wait-mount@opt-usr.service + +[Service] +User=multimedia_fw +Group=multimedia_fw +SmackProcessLabel=System +ExecStart=/usr/bin/mediacontroller +Type=simple + +[Install] +WantedBy=multi-user.target diff --git a/src/media_controller_ipc.c b/src/media_controller_ipc.c index cfe695c..03b5642 100644 --- a/src/media_controller_ipc.c +++ b/src/media_controller_ipc.c @@ -475,14 +475,17 @@ RETRY: int mc_ipc_service_connect(mc_priv_type_e priv_type) { int ret = MEDIA_CONTROLLER_ERROR_NONE; +#ifdef _ON_DEMAND_SOCKET_ACTIVATION int sockfd = -1; struct sockaddr_un serv_addr; unsigned int retrycount = 0; +#endif ret = __make_service_connection(priv_type); mc_retvm_if(ret == MEDIA_CONTROLLER_ERROR_NONE, ret, "service is already running!"); mc_retvm_if(ret == MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED, ret, "Permission deny!"); +#ifdef _ON_DEMAND_SOCKET_ACTIVATION /* If can't make connection to service, the service activation is needed */ /* Create Socket */ @@ -517,6 +520,7 @@ int mc_ipc_service_connect(mc_priv_type_e priv_type) ret = __make_service_connection(priv_type); mc_retvm_if(ret == MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED, ret, "Permission deny!"); } +#endif return ret; } diff --git a/svc/CMakeLists.txt b/svc/CMakeLists.txt index 5a239c6..647d643 100755 --- a/svc/CMakeLists.txt +++ b/svc/CMakeLists.txt @@ -27,6 +27,9 @@ ENDIF("${ARCH}" MATCHES "^arm.*") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DTIZEN_DEBUG") ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64") +IF(ON_DEMAND_SOCKET_ACTIVATION) +ADD_DEFINITIONS("-D_ON_DEMAND_SOCKET_ACTIVATION") +ENDIF(ON_DEMAND_SOCKET_ACTIVATION) SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") diff --git a/svc/daemon/media_controller_main.c b/svc/daemon/media_controller_main.c index 65cf425..009f9d9 100755 --- a/svc/daemon/media_controller_main.c +++ b/svc/daemon/media_controller_main.c @@ -14,7 +14,9 @@ * limitations under the License. */ +#ifdef _ON_DEMAND_SOCKET_ACTIVATION #include +#endif #include "media_controller_private.h" #include "media_controller_socket.h" @@ -22,6 +24,8 @@ #include "media_controller_cynara.h" GMainLoop *g_mc_mainloop = NULL; + +#ifdef _ON_DEMAND_SOCKET_ACTIVATION static int g_mc_timer_id = 0; #define MC_MAIN_TIMEOUT_SEC_60 60 @@ -84,14 +88,17 @@ static int __mc_main_create_socket_activation(void) return -1; } } +#endif int main(int argc, char **argv) { GThread *svc_thread = NULL; +#ifdef _ON_DEMAND_SOCKET_ACTIVATION int fd = -1; int client_fd = -1; struct sockaddr_in client_addr; int client_addr_size = 0; +#endif mc_debug_fenter(); @@ -103,6 +110,7 @@ int main(int argc, char **argv) return -1; } +#ifdef _ON_DEMAND_SOCKET_ACTIVATION fd = __mc_main_create_socket_activation(); if (fd < 0) { mc_error("Failed to socket creation"); @@ -112,12 +120,15 @@ int main(int argc, char **argv) if (client_fd == -1) mc_error("accept failed"); } +#endif /* Create media controller service thread */ svc_thread = g_thread_new("mc_svc_thread", (GThreadFunc)mc_svc_thread, NULL); +#ifdef _ON_DEMAND_SOCKET_ACTIVATION /* Create Timer */ __mc_main_create_timer(g_mc_timer_id); +#endif mc_debug("*** Media Controller Daemon is running ***"); @@ -126,7 +137,9 @@ int main(int argc, char **argv) g_thread_join(svc_thread); g_main_loop_unref(g_mc_mainloop); +#ifdef _ON_DEMAND_SOCKET_ACTIVATION __mc_main_destroy_timer(g_mc_timer_id); +#endif mc_cynara_finish(); mc_debug("*** Media Controller Daemon is stopped ***"); -- 2.7.4