packaging: depend on the same release
[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_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                 return mm_attrs_get_double(attrs, idx, val);
422         }
423         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
424 }
425
426
427 int mm_attrs_set_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
428 {
429         const char *name = NULL;
430         int ret = MM_ERROR_NONE;
431
432         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
433 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
434         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
435
436         if (err_attr_name)
437                 *err_attr_name = NULL;
438         name = attribute_name;
439
440         while (name)
441         {
442                 int idx = -1;
443                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
444
445                 //name check
446                 if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
447                 {
448                         if (err_attr_name)
449                                 *err_attr_name = strdup(name);
450
451                         if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY)        //to avoid confusing
452                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
453                         else
454                                 return ret;
455                 }
456
457                 //type check
458                 if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
459                         return ret;
460
461                 //cast and set
462                 switch (attr_type)
463                 {
464                         case MM_ATTRS_TYPE_INT:
465                         {
466                                 int val =       va_arg ((var_args), int);
467                                 mmf_debug(MMF_DEBUG_LOG, "(%s: %d)\n", name, val);
468                                 ret = mm_attrs_set_int(attrs, idx, val);
469                                 break;
470                         }
471                         case MM_ATTRS_TYPE_DOUBLE:
472                         {
473                                 double val = va_arg ((var_args), double);
474                                 mmf_debug(MMF_DEBUG_LOG, "(%s: %f)\n", name, val);
475                                 ret = mm_attrs_set_double(attrs, idx, val);
476                                 break;
477                         }
478                         case MM_ATTRS_TYPE_STRING:
479                         {
480                                 char * val = va_arg ((var_args), char*);
481                                 int size = va_arg ((var_args), int);
482                                 mmf_debug(MMF_DEBUG_LOG, "(%s: \'%s\', size: %d)\n", name, val, size);
483                                 ret = mm_attrs_set_string(attrs, idx, (const char*)val, size);
484                                 break;
485                         }
486                         case MM_ATTRS_TYPE_DATA:
487                         {
488                                 void * val = va_arg ((var_args), void*);
489                                 int size = va_arg ((var_args), int);
490                                 mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %d)\n", name, val, size);
491                                 ret = mm_attrs_set_data(attrs, idx, val, size);
492                                 break;
493                         }
494                         case MM_ATTRS_TYPE_INVALID:
495                         default:
496                                 mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
497                                 if (err_attr_name)
498                                         *err_attr_name = strdup(name);
499                                 ret =  MM_ERROR_COMMON_INVALID_ARGUMENT;
500                 }
501
502                 if (ret != MM_ERROR_NONE)
503                 {
504                         if (err_attr_name)
505                                 *err_attr_name = strdup(name);
506                         mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
507                         return ret;
508                 }
509
510                 //next name
511                 name = va_arg (var_args, char*);
512         }
513
514         if (mmf_attrs_commit_err(attrs, err_attr_name) == -1)
515                 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
516         else
517                 return MM_ERROR_NONE;
518
519         return ret;
520 }
521
522
523 int mm_attrs_get_valist (MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
524 {
525         const char *name = NULL;
526         int ret = MM_ERROR_NONE;
527
528         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
529 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
530         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
531
532         if (err_attr_name)
533                 *err_attr_name = NULL;
534         name = attribute_name;
535
536         while (name)
537         {
538                 int idx = -1;
539                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
540
541                 //name check
542                 if ((ret = mm_attrs_get_index(attrs, name, &idx)) != MM_ERROR_NONE)
543                 {
544                         if (err_attr_name)
545                                 *err_attr_name = strdup(name);
546
547                         if (ret == MM_ERROR_COMMON_OUT_OF_ARRAY)        //to avoid confusing
548                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
549                         else
550                                 return ret;
551                 }
552
553                 //type check
554                 if ((ret = mm_attrs_get_type(attrs, idx, &attr_type)) != MM_ERROR_NONE)
555                         return ret;
556
557                 //cast and set
558                 switch (attr_type)
559                 {
560                         case MM_ATTRS_TYPE_INT:
561                         {
562                                 int * val =     va_arg ((var_args), int*);
563 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
564                                 ret = mm_attrs_get_int(attrs, idx, val);
565                                 break;
566                         }
567                         case MM_ATTRS_TYPE_DOUBLE:
568                         {
569                                 double * val =  va_arg ((var_args), double*);
570 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
571                                 ret = mm_attrs_get_double(attrs, idx, val);
572                                 break;
573                         }
574                         case MM_ATTRS_TYPE_STRING:
575                         {
576                                 char ** val = va_arg ((var_args), char**);
577                                 int * size = va_arg ((var_args), int*);
578 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
579                                 ret = mm_attrs_get_string(attrs, idx, (char**)val, size);
580                                 break;
581                         }
582                         case MM_ATTRS_TYPE_DATA:
583                         {
584                                 void ** val = va_arg ((var_args), void**);
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_data(attrs, idx, val, size);
588                                 break;
589                         }
590                         case MM_ATTRS_TYPE_INVALID:
591                         default:
592 //                              mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
593                                 if (err_attr_name)
594                                         *err_attr_name = strdup(name);
595                                 ret =  MM_ERROR_COMMON_INVALID_ARGUMENT;
596                 }
597
598                 if (ret != MM_ERROR_NONE)
599                 {
600                         if (err_attr_name)
601                                 *err_attr_name = strdup(name);
602                         mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
603                         return ret;
604                 }
605
606                 //next name
607                 name = va_arg (var_args, char*);
608         }
609
610         return ret;
611 }
612
613
614 int mm_attrs_multiple_set(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
615 {
616         va_list var_args;
617         int ret = MM_ERROR_NONE;
618
619         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
620
621         va_start (var_args, attribute_name);
622         ret = mm_attrs_set_valist (handle, err_attr_name, attribute_name, var_args);
623         va_end (var_args);
624
625         return ret;
626 }
627
628
629 int mm_attrs_multiple_get(MMHandleType handle,  char **err_attr_name, const char *attribute_name, ...)
630 {
631         va_list var_args;
632         int ret = MM_ERROR_NONE;
633
634         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
635
636         va_start (var_args, attribute_name);
637         ret = mm_attrs_get_valist (handle, err_attr_name, attribute_name, var_args);
638         va_end (var_args);
639
640         return ret;
641 }
642
643
644 int mm_attrs_get_info(MMHandleType h, int idx, MMAttrsInfo *info)
645 {
646         mmf_attrs_t *attrs = (mmf_attrs_t *) h;
647
648         return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
649         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
650         return_val_if_fail( 0 <= idx && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
651
652         memset(info, 0x00, sizeof(MMAttrsInfo));
653
654         info->type = attrs->items[idx].value.type;
655         info->flag = attrs->items[idx].flags;
656         info->validity_type = attrs->items[idx].value_spec.type;
657
658         switch (info->validity_type)
659         {
660                 case MM_ATTRS_VALID_TYPE_INT_ARRAY:
661                         info->int_array.array = attrs->items[idx].value_spec.spec.int_spec.array.array;
662                         info->int_array.count = attrs->items[idx].value_spec.spec.int_spec.array.count;
663                         info->int_array.dval = attrs->items[idx].value_spec.spec.int_spec.array.dval;
664                 break;
665                 case MM_ATTRS_VALID_TYPE_INT_RANGE:
666                         info->int_range.min = attrs->items[idx].value_spec.spec.int_spec.range.min;
667                         info->int_range.max = attrs->items[idx].value_spec.spec.int_spec.range.max;
668                         info->int_range.dval = attrs->items[idx].value_spec.spec.int_spec.range.dval;
669                 break;
670                 case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
671                         info->double_array.array = attrs->items[idx].value_spec.spec.double_spec.array.array;
672                         info->double_array.count = attrs->items[idx].value_spec.spec.double_spec.array.count;
673                         info->double_array.dval = attrs->items[idx].value_spec.spec.double_spec.array.dval;
674                 break;
675                 case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
676                         info->double_range.min = attrs->items[idx].value_spec.spec.double_spec.range.min;
677                         info->double_range.max = attrs->items[idx].value_spec.spec.double_spec.range.max;
678                         info->double_range.dval = attrs->items[idx].value_spec.spec.double_spec.range.dval;
679                 break;
680                 case MM_ATTRS_VALID_TYPE_NONE:
681                         mmf_debug(MMF_DEBUG_LOG, "Valid type none.\n");
682                 break;
683                 case MM_ATTRS_VALID_TYPE_INVALID:
684                 default:
685                 break;
686         }
687
688         return MM_ERROR_NONE;
689 }
690
691
692 int mm_attrs_get_info_by_name(MMHandleType h, const char *attr_name, MMAttrsInfo *info)
693 {
694         int idx = -1;
695         int ret = MM_ERROR_NONE;
696
697         return_val_if_fail(h, MM_ERROR_COMMON_INVALID_ARGUMENT);
698         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
699
700         mmf_debug(MMF_DEBUG_LOG, "(attr_name:%s)\n", attr_name);
701
702         mm_attrs_get_index(h, attr_name, &idx);
703
704         return_val_if_fail(idx >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
705
706         ret = mm_attrs_get_info(h, idx, info);
707
708         return ret;
709 }