Add define to enable/disalbe on-demand service 68/205268/7
authorjiyong.min <jiyong.min@samsung.com>
Tue, 30 Apr 2019 07:40:13 +0000 (16:40 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 7 May 2019 02:52:47 +0000 (11:52 +0900)
Change-Id: I85debe67908c010275ce03412271cea463d4ff72

packaging/capi-media-controller.spec [changed mode: 0755->0644]
packaging/mediacontroller2.service [new file with mode: 0755]
src/media_controller_ipc.c
svc/CMakeLists.txt
svc/daemon/media_controller_main.c

old mode 100755 (executable)
new mode 100644 (file)
index 3821647..0c0b3fe
@@ -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 (executable)
index 0000000..247b794
--- /dev/null
@@ -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
index cfe695c..03b5642 100644 (file)
@@ -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;
 }
index 5a239c6..647d643 100755 (executable)
@@ -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}")
 
index 65cf425..009f9d9 100755 (executable)
@@ -14,7 +14,9 @@
 * limitations under the License.
 */
 
+#ifdef _ON_DEMAND_SOCKET_ACTIVATION
 #include <systemd/sd-daemon.h>
+#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 ***");