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