Changeset 4492 for pjproject/trunk/pjsip-apps/src/pjsua/wm/main_wm.c
- Timestamp:
- Apr 23, 2013 10:59:52 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/wm/main_wm.c
r4484 r4492 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #include <windows.h>20 21 #include <pjlib.h>22 #include <windows.h>23 19 #include <winuserm.h> 24 20 #include <aygshell.h> 25 21 #include "..\pjsua_app.h" 22 #include "..\pjsua_app_config.h" 26 23 27 24 #define MAINWINDOWCLASS TEXT("PjsuaDlg") … … 40 37 static HBITMAP g_hBmp; 41 38 42 static int restart_argc = 0; 43 static char **restart_argv = NULL; 44 45 /* Helper funtions to init/restart/destroy the pjsua */ 46 static void LibInit(); 47 static void LibDestroy(); 48 static void LibRestart(); 39 static int start_argc; 40 static char **start_argv; 41 42 /* Helper funtions to init/destroy the pjsua */ 43 static void PjsuaInit(); 44 static void PjsuaDestroy(); 49 45 50 46 /* pjsua app callbacks */ 51 static void lib_on_started(pj_status_t status, const char* title);52 static pj_bool_t lib_on_stopped(pj_bool_t restart, int argc, char** argv);53 static void lib_on_config_init(pjsua_app_config *cfg);47 static void PjsuaOnStarted(pj_status_t status, const char* title); 48 static void PjsuaOnStopped(pj_bool_t restart, int argc, char** argv); 49 static void PjsuaOnConfig(pjsua_app_config *cfg); 54 50 55 51 LRESULT CALLBACK DialogProc(const HWND hWnd, … … 86 82 87 83 case WM_APP_INIT: 88 LibInit(); 84 case WM_APP_RESTART: 85 PjsuaInit(); 89 86 break; 90 87 91 88 case WM_APP_DESTROY: 92 LibDestroy();93 89 PostQuitMessage(0); 94 break;95 96 case WM_APP_RESTART:97 LibRestart();98 90 break; 99 91 … … 108 100 /* === GUI === */ 109 101 110 pj_status_t gui_init()102 pj_status_t GuiInit() 111 103 { 112 104 WNDCLASS wc; … … 193 185 194 186 /* Create logo */ 195 g_hBmp = SHLoadDIBitmap(LOGO_PATH); / / for jpeg, uses SHLoadImageFile()187 g_hBmp = SHLoadDIBitmap(LOGO_PATH); /* for jpeg, uses SHLoadImageFile() */ 196 188 if (g_hBmp == NULL) { 197 189 DWORD err = GetLastError(); … … 228 220 229 221 230 pj_status_t gui_start()222 pj_status_t GuiStart() 231 223 { 232 224 MSG msg; … … 239 231 } 240 232 241 void gui_destroy(void)233 void GuiDestroy(void) 242 234 { 243 235 if (g_hWndMain) { … … 267 259 268 260 /* Called when pjsua is started */ 269 void lib_on_started(pj_status_t status, const char* title)261 void PjsuaOnStarted(pj_status_t status, const char* title) 270 262 { 271 263 wchar_t wtitle[128]; 272 273 PJ_UNUSED_ARG(status); 264 char err_msg[128]; 265 266 if (status != PJ_SUCCESS || title == NULL) { 267 char err_str[PJ_ERR_MSG_SIZE]; 268 pj_strerror(status, err_str, sizeof(err_str)); 269 pj_ansi_snprintf(err_msg, sizeof(err_msg), "%s: %s", 270 (title?title:"App start error"), err_str); 271 title = err_msg; 272 } 274 273 275 274 pj_ansi_to_unicode(title, strlen(title), wtitle, PJ_ARRAY_SIZE(wtitle)); … … 278 277 279 278 /* Called when pjsua is stopped */ 280 pj_bool_t lib_on_stopped(pj_bool_t restart, int argc, char** argv)279 void PjsuaOnStopped(pj_bool_t restart, int argc, char** argv) 281 280 { 282 281 if (restart) { 283 restart_argc = argc;284 restart_argv = argv;282 start_argc = argc; 283 start_argv = argv; 285 284 286 285 // Schedule Lib Restart … … 290 289 PostMessage(g_hWndMain, WM_APP_DESTROY, 0, 0); 291 290 } 292 293 return PJ_FALSE;294 291 } 295 292 296 293 /* Called before pjsua initializing config. */ 297 void lib_on_config_init(pjsua_app_config *cfg)294 void PjsuaOnConfig(pjsua_app_config *cfg) 298 295 { 299 296 PJ_UNUSED_ARG(cfg); 300 297 } 301 298 302 void LibInit() 303 { 304 char* argv[] = { 305 "", 306 "--use-cli", 307 "--cli-telnet-port=0", 308 "--no-cli-console" 309 }; 310 app_cfg_t app_cfg; 299 void PjsuaInit() 300 { 301 pjsua_app_cfg_t app_cfg; 311 302 pj_status_t status; 312 303 304 /* Destroy pjsua app first */ 305 pjsua_app_destroy(); 306 307 /* Init pjsua app */ 313 308 pj_bzero(&app_cfg, sizeof(app_cfg)); 314 app_cfg.argc = PJ_ARRAY_SIZE(argv);315 app_cfg.argv = argv;316 app_cfg.on_started = & lib_on_started;317 app_cfg.on_stopped = & lib_on_stopped;318 app_cfg.on_config_init = & lib_on_config_init;309 app_cfg.argc = start_argc; 310 app_cfg.argv = start_argv; 311 app_cfg.on_started = &PjsuaOnStarted; 312 app_cfg.on_stopped = &PjsuaOnStopped; 313 app_cfg.on_config_init = &PjsuaOnConfig; 319 314 320 315 SetWindowText(g_hWndLbl, _T("Initializing..")); 321 status = app_init(&app_cfg);316 status = pjsua_app_init(&app_cfg); 322 317 if (status != PJ_SUCCESS) 323 318 goto on_return; 324 319 325 320 SetWindowText(g_hWndLbl, _T("Starting..")); 326 status = app_run(PJ_FALSE);321 status = pjsua_app_run(PJ_FALSE); 327 322 if (status != PJ_SUCCESS) 328 323 goto on_return; … … 333 328 } 334 329 335 void LibDestroy() 336 { 337 app_destroy(); 338 } 339 340 void LibRestart() 341 { 342 app_cfg_t app_cfg; 343 pj_status_t status; 344 345 /* Destroy pjsua app first */ 346 347 app_destroy(); 348 349 /* Reinit pjsua app */ 350 351 pj_bzero(&app_cfg, sizeof(app_cfg)); 352 app_cfg.argc = restart_argc; 353 app_cfg.argv = restart_argv; 354 app_cfg.on_started = &lib_on_started; 355 app_cfg.on_stopped = &lib_on_stopped; 356 app_cfg.on_config_init = &lib_on_config_init; 357 358 status = app_init(&app_cfg); 359 if (status != PJ_SUCCESS) { 360 SetWindowText(g_hWndLbl, _T("app_init() failed")); 361 return; 362 } 363 364 /* Run pjsua app */ 365 366 status = app_run(PJ_FALSE); 367 if (status != PJ_SUCCESS) { 368 SetWindowText(g_hWndLbl, _T("app_run() failed")); 369 return; 370 } 371 } 372 330 void PjsuaDestroy() 331 { 332 pjsua_app_destroy(); 333 } 373 334 374 335 /* === MAIN === */ … … 390 351 g_hInst = hInstance; 391 352 392 status = gui_init(); 353 // Start GUI 354 status = GuiInit(); 393 355 if (status != 0) 394 356 goto on_return; 395 357 396 // Start the engine 358 // Setup args and start pjsua 359 start_argc = pjsua_app_def_argc; 360 start_argv = (char**)pjsua_app_def_argv; 397 361 PostMessage(g_hWndMain, WM_APP_INIT, 0, 0); 398 362 399 status = gui_start();363 status = GuiStart(); 400 364 401 365 on_return: 402 LibDestroy();403 gui_destroy();366 PjsuaDestroy(); 367 GuiDestroy(); 404 368 405 369 return status;
Note: See TracChangeset
for help on using the changeset viewer.