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