259 |
return 1; |
return 1; |
260 |
} |
} |
261 |
|
|
262 |
|
struct mutex global_lock; |
263 |
static vcons_t active_vcons = NULL; |
static vcons_t active_vcons = NULL; |
264 |
|
|
265 |
error_t |
error_t |
266 |
cons_vcons_activate (vcons_t vcons) |
console_switch (int id, int delta) |
267 |
{ |
{ |
268 |
error_t err; |
error_t err = 0; |
269 |
|
int active_id; |
270 |
|
cons_t cons; |
271 |
|
vcons_t vcons; |
272 |
|
|
273 |
|
mutex_lock (&global_lock); |
274 |
|
if (!active_vcons) |
275 |
|
{ |
276 |
|
mutex_unlock (&global_lock); |
277 |
|
return 0; |
278 |
|
} |
279 |
|
cons = active_vcons->cons; |
280 |
|
active_id = active_vcons->id; |
281 |
|
|
282 |
assert (vcons); |
/* We must give up our global lock before we can call back into |
283 |
assert (vcons != active_vcons); |
libcons. This is because cons_switch will lock CONS, and as |
284 |
|
other functions in libcons lock CONS while calling back into our |
285 |
|
functions which take the global lock (like cons_vcons_add), we |
286 |
|
would deadlock. Because of this, we can not refer to our active |
287 |
|
console directly, but we must refer to it by name (ID). XXX |
288 |
|
Likewise, we can not really refer to CONS directly, but the |
289 |
|
current implementation guarantees an eternal life span for |
290 |
|
CONS. */ |
291 |
|
mutex_unlock (&global_lock); |
292 |
|
err = cons_switch (cons, active_id, id, delta, &vcons); |
293 |
|
if (!err) |
294 |
|
{ |
295 |
|
mutex_lock (&global_lock); |
296 |
|
if (active_vcons != vcons) |
297 |
|
{ |
298 |
|
cons_vcons_close (active_vcons); |
299 |
|
active_vcons = vcons; |
300 |
|
} |
301 |
|
mutex_unlock (&vcons->lock); |
302 |
|
mutex_unlock (&global_lock); |
303 |
|
} |
304 |
|
return err; |
305 |
|
} |
306 |
|
|
307 |
err = cons_vcons_open (vcons); |
void |
308 |
if (err) |
cons_vcons_add (cons_t cons, vcons_list_t vcons_entry) |
309 |
return err; |
{ |
310 |
|
error_t err = 0; |
311 |
if (active_vcons) |
mutex_lock (&global_lock); |
312 |
cons_vcons_close (active_vcons); |
if (!active_vcons) |
313 |
active_vcons = vcons; |
{ |
314 |
return 0; |
vcons_t vcons; |
315 |
|
err = cons_vcons_open (cons, vcons_entry, &vcons); |
316 |
|
if (!err) |
317 |
|
{ |
318 |
|
vcons_entry->vcons = vcons; |
319 |
|
active_vcons = vcons; |
320 |
|
mutex_unlock (&vcons->lock); |
321 |
|
} |
322 |
|
} |
323 |
|
mutex_unlock (&global_lock); |
324 |
} |
} |
325 |
|
|
326 |
any_t |
any_t |
375 |
case '9': |
case '9': |
376 |
/* Avoid a dead lock. */ |
/* Avoid a dead lock. */ |
377 |
mutex_unlock (&ncurses_lock); |
mutex_unlock (&ncurses_lock); |
378 |
/* XXX: We ignore any error here. */ |
console_switch (1 + (ret - '1'), 0); |
|
cons_switch (active_vcons->cons, 1 + (ret - '1'), 0); |
|
379 |
mutex_lock (&ncurses_lock); |
mutex_lock (&ncurses_lock); |
380 |
break; |
break; |
381 |
default: |
default: |
416 |
mutex_unlock (&ncurses_lock); |
mutex_unlock (&ncurses_lock); |
417 |
if (size) |
if (size) |
418 |
{ |
{ |
419 |
|
mutex_lock (&global_lock); |
420 |
if (active_vcons) |
if (active_vcons) |
421 |
{ |
{ |
|
mutex_lock (&active_vcons->lock); |
|
422 |
do |
do |
423 |
{ |
{ |
424 |
ret = write (active_vcons->input, buf, size); |
ret = write (active_vcons->input, buf, size); |
429 |
} |
} |
430 |
} |
} |
431 |
while (size && (ret != -1 || errno == EINTR)); |
while (size && (ret != -1 || errno == EINTR)); |
|
mutex_unlock (&active_vcons->lock); |
|
432 |
} |
} |
433 |
|
mutex_unlock (&global_lock); |
434 |
} |
} |
435 |
} |
} |
436 |
} |
} |
509 |
void |
void |
510 |
cons_vcons_update (vcons_t vcons) |
cons_vcons_update (vcons_t vcons) |
511 |
{ |
{ |
512 |
if (vcons != active_vcons) |
mutex_lock (&global_lock); |
513 |
return; |
if (vcons == active_vcons) |
514 |
refresh (); |
refresh (); |
515 |
|
mutex_unlock (&global_lock); |
516 |
} |
} |
517 |
|
|
518 |
void |
void |
519 |
cons_vcons_set_cursor_pos (vcons_t vcons, uint32_t col, uint32_t row) |
cons_vcons_set_cursor_pos (vcons_t vcons, uint32_t col, uint32_t row) |
520 |
{ |
{ |
521 |
if (vcons != active_vcons) |
mutex_lock (&global_lock); |
522 |
return; |
if (vcons == active_vcons) |
523 |
mutex_lock (&ncurses_lock); |
{ |
524 |
move (row, col); |
mutex_lock (&ncurses_lock); |
525 |
mutex_unlock (&ncurses_lock); |
move (row, col); |
526 |
|
mutex_unlock (&ncurses_lock); |
527 |
|
} |
528 |
|
mutex_unlock (&global_lock); |
529 |
} |
} |
530 |
|
|
531 |
void |
void |
532 |
cons_vcons_set_cursor_status (vcons_t vcons, uint32_t status) |
cons_vcons_set_cursor_status (vcons_t vcons, uint32_t status) |
533 |
{ |
{ |
534 |
if (vcons != active_vcons) |
mutex_lock (&global_lock); |
535 |
return; |
if (vcons == active_vcons) |
536 |
mutex_lock (&ncurses_lock); |
{ |
537 |
curs_set (status ? (status == 1 ? 1 : 2) : 0); |
mutex_lock (&ncurses_lock); |
538 |
mutex_unlock (&ncurses_lock); |
curs_set (status ? (status == 1 ? 1 : 2) : 0); |
539 |
|
mutex_unlock (&ncurses_lock); |
540 |
|
} |
541 |
|
mutex_unlock (&global_lock); |
542 |
} |
} |
543 |
|
|
544 |
void |
void |
545 |
cons_vcons_scroll (vcons_t vcons, int delta) |
cons_vcons_scroll (vcons_t vcons, int delta) |
546 |
{ |
{ |
547 |
assert (delta >= 0); |
assert (delta >= 0); |
|
if (vcons != active_vcons) |
|
|
return; |
|
548 |
|
|
549 |
mutex_lock (&ncurses_lock); |
mutex_lock (&global_lock); |
550 |
idlok (stdscr, TRUE); |
if (vcons == active_vcons) |
551 |
scrollok (stdscr, TRUE); |
{ |
552 |
scrl (delta); |
mutex_lock (&ncurses_lock); |
553 |
idlok (stdscr, FALSE); |
idlok (stdscr, TRUE); |
554 |
scrollok (stdscr, FALSE); |
scrollok (stdscr, TRUE); |
555 |
mutex_unlock (&ncurses_lock); |
scrl (delta); |
556 |
|
idlok (stdscr, FALSE); |
557 |
|
scrollok (stdscr, FALSE); |
558 |
|
mutex_unlock (&ncurses_lock); |
559 |
|
} |
560 |
|
mutex_unlock (&global_lock); |
561 |
} |
} |
562 |
|
|
563 |
void |
void |
567 |
int x; |
int x; |
568 |
int y; |
int y; |
569 |
|
|
570 |
if (vcons != active_vcons) |
mutex_lock (&global_lock); |
571 |
return; |
if (vcons == active_vcons) |
572 |
|
{ |
573 |
mutex_lock (&ncurses_lock); |
mutex_lock (&ncurses_lock); |
574 |
getyx (stdscr, y, x); |
getyx (stdscr, y, x); |
575 |
mvwputsn (str, length, col, row); |
mvwputsn (str, length, col, row); |
576 |
wmove (stdscr, y, x); |
wmove (stdscr, y, x); |
577 |
mutex_unlock (&ncurses_lock); |
mutex_unlock (&ncurses_lock); |
578 |
|
} |
579 |
|
mutex_unlock (&global_lock); |
580 |
} |
} |
581 |
|
|
582 |
void |
void |
583 |
cons_vcons_beep (vcons_t vcons) |
cons_vcons_beep (vcons_t vcons) |
584 |
{ |
{ |
585 |
if (vcons != active_vcons) |
mutex_lock (&global_lock); |
586 |
return; |
if (vcons == active_vcons) |
587 |
|
{ |
588 |
mutex_lock (&ncurses_lock); |
mutex_lock (&ncurses_lock); |
589 |
beep (); |
beep (); |
590 |
mutex_unlock (&ncurses_lock); |
mutex_unlock (&ncurses_lock); |
591 |
|
} |
592 |
|
mutex_unlock (&global_lock); |
593 |
} |
} |
594 |
|
|
595 |
void |
void |
596 |
cons_vcons_flash (vcons_t vcons) |
cons_vcons_flash (vcons_t vcons) |
597 |
{ |
{ |
598 |
if (vcons != active_vcons) |
mutex_lock (&global_lock); |
599 |
return; |
if (vcons == active_vcons) |
600 |
|
{ |
601 |
mutex_lock (&ncurses_lock); |
mutex_lock (&ncurses_lock); |
602 |
flash (); |
flash (); |
603 |
mutex_unlock (&ncurses_lock); |
mutex_unlock (&ncurses_lock); |
604 |
|
} |
605 |
|
mutex_unlock (&global_lock); |
606 |
} |
} |
607 |
|
|
608 |
|
|
616 |
argp_parse (&cons_startup_argp, argc, argv, 0, 0, 0); |
argp_parse (&cons_startup_argp, argc, argv, 0, 0, 0); |
617 |
|
|
618 |
mutex_init (&ncurses_lock); |
mutex_init (&ncurses_lock); |
619 |
|
mutex_init (&global_lock); |
620 |
|
|
621 |
initscr (); |
initscr (); |
622 |
start_color (); |
start_color (); |