Changeset a35b458 in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r3061bc1 ra35b458 62 62 atomic_t refcnt; /**< Connection reference count */ 63 63 prodcons_t input_pc; /**< Incoming keyboard events */ 64 64 65 65 /** 66 66 * Not yet sent bytes of last char event. … … 68 68 char char_remains[UTF8_CHAR_BUFFER_SIZE]; 69 69 size_t char_remains_len; /**< Number of not yet sent bytes. */ 70 70 71 71 fibril_mutex_t mtx; /**< Lock protecting mutable fields */ 72 72 73 73 size_t index; /**< Console index */ 74 74 service_id_t dsid; /**< Service handle */ 75 75 76 76 sysarg_t cols; /**< Number of columns */ 77 77 sysarg_t rows; /**< Number of rows */ 78 78 console_caps_t ccaps; /**< Console capabilities */ 79 79 80 80 chargrid_t *frontbuf; /**< Front buffer */ 81 81 frontbuf_handle_t fbid; /**< Front buffer handle */ … … 162 162 fibril_mutex_lock(&switch_mtx); 163 163 fibril_mutex_lock(&cons->mtx); 164 164 165 165 if ((active) && (cons == active_console)) { 166 166 output_update(output_sess, cons->fbid); 167 167 output_cursor_update(output_sess, cons->fbid); 168 168 } 169 169 170 170 fibril_mutex_unlock(&cons->mtx); 171 171 fibril_mutex_unlock(&switch_mtx); … … 176 176 fibril_mutex_lock(&switch_mtx); 177 177 fibril_mutex_lock(&cons->mtx); 178 178 179 179 if ((active) && (cons == active_console)) 180 180 output_cursor_update(output_sess, cons->fbid); 181 181 182 182 fibril_mutex_unlock(&cons->mtx); 183 183 fibril_mutex_unlock(&switch_mtx); … … 188 188 fibril_mutex_lock(&switch_mtx); 189 189 fibril_mutex_lock(&cons->mtx); 190 190 191 191 if ((active) && (cons == active_console)) { 192 192 output_damage(output_sess, cons->fbid, 0, 0, cons->cols, … … 194 194 output_cursor_update(output_sess, cons->fbid); 195 195 } 196 196 197 197 fibril_mutex_unlock(&cons->mtx); 198 198 fibril_mutex_unlock(&switch_mtx); … … 208 208 if (console_kcon()) 209 209 active = false; 210 210 211 211 return; 212 212 } 213 213 214 214 if (index > CONSOLE_COUNT) 215 215 return; 216 216 217 217 console_t *cons = &consoles[index]; 218 218 219 219 fibril_mutex_lock(&switch_mtx); 220 220 221 221 if (cons == active_console) { 222 222 fibril_mutex_unlock(&switch_mtx); 223 223 return; 224 224 } 225 225 226 226 active_console = cons; 227 227 228 228 fibril_mutex_unlock(&switch_mtx); 229 229 230 230 cons_damage(cons); 231 231 } … … 236 236 output_claim(output_sess); 237 237 cons_damage(active_console); 238 238 239 239 return EOK; 240 240 } … … 244 244 active = false; 245 245 output_yield(output_sess); 246 246 247 247 return EOK; 248 248 } … … 261 261 return ENOMEM; 262 262 } 263 263 264 264 link_initialize(&event->link); 265 265 event->type = type; … … 267 267 event->mods = mods; 268 268 event->c = c; 269 269 270 270 prodcons_produce(&active_console->input_pc, 271 271 &event->link); 272 272 } 273 273 274 274 return EOK; 275 275 } … … 295 295 { 296 296 sysarg_t updated = 0; 297 298 fibril_mutex_lock(&cons->mtx); 299 297 298 fibril_mutex_lock(&cons->mtx); 299 300 300 switch (ch) { 301 301 case '\n': … … 313 313 updated = chargrid_putchar(cons->frontbuf, ch, true); 314 314 } 315 316 fibril_mutex_unlock(&cons->mtx); 317 315 316 fibril_mutex_unlock(&cons->mtx); 317 318 318 if (updated > 1) 319 319 cons_update(cons); … … 325 325 chargrid_set_cursor_visibility(cons->frontbuf, visible); 326 326 fibril_mutex_unlock(&cons->mtx); 327 327 328 328 cons_update_cursor(cons); 329 329 } … … 344 344 console_t *cons = srv_to_console(srv); 345 345 size_t pos = 0; 346 346 347 347 /* 348 348 * Read input from keyboard and copy it to the buffer. … … 355 355 bbuf[pos] = cons->char_remains[0]; 356 356 pos++; 357 357 358 358 /* Unshift the array. */ 359 359 for (size_t i = 1; i < cons->char_remains_len; i++) 360 360 cons->char_remains[i - 1] = cons->char_remains[i]; 361 361 362 362 cons->char_remains_len--; 363 363 } 364 364 365 365 /* Still not enough? Then get another key from the queue. */ 366 366 if (pos < size) { 367 367 link_t *link = prodcons_consume(&cons->input_pc); 368 368 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 369 369 370 370 /* Accept key presses of printable chars only. */ 371 371 if ((event->type == KEY_PRESS) && (event->c != 0)) { … … 374 374 cons->char_remains_len = str_size(cons->char_remains); 375 375 } 376 376 377 377 free(event); 378 378 } 379 379 } 380 380 381 381 *nread = size; 382 382 return EOK; … … 390 390 while (off < size) 391 391 cons_write_char(cons, str_decode(data, &off, size)); 392 392 393 393 *nwritten = size; 394 394 return EOK; … … 398 398 { 399 399 console_t *cons = srv_to_console(srv); 400 400 401 401 cons_update(cons); 402 402 } … … 405 405 { 406 406 console_t *cons = srv_to_console(srv); 407 407 408 408 fibril_mutex_lock(&cons->mtx); 409 409 chargrid_clear(cons->frontbuf); 410 410 fibril_mutex_unlock(&cons->mtx); 411 411 412 412 cons_update(cons); 413 413 } … … 416 416 { 417 417 console_t *cons = srv_to_console(srv); 418 418 419 419 fibril_mutex_lock(&cons->mtx); 420 420 chargrid_set_cursor(cons->frontbuf, col, row); 421 421 fibril_mutex_unlock(&cons->mtx); 422 422 423 423 cons_update_cursor(cons); 424 424 } … … 427 427 { 428 428 console_t *cons = srv_to_console(srv); 429 429 430 430 fibril_mutex_lock(&cons->mtx); 431 431 chargrid_get_cursor(cons->frontbuf, col, row); 432 432 fibril_mutex_unlock(&cons->mtx); 433 433 434 434 return EOK; 435 435 } … … 438 438 { 439 439 console_t *cons = srv_to_console(srv); 440 440 441 441 fibril_mutex_lock(&cons->mtx); 442 442 *cols = cons->cols; 443 443 *rows = cons->rows; 444 444 fibril_mutex_unlock(&cons->mtx); 445 445 446 446 return EOK; 447 447 } … … 450 450 { 451 451 console_t *cons = srv_to_console(srv); 452 452 453 453 fibril_mutex_lock(&cons->mtx); 454 454 *ccaps = cons->ccaps; 455 455 fibril_mutex_unlock(&cons->mtx); 456 456 457 457 return EOK; 458 458 } … … 461 461 { 462 462 console_t *cons = srv_to_console(srv); 463 463 464 464 fibril_mutex_lock(&cons->mtx); 465 465 chargrid_set_style(cons->frontbuf, style); … … 471 471 { 472 472 console_t *cons = srv_to_console(srv); 473 473 474 474 fibril_mutex_lock(&cons->mtx); 475 475 chargrid_set_color(cons->frontbuf, bgcolor, fgcolor, attr); … … 481 481 { 482 482 console_t *cons = srv_to_console(srv); 483 483 484 484 fibril_mutex_lock(&cons->mtx); 485 485 chargrid_set_rgb_color(cons->frontbuf, bgcolor, fgcolor); … … 490 490 { 491 491 console_t *cons = srv_to_console(srv); 492 492 493 493 cons_set_cursor_vis(cons, visible); 494 494 } … … 499 499 link_t *link = prodcons_consume(&cons->input_pc); 500 500 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link); 501 501 502 502 event->type = CEV_KEY; 503 503 event->ev.key = *kevent; 504 504 505 505 free(kevent); 506 506 return EOK; … … 510 510 { 511 511 console_t *cons = NULL; 512 512 513 513 for (size_t i = 0; i < CONSOLE_COUNT; i++) { 514 514 if (consoles[i].dsid == (service_id_t) IPC_GET_ARG2(*icall)) { … … 517 517 } 518 518 } 519 519 520 520 if (cons == NULL) { 521 521 async_answer_0(iid, ENOENT); 522 522 return; 523 523 } 524 524 525 525 if (atomic_postinc(&cons->refcnt) == 0) 526 526 cons_set_cursor_vis(cons, true); 527 527 528 528 con_conn(iid, icall, &cons->srvs); 529 529 } … … 533 533 async_sess_t *sess; 534 534 service_id_t dsid; 535 535 536 536 errno_t rc = loc_service_get_id(svc, &dsid, 0); 537 537 if (rc != EOK) { … … 546 546 return EIO; 547 547 } 548 548 549 549 rc = input_open(sess, &input_ev_ops, NULL, &input); 550 550 if (rc != EOK) { … … 554 554 return rc; 555 555 } 556 556 557 557 return EOK; 558 558 } … … 562 562 async_sess_t *sess; 563 563 service_id_t dsid; 564 564 565 565 errno_t rc = loc_service_get_id(svc, &dsid, 0); 566 566 if (rc == EOK) { … … 573 573 } else 574 574 return NULL; 575 575 576 576 return sess; 577 577 } … … 583 583 if (rc != EOK) 584 584 return false; 585 585 586 586 /* Connect to output service */ 587 587 output_sess = output_connect(output_svc); 588 588 if (output_sess == NULL) 589 589 return false; 590 590 591 591 /* Register server */ 592 592 async_set_fallback_port_handler(client_connection, NULL); … … 597 597 return false; 598 598 } 599 599 600 600 output_get_dimensions(output_sess, &cols, &rows); 601 601 output_set_style(output_sess, STYLE_NORMAL); 602 602 603 603 console_caps_t ccaps; 604 604 output_get_caps(output_sess, &ccaps); 605 605 606 606 /* 607 607 * Inititalize consoles only if there are … … 615 615 prodcons_initialize(&consoles[i].input_pc); 616 616 consoles[i].char_remains_len = 0; 617 617 618 618 consoles[i].cols = cols; 619 619 consoles[i].rows = rows; … … 621 621 consoles[i].frontbuf = 622 622 chargrid_create(cols, rows, CHARGRID_FLAG_SHARED); 623 623 624 624 if (consoles[i].frontbuf == NULL) { 625 625 printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i); 626 626 return false; 627 627 } 628 628 629 629 consoles[i].fbid = output_frontbuf_create(output_sess, 630 630 consoles[i].frontbuf); … … 633 633 return false; 634 634 } 635 635 636 636 con_srvs_init(&consoles[i].srvs); 637 637 consoles[i].srvs.ops = &con_ops; 638 638 consoles[i].srvs.sarg = &consoles[i]; 639 639 640 640 char vc[LOC_NAME_MAXLEN + 1]; 641 641 snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i); 642 642 643 643 if (loc_service_register(vc, &consoles[i].dsid) != EOK) { 644 644 printf("%s: Unable to register device %s\n", NAME, vc); … … 646 646 } 647 647 } 648 648 649 649 input_activate(input); 650 650 } 651 651 652 652 return true; 653 653 } … … 664 664 return -1; 665 665 } 666 666 667 667 printf("%s: HelenOS Console service\n", NAME); 668 668 669 669 if (!console_srv_init(argv[1], argv[2])) 670 670 return -1; 671 671 672 672 printf("%s: Accepting connections\n", NAME); 673 673 task_retval(0); 674 674 async_manager(); 675 675 676 676 /* Never reached */ 677 677 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.