tizen beta release
[platform/core/multimedia/avsystem.git] / include / avsys-common.h
1 /*
2  * avsystem
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jonghyuk Choi <jhchoi.choi@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 __AVSYS_COMMON_H__
23 #define __AVSYS_COMMON_H__
24
25 #include <stdlib.h>
26 #include <sys/syscall.h>
27
28 #ifdef __cplusplus
29     extern "C" {
30 #endif
31 #define EXPORT_API __attribute__((__visibility__("default")))
32
33 #define AVSYS_MAGIC_START   "TSVA"
34 #define AVSYS_MAGIC_END     "NEVA"
35
36 #define AVSYS_KEY_PREFIX_AUDIO 0x10
37 #define AVSYS_KEY_PREFIX_GEN(X,Y) ((X) + (Y))
38
39 typedef struct {
40     char    *key_path;
41     int     key_prefix;
42     int     size;
43 } avsys_shm_param_t;
44
45 typedef struct {
46     char    *key_path;
47     int     key_prefix;
48 } avsys_sync_param_t;
49
50
51 #define LOCK_TIMEOUT_SEC 6
52
53 /* get thread id : Not implemented 'gettid' at system libs. */
54 #define avsys_gettid() (long int)syscall(__NR_gettid)
55
56 /* memory */
57 void * avsys_malloc(size_t size);
58 void avsys_free(void *ptr);
59 #define avsys_mem_check(ptr) ( (memcmp(AVSYS_MAGIC_START, ((char*)(ptr))-8, 4) == 0) && \
60                                                 (memcmp(AVSYS_MAGIC_END, ((char*)(ptr))+(*((int*)((ptr)-4))), 4) == 0) )
61
62 /* shared memory */
63 int avsys_create_shm(const avsys_shm_param_t* param);
64 int avsys_remove_shm(const avsys_shm_param_t* param);
65 void* avsys_get_shm(const avsys_shm_param_t* param);
66
67 /* Sync object */
68 int avsys_create_sync(const avsys_sync_param_t *param);
69 int avsys_remove_sync(const avsys_sync_param_t *param);
70 int avsys_lock_sync(const avsys_sync_param_t *param);
71 int avsys_unlock_sync(const avsys_sync_param_t *param);
72
73 /* Privilege */
74 int avsys_check_root_privilege(void);
75
76 #ifdef __cplusplus
77         }
78 #endif
79
80 #endif /* __AVSYS_COMMON_H__ */