Move write_lock from attrs to each attribute
[platform/core/multimedia/libmm-common.git] / mm_attrs.c
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
23
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <malloc.h>
27 #include <string.h>
28 #include <assert.h>
29 #include "mm_debug.h"
30 #include "mm_attrs.h"
31 #include "mm_attrs_private.h"
32 #include "mm_error.h"
33
34 int mm_attrs_get_type(MMHandleType h, int idx, MMAttrsType *attrtype)
35 {
36         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
37         return_val_if_fail(h && idx >= 0 && idx < attrs->count && attrtype, MM_ERROR_COMMON_INVALID_ARGUMENT);
38         *attrtype=attrs->items[idx].value.type;
39         return MM_ERROR_NONE;
40 }
41
42
43 int mm_attrs_get_flags(MMHandleType h, int idx, int *flags)
44 {
45         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
46         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && flags, MM_ERROR_COMMON_INVALID_ARGUMENT);
47
48         *flags=attrs->items[idx].flags;
49         return MM_ERROR_NONE;
50 }
51
52
53 int mm_attrs_get_valid_type(MMHandleType h, int idx, int *type)
54 {
55         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
56         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && type, MM_ERROR_COMMON_INVALID_ARGUMENT);
57         *type=attrs->items[idx].value_spec.type;
58         return MM_ERROR_NONE;
59 }
60
61
62 int mm_attrs_get_valid_range(MMHandleType h, int idx, int *min, int *max)
63 {
64         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
65         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && min && max, MM_ERROR_COMMON_INVALID_ARGUMENT);
66
67         if (min) {
68                 *min = attrs->items[idx].value_spec.spec.int_spec.range.min;
69         }
70         if (max) {
71                 *max = attrs->items[idx].value_spec.spec.int_spec.range.max;
72         }
73         return MM_ERROR_NONE;
74 }
75
76
77 int mm_attrs_get_valid_array(MMHandleType h, int idx, int *count,  int **array)
78 {
79         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
80         if (count)
81                 *count = 0;
82         return_val_if_fail(attrs && count && idx >= 0 && idx < attrs->count && array, MM_ERROR_COMMON_INVALID_ARGUMENT);
83         if (count)
84                 *count = attrs->items[idx].value_spec.spec.int_spec.array.count;
85         *array=attrs->items[idx].value_spec.spec.int_spec.array.array;
86         return MM_ERROR_NONE;
87 }
88
89
90 int mm_attrs_get_size(MMHandleType h, int *size)
91 {
92         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
93         return_val_if_fail(h && size, MM_ERROR_COMMON_INVALID_ARGUMENT);
94         *size = attrs->count;
95         return MM_ERROR_NONE;
96 }
97
98
99 int mm_attrs_get_name(MMHandleType h, int idx, char **name)
100 {
101         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
102         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
103         *name = attrs->items[idx].name;
104         return MM_ERROR_NONE;
105 }
106
107
108 int mm_attrs_get_index(MMHandleType h, const char *attrname, int *index)
109 {
110         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
111         int i;
112
113         return_val_if_fail(h && attrname && index, MM_ERROR_COMMON_INVALID_ARGUMENT);
114
115         for (i = 0; i < attrs->count; i++) {
116                 if (0 == strcmp(attrs->items[i].name, attrname)) {
117                         *index = i;
118                         return MM_ERROR_NONE;
119                 }
120         }
121         return MM_ERROR_COMMON_OUT_OF_ARRAY;
122 }
123
124
125 int mm_attrs_set_int(MMHandleType h, int idx, int val)
126 {
127         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
128         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
129
130         mmf_attribute_t *item = &attrs->items[idx];
131         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
132
133         if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
134         {
135                 return MM_ERROR_COMMON_INVALID_PERMISSION;
136         }
137
138         if (mmf_attribute_validate_int(item, val))
139         {
140                 int ret = 0;
141                 ret = mmf_attribute_set_int(item, val);
142
143                 if (ret == 0)
144                         return MM_ERROR_NONE;
145                 else
146                         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
147         }
148
149         if (item->value_spec.type == MMF_VALUE_SPEC_INT_RANGE)
150                 return MM_ERROR_COMMON_OUT_OF_RANGE;
151         else if (item->value_spec.type == MMF_VALUE_SPEC_INT_ARRAY)
152                 return MM_ERROR_COMMON_OUT_OF_ARRAY;
153         else
154                 return MM_ERROR_COMMON_INVALID_ARGUMENT;
155 }
156
157
158 int mm_attrs_get_int(MMHandleType h, int idx,  int *val)
159 {
160         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
161         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
162         mmf_attribute_t *item = &attrs->items[idx];
163         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
164
165         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE))
166         {
167                 *val=mmf_value_get_int(&attrs->items[idx].value);
168                 return MM_ERROR_NONE;
169         }
170
171         return MM_ERROR_COMMON_INVALID_PERMISSION;
172 }
173
174
175 int mm_attrs_set_double(MMHandleType h, int idx, double val)
176 {
177         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
178         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
179
180         mmf_attribute_t *item = &attrs->items[idx];
181         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
182
183         if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
184         {
185                 return MM_ERROR_COMMON_INVALID_PERMISSION;
186         }
187
188         if (mmf_attribute_validate_double(item, val))
189         {
190                 int ret = 0;
191                 ret = mmf_attribute_set_double(item, val);
192
193                 if (ret == 0)
194                         return MM_ERROR_NONE;
195                 else
196                         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
197         }
198
199         if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_RANGE)
200                 return MM_ERROR_COMMON_OUT_OF_RANGE;
201         else if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_ARRAY)
202                 return MM_ERROR_COMMON_OUT_OF_ARRAY;
203         else
204                 return MM_ERROR_COMMON_INVALID_ARGUMENT;
205 }
206
207
208 int mm_attrs_get_double(MMHandleType h, int idx, double *val)
209 {
210         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
211         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
212         mmf_attribute_t *item = &attrs->items[idx];
213         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
214
215         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE))
216         {
217                 *val=mmf_value_get_double(&attrs->items[idx].value);
218                 return MM_ERROR_NONE;
219         }
220
221         return MM_ERROR_COMMON_INVALID_PERMISSION;
222 }
223
224
225 int mm_attrs_set_string(MMHandleType h, int idx, const char *string, int size)
226 {
227         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
228         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
229
230         mmf_attribute_t *item = &attrs->items[idx];
231
232         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
233
234         MM_ATTR_ITEM_WRITE_LOCK(item);
235
236         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
237         {
238                 int ret = 0;
239                 ret = mmf_attribute_set_string(item, string, size);
240
241                 MM_ATTR_ITEM_WRITE_UNLOCK(item);
242
243                 if (ret == 0)
244                         return MM_ERROR_NONE;
245                 else
246                         return MM_ERROR_COMMON_INVALID_ARGUMENT;
247         }
248
249         MM_ATTR_ITEM_WRITE_UNLOCK(item);
250
251         return MM_ERROR_COMMON_INVALID_PERMISSION;
252 }
253
254
255 int mm_attrs_get_string(MMHandleType h, int idx, char **sval, int *size)
256 {
257         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
258         mmf_attribute_t *item = NULL;
259         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT);
260
261         item = &attrs->items[idx];
262
263         MM_ATTR_ITEM_WRITE_LOCK(item);
264
265         if (!(item->flags & MM_ATTRS_FLAG_READABLE)) {
266                 //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
267                 MM_ATTR_ITEM_WRITE_UNLOCK(item);
268                 return MM_ERROR_COMMON_INVALID_PERMISSION;
269         }
270
271         *sval = mmf_value_get_string(&item->value, size);
272
273         MM_ATTR_ITEM_WRITE_UNLOCK(item);
274
275         return MM_ERROR_NONE;
276 }
277
278
279 int mm_attrs_set_data(MMHandleType h, int idx, void *data, int size)
280 {
281         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
282         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
283
284         mmf_attribute_t *item = &attrs->items[idx];
285         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
286
287         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
288         {
289                 int ret = 0;
290                 ret =  mmf_attribute_set_data(item, data, size);
291
292                 if (ret == 0)
293                         return MM_ERROR_NONE;
294                 else
295                         return MM_ERROR_COMMON_INVALID_ARGUMENT;
296         }
297
298         return MM_ERROR_COMMON_INVALID_ARGUMENT;
299 }
300
301
302 int mm_attrs_get_data(MMHandleType h, int idx,void **data,  int *size)
303 {
304         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
305         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && data, MM_ERROR_COMMON_INVALID_ARGUMENT);
306
307         if (!(attrs->items[idx].flags & MM_ATTRS_FLAG_READABLE)) {
308                 //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
309                 return MM_ERROR_COMMON_INVALID_PERMISSION;
310         }
311         *data=mmf_value_get_data(&attrs->items[idx].value,size);
312         return MM_ERROR_NONE;
313 }
314
315
316 int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int val)
317 {
318         return_val_if_fail(attrs && name, -1);
319         int idx = 0;
320         mm_attrs_get_index(attrs, name, &idx);
321         if (idx >= 0) {
322                 return mm_attrs_set_int(attrs, idx, val);
323         }
324         return -1;
325 }
326
327
328 int mm_attrs_get_int_by_name(MMHandleType attrs, const char *name, int *val)
329 {
330         int idx = -1;
331         return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
332         mm_attrs_get_index(attrs, name, &idx);
333         if (idx >= 0) {
334                 return mm_attrs_get_int(attrs, idx, val);
335         }
336         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
337 }
338
339
340 int mm_attrs_set_string_by_name(MMHandleType attrs, const char *name, const char *string)
341 {
342         return_val_if_fail(attrs && name, -1);
343
344         int size;
345         int idx = 0;
346         mm_attrs_get_index(attrs, name, &idx);
347         if (idx >= 0) {
348                 if (string) {
349                         size = strlen(string);
350                 }
351                 else {
352                         string = NULL;
353                         size = 0;
354                 }
355
356                 return mm_attrs_set_string(attrs, idx, string, size);
357         }
358         return -1;
359 }
360
361
362 int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **string)
363 {
364         int idx = -1;
365         int len = 0;
366         return_val_if_fail(attrs && name && string, MM_ERROR_COMMON_INVALID_ARGUMENT);
367
368         mm_attrs_get_index(attrs, name, &idx);
369         if (idx >= 0) {
370                 return mm_attrs_get_string(attrs, idx, string, &len);
371         }
372         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
373 }
374
375
376 int mm_attrs_set_data_by_name(MMHandleType attrs, const char *name, void *data, int size)
377 {
378         return_val_if_fail(attrs && name, -1);
379         int idx = 0;
380         mm_attrs_get_index(attrs, name, &idx);
381
382         if (idx >= 0) {
383                 return mm_attrs_set_data(attrs, idx, data, size);
384         }
385         return -1;
386 }
387
388
389 int mm_attrs_get_data_by_name(MMHandleType attrs, const char *name, void **data)
390 {
391         int idx = -1;
392         int len = 0;
393
394         return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
395
396         mm_attrs_get_index(attrs, name, &idx);
397         if (idx >= 0) {
398                 return mm_attrs_get_data(attrs, idx, data, &len);
399         }
400         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
401 }
402
403
404 int mm_attrs_set_double_by_name(MMHandleType attrs, const char *name, double val)
405 {
406         int idx = -1;
407         return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
408
409         mm_attrs_get_index(attrs, name, &idx);
410         if (idx >= 0) {
411                 return mm_attrs_set_double(attrs, idx, val);
412         }
413         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
414 }
415
416
417 int mm_attrs_get_double_by_name(MMHandleType attrs, const char *name, double *val)
418 {
419         int idx = -1;
420         return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
421
422         mm_attrs_get_index(attrs, name, &idx);
423         if (idx >= 0) {
424                 *val = mm_attrs_get_double(attrs, idx, val);
425                 return 0;
426         }
427         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
428 }
429
430
431 int mm_attrs_set_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
432 {
433         const char *name = NULL;
434         unsigned int ret = MM_ERROR_NONE;
435
436         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
437 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
438         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
439
440         if (err_attr_name)
441                 *err_attr_name = NULL;
442         name = attribute_name;
443
444         while (name)
445         {
446                 int idx = -1;
447                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
448
449                 //name check
450                 if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
451                 {
452                         if (err_attr_name)
453                                 *err_attr_name = strdup(name);
454
455                         if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY) {      //to avoid confusing
456                                 //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);
457                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
458                         } else {
459                                 //mmf_debug(MMF_DEBUG_ERROR, "result of mm_attrs_get_index is %x so return(name:%s)",ret, name);
460                                 return ret;
461                         }
462                 }
463
464                 //type check
465                 if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
466                         return ret;
467
468                 //cast and set
469                 switch (attr_type)
470                 {
471                         case MM_ATTRS_TYPE_INT:
472                         {
473                                 int val =       va_arg ((var_args), int);
474 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %d)\n", name, val);
475                                 ret = mm_attrs_set_int(attrs, idx, val);
476                                 break;
477                         }
478                         case MM_ATTRS_TYPE_DOUBLE:
479                         {
480                                 double val = va_arg ((var_args), double);
481 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %f)\n", name, val);
482                                 ret = mm_attrs_set_double(attrs, idx, val);
483                                 break;
484                         }
485                         case MM_ATTRS_TYPE_STRING:
486                         {
487                                 char * val = va_arg ((var_args), char*);
488                                 int size = va_arg ((var_args), int);
489 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: \'%s\', size: %d)\n", name, val, size);
490                                 ret = mm_attrs_set_string(attrs, idx, (const char*)val, size);
491                                 break;
492                         }
493                         case MM_ATTRS_TYPE_DATA:
494                         {
495                                 void * val = va_arg ((var_args), void*);
496                                 int size = va_arg ((var_args), int);
497 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %d)\n", name, val, size);
498                                 ret = mm_attrs_set_data(attrs, idx, val, size);
499                                 break;
500                         }
501                         case MM_ATTRS_TYPE_INVALID:
502                         default:
503                                 //mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
504                                 return MM_ERROR_COMMON_INVALID_ARGUMENT;
505                                 break;
506                 }
507
508                 if (ret != MM_ERROR_NONE)
509                 {
510                         if (err_attr_name)
511                                 *err_attr_name = strdup(name);
512                         //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
513                         return ret;
514                 }
515
516                 //next name
517                 name = va_arg (var_args, char*);
518         }
519
520         if (mmf_attrs_commit_err(attrs, err_attr_name) == -1) {
521                 //mmf_debug(MMF_DEBUG_ERROR, "result of mmf_attrs_commit_err is -1 (name:%s)", name);
522                 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
523         }
524         else
525                 return MM_ERROR_NONE;
526
527         return ret;
528 }
529
530
531 int mm_attrs_get_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
532 {
533         const char *name = NULL;
534         unsigned int ret = MM_ERROR_NONE;
535
536         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
537 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
538         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
539
540         if (err_attr_name)
541                 *err_attr_name = NULL;
542         name = attribute_name;
543
544         while (name)
545         {
546                 int idx = -1;
547                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
548
549                 //name check
550                 if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
551                 {
552                         if (err_attr_name)
553                                 *err_attr_name = strdup(name);
554
555                         if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY)        //to avoid confusing
556                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
557                         else
558                                 return ret;
559                 }
560
561                 //type check
562                 if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
563                         return ret;
564
565                 //cast and set
566                 switch (attr_type)
567                 {
568                         case MM_ATTRS_TYPE_INT:
569                         {
570                                 int * val =     va_arg ((var_args), int*);
571 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
572                                 ret = mm_attrs_get_int(attrs, idx, val);
573                                 break;
574                         }
575                         case MM_ATTRS_TYPE_DOUBLE:
576                         {
577                                 double * val =  va_arg ((var_args), double*);
578 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
579                                 ret = mm_attrs_get_double(attrs, idx, val);
580                                 break;
581                         }
582                         case MM_ATTRS_TYPE_STRING:
583                         {
584                                 char ** val = va_arg ((var_args), char**);
585                                 int * size = va_arg ((var_args), int*);
586 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
587                                 ret = mm_attrs_get_string(attrs, idx, (char**)val, size);
588                                 break;
589                         }
590                         case MM_ATTRS_TYPE_DATA:
591                         {
592                                 void ** val = va_arg ((var_args), void**);
593                                 int * size = va_arg ((var_args), int*);
594 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
595                                 ret = mm_attrs_get_data(attrs, idx, val, size);
596                                 break;
597                         }
598                         case MM_ATTRS_TYPE_INVALID:
599                         default:
600 //                              mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
601                                 //if (err_attr_name)
602                                 //      *err_attr_name = strdup(name);
603                                 ret =  MM_ERROR_COMMON_INVALID_ARGUMENT;
604                 }
605
606                 if (ret != MM_ERROR_NONE)
607                 {
608                         if (err_attr_name)
609                                 *err_attr_name = strdup(name);
610                         //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
611                         return ret;
612                 }
613
614                 //next name
615                 name = va_arg (var_args, char*);
616         }
617
618         return ret;
619 }
620
621
622 int mm_attrs_multiple_set(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
623 {
624         va_list var_args;
625         int ret = MM_ERROR_NONE;
626
627         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
628
629         va_start (var_args, attribute_name);
630         ret = mm_attrs_set_valist (handle, err_attr_name, attribute_name, var_args);
631         va_end (var_args);
632
633         return ret;
634 }
635
636
637 int mm_attrs_multiple_get(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
638 {
639         va_list var_args;
640         int ret = MM_ERROR_NONE;
641
642         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
643
644         va_start (var_args, attribute_name);
645         ret = mm_attrs_get_valist (handle, err_attr_name, attribute_name, var_args);
646         va_end (var_args);
647
648         return ret;
649 }
650
651
652 int mm_attrs_get_info(MMHandleType h, int idx, MMAttrsInfo *info)
653 {
654         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
655
656         return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
657         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
658         return_val_if_fail( 0 <= idx && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
659
660         memset(info, 0x00, sizeof(MMAttrsInfo));
661
662         info->type = attrs->items[idx].value.type;
663         info->flag = attrs->items[idx].flags;
664         info->validity_type = attrs->items[idx].value_spec.type;
665
666         switch (info->validity_type)
667         {
668                 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
669                         info->int_array.array = attrs->items[idx].value_spec.spec.int_spec.array.array;
670                         info->int_array.count = attrs->items[idx].value_spec.spec.int_spec.array.count;
671                         info->int_array.dval = attrs->items[idx].value_spec.spec.int_spec.array.dval;
672                 break;
673                 case MM_ATTRS_VALID_TYPE_INT_RANGE:
674                         info->int_range.min = attrs->items[idx].value_spec.spec.int_spec.range.min;
675                         info->int_range.max = attrs->items[idx].value_spec.spec.int_spec.range.max;
676                         info->int_range.dval = attrs->items[idx].value_spec.spec.int_spec.range.dval;
677                 break;
678                 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
679                         info->double_array.array = attrs->items[idx].value_spec.spec.double_spec.array.array;
680                         info->double_array.count = attrs->items[idx].value_spec.spec.double_spec.array.count;
681                         info->double_array.dval = attrs->items[idx].value_spec.spec.double_spec.array.dval;
682                 break;
683                 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
684                         info->double_range.min = attrs->items[idx].value_spec.spec.double_spec.range.min;
685                         info->double_range.max = attrs->items[idx].value_spec.spec.double_spec.range.max;
686                         info->double_range.dval = attrs->items[idx].value_spec.spec.double_spec.range.dval;
687                 break;
688                 case MM_ATTRS_VALID_TYPE_NONE:
689                         //mmf_debug(MMF_DEBUG_LOG, "Valid type none.\n");
690                 break;
691                 case MM_ATTRS_VALID_TYPE_INVALID:
692                 default:
693                 break;
694         }
695
696         return MM_ERROR_NONE;
697 }
698
699
700 int mm_attrs_get_info_by_name(MMHandleType h, const char *attr_name, MMAttrsInfo *info)
701 {
702         int idx = -1;
703         int ret = MM_ERROR_NONE;
704
705         return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
706         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
707
708         //mmf_debug(MMF_DEBUG_LOG, "(attr_name:%s)\n", attr_name);
709
710         mm_attrs_get_index(h, attr_name, &idx);
711
712         return_val_if_fail(idx >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
713
714         ret = mm_attrs_get_info(h, idx, info);
715
716         return ret;
717 }