summaryrefslogtreecommitdiff
path: root/include/mm_attrs_private.h
blob: a303168e7d6903c8cb9ae5b3a5d58de7c71649fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 * libmm-common
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef MMF_ATTRS_PRIVATE_H_
#define MMF_ATTRS_PRIVATE_H_

#include <stdbool.h>
#include <mm_types.h>
#include <mm_attrs.h>
#include <pthread.h>

#ifdef __cplusplus
	extern "C" {
#endif

#define MMF_IS_VALUE_TYPE(t) ((t) == MMF_VALUE_TYPE_INT || \
		(t) == MMF_VALUE_TYPE_DOUBLE || \
		(t) == MMF_VALUE_TYPE_STRING || \
		(t) == MMF_VALUE_TYPE_DATA)

#define MMF_IS_VALUE_SPEC_TYPE(t) ((t) == MMF_VALUE_SPEC_NONE || \
		(t) == MMF_VALUE_SPEC_INT_ARRAY || \
		(t) == MMF_VALUE_SPEC_INT_RANGE) || \
		(t) == MMF_VALUE_SPEC_DOUBLE_ARRAY || \
		(t) == MMF_VALUE_SPEC_DOUBLE_RANGE)

#define MM_ATTR_ITEM_WRITE_LOCK(item)	do { pthread_mutex_lock(&item->write_lock); } while (0)
#define MM_ATTR_ITEM_WRITE_UNLOCK(item)	do { pthread_mutex_unlock(&item->write_lock); } while (0)

enum mmf_value_type {
	MMF_VALUE_TYPE_INT = MM_ATTRS_TYPE_INT,
	MMF_VALUE_TYPE_DOUBLE=MM_ATTRS_TYPE_DOUBLE,
	MMF_VALUE_TYPE_STRING = MM_ATTRS_TYPE_STRING,
	MMF_VALUE_TYPE_DATA = MM_ATTRS_TYPE_DATA,
};

enum mmf_value_spec_type {
	MMF_VALUE_SPEC_NONE = MM_ATTRS_VALID_TYPE_NONE,
	MMF_VALUE_SPEC_INT_ARRAY = MM_ATTRS_VALID_TYPE_INT_ARRAY,
	MMF_VALUE_SPEC_INT_RANGE = MM_ATTRS_VALID_TYPE_INT_RANGE,
	MMF_VALUE_SPEC_DOUBLE_ARRAY = MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY,
	MMF_VALUE_SPEC_DOUBLE_RANGE = MM_ATTRS_VALID_TYPE_DOUBLE_RANGE,
};

typedef struct mmf_value					mmf_value_t;
typedef struct mmf_value_spec				mmf_value_spec_t;
typedef struct mmf_attribute				mmf_attribute_t;
typedef struct mmf_attrs					mmf_attrs_t;
typedef struct mmf_attrs_list				mmf_attrs_list_t;
typedef struct mmf_attribute_construct_info	mmf_attrs_construct_info_t;

typedef bool (*mmf_attrs_commit_func_t)(int attr_idx,
                                        const char* attr_name,
                                        const mmf_value_t *value,
                                        void *commit_param);

struct mmf_value {
	int type;
	int size;
	union {
		int i_val;
		double d_val;
		char *s_val;
		void *p_val;
	} value;
};

struct mmf_value_spec {
	int type;
	union {
		union {
			struct {
				int *array;
				int count;
				int dval;
			} array;
			struct {
				int min;
				int max;
				int dval;
			} range;
		} int_spec;
		union {
			struct {
				double *array;
				int count;
				double dval;
			} array;
			struct {
				double min;
				double max;
				double dval;
			} range;
		} double_spec;
		struct {
			int max_length;
		} string_spec;
	} spec;
};

struct mmf_attribute {
	char *name;
	int flags;
	mmf_value_t value;
	mmf_value_t tmpval;
	mmf_value_spec_t value_spec;
	pthread_mutex_t write_lock;
};

struct mmf_attrs {
	char *name;
	int count;
	mmf_attribute_t *items;
	mmf_attrs_commit_func_t commit_func;
	void *commit_param;
};

struct mmf_attrs_list {
	MMHandleType attrs;
	mmf_attrs_list_t *next;
};

struct mmf_attribute_construct_info {
	char *name;
	int value_type;
	int flags;
	void *default_value;
};

int mmf_value_init(mmf_value_t *value, int type);

int mmf_value_copy(mmf_value_t *dest, const mmf_value_t *src);

int mmf_value_set_int(mmf_value_t *v, int ival);

int mmf_value_get_int(const mmf_value_t *v);

int mmf_value_set_double(mmf_value_t *v, double dval);

double mmf_value_get_double(mmf_value_t *v);

int mmf_value_set_string(mmf_value_t *v, const char *sval, int size);

char* mmf_value_get_string(const mmf_value_t *v, int *size);

int mmf_value_set_data(mmf_value_t *v, void *data, int size);

void* mmf_value_get_data(const mmf_value_t *v, int *size);

void mmf_value_dump(const mmf_value_t *value);

int mmf_value_clear(mmf_value_t *value);

int mmf_value_spec_init(mmf_value_spec_t *vs, int vs_type);

int mmf_value_spec_set_int_range(mmf_value_spec_t *vs, int min, int max, int dval);

int mmf_value_spec_get_int_range(mmf_value_spec_t *vs, int *min, int *max, int *dval);

int mmf_value_spec_set_int_array(mmf_value_spec_t *vs, const int *array, int count, int dval);

int mmf_value_spec_get_int_array(mmf_value_spec_t *vs, int **array, int *count, int *dval);

int mmf_value_spec_set_double_range(mmf_value_spec_t *vs, double min, double max, double dval);

int mmf_value_spec_get_double_range(mmf_value_spec_t *vs, double *min, double *max, double *dval);

int mmf_value_spec_set_double_array(mmf_value_spec_t *vs, const double *array, int count, double dval);

int mmf_value_spec_get_double_array(mmf_value_spec_t *vs, double **array, int *count, double *dval);

int mmf_value_spec_clear(mmf_value_spec_t *vs);

int mmf_attribute_init(mmf_attribute_t *item, const char *name, int value_type, int flags);

bool mmf_attribute_check_flags(mmf_attribute_t *item, int flags);

bool mmf_attribute_validate_int(mmf_attribute_t *item, int val);

bool mmf_attribute_validate_double(mmf_attribute_t *item, double val);

void mmf_attribute_clear(mmf_attribute_t *item);

bool mmf_attribute_is_modified(mmf_attribute_t *item);

void mmf_attribute_set_modified(mmf_attribute_t *item);

void mmf_attribute_set_readonly(mmf_attribute_t *item);

void mmf_attribute_set_disabled(mmf_attribute_t *item);

void mmf_attribute_commit(mmf_attribute_t *item);

int mmf_attribute_set_int(mmf_attribute_t *item, int val);

int mmf_attribute_set_double(mmf_attribute_t *item, double val);

int mmf_attribute_set_string(mmf_attribute_t *item, const char *string, int size);

int mmf_attribute_set_data(mmf_attribute_t *item, void *data, int size);

/* --- Create, Destroy and Initialize MmfAttrs --- */

MMHandleType mmf_attrs_new(int count);

MMHandleType mmf_attrs_new_from_data(const char *name,
                                     mmf_attrs_construct_info_t *info,
                                     int count,
                                     mmf_attrs_commit_func_t commit_func,
                                     void *commit_param);

void mmf_attrs_free(MMHandleType attrs);

int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count);

int mmf_attrs_commit(MMHandleType h);

int mmf_attrs_commit_err(MMHandleType h, char **err_attr_name);

int mmf_attrs_set_valid_type(MMHandleType h, int idx, int v_type);

int mmf_attrs_set_valid_range(MMHandleType h, int idx, int min, int max, int dval);

int mmf_attrs_set_valid_array(MMHandleType h, int idx, const int *array, int count, int dval);

int mmf_attrs_set_valid_double_range(MMHandleType h, int idx, double min, double max, double dval);

int mmf_attrs_set_valid_double_array(MMHandleType h, int idx, const double *array, int count, double dval);


#ifdef __cplusplus
	}
#endif

#endif /*MMF_ATTRS_PRIVATE_H_*/