- Timestamp:
- Jun 30, 2010 5:29:59 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/cli/pjlib-util/src/pjlib-util/cli_console.c
r3211 r3231 22 22 #include <pj/assert.h> 23 23 #include <pj/errno.h> 24 #include <pj/log.h> 24 25 #include <pj/os.h> 25 26 #include <pj/pool.h> … … 44 45 }; 45 46 47 static void cli_console_write_log(pj_cli_front_end *fe, int level, 48 const char *data, int len) 49 { 50 struct cli_console_fe * cfe = (struct cli_console_fe *)fe; 51 52 if (cfe->sess->log_level > level) 53 printf("%.*s", len, data); 54 } 55 56 46 57 static void cli_console_quit(pj_cli_front_end *fe, pj_cli_sess *req) 47 58 { … … 65 76 cli_console_quit(fe, NULL); 66 77 78 if (cfe->input_thread) 79 pj_thread_destroy(cfe->input_thread); 67 80 pj_sem_destroy(cfe->thread_sem); 68 81 pj_sem_destroy(cfe->input.sem); … … 90 103 91 104 pool = pj_pool_create(pj_cli_get_param(cli)->pf, "console_fe", 92 256, 256, NULL); 105 PJ_CLI_CONSOLE_POOL_SIZE, PJ_CLI_CONSOLE_POOL_INC, 106 NULL); 107 if (!pool) 108 return PJ_ENOMEM; 93 109 sess = PJ_POOL_ZALLOC_T(pool, pj_cli_sess); 94 110 fe = PJ_POOL_ZALLOC_T(pool, struct cli_console_fe); 95 if (!sess || !fe)96 return PJ_ENOMEM;97 111 98 112 if (!param) { … … 102 116 sess->fe = &fe->base; 103 117 sess->log_level = param->log_level; 118 sess->op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_sess_op); 119 fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op); 104 120 fe->base.cli = cli; 105 121 fe->base.type = PJ_CLI_CONSOLE_FRONT_END; 106 fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op);122 fe->base.op->on_write_log = &cli_console_write_log; 107 123 fe->base.op->on_quit = &cli_console_quit; 108 124 fe->base.op->on_destroy = &cli_console_destroy; … … 128 144 fgets(fe->input.buf, fe->input.maxlen, stdin); 129 145 for (i = pj_ansi_strlen(fe->input.buf) - 1; i >= 0; i--) { 130 if (fe->input.buf[i] == '\n' )146 if (fe->input.buf[i] == '\n' || fe->input.buf[i] == '\r') 131 147 fe->input.buf[i] = 0; 132 148 else … … 137 153 pj_sem_wait(fe->thread_sem); 138 154 } 139 pj_sem_post(fe->input.sem);140 155 fe->input_thread = NULL; 141 156 … … 155 170 156 171 if (!fe->input_thread) { 157 if (pj_thread_create(fe->pool, NULL, &readline_thread, fe, 158 0, 0, &fe->input_thread) != PJ_SUCCESS) 159 { 160 return PJ_EUNKNOWN; 161 } 172 pj_status_t status; 173 174 status = pj_thread_create(fe->pool, NULL, &readline_thread, fe, 175 0, 0, &fe->input_thread); 176 if (status != PJ_SUCCESS) 177 return status; 162 178 } else { 163 179 /* Wake up readline thread */ … … 166 182 167 183 pj_sem_wait(fe->input.sem); 168 169 return ( fe->thread_quit? PJ_CLI_EEXIT : PJ_SUCCESS);184 185 return (pj_cli_is_quitting(fe->base.cli)? PJ_CLI_EEXIT : PJ_SUCCESS); 170 186 }
Note: See TracChangeset
for help on using the changeset viewer.