Implementation of re #1202 (PJLIB System Information API) on iPhone OS.

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3428 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Sauw Ming 2011-03-01 05:25:27 +00:00
parent 155791d5e5
commit 6a970a3e5a
6 changed files with 9420 additions and 3041 deletions

12327
aconfigure

File diff suppressed because it is too large Load Diff

View File

@ -410,6 +410,11 @@ case $target in
;;
*)
ac_os_objs="$ac_os_objs file_access_unistd.o file_io_ansi.o os_core_unix.o os_error_unix.o os_time_unix.o os_timestamp_posix.o"
case $target in
arm-apple-darwin*)
ac_os_objs="$ac_os_objs os_info_iphone.o"
;;
esac
# UUID
if test "$ac_has_uuid_lib" = "1" -a "$ac_has_uuid_h" = "1"; then
ac_os_objs="$ac_os_objs guid_uuid.o"
@ -535,7 +540,7 @@ if test "$enable_sound" = "no"; then
else
case $target in
arm-apple-darwin*)
LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework AudioToolbox -framework CFNetwork"
LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework AudioToolbox -framework CFNetwork -framework UIKit"
AC_MSG_RESULT([Checking sound device backend... AudioUnit])
;;
*darwin*)

View File

@ -115,6 +115,11 @@ $(OBJDIR)/$(app).ko: $(OBJDIR)/$(app).o
../lib/$(app).ko: $(LIB) $(OBJDIR)/$(app).ko
cp $(OBJDIR)/$(app).ko ../lib
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.m
$(CC) $($(APP)_CFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \
$(subst /,$(HOST_PSEP),$<)
$(OBJDIR)/%$(OBJEXT): $(SRCDIR)/%.c
$(CC) $($(APP)_CFLAGS) \
$(CC_OUT)$(subst /,$(HOST_PSEP),$@) \

View File

@ -100,7 +100,7 @@ fi
# Other settings to feed to configure script.
#ARCH="-arch armv6"
export CFLAGS="${CFLAGS} ${ARCH} -isysroot ${SDKPATH}"
export CFLAGS="${CFLAGS} -DPJ_SDK_NAME=\"\\\"`basename $SDKPATH`\\\"\" ${ARCH} -isysroot ${SDKPATH}"
export LDFLAGS="${LDFLAGS} ${ARCH} -isysroot ${SDKPATH} -framework AudioToolbox -framework Foundation"
export AR="${DEVPATH}/usr/bin/libtool -static -o"
export RANLIB="echo ranlib"

View File

@ -47,11 +47,19 @@
# include <windows.h>
#endif
#if defined(PJ_DARWINOS) && PJ_DARWINOS != 0
# include "TargetConditionals.h"
#endif
#ifndef PJ_SYS_INFO_BUFFER_SIZE
# define PJ_SYS_INFO_BUFFER_SIZE 64
#endif
#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
static char *ver_info(pj_uint32_t ver, char *buf)
{
int len;
@ -78,6 +86,31 @@ static char *ver_info(pj_uint32_t ver, char *buf)
return buf;
}
static pj_uint32_t parse_version(char *str)
{
char *tok;
int i, maxtok;
pj_uint32_t version = 0;
while (*str && !pj_isdigit(*str))
str++;
maxtok = 4;
for (tok = strtok(str, ".-"), i=0; tok && i<maxtok;
++i, tok=strtok(NULL, ".-"))
{
int n;
if (!pj_isdigit(*tok))
break;
n = atoi(tok);
version |= (n << ((3-i)*8));
}
return version;
}
PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
{
static char si_buffer[PJ_SYS_INFO_BUFFER_SIZE];
@ -105,10 +138,29 @@ PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
* Machine and OS info.
*/
#if defined(PJ_HAS_UNAME) && PJ_HAS_UNAME
#if defined(PJ_DARWINOS) && PJ_DARWINOS != 0 && TARGET_OS_IPHONE
{
pj_str_t buf = {si_buffer + PJ_SYS_INFO_BUFFER_SIZE - left, left};
pj_str_t machine = {"arm", 3};
pj_str_t sdk_name = {"iOS-SDK", 7};
char tmp[PJ_SYS_INFO_BUFFER_SIZE];
pj_iphone_os_get_sys_info(&si, &buf);
left -= si.os_name.slen + 1;
si.os_ver = parse_version(si.machine.ptr);
si.machine = machine;
si.sdk_name = sdk_name;
#ifdef PJ_SDK_NAME
pj_memcpy(tmp, PJ_SDK_NAME, pj_ansi_strlen(PJ_SDK_NAME) + 1);
si.sdk_ver = parse_version(tmp);
#endif
}
#else
{
struct utsname u;
char *tok;
int i, maxtok;
/* Successful uname() returns zero on Linux and positive value
* on OpenSolaris.
@ -118,21 +170,10 @@ PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
ALLOC_CP_STR(u.machine, machine);
ALLOC_CP_STR(u.sysname, os_name);
maxtok = 4;
for (tok = strtok(u.release, ".-"), i=0;
tok && i<maxtok;
++i, tok=strtok(NULL, ".-"))
{
int n;
if (!pj_isdigit(*tok))
break;
n = atoi(tok);
si.os_ver |= (n << ((3-i)*8));
}
si.os_ver = parse_version(u.release);
}
#endif
#elif defined(_MSC_VER)
{
OSVERSIONINFO ovi;

View File

@ -0,0 +1,47 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
* 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
*/
#include <pj/os.h>
#include <pj/string.h>
#include <UIKit/UIDevice.h>
void pj_iphone_os_get_sys_info(pj_sys_info *si, pj_str_t *si_buffer)
{
unsigned buf_len = si_buffer->slen, left = si_buffer->slen, len;
UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:@selector(isMultitaskingSupported)])
si->flags |= PJ_SYS_HAS_IOS_BG;
#define ALLOC_CP_STR(str,field) \
do { \
len = [str length]; \
if (len && left >= len+1) { \
si->field.ptr = si_buffer->ptr + buf_len - left; \
si->field.slen = len; \
[str getCString:si->field.ptr maxLength:len+1 \
encoding:NSASCIIStringEncoding]; \
left -= (len+1); \
} \
} while (0)
ALLOC_CP_STR([device systemName], os_name);
ALLOC_CP_STR([device systemVersion], machine);
}