Tizen 2.1 base
[platform/core/appfw/ail.git] / src / ail_convert.c
1 /*
2  * ail
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@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 <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
27 #include "ail.h"
28 #include "ail_private.h"
29 #include "ail_convert.h"
30
31
32 struct _ail_str_map_t {
33         ail_prop_str_e prop;
34         const char *property;
35 };
36
37 static struct _ail_str_map_t str_prop_map[] = {
38         {E_AIL_PROP_PACKAGE_STR,                AIL_PROP_PACKAGE_STR},
39         {E_AIL_PROP_EXEC_STR,                   AIL_PROP_EXEC_STR},
40         {E_AIL_PROP_NAME_STR,                   AIL_PROP_NAME_STR},
41         {E_AIL_PROP_TYPE_STR,                   AIL_PROP_TYPE_STR},
42         {E_AIL_PROP_ICON_STR,                   AIL_PROP_ICON_STR},
43         {E_AIL_PROP_CATEGORIES_STR,             AIL_PROP_CATEGORIES_STR},
44         {E_AIL_PROP_VERSION_STR,                AIL_PROP_VERSION_STR},
45         {E_AIL_PROP_MIMETYPE_STR,               AIL_PROP_MIMETYPE_STR},
46         {E_AIL_PROP_X_SLP_SERVICE_STR,          AIL_PROP_X_SLP_SERVICE_STR},
47         {E_AIL_PROP_X_SLP_PACKAGETYPE_STR,      AIL_PROP_X_SLP_PACKAGETYPE_STR},
48         {E_AIL_PROP_X_SLP_PACKAGECATEGORIES_STR, AIL_PROP_X_SLP_PACKAGECATEGORIES_STR},
49         {E_AIL_PROP_X_SLP_PACKAGEID_STR,        AIL_PROP_X_SLP_PACKAGEID_STR},
50 /*      {E_AIL_PROP_X_SLP_URI_STR,              AIL_PROP_X_SLP_URI_STR}, */
51         {E_AIL_PROP_X_SLP_SVC_STR,              AIL_PROP_X_SLP_SVC_STR},
52         {E_AIL_PROP_X_SLP_EXE_PATH,             AIL_PROP_X_SLP_EXE_PATH},
53         {E_AIL_PROP_X_SLP_APPID_STR,            AIL_PROP_X_SLP_APPID_STR},
54         {E_AIL_PROP_X_SLP_PKGID_STR,            AIL_PROP_X_SLP_PKGID_STR},
55         {E_AIL_PROP_X_SLP_DOMAIN_STR,           AIL_PROP_X_SLP_DOMAIN_STR}
56 };
57
58
59 struct _ail_int_map_t {
60         ail_prop_int_e prop;
61         const char *property;
62 };
63
64 static struct _ail_int_map_t int_prop_map[] = {
65         {E_AIL_PROP_X_SLP_TEMP_INT, AIL_PROP_X_SLP_TEMP_INT},
66         {E_AIL_PROP_X_SLP_INSTALLEDTIME_INT, AIL_PROP_X_SLP_INSTALLEDTIME_INT}
67 };
68
69
70 struct _ail_bool_map_t {
71         ail_prop_bool_e prop;
72         const char *property;
73 };
74
75 static struct _ail_bool_map_t bool_prop_map[] = {
76         {E_AIL_PROP_NODISPLAY_BOOL, AIL_PROP_NODISPLAY_BOOL},
77         {E_AIL_PROP_X_SLP_TASKMANAGE_BOOL, AIL_PROP_X_SLP_TASKMANAGE_BOOL},
78         {E_AIL_PROP_X_SLP_MULTIPLE_BOOL, AIL_PROP_X_SLP_MULTIPLE_BOOL},
79         {E_AIL_PROP_X_SLP_REMOVABLE_BOOL, AIL_PROP_X_SLP_REMOVABLE_BOOL},
80 /*      {E_AIL_PROP_X_SLP_ISHORIZONTALSCALE_BOOL, AIL_PROP_X_SLP_ISHORIZONTALSCALE_BOOL}, */
81         {E_AIL_PROP_X_SLP_INACTIVATED_BOOL, AIL_PROP_X_SLP_INACTIVATED_BOOL}
82 };
83
84
85 inline ail_prop_str_e _ail_convert_to_prop_str(const char *property)
86 {
87         int i = 0;
88         ail_prop_str_e prop = -1;
89
90         retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
91
92         for (i=0 ; i<(E_AIL_PROP_STR_MAX - E_AIL_PROP_STR_MIN + 1) ; i++) {
93                 if (strcmp(property, str_prop_map[i].property) == 0) {
94                         prop =  str_prop_map[i].prop;
95                         break;
96                 }
97         }
98
99         return prop;
100 }
101
102 inline ail_prop_int_e _ail_convert_to_prop_int(const char *property)
103 {
104         int i = 0;
105         ail_prop_int_e prop = -1;
106
107         retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
108
109         for (i=0 ; i<(E_AIL_PROP_INT_MAX - E_AIL_PROP_INT_MIN + 1) ; i++) {
110                 if (strcmp(property, int_prop_map[i].property) == 0) {
111                         prop =  int_prop_map[i].prop;
112                         break;
113                 }
114         }
115
116         return prop;
117 }
118
119 inline ail_prop_bool_e _ail_convert_to_prop_bool(const char *property)
120 {
121         int i = 0;
122         ail_prop_bool_e prop = -1;
123
124         retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
125
126         for (i=0 ; i<(E_AIL_PROP_BOOL_MAX - E_AIL_PROP_BOOL_MIN + 1) ; i++) {
127                 if (strcmp(property, bool_prop_map[i].property) == 0) {
128                         prop =  bool_prop_map[i].prop;
129                         break;
130                 }
131         }
132
133         return prop;
134 }
135