Applying light weight ipc
[platform/core/multimedia/libmm-sound.git] / include / mm_sound_common.h
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 #ifndef __MM_SOUND_COMMON_H__
23 #define __MM_SOUND_COMMON_H__
24
25 #include <errno.h>
26
27 ///////////////////////////////////
28 ////     MMSOUND VOLUME APIs
29 ///////////////////////////////////
30 #define VCONF_KEY_VOLUME_PREFIX                         "file/private/sound/volume"
31 #define VCONF_KEY_VOLUME_TYPE_SYSTEM            VCONF_KEY_VOLUME_PREFIX"/system"
32 #define VCONF_KEY_VOLUME_TYPE_NOTIFICATION      VCONF_KEY_VOLUME_PREFIX"/notification"
33 #define VCONF_KEY_VOLUME_TYPE_ALARM                     VCONF_KEY_VOLUME_PREFIX"/alarm"
34 #define VCONF_KEY_VOLUME_TYPE_RINGTONE          VCONF_KEY_VOLUME_PREFIX"/ringtone"
35 #define VCONF_KEY_VOLUME_TYPE_MEDIA                     VCONF_KEY_VOLUME_PREFIX"/media"
36 #define VCONF_KEY_VOLUME_TYPE_CALL                      VCONF_KEY_VOLUME_PREFIX"/call"
37 #define VCONF_KEY_VOLUME_TYPE_VOIP                      VCONF_KEY_VOLUME_PREFIX"/voip"
38 #define VCONF_KEY_VOLUME_TYPE_VOICE             VCONF_KEY_VOLUME_PREFIX"/voice"
39 #define VCONF_KEY_VOLUME_TYPE_ANDROID           VCONF_KEY_VOLUME_PREFIX"/fixed"
40
41 #ifndef _TIZEN_PUBLIC_
42 #ifdef TIZEN_MICRO
43 #define VCONF_KEY_VR_LEFTHAND_ENABLED           VCONFKEY_SETAPPL_PERFERED_ARM_LEFT_BOOL
44 #endif
45 #endif
46
47 #define PA_READY "/tmp/.pa_ready"
48
49 #ifdef TIZEN_TV
50 #ifdef USE_LWIPC
51 #define SOUND_SERVER_READY "sound_server_ready"
52 #else
53 #define SOUND_SERVER_READY "/tmp/.sound_server_ready"
54 #endif
55 #endif
56
57 #define MMSOUND_ENTER_CRITICAL_SECTION(x_mutex) \
58 switch ( pthread_mutex_lock( x_mutex ) ) \
59 { \
60 case EINVAL: \
61         debug_warning("try mutex init..\n"); \
62         if( 0 > pthread_mutex_init( x_mutex, NULL) ) { \
63                 return; \
64         } else { \
65                 break; \
66         } \
67         return; \
68 case 0: \
69         break; \
70 default: \
71         debug_error("mutex lock failed\n"); \
72         return; \
73 }
74
75 #define MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(x_mutex,x_return) \
76 switch ( pthread_mutex_lock( x_mutex ) ) \
77 { \
78 case EINVAL: \
79         debug_warning("try mutex init..\n"); \
80         if( 0 > pthread_mutex_init( x_mutex, NULL) ) { \
81                 return x_return; \
82         } else { \
83                 break; \
84         } \
85         return x_return; \
86 case 0: \
87         break; \
88 default: \
89         debug_error("mutex lock failed\n"); \
90         return x_return; \
91 }
92
93 #define MMSOUND_LEAVE_CRITICAL_SECTION(x_mutex) \
94 if( pthread_mutex_unlock( x_mutex ) ) { \
95         debug_error("mutex unlock failed\n"); \
96 }
97
98 #define MMSOUND_STRNCPY(dst, src, size) \
99 do { \
100         if (dst == NULL) \
101                 debug_error("STRNCPY ERROR: Destination String is NULL"); \
102         else if (src == NULL) \
103                 debug_error("STRNCPY ERROR: Source String is NULL"); \
104         else if (size <= 0) \
105                 debug_error("STRNCPY ERROR: Size(%d) <= 0", size); \
106         else { \
107                 strncpy(dst, src, size - 1); \
108                 dst[size - 1] = '\0';\
109         } \
110 } while(0)
111
112 #endif /* __MM_SOUND_COMMON_H__ */
113