daemon: Add initial support for being launched as a Tizen service application
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 18 May 2023 11:19:20 +0000 (20:19 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Wed, 24 May 2023 01:36:23 +0000 (10:36 +0900)
A meson option('service-app') is added to support it.

Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
meson_options.txt
packaging/espp-service.spec
src/daemon/espp_service.c
src/daemon/meson.build

index bced3864e01a967626a9a8c47e2950f6b9ef9ab4..db5fd736d4a83002f89ab81a1e7f42ee4123ecc2 100644 (file)
@@ -1,3 +1,4 @@
 option('version', type: 'string', value: '0.0.0', description: 'ESPP service version')
 option('sock-path', type: 'string', value: '/tmp/espp_service.socket', description: 'ESPP service socket path')
-option('dlog', type: 'boolean', value: true, description: 'Use dlog')
\ No newline at end of file
+option('dlog', type: 'boolean', value: true, description: 'Use dlog')
+option('service-app', type: 'boolean', value: false, description: 'Daemon is launched as Tizen service app')
index 0986ee88ac99ccded2c6c8e64911eee487b19170..542f48b2fd61aeb99705b5ef47e6cdf62876a13f 100644 (file)
@@ -16,6 +16,9 @@ BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(json-glib-1.0)
 BuildRequires: pkgconfig(esplusplayer)
+%if "%{use_service_app}" == "1"
+BuildRequires: pkgconfig(capi-appfw-service-application)
+%endif
 
 %description
 ESPP service package contains daemon binary which uses esplusplayer to render audio/video buffers and it's client library
@@ -48,6 +51,9 @@ meson setup --auto-features=disabled \
   --datadir=%{_datadir} \
   -Dversion=%{version} \
   -Dsock-path=/run/espp_service.sock \
+%if "%{use_service_app}" == "1"
+  -Dservice-app=true \
+%endif
   build
 
 ninja -C build
index 775ad737341deaea5ade9bc2b9e8a6c30df0143a..a9434703fc8c69db2661574aac48f6adc295c521 100644 (file)
@@ -19,7 +19,9 @@
 #include <stdio.h>
 #include <getopt.h>
 #include <sys/stat.h>
-
+#ifdef USE_SERVICE_APP
+#include <service_app.h>
+#else
 static struct sigaction g_int_old_action;
 static struct sigaction g_abrt_old_action;
 static struct sigaction g_segv_old_action;
@@ -28,6 +30,7 @@ static struct sigaction g_sys_old_action;
 static struct sigaction g_xcpu_old_action;
 
 espp_service_s *g_svc;
+#endif
 
 static void print_usage()
 {
@@ -69,6 +72,7 @@ static int get_option(int argc, char **argv, espp_service_s *svc)
        return 0;
 }
 
+#ifndef USE_SERVICE_APP
 static void __sa_handler(int signal)
 {
        LOG_ERROR("-------------------- signal[%d] --------------------", signal);
@@ -161,6 +165,63 @@ static void run(espp_service_s *svc)
 
        LOG_DEBUG_LEAVE();
 }
+#else
+static bool svc_app_create_cb(void *user_data)
+{
+       espp_service_s *svc = (espp_service_s *)user_data;
+
+       ASSERT(svc);
+       LOG_INFO("svc[%p]", svc);
+
+       if (espp_service_init_socket(svc) != 0)
+               return false;
+
+       svc->fd_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, espp_service_handle_destroy_cb);
+
+       return true;
+}
+
+static void svc_app_terminate_cb(void *user_data)
+{
+       espp_service_s *svc = (espp_service_s *)user_data;
+
+       ASSERT(svc);
+       LOG_INFO("svc[%p]", svc);
+
+       g_hash_table_destroy(svc->fd_table);
+       espp_service_deinit_socket(svc);
+
+       LOG_WARNING("exit");
+}
+
+static void svc_app_control_cb(app_control_h app_control, void *user_data)
+{
+       char *app_id = NULL;
+       char *operation = NULL;
+       espp_service_s *svc = (espp_service_s *)user_data;
+
+       ASSERT(svc);
+       LOG_INFO("app_control[%p], svc[%p]", app_control, svc);
+
+       if (app_control_get_app_id(app_control, &app_id) != APP_CONTROL_ERROR_NONE) {
+               LOG_ERROR("failed to app_control_get_app_id()");
+               goto exit;
+       }
+
+       if (app_control_get_operation(app_control, &operation) != APP_CONTROL_ERROR_NONE) {
+               LOG_ERROR("failed to app_control_get_operation()");
+               goto exit;
+       }
+
+       LOG_INFO("app_id[%s] operation[%s]", app_id, operation);
+
+exit:
+       if (app_id)
+               free(app_id);
+       if (operation)
+               free(operation);
+}
+#endif
 
 int main(int argc, char *argv[])
 {
@@ -176,6 +237,7 @@ int main(int argc, char *argv[])
                goto exit;
        }
 
+#ifndef USE_SERVICE_APP
        g_svc = &svc;
 
        initialize_signals();
@@ -194,6 +256,15 @@ int main(int argc, char *argv[])
        g_hash_table_destroy(svc.fd_table);
        espp_service_deinit_socket(&svc);
        deinitialize_signals();
+#else
+       service_app_lifecycle_callback_s event_cb = {0, };
+       event_cb.create = svc_app_create_cb;
+       event_cb.terminate = svc_app_terminate_cb;
+       event_cb.app_control = svc_app_control_cb;
+
+       LOG_WARNING("Use service_app_main()");
+       return service_app_main(argc, argv, &event_cb, &svc);
+#endif
 
 exit:
        LOG_WARNING("exit");
index 9196b928445cee0bf339106460138a3557a07706..96d6dfec5eb343445689762d08bb8a2b88bf2d58 100644 (file)
@@ -6,13 +6,27 @@ espp_service_sources = [
   'espp_service_msg.c',
 ]
 
+daemon_deps = common_deps
+
+message('================ daemon options ================')
+
+if get_option('service-app')
+  message('service-app option is enabled, set USE_SERVICE_APP')
+  conf_data.set('USE_SERVICE_APP', true)
+  service_app_dep = dependency('capi-appfw-service-application', required: true)
+  daemon_deps += [service_app_dep]
+endif
+
+message('================================================')
+
 thread_dep = dependency('threads', required: true)
 espp_dep = dependency('esplusplayer', required: true)
+daemon_deps += [thread_dep, espp_dep]
 
 executable('espp-service',
   espp_service_sources,
   include_directories : [configinc],
-  dependencies : [common_deps, thread_dep, espp_dep],
+  dependencies : daemon_deps,
   install: true,
   install_rpath : libdir_path,
   pie : true,