tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / SystemInfo / SystemInfo.cpp
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  * @author        Taejeong Lee <taejeong.lee@samsung.com>
18  */
19
20 #include "SystemInfo.h"
21 #include <Commons/Exception.h>
22 #include <cstdlib>
23
24 extern "C" {
25 #include <iniparser.h>
26 #include <libintl.h>
27 }
28
29 #define DEVICE_INFO_PATH "/etc/info.ini"
30
31 namespace WrtDeviceApis {
32 namespace SystemInfo {
33 SystemInfo& SystemInfo::getInstance()
34 {
35     static SystemInfo instance;
36     return instance;
37 }
38
39 SystemInfo::~SystemInfo()
40 {
41 }
42
43 SystemInfo::SystemInfo()
44 {
45 }
46
47 string SystemInfo::getDeviceModelName()
48 {
49     // copied from settings-beat package
50     char szBin[50];
51     char szEmul[50];
52
53     const char* szBinVer = NULL;
54
55     dictionary* dic = iniparser_load(DEVICE_INFO_PATH);
56     if (dic) {
57         szBinVer = (char*)iniparser_getstr(dic, "Version:Build");
58         if (szBinVer) {
59             char* str = strdup(szBinVer);
60             if (str) {
61                 char* pPos = str;
62                 while (*pPos++) {
63                     if ('_' == *pPos)
64                         *pPos = ' ';
65                 }
66                 sscanf(str, "%s %s", szBin, szEmul);
67             }
68             free(str);
69         }
70     }
71
72     if (dic) {
73         iniparser_freedict(dic);
74         dic = NULL;
75     }
76
77     if (!strncmp(szEmul, "emul", 4)) {
78         return string("SDK");
79     } else {
80         return string(string("GT-")+string(szBin));
81     }
82 }
83
84 string SystemInfo::getDeviceVersion()
85 {
86     // copied from settings-beat package
87     string result;
88
89     dictionary* dic = iniparser_load(DEVICE_INFO_PATH);
90     if (dic == NULL) {
91         result = gettext("IDS_ST_HEADER_UNAVAILABLE");
92     } else {
93         char* szBinVer =
94             strdup((char*)iniparser_getstr(dic, "Version:Build"));
95         char* pPos = szBinVer;
96         while(*pPos++) {
97             if ('.' == *pPos) *pPos = '\0';
98         }
99
100         result = string("Tizen") +
101             string((char*)iniparser_getstr(dic, "Version:Major")) +
102             string(".") +
103             string((char*)iniparser_getstr(dic, "Version:Minor")) +
104             string(" (") + string(szBinVer) + string(")");
105
106         free(szBinVer);
107     }
108
109     if (dic) {
110         iniparser_freedict(dic);
111         dic = NULL;
112     }
113
114     return result;
115 }
116
117 } // SystemInfo
118 } // WrtDeviceApis