fixup! Adjust several operation's timeout threshold
[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 #define PA_READY "/tmp/.pa_ready"
28 #define SOUND_SERVER_READY "/tmp/.sound_server_ready"
29 #define FOCUS_SERVER_READY "/tmp/.focus_server_ready"
30 #define FOCUS_PATH_PREFIX "/tmp/focus/FOCUS."
31
32 #define MM_SOUND_NAME_NUM 32
33
34 #define MMSOUND_ENTER_CRITICAL_SECTION(x_mutex) \
35 switch (pthread_mutex_lock(x_mutex)) { \
36 case EINVAL: \
37         debug_warning("try mutex init.."); \
38         if (0 > pthread_mutex_init(x_mutex, NULL)) { \
39                 return; \
40         } else { \
41                 break; \
42         } \
43         return; \
44 case 0: \
45         break; \
46 default: \
47         debug_error("mutex lock failed"); \
48         return; \
49 }
50
51 #define MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(x_mutex, x_return) \
52 switch (pthread_mutex_lock(x_mutex)) { \
53 case EINVAL: \
54         debug_warning("try mutex init.."); \
55         if (0 > pthread_mutex_init(x_mutex, NULL)) { \
56                 return x_return; \
57         } else { \
58                 break; \
59         } \
60         return x_return; \
61 case 0: \
62         break; \
63 default: \
64         debug_error("mutex lock failed"); \
65         return x_return; \
66 }
67
68 #define MMSOUND_LEAVE_CRITICAL_SECTION(x_mutex) \
69 if (pthread_mutex_unlock(x_mutex)) { \
70         debug_error("mutex unlock failed"); \
71 }
72
73 #define MMSOUND_STRNCPY(dst, src, size) \
74 do { \
75         if (dst == NULL) \
76                 debug_error("STRNCPY ERROR: Destination String is NULL"); \
77         else if (src == NULL) \
78                 debug_error("STRNCPY ERROR: Source String is NULL"); \
79         else if (size <= 0) \
80                 debug_error("STRNCPY ERROR: Size(%d) <= 0", size); \
81         else { \
82                 strncpy(dst, src, size); \
83                 dst[size - 1] = '\0';\
84         } \
85 } while (0)
86
87 #endif /* __MM_SOUND_COMMON_H__ */
88