Changeset 4476 for pjproject/trunk/pjsip-apps/src/pjsua/main.c
- Timestamp:
- Apr 19, 2013 6:05:06 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/main.c
r4461 r4476 18 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 #include <pjsua-lib/pjsua.h> 21 20 #include "pjsua_app.h" 22 21 23 22 #define THIS_FILE "main.c" 24 23 24 static pj_bool_t running = PJ_TRUE; 25 static pj_status_t receive_end_sig; 26 static pj_thread_t *sig_thread; 27 static app_cfg_t cfg; 25 28 26 /* 27 * These are defined in pjsua_app.c. 28 */ 29 int main_func(int argc, char *argv[]); 29 /* Called when CLI (re)started */ 30 void on_app_started(pj_status_t status, const char *msg) 31 { 32 pj_perror(3, THIS_FILE, status, (msg)?msg:""); 33 } 34 35 pj_bool_t on_app_stopped(pj_bool_t restart, int argc, char** argv) 36 { 37 cfg.argc = argc; 38 cfg.argv = argv; 39 40 running = restart; 41 return PJ_TRUE; 42 } 43 44 #if defined(PJ_WIN32) && PJ_WIN32!=0 45 #include <windows.h> 46 47 static pj_thread_desc handler_desc; 48 49 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) 50 { 51 switch (fdwCtrlType) 52 { 53 // Handle the CTRL+C signal. 54 55 case CTRL_C_EVENT: 56 case CTRL_CLOSE_EVENT: 57 case CTRL_BREAK_EVENT: 58 case CTRL_LOGOFF_EVENT: 59 case CTRL_SHUTDOWN_EVENT: 60 pj_thread_register("ctrlhandler", handler_desc, &sig_thread); 61 PJ_LOG(3,(THIS_FILE, "Ctrl-C detected, quitting..")); 62 receive_end_sig = PJ_TRUE; 63 app_destroy(); 64 ExitProcess(1); 65 PJ_UNREACHED(return TRUE;) 66 67 default: 68 69 return FALSE; 70 } 71 } 72 73 static void setup_socket_signal() 74 { 75 } 76 77 static void setup_signal_handler(void) 78 { 79 SetConsoleCtrlHandler(&CtrlHandler, TRUE); 80 } 81 82 #else 83 #include <signal.h> 84 85 static void setup_socket_signal() 86 { 87 signal(SIGPIPE, SIG_IGN); 88 } 89 90 static void setup_signal_handler(void) {} 91 #endif 30 92 31 93 int main(int argc, char *argv[]) 32 94 { 33 return pj_run_app(&main_func, argc, argv, 0); 95 pj_status_t status = PJ_TRUE; 96 97 pj_bzero(&cfg, sizeof(cfg)); 98 cfg.on_started = &on_app_started; 99 cfg.on_stopped = &on_app_stopped; 100 cfg.argc = argc; 101 cfg.argv = argv; 102 103 setup_signal_handler(); 104 setup_socket_signal(); 105 106 while (running) { 107 status = app_init(&cfg); 108 if (status == PJ_SUCCESS) { 109 status = app_run(PJ_TRUE); 110 } else { 111 pj_perror(3, THIS_FILE, status, "Failed init"); 112 running = PJ_FALSE; 113 } 114 115 if (!receive_end_sig) { 116 app_destroy(); 117 118 /* This is on purpose */ 119 app_destroy(); 120 } else { 121 pj_thread_join(sig_thread); 122 } 123 } 34 124 }
Note: See TracChangeset
for help on using the changeset viewer.