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