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