OnDemand sound-server 13/81013/13
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 23 Aug 2016 06:04:53 +0000 (15:04 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 23 Aug 2016 06:15:49 +0000 (15:15 +0900)
1. Split focus_server code from sound_server (go back to original)
2. Modifiy service files (sound-server systemd service will not be exists)
3. Add dbus activation service file (org.tizen.SoundServer.service) for sound-server
4. Shutdown sound-server if no use (check every 10 seconds....)
5. Move boot semaphore and  pa_ready / sound_server_ready handling code to focus_server
6. Modifications for coding rules
7. Fix creat() fd leak
8. Apply lwipc code to mm_sound_focus_server.c

Change-Id: I946ddf504541a4839056fc6a412ae9d5eb2b9a34

21 files changed:
Makefile.am
configure.ac
focus_server/Makefile.am [new file with mode: 0644]
focus_server/include/mm_sound_mgr_focus.h [moved from server/include/mm_sound_mgr_focus.h with 100% similarity]
focus_server/include/mm_sound_mgr_focus_dbus.h [moved from server/include/mm_sound_mgr_focus_dbus.h with 100% similarity]
focus_server/include/mm_sound_mgr_focus_ipc.h [moved from server/include/mm_sound_mgr_focus_ipc.h with 88% similarity]
focus_server/mm_sound_focus_server.c [new file with mode: 0644]
focus_server/mm_sound_mgr_focus.c [moved from server/mm_sound_mgr_focus.c with 99% similarity]
focus_server/mm_sound_mgr_focus_dbus.c [moved from server/mm_sound_mgr_focus_dbus.c with 96% similarity]
focus_server/mm_sound_mgr_focus_ipc.c [moved from server/mm_sound_mgr_focus_ipc.c with 100% similarity]
packaging/focus-server-tv.service [moved from packaging/sound-server-tv.service with 79% similarity]
packaging/focus-server.path [new file with mode: 0644]
packaging/focus-server.service [moved from packaging/sound-server.service with 82% similarity]
packaging/libmm-sound.spec
packaging/org.tizen.SoundServer.service [new file with mode: 0644]
packaging/sound-server.path [deleted file]
server/Makefile.am
server/include/mm_sound_thread_pool.h
server/mm_sound_mgr_ipc_dbus.c
server/mm_sound_server.c
server/mm_sound_thread_pool.c

index f4d256a..00f4cf7 100644 (file)
@@ -2,7 +2,8 @@ SUBDIRS = common \
                pkgconfig \
                . \
                server \
-               testsuite
+               testsuite \
+               focus_server
 
 lib_LTLIBRARIES = libmmfsound.la
 
index 85b1e6c..c2ac18b 100644 (file)
@@ -175,6 +175,7 @@ server/plugin/Makefile
 server/plugin/wav/Makefile
 server/plugin/ogg/Makefile
 server/plugin/tone/Makefile
+focus_server/Makefile
 pkgconfig/Makefile
 pkgconfig/mm-sound.pc
 pkgconfig/mm-keysound.pc
diff --git a/focus_server/Makefile.am b/focus_server/Makefile.am
new file mode 100644 (file)
index 0000000..796e673
--- /dev/null
@@ -0,0 +1,38 @@
+bin_PROGRAMS = focus_server
+focus_server_SOURCES = mm_sound_mgr_focus_ipc.c \
+                                               mm_sound_mgr_focus_dbus.c \
+                                               mm_sound_focus_server.c \
+                                               mm_sound_mgr_focus.c
+
+focus_server_CFLAGS = -I$(srcdir)/../include \
+                                         -I$(srcdir)/include \
+                                         $(MMCOMMON_CFLAGS) \
+                                         $(MMLOGSVR_CFLAGS) \
+                                         -DMMF_LOG_OWNER=0x004 \
+                                         -DMMF_DEBUG_PREFIX=\"MMF-SOUND\" \
+                                         -D__DEBUG_MODE__ -D__USE_LOGMANAGER__ \
+                                         $(GLIB2_CFLAGS) \
+                                         $(GIO_CFLAGS)
+
+focus_server_LDADD = $(MMLOGSVR_LIBS) \
+                    -ldl -lrt \
+                    $(MMCOMMON_LIBS) \
+                    $(GLIB2_LIBS) \
+                    $(GIO_LIBS) \
+                    $(srcdir)/../libmmfsound.la \
+                    $(srcdir)/../common/libmmfsoundcommon.la
+
+if USE_LWIPC
+focus_server_CFLAGS += $(LWIPC_CFLAGS) -DUSE_LWIPC
+focus_server_LDADD += $(LWIPC_LIBS)
+endif
+
+if USE_SECURITY
+focus_server_CFLAGS += $(SECURITY_CFLAGS) -DUSE_SECURITY
+focus_server_LDADD += $(SECURITY_LIBS)
+endif
+
+focus_server_DEPENDENCIES = $(srcdir)/../common/libmmfsoundcommon.la
+if !USE_PRELINK
+focus_server_CFLAGS += -fPIC -pie
+endif
similarity index 88%
rename from server/include/mm_sound_mgr_focus_ipc.h
rename to focus_server/include/mm_sound_mgr_focus_ipc.h
index 686459b..093e8f0 100644 (file)
@@ -35,31 +35,20 @@ typedef struct container_info
 } container_info_t;
 #endif
 
-//int __mm_sound_mgr_ipc_create_focus_node(mm_ipc_msg_t *msg);
 #ifdef SUPPORT_CONTAINER
 int __mm_sound_mgr_focus_ipc_register_focus(int client_pid, int handle_id, const char* stream_type, bool is_for_session, const char* container_name, int container_pid);
+int __mm_sound_mgr_focus_ipc_watch_focus(int pid, int handle_id, int focus_type, bool is_for_session, const char* container_name, int container_pid);
 #else
 int __mm_sound_mgr_focus_ipc_register_focus(int client_pid, int handle_id, const char* stream_type, bool is_for_session);
+int __mm_sound_mgr_focus_ipc_watch_focus(int pid, int handle_id, int focus_type, bool is_for_session);
 #endif
-//int __mm_sound_mgr_ipc_destroy_focus_node(mm_ipc_msg_t *msg);
-int __mm_sound_mgr_focus_ipc_unregister_focus(int pid, int handle_id);
 
 int __mm_sound_mgr_focus_ipc_set_focus_reacquisition(int pid, int handle_id, bool reacquisition);
-
 int __mm_sound_mgr_focus_ipc_get_acquired_focus_stream_type(int focus_type, char **stream_type, char **additional_info);
-
 int __mm_sound_mgr_focus_ipc_acquire_focus(int pid, int handle_id, int focus_type, const char* name );
-
 int __mm_sound_mgr_focus_ipc_release_focus(int pid, int handle_id, int focus_type, const char* name);
-//int __mm_sound_mgr_ipc_set_focus_watch_cb(mm_ipc_msg_t *msg);
-#ifdef SUPPORT_CONTAINER
-int __mm_sound_mgr_focus_ipc_watch_focus(int pid, int handle_id, int focus_type, bool is_for_session, const char* container_name, int container_pid);
-#else
-int __mm_sound_mgr_focus_ipc_watch_focus(int pid, int handle_id, int focus_type, bool is_for_session);
-#endif
-//int __mm_sound_mgr_ipc_unset_focus_watch_cb(mm_ipc_msg_t *msg);
 int __mm_sound_mgr_focus_ipc_unwatch_focus(int pid, int handle_id);
-
+int __mm_sound_mgr_focus_ipc_unregister_focus(int pid, int handle_id);
 int __mm_sound_mgr_focus_ipc_emergent_exit(int pid);
 
 #endif /* __MM_SOUND_MGR_FOCUS_IPC_H__ */
diff --git a/focus_server/mm_sound_focus_server.c b/focus_server/mm_sound_focus_server.c
new file mode 100644 (file)
index 0000000..2a27365
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Seungbae Shin <seungbae.shin@samsung.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <getopt.h>
+
+#include <mm_debug.h>
+
+#include <fcntl.h>
+#include <semaphore.h>
+
+#include "../include/mm_sound_common.h"
+#include "include/mm_sound_mgr_focus.h"
+#include "include/mm_sound_mgr_focus_dbus.h"
+
+#define USE_SYSTEM_SERVER_PROCESS_MONITORING
+
+typedef struct {
+    int startserver;
+    int printlist;
+    int testmode;
+} server_arg;
+
+static int _get_option(int argc, char **argv, server_arg *arg);
+static int _usage(int argc, char **argv);
+
+static struct sigaction sigint_action;  /* Backup pointer of SIGINT handler */
+static struct sigaction sigabrt_action; /* Backup pointer of SIGABRT signal handler */
+static struct sigaction sigsegv_action; /* Backup pointer of SIGSEGV fault signal handler */
+static struct sigaction sigterm_action; /* Backup pointer of SIGTERM signal handler */
+static struct sigaction sigsys_action;  /* Backup pointer of SIGSYS signal handler */
+static void _exit_handler(int sig);
+
+GMainLoop *g_mainloop;
+
+static void _mainloop_run()
+{
+       g_mainloop = g_main_loop_new(NULL, TRUE);
+       if (g_mainloop == NULL) {
+               debug_error("g_main_loop_new() failed\n");
+       }
+
+       g_main_loop_run(g_mainloop);
+}
+
+static sem_t* _sem_create_n_wait()
+{
+       sem_t* sem = NULL;
+
+       if ((sem = sem_open("booting-sound", O_CREAT, 0660, 0)) == SEM_FAILED) {
+               debug_error("error creating sem : %d", errno);
+               return NULL;
+       }
+
+       debug_msg("returning sem [%p]", sem);
+       return sem;
+}
+
+static int _get_option(int argc, char **argv, server_arg *arg)
+{
+       int c;
+       static struct option long_options[] = {
+               {"start", 0, 0, 'S'},
+               {"help", 0, 0, 'H'},
+               {"testmode", 0, 0, 'T'},
+               {0, 0, 0, 0}
+       };
+       memset(arg, 0, sizeof(server_arg));
+
+       arg->testmode = 0;
+
+       while (1) {
+               int opt_idx = 0;
+
+               c = getopt_long (argc, argv, "SFLHRUP:Tiurd", long_options, &opt_idx);
+               if (c == -1)
+                       break;
+               switch (c)
+               {
+               case 'S': /* Start daemon */
+                       arg->startserver = 1;
+                       break;
+               case 'T': /* Test mode */
+                       arg->testmode = 1;
+                       break;
+               case 'H': /* help msg */
+               default:
+                       return _usage(argc, argv);
+               }
+       }
+       if (argc == 1)
+               return _usage(argc, argv);
+       return 0;
+}
+
+//__attribute__ ((destructor))
+static void _exit_handler(int sig)
+{
+       switch (sig) {
+       case SIGINT:
+               sigaction(SIGINT, &sigint_action, NULL);
+               debug_error("signal(SIGINT) error");
+               break;
+       case SIGABRT:
+               sigaction(SIGABRT, &sigabrt_action, NULL);
+               debug_error("signal(SIGABRT) error");
+               break;
+       case SIGSEGV:
+               sigaction(SIGSEGV, &sigsegv_action, NULL);
+               debug_error("signal(SIGSEGV) error");
+               break;
+       case SIGTERM:
+               sigaction(SIGTERM, &sigterm_action, NULL);
+               debug_error("signal(SIGTERM) error");
+               break;
+       case SIGSYS:
+               sigaction(SIGSYS, &sigsys_action, NULL);
+               debug_error("signal(SIGSYS) error");
+               break;
+       default:
+               break;
+       }
+       raise(sig);
+}
+
+static int _usage(int argc, char **argv)
+{
+       fprintf(stderr, "Usage: %s [Options]\n", argv[0]);
+       fprintf(stderr, "\t%-20s: start focus server.\n", "--start,-S");
+       fprintf(stderr, "\t%-20s: help message.\n", "--help,-H");
+
+       return 1;
+}
+
+int main(int argc, char **argv)
+{
+       sem_t* sem = NULL;
+       server_arg serveropt;
+       struct sigaction action;
+#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
+       int pid;
+#endif
+#ifdef TIZEN_TV
+       int fd_ss_ready = -1;
+#endif
+
+       action.sa_handler = _exit_handler;
+       action.sa_flags = 0;
+       sigemptyset(&action.sa_mask);
+
+       if (_get_option(argc, argv, &serveropt))
+               return 1;
+
+       debug_warning("focus_server [%d] init \n", getpid());
+
+       if (serveropt.startserver) {
+               sem = _sem_create_n_wait();
+       }
+       /* Daemon process create */
+       if (!serveropt.testmode && serveropt.startserver) {
+#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
+               daemon(0,0); //chdir to ("/"), and close stdio
+#endif
+       }
+
+       /* focus Server Starts!!!*/
+       debug_warning("focus_server [%d] start \n", getpid());
+
+       signal(SIGPIPE, SIG_IGN); //ignore SIGPIPE
+
+#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
+       while (1) {
+               if ((pid = fork()) < 0) {
+                       fprintf(stderr, "Sub Fork Error\n");
+                       return 2;
+               } else if (pid == 0) {
+                       break;
+               } else if (pid > 0) {
+                       wait(&ret);
+                       fprintf(stderr, "Killed by signal [%05X]\n", ret);
+                       fprintf(stderr, "Daemon is run againg\n");
+               }
+       }
+#endif
+       sigaction(SIGABRT, &action, &sigabrt_action);
+       sigaction(SIGSEGV, &action, &sigsegv_action);
+       sigaction(SIGTERM, &action, &sigterm_action);
+       sigaction(SIGSYS, &action, &sigsys_action);
+
+       if (serveropt.startserver) {
+               MMSoundMgrFocusDbusInit();
+               MMSoundMgrFocusInit();
+       }
+
+       debug_warning("focus_server [%d] initialization complete...now, start running!!\n", getpid());
+
+       if (serveropt.startserver) {
+               unlink(PA_READY); // remove pa_ready file after focus-server init.
+
+               if (sem) {
+                       if (sem_post(sem) == -1) {
+                               debug_error("error sem post : %d", errno);
+                       } else {
+                               debug_msg("Ready to play booting sound!!!!");
+                       }
+               }
+
+#ifdef TIZEN_TV
+               /* FIXME : This code is moved from sound_server temporally for TV migration
+                                       As other modules which has dependancy on this file is cleared,
+                                       this code will be removed */
+               /* broadcast if we're ready */
+#ifdef USE_LWIPC
+               if (LwipcEventDone(SOUND_SERVER_READY) < 0) {
+                               debug_error("cannot create SOUND_SERVER_READY(sound_server_ready)");
+               } else {
+                               debug_warning("SOUND_SERVER_READY(%s) event was created", SOUND_SERVER_READY);
+               }
+#else
+               if ((fd_ss_ready = creat(SOUND_SERVER_READY, 0644)) != -1) {
+                       debug_warning("SOUND_SERVER_READY(%s) file was created", SOUND_SERVER_READY);
+                       close(fd_ss_ready);
+               } else {
+                       debug_error("cannot create SOUND_SERVER_READY(/tmp/.sound_server_ready)");
+               }
+#endif
+#endif
+
+               _mainloop_run();
+       }
+
+       debug_warning("focus_server [%d] terminating \n", getpid());
+
+       if (serveropt.startserver) {
+               MMSoundMgrFocusDbusFini();
+               MMSoundMgrFocusFini();
+       }
+
+       debug_warning("focus_server [%d] exit ----------------- END \n", getpid());
+
+       return 0;
+}
similarity index 99%
rename from server/mm_sound_mgr_focus.c
rename to focus_server/mm_sound_mgr_focus.c
index 71ac52a..a432765 100644 (file)
@@ -62,14 +62,14 @@ typedef struct {
                x = g_list_remove (x, node); \
                g_free (node); \
        } \
-} while(0)
+} while (0)
 
 #define UPDATE_FOCUS_TAKEN_INFO(x_postfix, x_node, x_pid, x_hid, x_by_session) do { \
        debug_msg("updating node[%p], taken_"#x_postfix"[%d] : pid = [%d], handle_id = [%d], is_for_session = [%d]", x_node, i, x_pid, x_hid, x_by_session); \
        x_node->taken_##x_postfix[i].pid = x_pid; \
        x_node->taken_##x_postfix[i].handle_id = x_hid; \
        x_node->taken_##x_postfix[i].by_session = x_by_session; \
-} while(0)
+} while (0)
 
 #ifdef SUPPORT_CONTAINER
 static void __set_container_data(int pid, int handle, const char* container_name, int container_pid)
@@ -174,14 +174,14 @@ static void __clear_focus_pipe(focus_node_t *node)
                filename2 = __get_focus_pipe_path(node->pid, node->handle_id, "r", true);
        }
        if (filename) {
-               if(remove(filename))
+               if (remove(filename))
                        debug_error("remove() failure, filename(%s), errno(%d)", filename, errno);
                else
                        debug_log("removed file(%s)", filename);
                free(filename);
        }
        if (filename2) {
-               if(remove(filename2))
+               if (remove(filename2))
                        debug_error("remove() failure, filename2(%s), errno(%d)", filename2, errno);
                else
                        debug_log("removed file(%s)", filename2);
@@ -783,7 +783,7 @@ int mm_sound_mgr_focus_destroy_node(const _mm_sound_mgr_focus_param_t *param)
                        } else {
                                for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
                                        if (node->taken_by_id[i].pid == param->pid) {
-                                               if(my_node->taken_by_id[i].pid) {
+                                               if (my_node->taken_by_id[i].pid) {
                                                /* If exists update the taken focus info to my victim node */
                                                        if (node->taken_by_id[i].by_session && !node->status) {
                                                                UPDATE_FOCUS_TAKEN_INFO(by_id, node, my_node->taken_by_id[i].pid, my_node->taken_by_id[i].handle_id, my_node->taken_by_id[i].by_session);
@@ -1079,7 +1079,7 @@ int mm_sound_mgr_focus_request_release(const _mm_sound_mgr_focus_param_t *param)
        }
 
        /* Check if there's activating focus for session for the same PID of incomming param*/
-       if(my_node->is_for_session) {
+       if (my_node->is_for_session) {
                for (list = g_focus_node_list; list != NULL; list = list->next) {
                        node = (focus_node_t *)list->data;
                        if (!node) {
@@ -1242,11 +1242,11 @@ int mm_sound_mgr_focus_emergent_exit(const _mm_sound_mgr_focus_param_t *param)
        g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
 
        list = g_focus_node_list;
-       while(list) {
+       while (list) {
                node = (focus_node_t *)list->data;
                if (node && (node->pid == param->pid)) {
                        debug_log("found pid node");
-                       if(node->is_for_watch) {
+                       if (node->is_for_watch) {
                                debug_log("clearing watch cb of pid(%d) handle(%d)", node->pid, node->handle_id);
                                __clear_focus_pipe(node);
                                g_focus_node_list = g_list_remove(g_focus_node_list, node);
similarity index 96%
rename from server/mm_sound_mgr_focus_dbus.c
rename to focus_server/mm_sound_mgr_focus_dbus.c
index 12ce404..c6af8b7 100644 (file)
@@ -235,16 +235,16 @@ static int _get_sender_pid(GDBusMethodInvocation* invocation)
        connection = g_dbus_method_invocation_get_connection(invocation);
        sender = g_dbus_method_invocation_get_sender(invocation);
 
-       debug_error ("connection = %p, sender = %s", connection, sender);
+       debug_error("connection = %p, sender = %s", connection, sender);
 
-       value = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
+       value = g_dbus_connection_call_sync(connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
                                                                                "org.freedesktop.DBus", "GetConnectionUnixProcessID",
                                                                                g_variant_new("(s)", sender, NULL), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
        if (value) {
                g_variant_get(value, "(u)", &pid);
-               debug_error ("Sender PID = [%d]", pid);
+               debug_error("Sender PID = [%d]", pid);
        } else {
-               debug_error ("err code = %d, err msg = %s", err->code, err->message);
+               debug_error("err code = %d, err msg = %s", err->code, err->message);
        }
        return pid;
 }
@@ -527,7 +527,7 @@ send_reply:
        debug_fleave();
 }
 
-static void handle_method_unwatch_focus (GDBusMethodInvocation* invocation)
+static void handle_method_unwatch_focus(GDBusMethodInvocation* invocation)
 {
        int ret = MM_ERROR_NONE;
        int pid = 0;
@@ -668,7 +668,7 @@ static int _mm_sound_mgr_focus_dbus_own_name(GBusType bus_type, const char* well
 
        debug_log("Own name (%s) for focus-server", wellknown_name);
 
-       oid = g_bus_own_name(bus_type, wellknown_name , G_BUS_NAME_OWNER_FLAGS_NONE,
+       oid = g_bus_own_name(bus_type, wellknown_name, G_BUS_NAME_OWNER_FLAGS_NONE,
                        on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
        if (oid <= 0) {
                debug_error("Dbus own name failed");
@@ -677,12 +677,14 @@ static int _mm_sound_mgr_focus_dbus_own_name(GBusType bus_type, const char* well
                *owner_id = oid;
        }
 
+       debug_log("OwnerID (%d) for focus-server", *owner_id);
+
        return MM_ERROR_NONE;
 }
 
 static void _mm_sound_mgr_focus_dbus_unown_name(guint oid)
 {
-       debug_log("Unown name for focus-server");
+       debug_log("Unown name for focus-server [%d]", oid);
        if (oid > 0) {
                g_bus_unown_name(oid);
        }
@@ -704,11 +706,11 @@ int __mm_sound_mgr_focus_dbus_get_stream_list(stream_list_t* stream_list)
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        if (!conn && err) {
                LOGE("g_bus_get_sync() error (%s)", err->message);
-               g_error_free (err);
+               g_error_free(err);
                ret = MM_ERROR_SOUND_INTERNAL;
                return ret;
        }
-       result = g_dbus_connection_call_sync (conn,
+       result = g_dbus_connection_call_sync(conn,
                                                        PA_BUS_NAME,
                                                        PA_STREAM_MANAGER_OBJECT_PATH,
                                                        PA_STREAM_MANAGER_INTERFACE,
@@ -731,11 +733,11 @@ int __mm_sound_mgr_focus_dbus_get_stream_list(stream_list_t* stream_list)
                i = 0;
                g_variant_iter_init(&iter, item);
                while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "&s", &name)) {
-                       debug_log ("name : %s", name);
+                       debug_log("name : %s", name);
                        stream_list->stream_types[i++] = strdup(name);
                }
-               g_variant_unref (item);
-               g_variant_unref (child);
+               g_variant_unref(item);
+               g_variant_unref(child);
 
                child = g_variant_get_child_value(result, 1);
                item = g_variant_get_variant(child);
@@ -743,11 +745,11 @@ int __mm_sound_mgr_focus_dbus_get_stream_list(stream_list_t* stream_list)
                i = 0;
                g_variant_iter_init(&iter, item);
                while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "i", &priority)) {
-                       debug_log ("priority : %d", priority);
+                       debug_log("priority : %d", priority);
                        stream_list->priorities[i++] = priority;
                }
-               g_variant_unref (item);
-               g_variant_unref (child);
+               g_variant_unref(item);
+               g_variant_unref(child);
 
                g_variant_unref(result);
        }
@@ -765,11 +767,11 @@ int MMSoundMgrFocusDbusInit(void)
                return MM_ERROR_SOUND_INTERNAL;
 
        if (_mm_sound_mgr_focus_dbus_own_name(G_BUS_TYPE_SYSTEM, BUS_NAME_FOCUS_SERVER, &focus_server_owner_id) != MM_ERROR_NONE) {
-               debug_error ("dbus own name for focus-server error\n");
+               debug_error("dbus own name for focus-server error\n");
                return MM_ERROR_SOUND_INTERNAL;
        }
        if (mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_AUDIO_CLIENT, AUDIO_EVENT_EMERGENT_EXIT, emergent_exit_signal_handler, NULL, NULL, &emergent_exit_subs_id) != MM_ERROR_NONE) {
-               debug_error ("dbus signal subscribe for emergent exit error\n");
+               debug_error("dbus signal subscribe for emergent exit error\n");
                return MM_ERROR_SOUND_INTERNAL;
        }
 
@@ -785,7 +787,7 @@ void MMSoundMgrFocusDbusFini(void)
        if (emergent_exit_subs_id != 0)
                mm_sound_dbus_signal_unsubscribe(emergent_exit_subs_id);
        _mm_sound_mgr_focus_dbus_unown_name(focus_server_owner_id);
-       g_dbus_node_info_unref (introspection_data);
+       g_dbus_node_info_unref(introspection_data);
 
        debug_leave();
 }
similarity index 79%
rename from packaging/sound-server-tv.service
rename to packaging/focus-server-tv.service
index ebf80a5..723ea1f 100644 (file)
@@ -1,5 +1,5 @@
 [Unit]
-Description=Start the sound profile service
+Description=Start the focus profile service
 DefaultDependencies=false
 After=factory-init.service pulseaudio.service
 
diff --git a/packaging/focus-server.path b/packaging/focus-server.path
new file mode 100644 (file)
index 0000000..1bcc261
--- /dev/null
@@ -0,0 +1,5 @@
+[Unit]
+Description=Path activation for the "focus-server" programme
+
+[Path]
+PathExists=/tmp/.pa_ready
similarity index 82%
rename from packaging/sound-server.service
rename to packaging/focus-server.service
index b3de83c..d11f4c1 100644 (file)
@@ -1,5 +1,5 @@
 [Unit]
-Description=Start the sound profile service
+Description=Start the focus profile service
 
 [Service]
 ExecStart=/usr/bin/focus_server -S
index 0284977..f75039a 100644 (file)
@@ -5,14 +5,15 @@ Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
-Source1:    sound-server.service
-Source2:    sound-server.path
-Source3:    focus-server.conf
-Source4:    sound-server.conf
+Source3:    sound-server.conf
+Source4:    focus-server.service
+Source5:    focus-server.path
+Source6:    focus-server.conf
 Requires: security-config
 %if "%{?tizen_profile_name}" == "tv"
-Source7:    sound-server-tv.service
+Source8:    focus-server-tv.service
 %endif
+Source9:    org.tizen.SoundServer.service
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 BuildRequires: pkgconfig(mm-common)
@@ -110,11 +111,13 @@ mkdir -p %{buildroot}/usr/share/license
 cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
 cp LICENSE.APLv2 %{buildroot}/usr/share/license/libmm-sound-tool
 mkdir -p %{buildroot}/etc/dbus-1/system.d/
-cp %{SOURCE3} %{buildroot}/etc/dbus-1/system.d/focus-server.conf
-cp %{SOURCE4} %{buildroot}/etc/dbus-1/system.d/sound-server.conf
+cp %{SOURCE3} %{buildroot}/etc/dbus-1/system.d/sound-server.conf
+cp %{SOURCE6} %{buildroot}/etc/dbus-1/system.d/focus-server.conf
 %if "%{?tizen_profile_name}" == "tv"
-cp %{SOURCE7} %{SOURCE1}
+cp %{SOURCE8} %{SOURCE4}
 %endif
+mkdir -p %{buildroot}/usr/share/dbus-1/system-services/
+cp %{SOURCE9} %{buildroot}/usr/share/dbus-1/system-services/org.tizen.SoundServer.service
 
 %make_install
 %if "%{?tizen_profile_name}" == "tv"
@@ -122,12 +125,12 @@ install -d %{buildroot}%{_unitdir}/sysinit.target.wants
 %else
 install -d %{buildroot}%{_unitdir}/multi-user.target.wants
 %endif
-install -m0644 %{SOURCE1} %{buildroot}%{_unitdir}/
-install -m0644 %{SOURCE2} %{buildroot}%{_unitdir}/
+install -m0644 %{SOURCE4} %{buildroot}%{_unitdir}/
+install -m0644 %{SOURCE5} %{buildroot}%{_unitdir}/
 %if "%{?tizen_profile_name}" == "tv"
-ln -sf ../sound-server.path %{buildroot}%{_unitdir}/sysinit.target.wants/sound-server.path
+ln -sf ../focus-server.path %{buildroot}%{_unitdir}/sysinit.target.wants/focus-server.path
 %else
-ln -sf ../sound-server.path %{buildroot}%{_unitdir}/multi-user.target.wants/sound-server.path
+ln -sf ../focus-server.path %{buildroot}%{_unitdir}/multi-user.target.wants/focus-server.path
 %endif
 %post
 /sbin/ldconfig
@@ -139,6 +142,7 @@ ln -sf ../sound-server.path %{buildroot}%{_unitdir}/multi-user.target.wants/soun
 %manifest libmm-sound.manifest
 %defattr(-,root,root,-)
 %caps(cap_chown,cap_dac_override,cap_fowner,cap_lease=eip) %{_bindir}/focus_server
+%caps(cap_chown,cap_dac_override,cap_fowner,cap_lease=eip) %{_bindir}/sound_server
 %{_libdir}/libmmfsound.so.*
 %{_libdir}/libmmfsoundcommon.so.*
 %{_libdir}/libmmfkeysound.so.*
@@ -154,17 +158,18 @@ ln -sf ../sound-server.path %{buildroot}%{_unitdir}/multi-user.target.wants/soun
 %{_libdir}/soundplugins/libsoundplugintremoloogg.so
 %endif
 %if "%{?tizen_profile_name}" == "tv"
-%{_unitdir}/sysinit.target.wants/sound-server.path
+%{_unitdir}/sysinit.target.wants/focus-server.path
 %else
-%{_unitdir}/multi-user.target.wants/sound-server.path
+%{_unitdir}/multi-user.target.wants/focus-server.path
 %endif
-%{_unitdir}/sound-server.service
-%{_unitdir}/sound-server.path
+%{_unitdir}/focus-server.service
+%{_unitdir}/focus-server.path
+/usr/share/sounds/sound-server/*
 %{_datadir}/license/%{name}
 %{_datadir}/license/libmm-sound-tool
-/usr/share/sounds/sound-server/*
-/etc/dbus-1/system.d/focus-server.conf
 /etc/dbus-1/system.d/sound-server.conf
+/etc/dbus-1/system.d/focus-server.conf
+%{_datadir}/dbus-1/system-services/org.tizen.SoundServer.service
 
 %files devel
 %defattr(-,root,root,-)
diff --git a/packaging/org.tizen.SoundServer.service b/packaging/org.tizen.SoundServer.service
new file mode 100644 (file)
index 0000000..0d3a64f
--- /dev/null
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=org.tizen.SoundServer
+Exec=/usr/bin/sound_server -S
+User=multimedia_fw
+Group=multimedia_fw
diff --git a/packaging/sound-server.path b/packaging/sound-server.path
deleted file mode 100644 (file)
index 5f605f8..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Unit]
-Description=Path activation for the "sound-server" programme
-
-[Path]
-PathExists=/tmp/.pa_ready
index 38007bd..558ff33 100644 (file)
@@ -1,59 +1,47 @@
 SUBDIRS = plugin
 
-bin_PROGRAMS = focus_server
-focus_server_SOURCES = mm_sound_mgr_codec.c \
+bin_PROGRAMS = sound_server
+sound_server_SOURCES = mm_sound_mgr_codec.c \
                                                mm_sound_mgr_ipc.c \
                                                mm_sound_mgr_ipc_dbus.c \
                                                mm_sound_mgr_run.c \
-                                               mm_sound_mgr_focus.c \
-                                               mm_sound_mgr_focus_dbus.c \
-                                               mm_sound_mgr_focus_ipc.c \
                                                mm_sound_plugin.c \
                                                mm_sound_server.c \
                                                mm_sound_thread_pool.c
 
-focus_server_CFLAGS = -I$(srcdir)/../include \
+sound_server_CFLAGS = -I$(srcdir)/../include \
                                          -I$(srcdir)/include \
                                          $(MMCOMMON_CFLAGS) \
                                          $(MMLOGSVR_CFLAGS) \
                                          -DMMF_LOG_OWNER=0x002 \
                                          -DMMF_DEBUG_PREFIX=\"MMF-SOUND\" \
-                                         -D__DEBUG_MODE__ -DUSE_VCONF -D__USE_LOGMANAGER__ \
+                                         -D__DEBUG_MODE__ -D__USE_LOGMANAGER__ \
                                          $(MMSESSION_CFLAGS) \
-                                         $(AUDIOSESSIONMGR_CFLAGS) \
-                                         $(VCONF_CFLAGS) \
                                          $(GLIB2_CFLAGS) \
                                          $(GIO_CFLAGS)
 
-focus_server_LDADD = $(MMLOGSVR_LIBS) \
+sound_server_LDADD = $(MMLOGSVR_LIBS) \
                     -ldl -lrt \
                     $(MMCOMMON_LIBS) \
                     $(MMSESSION_LIBS) \
-                    $(AUDIOSESSIONMGR_LIBS) \
                     $(GLIB2_LIBS) \
                     $(GIO_LIBS) \
-                    $(VCONF_LIBS) \
                     $(srcdir)/../libmmfsound.la \
                     $(srcdir)/../common/libmmfsoundcommon.la
 
 if USE_PULSE
-focus_server_CFLAGS += -DPULSE_CLIENT $(PA_CFLAGS) $(PASIMPLE_CFLAGS)
-focus_server_LDADD += $(PA_LIBS) $(PASIMPLE_CFLAGS)
-endif
-
-if USE_LWIPC
-focus_server_CFLAGS += $(LWIPC_CFLAGS) -DUSE_LWIPC
-focus_server_LDADD += $(LWIPC_LIBS)
+sound_server_CFLAGS += -DPULSE_CLIENT $(PA_CFLAGS) $(PASIMPLE_CFLAGS)
+sound_server_LDADD += $(PA_LIBS) $(PASIMPLE_CFLAGS)
 endif
 
 if USE_SECURITY
-focus_server_CFLAGS += $(SECURITY_CFLAGS) -DUSE_SECURITY
-focus_server_LDADD += $(SECURITY_LIBS)
+sound_server_CFLAGS += $(SECURITY_CFLAGS) -DUSE_SECURITY
+sound_server_LDADD += $(SECURITY_LIBS)
 endif
 
-focus_server_DEPENDENCIES = $(srcdir)/../common/libmmfsoundcommon.la
+sound_server_DEPENDENCIES = $(srcdir)/../common/libmmfsoundcommon.la
 if !USE_PRELINK
-focus_server_CFLAGS += -fPIC -pie
+sound_server_CFLAGS += -fPIC -pie
 endif
 installsounddir = $(prefix)/share/sounds/sound-server
 installsound_DATA = sounds/Tizen_HW_Touch.ogg
index 74271e5..8084040 100644 (file)
  *
  */
 
-#ifndef __MM_SOUND_THREAd_POOL_H__
-#define __MM_SOUND_THREAd_POOL_H__
+#ifndef __MM_SOUND_THREAD_POOL_H__
+#define __MM_SOUND_THREAD_POOL_H__
+
+#include <glib.h>
 
 int MMSoundThreadPoolDump(int fulldump);
 int MMSoundThreadPoolInit(void);
+gboolean IsMMSoundThreadPoolRunning(void);
 int MMSoundThreadPoolRun(void *param, void (*func)(void*));
 int MMSoundThreadPoolFini(void);
 
-#endif /* __MM_SOUND_THREAd_POOL_H__ */
+#endif /* __MM_SOUND_THREAD_POOL_H__ */
index d48aff7..3954ef7 100644 (file)
@@ -235,16 +235,16 @@ static int _get_sender_pid(GDBusMethodInvocation* invocation)
        connection = g_dbus_method_invocation_get_connection(invocation);
        sender = g_dbus_method_invocation_get_sender(invocation);
 
-       debug_error ("connection = %p, sender = %s", connection, sender);
+       debug_error("connection = %p, sender = %s", connection, sender);
 
-       value = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
+       value = g_dbus_connection_call_sync(connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
                                                                                "org.freedesktop.DBus", "GetConnectionUnixProcessID",
                                                                                g_variant_new("(s)", sender, NULL), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
        if (value) {
                g_variant_get(value, "(u)", &pid);
-               debug_error ("Sender PID = [%d]", pid);
+               debug_msg("Sender PID = [%d]", pid);
        } else {
-               debug_error ("err code = %d, err msg = %s", err->code, err->message);
+               debug_error("err code = %d, err msg = %s", err->code, err->message);
        }
        return pid;
 }
@@ -253,7 +253,7 @@ static void _method_call_return_value(GDBusMethodInvocation *invocation, GVarian
 {
        const char *method_name;
        method_name = g_dbus_method_invocation_get_method_name(invocation);
-       debug_error("Method Call '%s' success", method_name);
+       debug_msg("Method Call '%s' success", method_name);
        g_dbus_method_invocation_return_value(invocation, params);
 }
 static void _method_call_return_error(GDBusMethodInvocation *invocation, int ret)
@@ -620,7 +620,7 @@ static int _mm_sound_mgr_dbus_own_name(GBusType bus_type, const char* wellknown_
 
        debug_log("Own name (%s) for sound-server", wellknown_name);
 
-       oid = g_bus_own_name(bus_type, wellknown_name , G_BUS_NAME_OWNER_FLAGS_NONE,
+       oid = g_bus_own_name(bus_type, wellknown_name, G_BUS_NAME_OWNER_FLAGS_NONE,
                        on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
        if (oid <= 0) {
                debug_error("Dbus own name failed");
@@ -629,18 +629,20 @@ static int _mm_sound_mgr_dbus_own_name(GBusType bus_type, const char* wellknown_
                *owner_id = oid;
        }
 
+       debug_log("OwnerID (%d) for sound-server", *owner_id);
+
        return MM_ERROR_NONE;
 }
 
 static void _mm_sound_mgr_dbus_unown_name(guint oid)
 {
-       debug_log("Unown name for Sound-Server");
+       debug_log("Unown name for Sound-Server [%d]", oid);
        if (oid > 0) {
                g_bus_unown_name(oid);
        }
 }
 
-int __mm_sound_mgr_ipc_dbus_notify_device_connected (mm_sound_device_t *device, gboolean is_connected)
+int __mm_sound_mgr_ipc_dbus_notify_device_connected(mm_sound_device_t *device, gboolean is_connected)
 {
        int ret = MM_ERROR_NONE;
        GVariantBuilder builder;
@@ -665,7 +667,7 @@ int __mm_sound_mgr_ipc_dbus_notify_device_connected (mm_sound_device_t *device,
        return ret;
 }
 
-int __mm_sound_mgr_ipc_dbus_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type)
+int __mm_sound_mgr_ipc_dbus_notify_device_info_changed(mm_sound_device_t *device, int changed_device_info_type)
 {
        int ret = MM_ERROR_NONE;
        GVariantBuilder builder;
@@ -754,11 +756,11 @@ int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        if (!conn && err) {
                LOGE("g_bus_get_sync() error (%s)", err->message);
-               g_error_free (err);
+               g_error_free(err);
                ret = MM_ERROR_SOUND_INTERNAL;
                return ret;
        }
-       result = g_dbus_connection_call_sync (conn,
+       result = g_dbus_connection_call_sync(conn,
                                                        PA_BUS_NAME,
                                                        PA_STREAM_MANAGER_OBJECT_PATH,
                                                        PA_STREAM_MANAGER_INTERFACE,
@@ -781,11 +783,11 @@ int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
                i = 0;
                g_variant_iter_init(&iter, item);
                while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "&s", &name)) {
-                       debug_log ("name : %s", name);
+                       debug_log("name : %s", name);
                        stream_list->stream_types[i++] = strdup(name);
                }
-               g_variant_unref (item);
-               g_variant_unref (child);
+               g_variant_unref(item);
+               g_variant_unref(child);
 
                child = g_variant_get_child_value(result, 1);
                item = g_variant_get_variant(child);
@@ -793,11 +795,11 @@ int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
                i = 0;
                g_variant_iter_init(&iter, item);
                while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "i", &priority)) {
-                       debug_log ("priority : %d", priority);
+                       debug_log("priority : %d", priority);
                        stream_list->priorities[i++] = priority;
                }
-               g_variant_unref (item);
-               g_variant_unref (child);
+               g_variant_unref(item);
+               g_variant_unref(child);
 
                g_variant_unref(result);
        }
@@ -810,12 +812,14 @@ int MMSoundMgrDbusInit(void)
 {
        debug_enter();
 
-       introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
-       if (!introspection_data)
+       introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+       if (!introspection_data) {
+               debug_error("g_dbus_node_info_new_for_xml() failed...");
                return MM_ERROR_SOUND_INTERNAL;
+       }
 
        if (_mm_sound_mgr_dbus_own_name(G_BUS_TYPE_SYSTEM, BUS_NAME_SOUND_SERVER, &sound_server_owner_id) != MM_ERROR_NONE) {
-               debug_error ("dbus own name for sound-server error\n");
+               debug_error("dbus own name for sound-server error\n");
                return MM_ERROR_SOUND_INTERNAL;
        }
 
@@ -829,7 +833,7 @@ void MMSoundMgrDbusFini(void)
        debug_enter("\n");
 
        _mm_sound_mgr_dbus_unown_name(sound_server_owner_id);
-       g_dbus_node_info_unref (introspection_data);
+       g_dbus_node_info_unref(introspection_data);
 
        debug_leave("\n");
 }
index 9236aa2..f66aca4 100644 (file)
 #include <unistd.h>
 #include <getopt.h>
 
-#include <vconf.h>
 #include <mm_error.h>
 #include <mm_debug.h>
 
-#ifdef USE_LWIPC
-#include <lwipc.h>
-#endif
-
-#include <fcntl.h>
-#include <semaphore.h>
-
 #include "../include/mm_sound_common.h"
 #include "include/mm_sound_thread_pool.h"
 #include "include/mm_sound_mgr_run.h"
 #include "include/mm_sound_mgr_codec.h"
 #include "include/mm_sound_mgr_ipc_dbus.h"
-#include "include/mm_sound_mgr_focus.h"
-#include "include/mm_sound_mgr_focus_dbus.h"
 
 #include "../config.h" /* for PLUGIN_DIR */
 
 #define PLUGIN_ENV "MM_SOUND_PLUGIN_PATH"
 #define PLUGIN_MAX 30
 #define MAX_PLUGIN_DIR_PATH_LEN        256
+#define SHUTDOWN_TIMEOUT_SEC 10
 
 #define USE_SYSTEM_SERVER_PROCESS_MONITORING
 
@@ -60,7 +51,7 @@ typedef struct {
     int testmode;
 } server_arg;
 
-static int getOption(int argc, char **argv, server_arg *arg);
+static int _get_option(int argc, char **argv, server_arg *arg);
 static int _usage(int argc, char **argv);
 
 static struct sigaction sigint_action;  /* Backup pointer of SIGINT handler */
@@ -72,146 +63,31 @@ static void _exit_handler(int sig);
 
 GMainLoop *g_mainloop;
 
-static void _mainloop_run()
-{
-       g_mainloop = g_main_loop_new(NULL, TRUE);
-       if (g_mainloop == NULL) {
-               debug_error("g_main_loop_new() failed\n");
-       }
-       g_main_loop_run(g_mainloop);
-}
-
-static sem_t* sem_create_n_wait()
+static gboolean _shutdown_timer_cb(gpointer user_data)
 {
-       sem_t* sem = NULL;
-
-       if ((sem = sem_open ("booting-sound", O_CREAT, 0660, 0))== SEM_FAILED) {
-               debug_error ("error creating sem : %d", errno);
-               return NULL;
+       if (!IsMMSoundThreadPoolRunning()) {
+               debug_warning("Thread pool is not running..quit mainloop now!");
+               g_main_loop_quit(g_mainloop);
+               return FALSE;
        }
 
-       debug_msg ("returning sem [%p]", sem);
-       return sem;
+       debug_warning("still running......keep timer...");
+       return TRUE;
 }
 
-int main(int argc, char **argv)
+static void _mainloop_run()
 {
-       sem_t* sem = NULL;
-       server_arg serveropt;
-       struct sigaction action;
-#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
-       int pid;
-#endif
-
-       action.sa_handler = _exit_handler;
-       action.sa_flags = 0;
-       sigemptyset(&action.sa_mask);
-
-       if (getOption(argc, argv, &serveropt))
-               return 1;
-
-       debug_warning("sound_server [%d] init \n", getpid());
-
-       if (serveropt.startserver) {
-               sem = sem_create_n_wait();
-       }
-       /* Daemon process create */
-       if (!serveropt.testmode && serveropt.startserver) {
-#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
-               daemon(0,0); //chdir to ("/"), and close stdio
-#endif
-       }
-
-       /* Sound Server Starts!!!*/
-       debug_warning("sound_server [%d] start \n", getpid());
-
-       signal(SIGPIPE, SIG_IGN); //ignore SIGPIPE
-
-#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
-       while(1)
-       {
-               if ((pid = fork()) < 0)
-               {
-                       fprintf(stderr, "Sub Fork Error\n");
-                       return 2;
-               }
-               else if(pid == 0)
-               {
-                       break;
-               }
-               else if(pid > 0)
-               {
-                       wait(&ret);
-                       fprintf(stderr, "Killed by signal [%05X]\n", ret);
-                       fprintf(stderr, "Daemon is run againg\n");
-               }
-       }
-#endif
-       sigaction(SIGABRT, &action, &sigabrt_action);
-       sigaction(SIGSEGV, &action, &sigsegv_action);
-       sigaction(SIGTERM, &action, &sigterm_action);
-       sigaction(SIGSYS, &action, &sigsys_action);
-
-       if (serveropt.startserver || serveropt.printlist) {
-               MMSoundThreadPoolInit();
-               MMSoundMgrRunInit(serveropt.plugdir);
-               MMSoundMgrCodecInit(serveropt.plugdir);
-               MMSoundMgrDbusInit();
-               MMSoundMgrFocusDbusInit();
-               MMSoundMgrFocusInit();
-       }
-
-       debug_warning("sound_server [%d] initialization complete...now, start running!!\n", getpid());
-
-       if (serveropt.startserver) {
-               /* Start Run types */
-               MMSoundMgrRunRunAll();
-
-               unlink(PA_READY); // remove pa_ready file after sound-server init.
-
-               if (sem) {
-                       if (sem_post(sem) == -1) {
-                               debug_error ("error sem post : %d", errno);
-                       } else {
-                               debug_msg ("Ready to play booting sound!!!!");
-                       }
-               }
-#ifdef TIZEN_TV
-#ifdef USE_LWIPC
-               /* broadcast if we're ready */
-               if (LwipcEventDone(SOUND_SERVER_READY) < 0) {
-                       debug_error("cannot create SOUND_SERVER_READY(sound_server_ready)");
-               } else {
-                       debug_warning("SOUND_SERVER_READY(%s) event was created", SOUND_SERVER_READY);
-               }
-#else
-               if (creat(SOUND_SERVER_READY, 0644) != -1) {
-                       debug_warning("SOUND_SERVER_READY(%s) file was created", SOUND_SERVER_READY);
-               } else {
-                       debug_error("cannot create SOUND_SERVER_READY(/tmp/.sound_server_ready)");
-               }
-#endif
-#endif
-               /* Start MainLoop */
-               _mainloop_run();
-       }
-
-       debug_warning("sound_server [%d] terminating \n", getpid());
-
-       if (serveropt.startserver || serveropt.printlist) {
-               MMSoundMgrRunStopAll();
-               MMSoundMgrDbusFini();
-               MMSoundMgrCodecFini();
-               MMSoundMgrRunFini();
-               MMSoundThreadPoolFini();
+       g_mainloop = g_main_loop_new(NULL, TRUE);
+       if (g_mainloop == NULL) {
+               debug_error("g_main_loop_new() failed\n");
        }
 
-       debug_warning("sound_server [%d] exit ----------------- END \n", getpid());
+       g_timeout_add_seconds(SHUTDOWN_TIMEOUT_SEC, _shutdown_timer_cb, NULL);
 
-       return 0;
+       g_main_loop_run(g_mainloop);
 }
 
-static int getOption(int argc, char **argv, server_arg *arg)
+static int _get_option(int argc, char **argv, server_arg *arg)
 {
        int c;
        char *plugin_env_dir = NULL;
@@ -226,23 +102,17 @@ static int getOption(int argc, char **argv, server_arg *arg)
        memset(arg, 0, sizeof(server_arg));
 
        plugin_env_dir = getenv(PLUGIN_ENV);
-       if (plugin_env_dir) {
-               MMSOUND_STRNCPY(arg->plugdir, plugin_env_dir, MAX_PLUGIN_DIR_PATH_LEN);
-       } else {
-               MMSOUND_STRNCPY(arg->plugdir, PLUGIN_DIR, MAX_PLUGIN_DIR_PATH_LEN);
-       }
+       MMSOUND_STRNCPY(arg->plugdir, (plugin_env_dir? plugin_env_dir : PLUGIN_DIR), MAX_PLUGIN_DIR_PATH_LEN);
 
        arg->testmode = 0;
 
-       while (1)
-       {
+       while (1) {
                int opt_idx = 0;
 
-               c = getopt_long (argc, argv, "SFLHRUP:Tiurd", long_options, &opt_idx);
+               c = getopt_long(argc, argv, "SFLHRUP:Tiurd", long_options, &opt_idx);
                if (c == -1)
                        break;
-               switch (c)
-               {
+               switch (c) {
                case 'S': /* Start daemon */
                        arg->startserver = 1;
                        break;
@@ -257,7 +127,7 @@ static int getOption(int argc, char **argv, server_arg *arg)
                        break;
                case 'H': /* help msg */
                default:
-               return _usage(argc, argv);
+                       return _usage(argc, argv);
                }
        }
        if (argc == 1)
@@ -277,8 +147,7 @@ static void _exit_handler(int sig)
                debug_log("All run-type plugin stopped\n");
        }
 
-       switch(sig)
-       {
+       switch(sig) {
        case SIGINT:
                sigaction(SIGINT, &sigint_action, NULL);
                debug_error("signal(SIGINT) error");
@@ -314,3 +183,82 @@ static int _usage(int argc, char **argv)
        return 1;
 }
 
+int main(int argc, char **argv)
+{
+       server_arg serveropt;
+       struct sigaction action;
+#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
+       int pid;
+#endif
+
+       action.sa_handler = _exit_handler;
+       action.sa_flags = 0;
+       sigemptyset(&action.sa_mask);
+
+       if (_get_option(argc, argv, &serveropt))
+               return 1;
+
+       debug_warning("sound_server [%d] init \n", getpid());
+
+       /* Daemon process create */
+       if (!serveropt.testmode && serveropt.startserver) {
+#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
+               daemon(0,0); //chdir to ("/"), and close stdio
+#endif
+       }
+
+       /* Sound Server Starts!!!*/
+       debug_warning("sound_server [%d] start \n", getpid());
+
+       signal(SIGPIPE, SIG_IGN); //ignore SIGPIPE
+
+#if !defined(USE_SYSTEM_SERVER_PROCESS_MONITORING)
+       while (1) {
+               if ((pid = fork()) < 0) {
+                       fprintf(stderr, "Sub Fork Error\n");
+                       return 2;
+               } else if(pid == 0) {
+                       break;
+               } else if(pid > 0) {
+                       wait(&ret);
+                       fprintf(stderr, "Killed by signal [%05X]\n", ret);
+                       fprintf(stderr, "Daemon is run againg\n");
+               }
+       }
+#endif
+       sigaction(SIGABRT, &action, &sigabrt_action);
+       sigaction(SIGSEGV, &action, &sigsegv_action);
+       sigaction(SIGTERM, &action, &sigterm_action);
+       sigaction(SIGSYS, &action, &sigsys_action);
+
+       if (serveropt.startserver || serveropt.printlist) {
+               MMSoundThreadPoolInit();
+               MMSoundMgrRunInit(serveropt.plugdir);
+               MMSoundMgrCodecInit(serveropt.plugdir);
+               MMSoundMgrDbusInit();
+       }
+
+       debug_warning("sound_server [%d] initialization complete...now, start running!!\n", getpid());
+
+       if (serveropt.startserver) {
+               /* Start Run types */
+               MMSoundMgrRunRunAll();
+
+               /* Start MainLoop */
+               _mainloop_run();
+       }
+
+       debug_warning("sound_server [%d] terminating \n", getpid());
+
+       if (serveropt.startserver || serveropt.printlist) {
+               MMSoundMgrRunStopAll();
+               MMSoundMgrDbusFini();
+               MMSoundMgrCodecFini();
+               MMSoundMgrRunFini();
+               MMSoundThreadPoolFini();
+       }
+
+       debug_warning("sound_server [%d] exit ----------------- END \n", getpid());
+
+       return 0;
+}
index 57a5279..5b5df31 100644 (file)
@@ -34,6 +34,8 @@ GThreadPool* g_pool;
 
 #define MAX_UNUSED_THREADS_IN_THREADPOOL       10
 
+#define MIN_RUNNING_THREAD 0
+
 typedef struct __THREAD_INFO
 {
        void (*func)(gpointer data);
@@ -87,6 +89,12 @@ int MMSoundThreadPoolDump(int fulldump)
        return MM_ERROR_NONE;
 }
 
+gboolean IsMMSoundThreadPoolRunning(void)
+{
+       MMSoundThreadPoolDump(FALSE);
+       return (g_thread_pool_get_num_threads(g_pool) > MIN_RUNNING_THREAD);
+}
+
 int MMSoundThreadPoolInit()
 {
        int i=0;