4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef MMF_ATTRS_PRIVATE_H_
23 #define MMF_ATTRS_PRIVATE_H_
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)
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)
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)
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,
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,
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;
70 typedef bool (*mmf_attrs_commit_func_t)(int attr_idx,
71 const char* attr_name,
72 const mmf_value_t *value,
86 struct mmf_value_spec {
119 struct mmf_attribute {
124 mmf_value_spec_t value_spec;
130 mmf_attribute_t *items;
131 mmf_attrs_commit_func_t commit_func;
133 pthread_mutex_t write_lock;
136 struct mmf_attrs_list {
138 mmf_attrs_list_t *next;
141 struct mmf_attribute_construct_info {
148 int mmf_value_init(mmf_value_t *value, int type);
150 int mmf_value_copy(mmf_value_t *dest, const mmf_value_t *src);
152 int mmf_value_set_int(mmf_value_t *v, int ival);
154 int mmf_value_get_int(const mmf_value_t *v);
156 int mmf_value_set_double(mmf_value_t *v, double dval);
158 double mmf_value_get_double(mmf_value_t *v);
160 int mmf_value_set_string(mmf_value_t *v, const char *sval, int size);
162 char* mmf_value_get_string(const mmf_value_t *v, int *size);
164 int mmf_value_set_data(mmf_value_t *v, void *data, int size);
166 void* mmf_value_get_data(const mmf_value_t *v, int *size);
168 void mmf_value_dump(const mmf_value_t *value);
170 int mmf_value_clear(mmf_value_t *value);
172 int mmf_value_spec_init(mmf_value_spec_t *vs, int vs_type);
174 int mmf_value_spec_set_int_range(mmf_value_spec_t *vs, int min, int max, int dval);
176 int mmf_value_spec_get_int_range(mmf_value_spec_t *vs, int *min, int *max, int *dval);
178 int mmf_value_spec_set_int_array(mmf_value_spec_t *vs, const int *array, int count, int dval);
180 int mmf_value_spec_get_int_array(mmf_value_spec_t *vs, int **array, int *count, int *dval);
182 int mmf_value_spec_set_double_range(mmf_value_spec_t *vs, double min, double max, double dval);
184 int mmf_value_spec_get_double_range(mmf_value_spec_t *vs, double *min, double *max, double *dval);
186 int mmf_value_spec_set_double_array(mmf_value_spec_t *vs, const double *array, int count, double dval);
188 int mmf_value_spec_get_double_array(mmf_value_spec_t *vs, double **array, int *count, double *dval);
190 int mmf_value_spec_clear(mmf_value_spec_t *vs);
192 int mmf_attribute_init(mmf_attribute_t *item, const char *name, int value_type, int flags);
194 bool mmf_attribute_check_flags(mmf_attribute_t *item, int flags);
196 bool mmf_attribute_validate_int(mmf_attribute_t *item, int val);
198 bool mmf_attribute_validate_double(mmf_attribute_t *item, double val);
200 void mmf_attribute_clear(mmf_attribute_t *item);
202 bool mmf_attribute_is_modified(mmf_attribute_t *item);
204 void mmf_attribute_set_modified(mmf_attribute_t *item);
206 void mmf_attribute_set_readonly(mmf_attribute_t *item);
208 void mmf_attribute_set_disabled(mmf_attribute_t *item);
210 void mmf_attribute_commit(mmf_attribute_t *item);
212 int mmf_attribute_set_int(mmf_attribute_t *item, int val);
214 int mmf_attribute_set_double(mmf_attribute_t *item, double val);
216 int mmf_attribute_set_string(mmf_attribute_t *item, const char *string, int size);
218 int mmf_attribute_set_data(mmf_attribute_t *item, void *data, int size);
220 /* --- Create, Destroy and Initialize MmfAttrs --- */
222 MMHandleType mmf_attrs_new(int count);
224 MMHandleType mmf_attrs_new_from_data(const char *name,
225 mmf_attrs_construct_info_t *info,
227 mmf_attrs_commit_func_t commit_func,
230 void mmf_attrs_free(MMHandleType attrs);
232 int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count);
234 int mmf_attrs_commit(MMHandleType h);
236 int mmf_attrs_commit_err(MMHandleType h, char **err_attr_name);
238 int mmf_attrs_set_valid_type(MMHandleType h, int idx, int v_type);
240 int mmf_attrs_set_valid_range(MMHandleType h, int idx, int min, int max, int dval);
242 int mmf_attrs_set_valid_array(MMHandleType h, int idx, const int *array, int count, int dval);
244 int mmf_attrs_set_valid_double_range(MMHandleType h, int idx, double min, double max, double dval);
246 int mmf_attrs_set_valid_double_array(MMHandleType h, int idx, const double *array, int count, double dval);
253 #endif /*MMF_ATTRS_PRIVATE_H_*/