[0.2.116] mm_attrs: Export API set located in mm_attrs_private.h
[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 #include <stdio.h>
23 #include <stdbool.h>
24 #include <malloc.h>
25 #include <string.h>
26 #include <assert.h>
27 #include "mm_debug.h"
28 #include "mm_attrs.h"
29 #include "mm_attrs_private.h"
30 #include "mm_error.h"
31
32 int mm_attrs_new(MMAttrsConstructInfo *info, int count, const char *name,
33                                                                 mm_attrs_commit_callback callback, void *user_param, MMHandleType *attrs)
34 {
35         MMHandleType _attrs;
36
37         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
38
39         _attrs = mmf_attrs_new_from_data(name, (mmf_attrs_construct_info_t *) info, count, (mmf_attrs_commit_func_t) callback, user_param);
40         if (!_attrs)
41                 return MM_ERROR_COMMON_INTERNAL;
42
43         *attrs = _attrs;
44
45         return MM_ERROR_NONE;
46 }
47
48
49 void mm_attrs_free(MMHandleType attrs)
50 {
51         mmf_attrs_free(attrs);
52 }
53
54
55 int mm_attrs_commit_all(MMHandleType attrs)
56 {
57         return mmf_attrs_commit(attrs);
58 }
59
60 int mm_attrs_commit(MMHandleType attrs, int index)
61 {
62         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
63         mmf_attribute_t *item;
64
65         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
66         return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
67
68         item = &h->items[index];
69
70         MM_ATTR_ITEM_WRITE_LOCK(item);
71
72         mmf_attribute_commit(item);
73
74         MM_ATTR_ITEM_WRITE_UNLOCK(item);
75
76         return MM_ERROR_NONE;
77 }
78
79 int mm_attrs_get_type(MMHandleType attrs, int index, MMAttrsType *attrtype)
80 {
81         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
82
83         return_val_if_fail(h && index >= 0 && index < h->count && attrtype, MM_ERROR_COMMON_INVALID_ARGUMENT);
84
85         *attrtype = h->items[index].value.type;
86         return MM_ERROR_NONE;
87 }
88
89
90 int mm_attrs_get_flags(MMHandleType attrs, int index, int *flags)
91 {
92         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
93
94         return_val_if_fail(h && index >= 0 && index < h->count && flags, MM_ERROR_COMMON_INVALID_ARGUMENT);
95
96         *flags = h->items[index].flags;
97         return MM_ERROR_NONE;
98 }
99
100
101 int mm_attrs_get_valid_type(MMHandleType attrs, int index, MMAttrsValidType *type)
102 {
103         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
104
105         return_val_if_fail(h && index >= 0 && index < h->count && type, MM_ERROR_COMMON_INVALID_ARGUMENT);
106
107         *type = h->items[index].value_spec.type;
108         return MM_ERROR_NONE;
109 }
110
111
112 int mm_attrs_get_valid_range(MMHandleType attrs, int index, int *min, int *max)
113 {
114         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
115
116         return_val_if_fail(h && index >= 0 && index < h->count && min && max, MM_ERROR_COMMON_INVALID_ARGUMENT);
117
118         if (min) {
119                 *min = h->items[index].value_spec.spec.int_spec.range.min;
120         }
121         if (max) {
122                 *max = h->items[index].value_spec.spec.int_spec.range.max;
123         }
124         return MM_ERROR_NONE;
125 }
126
127
128 int mm_attrs_get_valid_array(MMHandleType attrs, int index, int *count,  int **array)
129 {
130         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
131
132         if (count)
133                 *count = 0;
134
135         return_val_if_fail(h && count && index >= 0 && index < h->count && array, MM_ERROR_COMMON_INVALID_ARGUMENT);
136
137         if (count)
138                 *count = h->items[index].value_spec.spec.int_spec.array.count;
139         *array = h->items[index].value_spec.spec.int_spec.array.array;
140         return MM_ERROR_NONE;
141 }
142
143
144 int mm_attrs_get_size(MMHandleType attrs, int *size)
145 {
146         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
147
148         return_val_if_fail(h && size, MM_ERROR_COMMON_INVALID_ARGUMENT);
149
150         *size = h->count;
151         return MM_ERROR_NONE;
152 }
153
154
155 int mm_attrs_get_name(MMHandleType attrs, int index, char **name)
156 {
157         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
158
159         return_val_if_fail(h && index >= 0 && index < h->count && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
160
161         *name = h->items[index].name;
162         return MM_ERROR_NONE;
163 }
164
165
166 int mm_attrs_get_index(MMHandleType attrs, const char *attrname, int *index)
167 {
168         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
169         int i;
170
171         return_val_if_fail(h && attrname && index, MM_ERROR_COMMON_INVALID_ARGUMENT);
172
173         for (i = 0; i < h->count; i++) {
174                 if (0 == strcmp(h->items[i].name, attrname)) {
175                         *index = i;
176                         return MM_ERROR_NONE;
177                 }
178         }
179
180         debug_error("failed to get index for [%s]", attrname);
181
182         return MM_ERROR_COMMON_OUT_OF_ARRAY;
183 }
184
185
186 int mm_attrs_set_int(MMHandleType attrs, int index, int val)
187 {
188         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
189         mmf_attribute_t *item;
190
191         return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
192
193         item = &h->items[index];
194         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
195
196         if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) {
197                 return MM_ERROR_COMMON_INVALID_PERMISSION;
198         }
199
200         if (mmf_attribute_validate_int(item, val)) {
201                 int ret = 0;
202                 ret = mmf_attribute_set_int(item, val);
203
204                 if (ret == 0)
205                         return MM_ERROR_NONE;
206                 else
207                         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
208         }
209
210         if (item->value_spec.type == MMF_VALUE_SPEC_INT_RANGE)
211                 return MM_ERROR_COMMON_OUT_OF_RANGE;
212         else if (item->value_spec.type == MMF_VALUE_SPEC_INT_ARRAY)
213                 return MM_ERROR_COMMON_OUT_OF_ARRAY;
214         else
215                 return MM_ERROR_COMMON_INVALID_ARGUMENT;
216 }
217
218
219 int mm_attrs_get_int(MMHandleType attrs, int index,  int *val)
220 {
221         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
222         mmf_attribute_t *item;
223
224         return_val_if_fail(h && index >= 0 && index < h->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
225
226         item = &h->items[index];
227         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
228
229         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) {
230                 *val = mmf_value_get_int(&h->items[index].value);
231                 return MM_ERROR_NONE;
232         }
233
234         return MM_ERROR_COMMON_INVALID_PERMISSION;
235 }
236
237
238 int mm_attrs_set_double(MMHandleType attrs, int index, double val)
239 {
240         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
241         mmf_attribute_t *item;
242
243         return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
244
245         item = &h->items[index];
246         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
247
248         if (!mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
249                 return MM_ERROR_COMMON_INVALID_PERMISSION;
250
251         if (mmf_attribute_validate_double(item, val)) {
252                 int ret = 0;
253                 ret = mmf_attribute_set_double(item, val);
254
255                 if (ret == 0)
256                         return MM_ERROR_NONE;
257                 else
258                         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
259         }
260
261         if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_RANGE)
262                 return MM_ERROR_COMMON_OUT_OF_RANGE;
263         else if (item->value_spec.type == MMF_VALUE_SPEC_DOUBLE_ARRAY)
264                 return MM_ERROR_COMMON_OUT_OF_ARRAY;
265         else
266                 return MM_ERROR_COMMON_INVALID_ARGUMENT;
267 }
268
269
270 int mm_attrs_get_double(MMHandleType attrs, int index, double *val)
271 {
272         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
273         mmf_attribute_t *item;
274
275         return_val_if_fail(h && index >= 0 && index < h->count && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
276
277         item = &h->items[index];
278         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
279
280         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_READABLE)) {
281                 *val = mmf_value_get_double(&h->items[index].value);
282                 return MM_ERROR_NONE;
283         }
284
285         return MM_ERROR_COMMON_INVALID_PERMISSION;
286 }
287
288
289 int mm_attrs_set_string(MMHandleType attrs, int index, const char *string, int size)
290 {
291         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
292         mmf_attribute_t *item;
293
294         return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
295
296         item = &h->items[index];
297         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
298
299         MM_ATTR_ITEM_WRITE_LOCK(item);
300
301         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) {
302                 int ret = 0;
303                 ret = mmf_attribute_set_string(item, string, size);
304
305                 MM_ATTR_ITEM_WRITE_UNLOCK(item);
306
307                 if (ret == 0)
308                         return MM_ERROR_NONE;
309                 else
310                         return MM_ERROR_COMMON_INVALID_ARGUMENT;
311         }
312
313         MM_ATTR_ITEM_WRITE_UNLOCK(item);
314
315         return MM_ERROR_COMMON_INVALID_PERMISSION;
316 }
317
318
319 int mm_attrs_get_string(MMHandleType attrs, int index, char **sval, int *size)
320 {
321         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
322         mmf_attribute_t *item;
323
324         return_val_if_fail(h && index >= 0 && index < h->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT);
325
326         item = &h->items[index];
327
328         MM_ATTR_ITEM_WRITE_LOCK(item);
329
330         if (!(item->flags & MM_ATTRS_FLAG_READABLE)) {
331                 //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
332                 MM_ATTR_ITEM_WRITE_UNLOCK(item);
333                 return MM_ERROR_COMMON_INVALID_PERMISSION;
334         }
335
336         *sval = mmf_value_get_string(&item->value, size);
337
338         MM_ATTR_ITEM_WRITE_UNLOCK(item);
339
340         return MM_ERROR_NONE;
341 }
342
343
344 int mm_attrs_set_data(MMHandleType attrs, int index, void *data, int size)
345 {
346         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
347         mmf_attribute_t *item;
348
349         return_val_if_fail(h && index >= 0 && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
350
351         item = &h->items[index];
352         return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
353
354         if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE)) {
355                 int ret = 0;
356                 ret =  mmf_attribute_set_data(item, data, size);
357
358                 if (ret == 0)
359                         return MM_ERROR_NONE;
360                 else
361                         return MM_ERROR_COMMON_INVALID_ARGUMENT;
362         }
363
364         return MM_ERROR_COMMON_INVALID_ARGUMENT;
365 }
366
367
368 int mm_attrs_get_data(MMHandleType attrs, int index, void **data, int *size)
369 {
370         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
371
372         return_val_if_fail(h && index >= 0 && index < h->count && data, MM_ERROR_COMMON_INVALID_ARGUMENT);
373
374         if (!(h->items[index].flags & MM_ATTRS_FLAG_READABLE)) {
375                 //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
376                 return MM_ERROR_COMMON_INVALID_PERMISSION;
377         }
378         *data = mmf_value_get_data(&h->items[index].value, size);
379         return MM_ERROR_NONE;
380 }
381
382
383 int mm_attrs_set_int_by_name(MMHandleType attrs, const char *name, int val)
384 {
385         int index = 0;
386
387         return_val_if_fail(attrs && name, -1);
388
389         mm_attrs_get_index(attrs, name, &index);
390         if (index >= 0) {
391                 return mm_attrs_set_int(attrs, index, val);
392         }
393         return -1;
394 }
395
396
397 int mm_attrs_get_int_by_name(MMHandleType attrs, const char *name, int *val)
398 {
399         int index = -1;
400
401         return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
402
403         mm_attrs_get_index(attrs, name, &index);
404         if (index >= 0) {
405                 return mm_attrs_get_int(attrs, index, val);
406         }
407         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
408 }
409
410
411 int mm_attrs_set_string_by_name(MMHandleType attrs, const char *name, const char *string)
412 {
413         int size;
414         int index = 0;
415
416         return_val_if_fail(attrs && name, -1);
417
418         mm_attrs_get_index(attrs, name, &index);
419         if (index >= 0) {
420                 if (string) {
421                         size = strlen(string);
422                 } else {
423                         string = NULL;
424                         size = 0;
425                 }
426
427                 return mm_attrs_set_string(attrs, index, string, size);
428         }
429         return -1;
430 }
431
432
433 int mm_attrs_get_string_by_name(MMHandleType attrs, const char *name, char **string)
434 {
435         int index = -1;
436         int len = 0;
437
438         return_val_if_fail(attrs && name && string, MM_ERROR_COMMON_INVALID_ARGUMENT);
439
440         mm_attrs_get_index(attrs, name, &index);
441         if (index >= 0) {
442                 return mm_attrs_get_string(attrs, index, string, &len);
443         }
444         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
445 }
446
447
448 int mm_attrs_set_data_by_name(MMHandleType attrs, const char *name, void *data, int size)
449 {
450         int index = 0;
451
452         return_val_if_fail(attrs && name, -1);
453
454         mm_attrs_get_index(attrs, name, &index);
455         if (index >= 0) {
456                 return mm_attrs_set_data(attrs, index, data, size);
457         }
458         return -1;
459 }
460
461
462 int mm_attrs_get_data_by_name(MMHandleType attrs, const char *name, void **data)
463 {
464         int index = -1;
465         int len = 0;
466
467         return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
468
469         mm_attrs_get_index(attrs, name, &index);
470         if (index >= 0) {
471                 return mm_attrs_get_data(attrs, index, data, &len);
472         }
473         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
474 }
475
476
477 int mm_attrs_set_double_by_name(MMHandleType attrs, const char *name, double val)
478 {
479         int index = -1;
480
481         return_val_if_fail(attrs && name, MM_ERROR_COMMON_INVALID_ARGUMENT);
482
483         mm_attrs_get_index(attrs, name, &index);
484         if (index >= 0) {
485                 return mm_attrs_set_double(attrs, index, val);
486         }
487         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
488 }
489
490
491 int mm_attrs_get_double_by_name(MMHandleType attrs, const char *name, double *val)
492 {
493         int index = -1;
494
495         return_val_if_fail(attrs && name && val, MM_ERROR_COMMON_INVALID_ARGUMENT);
496
497         mm_attrs_get_index(attrs, name, &index);
498         if (index >= 0) {
499                 *val = mm_attrs_get_double(attrs, index, val);
500                 return 0;
501         }
502         return MM_ERROR_COMMON_INVALID_ATTRTYPE;
503 }
504
505
506 int mm_attrs_set_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
507 {
508         const char *name = NULL;
509         int ret = MM_ERROR_NONE;
510
511         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
512 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
513         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
514
515         if (err_attr_name)
516                 *err_attr_name = NULL;
517         name = attribute_name;
518
519         while (name) {
520                 int index = -1;
521                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
522
523                 //name check
524                 if ((ret = mm_attrs_get_index(attrs, name, &index)) != MM_ERROR_NONE) {
525
526                         if (err_attr_name)
527                                 *err_attr_name = strdup(name);
528
529                         if (ret == (int)MM_ERROR_COMMON_OUT_OF_ARRAY) { //to avoid confusing
530                                 //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);
531                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
532                         } else {
533                                 //mmf_debug(MMF_DEBUG_ERROR, "result of mm_attrs_get_index is %x so return(name:%s)",ret, name);
534                                 return ret;
535                         }
536                 }
537
538                 //type check
539                 if ((ret = mm_attrs_get_type(attrs, index, &attr_type)) != MM_ERROR_NONE)
540                         return ret;
541
542                 //cast and set
543                 switch (attr_type) {
544                 case MM_ATTRS_TYPE_INT:
545                 {
546                         int val = va_arg((var_args), int);
547 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %d)\n", name, val);
548                         ret = mm_attrs_set_int(attrs, index, val);
549                         break;
550                 }
551                 case MM_ATTRS_TYPE_DOUBLE:
552                 {
553                         double val = va_arg((var_args), double);
554 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %f)\n", name, val);
555                         ret = mm_attrs_set_double(attrs, index, val);
556                         break;
557                 }
558                 case MM_ATTRS_TYPE_STRING:
559                 {
560                         char * val = va_arg((var_args), char*);
561                         int size = va_arg((var_args), int);
562 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: \'%s\', size: %d)\n", name, val, size);
563                         ret = mm_attrs_set_string(attrs, index, (const char*)val, size);
564                         break;
565                 }
566                 case MM_ATTRS_TYPE_DATA:
567                 {
568                         void * val = va_arg((var_args), void*);
569                         int size = va_arg((var_args), int);
570 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %d)\n", name, val, size);
571                         ret = mm_attrs_set_data(attrs, index, val, size);
572                         break;
573                 }
574                 case MM_ATTRS_TYPE_INVALID:
575                 default:
576                         //mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
577                         return MM_ERROR_COMMON_INVALID_ARGUMENT;
578                         break;
579                 }
580
581                 if (ret != MM_ERROR_NONE) {
582                         if (err_attr_name)
583                                 *err_attr_name = strdup(name);
584                         //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
585                         return ret;
586                 }
587
588                 //next name
589                 name = va_arg(var_args, char*);
590         }
591
592         if (mmf_attrs_commit_err(attrs, err_attr_name) == -1) {
593                 //mmf_debug(MMF_DEBUG_ERROR, "result of mmf_attrs_commit_err is -1 (name:%s)", name);
594                 return MM_ERROR_COMMON_UNKNOWN;
595         } else {
596                 return MM_ERROR_NONE;
597         }
598
599         return ret;
600 }
601
602
603 int mm_attrs_get_valist(MMHandleType attrs, char **err_attr_name, const char *attribute_name, va_list var_args)
604 {
605         const char *name = NULL;
606         int ret = MM_ERROR_NONE;
607
608         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
609 //      return_val_if_fail(err_attr_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
610         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
611
612         if (err_attr_name)
613                 *err_attr_name = NULL;
614         name = attribute_name;
615
616         while (name) {
617                 int index = -1;
618                 MMAttrsType attr_type = MM_ATTRS_TYPE_INVALID;
619
620                 //name check
621                 if ((ret = mm_attrs_get_index(attrs, name, &index)) != MM_ERROR_NONE) {
622                         if (err_attr_name)
623                                 *err_attr_name = strdup(name);
624
625                         if (ret == (int)MM_ERROR_COMMON_OUT_OF_ARRAY)   //to avoid confusing
626                                 return MM_ERROR_COMMON_ATTR_NOT_EXIST;
627                         else
628                                 return ret;
629                 }
630
631                 //type check
632                 if ((ret = mm_attrs_get_type(attrs, index, &attr_type)) != MM_ERROR_NONE)
633                         return ret;
634
635                 //cast and set
636                 switch (attr_type) {
637                 case MM_ATTRS_TYPE_INT:
638                 {
639                         int * val = va_arg((var_args), int*);
640 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
641                         ret = mm_attrs_get_int(attrs, index, val);
642                         break;
643                 }
644                 case MM_ATTRS_TYPE_DOUBLE:
645                 {
646                         double * val = va_arg((var_args), double*);
647 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p)\n", name, val);
648                         ret = mm_attrs_get_double(attrs, index, val);
649                         break;
650                 }
651                 case MM_ATTRS_TYPE_STRING:
652                 {
653                         char ** val = va_arg((var_args), char**);
654                         int * size = va_arg((var_args), int*);
655 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
656                         ret = mm_attrs_get_string(attrs, index, (char**)val, size);
657                         break;
658                 }
659                 case MM_ATTRS_TYPE_DATA:
660                 {
661                         void ** val = va_arg((var_args), void**);
662                         int * size = va_arg((var_args), int*);
663 //                              mmf_debug(MMF_DEBUG_LOG, "(%s: %p, size: %p)\n", name, val, size);
664                         ret = mm_attrs_get_data(attrs, index, val, size);
665                         break;
666                 }
667                 case MM_ATTRS_TYPE_INVALID:
668                 default:
669 //                              mmf_debug(MMF_DEBUG_ERROR, "This function doesn't support attribute type(%d, name:%s)\n", attr_type, name);
670                         //if (err_attr_name)
671                         //      *err_attr_name = strdup(name);
672                         ret =  MM_ERROR_COMMON_INVALID_ARGUMENT;
673                         break;
674                 }
675
676                 if (ret != MM_ERROR_NONE) {
677                         if (err_attr_name)
678                                 *err_attr_name = strdup(name);
679                         //mmf_debug(MMF_DEBUG_ERROR, "Setting failure.(name:%s)\n", name);
680                         return ret;
681                 }
682
683                 //next name
684                 name = va_arg(var_args, char*);
685         }
686
687         return ret;
688 }
689
690
691 int mm_attrs_multiple_set(MMHandleType attrs,  char **err_attr_name, const char *attribute_name, ...)
692 {
693         va_list var_args;
694         int ret = MM_ERROR_NONE;
695
696         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
697
698         va_start(var_args, attribute_name);
699         ret = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, var_args);
700         va_end(var_args);
701
702         return ret;
703 }
704
705
706 int mm_attrs_multiple_get(MMHandleType attrs,  char **err_attr_name, const char *attribute_name, ...)
707 {
708         va_list var_args;
709         int ret = MM_ERROR_NONE;
710
711         return_val_if_fail(attribute_name, MM_ERROR_COMMON_INVALID_ARGUMENT);
712
713         va_start(var_args, attribute_name);
714         ret = mm_attrs_get_valist(attrs, err_attr_name, attribute_name, var_args);
715         va_end(var_args);
716
717         return ret;
718 }
719
720
721 int mm_attrs_get_info(MMHandleType attrs, int index, MMAttrsInfo *info)
722 {
723         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
724
725         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
726         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
727         return_val_if_fail(0 <= index && index < h->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
728
729         memset(info, 0x00, sizeof(MMAttrsInfo));
730
731         info->type = h->items[index].value.type;
732         info->flag = h->items[index].flags;
733         info->validity_type = h->items[index].value_spec.type;
734
735         switch (info->validity_type) {
736         case MM_ATTRS_VALID_TYPE_INT_ARRAY:
737                 info->int_array.array = h->items[index].value_spec.spec.int_spec.array.array;
738                 info->int_array.count = h->items[index].value_spec.spec.int_spec.array.count;
739                 info->int_array.dval = h->items[index].value_spec.spec.int_spec.array.dval;
740                 break;
741         case MM_ATTRS_VALID_TYPE_INT_RANGE:
742                 info->int_range.min = h->items[index].value_spec.spec.int_spec.range.min;
743                 info->int_range.max = h->items[index].value_spec.spec.int_spec.range.max;
744                 info->int_range.dval = h->items[index].value_spec.spec.int_spec.range.dval;
745                 break;
746         case MM_ATTRS_VALID_TYPE_DOUBLE_ARRAY:
747                 info->double_array.array = h->items[index].value_spec.spec.double_spec.array.array;
748                 info->double_array.count = h->items[index].value_spec.spec.double_spec.array.count;
749                 info->double_array.dval = h->items[index].value_spec.spec.double_spec.array.dval;
750                 break;
751         case MM_ATTRS_VALID_TYPE_DOUBLE_RANGE:
752                 info->double_range.min = h->items[index].value_spec.spec.double_spec.range.min;
753                 info->double_range.max = h->items[index].value_spec.spec.double_spec.range.max;
754                 info->double_range.dval = h->items[index].value_spec.spec.double_spec.range.dval;
755                 break;
756         case MM_ATTRS_VALID_TYPE_NONE:
757                 //mmf_debug(MMF_DEBUG_LOG, "Valid type none.\n");
758                 break;
759         case MM_ATTRS_VALID_TYPE_INVALID:
760         default:
761                 break;
762         }
763
764         return MM_ERROR_NONE;
765 }
766
767
768 int mm_attrs_get_info_by_name(MMHandleType attrs, const char *attr_name, MMAttrsInfo *info)
769 {
770         int index = -1;
771         int ret = MM_ERROR_NONE;
772
773         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
774         return_val_if_fail(info, MM_ERROR_COMMON_INVALID_ARGUMENT);
775
776         //mmf_debug(MMF_DEBUG_LOG, "(attr_name:%s)\n", attr_name);
777
778         mm_attrs_get_index(attrs, attr_name, &index);
779
780         return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
781
782         ret = mm_attrs_get_info(attrs, index, info);
783
784         return ret;
785 }
786
787
788 int mm_attrs_set_valid_type(MMHandleType attrs, int index, MMAttrsValidType type)
789 {
790         return_val_if_fail(type > MM_ATTRS_VALID_TYPE_INVALID, MM_ERROR_COMMON_INVALID_ARGUMENT);
791         return_val_if_fail(type <= MM_ATTRS_VALID_TYPE_DOUBLE_RANGE, MM_ERROR_COMMON_INVALID_ARGUMENT);
792
793         return mmf_attrs_set_valid_type(attrs, index, (int)type);
794 }
795
796
797 int mm_attrs_set_valid_range(MMHandleType attrs, int index, int min, int max, int dval)
798 {
799         return mmf_attrs_set_valid_range(attrs, index, min, max, dval);
800 }
801
802
803 int mm_attrs_set_valid_array(MMHandleType attrs, int index, const int *array, int count, int dval)
804 {
805         return mmf_attrs_set_valid_array(attrs, index, array, count, dval);
806 }
807
808
809 int mm_attrs_set_valid_double_range(MMHandleType attrs, int index, double min, double max, double dval)
810 {
811         return mmf_attrs_set_valid_double_range(attrs, index, min, max, dval);
812 }
813
814
815 int mm_attrs_set_valid_double_array(MMHandleType attrs, int index, const double *array, int count, double dval)
816 {
817         return mmf_attrs_set_valid_double_array(attrs, index, array, count, dval);
818 }
819
820
821 int mm_attrs_is_modified(MMHandleType attrs, int index, bool *modified)
822 {
823         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
824         mmf_attribute_t *item;
825
826         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
827         return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
828
829         item = &h->items[index];
830
831         MM_ATTR_ITEM_WRITE_LOCK(item);
832
833         *modified = mmf_attribute_is_modified(item);
834
835         MM_ATTR_ITEM_WRITE_UNLOCK(item);
836
837         return MM_ERROR_NONE;
838 }
839
840
841 int mm_attrs_set_modified(MMHandleType attrs, int index)
842 {
843         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
844         mmf_attribute_t *item;
845
846         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
847         return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
848
849         item = &h->items[index];
850
851         MM_ATTR_ITEM_WRITE_LOCK(item);
852
853         mmf_attribute_set_modified(item);
854
855         MM_ATTR_ITEM_WRITE_UNLOCK(item);
856
857         return MM_ERROR_NONE;
858 }
859
860
861 int mm_attrs_set_readonly(MMHandleType attrs, int index)
862 {
863         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
864         mmf_attribute_t *item;
865
866         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
867         return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
868
869         item = &h->items[index];
870
871         MM_ATTR_ITEM_WRITE_LOCK(item);
872
873         mmf_attribute_set_readonly(item);
874
875         MM_ATTR_ITEM_WRITE_UNLOCK(item);
876
877         return MM_ERROR_NONE;
878 }
879
880
881 int mm_attrs_set_disabled(MMHandleType attrs, int index)
882 {
883         mmf_attrs_t *h = (mmf_attrs_t *) attrs;
884         mmf_attribute_t *item;
885
886         return_val_if_fail(attrs, MM_ERROR_COMMON_INVALID_ARGUMENT);
887         return_val_if_fail(index >= 0, MM_ERROR_COMMON_INVALID_ARGUMENT);
888
889         item = &h->items[index];
890
891         MM_ATTR_ITEM_WRITE_LOCK(item);
892
893         mmf_attribute_set_disabled(item);
894
895         MM_ATTR_ITEM_WRITE_UNLOCK(item);
896
897         return MM_ERROR_NONE;
898 }