3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <glib-object.h>
23 #include <vconf-keys.h>
25 #include "slp_device_info.h"
27 #include "utility/sync_util.h"
28 #include "plugin/device_info_interface.h"
31 #define EXPORT_API __attribute__ ((visibility("default")))
34 #ifndef SYNC_AGENT_LOG
36 #define LOG_TAG "PLUGIN_DEVINFO_SLP"
40 #define FW_VERSION_LEN 20
41 #define BUFF_SIZE 1000
43 /* todo : temporary definition */
44 #define HW_VERSION "1.0"
49 } dici_name_key_map_s;
51 dici_name_key_map_s dev_key_map[] = {
52 {"SwV", VCONFKEY_TELEPHONY_SWVERSION},
53 {"HwV", VCONFKEY_TELEPHONY_HWVERSION},
54 /*{"Lang", "db/menu_widget/language"}, */
55 {"Lang", VCONFKEY_LANGSET},
59 static GList *dev_info;
60 static void _free_device_info(sync_agent_plugin_device_info_s * devinfo);
62 /*static int find_key(const char *info_name, char *key);*/
64 EXPORT_API int sync_agent_plugin_load_devinfo()
75 sync_agent_plugin_device_info_s *dev_id = NULL;
76 sync_agent_plugin_device_info_s *man = NULL;
77 sync_agent_plugin_device_info_s *mod = NULL;
78 sync_agent_plugin_device_info_s *fw = NULL;
79 sync_agent_plugin_device_info_s *oem = NULL;
80 sync_agent_plugin_device_info_s *dev_type = NULL;
81 sync_agent_plugin_device_info_s *modem_version = NULL;
82 sync_agent_plugin_device_info_s *pda_version = NULL;
83 sync_agent_plugin_device_info_s *csc_version = NULL;
85 dev_id = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
87 _DEBUG_ERROR("malloc() dev_id FAIL !!!");
90 memset(dev_id, 0x00, sizeof(sync_agent_plugin_device_info_s));
91 man = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
93 _DEBUG_ERROR("malloc() man FAIL !!!");
96 memset(man, 0x00, sizeof(sync_agent_plugin_device_info_s));
97 mod = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
99 _DEBUG_ERROR("malloc() mod FAIL !!!");
102 memset(mod, 0x00, sizeof(sync_agent_plugin_device_info_s));
103 fw = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
105 _DEBUG_ERROR("malloc() fw FAIL !!!");
108 memset(fw, 0x00, sizeof(sync_agent_plugin_device_info_s));
109 oem = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
111 _DEBUG_ERROR("malloc() oem FAIL !!!");
114 memset(oem, 0x00, sizeof(sync_agent_plugin_device_info_s));
115 dev_type = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
116 if (dev_type == NULL) {
117 _DEBUG_ERROR("malloc() dev_type FAIL !!!");
120 memset(dev_type, 0x00, sizeof(sync_agent_plugin_device_info_s));
121 modem_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
122 if (modem_version == NULL) {
123 _DEBUG_ERROR("malloc() modem_version FAIL !!!");
126 memset(modem_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
127 pda_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
128 if (pda_version == NULL) {
129 _DEBUG_ERROR("malloc() pda_version FAIL !!!");
132 memset(pda_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
133 csc_version = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
134 if (csc_version == NULL) {
135 _DEBUG_ERROR("malloc() csc_version FAIL !!!");
138 memset(csc_version, 0x00, sizeof(sync_agent_plugin_device_info_s));
140 /* get SwV, HwV, Lang */
141 sync_agent_plugin_device_info_s *info = NULL;
142 while (dev_key_map[idx].info_name != NULL) {
144 info = (sync_agent_plugin_device_info_s *) malloc(sizeof(sync_agent_plugin_device_info_s));
146 _DEBUG_ERROR("malloc() info FAIL !!!");
149 memset(info, 0x00, sizeof(sync_agent_plugin_device_info_s));
151 info->info_name = strdup(dev_key_map[idx].info_name);
152 info->value = strdup(vconf_get_str(dev_key_map[idx].vconf_key));
153 _DEBUG_INFO("[devInfo_slp_plugIn] info_name : %s\n", info->info_name);
154 _DEBUG_INFO("[devInfo_slp_plugIn] value : %s\n", info->value);
156 if (!strcmp(info->info_name, "HwV")) {
157 if ((info->value == NULL) || (!strcmp(info->value, "")) || (!strcmp(info->value, "REV__"))) {
159 info->value = strdup(HW_VERSION);
163 _DEBUG_INFO("[devInfo_slp_plugIn] value : %s\n", info->value);
164 dev_info = g_list_append(dev_info, info);
169 dev_id->info_name = strdup("DevID");
170 dev_id->value = slp_device_info_get_device_id();
171 dev_info = g_list_append(dev_info, dev_id);
172 _DEBUG_INFO("mdi ============= \n");
174 /* get Manufacture */
175 man->info_name = strdup("Man");
176 man->value = slp_device_info_get_manufacturer_info();
177 dev_info = g_list_append(dev_info, man);
180 mod->info_name = strdup("Mod");
181 mod->value = slp_device_info_get_model_info();
182 dev_info = g_list_append(dev_info, mod);
185 fw->info_name = strdup("FwV");
186 fw->value = slp_device_info_get_firmware_version();
187 dev_info = g_list_append(dev_info, fw);
190 oem->info_name = strdup("OEM");
191 oem->value = slp_device_info_get_oem_info();
192 dev_info = g_list_append(dev_info, oem);
195 dev_type->info_name = strdup("DevTyp");
196 dev_type->value = slp_device_info_get_device_type();
197 dev_info = g_list_append(dev_info, dev_type);
199 /* get Modem version */
200 modem_version->info_name = strdup("ModemV");
201 modem_version->value = slp_device_info_get_modem_version();
202 dev_info = g_list_append(dev_info, modem_version);
204 /* get PDA version */
205 pda_version->info_name = strdup("PDAV");
206 pda_version->value = slp_device_info_get_pda_version();
207 dev_info = g_list_append(dev_info, pda_version);
209 /* get CSC version */
210 csc_version->info_name = strdup("CSCV");
211 csc_version->value = slp_device_info_get_csc_version();
212 dev_info = g_list_append(dev_info, csc_version);
217 for (iter = dev_info; iter != NULL; iter = g_list_next(iter)) {
218 _DEBUG_INFO("[devInfo_slp_plugIn] cnt : %d, info_name : %s, value : %s\n", cnt, ((sync_agent_plugin_device_info_s *) (iter->data))->info_name, ((sync_agent_plugin_device_info_s *) (iter->data))->value);
228 _free_device_info(dev_id);
229 _free_device_info(man);
230 _free_device_info(mod);
231 _free_device_info(fw);
232 _free_device_info(oem);
233 _free_device_info(dev_type);
234 _free_device_info(modem_version);
235 _free_device_info(pda_version);
236 _free_device_info(csc_version);
238 res = sync_agent_plugin_clear_devinfo();
240 _DEBUG_ERROR("Returning with error.. means FAIL !!!");
247 EXPORT_API int sync_agent_plugin_get_devinfo(char *info_name, char **value)
251 retvm_if(info_name == NULL, 0, "info_name is NULL. FAIL !!!");
256 sync_agent_plugin_device_info_s *iter_data;
258 for (iter = dev_info; iter != NULL; iter = g_list_next(iter)) {
260 iter_data = (sync_agent_plugin_device_info_s *) (iter->data);
261 if (iter_data->info_name != NULL) {
262 if (!strcmp(iter_data->info_name, info_name)) {
263 if (iter_data->value != NULL) {
265 *value = strdup(iter_data->value);
270 _DEBUG_INFO("[devInfo_slp_plugIn] %s value is NULL !!\n", info_name);
278 if (strcmp("Battery", info_name) == 0) {
279 *value = slp_device_info_get_battery_level();
285 _DEBUG_INFO("[devInfo_slp_plugIn] not exist %s information !!\n", info_name);
295 EXPORT_API int sync_agent_plugin_clear_devinfo()
302 sync_agent_plugin_device_info_s *iter_data;
304 if (dev_info != NULL) {
305 for (iter = dev_info; iter != NULL;) {
307 iter_data = ((sync_agent_plugin_device_info_s *) (iter->data));
308 iter = g_list_next(iter);
309 dev_info = g_list_remove(dev_info, iter_data);
311 _free_device_info((sync_agent_plugin_device_info_s *) (iter_data));
314 g_list_free(dev_info);
322 static void _free_device_info(sync_agent_plugin_device_info_s * devinfo)
324 if (devinfo != NULL) {
325 if (devinfo->info_name != NULL) {
326 free(devinfo->info_name);
327 devinfo->info_name = NULL;
329 if (devinfo->value != NULL) {
330 free(devinfo->value);
331 devinfo->value = NULL;
338 /*static int find_key(const char *info_name, char *key)
343 while (dev_key_map[idx].info_name != NULL) {
344 if (!strcmp(dev_key_map[idx].info_name, info_name)) {
345 if (dev_key_map[idx].vconf_key != NULL) {
346 key = dev_key_map[idx].vconf_key;
349 _DEBUG_INFO("[devInfo_slp_plugIn] vconf_key is NULL ( %s )\n", info_name);
358 _DEBUG_INFO("[devInfo_slp_plugIn] vconf_key : %s\n", key);