diff options
Diffstat (limited to 'pjlib/src')
-rw-r--r-- | pjlib/src/pj/errno.c | 4 | ||||
-rw-r--r-- | pjlib/src/pj/os_core_darwin.m | 86 | ||||
-rw-r--r-- | pjlib/src/pj/os_core_symbian.cpp | 9 | ||||
-rw-r--r-- | pjlib/src/pj/os_core_unix.c | 8 | ||||
-rw-r--r-- | pjlib/src/pj/os_core_win32.c | 9 |
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, ¶m) == 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); +} |