Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4337 → Rev 4338

/branches/dynload/uspace/srv/console/console.c
40,7 → 40,7
#include <ipc/services.h>
#include <errno.h>
#include <key_buffer.h>
#include <console.h>
#include <ipc/console.h>
#include <unistd.h>
#include <async.h>
#include <libadt/fifo.h>
47,7 → 47,9
#include <screenbuffer.h>
#include <sys/mman.h>
#include <stdio.h>
#include <sysinfo.h>
 
#include "console.h"
#include "gcons.h"
 
#define MAX_KEYREQUESTS_BUFFERED 32
57,6 → 59,7
/** Index of currently used virtual console.
*/
int active_console = 0;
int prev_console = 0;
 
/** Information about framebuffer
*/
121,17 → 124,39
async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
}
 
static void set_style(style_t *style)
static void set_style(int style)
{
async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color,
style->bg_color);
async_msg_1(fb_info.phone, FB_SET_STYLE, style);
}
 
static void set_style_col(int fgcolor, int bgcolor)
static void set_color(int fgcolor, int bgcolor, int flags)
{
async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor);
async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
}
 
static void set_rgb_color(int fgcolor, int bgcolor)
{
async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
}
 
static void set_attrs(attrs_t *attrs)
{
switch (attrs->t) {
case at_style:
set_style(attrs->a.s.style);
break;
 
case at_idx:
set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
attrs->a.i.flags);
break;
 
case at_rgb:
set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
break;
}
}
 
static void prtchr(char c, int row, int col)
{
async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
195,7 → 220,7
connection_t *conn;
int i, j, rc;
keyfield_t *field;
style_t *style;
attrs_t *attrs;
if (newcons == active_console)
return;
206,9 → 231,10
gcons_in_kernel();
async_serialize_end();
if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE))
if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
prev_console = active_console;
active_console = KERNEL_CONSOLE;
else
} else
newcons = active_console;
}
222,7 → 248,7
gcons_change_console(newcons);
conn = &connections[active_console];
set_style(&conn->screenbuffer.style);
set_attrs(&conn->screenbuffer.attrs);
curs_visibility(false);
if (interbuffer) {
for (i = 0; i < conn->screenbuffer.size_x; i++)
234,25 → 260,25
*get_field_at(&conn->screenbuffer, i, j);
}
/* This call can preempt, but we are already at the end */
rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);
rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);
}
if ((!interbuffer) || (rc != 0)) {
set_style(&conn->screenbuffer.style);
set_attrs(&conn->screenbuffer.attrs);
clrscr();
style = &conn->screenbuffer.style;
attrs = &conn->screenbuffer.attrs;
for (j = 0; j < conn->screenbuffer.size_y; j++)
for (j = 0; j < conn->screenbuffer.size_y; j++)
for (i = 0; i < conn->screenbuffer.size_x; i++) {
field = get_field_at(&conn->screenbuffer, i, j);
if (!style_same(*style, field->style))
set_style(&field->style);
style = &field->style;
if (!attrs_same(*attrs, field->attrs))
set_attrs(&field->attrs);
attrs = &field->attrs;
if ((field->character == ' ') &&
(style_same(field->style,
conn->screenbuffer.style)))
(attrs_same(field->attrs,
conn->screenbuffer.attrs)))
continue;
 
prtchr(field->character, j, i);
}
}
337,9 → 363,9
ipc_callid_t callid;
ipc_call_t call;
int consnum;
ipcarg_t arg1, arg2;
ipcarg_t arg1, arg2, arg3;
connection_t *conn;
 
if ((consnum = find_free_connection()) == -1) {
ipc_answer_0(iid, ELIMIT);
return;
354,12 → 380,12
/* Accept the connection */
ipc_answer_0(iid, EOK);
 
while (1) {
async_serialize_end();
callid = async_get_call(&call);
async_serialize_start();
 
arg1 = 0;
arg2 = 0;
switch (IPC_GET_METHOD(call)) {
367,7 → 393,7
gcons_notify_disconnect(consnum);
/* Answer all pending requests */
while (conn->keyrequest_counter > 0) {
while (conn->keyrequest_counter > 0) {
conn->keyrequest_counter--;
ipc_answer_0(fifo_pop(conn->keyrequests),
ENOENT);
405,11 → 431,26
break;
case CONSOLE_SET_STYLE:
arg1 = IPC_GET_ARG1(call);
screenbuffer_set_style(&conn->screenbuffer, arg1);
if (consnum == active_console)
set_style(arg1);
break;
case CONSOLE_SET_COLOR:
arg1 = IPC_GET_ARG1(call);
arg2 = IPC_GET_ARG2(call);
screenbuffer_set_style(&conn->screenbuffer, arg1,
arg3 = IPC_GET_ARG3(call);
screenbuffer_set_color(&conn->screenbuffer, arg1,
arg2, arg3);
if (consnum == active_console)
set_color(arg1, arg2, arg3);
break;
case CONSOLE_SET_RGB_COLOR:
arg1 = IPC_GET_ARG1(call);
arg2 = IPC_GET_ARG2(call);
screenbuffer_set_rgb_color(&conn->screenbuffer, arg1,
arg2);
if (consnum == active_console)
set_style_col(arg1, arg2);
set_rgb_color(arg1, arg2);
break;
case CONSOLE_CURSOR_VISIBILITY:
arg1 = IPC_GET_ARG1(call);
442,6 → 483,11
}
}
 
static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
{
change_console(prev_console);
}
 
int main(int argc, char *argv[])
{
printf(NAME ": HelenOS Console service\n");
449,11 → 495,11
ipcarg_t phonehash;
int kbd_phone;
int i;
 
async_set_client_connection(client_connection);
/* Connect to keyboard driver */
 
kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
while (kbd_phone < 0) {
usleep(10000);
478,7 → 524,7
async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows,
&fb_info.cols);
set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
clrscr();
/* Init virtual consoles */
510,20 → 556,30
interbuffer = NULL;
}
}
 
curs_goto(0, 0);
curs_visibility(
connections[active_console].screenbuffer.is_cursor_visible);
 
/* Register at NS */
if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
return -1;
/* Receive kernel notifications */
if (sysinfo_value("kconsole.present")) {
int devno = sysinfo_value("kconsole.devno");
int inr = sysinfo_value("kconsole.inr");
if (ipc_register_irq(inr, devno, 0, NULL) != EOK)
printf(NAME ": Error registering kconsole notifications\n");
async_set_interrupt_received(interrupt_received);
}
// FIXME: avoid connectiong to itself, keep using klog
// printf(NAME ": Accepting connections\n");
async_manager();
 
return 0;
return 0;
}
/** @}