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