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