blob: 37941efe2280309c1da9eda06a1c7ab4af1d2519 [file] [log] [blame]
Benny Prijono8df5b022006-03-01 19:31:18 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono8df5b022006-03-01 19:31:18 +00005 *
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 */
20#include <pjsua-lib/pjsua.h>
Benny Prijono8df5b022006-03-01 19:31:18 +000021
22#define THIS_FILE "main.c"
23
Benny Prijonoeebe9af2006-06-13 22:57:13 +000024
25/*
Benny Prijonoec5fb812009-08-17 15:33:45 +000026 * These are defined in pjsua_app.c.
Benny Prijono8df5b022006-03-01 19:31:18 +000027 */
Benny Prijonoec5fb812009-08-17 15:33:45 +000028extern pj_bool_t app_restart;
Benny Prijonoeebe9af2006-06-13 22:57:13 +000029pj_status_t app_init(int argc, char *argv[]);
30pj_status_t app_main(void);
31pj_status_t app_destroy(void);
32
Benny Prijono80019eb2006-08-07 13:22:23 +000033
34#if defined(PJ_WIN32) && PJ_WIN32!=0
35#include <windows.h>
36
37static pj_thread_desc handler_desc;
38
39static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
40{
41 pj_thread_t *thread;
42
43 switch (fdwCtrlType)
44 {
45 // Handle the CTRL+C signal.
46
47 case CTRL_C_EVENT:
48 case CTRL_CLOSE_EVENT:
49 case CTRL_BREAK_EVENT:
50 case CTRL_LOGOFF_EVENT:
51 case CTRL_SHUTDOWN_EVENT:
52 pj_thread_register("ctrlhandler", handler_desc, &thread);
53 PJ_LOG(3,(THIS_FILE, "Ctrl-C detected, quitting.."));
54 app_destroy();
55 ExitProcess(1);
Benny Prijono95b53402009-01-01 20:56:36 +000056 PJ_UNREACHED(return TRUE;)
Benny Prijono80019eb2006-08-07 13:22:23 +000057
58 default:
59
60 return FALSE;
61 }
62}
63
64static void setup_signal_handler(void)
65{
66 SetConsoleCtrlHandler(&CtrlHandler, TRUE);
67}
68
69#else
70
71static void setup_signal_handler(void)
72{
73}
74
75#endif
76
Benny Prijono8df5b022006-03-01 19:31:18 +000077int main(int argc, char *argv[])
78{
Benny Prijonoec5fb812009-08-17 15:33:45 +000079 do {
80 app_restart = PJ_FALSE;
Benny Prijono8df5b022006-03-01 19:31:18 +000081
Benny Prijonoec5fb812009-08-17 15:33:45 +000082 if (app_init(argc, argv) != PJ_SUCCESS)
83 return 1;
Benny Prijono80019eb2006-08-07 13:22:23 +000084
Benny Prijonoec5fb812009-08-17 15:33:45 +000085 setup_signal_handler();
Benny Prijono8df5b022006-03-01 19:31:18 +000086
Benny Prijonoec5fb812009-08-17 15:33:45 +000087 app_main();
88 app_destroy();
89
90 /* This is on purpose */
91 app_destroy();
92 } while (app_restart);
Benny Prijonoad2e0ca2007-04-29 12:31:51 +000093
Benny Prijono8df5b022006-03-01 19:31:18 +000094 return 0;
95}
96