Adds checking dbus error messages
[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 pid, int handle_id, const char* stream_type)
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 = pid;
39         param.handle_id = handle_id;
40         MMSOUND_STRNCPY(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
41
42         ret = mm_sound_mgr_focus_create_node(&param);
43
44         return ret;
45 }
46
47 // method + remove callback
48 int __mm_sound_mgr_focus_ipc_unregister_focus(int pid, int handle_id)
49 {
50         _mm_sound_mgr_focus_param_t param;
51         int ret = MM_ERROR_NONE;
52
53         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
54         param.pid = pid;
55         param.handle_id = handle_id;
56
57         ret = mm_sound_mgr_focus_destroy_node(&param);
58
59         return ret;
60 }
61
62 int __mm_sound_mgr_focus_ipc_add_watch_node(int pid, int handle_id, int focus_type)
63 {
64         _mm_sound_mgr_focus_param_t param;
65         int ret = MM_ERROR_NONE;
66
67         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
68         param.pid = pid;
69         param.handle_id = handle_id;
70         param.request_type = focus_type;
71
72         ret = mm_sound_mgr_focus_add_watch_node(&param);
73
74         return ret;
75 }
76
77 int __mm_sound_mgr_focus_ipc_remove_watch_node(int pid, int handle_id)
78 {
79         _mm_sound_mgr_focus_param_t param;
80         int ret = MM_ERROR_NONE;
81
82         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
83         param.pid = pid;
84         param.handle_id = handle_id;
85
86         ret = mm_sound_mgr_focus_remove_watch_node(&param);
87
88         return ret;
89 }
90
91 // method -> callback
92 int __mm_sound_mgr_focus_ipc_set_focus_reacquisition(int pid, int handle_id, bool reacquisition)
93 {
94         _mm_sound_mgr_focus_param_t param;
95         int ret = MM_ERROR_NONE;
96
97         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
98         param.pid = pid;
99         param.handle_id = handle_id;
100         param.reacquisition = reacquisition;
101
102         ret = mm_sound_mgr_focus_set_reacquisition(&param);
103
104         return ret;
105 }
106
107 // method
108 int __mm_sound_mgr_focus_ipc_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
109 {
110         int ret = MM_ERROR_NONE;
111         char *stream_type_str = NULL;
112         char *ext_info_str = NULL;
113
114         if (!stream_type || !option)
115                 return MM_ERROR_INVALID_ARGUMENT;
116
117         ret = mm_sound_mgr_focus_get_stream_type_of_acquired_focus(focus_type, &stream_type_str, option, &ext_info_str);
118         if (ret == MM_ERROR_NONE) {
119                 *stream_type = stream_type_str;
120                 if (ext_info)
121                         *ext_info = ext_info_str;
122         }
123
124         return ret;
125 }
126
127 // method -> callback
128 int __mm_sound_mgr_focus_ipc_acquire_focus(int pid, int handle_id, int focus_type, int option, const char *ext_info, bool is_in_thread)
129 {
130         _mm_sound_mgr_focus_param_t param;
131         int ret = MM_ERROR_NONE;
132
133         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
134         param.pid = pid;
135         param.handle_id = handle_id;
136         param.request_type = focus_type;
137         param.option = option;
138         param.is_in_thread = is_in_thread;
139         MMSOUND_STRNCPY(param.ext_info, ext_info, MM_SOUND_NAME_NUM);
140
141         ret = mm_sound_mgr_focus_request_acquire(&param);
142
143         return ret;
144 }
145
146 // method -> callback
147 int __mm_sound_mgr_focus_ipc_release_focus(int pid, int handle_id, int focus_type, int option, const char *ext_info, bool is_in_thread)
148 {
149         _mm_sound_mgr_focus_param_t param;
150         int ret = MM_ERROR_NONE;
151
152         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
153         param.pid = pid;
154         param.handle_id = handle_id;
155         param.request_type = focus_type;
156         param.option = option;
157         param.is_in_thread = is_in_thread;
158         MMSOUND_STRNCPY(param.ext_info, ext_info, MM_SOUND_NAME_NUM);
159
160         ret = mm_sound_mgr_focus_request_release(&param);
161
162         return ret;
163 }
164
165 int __mm_sound_mgr_focus_ipc_deliver_focus(int pid, int src_handle_id, int dst_handle_id, int focus_type)
166 {
167         _mm_sound_mgr_focus_param_t param;
168         int ret = MM_ERROR_NONE;
169
170         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
171         param.pid = pid;
172         param.handle_id = src_handle_id;
173         param.handle_id_dst = dst_handle_id;
174         param.request_type = focus_type;
175
176         ret = mm_sound_mgr_focus_deliver(&param);
177
178         return ret;
179 }