Adapt session interrupt callback to focus callback
[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_uniq_id(id);
74         if (ret) {
75                 debug_error("Failed to mm_sound_client_get_uniq_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, stream_type, callback, 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_unregister_focus(int id)
107 {
108         int ret = MM_ERROR_NONE;
109
110         debug_fenter();
111
112         if (id < 0) {
113                 debug_error("argument is not valid\n");
114                 return MM_ERROR_INVALID_ARGUMENT;
115         }
116
117         ret = mm_sound_client_unregister_focus(id);
118         if (ret) {
119                 debug_error("Could not unregister focus, ret = %x\n", ret);
120         }
121
122         debug_fleave();
123
124         return ret;
125 }
126
127 EXPORT_API
128 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
129 {
130         int ret = MM_ERROR_NONE;
131
132         debug_fenter();
133
134         if (id < 0) {
135                 debug_error("argument is not valid\n");
136                 return MM_ERROR_INVALID_ARGUMENT;
137         }
138         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
139                 debug_error("argument is not valid\n");
140                 return MM_ERROR_INVALID_ARGUMENT;
141         }
142
143         ret = mm_sound_client_acquire_focus(id, focus_type, additional_info);
144         if (ret) {
145                 debug_error("Could not acquire focus, ret[0x%x]\n", ret);
146         }
147
148         debug_fleave();
149
150         return ret;
151 }
152
153 EXPORT_API
154 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
155 {
156         int ret = MM_ERROR_NONE;
157
158         debug_fenter();
159
160         if (id < 0) {
161                 debug_error("argument is not valid\n");
162                 return MM_ERROR_INVALID_ARGUMENT;
163         }
164         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
165                 debug_error("argument is not valid\n");
166                 return MM_ERROR_INVALID_ARGUMENT;
167         }
168
169         ret = mm_sound_client_release_focus(id, focus_type, additional_info);
170         if (ret) {
171                 debug_error("Could not release focus, ret[0x%x]\n", ret);
172         }
173
174         debug_fleave();
175
176         return ret;
177 }
178
179 EXPORT_API
180 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)
181 {
182         int ret = MM_ERROR_NONE;
183
184         debug_fenter();
185
186         if (callback == NULL || id == NULL) {
187                 debug_error("argument is not valid\n");
188                 return MM_ERROR_INVALID_ARGUMENT;
189         }
190         ret = mm_sound_client_set_focus_watch_callback(focus_type, callback, user_data, id);
191         if (ret) {
192                 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
193         }
194
195         debug_fleave();
196
197         return ret;
198 }
199
200 EXPORT_API
201 int mm_sound_unset_focus_watch_callback(int id)
202 {
203         int ret = MM_ERROR_NONE;
204
205         debug_fenter();
206
207         ret = mm_sound_client_unset_focus_watch_callback(id);
208         if (ret) {
209                 debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);
210         }
211
212         debug_fleave();
213
214         return ret;
215 }