319ad6453020fb8a32aee9d2b7e2d7f4c13dd6b0
[platform/core/multimedia/libmm-sound.git] / focus_server / mm_sound_mgr_focus_ipc.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 <stdlib.h>
23 #include <string.h>
24
25 #include "include/mm_sound_mgr_focus_ipc.h"
26 #include "include/mm_sound_mgr_focus_dbus.h"
27
28 #include "../include/mm_sound_common.h"
29 #include "include/mm_sound_mgr_focus.h"
30 #include <mm_debug.h>
31
32 int __mm_sound_mgr_focus_ipc_register_focus(int client_pid, int handle_id, const char* stream_type, bool is_for_session)
33 {
34         _mm_sound_mgr_focus_param_t param;
35         int ret = MM_ERROR_NONE;
36
37         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
38         param.pid = client_pid;
39         param.handle_id = handle_id;
40         param.is_for_session = is_for_session;
41         MMSOUND_STRNCPY(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
42
43         ret = mm_sound_mgr_focus_create_node(&param);
44
45         return ret;
46 }
47
48 // method + remove callback
49 int __mm_sound_mgr_focus_ipc_unregister_focus(int pid, int handle_id, bool is_for_session)
50 {
51         _mm_sound_mgr_focus_param_t param;
52         int ret = MM_ERROR_NONE;
53
54         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
55         param.pid = pid;
56         param.handle_id = handle_id;
57         param.is_for_session = is_for_session;
58
59         ret = mm_sound_mgr_focus_destroy_node(&param);
60
61         return ret;
62 }
63
64 // method -> callback
65 int __mm_sound_mgr_focus_ipc_set_focus_reacquisition(int pid, int handle_id, bool reacquisition, bool is_for_session)
66 {
67         _mm_sound_mgr_focus_param_t param;
68         int ret = MM_ERROR_NONE;
69
70         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
71         param.pid = pid;
72         param.handle_id = handle_id;
73         param.reacquisition = reacquisition;
74         param.is_for_session = is_for_session;
75
76         ret = mm_sound_mgr_focus_set_reacquisition(&param);
77
78         return ret;
79 }
80
81 // method
82 int __mm_sound_mgr_focus_ipc_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
83 {
84         int ret = MM_ERROR_NONE;
85         char *stream_type_str = NULL;
86         char *ext_info_str = NULL;
87
88         if (!stream_type)
89                 return MM_ERROR_INVALID_ARGUMENT;
90
91         ret = mm_sound_mgr_focus_get_stream_type_of_acquired_focus(focus_type, &stream_type_str, option, &ext_info_str);
92         if (ret == MM_ERROR_NONE) {
93                 *stream_type = stream_type_str;
94                 if (ext_info)
95                         *ext_info = ext_info_str;
96         }
97
98         return ret;
99 }
100
101 // method -> callback
102 int __mm_sound_mgr_focus_ipc_acquire_focus(int pid, int handle_id, int focus_type, int option, const char *ext_info, bool is_for_session)
103 {
104         _mm_sound_mgr_focus_param_t param;
105         int ret = MM_ERROR_NONE;
106
107         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
108         param.pid = pid;
109         param.handle_id = handle_id;
110         param.request_type = focus_type;
111         param.option = option;
112         param.is_for_session = is_for_session;
113         MMSOUND_STRNCPY(param.ext_info, ext_info, MM_SOUND_NAME_NUM);
114
115         ret = mm_sound_mgr_focus_request_acquire(&param);
116
117         return ret;
118 }
119
120 // method -> callback
121 int __mm_sound_mgr_focus_ipc_release_focus(int pid, int handle_id, int focus_type, int option, const char *ext_info, bool is_for_session)
122 {
123         _mm_sound_mgr_focus_param_t param;
124         int ret = MM_ERROR_NONE;
125
126         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
127         param.pid = pid;
128         param.handle_id = handle_id;
129         param.request_type = focus_type;
130         param.option = option;
131         param.is_for_session = is_for_session;
132         MMSOUND_STRNCPY(param.ext_info, ext_info, MM_SOUND_NAME_NUM);
133
134         ret = mm_sound_mgr_focus_request_release(&param);
135
136         return ret;
137 }
138
139 int __mm_sound_mgr_focus_ipc_watch_focus(int pid, int handle_id, int focus_type, bool is_for_session)
140 {
141         _mm_sound_mgr_focus_param_t param;
142         int ret = MM_ERROR_NONE;
143
144         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
145         param.pid = pid;
146         param.handle_id = handle_id;
147         param.request_type = focus_type;
148         param.is_for_session = is_for_session;
149
150         ret = mm_sound_mgr_focus_set_watch_cb(&param);
151
152         return ret;
153 }
154
155 // method + remove callback
156 int __mm_sound_mgr_focus_ipc_unwatch_focus(int pid, int handle_id)
157 {
158         _mm_sound_mgr_focus_param_t param;
159         int ret = MM_ERROR_NONE;
160
161         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
162         param.pid = pid;
163         param.handle_id = handle_id;
164
165         ret = mm_sound_mgr_focus_unset_watch_cb(&param);
166
167         return ret;
168 }
169
170 int __mm_sound_mgr_focus_ipc_emergent_exit(int pid)
171 {
172         _mm_sound_mgr_focus_param_t param;
173         int ret = MM_ERROR_NONE;
174
175         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
176         param.pid = pid;
177
178         ret = mm_sound_mgr_focus_emergent_exit(&param);
179
180         return ret;
181 }
182