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