Implementation of re #1202 (PJLIB System Information API) on Symbian/S60 platforms.



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3437 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/build.symbian/pjlib.mmp b/build.symbian/pjlib.mmp
index 3765e0f..e5c3107 100644
--- a/build.symbian/pjlib.mmp
+++ b/build.symbian/pjlib.mmp
@@ -43,6 +43,8 @@
 SOURCE		lock.c
 SOURCE		string.c
 SOURCE		log.c
+SOURCE		os_info.c
+SOURCE		os_info_symbian.cpp
 SOURCE		os_time_common.c
 SOURCE		pool.c
 SOURCE		pool_buf.c
diff --git a/build.symbian/pjlib_test.mmp b/build.symbian/pjlib_test.mmp
index 65b654c..73f004b 100644
--- a/build.symbian/pjlib_test.mmp
+++ b/build.symbian/pjlib_test.mmp
@@ -71,6 +71,7 @@
 
 LIBRARY		esock.lib insock.lib charconv.lib euser.lib estlib.lib 
 LIBRARY		securesocket.lib x509.lib crypto.lib x500.lib 
+LIBRARY		hal.lib efsrv.lib
  
 #ifdef WINSCW
 STATICLIBRARY   eexe.lib ecrt0.lib
diff --git a/build.symbian/symbian_ua.mmp b/build.symbian/symbian_ua.mmp
index 666d045..af85b71 100644
--- a/build.symbian/symbian_ua.mmp
+++ b/build.symbian/symbian_ua.mmp
@@ -76,6 +76,7 @@
 

 LIBRARY			esock.lib insock.lib charconv.lib euser.lib estlib.lib commdb.lib apengine.lib 

 LIBRARY			securesocket.lib x509.lib crypto.lib x500.lib 

+LIBRARY			hal.lib efsrv.lib

 

 // The default 8KB seems to be insufficient with all bells and

 // whistles turned on

diff --git a/pjlib/src/pj/os_info.c b/pjlib/src/pj/os_info.c
index 4f4bbf1..2d57352 100644
--- a/pjlib/src/pj/os_info.c
+++ b/pjlib/src/pj/os_info.c
@@ -59,6 +59,15 @@
 #if defined(PJ_DARWINOS) && PJ_DARWINOS != 0 && TARGET_OS_IPHONE
     void pj_iphone_os_get_sys_info(pj_sys_info *si, pj_str_t *si_buffer);
 #endif
+    
+#if defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0
+    PJ_BEGIN_DECL
+    unsigned pj_symbianos_get_model_info(char *buf, unsigned buf_size);
+    unsigned pj_symbianos_get_platform_info(char *buf, unsigned buf_size);
+    void pj_symbianos_get_sdk_info(pj_str_t *name, pj_uint32_t *ver);
+    PJ_END_DECL
+#endif
+
 
 static char *ver_info(pj_uint32_t ver, char *buf)
 {
@@ -218,6 +227,22 @@
     #endif	/* PJ_WIN32_WINCE */
 	}
     }
+#elif defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0
+    {
+	pj_symbianos_get_model_info(si_buffer, sizeof(si_buffer));
+	ALLOC_CP_STR(si_buffer, machine);
+	
+	char *p = si_buffer + sizeof(si_buffer) - left;
+	unsigned plen;
+	plen = pj_symbianos_get_platform_info(p, left);
+	if (plen) {
+	    /* Output format will be "Series60vX.X" */
+	    si.os_name = pj_str("S60");
+	    si.os_ver  = parse_version(p+9);
+	} else {
+	    si.os_name = pj_str("Unknown");
+	}
+    }
 #endif
 
     /*
@@ -263,6 +288,8 @@
     	         (((_MSC_VER % 100) / 10) << 16) |
     	         ((_MSC_VER % 10) << 8);
     si.sdk_name = pj_str("msvc");
+#elif defined(PJ_SYMBIAN) && PJ_SYMBIAN != 0
+    pj_symbianos_get_sdk_info(&si.sdk_name, &si.sdk_ver);
 #endif
 
     /*
diff --git a/pjlib/src/pj/os_info_symbian.cpp b/pjlib/src/pj/os_info_symbian.cpp
new file mode 100644
index 0000000..4c2e86b
--- /dev/null
+++ b/pjlib/src/pj/os_info_symbian.cpp
@@ -0,0 +1,190 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+#if !defined(PJ_SYMBIAN) || PJ_SYMBIAN == 0
+#   error This file is only for Symbian platform
+#endif
+
+#include <pj/ctype.h>
+#include <pj/string.h>
+
+#include <f32file.h>	/* link against efsrv.lib	*/
+#include <hal.h>	/* link against hal.lib		*/
+#include <utf.h>	/* link against charconv.lib	*/
+
+
+PJ_BEGIN_DECL
+unsigned pj_symbianos_get_model_info(char *buf, unsigned buf_size);
+unsigned pj_symbianos_get_platform_info(char *buf, unsigned buf_size);
+void pj_symbianos_get_sdk_info(pj_str_t *name, pj_uint32_t *ver);
+PJ_END_DECL
+
+
+/* Get Symbian phone model info, returning length of model info */
+unsigned pj_symbianos_get_model_info(char *buf, unsigned buf_size)
+{
+    pj_str_t model_name;
+
+    /* Get machine UID */
+    TInt hal_val;
+    HAL::Get(HAL::EMachineUid, hal_val);
+    pj_ansi_snprintf(buf, buf_size, "0x%08X", hal_val);
+    pj_strset2(&model_name, buf);
+
+    /* Get model name */
+    const pj_str_t st_copyright = {"(C)", 3};
+    const pj_str_t st_nokia = {"Nokia", 5};
+    char tmp_buf[64];
+    pj_str_t tmp_str;
+
+    _LIT(KModelFilename,"Z:\\resource\\versions\\model.txt");
+    RFile file;
+    RFs fs;
+    TInt err;
+    
+    fs.Connect(1);
+    err = file.Open(fs, KModelFilename, EFileRead);
+    if (err == KErrNone) {
+	TFileText text;
+	text.Set(file);
+	TBuf16<64> ModelName16;
+	err = text.Read(ModelName16);
+	if (err == KErrNone) {
+	    TPtr8 ptr8((TUint8*)tmp_buf, sizeof(tmp_buf));
+	    ptr8.Copy(ModelName16);
+	    pj_strset(&tmp_str, tmp_buf, ptr8.Length());
+	    pj_strtrim(&tmp_str);
+	}
+	file.Close();
+    }
+    fs.Close();
+    if (err != KErrNone)
+	goto on_return;
+    
+    /* The retrieved model name is usually in long format, e.g: 
+     * "© Nokia N95 (01.01)", "(C) Nokia E52". As we need only
+     * the short version, let's clean it up.
+     */
+    
+    /* Remove preceding non-ASCII chars, e.g: "©" */
+    char *p = tmp_str.ptr;
+    while (!pj_isascii(*p)) { p++; }
+    pj_strset(&tmp_str, p, tmp_str.slen - (p - tmp_str.ptr));
+    
+    /* Remove "(C)" */
+    p = pj_stristr(&tmp_str, &st_copyright);
+    if (p) {
+	p += st_copyright.slen;
+	pj_strset(&tmp_str, p, tmp_str.slen - (p - tmp_str.ptr));
+    }
+
+    /* Remove "Nokia" */
+    p = pj_stristr(&tmp_str, &st_nokia);
+    if (p) {
+	p += st_nokia.slen;
+	pj_strset(&tmp_str, p, tmp_str.slen - (p - tmp_str.ptr));
+    }
+    
+    /* Remove language version, e.g: "(01.01)" */
+    p = pj_strchr(&tmp_str, '(');
+    if (p) {
+	tmp_str.slen = p - tmp_str.ptr;
+    }
+    
+    pj_strtrim(&tmp_str);
+    
+    if (tmp_str.slen == 0)
+	goto on_return;
+    
+    if ((unsigned)tmp_str.slen > buf_size - model_name.slen - 3)
+	tmp_str.slen = buf_size - model_name.slen - 3;
+    
+    pj_strcat2(&model_name, "(");
+    pj_strcat(&model_name, &tmp_str);
+    pj_strcat2(&model_name, ")");
+    
+    /* Zero terminate */
+    buf[model_name.slen] = '\0';
+    
+on_return:
+    return model_name.slen;
+}
+
+
+/* Get platform info, returned format will be "Series60vX.X" */
+unsigned pj_symbianos_get_platform_info(char *buf, unsigned buf_size)
+{
+    /* OS info */
+    _LIT(KS60ProductIDFile, "Series60v*.sis");
+    _LIT(KROMInstallDir, "z:\\system\\install\\");
+
+    RFs fs;
+    TFindFile ff(fs);
+    CDir* result;
+    pj_str_t plat_info = {NULL, 0};
+    TInt err;
+
+    fs.Connect(1);
+    err = ff.FindWildByDir(KS60ProductIDFile, KROMInstallDir, result);
+    if (err == KErrNone) {
+	err = result->Sort(ESortByName|EDescending);
+	if (err == KErrNone) {
+	    TPtr8 tmp_ptr8((TUint8*)buf, buf_size);
+	    const pj_str_t tmp_ext = {".sis", 4};
+	    char *p;
+	    
+	    tmp_ptr8.Copy((*result)[0].iName);
+	    pj_strset(&plat_info, buf, (pj_size_t)tmp_ptr8.Length());
+	    p = pj_stristr(&plat_info, &tmp_ext);
+	    if (p)
+		plat_info.slen -= (p - plat_info.ptr);
+	}
+	delete result;
+    }
+    fs.Close();
+    buf[plat_info.slen] = '\0';
+    
+    return plat_info.slen;
+}
+
+
+/* Get SDK info */
+void pj_symbianos_get_sdk_info(pj_str_t *name, pj_uint32_t *ver)
+{
+    const pj_str_t S60 = {"S60", 3};
+    #if defined(__SERIES60_30__)
+	*name = S60;
+	*ver  = (3 << 24);
+    #elif defined(__SERIES60_31__)
+	*name = S60;
+	*ver  = (3 << 24) | (1 << 16);
+    #elif defined(__S60_32__)
+	*name = S60;
+	*ver  = (3 << 24) | (2 << 16);
+    #elif defined(__S60_50__)
+	*name = S60;
+	*ver  = (5 << 24);
+    #elif defined(__NOKIA_N97__)
+	*name = pj_str("N97");
+	*ver  = (1 << 24);
+    #else
+	*name = pj_str("Unknown");
+	*ver  = 0;
+    #endif
+}
+
diff --git a/pjsip-apps/src/symbian_ua_gui/group/symbian_ua_gui.mmp b/pjsip-apps/src/symbian_ua_gui/group/symbian_ua_gui.mmp
index 33930ab..1d6b2e7 100644
--- a/pjsip-apps/src/symbian_ua_gui/group/symbian_ua_gui.mmp
+++ b/pjsip-apps/src/symbian_ua_gui/group/symbian_ua_gui.mmp
@@ -45,6 +45,7 @@
 LIBRARY			ecom.lib inetprotutil.lib http.lib esock.lib

 LIBRARY			charconv.lib estlib.lib 

 LIBRARY			securesocket.lib x509.lib crypto.lib x500.lib

+LIBRARY			hal.lib

 

 // Ordering static libs based on dependencies, most to least dependent,

 // this could be necessary for some SDKs, e.g: S60 3rd MR