Changeset 87822ce in mainline
- Timestamp:
- 2021-03-04T19:14:30Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d6c4d40
- Parents:
- 760a392
- Location:
- uspace
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
r760a392 r87822ce 122 122 cons_event_t ev; 123 123 kbd_event_t *kev; 124 errno_t rc; 124 125 125 126 while (true) { 126 if (!console_get_event(console, &ev)) { 127 rc = console_get_event(console, &ev); 128 if (rc != EOK) 127 129 return; 128 }129 130 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { 130 131 kev = &ev.ev.key; -
uspace/app/bdsh/cmds/modules/cp/cp.c
r760a392 r87822ce 146 146 { 147 147 va_list args; 148 errno_t rc; 148 149 149 150 va_start(args, message); … … 154 155 cons_event_t ev; 155 156 console_flush(con); 156 console_get_event(con, &ev); 157 rc = console_get_event(con, &ev); 158 if (rc != EOK) 159 exit(1); 157 160 if (ev.type != CEV_KEY || ev.ev.key.type != KEY_PRESS || 158 161 (ev.ev.key.mods & (KM_CTRL | KM_ALT)) != 0) { -
uspace/app/edit/edit.c
r760a392 r87822ce 251 251 252 252 while (!done) { 253 console_get_event(con, &ev); 253 rc = console_get_event(con, &ev); 254 if (rc != EOK) 255 break; 256 254 257 pane.rflags = 0; 255 258 … … 634 637 int nc; 635 638 bool done; 639 errno_t rc; 636 640 637 641 asprintf(&str, "%s: %s", prompt, init_value); … … 648 652 649 653 while (!done) { 650 console_get_event(con, &ev); 654 rc = console_get_event(con, &ev); 655 if (rc != EOK) 656 return NULL; 651 657 652 658 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { -
uspace/app/mkbd/main.c
r760a392 r87822ce 174 174 while (true) { 175 175 cons_event_t ev; 176 bool ok= console_get_event(con, &ev);177 if ( !ok) {176 errno_t rc = console_get_event(con, &ev); 177 if (rc != EOK) { 178 178 printf("Connection with console broken: %s.\n", 179 179 str_error(errno)); -
uspace/app/modplay/modplay.c
r760a392 r87822ce 174 174 while (true) { 175 175 timeout = 0; 176 if (console_get_event_timeout(con, &event, &timeout)) 176 rc = console_get_event_timeout(con, &event, &timeout); 177 if (rc == EOK) 177 178 modplay_event(&event); 179 else if (rc != ETIMEOUT) 180 break; 181 178 182 if (quit) 179 183 break; -
uspace/app/netecho/netecho.c
r760a392 r87822ce 121 121 { 122 122 cons_event_t ev; 123 errno_t rc; 123 124 124 125 printf("Communication started. Press Ctrl-Q to quit.\n"); … … 128 129 done = false; 129 130 while (!done) { 130 console_get_event(con, &ev); 131 rc = console_get_event(con, &ev); 132 if (rc != EOK) 133 break; 134 131 135 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) 132 136 key_handle(&ev.ev.key); -
uspace/app/nterm/nterm.c
r760a392 r87822ce 130 130 done = false; 131 131 while (!done) { 132 console_get_event(con, &ev); 132 rc = console_get_event(con, &ev); 133 if (rc != EOK) 134 break; 135 133 136 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) 134 137 key_handle(&ev.ev.key); -
uspace/app/ping/ping.c
r760a392 r87822ce 196 196 while (true) { 197 197 cons_event_t ev; 198 if (!console_get_event(con, &ev)) 199 break; 198 errno_t rc; 199 rc = console_get_event(con, &ev); 200 if (rc != EOK) { 201 ping_signal_received(RECEIVED_INTERRUPT); 202 break; 203 } 200 204 201 205 if ((ev.type == CEV_KEY) && (ev.ev.key.type == KEY_PRESS) && -
uspace/app/tester/ipc/starve.c
r760a392 r87822ce 57 57 cons_event_t ev; 58 58 usec_t timeout = 0; 59 bool has_event = console_get_event_timeout(console, &ev, &timeout); 60 if (has_event && ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { 61 TPRINTF("Key %d pressed, terminating.\n", ev.ev.key.key); 59 errno_t rc = console_get_event_timeout(console, &ev, &timeout); 60 if (rc == EOK) { 61 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { 62 TPRINTF("Key %d pressed, terminating.\n", ev.ev.key.key); 63 break; 64 } 65 } else if (rc != ETIMEOUT) { 66 TPRINTF("Got rc=%d, terminating.\n", rc); 62 67 break; 63 68 } -
uspace/app/tetris/scores.c
r760a392 r87822ce 126 126 cons_event_t ev; 127 127 kbd_event_t *kev; 128 errno_t rc; 128 129 129 130 clear_screen(); … … 141 142 while (true) { 142 143 console_flush(console); 143 if (!console_get_event(console, &ev)) 144 rc = console_get_event(console, &ev); 145 if (rc != EOK) 144 146 exit(1); 145 147 -
uspace/app/tetris/screen.c
r760a392 r87822ce 54 54 */ 55 55 56 #include <errno.h> 56 57 #include <stdio.h> 57 58 #include <stdlib.h> … … 340 341 { 341 342 usec_t timeout = fallrate; 343 errno_t rc; 342 344 343 345 while (timeout > 0) { 344 346 cons_event_t event; 345 347 346 if (!console_get_event_timeout(console, &event, &timeout)) 348 rc = console_get_event_timeout(console, &event, &timeout); 349 if (rc == ETIMEOUT) 347 350 break; 351 if (rc != EOK) 352 exit(1); 348 353 } 349 354 } … … 354 359 int tgetchar(void) 355 360 { 361 errno_t rc; 362 356 363 /* 357 364 * Reset timeleft to fallrate whenever it is not positive … … 376 383 cons_event_t event; 377 384 378 if (!console_get_event_timeout(console, &event, &timeleft)) { 385 rc = console_get_event_timeout(console, &event, &timeleft); 386 if (rc == ETIMEOUT) { 379 387 timeleft = 0; 380 388 return -1; 381 389 } 390 if (rc != EOK) 391 exit(1); 382 392 383 393 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) … … 394 404 { 395 405 char32_t c = 0; 406 errno_t rc; 396 407 397 408 while (c == 0) { 398 409 cons_event_t event; 399 410 400 if (!console_get_event(console, &event)) 411 rc = console_get_event(console, &event); 412 if (rc == ETIMEOUT) 401 413 return -1; 414 if (rc != EOK) 415 exit(1); 402 416 403 417 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) -
uspace/app/tetris/tetris.c
r760a392 r87822ce 202 202 while (true) { 203 203 int i = getchar(); 204 if (i < 0) 205 return 0; 204 206 205 207 switch (i) { -
uspace/app/top/screen.c
r760a392 r87822ce 534 534 /** Get char with timeout 535 535 * 536 * @param sec Timeout in seconds 537 * @param rch Place to store character on success 538 * @return EOK on success, ETIMEOUT on time out, EIO on other error 536 539 */ 537 int tgetchar(sec_t sec) 538 { 540 errno_t tgetchar(sec_t sec, int *rch) 541 { 542 errno_t rc; 543 539 544 /* 540 545 * Reset timeleft whenever it is not positive. … … 548 553 * update timeleft so that the next call to tgetchar() 549 554 * will not wait as long. If there is no input, 550 * make timeleft zero and return -1.555 * make timeleft zero and return ETIMEOUT. 551 556 */ 552 557 … … 557 562 558 563 warning_timeleft -= timeleft; 559 if (!console_get_event_timeout(console, &event, &timeleft)) { 564 rc = console_get_event_timeout(console, &event, &timeleft); 565 if (rc == ETIMEOUT) { 560 566 timeleft = 0; 561 return -1; 562 } 567 return ETIMEOUT; 568 } 569 570 if (rc != EOK) 571 return EIO; 572 563 573 warning_timeleft += timeleft; 564 574 … … 567 577 } 568 578 569 return (int) c; 579 *rch = (int) c; 580 return EOK; 570 581 } 571 582 -
uspace/app/top/screen.h
r760a392 r87822ce 35 35 #define TOP_SCREEN_H_ 36 36 37 #include <errno.h> 37 38 #include <io/console.h> 38 39 #include <io/verify.h> … … 47 48 _HELENOS_PRINTF_ATTRIBUTE(1, 2); 48 49 49 extern int tgetchar(sec_t);50 extern errno_t tgetchar(sec_t, int *); 50 51 51 52 #endif -
uspace/app/top/top.c
r760a392 r87822ce 583 583 data_t data_prev; 584 584 const char *ret = NULL; 585 errno_t rc; 586 int c; 585 587 586 588 screen_init(); … … 595 597 /* And paint screen until death */ 596 598 while (true) { 597 int c = tgetchar(UPDATE_INTERVAL);598 599 if ( c < 0) { /* timeout */599 rc = tgetchar(UPDATE_INTERVAL, &c); 600 601 if (rc == ETIMEOUT) { /* timeout */ 600 602 data_prev = data; 601 603 if ((ret = read_data(&data)) != NULL) { … … 608 610 609 611 c = -1; 612 } else if (rc != EOK) { 613 /* Error (e.g. communication with console lost) */ 614 goto out; 610 615 } 611 616 -
uspace/app/trace/trace.c
r760a392 r87822ce 511 511 { 512 512 cons_event_t event; 513 errno_t rc; 513 514 514 515 (void) arg; … … 522 523 fibril_mutex_unlock(&state_lock); 523 524 524 if (!console_get_event(console, &event)) 525 rc = console_get_event(console, &event); 526 if (rc != EOK) 525 527 return EINVAL; 526 528 -
uspace/lib/c/generic/io/console.c
r760a392 r87822ce 180 180 } 181 181 182 bool console_get_event(console_ctrl_t *ctrl, cons_event_t *event) 182 /** Get console event. 183 * 184 * @param ctrl Console 185 * @param event Place to store event 186 * @return EOK on success, EIO on failure 187 */ 188 errno_t console_get_event(console_ctrl_t *ctrl, cons_event_t *event) 183 189 { 184 190 if (ctrl->input_aid == 0) { … … 192 198 async_wait_for(aid, &rc); 193 199 194 if (rc != EOK) { 195 errno = rc; 196 return false; 197 } 200 if (rc != EOK) 201 return EIO; 198 202 199 203 rc = console_ev_decode(&result, event); 200 if (rc != EOK) { 201 errno = rc; 202 return false; 203 } 204 if (rc != EOK) 205 return EIO; 204 206 } else { 205 207 errno_t retval; … … 208 210 ctrl->input_aid = 0; 209 211 210 if (retval != EOK) { 211 errno = retval; 212 return false; 213 } 212 if (retval != EOK) 213 return EIO; 214 214 215 215 errno_t rc = console_ev_decode(&ctrl->input_call, event); 216 if (rc != EOK) { 217 errno = rc; 218 return false; 219 } 220 } 221 222 return true; 223 } 224 225 bool console_get_event_timeout(console_ctrl_t *ctrl, cons_event_t *event, 216 if (rc != EOK) 217 return EIO; 218 } 219 220 return EOK; 221 } 222 223 /** Get console event with timeout. 224 * 225 * @param ctrl Console 226 * @param event Place to store event 227 * @param timeout Pointer to timeout. This will be updated to reflect 228 * the remaining time in case of timeout. 229 * @return EOK on success (event received), ETIMEOUT on time out, 230 * EIO on I/O error (e.g. lost console connection), ENOMEM 231 * if out of memory 232 */ 233 errno_t console_get_event_timeout(console_ctrl_t *ctrl, cons_event_t *event, 226 234 usec_t *timeout) 227 235 { … … 239 247 errno_t rc = async_wait_timeout(ctrl->input_aid, &retval, *timeout); 240 248 if (rc != EOK) { 249 if (rc == ENOMEM) 250 return ENOMEM; 241 251 *timeout = 0; 242 errno = rc; 243 return false; 252 return ETIMEOUT; 244 253 } 245 254 246 255 ctrl->input_aid = 0; 247 256 248 if (retval != EOK) { 249 errno = retval; 250 return false; 251 } 257 if (retval != EOK) 258 return EIO; 252 259 253 260 rc = console_ev_decode(&ctrl->input_call, event); 254 if (rc != EOK) { 255 errno = rc; 256 return false; 257 } 261 if (rc != EOK) 262 return EIO; 258 263 259 264 /* Update timeout */ … … 262 267 *timeout -= NSEC2USEC(ts_sub_diff(&t1, &t0)); 263 268 264 return true;269 return EOK; 265 270 } 266 271 -
uspace/lib/c/include/io/console.h
r760a392 r87822ce 84 84 extern void console_cursor_visibility(console_ctrl_t *, bool); 85 85 extern errno_t console_get_color_cap(console_ctrl_t *, sysarg_t *); 86 extern boolconsole_get_event(console_ctrl_t *, cons_event_t *);87 extern boolconsole_get_event_timeout(console_ctrl_t *, cons_event_t *,86 extern errno_t console_get_event(console_ctrl_t *, cons_event_t *); 87 extern errno_t console_get_event_timeout(console_ctrl_t *, cons_event_t *, 88 88 usec_t *); 89 89 extern errno_t console_map(console_ctrl_t *, sysarg_t, sysarg_t, -
uspace/lib/clui/tinput.c
r760a392 r87822ce 874 874 errno_t tinput_read_i(tinput_t *ti, const char *istr, char **dstr) 875 875 { 876 errno_t rc; 877 876 878 console_flush(ti->console); 877 879 if (console_get_size(ti->console, &ti->con_cols, &ti->con_rows) != EOK) … … 891 893 892 894 cons_event_t ev; 893 if (!console_get_event(ti->console, &ev)) 895 rc = console_get_event(ti->console, &ev); 896 if (rc != EOK) 894 897 return EIO; 895 898 -
uspace/lib/ui/src/ui.c
r760a392 r87822ce 39 39 #include <fibril.h> 40 40 #include <io/console.h> 41 #include <stdbool.h> 41 42 #include <stdlib.h> 42 43 #include <str.h> … … 220 221 void ui_run(ui_t *ui) 221 222 { 222 bool have_event;223 223 cons_event_t event; 224 224 usec_t timeout; 225 errno_t rc; 225 226 226 227 /* Only return command prompt if we are running in a separate window */ … … 231 232 if (ui->console != NULL) { 232 233 timeout = 100000; 233 have_event= console_get_event_timeout(ui->console,234 rc = console_get_event_timeout(ui->console, 234 235 &event, &timeout); 235 if (have_event) 236 237 /* Do we actually have an event? */ 238 if (rc == EOK) { 236 239 ui_cons_event_process(ui, &event); 240 } else if (rc != ETIMEOUT) { 241 /* Error, quit */ 242 break; 243 } 237 244 } else { 238 245 fibril_usleep(100000);
Note:
See TracChangeset
for help on using the changeset viewer.