Fix mm_sound_testsuite input error and remove focus client warnings remained
[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_get_id(int *id)
36 {
37         int ret = MM_ERROR_NONE;
38
39         debug_fenter();
40
41         ret = mm_sound_client_get_uniq_id(id);
42         if (ret) {
43                 debug_error("Failed to mm_sound_client_get_uniq_id(), ret[0x%x]\n", ret);
44         }
45
46         debug_fleave();
47
48         return ret;
49 }
50
51 EXPORT_API
52 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
53 {
54         int ret = MM_ERROR_NONE;
55
56         debug_fenter();
57
58         if (id < 0 || callback == NULL) {
59                 debug_error("argument is not valid\n");
60                 return MM_ERROR_INVALID_ARGUMENT;
61         }
62
63         ret = mm_sound_client_register_focus(id, stream_type, callback, user_data);
64         if (ret) {
65                 debug_error("Could not register focus, ret[0x%x]\n", ret);
66         }
67
68         debug_fleave();
69
70         return ret;
71 }
72
73 EXPORT_API
74 int mm_sound_unregister_focus(int id)
75 {
76         int ret = MM_ERROR_NONE;
77
78         debug_fenter();
79
80         if (id < 0) {
81                 debug_error("argument is not valid\n");
82                 return MM_ERROR_INVALID_ARGUMENT;
83         }
84
85         ret = mm_sound_client_unregister_focus(id);
86         if (ret) {
87                 debug_error("Could not unregister focus, ret = %x\n", ret);
88         }
89
90         debug_fleave();
91
92         return ret;
93 }
94
95 EXPORT_API
96 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
97 {
98         int ret = MM_ERROR_NONE;
99
100         debug_fenter();
101
102         if (id < 0) {
103                 debug_error("argument is not valid\n");
104                 return MM_ERROR_INVALID_ARGUMENT;
105         }
106         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
107                 debug_error("argument is not valid\n");
108                 return MM_ERROR_INVALID_ARGUMENT;
109         }
110
111         ret = mm_sound_client_acquire_focus(id, focus_type, additional_info);
112         if (ret) {
113                 debug_error("Could not acquire focus, ret[0x%x]\n", ret);
114         }
115
116         debug_fleave();
117
118         return ret;
119 }
120
121 EXPORT_API
122 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
123 {
124         int ret = MM_ERROR_NONE;
125
126         debug_fenter();
127
128         if (id < 0) {
129                 debug_error("argument is not valid\n");
130                 return MM_ERROR_INVALID_ARGUMENT;
131         }
132         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
133                 debug_error("argument is not valid\n");
134                 return MM_ERROR_INVALID_ARGUMENT;
135         }
136
137         ret = mm_sound_client_release_focus(id, focus_type, additional_info);
138         if (ret) {
139                 debug_error("Could not release focus, ret[0x%x]\n", ret);
140         }
141
142         debug_fleave();
143
144         return ret;
145 }
146
147 EXPORT_API
148 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)
149 {
150         int ret = MM_ERROR_NONE;
151
152         debug_fenter();
153
154         if (callback == NULL || id == NULL) {
155                 debug_error("argument is not valid\n");
156                 return MM_ERROR_INVALID_ARGUMENT;
157         }
158         ret = mm_sound_client_set_focus_watch_callback(focus_type, callback, user_data, id);
159         if (ret) {
160                 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
161         }
162
163         debug_fleave();
164
165         return ret;
166 }
167
168 EXPORT_API
169 int mm_sound_unset_focus_watch_callback(int id)
170 {
171         int ret = MM_ERROR_NONE;
172
173         debug_fenter();
174
175         ret = mm_sound_client_unset_focus_watch_callback(id);
176         if (ret) {
177                 debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);
178         }
179
180         debug_fleave();
181
182         return ret;
183 }