From d2002bd07c284f3d7c4c93179927e89268993688 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 14 May 2007 16:20:57 +0000 Subject: [PATCH] tweak for editline stuff git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5175 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- Makefile.am | 2 +- src/switch_console.c | 86 ++++++++++++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 28 deletions(-) diff --git a/Makefile.am b/Makefile.am index de6c9c190c..79914e18ba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -133,7 +133,7 @@ freeswitch_LDADD = libfreeswitch.la libs/apr/libapr-1.la if ADD_LIBEDIT CORE_CFLAGS += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT CORE_LIBS += libs/libedit/src/.libs/libedit.a -freeswitch_LDADD += -ltermcap +freeswitch_LDADD += -lcurses endif diff --git a/src/switch_console.c b/src/switch_console.c index e239936523..3e655be1e8 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -176,6 +176,7 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const } static char hostname[256] = ""; +static int32_t running = 1; #ifdef SWITCH_HAVE_LIBEDIT #include @@ -191,33 +192,16 @@ char * prompt(EditLine *e) { } -SWITCH_DECLARE(void) switch_console_loop(void) +static EditLine *el; +static History *myhistory; +static HistEvent ev; +static char *hfile = NULL; + +static void *SWITCH_THREAD_FUNC console_thread(switch_thread_t *thread, void *obj) { - EditLine *el; - History *myhistory; int count; const char *line; - HistEvent ev; - int32_t running = 1; - char *hfile; - - el = el_init(__FILE__, switch_core_get_console(), switch_core_get_console(), switch_core_get_console()); - el_set(el, EL_PROMPT, &prompt); - el_set(el, EL_EDITOR, "emacs"); - - myhistory = history_init(); - if (myhistory == 0) { - fprintf(stderr, "history could not be initialized\n"); - return; - } - - hfile = switch_mprintf("%s%sfreeswitch.history", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR); - assert(hfile != NULL); - - - history(myhistory, &ev, H_SETSIZE, 800); - el_set(el, EL_HIST, history, myhistory); - history(myhistory, &ev, H_LOAD, hfile); + switch_memory_pool_t *pool = (switch_memory_pool_t *) obj; while (running) { uint32_t arg; @@ -245,15 +229,63 @@ SWITCH_DECLARE(void) switch_console_loop(void) } } + switch_core_destroy_memory_pool(&pool); + return NULL; +} + + +SWITCH_DECLARE(void) switch_console_loop(void) +{ + switch_thread_t *thread; + switch_threadattr_t *thd_attr = NULL; + switch_memory_pool_t *pool; + + if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n"); + return; + } + + el = el_init(__FILE__, switch_core_get_console(), switch_core_get_console(), switch_core_get_console()); + el_set(el, EL_PROMPT, &prompt); + el_set(el, EL_EDITOR, "emacs"); + + myhistory = history_init(); + if (myhistory == 0) { + fprintf(stderr, "history could not be initialized\n"); + return; + } + + hfile = switch_mprintf("%s%sfreeswitch.history", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR); + assert(hfile != NULL); + + + history(myhistory, &ev, H_SETSIZE, 800); + el_set(el, EL_HIST, history, myhistory); + history(myhistory, &ev, H_LOAD, hfile); + + + switch_threadattr_create(&thd_attr, pool); + switch_threadattr_detach_set(thd_attr, 1); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_thread_create(&thread, thd_attr, console_thread, pool, pool); + + while (running) { + uint32_t arg = 0; + switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg); + if (!arg) { + break; + } + switch_yield(1000000); + } history(myhistory, &ev, H_SAVE, hfile); - free(hfile); /* Clean up our memory */ history_end(myhistory); el_end(el); - + + } #else @@ -262,7 +294,7 @@ SWITCH_DECLARE(void) switch_console_loop(void) { char cmd[2048]; - int32_t activity = 1, running = 1; + int32_t activity = 1; switch_size_t x = 0; gethostname(hostname, sizeof(hostname));