e9c1093d1860b668f385d9f3e3dc06840823505f
[platform/core/multimedia/libmm-common.git] / include / mm_attrs_private.h
1 /*
2  * libmm-common
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 MMF_ATTRS_PRIVATE_H_
23 #define MMF_ATTRS_PRIVATE_H_
24
25 #include <stdbool.h>
26 #include <mm_types.h>
27 #include <mm_attrs.h>
28 #include <pthread.h>
29
30 #ifdef __cplusplus
31         extern "C" {
32 #endif
33
34 #define MMF_IS_VALUE_TYPE(t) ((t) == MMF_VALUE_TYPE_INT || \
35                 (t) == MMF_VALUE_TYPE_DOUBLE || \
36                 (t) == MMF_VALUE_TYPE_STRING || \
37                 (t) == MMF_VALUE_TYPE_DATA)
38
39 #define MMF_IS_VALUE_SPEC_TYPE(t) ((t) == MMF_VALUE_SPEC_NONE || \
40                 (t) == MMF_VALUE_SPEC_INT_ARRAY || \
41                 (t) == MMF_VALUE_SPEC_INT_RANGE) || \
42                 (t) == MMF_VALUE_SPEC_DOUBLE_ARRAY || \
43                 (t) == MMF_VALUE_SPEC_DOUBLE_RANGE)
44
45 #define MM_ATTRS_WRITE_LOCK(attrs)              do { pthread_mutex_lock(&attrs->write_lock); } while (0)
46 #define MM_ATTRS_WRITE_UNLOCK(attrs)    do { pthread_mutex_unlock(&attrs->write_lock); } while (0)
47
48 enum mmf_value_type {
49         MMF_VALUE_TYPE_INT = MM_ATTRS_TYPE_INT,
50         MMF_VALUE_TYPE_DOUBLE=MM_ATTRS_TYPE_DOUBLE,
51         MMF_VALUE_TYPE_STRING = MM_ATTRS_TYPE_STRING,
52         MMF_VALUE_TYPE_DATA = MM_ATTRS_TYPE_DATA,
53 };
54
55 enum mmf_value_spec_type {
56         MMF_VALUE_SPEC_NONE = MM_ATTRS_VALID_TYPE_NONE,
57         MMF_VALUE_SPEC_INT_ARRAY = MM_ATTRS_VALID_TYPE_INT_ARRAY,
58         MMF_VALUE_SPEC_INT_RANGE = MM_ATTRS_VALID_TYPE_INT_RANGE,
59         MMF_VALUE_SPEC_DOUBLE_ARRAY = MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY,
60         MMF_VALUE_SPEC_DOUBLE_RANGE = MM_ATTRS_VALID_TYPE_DOUBLE_RANGE,
61 };
62
63 typedef struct mmf_value                                        mmf_value_t;
64 typedef struct mmf_value_spec                           mmf_value_spec_t;
65 typedef struct mmf_attribute                            mmf_attribute_t;
66 typedef struct mmf_attrs                                        mmf_attrs_t;
67 typedef struct mmf_attrs_list                           mmf_attrs_list_t;
68 typedef struct mmf_attribute_construct_info     mmf_attrs_construct_info_t;
69
70 typedef bool (*mmf_attrs_commit_func_t)(int attr_idx,
71                                         const char* attr_name,
72                                         const mmf_value_t *value,
73                                         void *commit_param);
74
75 struct mmf_value {
76         int type;
77         int size;
78         union {
79                 int i_val;
80                 double d_val;
81                 char *s_val;
82                 void *p_val;
83         } value;
84 };
85
86 struct mmf_value_spec {
87         int type;
88         union {
89                 union {
90                         struct {
91                                 int *array;
92                                 int count;
93                                 int dval;
94                         } array;
95                         struct {
96                                 int min;
97                                 int max;
98                                 int dval;
99                         } range;
100                 } int_spec;
101                 union {
102                         struct {
103                                 double *array;
104                                 int count;
105                                 double dval;
106                         } array;
107                         struct {
108                                 double min;
109                                 double max;
110                                 double dval;
111                         } range;
112                 } double_spec;
113                 struct {
114                         int max_length;
115                 } string_spec;
116         } spec;
117 };
118
119 struct mmf_attribute {
120         char *name;
121         int flags;
122         mmf_value_t value;
123         mmf_value_t tmpval;
124         mmf_value_spec_t value_spec;
125 };
126
127 struct mmf_attrs {
128         char *name;
129         int count;
130         mmf_attribute_t *items;
131         mmf_attrs_commit_func_t commit_func;
132         void *commit_param;
133         pthread_mutex_t write_lock;
134 };
135
136 struct mmf_attrs_list {
137         MMHandleType attrs;
138         mmf_attrs_list_t *next;
139 };
140
141 struct mmf_attribute_construct_info {
142         char *name;
143         int value_type;
144         int flags;
145         void *default_value;
146 };
147
148 int mmf_value_init(mmf_value_t *value, int type);
149
150 int mmf_value_copy(mmf_value_t *dest, const mmf_value_t *src);
151
152 int mmf_value_set_int(mmf_value_t *v, int ival);
153
154 int mmf_value_get_int(const mmf_value_t *v);
155
156 int mmf_value_set_double(mmf_value_t *v, double dval);
157
158 double mmf_value_get_double(mmf_value_t *v);
159
160 int mmf_value_set_string(mmf_value_t *v, const char *sval, int size);
161
162 char* mmf_value_get_string(const mmf_value_t *v, int *size);
163
164 int mmf_value_set_data(mmf_value_t *v, void *data, int size);
165
166 void* mmf_value_get_data(const mmf_value_t *v, int *size);
167
168 void mmf_value_dump(const mmf_value_t *value);
169
170 int mmf_value_clear(mmf_value_t *value);
171
172 int mmf_value_spec_init(mmf_value_spec_t *vs, int vs_type);
173
174 int mmf_value_spec_set_int_range(mmf_value_spec_t *vs, int min, int max, int dval);
175
176 int mmf_value_spec_get_int_range(mmf_value_spec_t *vs, int *min, int *max, int *dval);
177
178 int mmf_value_spec_set_int_array(mmf_value_spec_t *vs, const int *array, int count, int dval);
179
180 int mmf_value_spec_get_int_array(mmf_value_spec_t *vs, int **array, int *count, int *dval);
181
182 int mmf_value_spec_set_double_range(mmf_value_spec_t *vs, double min, double max, double dval);
183
184 int mmf_value_spec_get_double_range(mmf_value_spec_t *vs, double *min, double *max, double *dval);
185
186 int mmf_value_spec_set_double_array(mmf_value_spec_t *vs, const double *array, int count, double dval);
187
188 int mmf_value_spec_get_double_array(mmf_value_spec_t *vs, double **array, int *count, double *dval);
189
190 int mmf_value_spec_clear(mmf_value_spec_t *vs);
191
192 int mmf_attribute_init(mmf_attribute_t *item, const char *name, int value_type, int flags);
193
194 bool mmf_attribute_check_flags(mmf_attribute_t *item, int flags);
195
196 bool mmf_attribute_validate_int(mmf_attribute_t *item, int val);
197
198 bool mmf_attribute_validate_double(mmf_attribute_t *item, double val);
199
200 void mmf_attribute_clear(mmf_attribute_t *item);
201
202 bool mmf_attribute_is_modified(mmf_attribute_t *item);
203
204 void mmf_attribute_set_modified(mmf_attribute_t *item);
205
206 void mmf_attribute_set_readonly(mmf_attribute_t *item);
207
208 void mmf_attribute_set_disabled(mmf_attribute_t *item);
209
210 void mmf_attribute_commit(mmf_attribute_t *item);
211
212 int mmf_attribute_set_int(mmf_attribute_t *item, int val);
213
214 int mmf_attribute_set_double(mmf_attribute_t *item, double val);
215
216 int mmf_attribute_set_string(mmf_attribute_t *item, const char *string, int size);
217
218 int mmf_attribute_set_data(mmf_attribute_t *item, void *data, int size);
219
220 /* --- Create, Destroy and Initialize MmfAttrs --- */
221
222 MMHandleType mmf_attrs_new(int count);
223
224 MMHandleType mmf_attrs_new_from_data(const char *name,
225                                      mmf_attrs_construct_info_t *info,
226                                      int count,
227                                      mmf_attrs_commit_func_t commit_func,
228                                      void *commit_param);
229
230 void mmf_attrs_free(MMHandleType attrs);
231
232 int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count);
233
234 int mmf_attrs_commit(MMHandleType h);
235
236 int mmf_attrs_commit_err(MMHandleType h, char **err_attr_name);
237
238 int mmf_attrs_set_valid_type(MMHandleType h, int idx, int v_type);
239
240 int mmf_attrs_set_valid_range(MMHandleType h, int idx, int min, int max, int dval);
241
242 int mmf_attrs_set_valid_array(MMHandleType h, int idx, const int *array, int count, int dval);
243
244 int mmf_attrs_set_valid_double_range(MMHandleType h, int idx, double min, double max, double dval);
245
246 int mmf_attrs_set_valid_double_array(MMHandleType h, int idx, const double *array, int count, double dval);
247
248
249 #ifdef __cplusplus
250         }
251 #endif
252
253 #endif /*MMF_ATTRS_PRIVATE_H_*/