Check for AM_PROG_AR
[framework/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_ATTRS_WRITE_LOCK(attrs);
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_ATTRS_WRITE_UNLOCK(attrs);
242
243                 if (ret == 0)
244                         return MM_ERROR_NONE;
245                 else
246                         return MM_ERROR_COMMON_INVALID_ARGUMENT;
247         }
248
249         MM_ATTRS_WRITE_UNLOCK(attrs);
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         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT);
259
260         MM_ATTRS_WRITE_LOCK(attrs);
261
262         if (!(attrs->items[idx].flags & MM_ATTRS_FLAG_READABLE)) {
263                 mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
264                 MM_ATTRS_WRITE_UNLOCK(attrs);
265                 return MM_ERROR_COMMON_INVALID_PERMISSION;
266         }
267
268         *sval = mmf_value_get_string(&attrs->items[idx].value,size);
269
270         MM_ATTRS_WRITE_UNLOCK(attrs);
271
272         return MM_ERROR_NONE;
273 }
274
275
276 int mm_attrs_set_data(MMHandleType h, int idx, void *data, int size)
277 {
278         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
279         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
280
281         mmf_attribute_t *item = &attrs->items[idx];
282         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
283
284         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
285         {
286                 int ret = 0;
287                 ret =  mmf_attribute_set_data(item, data, size);
288
289                 if (ret == 0)
290                         return MM_ERROR_NONE;
291                 else
292                         return MM_ERROR_COMMON_INVALID_ARGUMENT;
293         }
294
295         return MM_ERROR_COMMON_INVALID_ARGUMENT;
296 }
297
298
299 int mm_attrs_get_data(MMHandleType h, int idx,void **data,  int *size)
300 {
301         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
302         return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && data, MM_ERROR_COMMON_INVALID_ARGUMENT);
303
304         if (!(attrs->items[idx].flags & MM_ATTRS_FLAG_READABLE)) {
305                 mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
306                 return MM_ERROR_COMMON_INVALID_PERMISSION;
307         }
308         *data=mmf_value_get_data(&attrs->items[idx].value,size);
309         return MM_ERROR_NONE;
310 }
311
312
313 int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int val)
314 {
315         return_val_if_fail(attrs && name, -1);
316         int idx = 0;
317         mm_attrs_get_index(attrs, name, &idx);
318         if (idx >= 0) {
319                 return mm_attrs_set_int(attrs, idx, val);
320         }
321         return -1;
322 }
323
324
325 int mm_attrs_get_int_by_name(MMHandleType attrs, const char *name, int *val)
326 {
327         int idx = -1;
328         return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
329         mm_attrs_get_index(attrs, name, &idx);
330         if (idx >= 0) {
331                 return mm_attrs_get_int(attrs, idx, val);
332         }
333         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
334 }
335
336
337 int mm_attrs_set_string_by_name(MMHandleType attrs, const char *name, const char *string)
338 {
339         return_val_if_fail(attrs && name, -1);
340
341         int size;
342         int idx = 0;
343         mm_attrs_get_index(attrs, name, &idx);
344         if (idx >= 0) {
345                 if (string) {
346                         size = strlen(string);
347                 }
348                 else {
349                         string = NULL;
350                         size = 0;
351                 }
352                 
353                 return mm_attrs_set_string(attrs, idx, string, size);
354         }
355         return -1;
356 }
357
358
359 int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **string)
360 {
361         int idx = -1;
362         int len = 0;
363         return_val_if_fail(attrs && name && string, MM_ERROR_COMMON_INVALID_ARGUMENT);
364
365         mm_attrs_get_index(attrs, name, &idx);
366         if (idx >= 0) {
367                 return mm_attrs_get_string(attrs, idx, string, &len);
368         }
369         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
370 }
371
372
373 int mm_attrs_set_data_by_name(MMHandleType attrs, const char *name, void *data, int size)
374 {
375         return_val_if_fail(attrs && name, -1);
376         int idx = 0;
377         mm_attrs_get_index(attrs, name, &idx);
378
379         if (idx >= 0) {
380                 return mm_attrs_set_data(attrs, idx, data, size);
381         }
382         return -1;
383 }
384
385
386 int mm_attrs_get_data_by_name(MMHandleType attrs, const char *name, void **data)
387 {
388         int idx = -1;
389         int len = 0;
390
391         return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
392
393         mm_attrs_get_index(attrs, name, &idx);
394         if (idx >= 0) {
395                 return mm_attrs_get_data(attrs, idx, data, &len);
396         }
397         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
398 }
399
400
401 int mm_attrs_set_double_by_name(MMHandleType attrs, const char *name, double val)
402 {
403         int idx = -1;
404         return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
405
406         mm_attrs_get_index(attrs, name, &idx);
407         if (idx >= 0) {
408                 return mm_attrs_set_double(attrs, idx, val);
409         }
410         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
411 }
412
413
414 int mm_attrs_get_double_by_name(MMHandleType attrs, const char *name, double *val)
415 {
416         int idx = -1;
417         return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
418
419         mm_attrs_get_index(attrs, name, &idx);
420         if (idx >= 0) {
421                 *val = mm_attrs_get_double(attrs, idx, val);
422                 return 0;
423         }
424         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
425 }
426
427
428 int mm_attrs_set_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
429 {
430         const char *name = NULL;
431         int ret = MM_ERROR_NONE;
432
433         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
434 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
435         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
436
437         if (err_attr_name)
438                 *err_attr_name = NULL;
439         name = attribute_name;
440
441         while (name)
442         {
443                 int idx = -1;
444                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
445
446                 //name check
447                 if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
448                 {
449                         if (err_attr_name)
450                                 *err_attr_name = strdup(name);
451
452                         if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY)        //to avoid confusing
453                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
454                         else
455                                 return ret;
456                 }
457
458                 //type check
459                 if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
460                         return ret;
461
462                 //cast and set
463                 switch (attr_type)
464                 {
465                         case MM_ATTRS_TYPE_INT:
466                         {
467                                 int val =       va_arg ((var_args), int);
468                                 mmf_debug(MMF_DEBUG_LOG, "(%s: %d)\n", name, val);
469                                 ret = mm_attrs_set_int(attrs, idx, val);
470                                 break;
471                         }
472                         case MM_ATTRS_TYPE_DOUBLE:
473                         {
474                                 double val = va_arg ((var_args), double);
475                                 mmf_debug(MMF_DEBUG_LOG, "(%s: %f)\n", name, val);
476                                 ret = mm_attrs_set_double(attrs, idx, val);
477                                 break;
478                         }
479                         case MM_ATTRS_TYPE_STRING:
480                         {
481                                 char * val = va_arg ((var_args), char*);
482                                 int size = va_arg ((var_args), int);
483                                 mmf_debug(MMF_DEBUG_LOG, "(%s: \'%s\', size: %d)\n", name, val, size);
484                                 ret = mm_attrs_set_string(attrs, idx, (const char*)val, size);
485                                 break;
486                         }
487                         case MM_ATTRS_TYPE_DATA:
488                         {
489                                 void * val = va_arg ((var_args), void*);
490                                 int size = va_arg ((var_args), int);
491                                 mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %d)\n", name, val, size);
492                                 ret = mm_attrs_set_data(attrs, idx, val, size);
493                                 break;
494                         }
495                         case MM_ATTRS_TYPE_INVALID:
496                         default:
497                                 mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
498                                 if (err_attr_name)
499                                         *err_attr_name = strdup(name);
500                                 ret =  MM_ERROR_COMMON_INVALID_ARGUMENT;
501                 }
502
503                 if (ret != MM_ERROR_NONE)
504                 {
505                         if (err_attr_name)
506                                 *err_attr_name = strdup(name);
507                         mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
508                         return ret;
509                 }
510
511                 //next name
512                 name = va_arg (var_args, char*);
513         }
514
515         if (mmf_attrs_commit_err(attrs, err_attr_name) == -1)
516                 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
517         else
518                 return MM_ERROR_NONE;
519
520         return ret;
521 }
522
523
524 int mm_attrs_get_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
525 {
526         const char *name = NULL;
527         int ret = MM_ERROR_NONE;
528
529         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
530 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
531         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
532
533         if (err_attr_name)
534                 *err_attr_name = NULL;
535         name = attribute_name;
536
537         while (name)
538         {
539                 int idx = -1;
540                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
541
542                 //name check
543                 if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
544                 {
545                         if (err_attr_name)
546                                 *err_attr_name = strdup(name);
547
548                         if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY)        //to avoid confusing
549                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
550                         else
551                                 return ret;
552                 }
553
554                 //type check
555                 if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
556                         return ret;
557
558                 //cast and set
559                 switch (attr_type)
560                 {
561                         case MM_ATTRS_TYPE_INT:
562                         {
563                                 int * val =     va_arg ((var_args), int*);
564 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
565                                 ret = mm_attrs_get_int(attrs, idx, val);
566                                 break;
567                         }
568                         case MM_ATTRS_TYPE_DOUBLE:
569                         {
570                                 double * val =  va_arg ((var_args), double*);
571 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
572                                 ret = mm_attrs_get_double(attrs, idx, val);
573                                 break;
574                         }
575                         case MM_ATTRS_TYPE_STRING:
576                         {
577                                 char ** val = va_arg ((var_args), char**);
578                                 int * size = va_arg ((var_args), int*);
579 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
580                                 ret = mm_attrs_get_string(attrs, idx, (char**)val, size);
581                                 break;
582                         }
583                         case MM_ATTRS_TYPE_DATA:
584                         {
585                                 void ** val = va_arg ((var_args), void**);
586                                 int * size = va_arg ((var_args), int*);
587 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
588                                 ret = mm_attrs_get_data(attrs, idx, val, size);
589                                 break;
590                         }
591                         case MM_ATTRS_TYPE_INVALID:
592                         default:
593 //                              mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
594                                 if (err_attr_name)
595                                         *err_attr_name = strdup(name);
596                                 ret =  MM_ERROR_COMMON_INVALID_ARGUMENT;
597                 }
598
599                 if (ret != MM_ERROR_NONE)
600                 {
601                         if (err_attr_name)
602                                 *err_attr_name = strdup(name);
603                         mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
604                         return ret;
605                 }
606
607                 //next name
608                 name = va_arg (var_args, char*);
609         }
610
611         return ret;
612 }
613
614
615 int mm_attrs_multiple_set(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
616 {
617         va_list var_args;
618         int ret = MM_ERROR_NONE;
619
620         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
621
622         va_start (var_args, attribute_name);
623         ret = mm_attrs_set_valist (handle, err_attr_name, attribute_name, var_args);
624         va_end (var_args);
625
626         return ret;
627 }
628
629
630 int mm_attrs_multiple_get(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
631 {
632         va_list var_args;
633         int ret = MM_ERROR_NONE;
634
635         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
636
637         va_start (var_args, attribute_name);
638         ret = mm_attrs_get_valist (handle, err_attr_name, attribute_name, var_args);
639         va_end (var_args);
640
641         return ret;
642 }
643
644
645 int mm_attrs_get_info(MMHandleType h, int idx, MMAttrsInfo *info)
646 {
647         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
648
649         return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
650         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
651         return_val_if_fail( 0 <= idx && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
652
653         memset(info, 0x00, sizeof(MMAttrsInfo));
654
655         info->type = attrs->items[idx].value.type;
656         info->flag = attrs->items[idx].flags;
657         info->validity_type = attrs->items[idx].value_spec.type;
658
659         switch (info->validity_type)
660         {
661                 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
662                         info->int_array.array = attrs->items[idx].value_spec.spec.int_spec.array.array;
663                         info->int_array.count = attrs->items[idx].value_spec.spec.int_spec.array.count;
664                         info->int_array.dval = attrs->items[idx].value_spec.spec.int_spec.array.dval;
665                 break;
666                 case MM_ATTRS_VALID_TYPE_INT_RANGE:
667                         info->int_range.min = attrs->items[idx].value_spec.spec.int_spec.range.min;
668                         info->int_range.max = attrs->items[idx].value_spec.spec.int_spec.range.max;
669                         info->int_range.dval = attrs->items[idx].value_spec.spec.int_spec.range.dval;
670                 break;
671                 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
672                         info->double_array.array = attrs->items[idx].value_spec.spec.double_spec.array.array;
673                         info->double_array.count = attrs->items[idx].value_spec.spec.double_spec.array.count;
674                         info->double_array.dval = attrs->items[idx].value_spec.spec.double_spec.array.dval;
675                 break;
676                 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
677                         info->double_range.min = attrs->items[idx].value_spec.spec.double_spec.range.min;
678                         info->double_range.max = attrs->items[idx].value_spec.spec.double_spec.range.max;
679                         info->double_range.dval = attrs->items[idx].value_spec.spec.double_spec.range.dval;
680                 break;
681                 case MM_ATTRS_VALID_TYPE_NONE:
682                         mmf_debug(MMF_DEBUG_LOG, "Valid type none.\n");
683                 break;
684                 case MM_ATTRS_VALID_TYPE_INVALID:
685                 default:
686                 break;
687         }
688
689         return MM_ERROR_NONE;
690 }
691
692
693 int mm_attrs_get_info_by_name(MMHandleType h, const char *attr_name, MMAttrsInfo *info)
694 {
695         int idx = -1;
696         int ret = MM_ERROR_NONE;
697
698         return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
699         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
700
701         mmf_debug(MMF_DEBUG_LOG, "(attr_name:%s)\n", attr_name);
702
703         mm_attrs_get_index(h, attr_name, &idx);
704
705         return_val_if_fail(idx >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
706
707         ret = mm_attrs_get_info(h, idx, info);
708
709         return ret;
710 }