Remove useless parameters(route_info, priority) regarding audio path routing since...
[platform/core/multimedia/libmm-sound.git] / server / mm_sound_mgr_run.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21  
22 #include <stdio.h>
23
24 #include "include/mm_sound_plugin_run.h"
25 #include "include/mm_sound_mgr_run.h"
26 #include "include/mm_sound_thread_pool.h"
27
28 #include <mm_error.h>
29 #include <mm_debug.h>
30
31 static void _MMsoundMgrRunRunInternal(void *param);
32
33 static MMSoundPluginType *g_run_plugins = NULL;
34
35 int MMSoundMgrRunInit(const char *targetdir)
36 {
37     debug_fenter();
38
39     if (g_run_plugins) {
40         debug_error("Please Check Init twice\n");
41         return MM_ERROR_SOUND_INTERNAL;
42     }
43     MMSoundPluginScan(targetdir, MM_SOUND_PLUGIN_TYPE_RUN, &g_run_plugins);
44
45     debug_fleave();
46     return MM_ERROR_NONE;
47 }
48
49 int MMSoundMgrRunFini(void)
50 {
51         debug_fenter();
52
53     MMSoundPluginRelease(g_run_plugins);
54     g_run_plugins = NULL;
55
56     debug_fleave();
57     return MM_ERROR_NONE;
58 }
59
60 int MMSoundMgrRunRunAll(void)
61 {
62     int loop = 0;
63
64     debug_fenter();
65
66     while (g_run_plugins[loop].type != MM_SOUND_PLUGIN_TYPE_NONE) {
67         MMSoundThreadPoolRun((void*)loop, _MMsoundMgrRunRunInternal);
68         loop++;
69     }
70
71     debug_fleave();
72     return MM_ERROR_NONE;
73 }
74
75 int MMSoundMgrRunStopAll(void)
76 {
77         mmsound_run_interface_t intface;
78         void *func = NULL;
79         int loop = 0;
80
81         debug_fenter();
82
83         while (g_run_plugins && g_run_plugins[loop].type != MM_SOUND_PLUGIN_TYPE_NONE) {
84                 debug_msg("loop : %d\n", loop);
85                 MMSoundPluginGetSymbol(&g_run_plugins[loop], RUN_GET_INTERFACE_FUNC_NAME, &func);
86                 MMSoundPlugRunCastGetInterface(func)(&intface);
87                 intface.stop();
88                 loop++;
89         }
90
91         debug_fleave();
92     return MM_ERROR_NONE;
93 }
94
95 static void _MMsoundMgrRunRunInternal(void *param)
96 {
97         int err = MM_ERROR_NONE;
98         mmsound_run_interface_t intface;
99         void* func = NULL;
100
101         debug_enter("plugin number %d\n", (int)param);
102
103         err = MMSoundPluginGetSymbol(&g_run_plugins[(int)param], RUN_GET_INTERFACE_FUNC_NAME, &func);
104         if (err  != MM_ERROR_NONE) {
105                 debug_error("Get Symbol RUN_GET_INTERFACE_FUNC_NAME is fail : %x\n", err);
106         }
107         err = MMSoundPlugRunCastGetInterface(func)(&intface);
108         if (err != MM_ERROR_NONE) {
109                 debug_error("Get interface fail : %x\n", err);
110                 /* If error occur, clean interface */
111                 //memset(&g_run_plugins[(int)param], 0, sizeof(mmsound_run_interface_t));
112         }
113         if(intface.SetThreadPool)
114                 intface.SetThreadPool(MMSoundThreadPoolRun);
115         intface.run();
116         debug_msg("Trace\n");
117         debug_msg("Trace\n");
118
119         debug_fleave();
120 }
121