summaryrefslogtreecommitdiff
path: root/mm_attrs.c
blob: fefd2d9047c528b937a0685ee005d01b7f09f37f (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*
 * 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.
 *
 */



#include <stdio.h>
#include <stdbool.h>
#include <malloc.h>
#include <string.h>
#include <assert.h>
#include "mm_debug.h"
#include "mm_attrs.h"
#include "mm_attrs_private.h"
#include "mm_error.h"

int mm_attrs_get_type(MMHandleType h, int idx, MMAttrsType *attrtype)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(h && idx >= 0 && idx < attrs->count && attrtype, MM_ERROR_COMMON_INVALID_ARGUMENT);
	*attrtype=attrs->items[idx].value.type;
	return MM_ERROR_NONE;
}


int mm_attrs_get_flags(MMHandleType h, int idx, int *flags)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && flags, MM_ERROR_COMMON_INVALID_ARGUMENT);

	*flags=attrs->items[idx].flags;
	return MM_ERROR_NONE;
}


int mm_attrs_get_valid_type(MMHandleType h, int idx, int *type)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && type, MM_ERROR_COMMON_INVALID_ARGUMENT);
	*type=attrs->items[idx].value_spec.type;
	return MM_ERROR_NONE;
}


int mm_attrs_get_valid_range(MMHandleType h, int idx, int *min, int *max)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && min && max, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (min) {
		*min = attrs->items[idx].value_spec.spec.int_spec.range.min;
	}
	if (max) {
		*max = attrs->items[idx].value_spec.spec.int_spec.range.max;
	}
	return MM_ERROR_NONE;
}


int mm_attrs_get_valid_array(MMHandleType h, int idx, int *count,  int **array)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	if (count)
		*count = 0;
	return_val_if_fail(attrs && count && idx >= 0 && idx < attrs->count && array, MM_ERROR_COMMON_INVALID_ARGUMENT);
	if (count)
		*count = attrs->items[idx].value_spec.spec.int_spec.array.count;
	*array=attrs->items[idx].value_spec.spec.int_spec.array.array;
	return MM_ERROR_NONE;
}


int mm_attrs_get_size(MMHandleType h, int *size)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(h && size, MM_ERROR_COMMON_INVALID_ARGUMENT);
	*size = attrs->count;
	return MM_ERROR_NONE;
}


int mm_attrs_get_name(MMHandleType h, int idx, char **name)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
	*name = attrs->items[idx].name;
	return MM_ERROR_NONE;
}


int mm_attrs_get_index(MMHandleType h, const char *attrname, int *index)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	int i;

	return_val_if_fail(h && attrname && index, MM_ERROR_COMMON_INVALID_ARGUMENT);

	for (i = 0; i < attrs->count; i++) {
		if (0 == strcmp(attrs->items[i].name, attrname)) {
			*index = i;
			return MM_ERROR_NONE;
		}
	}
	return MM_ERROR_COMMON_OUT_OF_ARRAY;
}


int mm_attrs_set_int(MMHandleType h, int idx, int val)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mmf_attribute_t *item = &attrs->items[idx];
	return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
	{
		return MM_ERROR_COMMON_INVALID_PERMISSION;
	}

	if (mmf_attribute_validate_int(item, val))
	{
		int ret = 0;
		ret = mmf_attribute_set_int(item, val);

		if (ret == 0)
			return MM_ERROR_NONE;
		else
			return MM_ERROR_COMMON_INVALID_ATTRTYPE;
	}

	if (item->value_spec.type == MMF_VALUE_SPEC_INT_RANGE)
		return MM_ERROR_COMMON_OUT_OF_RANGE;
	else if (item->value_spec.type == MMF_VALUE_SPEC_INT_ARRAY)
		return MM_ERROR_COMMON_OUT_OF_ARRAY;
	else
		return MM_ERROR_COMMON_INVALID_ARGUMENT;
}


int mm_attrs_get_int(MMHandleType h, int idx,  int *val)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
	mmf_attribute_t *item = &attrs->items[idx];
	return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE))
	{
		*val=mmf_value_get_int(&attrs->items[idx].value);
		return MM_ERROR_NONE;
	}

	return MM_ERROR_COMMON_INVALID_PERMISSION;
}


int mm_attrs_set_double(MMHandleType h, int idx, double val)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mmf_attribute_t *item = &attrs->items[idx];
	return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
	{
		return MM_ERROR_COMMON_INVALID_PERMISSION;
	}

	if (mmf_attribute_validate_double(item, val))
	{
		int ret = 0;
		ret = mmf_attribute_set_double(item, val);

		if (ret == 0)
			return MM_ERROR_NONE;
		else
			return MM_ERROR_COMMON_INVALID_ATTRTYPE;
	}

	if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_RANGE)
		return MM_ERROR_COMMON_OUT_OF_RANGE;
	else if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_ARRAY)
		return MM_ERROR_COMMON_OUT_OF_ARRAY;
	else
		return MM_ERROR_COMMON_INVALID_ARGUMENT;
}


int mm_attrs_get_double(MMHandleType h, int idx, double *val)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
	mmf_attribute_t *item = &attrs->items[idx];
	return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE))
	{
		*val=mmf_value_get_double(&attrs->items[idx].value);
		return MM_ERROR_NONE;
	}

	return MM_ERROR_COMMON_INVALID_PERMISSION;
}


int mm_attrs_set_string(MMHandleType h, int idx, const char *string, int size)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mmf_attribute_t *item = &attrs->items[idx];

	return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);

	MM_ATTR_ITEM_WRITE_LOCK(item);

	if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
	{
		int ret = 0;
		ret = mmf_attribute_set_string(item, string, size);

		MM_ATTR_ITEM_WRITE_UNLOCK(item);

		if (ret == 0)
			return MM_ERROR_NONE;
		else
			return MM_ERROR_COMMON_INVALID_ARGUMENT;
	}

	MM_ATTR_ITEM_WRITE_UNLOCK(item);

	return MM_ERROR_COMMON_INVALID_PERMISSION;
}


int mm_attrs_get_string(MMHandleType h, int idx, char **sval, int *size)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	mmf_attribute_t *item = NULL;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT);

	item = &attrs->items[idx];

	MM_ATTR_ITEM_WRITE_LOCK(item);

	if (!(item->flags & MM_ATTRS_FLAG_READABLE)) {
		//mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
		MM_ATTR_ITEM_WRITE_UNLOCK(item);
		return MM_ERROR_COMMON_INVALID_PERMISSION;
	}

	*sval = mmf_value_get_string(&item->value, size);

	MM_ATTR_ITEM_WRITE_UNLOCK(item);

	return MM_ERROR_NONE;
}


int mm_attrs_set_data(MMHandleType h, int idx, void *data, int size)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mmf_attribute_t *item = &attrs->items[idx];
	return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
	{
		int ret = 0;
		ret =  mmf_attribute_set_data(item, data, size);

		if (ret == 0)
			return MM_ERROR_NONE;
		else
			return MM_ERROR_COMMON_INVALID_ARGUMENT;
	}

	return MM_ERROR_COMMON_INVALID_ARGUMENT;
}


int mm_attrs_get_data(MMHandleType h, int idx,void **data,  int *size)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;
	return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && data, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (!(attrs->items[idx].flags & MM_ATTRS_FLAG_READABLE)) {
		//mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
		return MM_ERROR_COMMON_INVALID_PERMISSION;
	}
	*data=mmf_value_get_data(&attrs->items[idx].value,size);
	return MM_ERROR_NONE;
}


int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int val)
{
	return_val_if_fail(attrs && name, -1);
	int idx = 0;
	mm_attrs_get_index(attrs, name, &idx);
	if (idx >= 0) {
		return mm_attrs_set_int(attrs, idx, val);
	}
	return -1;
}


int mm_attrs_get_int_by_name(MMHandleType attrs, const char *name, int *val)
{
	int idx = -1;
	return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
	mm_attrs_get_index(attrs, name, &idx);
	if (idx >= 0) {
		return mm_attrs_get_int(attrs, idx, val);
	}
	return MM_ERROR_COMMON_INVALID_ATTRTYPE;
}


int mm_attrs_set_string_by_name(MMHandleType attrs, const char *name, const char *string)
{
	return_val_if_fail(attrs && name, -1);

	int size;
	int idx = 0;
	mm_attrs_get_index(attrs, name, &idx);
	if (idx >= 0) {
		if (string) {
			size = strlen(string);
		}
		else {
			string = NULL;
			size = 0;
		}

		return mm_attrs_set_string(attrs, idx, string, size);
	}
	return -1;
}


int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **string)
{
	int idx = -1;
	int len = 0;
	return_val_if_fail(attrs && name && string, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mm_attrs_get_index(attrs, name, &idx);
	if (idx >= 0) {
		return mm_attrs_get_string(attrs, idx, string, &len);
	}
	return MM_ERROR_COMMON_INVALID_ATTRTYPE;
}


int mm_attrs_set_data_by_name(MMHandleType attrs, const char *name, void *data, int size)
{
	return_val_if_fail(attrs && name, -1);
	int idx = 0;
	mm_attrs_get_index(attrs, name, &idx);

	if (idx >= 0) {
		return mm_attrs_set_data(attrs, idx, data, size);
	}
	return -1;
}


int mm_attrs_get_data_by_name(MMHandleType attrs, const char *name, void **data)
{
	int idx = -1;
	int len = 0;

	return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mm_attrs_get_index(attrs, name, &idx);
	if (idx >= 0) {
		return mm_attrs_get_data(attrs, idx, data, &len);
	}
	return MM_ERROR_COMMON_INVALID_ATTRTYPE;
}


int mm_attrs_set_double_by_name(MMHandleType attrs, const char *name, double val)
{
	int idx = -1;
	return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mm_attrs_get_index(attrs, name, &idx);
	if (idx >= 0) {
		return mm_attrs_set_double(attrs, idx, val);
	}
	return MM_ERROR_COMMON_INVALID_ATTRTYPE;
}


int mm_attrs_get_double_by_name(MMHandleType attrs, const char *name, double *val)
{
	int idx = -1;
	return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);

	mm_attrs_get_index(attrs, name, &idx);
	if (idx >= 0) {
		*val = mm_attrs_get_double(attrs, idx, val);
		return 0;
	}
	return MM_ERROR_COMMON_INVALID_ATTRTYPE;
}


int mm_attrs_set_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
{
	const char *name = NULL;
	unsigned int ret = MM_ERROR_NONE;

	return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
//	return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
	return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (err_attr_name)
		*err_attr_name = NULL;
	name = attribute_name;

	while (name)
	{
		int idx = -1;
		MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;

		//name check
		if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
		{
			if (err_attr_name)
				*err_attr_name = strdup(name);

			if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY) {	//to avoid confusing
				//mmf_debug(MMF_DEBUG_ERROR, "result of mm_attrs_get_index is MM_ERROR_COMMON_OUT_OF_ARRAY so return(ret = %x, name:%s)",ret, name);
				return MM_ERROR_COMMON_ATTR_NOT_EXIST;
			} else {
				//mmf_debug(MMF_DEBUG_ERROR, "result of mm_attrs_get_index is %x so return(name:%s)",ret, name);
				return ret;
			}
		}

		//type check
		if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
			return ret;

		//cast and set
		switch (attr_type)
		{
			case MM_ATTRS_TYPE_INT:
			{
				int val = 	va_arg ((var_args), int);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: %d)\n", name, val);
				ret = mm_attrs_set_int(attrs, idx, val);
				break;
			}
			case MM_ATTRS_TYPE_DOUBLE:
			{
				double val = va_arg ((var_args), double);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: %f)\n", name, val);
				ret = mm_attrs_set_double(attrs, idx, val);
				break;
			}
			case MM_ATTRS_TYPE_STRING:
			{
				char * val = va_arg ((var_args), char*);
				int size = va_arg ((var_args), int);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: \'%s\', size: %d)\n", name, val, size);
				ret = mm_attrs_set_string(attrs, idx, (const char*)val, size);
				break;
			}
			case MM_ATTRS_TYPE_DATA:
			{
				void * val = va_arg ((var_args), void*);
				int size = va_arg ((var_args), int);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %d)\n", name, val, size);
				ret = mm_attrs_set_data(attrs, idx, val, size);
				break;
			}
			case MM_ATTRS_TYPE_INVALID:
			default:
				//mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
				return MM_ERROR_COMMON_INVALID_ARGUMENT;
				break;
		}

		if (ret != MM_ERROR_NONE)
		{
			if (err_attr_name)
				*err_attr_name = strdup(name);
			//mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
			return ret;
		}

		//next name
		name = va_arg (var_args, char*);
	}

	if (mmf_attrs_commit_err(attrs, err_attr_name) == -1) {
		//mmf_debug(MMF_DEBUG_ERROR, "result of mmf_attrs_commit_err is -1 (name:%s)", name);
		return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
	}
	else
		return MM_ERROR_NONE;

	return ret;
}


int mm_attrs_get_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
{
	const char *name = NULL;
	unsigned int ret = MM_ERROR_NONE;

	return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
//	return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
	return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);

	if (err_attr_name)
		*err_attr_name = NULL;
	name = attribute_name;

	while (name)
	{
		int idx = -1;
		MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;

		//name check
		if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
		{
			if (err_attr_name)
				*err_attr_name = strdup(name);

			if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY)	//to avoid confusing
				return MM_ERROR_COMMON_ATTR_NOT_EXIST;
			else
				return ret;
		}

		//type check
		if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
			return ret;

		//cast and set
		switch (attr_type)
		{
			case MM_ATTRS_TYPE_INT:
			{
				int * val = 	va_arg ((var_args), int*);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
				ret = mm_attrs_get_int(attrs, idx, val);
				break;
			}
			case MM_ATTRS_TYPE_DOUBLE:
			{
				double * val = 	va_arg ((var_args), double*);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
				ret = mm_attrs_get_double(attrs, idx, val);
				break;
			}
			case MM_ATTRS_TYPE_STRING:
			{
				char ** val = va_arg ((var_args), char**);
				int * size = va_arg ((var_args), int*);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
				ret = mm_attrs_get_string(attrs, idx, (char**)val, size);
				break;
			}
			case MM_ATTRS_TYPE_DATA:
			{
				void ** val = va_arg ((var_args), void**);
				int * size = va_arg ((var_args), int*);
//				mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
				ret = mm_attrs_get_data(attrs, idx, val, size);
				break;
			}
			case MM_ATTRS_TYPE_INVALID:
			default:
//				mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
				//if (err_attr_name)
				//	*err_attr_name = strdup(name);
				ret =  MM_ERROR_COMMON_INVALID_ARGUMENT;
		}

		if (ret != MM_ERROR_NONE)
		{
			if (err_attr_name)
				*err_attr_name = strdup(name);
			//mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
			return ret;
		}

		//next name
		name = va_arg (var_args, char*);
	}

	return ret;
}


int mm_attrs_multiple_set(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
{
	va_list var_args;
	int ret = MM_ERROR_NONE;

	return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);

	va_start (var_args, attribute_name);
	ret = mm_attrs_set_valist (handle, err_attr_name, attribute_name, var_args);
	va_end (var_args);

	return ret;
}


int mm_attrs_multiple_get(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
{
	va_list var_args;
	int ret = MM_ERROR_NONE;

	return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);

	va_start (var_args, attribute_name);
	ret = mm_attrs_get_valist (handle, err_attr_name, attribute_name, var_args);
	va_end (var_args);

	return ret;
}


int mm_attrs_get_info(MMHandleType h, int idx, MMAttrsInfo *info)
{
	mmf_attrs_t *attrs = (mmf_attrs_t *) h;

	return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
	return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
	return_val_if_fail( 0 <= idx && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);

	memset(info, 0x00, sizeof(MMAttrsInfo));

	info->type = attrs->items[idx].value.type;
	info->flag = attrs->items[idx].flags;
	info->validity_type = attrs->items[idx].value_spec.type;

	switch (info->validity_type)
	{
		case MM_ATTRS_VALID_TYPE_INT_ARRAY:
			info->int_array.array = attrs->items[idx].value_spec.spec.int_spec.array.array;
			info->int_array.count = attrs->items[idx].value_spec.spec.int_spec.array.count;
			info->int_array.dval = attrs->items[idx].value_spec.spec.int_spec.array.dval;
		break;
		case MM_ATTRS_VALID_TYPE_INT_RANGE:
			info->int_range.min = attrs->items[idx].value_spec.spec.int_spec.range.min;
			info->int_range.max = attrs->items[idx].value_spec.spec.int_spec.range.max;
			info->int_range.dval = attrs->items[idx].value_spec.spec.int_spec.range.dval;
		break;
		case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
			info->double_array.array = attrs->items[idx].value_spec.spec.double_spec.array.array;
			info->double_array.count = attrs->items[idx].value_spec.spec.double_spec.array.count;
			info->double_array.dval = attrs->items[idx].value_spec.spec.double_spec.array.dval;
		break;
		case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
			info->double_range.min = attrs->items[idx].value_spec.spec.double_spec.range.min;
			info->double_range.max = attrs->items[idx].value_spec.spec.double_spec.range.max;
			info->double_range.dval = attrs->items[idx].value_spec.spec.double_spec.range.dval;
		break;
		case MM_ATTRS_VALID_TYPE_NONE:
			//mmf_debug(MMF_DEBUG_LOG, "Valid type none.\n");
		break;
		case MM_ATTRS_VALID_TYPE_INVALID:
		default:
		break;
	}

	return MM_ERROR_NONE;
}


int mm_attrs_get_info_by_name(MMHandleType h, const char *attr_name, MMAttrsInfo *info)
{
	int idx = -1;
	int ret = MM_ERROR_NONE;

	return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
	return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);

	//mmf_debug(MMF_DEBUG_LOG, "(attr_name:%s)\n", attr_name);

	mm_attrs_get_index(h, attr_name, &idx);

	return_val_if_fail(idx >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);

	ret = mm_attrs_get_info(h, idx, info);

	return ret;
}