2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <system_info.h>
26 #include <system_info_private.h>
32 #define LOG_TAG "CAPI_SYSTEM_INFO"
34 int system_info_get_model(system_info_key_e key, system_info_data_type_e data_type, void **value)
36 return system_info_ini_get_string(INFO_FILE_PATH, "version:model", (char **)value);
39 int system_info_get_build_string(system_info_key_e key, system_info_data_type_e data_type, void **value)
41 return system_info_ini_get_string(INFO_FILE_PATH, "version:build", (char **)value);
44 int system_info_get_build_date(system_info_key_e key, system_info_data_type_e data_type, void **value)
46 return system_info_ini_get_string(INFO_FILE_PATH, "build:date", (char **)value);
49 int system_info_get_build_time(system_info_key_e key, system_info_data_type_e data_type, void **value)
51 return system_info_ini_get_string(INFO_FILE_PATH, "build:time", (char **)value);
54 int system_info_get_tizen_version(system_info_key_e key, system_info_data_type_e data_type, void **value)
56 return system_info_get_platform_string("tizen.org/feature/platform.version", (char**)value);
59 int system_info_get_core_cpu_arch(system_info_key_e key, system_info_data_type_e data_type, void **value)
62 char *CORE_CPU_ARCH = NULL;
64 if (system_info_get_platform_bool("tizen.org/feature/platform.core.cpu.arch.armv6", &cpu_arch) == SYSTEM_INFO_ERROR_NONE
66 CORE_CPU_ARCH = strdup("armv6");
67 else if (system_info_get_platform_bool("tizen.org/feature/platform.core.cpu.arch.armv7", &cpu_arch) == SYSTEM_INFO_ERROR_NONE
69 CORE_CPU_ARCH = strdup("armv7");
70 else if (system_info_get_platform_bool("tizen.org/feature/platform.core.cpu.arch.x86", &cpu_arch) == SYSTEM_INFO_ERROR_NONE
72 CORE_CPU_ARCH = strdup("x86");
74 if (CORE_CPU_ARCH == NULL) {
76 return SYSTEM_INFO_ERROR_IO_ERROR;
79 *value = CORE_CPU_ARCH;
81 return SYSTEM_INFO_ERROR_NONE;
84 int system_info_get_core_cpu_freq(system_info_key_e key, system_info_data_type_e data_type, void **value)
87 FILE *cpuinfo, *cpuinfo_max_freq;
88 double max_freq = 0.0;
92 if (system_info_get_system_info_model_type() != SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
93 cpuinfo_max_freq = fopen(CPU_INFO_MAX_FREQ_PATH, "r");
94 if (NULL == cpuinfo_max_freq) {
95 LOGE("cannot file open %s file!!!", CPU_INFO_MAX_FREQ_PATH);
96 return SYSTEM_INFO_ERROR_IO_ERROR;
98 if (fscanf(cpuinfo_max_freq, "%lf", &max_freq) < 1) {
99 fclose(cpuinfo_max_freq);
100 return SYSTEM_INFO_ERROR_IO_ERROR;
102 max_freq = max_freq / 1024;
104 fclose(cpuinfo_max_freq);
107 cpuinfo = fopen(CPU_INFO_FILE_PATH, "r");
108 if (NULL == cpuinfo) {
109 LOGE("cannot file open %s file!!!", CPU_INFO_FILE_PATH);
110 return SYSTEM_INFO_ERROR_IO_ERROR;
112 while (fgets(str, MAXBUFSIZE, cpuinfo)) {
113 if (!strncmp("cpu MHz", str, strlen("cpu MHz"))) {
114 name = strchr(str, ':');
115 max_freq = atof(name+2);
123 count = (double *)value;
127 return SYSTEM_INFO_ERROR_NONE;
130 int system_info_get_platform_name(system_info_key_e key, system_info_data_type_e data_type, void **value)
132 return system_info_get_platform_string("tizen.org/system/platform.name", (char**)value);
135 int system_info_get_tizen_version_name(system_info_key_e key, system_info_data_type_e data_type, void **value)
137 char *TIZEN_VERSION_NAME = NULL;
139 char str[MAXBUFSIZE];
140 char tmpStr[MAXBUFSIZE];
143 extern char *strcasestr(const char *s, const char *find);
145 info = fopen(OS_RELEASE_FILE_PATH, "r");
147 LOGE("cannot file open %s file!!!", OS_RELEASE_FILE_PATH);
148 return SYSTEM_INFO_ERROR_IO_ERROR;
151 while (fgets(str, MAXBUFSIZE, info)) {
152 if (strcasestr(str, "VERSION")) {
153 name = strchr(str, ',');
155 tmpStrlen = strlen(name);
157 strncpy(tmpStr, name, tmpStrlen-2);
158 tmpStr[tmpStrlen-2] = '\0';
160 TIZEN_VERSION_NAME = strdup(tmpStr);
161 if (TIZEN_VERSION_NAME == NULL) {
162 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
164 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
170 *value = TIZEN_VERSION_NAME;
172 return SYSTEM_INFO_ERROR_NONE;