tizen 2.3 release
[framework/api/sound-manager.git] / src / sound_manager_private.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <sound_manager.h>
18 #include <sound_manager_private.h>
19
20 #include <mm_sound.h>
21 #include <dlog.h>
22
23 extern _session_interrupt_info_s g_session_interrupt_cb_table;
24
25 int __convert_sound_manager_error_code(const char *func, int code) {
26         int ret = SOUND_MANAGER_ERROR_NONE;
27         char *errorstr = NULL;
28
29         switch(code)
30         {
31                 case MM_ERROR_FILE_WRITE:
32                 case MM_ERROR_INVALID_HANDLE:
33                         ret = SOUND_MANAGER_ERROR_INVALID_OPERATION;
34                         errorstr = "INVALID_OPERATION";
35                         break;
36                 case MM_ERROR_NONE:
37                         ret = SOUND_MANAGER_ERROR_NONE;
38                         errorstr = "ERROR_NONE";
39                         break;
40                 case MM_ERROR_INVALID_ARGUMENT:
41                 case MM_ERROR_SOUND_INVALID_POINTER:
42                         ret = SOUND_MANAGER_ERROR_INVALID_PARAMETER;
43                         errorstr = "INVALID_PARAMETER";
44                         break;
45                 case MM_ERROR_SOUND_PERMISSION_DENIED:
46                         ret = SOUND_MANAGER_ERROR_PERMISSION_DENIED;
47                         errorstr = "PERMISSION_DENIED";
48                         break;
49                 case MM_ERROR_SOUND_NO_DATA:
50                         ret = SOUND_MANAGER_ERROR_NO_DATA;
51                         errorstr = "NO_DATA";
52                         break;
53                 case MM_ERROR_SOUND_INTERNAL:
54                 case MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY:
55                         ret = SOUND_MANAGER_ERROR_INTERNAL;
56                         errorstr = "INTERNAL";
57                         break;
58                 case MM_ERROR_POLICY_DUPLICATED:
59                 case MM_ERROR_POLICY_INTERNAL:
60                 case MM_ERROR_POLICY_BLOCKED:
61                         ret = SOUND_MANAGER_ERROR_POLICY;
62                         errorstr = "POLICY";
63                         break;
64                 case MM_ERROR_SOUND_VOLUME_NO_INSTANCE:
65                         ret = SOUND_MANAGER_ERROR_NO_PLAYING_SOUND;
66                         errorstr = "NO_PLAYING_SOUND";
67                         break;
68         }
69         LOGE("[%s] %s(0x%08x) : core frameworks error code(0x%08x)",func, errorstr, ret, code);
70         return ret;
71 }
72
73 void __session_interrupt_cb(session_msg_t msg, session_event_t event, void *user_data){
74         if( g_session_interrupt_cb_table.user_cb ){
75                 sound_session_interrupted_code_e e = SOUND_SESSION_INTERRUPTED_COMPLETED;
76                 if( msg == MM_SESSION_MSG_RESUME )
77                         e = SOUND_SESSION_INTERRUPTED_COMPLETED;
78                 else{
79                         switch(event){
80                                 case MM_SESSION_EVENT_MEDIA :
81                                         e = SOUND_SESSION_INTERRUPTED_BY_MEDIA;
82                                         break;
83                                 case MM_SESSION_EVENT_CALL :
84                                         e = SOUND_SESSION_INTERRUPTED_BY_CALL;
85                                         break;
86                                 case MM_SESSION_EVENT_ALARM :
87                                         e = SOUND_SESSION_INTERRUPTED_BY_ALARM;
88                                         break;
89                                 case MM_SESSION_EVENT_EARJACK_UNPLUG:
90                                         e = SOUND_SESSION_INTERRUPTED_BY_EARJACK_UNPLUG;
91                                         break;
92                                 case MM_SESSION_EVENT_RESOURCE_CONFLICT:
93                                         e = SOUND_SESSION_INTERRUPTED_BY_RESOURCE_CONFLICT;
94                                         break;
95                                 case MM_SESSION_EVENT_EMERGENCY:
96                                         e = SOUND_SESSION_INTERRUPTED_BY_EMERGENCY;
97                                         break;
98                                 case MM_SESSION_EVENT_NOTIFICATION :
99                                         e = SOUND_SESSION_INTERRUPTED_BY_NOTIFICATION;
100                                         break;
101                                 default :
102                                         e = SOUND_SESSION_INTERRUPTED_BY_MEDIA;
103                                         break;
104                         }
105                 }
106                 g_session_interrupt_cb_table.user_cb(e, g_session_interrupt_cb_table.user_data);
107         }
108 }