~ubuntu-branches/ubuntu/vivid/sflphone/vivid

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjlib/src/pj/os_info_symbian.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: os_info_symbian.cpp 3437 2011-03-08 06:30:34Z nanang $ */
 
2
/*
 
3
 * Copyright (C) 2011 Teluu Inc. (http://www.teluu.com)
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 */
 
19
#if !defined(PJ_SYMBIAN) || PJ_SYMBIAN == 0
 
20
#   error This file is only for Symbian platform
 
21
#endif
 
22
 
 
23
#include <pj/ctype.h>
 
24
#include <pj/string.h>
 
25
 
 
26
#include <f32file.h>    /* link against efsrv.lib       */
 
27
#include <hal.h>        /* link against hal.lib         */
 
28
#include <utf.h>        /* link against charconv.lib    */
 
29
 
 
30
 
 
31
PJ_BEGIN_DECL
 
32
unsigned pj_symbianos_get_model_info(char *buf, unsigned buf_size);
 
33
unsigned pj_symbianos_get_platform_info(char *buf, unsigned buf_size);
 
34
void pj_symbianos_get_sdk_info(pj_str_t *name, pj_uint32_t *ver);
 
35
PJ_END_DECL
 
36
 
 
37
 
 
38
/* Get Symbian phone model info, returning length of model info */
 
39
unsigned pj_symbianos_get_model_info(char *buf, unsigned buf_size)
 
40
{
 
41
    pj_str_t model_name;
 
42
 
 
43
    /* Get machine UID */
 
44
    TInt hal_val;
 
45
    HAL::Get(HAL::EMachineUid, hal_val);
 
46
    pj_ansi_snprintf(buf, buf_size, "0x%08X", hal_val);
 
47
    pj_strset2(&model_name, buf);
 
48
 
 
49
    /* Get model name */
 
50
    const pj_str_t st_copyright = {"(C)", 3};
 
51
    const pj_str_t st_nokia = {"Nokia", 5};
 
52
    char tmp_buf[64];
 
53
    pj_str_t tmp_str;
 
54
 
 
55
    _LIT(KModelFilename,"Z:\\resource\\versions\\model.txt");
 
56
    RFile file;
 
57
    RFs fs;
 
58
    TInt err;
 
59
 
 
60
    fs.Connect(1);
 
61
    err = file.Open(fs, KModelFilename, EFileRead);
 
62
    if (err == KErrNone) {
 
63
        TFileText text;
 
64
        text.Set(file);
 
65
        TBuf16<64> ModelName16;
 
66
        err = text.Read(ModelName16);
 
67
        if (err == KErrNone) {
 
68
            TPtr8 ptr8((TUint8*)tmp_buf, sizeof(tmp_buf));
 
69
            ptr8.Copy(ModelName16);
 
70
            pj_strset(&tmp_str, tmp_buf, ptr8.Length());
 
71
            pj_strtrim(&tmp_str);
 
72
        }
 
73
        file.Close();
 
74
    }
 
75
    fs.Close();
 
76
    if (err != KErrNone)
 
77
        goto on_return;
 
78
 
 
79
    /* The retrieved model name is usually in long format, e.g:
 
80
     * "� Nokia N95 (01.01)", "(C) Nokia E52". As we need only
 
81
     * the short version, let's clean it up.
 
82
     */
 
83
 
 
84
    /* Remove preceding non-ASCII chars, e.g: "�" */
 
85
    char *p = tmp_str.ptr;
 
86
    while (!pj_isascii(*p)) { p++; }
 
87
    pj_strset(&tmp_str, p, tmp_str.slen - (p - tmp_str.ptr));
 
88
 
 
89
    /* Remove "(C)" */
 
90
    p = pj_stristr(&tmp_str, &st_copyright);
 
91
    if (p) {
 
92
        p += st_copyright.slen;
 
93
        pj_strset(&tmp_str, p, tmp_str.slen - (p - tmp_str.ptr));
 
94
    }
 
95
 
 
96
    /* Remove "Nokia" */
 
97
    p = pj_stristr(&tmp_str, &st_nokia);
 
98
    if (p) {
 
99
        p += st_nokia.slen;
 
100
        pj_strset(&tmp_str, p, tmp_str.slen - (p - tmp_str.ptr));
 
101
    }
 
102
 
 
103
    /* Remove language version, e.g: "(01.01)" */
 
104
    p = pj_strchr(&tmp_str, '(');
 
105
    if (p) {
 
106
        tmp_str.slen = p - tmp_str.ptr;
 
107
    }
 
108
 
 
109
    pj_strtrim(&tmp_str);
 
110
 
 
111
    if (tmp_str.slen == 0)
 
112
        goto on_return;
 
113
 
 
114
    if ((unsigned)tmp_str.slen > buf_size - model_name.slen - 3)
 
115
        tmp_str.slen = buf_size - model_name.slen - 3;
 
116
 
 
117
    pj_strcat2(&model_name, "(");
 
118
    pj_strcat(&model_name, &tmp_str);
 
119
    pj_strcat2(&model_name, ")");
 
120
 
 
121
    /* Zero terminate */
 
122
    buf[model_name.slen] = '\0';
 
123
 
 
124
on_return:
 
125
    return model_name.slen;
 
126
}
 
127
 
 
128
 
 
129
/* Get platform info, returned format will be "Series60vX.X" */
 
130
unsigned pj_symbianos_get_platform_info(char *buf, unsigned buf_size)
 
131
{
 
132
    /* OS info */
 
133
    _LIT(KS60ProductIDFile, "Series60v*.sis");
 
134
    _LIT(KROMInstallDir, "z:\\system\\install\\");
 
135
 
 
136
    RFs fs;
 
137
    TFindFile ff(fs);
 
138
    CDir* result;
 
139
    pj_str_t plat_info = {NULL, 0};
 
140
    TInt err;
 
141
 
 
142
    fs.Connect(1);
 
143
    err = ff.FindWildByDir(KS60ProductIDFile, KROMInstallDir, result);
 
144
    if (err == KErrNone) {
 
145
        err = result->Sort(ESortByName|EDescending);
 
146
        if (err == KErrNone) {
 
147
            TPtr8 tmp_ptr8((TUint8*)buf, buf_size);
 
148
            const pj_str_t tmp_ext = {".sis", 4};
 
149
            char *p;
 
150
 
 
151
            tmp_ptr8.Copy((*result)[0].iName);
 
152
            pj_strset(&plat_info, buf, (pj_size_t)tmp_ptr8.Length());
 
153
            p = pj_stristr(&plat_info, &tmp_ext);
 
154
            if (p)
 
155
                plat_info.slen -= (p - plat_info.ptr);
 
156
        }
 
157
        delete result;
 
158
    }
 
159
    fs.Close();
 
160
    buf[plat_info.slen] = '\0';
 
161
 
 
162
    return plat_info.slen;
 
163
}
 
164
 
 
165
 
 
166
/* Get SDK info */
 
167
void pj_symbianos_get_sdk_info(pj_str_t *name, pj_uint32_t *ver)
 
168
{
 
169
    const pj_str_t S60 = {"S60", 3};
 
170
    #if defined(__SERIES60_30__)
 
171
        *name = S60;
 
172
        *ver  = (3 << 24);
 
173
    #elif defined(__SERIES60_31__)
 
174
        *name = S60;
 
175
        *ver  = (3 << 24) | (1 << 16);
 
176
    #elif defined(__S60_32__)
 
177
        *name = S60;
 
178
        *ver  = (3 << 24) | (2 << 16);
 
179
    #elif defined(__S60_50__)
 
180
        *name = S60;
 
181
        *ver  = (5 << 24);
 
182
    #elif defined(__NOKIA_N97__)
 
183
        *name = pj_str("N97");
 
184
        *ver  = (1 << 24);
 
185
    #else
 
186
        *name = pj_str("Unknown");
 
187
        *ver  = 0;
 
188
    #endif
 
189
}