summaryrefslogtreecommitdiff
path: root/pjlib/src
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-01-19 03:58:29 +0000
committerBenny Prijono <bennylp@teluu.com>2006-01-19 03:58:29 +0000
commit47e7de1c94be7f826080b3711451eafee894791f (patch)
treed27cdefeb8b9939c47d3126ddcb1ae2d55287d6e /pjlib/src
parent5bad79ed937c72db0f066e2e50ebd74fcdd4dbc3 (diff)
Initial, quick and dirty WinCE port with EVC4
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@125 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src')
-rw-r--r--pjlib/src/pj/compat/unicode_win32.c38
-rw-r--r--pjlib/src/pj/file_access_win32.c66
-rw-r--r--pjlib/src/pj/file_io_win32.c5
-rw-r--r--pjlib/src/pj/ioqueue_common_abs.c15
-rw-r--r--pjlib/src/pj/ioqueue_select.c3
-rw-r--r--pjlib/src/pj/log.c8
-rw-r--r--pjlib/src/pj/os_core_win32.c9
-rw-r--r--pjlib/src/pj/os_time_ansi.c19
-rw-r--r--pjlib/src/pj/os_time_win32.c137
-rw-r--r--pjlib/src/pj/os_timestamp_win32.c8
-rw-r--r--pjlib/src/pj/sock_bsd.c3
-rw-r--r--pjlib/src/pjlib-test/main.c3
-rw-r--r--pjlib/src/pjlib-test/main_mod.c3
-rw-r--r--pjlib/src/pjlib-test/main_win32.c240
-rw-r--r--pjlib/src/pjlib-test/test.c2
15 files changed, 515 insertions, 44 deletions
diff --git a/pjlib/src/pj/compat/unicode_win32.c b/pjlib/src/pj/compat/unicode_win32.c
new file mode 100644
index 00000000..4727210b
--- /dev/null
+++ b/pjlib/src/pj/compat/unicode_win32.c
@@ -0,0 +1,38 @@
+/* $Id$ */
+/*
+ * Copyright (C)2003-2006 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/compat/unicode.h>
+#include <pj/assert.h>
+#include <pj/string.h>
+#include <windows.h>
+
+
+PJ_DEF(wchar_t*) pj_ansi_to_unicode(const char *s, wchar_t *buf,
+ pj_size_t buf_count)
+{
+ int len;
+
+ PJ_ASSERT_RETURN(s, NULL);
+
+ len = MultiByteToWideChar(CP_ACP, 0, s, strlen(s),
+ buf, buf_count);
+ if (!len)
+ return NULL;
+
+ return buf;
+}
diff --git a/pjlib/src/pj/file_access_win32.c b/pjlib/src/pj/file_access_win32.c
index 79eb1f89..9c6d83c2 100644
--- a/pjlib/src/pj/file_access_win32.c
+++ b/pjlib/src/pj/file_access_win32.c
@@ -17,8 +17,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <pj/file_access.h>
+#include <pj/compat/unicode.h>
#include <pj/assert.h>
#include <pj/errno.h>
+#include <pj/string.h>
+#include <pj/os.h>
#include <windows.h>
#include <time.h>
@@ -28,10 +31,12 @@
PJ_DEF(pj_bool_t) pj_file_exists(const char *filename)
{
HANDLE hFile;
+ PJ_DECL_UNICODE_TEMP_BUF(wfilename,256);
PJ_ASSERT_RETURN(filename != NULL, 0);
- hFile = CreateFile(filename, READ_CONTROL, FILE_SHARE_READ, NULL,
+ hFile = CreateFile(PJ_NATIVE_STRING(filename,wfilename), READ_CONTROL,
+ FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return 0;
@@ -49,10 +54,11 @@ PJ_DEF(pj_off_t) pj_file_size(const char *filename)
HANDLE hFile;
DWORD sizeLo, sizeHi;
pj_off_t size;
+ PJ_DECL_UNICODE_TEMP_BUF(wfilename,256);
PJ_ASSERT_RETURN(filename != NULL, -1);
- hFile = CreateFile(filename, READ_CONTROL,
+ hFile = CreateFile(PJ_NATIVE_STRING(filename, wfilename), READ_CONTROL,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
@@ -80,9 +86,11 @@ PJ_DEF(pj_off_t) pj_file_size(const char *filename)
*/
PJ_DEF(pj_status_t) pj_file_delete(const char *filename)
{
+ PJ_DECL_UNICODE_TEMP_BUF(wfilename,256);
+
PJ_ASSERT_RETURN(filename != NULL, PJ_EINVAL);
- if (DeleteFile(filename) == FALSE)
+ if (DeleteFile(PJ_NATIVE_STRING(filename,wfilename)) == FALSE)
return PJ_RETURN_OS_ERROR(GetLastError());
return PJ_SUCCESS;
@@ -95,14 +103,18 @@ PJ_DEF(pj_status_t) pj_file_delete(const char *filename)
PJ_DEF(pj_status_t) pj_file_move( const char *oldname, const char *newname)
{
BOOL rc;
+ PJ_DECL_UNICODE_TEMP_BUF(woldname,256);
+ PJ_DECL_UNICODE_TEMP_BUF(wnewname,256);
PJ_ASSERT_RETURN(oldname!=NULL && newname!=NULL, PJ_EINVAL);
#if PJ_WIN32_WINNT >= 0x0400
- rc = MoveFileEx(oldname, newname,
+ rc = MoveFileEx(PJ_NATIVE_STRING(oldname,woldname),
+ PJ_NATIVE_STRING(newname,wnewname),
MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING);
#else
- rc = MoveFile(oldname, newname);
+ rc = MoveFile(PJ_NATIVE_STRING(oldname, woldname),
+ PJ_NATIVE_STRING(newname, wnewname));
#endif
if (!rc)
@@ -115,31 +127,31 @@ PJ_DEF(pj_status_t) pj_file_move( const char *oldname, const char *newname)
static pj_status_t file_time_to_time_val(const FILETIME *file_time,
pj_time_val *time_val)
{
- SYSTEMTIME systemTime, localTime;
- struct tm tm;
+ FILETIME local_file_time;
+ SYSTEMTIME localTime;
+ pj_parsed_time pt;
- if (!FileTimeToSystemTime(file_time, &systemTime))
- return -1;
+ if (!FileTimeToLocalFileTime(file_time, &local_file_time))
+ return PJ_RETURN_OS_ERROR(GetLastError());
- if (!SystemTimeToTzSpecificLocalTime(NULL, &systemTime, &localTime))
- return -1;
+ if (!FileTimeToSystemTime(file_time, &localTime))
+ return PJ_RETURN_OS_ERROR(GetLastError());
- memset(&tm, 0, sizeof(struct tm));
- tm.tm_year = localTime.wYear - 1900;
- tm.tm_mon = localTime.wMonth - 1;
- tm.tm_mday = localTime.wDay;
- tm.tm_hour = localTime.wHour;
- tm.tm_min = localTime.wMinute;
- tm.tm_sec = localTime.wSecond;
- tm.tm_isdst = 0;
-
- time_val->sec = mktime(&tm);
- if (time_val->sec == (time_t)-1)
- return -1;
+ //if (!SystemTimeToTzSpecificLocalTime(NULL, &systemTime, &localTime))
+ // return PJ_RETURN_OS_ERROR(GetLastError());
- time_val->msec = localTime.wMilliseconds;
+ pj_memset(&pt, 0, sizeof(pt));
+ pt.year = localTime.wYear;
+ pt.mon = localTime.wMonth-1;
+ pt.day = localTime.wDay;
+ pt.wday = localTime.wDayOfWeek;
- return PJ_SUCCESS;
+ pt.hour = localTime.wHour;
+ pt.min = localTime.wMinute;
+ pt.sec = localTime.wSecond;
+ pt.msec = localTime.wMilliseconds;
+
+ return pj_time_encode(&pt, time_val);
}
/*
@@ -150,10 +162,12 @@ PJ_DEF(pj_status_t) pj_file_getstat(const char *filename, pj_file_stat *stat)
HANDLE hFile;
DWORD sizeLo, sizeHi;
FILETIME creationTime, accessTime, writeTime;
+ PJ_DECL_UNICODE_TEMP_BUF(wfilename,256);
PJ_ASSERT_RETURN(filename!=NULL && stat!=NULL, PJ_EINVAL);
- hFile = CreateFile(filename, READ_CONTROL, FILE_SHARE_READ, NULL,
+ hFile = CreateFile(PJ_NATIVE_STRING(filename,wfilename), READ_CONTROL,
+ FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return PJ_RETURN_OS_ERROR(GetLastError());
diff --git a/pjlib/src/pj/file_io_win32.c b/pjlib/src/pj/file_io_win32.c
index f7a4f162..bf8e11fa 100644
--- a/pjlib/src/pj/file_io_win32.c
+++ b/pjlib/src/pj/file_io_win32.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <pj/file_io.h>
+#include <pj/compat/unicode.h>
#include <pj/errno.h>
#include <pj/assert.h>
@@ -43,6 +44,7 @@ PJ_DEF(pj_status_t) pj_file_open( pj_pool_t *pool,
unsigned flags,
pj_oshandle_t *fd)
{
+ PJ_DECL_UNICODE_TEMP_BUF(wpathname,256);
HANDLE hFile;
DWORD dwDesiredAccess = 0;
DWORD dwShareMode = 0;
@@ -76,7 +78,8 @@ PJ_DEF(pj_status_t) pj_file_open( pj_pool_t *pool,
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
- hFile = CreateFile(pathname, dwDesiredAccess, dwShareMode, NULL,
+ hFile = CreateFile(PJ_NATIVE_STRING(pathname,wpathname),
+ dwDesiredAccess, dwShareMode, NULL,
dwCreationDisposition, dwFlagsAndAttributes, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
*fd = 0;
diff --git a/pjlib/src/pj/ioqueue_common_abs.c b/pjlib/src/pj/ioqueue_common_abs.c
index 285aefc9..9b59657e 100644
--- a/pjlib/src/pj/ioqueue_common_abs.c
+++ b/pjlib/src/pj/ioqueue_common_abs.c
@@ -215,12 +215,14 @@ void ioqueue_dispatch_write_event(pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h)
* the right errno through error slippage. This is a combination
* of suggestions from Douglas C. Schmidt and Ken Keys.
*/
- int gp_rc;
- struct sockaddr_in addr;
- socklen_t addrlen = sizeof(addr);
+ {
+ int gp_rc;
+ struct sockaddr_in addr;
+ socklen_t addrlen = sizeof(addr);
- gp_rc = getpeername(h->fd, (struct sockaddr*)&addr, &addrlen);
- bytes_transfered = gp_rc;
+ gp_rc = getpeername(h->fd, (struct sockaddr*)&addr, &addrlen);
+ bytes_transfered = gp_rc;
+ }
#endif
/* Call callback. */
@@ -399,7 +401,8 @@ void ioqueue_dispatch_read_event( pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h )
* read(). That's why we only specify PJ_LINUX here so
* that error is easier to catch.
*/
-# if defined(PJ_WIN32) && PJ_WIN32 != 0
+# if defined(PJ_WIN32) && PJ_WIN32 != 0 || \
+ defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE != 0
rc = pj_sock_recv(h->fd, read_op->buf, &bytes_read, 0);
//rc = ReadFile((HANDLE)h->fd, read_op->buf, read_op->size,
// &bytes_read, NULL);
diff --git a/pjlib/src/pj/ioqueue_select.c b/pjlib/src/pj/ioqueue_select.c
index df08d0c5..1dfcb113 100644
--- a/pjlib/src/pj/ioqueue_select.c
+++ b/pjlib/src/pj/ioqueue_select.c
@@ -221,7 +221,8 @@ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
/* Set socket to nonblocking. */
value = 1;
-#ifdef PJ_WIN32
+#if defined(PJ_WIN32) && PJ_WIN32!=0 || \
+ defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
if (ioctlsocket(sock, FIONBIO, (u_long*)&value)) {
#else
if (ioctl(sock, FIONBIO, &value)) {
diff --git a/pjlib/src/pj/log.c b/pjlib/src/pj/log.c
index 2077fc95..442ee942 100644
--- a/pjlib/src/pj/log.c
+++ b/pjlib/src/pj/log.c
@@ -138,13 +138,19 @@ PJ_DEF(void) pj_log( const char *sender, int level,
/* Print the whole message to the string log_buffer. */
len = len + vsnprintf(pre, sizeof(log_buffer)-len, format, marker);
- if (len > 0 && len < sizeof(log_buffer)-1) {
+ if (len > 0 && len < sizeof(log_buffer)-2) {
+ if (log_decor & PJ_LOG_HAS_CR) {
+ log_buffer[len++] = '\r';
+ }
if (log_decor & PJ_LOG_HAS_NEWLINE) {
log_buffer[len++] = '\n';
}
log_buffer[len++] = '\0';
} else {
len = sizeof(log_buffer)-1;
+ if (log_decor & PJ_LOG_HAS_CR) {
+ log_buffer[sizeof(log_buffer)-3] = '\r';
+ }
if (log_decor & PJ_LOG_HAS_NEWLINE) {
log_buffer[sizeof(log_buffer)-2] = '\n';
}
diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c
index 7633e7b0..94c438fe 100644
--- a/pjlib/src/pj/os_core_win32.c
+++ b/pjlib/src/pj/os_core_win32.c
@@ -536,7 +536,7 @@ PJ_DEF(pj_atomic_value_t) pj_atomic_inc_and_get(pj_atomic_t *atomic_var)
#if defined(PJ_WIN32_WINNT) && PJ_WIN32_WINNT >= 0x0400
return InterlockedIncrement(&atomic_var->value);
#else
-# error Fix Me
+ return InterlockedIncrement(&atomic_var->value);
#endif
}
@@ -558,7 +558,7 @@ PJ_DEF(pj_atomic_value_t) pj_atomic_dec_and_get(pj_atomic_t *atomic_var)
#if defined(PJ_WIN32_WINNT) && PJ_WIN32_WINNT >= 0x0400
return InterlockedDecrement(&atomic_var->value);
#else
-# error Fix me
+ return InterlockedDecrement(&atomic_var->value);
#endif
}
@@ -579,7 +579,7 @@ PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var,
#if defined(PJ_WIN32_WINNT) && PJ_WIN32_WINNT >= 0x0400
InterlockedExchangeAdd( &atomic_var->value, value );
#else
-# error Fix me
+ InterlockedExchangeAdd( &atomic_var->value, value );
#endif
}
@@ -593,7 +593,8 @@ PJ_DEF(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var,
long oldValue = InterlockedExchangeAdd( &atomic_var->value, value);
return oldValue + value;
#else
-# error Fix me
+ long oldValue = InterlockedExchangeAdd( &atomic_var->value, value);
+ return oldValue + value;
#endif
}
diff --git a/pjlib/src/pj/os_time_ansi.c b/pjlib/src/pj/os_time_ansi.c
index 21a117a6..c0cb9f51 100644
--- a/pjlib/src/pj/os_time_ansi.c
+++ b/pjlib/src/pj/os_time_ansi.c
@@ -48,7 +48,6 @@ PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
pt->min = local_time->tm_min;
pt->sec = local_time->tm_sec;
pt->wday = local_time->tm_wday;
- pt->yday = local_time->tm_yday;
pt->msec = tv->msec;
return PJ_SUCCESS;
@@ -57,7 +56,23 @@ PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
/**
* Encode parsed time to time value.
*/
-PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv);
+PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
+{
+ struct tm local_time;
+
+ local_time.tm_year = pt->year-1900;
+ local_time.tm_mon = pt->mon;
+ local_time.tm_mday = pt->day;
+ local_time.tm_hour = pt->hour;
+ local_time.tm_min = pt->min;
+ local_time.tm_sec = pt->sec;
+ local_time.tm_isdst = 0;
+
+ tv->sec = mktime(&local_time);
+ tv->msec = pt->msec;
+
+ return PJ_SUCCESS;
+}
/**
* Convert local time to GMT.
diff --git a/pjlib/src/pj/os_time_win32.c b/pjlib/src/pj/os_time_win32.c
new file mode 100644
index 00000000..f9799317
--- /dev/null
+++ b/pjlib/src/pj/os_time_win32.c
@@ -0,0 +1,137 @@
+/* $Id$ */
+/*
+ * Copyright (C)2003-2006 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 <windows.h>
+
+///////////////////////////////////////////////////////////////////////////////
+
+#define SECS_TO_FT_MULT 10000000
+
+static LARGE_INTEGER base_time;
+
+// Find 1st Jan 1970 as a FILETIME
+static void get_base_time(void)
+{
+ SYSTEMTIME st;
+ FILETIME ft;
+
+ memset(&st,0,sizeof(st));
+ st.wYear=1970;
+ st.wMonth=1;
+ st.wDay=1;
+ SystemTimeToFileTime(&st, &ft);
+
+ base_time.LowPart = ft.dwLowDateTime;
+ base_time.HighPart = ft.dwHighDateTime;
+ base_time.QuadPart /= SECS_TO_FT_MULT;
+}
+
+PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv)
+{
+ SYSTEMTIME st;
+ FILETIME ft;
+ LARGE_INTEGER li;
+
+ if (base_time.QuadPart == 0)
+ get_base_time();
+
+ GetLocalTime(&st);
+ SystemTimeToFileTime(&st, &ft);
+
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ li.QuadPart /= SECS_TO_FT_MULT;
+ li.QuadPart -= base_time.QuadPart;
+
+ tv->sec = li.LowPart;
+ tv->msec = st.wMilliseconds;
+
+ return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
+{
+ LARGE_INTEGER li;
+ FILETIME ft;
+ SYSTEMTIME st;
+
+ li.QuadPart = tv->sec;
+ li.QuadPart += base_time.QuadPart;
+ li.QuadPart *= SECS_TO_FT_MULT;
+
+ ft.dwLowDateTime = li.LowPart;
+ ft.dwHighDateTime = li.HighPart;
+ FileTimeToSystemTime(&ft, &st);
+
+ pt->year = st.wYear;
+ pt->mon = st.wMonth-1;
+ pt->day = st.wDay;
+ pt->wday = st.wDayOfWeek;
+
+ pt->hour = st.wHour;
+ pt->min = st.wMinute;
+ pt->sec = st.wSecond;
+ pt->msec = tv->msec;
+
+ return PJ_SUCCESS;
+}
+
+/**
+ * Encode parsed time to time value.
+ */
+PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
+{
+ SYSTEMTIME st;
+ FILETIME ft;
+ LARGE_INTEGER li;
+
+ pj_memset(&st, 0, sizeof(st));
+ st.wYear = pt->year;
+ st.wMonth = pt->mon + 1;
+ st.wDay = pt->day;
+ st.wHour = pt->hour;
+ st.wMinute = pt->min;
+ st.wSecond = pt->sec;
+ st.wMilliseconds = pt->msec;
+
+ SystemTimeToFileTime(&st, &ft);
+
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ li.QuadPart /= SECS_TO_FT_MULT;
+ li.QuadPart -= base_time.QuadPart;
+
+ tv->sec = li.LowPart;
+ tv->msec = st.wMilliseconds;
+
+ return PJ_SUCCESS;
+}
+
+/**
+ * Convert local time to GMT.
+ */
+PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv);
+
+/**
+ * Convert GMT to local time.
+ */
+PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv);
+
+
diff --git a/pjlib/src/pj/os_timestamp_win32.c b/pjlib/src/pj/os_timestamp_win32.c
index 5b63529b..7cd391e3 100644
--- a/pjlib/src/pj/os_timestamp_win32.c
+++ b/pjlib/src/pj/os_timestamp_win32.c
@@ -24,6 +24,7 @@
defined(PJ_M_I386) && PJ_M_I386 != 0 && \
defined(PJ_HAS_PENTIUM) && PJ_HAS_PENTIUM!=0 && \
defined(_MSC_VER)
+
/*
* Use rdtsc to get the OS timestamp.
*/
@@ -36,9 +37,16 @@ static pj_status_t GetCpuHz(void)
LONG rc;
DWORD size;
+#if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
+ rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
+ 0, 0, &key);
+#else
rc = RegOpenKey( HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
&key);
+#endif
+
if (rc != ERROR_SUCCESS)
return PJ_RETURN_OS_ERROR(rc);
diff --git a/pjlib/src/pj/sock_bsd.c b/pjlib/src/pj/sock_bsd.c
index 3ded3a54..cdb8ca8d 100644
--- a/pjlib/src/pj/sock_bsd.c
+++ b/pjlib/src/pj/sock_bsd.c
@@ -362,7 +362,8 @@ PJ_DEF(pj_status_t) pj_sock_close(pj_sock_t sock)
int rc;
PJ_CHECK_STACK();
-#if defined(PJ_WIN32) && PJ_WIN32==1
+#if defined(PJ_WIN32) && PJ_WIN32!=0 || \
+ defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
rc = closesocket(sock);
#else
rc = close(sock);
diff --git a/pjlib/src/pjlib-test/main.c b/pjlib/src/pjlib-test/main.c
index 20a34478..4236b5b5 100644
--- a/pjlib/src/pjlib-test/main.c
+++ b/pjlib/src/pjlib-test/main.c
@@ -90,6 +90,9 @@ int main(int argc, char *argv[])
}
}
+ pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
+ PJ_LOG_HAS_MICRO_SEC);
+
rc = test_main();
if (interractive) {
diff --git a/pjlib/src/pjlib-test/main_mod.c b/pjlib/src/pjlib-test/main_mod.c
index 2dada340..3ad07794 100644
--- a/pjlib/src/pjlib-test/main_mod.c
+++ b/pjlib/src/pjlib-test/main_mod.c
@@ -24,6 +24,9 @@ int init_module(void)
{
printk(KERN_INFO "PJLIB test module loaded. Starting tests...\n");
+ pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
+ PJ_LOG_HAS_MICRO_SEC);
+
test_main();
/* Prevent module from loading. We've finished test anyway.. */
diff --git a/pjlib/src/pjlib-test/main_win32.c b/pjlib/src/pjlib-test/main_win32.c
new file mode 100644
index 00000000..a0ca2f91
--- /dev/null
+++ b/pjlib/src/pjlib-test/main_win32.c
@@ -0,0 +1,240 @@
+/* $Id$ */
+/*
+ * Copyright (C)2003-2006 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 "test.h"
+
+#include <pj/string.h>
+#include <pj/compat/unicode.h>
+#include <pj/sock.h>
+#include <pj/log.h>
+
+#include <windows.h>
+#include <commctrl.h>
+
+#define MAX_LOADSTRING 100
+
+#define IDC_HELLO_WINCE 3
+#define ID_LOGWINDOW 104
+///#define IDI_HELLO_WINCE 101
+///#define IDM_MENU 102
+///#define IDD_ABOUTBOX 103
+///#define IDM_FILE_EXIT 40002
+///#define IDM_HELP_ABOUT 40003
+
+// Global Variables:
+HINSTANCE hInst; // The current instance
+///HWND hwndCB; // The command bar handle
+HWND hwLogWnd;
+
+// Forward declarations of functions included in this code module:
+ATOM MyRegisterClass (HINSTANCE, LPTSTR);
+BOOL InitInstance (HINSTANCE, int);
+LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
+///LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
+
+static TCHAR logbuf[8192];
+PJ_DECL_UNICODE_TEMP_BUF(wdata,256);
+
+static void write_log(int level, const char *data, int len)
+{
+ GetWindowText(hwLogWnd, logbuf, PJ_ARRAY_SIZE(logbuf));
+ wcscat(logbuf, PJ_NATIVE_STRING(data,wdata));
+ SetWindowText(hwLogWnd, logbuf);
+ UpdateWindow(hwLogWnd);
+}
+
+
+int WINAPI WinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPTSTR lpCmdLine,
+ int nCmdShow)
+{
+ MSG msg;
+ HACCEL hAccelTable;
+
+ // Perform application initialization:
+ if (!InitInstance (hInstance, nCmdShow))
+ {
+ return FALSE;
+ }
+
+ pj_log_set_log_func( &write_log );
+ pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR);
+
+ test_main();
+
+ hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_HELLO_WINCE);
+
+ // Main message loop:
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+
+ return msg.wParam;
+}
+
+//
+// FUNCTION: MyRegisterClass()
+//
+// PURPOSE: Registers the window class.
+//
+// COMMENTS:
+//
+// It is important to call this function so that the application
+// will get 'well formed' small icons associated with it.
+//
+ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
+{
+ WNDCLASS wc;
+
+ wc.style = CS_HREDRAW | CS_VREDRAW;
+ wc.lpfnWndProc = (WNDPROC) WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hInstance;
+ ///wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HELLO_WINCE));
+ wc.hIcon = NULL;
+ wc.hCursor = 0;
+ wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
+ wc.lpszMenuName = 0;
+ wc.lpszClassName = szWindowClass;
+
+ return RegisterClass(&wc);
+}
+
+//
+// FUNCTION: InitInstance(HANDLE, int)
+//
+// PURPOSE: Saves instance handle and creates main window
+//
+// COMMENTS:
+//
+// In this function, we save the instance handle in a global variable and
+// create and display the main program window.
+//
+BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
+{
+ HWND hWnd;
+ TCHAR *szTitle = L"PJSIP Test";
+ TCHAR *szWindowClass = L"PJSIP_TEST";
+
+ hInst = hInstance; // Store instance handle in our global variable
+
+ MyRegisterClass(hInstance, szWindowClass);
+
+ hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
+
+ if (!hWnd)
+ {
+ return FALSE;
+ }
+
+ ShowWindow(hWnd, nCmdShow);
+ UpdateWindow(hWnd);
+ ///if (hwndCB)
+ /// CommandBar_Show(hwndCB, TRUE);
+ if (hwLogWnd)
+ ShowWindow(hwLogWnd, TRUE);
+ return TRUE;
+}
+
+//
+// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
+//
+// PURPOSE: Processes messages for the main window.
+//
+// WM_COMMAND - process the application menu
+// WM_PAINT - Paint the main window
+// WM_DESTROY - post a quit message and return
+//
+//
+LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ int wmId, wmEvent;
+ RECT rt;
+ DWORD dwStyle;
+ TCHAR *szHello = L"Hello world!";
+
+ switch (message)
+ {
+ case WM_COMMAND:
+ wmId = LOWORD(wParam);
+ wmEvent = HIWORD(wParam);
+ // Parse the menu selections:
+ switch (wmId)
+ {
+ ///case IDM_HELP_ABOUT:
+ ///DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
+ /// break;
+ ///case IDM_FILE_EXIT:
+ /// DestroyWindow(hWnd);
+ /// break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ break;
+ case WM_CREATE:
+ ///hwndCB = CommandBar_Create(hInst, hWnd, 1);
+ ///CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
+ ///CommandBar_AddAdornments(hwndCB, 0, 0);
+ GetClientRect(hWnd, &rt);
+ dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
+ WS_BORDER | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL |
+ ES_AUTOHSCROLL | ES_AUTOVSCROLL;
+ hwLogWnd = CreateWindow( TEXT("edit"), // class
+ NULL, // window text
+ dwStyle, // style
+ 0, // x-left
+ 0, // y-top
+ rt.right-rt.left, // w
+ rt.bottom-rt.top, // h
+ hWnd, // parent
+ (HMENU)ID_LOGWINDOW, // id
+ hInst, // instance
+ NULL); // NULL for control.
+ break;
+ case WM_PAINT:
+ ///hdc = BeginPaint(hWnd, &ps);
+ ///GetClientRect(hWnd, &rt);
+ ///DrawText(hdc, szHello, _tcslen(szHello), &rt,
+ /// DT_SINGLELINE | DT_VCENTER | DT_CENTER);
+ ///EndPaint(hWnd, &ps);
+ break;
+ case WM_ACTIVATE:
+ if (LOWORD(wParam) == WA_INACTIVE)
+ DestroyWindow(hWnd);
+ break;
+ case WM_CLOSE:
+ DestroyWindow(hWnd);
+ break;
+ case WM_DESTROY:
+ ///CommandBar_Destroy(hwndCB);
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ return 0;
+}
+
diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c
index f8506fa9..ce0d1a3f 100644
--- a/pjlib/src/pjlib-test/test.c
+++ b/pjlib/src/pjlib-test/test.c
@@ -48,8 +48,6 @@ int test_inner(void)
mem = &caching_pool.factory;
pj_log_set_level(3);
- pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
- PJ_LOG_HAS_MICRO_SEC);
rc = pj_init();
if (rc != 0) {