Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | 844653c | 2008-12-23 17:27:53 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com) |
Benny Prijono | 32177c0 | 2008-06-20 22:44:47 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
Sauw Ming | 0c668f9 | 2011-03-25 06:57:25 +0000 | [diff] [blame^] | 20 | #include <pjmedia_videodev.h> |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 21 | #include <pjsua-lib/pjsua.h> |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 22 | |
| 23 | #define THIS_FILE "main.c" |
| 24 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 25 | |
| 26 | /* |
Benny Prijono | ec5fb81 | 2009-08-17 15:33:45 +0000 | [diff] [blame] | 27 | * These are defined in pjsua_app.c. |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 28 | */ |
Benny Prijono | ec5fb81 | 2009-08-17 15:33:45 +0000 | [diff] [blame] | 29 | extern pj_bool_t app_restart; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 30 | pj_status_t app_init(int argc, char *argv[]); |
| 31 | pj_status_t app_main(void); |
| 32 | pj_status_t app_destroy(void); |
| 33 | |
Benny Prijono | 80019eb | 2006-08-07 13:22:23 +0000 | [diff] [blame] | 34 | |
| 35 | #if defined(PJ_WIN32) && PJ_WIN32!=0 |
| 36 | #include <windows.h> |
| 37 | |
| 38 | static pj_thread_desc handler_desc; |
| 39 | |
| 40 | static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) |
| 41 | { |
| 42 | pj_thread_t *thread; |
| 43 | |
| 44 | switch (fdwCtrlType) |
| 45 | { |
| 46 | // Handle the CTRL+C signal. |
| 47 | |
| 48 | case CTRL_C_EVENT: |
| 49 | case CTRL_CLOSE_EVENT: |
| 50 | case CTRL_BREAK_EVENT: |
| 51 | case CTRL_LOGOFF_EVENT: |
| 52 | case CTRL_SHUTDOWN_EVENT: |
| 53 | pj_thread_register("ctrlhandler", handler_desc, &thread); |
| 54 | PJ_LOG(3,(THIS_FILE, "Ctrl-C detected, quitting..")); |
| 55 | app_destroy(); |
| 56 | ExitProcess(1); |
Benny Prijono | 95b5340 | 2009-01-01 20:56:36 +0000 | [diff] [blame] | 57 | PJ_UNREACHED(return TRUE;) |
Benny Prijono | 80019eb | 2006-08-07 13:22:23 +0000 | [diff] [blame] | 58 | |
| 59 | default: |
| 60 | |
| 61 | return FALSE; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | static void setup_signal_handler(void) |
| 66 | { |
| 67 | SetConsoleCtrlHandler(&CtrlHandler, TRUE); |
| 68 | } |
| 69 | |
| 70 | #else |
| 71 | |
| 72 | static void setup_signal_handler(void) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | #endif |
| 77 | |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 78 | int main(int argc, char *argv[]) |
| 79 | { |
Benny Prijono | ec5fb81 | 2009-08-17 15:33:45 +0000 | [diff] [blame] | 80 | do { |
| 81 | app_restart = PJ_FALSE; |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 82 | |
Benny Prijono | ec5fb81 | 2009-08-17 15:33:45 +0000 | [diff] [blame] | 83 | if (app_init(argc, argv) != PJ_SUCCESS) |
| 84 | return 1; |
Benny Prijono | 80019eb | 2006-08-07 13:22:23 +0000 | [diff] [blame] | 85 | |
Benny Prijono | ec5fb81 | 2009-08-17 15:33:45 +0000 | [diff] [blame] | 86 | setup_signal_handler(); |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 87 | |
Benny Prijono | ec5fb81 | 2009-08-17 15:33:45 +0000 | [diff] [blame] | 88 | app_main(); |
| 89 | app_destroy(); |
| 90 | |
| 91 | /* This is on purpose */ |
| 92 | app_destroy(); |
| 93 | } while (app_restart); |
Benny Prijono | ad2e0ca | 2007-04-29 12:31:51 +0000 | [diff] [blame] | 94 | |
Benny Prijono | 8df5b02 | 2006-03-01 19:31:18 +0000 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |