blob: c2099221b6b3cf4368e5a0fed50f420ccf3b15cd [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 */
Sauw Ming0c668f92011-03-25 06:57:25 +000020#include <pjmedia_videodev.h>
Benny Prijono8df5b022006-03-01 19:31:18 +000021#include <pjsua-lib/pjsua.h>
Benny Prijono8df5b022006-03-01 19:31:18 +000022
23#define THIS_FILE "main.c"
24
Benny Prijonoeebe9af2006-06-13 22:57:13 +000025
26/*
Benny Prijonoec5fb812009-08-17 15:33:45 +000027 * These are defined in pjsua_app.c.
Benny Prijono8df5b022006-03-01 19:31:18 +000028 */
Benny Prijonoec5fb812009-08-17 15:33:45 +000029extern pj_bool_t app_restart;
Benny Prijonoeebe9af2006-06-13 22:57:13 +000030pj_status_t app_init(int argc, char *argv[]);
31pj_status_t app_main(void);
32pj_status_t app_destroy(void);
33
Benny Prijono80019eb2006-08-07 13:22:23 +000034
35#if defined(PJ_WIN32) && PJ_WIN32!=0
36#include <windows.h>
37
38static pj_thread_desc handler_desc;
39
40static 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 Prijono95b53402009-01-01 20:56:36 +000057 PJ_UNREACHED(return TRUE;)
Benny Prijono80019eb2006-08-07 13:22:23 +000058
59 default:
60
61 return FALSE;
62 }
63}
64
65static void setup_signal_handler(void)
66{
67 SetConsoleCtrlHandler(&CtrlHandler, TRUE);
68}
69
70#else
71
72static void setup_signal_handler(void)
73{
74}
75
76#endif
77
Benny Prijono8df5b022006-03-01 19:31:18 +000078int main(int argc, char *argv[])
79{
Benny Prijonoec5fb812009-08-17 15:33:45 +000080 do {
81 app_restart = PJ_FALSE;
Benny Prijono8df5b022006-03-01 19:31:18 +000082
Benny Prijonoec5fb812009-08-17 15:33:45 +000083 if (app_init(argc, argv) != PJ_SUCCESS)
84 return 1;
Benny Prijono80019eb2006-08-07 13:22:23 +000085
Benny Prijonoec5fb812009-08-17 15:33:45 +000086 setup_signal_handler();
Benny Prijono8df5b022006-03-01 19:31:18 +000087
Benny Prijonoec5fb812009-08-17 15:33:45 +000088 app_main();
89 app_destroy();
90
91 /* This is on purpose */
92 app_destroy();
93 } while (app_restart);
Benny Prijonoad2e0ca2007-04-29 12:31:51 +000094
Benny Prijono8df5b022006-03-01 19:31:18 +000095 return 0;
96}
97