blob: b7f6af5dddfa8bf8c8611f70accd33370baded7c [file] [log] [blame]
Benny Prijono8df5b022006-03-01 19:31:18 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono8df5b022006-03-01 19:31:18 +00004 *
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 Prijono8df5b022006-03-01 19:31:18 +000020
21#define THIS_FILE "main.c"
22
Benny Prijonoeebe9af2006-06-13 22:57:13 +000023
24/*
25 * These are defined in pjsua.c.
Benny Prijono8df5b022006-03-01 19:31:18 +000026 */
Benny Prijonoeebe9af2006-06-13 22:57:13 +000027pj_status_t app_init(int argc, char *argv[]);
28pj_status_t app_main(void);
29pj_status_t app_destroy(void);
30
Benny Prijono80019eb2006-08-07 13:22:23 +000031
32#if defined(PJ_WIN32) && PJ_WIN32!=0
33#include <windows.h>
34
35static pj_thread_desc handler_desc;
36
37static 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
62static void setup_signal_handler(void)
63{
64 SetConsoleCtrlHandler(&CtrlHandler, TRUE);
65}
66
67#else
68
69static void setup_signal_handler(void)
70{
71}
72
73#endif
74
Benny Prijono8df5b022006-03-01 19:31:18 +000075int main(int argc, char *argv[])
76{
Benny Prijonoeebe9af2006-06-13 22:57:13 +000077 if (app_init(argc, argv) != PJ_SUCCESS)
Benny Prijono8df5b022006-03-01 19:31:18 +000078 return 1;
79
Benny Prijono80019eb2006-08-07 13:22:23 +000080 setup_signal_handler();
81
Benny Prijonoeebe9af2006-06-13 22:57:13 +000082 app_main();
83 app_destroy();
Benny Prijono8df5b022006-03-01 19:31:18 +000084
Benny Prijonoad2e0ca2007-04-29 12:31:51 +000085 /* This is on purpose */
86 app_destroy();
87
Benny Prijono8df5b022006-03-01 19:31:18 +000088 return 0;
89}
90