upload tizen1.0 source
[profile/ivi/system-info.git] / src / system_info.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. 
15  */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include <vconf.h>
23 #include <dlog.h>
24
25 #include <system_info.h>
26 #include <system_info_private.h>
27
28 #ifdef LOG_TAG
29 #undef LOG_TAG
30 #endif
31
32 #define LOG_TAG "TIZEN_N_SYSTEM_INFO"
33
34 #define SYSTEM_INFO_MAX -1
35
36 typedef struct {
37         system_info_key_e key;
38         system_info_data_type_e data_type;
39         system_info_get_value_cb get_value_cb;
40 } system_info_s;
41
42 typedef system_info_s *system_info_h;
43
44 system_info_s system_info_table[] = {
45
46 {
47          /**< The model of the device */
48         SYSTEM_INFO_KEY_MODEL,
49         SYSTEM_INFO_DATA_TYPE_STRING,
50         system_info_get_model
51 },
52
53 {
54          /**< The version of the Tizen supported by the platform */
55         SYSTEM_INFO_KEY_TIZEN_VERSION,
56         SYSTEM_INFO_DATA_TYPE_STRING,
57         system_info_get_tizen_version
58 },
59
60 {
61         /**< Indicates whether the device supports Bluetooth */
62         SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED,
63         SYSTEM_INFO_DATA_TYPE_BOOL,
64         system_info_get_bluetooth_supported
65 },
66
67 {
68         /**< The number of cameras in the device */
69         SYSTEM_INFO_KEY_CAMERA_COUNT,
70         SYSTEM_INFO_DATA_TYPE_INT,
71         system_info_get_camera_count
72 },
73
74 {
75         /**< Indicates whether the device supports FM radio */
76         SYSTEM_INFO_KEY_FMRADIO_SUPPORTED,
77         SYSTEM_INFO_DATA_TYPE_BOOL,
78         system_info_get_fmradio_supported
79 },
80
81 {
82         /**< Indicates whether the device supports GPS */
83         SYSTEM_INFO_KEY_GPS_SUPPORTED,
84         SYSTEM_INFO_DATA_TYPE_BOOL,
85         system_info_get_gps_supported
86 },
87
88 {
89         /**< The type of the keyboard */
90         SYSTEM_INFO_KEY_KEYBOARD_TYPE,
91         SYSTEM_INFO_DATA_TYPE_STRING,
92         system_info_get_keyboard_type
93 },
94
95 {
96         /**< The maximum number of concurrent touch points supported in the device */
97         SYSTEM_INFO_KEY_MULTI_POINT_TOUCH_COUNT,
98         SYSTEM_INFO_DATA_TYPE_INT,
99         system_info_get_multi_point_touch_count
100 },
101
102 {
103         /**< The supported network type */
104         SYSTEM_INFO_KEY_NETWORK_TYPE,
105         SYSTEM_INFO_DATA_TYPE_STRING,
106         system_info_get_network_type
107 },
108
109 {
110         /**< Indicates whether the device supports NFC */
111         SYSTEM_INFO_KEY_NFC_SUPPORTED,
112         SYSTEM_INFO_DATA_TYPE_BOOL,
113         system_info_get_nfc_supported
114 },
115
116 {
117         /**< The supported version of the OpenGL ES */
118         SYSTEM_INFO_KEY_OPENGLES_VERSION,
119         SYSTEM_INFO_DATA_TYPE_STRING,
120         system_info_get_opengles_version
121 },
122
123 {
124         /**< The number of bits per pixel */
125         SYSTEM_INFO_KEY_SCREEN_BITS_PER_PIXEL,
126         SYSTEM_INFO_DATA_TYPE_INT,
127         system_info_get_screen_bits_per_pixel
128 },
129
130 {
131         /**< The height of the screen in pixels */
132         SYSTEM_INFO_KEY_SCREEN_HEIGHT,
133         SYSTEM_INFO_DATA_TYPE_INT,
134         system_info_get_screen_height
135 },
136
137 {
138         /**< The width of the screen in pixels */
139         SYSTEM_INFO_KEY_SCREEN_WIDTH,
140         SYSTEM_INFO_DATA_TYPE_INT,
141         system_info_get_screen_width
142 },
143
144 {
145         /**< Indicates whether the device supports TV-out */
146         SYSTEM_INFO_KEY_TVOUT_SUPPORTED,
147         SYSTEM_INFO_DATA_TYPE_BOOL,
148         system_info_get_tvout_supported
149 },
150
151 {
152          /**< Indicates whether the device supports Wi-Fi */
153         SYSTEM_INFO_KEY_WIFI_SUPPORTED,
154         SYSTEM_INFO_DATA_TYPE_BOOL,
155         system_info_get_wifi_supported
156 },
157
158 {
159          /**< The unique ID to identify GSM, and UMTS mobile devices */
160         SYSTEM_INFO_KEY_MOBILE_DEVICE_ID,
161         SYSTEM_INFO_DATA_TYPE_STRING,
162         system_info_get_mobile_device_id
163 },
164
165 {
166         SYSTEM_INFO_MAX, -1, NULL
167 }
168
169 };
170
171 static int system_info_get(system_info_key_e key, system_info_h *system_info)
172 {
173         int index = 0;
174
175         while (system_info_table[index].key != SYSTEM_INFO_MAX)
176         {
177                 if (system_info_table[index].key == key)
178                 {
179                         *system_info = &system_info_table[index];
180                         return 0;
181                 }
182
183                 index++;
184         }
185
186         return -1;
187 }
188
189 int system_info_get_value(system_info_key_e key, system_info_data_type_e data_type, void **value)
190 {
191         system_info_h system_info;
192         system_info_get_value_cb system_info_getter;
193
194         if (value == NULL)
195         {
196                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, SYSTEM_INFO_ERROR_INVALID_PARAMETER);
197                 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
198         }
199
200         if (system_info_get(key, &system_info))
201         {
202                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_INFO_ERROR_INVALID_PARAMETER);
203                 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
204         }
205
206         if (system_info->data_type != data_type)
207         {
208                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid data type", __FUNCTION__, SYSTEM_INFO_ERROR_INVALID_PARAMETER);
209                 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
210         }
211
212         system_info_getter = system_info->get_value_cb;
213
214         if (system_info_getter == NULL)
215         {
216                 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system information", __FUNCTION__, SYSTEM_INFO_ERROR_IO_ERROR);
217                 return SYSTEM_INFO_ERROR_IO_ERROR;
218         }
219
220         return system_info_getter(key, system_info->data_type, value);
221 }
222
223 int system_info_get_value_int(system_info_key_e key, int *value)
224 {
225         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_INT, (void**)value);
226 }
227
228 int system_info_get_value_bool(system_info_key_e key, bool *value)
229 {
230         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_BOOL, (void**)value);
231 }
232
233 int system_info_get_value_double(system_info_key_e key, double *value)
234 {
235         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_DOUBLE, (void**)value);
236 }
237
238 int system_info_get_value_string(system_info_key_e key, char **value)
239 {
240         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_STRING, (void**)value);
241 }
242