Get unique id from focus server instead of client library itself (mm_sound_focus_get_id)
[platform/core/multimedia/libmm-sound.git] / mm_sound_focus.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Sangchul Lee <sc11.lee@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 <stdlib.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <vconf.h>
26
27 #include <mm_debug.h>
28
29 #include "include/mm_sound.h"
30 #include "include/mm_sound_client.h"
31 #include "include/mm_sound_focus.h"
32 #include "focus_server/include/mm_sound_mgr_focus.h"
33
34 EXPORT_API
35 int mm_sound_focus_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void *user_data)
36 {
37         int ret = MM_ERROR_NONE;
38         debug_fenter();
39
40         if (!callback)
41                 return MM_ERROR_INVALID_ARGUMENT;
42
43         ret = mm_sound_client_set_session_interrupt_callback (callback, user_data);
44
45         debug_fleave();
46
47         return ret;
48 }
49
50 EXPORT_API
51 int mm_sound_focus_unset_session_interrupt_callback(void)
52 {
53         int ret = MM_ERROR_NONE;
54         debug_fenter();
55
56         ret = mm_sound_client_unset_session_interrupt_callback ();
57         if (ret) {
58                 debug_error("Failed to mm_sound_client_unset_session_interrupt_callback(), ret[0x%x]\n", ret);
59         }
60
61         debug_fleave();
62
63         return ret;
64 }
65
66 EXPORT_API
67 int mm_sound_focus_get_id(int *id)
68 {
69         int ret = MM_ERROR_NONE;
70
71         debug_fenter();
72
73         ret = mm_sound_client_get_unique_id(id);
74         if (ret) {
75                 debug_error("Failed to mm_sound_client_get_unique_id(), ret[0x%x]\n", ret);
76         }
77
78         debug_fleave();
79
80         return ret;
81 }
82
83 EXPORT_API
84 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
85 {
86         int ret = MM_ERROR_NONE;
87
88         debug_fenter();
89
90         if (id < 0 || callback == NULL) {
91                 debug_error("argument is not valid\n");
92                 return MM_ERROR_INVALID_ARGUMENT;
93         }
94
95         ret = mm_sound_client_register_focus(id, getpid(), stream_type, callback, false, user_data);
96         if (ret) {
97                 debug_error("Could not register focus, ret[0x%x]\n", ret);
98         }
99
100         debug_fleave();
101
102         return ret;
103 }
104
105 EXPORT_API
106 int mm_sound_register_focus_for_session(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
107 {
108         int ret = MM_ERROR_NONE;
109
110         debug_fenter();
111
112         if (id < 0 || callback == NULL) {
113                 debug_error("argument is not valid\n");
114                 return MM_ERROR_INVALID_ARGUMENT;
115         }
116
117         ret = mm_sound_client_register_focus(id, pid, stream_type, callback, true, user_data);
118         if (ret) {
119                 debug_error("Could not register focus for session, ret[0x%x]\n", ret);
120         }
121
122         debug_fleave();
123
124         return ret;
125 }
126
127
128 EXPORT_API
129 int mm_sound_unregister_focus(int id)
130 {
131         int ret = MM_ERROR_NONE;
132
133         debug_fenter();
134
135         if (id < 0) {
136                 debug_error("argument is not valid\n");
137                 return MM_ERROR_INVALID_ARGUMENT;
138         }
139
140         ret = mm_sound_client_unregister_focus(id);
141         if (ret) {
142                 debug_error("Could not unregister focus, ret = %x\n", ret);
143         }
144
145         debug_fleave();
146
147         return ret;
148 }
149
150 EXPORT_API
151 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
152 {
153         int ret = MM_ERROR_NONE;
154
155         debug_fenter();
156
157         if (id < 0) {
158                 debug_error("argument is not valid\n");
159                 return MM_ERROR_INVALID_ARGUMENT;
160         }
161         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
162                 debug_error("argument is not valid\n");
163                 return MM_ERROR_INVALID_ARGUMENT;
164         }
165
166         ret = mm_sound_client_acquire_focus(id, focus_type, additional_info);
167         if (ret) {
168                 debug_error("Could not acquire focus, ret[0x%x]\n", ret);
169         }
170
171         debug_fleave();
172
173         return ret;
174 }
175
176 EXPORT_API
177 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
178 {
179         int ret = MM_ERROR_NONE;
180
181         debug_fenter();
182
183         if (id < 0) {
184                 debug_error("argument is not valid\n");
185                 return MM_ERROR_INVALID_ARGUMENT;
186         }
187         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
188                 debug_error("argument is not valid\n");
189                 return MM_ERROR_INVALID_ARGUMENT;
190         }
191
192         ret = mm_sound_client_release_focus(id, focus_type, additional_info);
193         if (ret) {
194                 debug_error("Could not release focus, ret[0x%x]\n", ret);
195         }
196
197         debug_fleave();
198
199         return ret;
200 }
201
202 EXPORT_API
203 int mm_sound_set_focus_watch_callback(mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void *user_data, int *id)
204 {
205         int ret = MM_ERROR_NONE;
206
207         debug_fenter();
208
209         if (callback == NULL || id == NULL) {
210                 debug_error("argument is not valid\n");
211                 return MM_ERROR_INVALID_ARGUMENT;
212         }
213         ret = mm_sound_client_set_focus_watch_callback(getpid(), focus_type, callback, false, user_data, id);
214         if (ret) {
215                 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
216         }
217
218         debug_fleave();
219
220         return ret;
221 }
222
223 EXPORT_API
224 int mm_sound_set_focus_watch_callback_for_session(int pid, mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void *user_data, int *id)
225 {
226         int ret = MM_ERROR_NONE;
227
228         debug_fenter();
229
230         if (callback == NULL || id == NULL) {
231                 debug_error("argument is not valid\n");
232                 return MM_ERROR_INVALID_ARGUMENT;
233         }
234         ret = mm_sound_client_set_focus_watch_callback(pid, focus_type, callback, true, user_data, id);
235         if (ret) {
236                 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
237         }
238
239         debug_fleave();
240
241         return ret;
242 }
243
244 EXPORT_API
245 int mm_sound_unset_focus_watch_callback(int id)
246 {
247         int ret = MM_ERROR_NONE;
248
249         debug_fenter();
250
251         ret = mm_sound_client_unset_focus_watch_callback(id);
252         if (ret) {
253                 debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);
254         }
255
256         debug_fleave();
257
258         return ret;
259 }