add subdir-objects option
[platform/core/multimedia/avsystem.git] / avsys-audio-shm.c
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 #include "avsys-audio-shm.h"
23 #include "avsys-common.h"
24 #include "avsys-error.h"
25 #include "avsys-audio-handle.h"
26 #include "avsys-audio-path.h"
27 #include "avsys-audio-logical-volume.h"
28
29 #define SHM_KEY_PATH "/tmp"
30
31 typedef struct {
32         avsys_shm_param_t param;
33         void *pdst;
34 } _avsys_audio_shm_control_t;
35
36 static _avsys_audio_shm_control_t g_presettings[AVSYS_AUDIO_SHM_IDEN_CNT] = {
37         {{SHM_KEY_PATH, AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO,AVSYS_AUDIO_SHM_IDEN_HANDLE) + 0x10,sizeof(avsys_audio_handle_info_t)}, NULL},
38         {{SHM_KEY_PATH, AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO,AVSYS_AUDIO_SHM_IDEN_PATH) + 0x10,sizeof(avsys_audio_path_ex_info_t)}, NULL},
39         {{SHM_KEY_PATH, AVSYS_KEY_PREFIX_GEN(AVSYS_KEY_PREFIX_AUDIO,AVSYS_AUDIO_SHM_IDEN_LVOLUME) + 0x10,sizeof(avsys_audio_lvol_info_t)}, NULL},
40 };
41
42 int avsys_audio_create_shm(const avsys_audio_shm_iden_t iden)
43 {
44         if (iden >= AVSYS_AUDIO_SHM_IDEN_CNT || 0 > iden)
45                 return AVSYS_STATE_ERR_INVALID_PARAMETER;
46         return avsys_create_shm(&g_presettings[iden].param);
47 }
48
49 int avsys_audio_remove_shm(const avsys_audio_shm_iden_t iden)
50 {
51         if (iden >= AVSYS_AUDIO_SHM_IDEN_CNT || 0 > iden)
52                 return AVSYS_STATE_ERR_INVALID_PARAMETER;
53         g_presettings[iden].pdst = NULL;
54         return avsys_remove_shm(&g_presettings[iden].param);
55 }
56
57 int avsys_audio_get_shm(const avsys_audio_shm_iden_t iden, void **ptr)
58 {
59         if (iden >= AVSYS_AUDIO_SHM_IDEN_CNT || 0 > iden)
60                 return AVSYS_STATE_ERR_INVALID_PARAMETER;
61
62         if (!ptr)
63                 return AVSYS_STATE_ERR_NULL_POINTER;
64
65         if (!g_presettings[iden].pdst) {
66                 g_presettings[iden].pdst = avsys_get_shm(&g_presettings[iden].param);
67                 if (!g_presettings[iden].pdst)
68                         return AVSYS_STATE_ERR_INTERNAL;
69         }
70         *ptr = (void *)g_presettings[iden].pdst;
71         return AVSYS_STATE_SUCCESS;
72 }