summaryrefslogtreecommitdiff
path: root/pjlib/src/pj
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2011-07-19 03:42:28 +0000
committerNanang Izzuddin <nanang@teluu.com>2011-07-19 03:42:28 +0000
commitcd283c8825c9a94400f27735acb1c9385e90ffc8 (patch)
tree56d5722310fa8957ce5d1ba7cbd137cf8802dcc7 /pjlib/src/pj
parented8f8d08abba9040f769e922aa0c1adbde86fbbc (diff)
Re #1326: Initial code integration from branch 2.0-dev to trunk as "2.0-pre-alpha-svn".
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3664 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pj')
-rw-r--r--pjlib/src/pj/errno.c4
-rw-r--r--pjlib/src/pj/os_core_darwin.m86
-rw-r--r--pjlib/src/pj/os_core_symbian.cpp9
-rw-r--r--pjlib/src/pj/os_core_unix.c8
-rw-r--r--pjlib/src/pj/os_core_win32.c9
5 files changed, 115 insertions, 1 deletions
diff --git a/pjlib/src/pj/errno.c b/pjlib/src/pj/errno.c
index ed09f266..615d1450 100644
--- a/pjlib/src/pj/errno.c
+++ b/pjlib/src/pj/errno.c
@@ -33,7 +33,9 @@ PJ_BEGIN_DECL
char *buf, pj_size_t bufsize );
PJ_END_DECL
-#define PJLIB_MAX_ERR_MSG_HANDLER 8
+#ifndef PJLIB_MAX_ERR_MSG_HANDLER
+# define PJLIB_MAX_ERR_MSG_HANDLER 10
+#endif
/* Error message handler. */
static unsigned err_msg_hnd_cnt;
diff --git a/pjlib/src/pj/os_core_darwin.m b/pjlib/src/pj/os_core_darwin.m
new file mode 100644
index 00000000..686d64be
--- /dev/null
+++ b/pjlib/src/pj/os_core_darwin.m
@@ -0,0 +1,86 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2011-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
+ */
+#include <pj/os.h>
+#include <pthread.h>
+#include <AppKit/AppKit.h>
+#include <CoreFoundation/CFRunLoop.h>
+#include <Foundation/Foundation.h>
+
+#define THIS_FILE "os_core_darwin.m"
+
+typedef struct run_app_t {
+ pj_main_func_ptr main_func;
+ int argc;
+ char **argv;
+ int retval;
+} run_app_t;
+
+@interface DeadThread: NSObject { ;; }
++ (void)enterMultiThreadedMode;
++ (void)emptyThreadMethod:(id)obj;
+@end
+
+@implementation DeadThread
++ (void)enterMultiThreadedMode
+{
+ [NSThread detachNewThreadSelector:@selector(emptyThreadMethod:)
+ toTarget:[DeadThread class] withObject:nil];
+}
+
++ (void)emptyThreadMethod:(id)obj { ; }
+@end
+
+static void* main_thread(void *data)
+{
+ run_app_t *param = (run_app_t *)data;
+
+ param->retval = (*param->main_func)(param->argc, param->argv);
+ CFRunLoopStop(CFRunLoopGetMain());
+
+ return NULL;
+}
+
+/*
+ * pj_run_app()
+ * This function has to be called from the main thread. The purpose of
+ * this function is to initialize the application's memory pool, event
+ * loop management, and multi-threading environment.
+ */
+PJ_DEF(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
+ unsigned flags)
+{
+ pthread_t thread;
+ run_app_t param;
+ NSAutoreleasePool *pool;
+
+ pool = [[NSAutoreleasePool alloc] init];
+ [NSApplication sharedApplication];
+ [DeadThread enterMultiThreadedMode];
+
+ param.argc = argc;
+ param.argv = (char **)argv;
+ param.main_func = main_func;
+ if (pthread_create(&thread, NULL, &main_thread, &param) == 0) {
+ CFRunLoopRun();
+ }
+
+ PJ_UNUSED_ARG(pool);
+
+ return param.retval;
+}
diff --git a/pjlib/src/pj/os_core_symbian.cpp b/pjlib/src/pj/os_core_symbian.cpp
index abf01b85..5446df5d 100644
--- a/pjlib/src/pj/os_core_symbian.cpp
+++ b/pjlib/src/pj/os_core_symbian.cpp
@@ -1036,3 +1036,12 @@ PJ_DEF(pj_status_t) pj_thread_get_stack_info(pj_thread_t *thread,
}
#endif /* PJ_OS_HAS_CHECK_STACK */
+
+/*
+ * pj_run_app()
+ */
+PJ_DEF(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
+ unsigned flags)
+{
+ return (*main_func)(argc, argv);
+}
diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
index 3fcfa565..fb0ba09e 100644
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -1819,3 +1819,11 @@ PJ_DEF(pj_color_t) pj_term_get_color(void)
#endif /* PJ_TERM_HAS_COLOR */
+/*
+ * pj_run_app()
+ */
+PJ_DEF(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
+ unsigned flags)
+{
+ return (*main_func)(argc, argv);
+}
diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c
index 2b7c2c91..2b703e74 100644
--- a/pjlib/src/pj/os_core_win32.c
+++ b/pjlib/src/pj/os_core_win32.c
@@ -1421,3 +1421,12 @@ PJ_DEF(pj_color_t) pj_term_get_color(void)
}
#endif /* PJ_TERM_HAS_COLOR */
+
+/*
+ * pj_run_app()
+ */
+PJ_DEF(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
+ unsigned flags)
+{
+ return (*main_func)(argc, argv);
+}