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