Subversion Repositories HelenOS

Rev

Rev 4154 | Rev 4164 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3767 svoboda 1
/*
4154 svoboda 2
 * Copyright (c) 2006 Josef Cejka
3
 * Copyright (c) 2006 Jakub Vana
3767 svoboda 4
 * Copyright (c) 2008 Jiri Svoboda
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright
12
 *   notice, this list of conditions and the following disclaimer.
13
 * - Redistributions in binary form must reproduce the above copyright
14
 *   notice, this list of conditions and the following disclaimer in the
15
 *   documentation and/or other materials provided with the distribution.
16
 * - The name of the author may not be used to endorse or promote products
17
 *   derived from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
 
31
/** @addtogroup libc
32
 * @{
33
 */
34
/** @file
35
 */
36
 
37
#include <async.h>
38
#include <io/stream.h>
39
#include <ipc/console.h>
4154 svoboda 40
#include <ipc/services.h>
3767 svoboda 41
#include <console.h>
42
 
4154 svoboda 43
static int console_phone = -1;
44
 
4160 jermar 45
void console_open(bool blocking)
4154 svoboda 46
{
47
    if (console_phone < 0) {
4160 jermar 48
        int phone;
49
        if (blocking) {
50
            phone = ipc_connect_me_to_blocking(PHONE_NS,
51
                SERVICE_CONSOLE, 0, 0);
52
        } else {
53
            phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0,
54
                0);
55
        }
4154 svoboda 56
        if (phone >= 0)
57
            console_phone = phone;
58
    }
59
}
60
 
61
void console_close(void)
62
{
63
    if (console_phone >= 0) {
64
        if (ipc_hangup(console_phone) == 0) {
65
            console_phone = -1;
66
        }
67
    }
68
}
69
 
4160 jermar 70
int console_phone_get(bool blocking)
4154 svoboda 71
{
72
    if (console_phone < 0)
4160 jermar 73
        console_open(blocking);
4154 svoboda 74
 
75
    return console_phone;
76
}
77
 
78
void console_wait(void)
79
{
80
    while (console_phone < 0)
4160 jermar 81
        console_open(true);
4154 svoboda 82
}
83
 
3768 svoboda 84
void console_clear(void)
85
{
4160 jermar 86
    int cons_phone = console_phone_get(true);
3768 svoboda 87
    async_msg_0(cons_phone, CONSOLE_CLEAR);
88
}
89
 
90
void console_goto(int row, int col)
91
{
4160 jermar 92
    int cons_phone = console_phone_get(true);
3768 svoboda 93
    async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
94
}
95
 
4154 svoboda 96
void console_putchar(int c)
97
{
4160 jermar 98
    int cons_phone = console_phone_get(true);
4154 svoboda 99
    async_msg_1(cons_phone, CONSOLE_PUTCHAR, c);
100
}
101
 
3768 svoboda 102
void console_flush(void)
103
{
4160 jermar 104
    int cons_phone = console_phone_get(true);
3768 svoboda 105
    async_msg_0(cons_phone, CONSOLE_FLUSH);
106
}
107
 
108
int console_get_size(int *rows, int *cols)
109
{
4160 jermar 110
    int cons_phone = console_phone_get(true);
3768 svoboda 111
    ipcarg_t r, c;
112
    int rc;
113
 
114
    rc = async_req_0_2(cons_phone, CONSOLE_GETSIZE, &r, &c);
115
 
116
    *rows = (int) r;
117
    *cols = (int) c;
118
 
119
    return rc;
120
}
121
 
3767 svoboda 122
void console_set_style(int style)
123
{
4160 jermar 124
    int cons_phone = console_phone_get(true);
3767 svoboda 125
    async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
126
}
127
 
128
void console_set_color(int fg_color, int bg_color, int flags)
129
{
4160 jermar 130
    int cons_phone = console_phone_get(true);
3767 svoboda 131
    async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
132
}
133
 
134
void console_set_rgb_color(int fg_color, int bg_color)
135
{
4160 jermar 136
    int cons_phone = console_phone_get(true);
3767 svoboda 137
    async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
138
}
139
 
3768 svoboda 140
void console_cursor_visibility(int show)
141
{
4160 jermar 142
    int cons_phone = console_phone_get(true);
3768 svoboda 143
    async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
144
}
145
 
3767 svoboda 146
/** @}
147
 */