source: mainline/uspace/lib/libc/generic/console.c@ 416abec

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 416abec was 416abec, checked in by Jakub Jermar <jakub@…>, 16 years ago

Improve the console library functions.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2006 Josef Cejka
3 * Copyright (c) 2006 Jakub Vana
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>
40#include <ipc/services.h>
41#include <console.h>
42
43static int console_phone = -1;
44
45void console_open(bool blocking)
46{
47 if (console_phone < 0) {
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 }
56 if (phone >= 0)
57 console_phone = phone;
58 }
59}
60
61void console_close(void)
62{
63 if (console_phone >= 0) {
64 if (ipc_hangup(console_phone) == 0) {
65 console_phone = -1;
66 }
67 }
68}
69
70int console_phone_get(bool blocking)
71{
72 if (console_phone < 0)
73 console_open(blocking);
74
75 return console_phone;
76}
77
78void console_wait(void)
79{
80 while (console_phone < 0)
81 console_open(true);
82}
83
84void console_clear(void)
85{
86 int cons_phone = console_phone_get(true);
87 async_msg_0(cons_phone, CONSOLE_CLEAR);
88}
89
90void console_goto(int row, int col)
91{
92 int cons_phone = console_phone_get(true);
93 async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
94}
95
96void console_putchar(int c)
97{
98 int cons_phone = console_phone_get(true);
99 async_msg_1(cons_phone, CONSOLE_PUTCHAR, c);
100}
101
102void console_flush(void)
103{
104 int cons_phone = console_phone_get(true);
105 async_msg_0(cons_phone, CONSOLE_FLUSH);
106}
107
108int console_get_size(int *rows, int *cols)
109{
110 int cons_phone = console_phone_get(true);
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
122void console_set_style(int style)
123{
124 int cons_phone = console_phone_get(true);
125 async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
126}
127
128void console_set_color(int fg_color, int bg_color, int flags)
129{
130 int cons_phone = console_phone_get(true);
131 async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
132}
133
134void console_set_rgb_color(int fg_color, int bg_color)
135{
136 int cons_phone = console_phone_get(true);
137 async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
138}
139
140void console_cursor_visibility(int show)
141{
142 int cons_phone = console_phone_get(true);
143 async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
144}
145
146/** @}
147 */
Note: See TracBrowser for help on using the repository browser.