Changeset d2cc7e1 in mainline for uspace/lib/libc/generic/console.c
- Timestamp:
- 2009-03-21T11:26:31Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0a5116db
- Parents:
- 5b8c75a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/console.c
r5b8c75a rd2cc7e1 39 39 #include <ipc/console.h> 40 40 #include <ipc/services.h> 41 #include <errno.h> 42 #include <string.h> 41 43 #include <console.h> 42 44 43 45 static int console_phone = -1; 46 47 /** Size of cbuffer. */ 48 #define CBUFFER_SIZE 256 49 50 /** Buffer for writing characters to the console. */ 51 static char cbuffer[CBUFFER_SIZE]; 52 53 /** Pointer to end of cbuffer. */ 54 static char *cbuffer_end = cbuffer + CBUFFER_SIZE; 55 56 /** Pointer to first available field in cbuffer. */ 57 static char *cbp = cbuffer; 58 59 static ssize_t cons_write(const char *buf, size_t nbyte); 60 static void cons_putchar(int c); 61 62 static void cbuffer_flush(void); 63 static void cbuffer_drain(void); 64 static void cbuffer_putc(int c); 65 44 66 45 67 void console_open(bool blocking) … … 85 107 { 86 108 int cons_phone = console_phone_get(true); 109 110 cbuffer_drain(); 87 111 async_msg_0(cons_phone, CONSOLE_CLEAR); 88 112 } … … 91 115 { 92 116 int cons_phone = console_phone_get(true); 117 118 cbuffer_flush(); 93 119 async_msg_2(cons_phone, CONSOLE_GOTO, row, col); 94 120 } … … 96 122 void console_putchar(int c) 97 123 { 124 cbuffer_putc(c); 125 } 126 127 /** Write all data from output buffer to the console. */ 128 static void cbuffer_flush(void) 129 { 130 int rc; 131 int len; 132 133 len = cbp - cbuffer; 134 135 while (len > 0) { 136 rc = cons_write(cbuffer, cbp - cbuffer); 137 if (rc < 0) 138 return; 139 140 len -= rc; 141 } 142 143 cbp = cbuffer; 144 } 145 146 /** Drop all data in console output buffer. */ 147 static void cbuffer_drain(void) 148 { 149 cbp = cbuffer; 150 } 151 152 /** Write one character to the output buffer. */ 153 static inline void cbuffer_putc(int c) 154 { 155 if (cbp == cbuffer_end) 156 cbuffer_flush(); 157 158 *cbp++ = c; 159 160 if (c == '\n') 161 cbuffer_flush(); 162 } 163 164 /** Write one character to the console via IPC. */ 165 static void cons_putchar(int c) 166 { 98 167 int cons_phone = console_phone_get(true); 99 168 async_msg_1(cons_phone, CONSOLE_PUTCHAR, c); 100 169 } 101 170 171 /** Write characters to the console via IPC. */ 172 static ssize_t cons_write(const char *buf, size_t nbyte) 173 { 174 int cons_phone = console_phone_get(true); 175 ipcarg_t rc; 176 ipc_call_t answer; 177 aid_t req; 178 179 async_serialize_start(); 180 181 req = async_send_0(cons_phone, CONSOLE_WRITE, &answer); 182 rc = ipc_data_write_start(cons_phone, (void *) buf, nbyte); 183 184 if (rc != EOK) { 185 async_wait_for(req, NULL); 186 async_serialize_end(); 187 return (ssize_t) rc; 188 } 189 190 async_wait_for(req, &rc); 191 async_serialize_end(); 192 193 if (rc == EOK) 194 return (ssize_t) IPC_GET_ARG1(answer); 195 else 196 return -1; 197 } 198 199 /** Write characters to the console. */ 200 ssize_t console_write(const char *buf, size_t nbyte) 201 { 202 size_t left; 203 204 left = nbyte; 205 206 while (left > 0) { 207 cbuffer_putc(*buf++); 208 --left; 209 } 210 211 return nbyte; 212 } 213 214 /** Write a NULL-terminated string to the console. */ 215 void console_putstr(const char *s) 216 { 217 size_t len; 218 ssize_t rc; 219 220 len = strlen(s); 221 while (len > 0) { 222 rc = console_write(s, len); 223 if (rc < 0) 224 return; /* Error */ 225 s += rc; 226 len -= rc; 227 } 228 } 229 230 /** Flush all output to the console. */ 102 231 void console_flush(void) 103 232 { 104 int cons_phone = console_phone_get(true); 233 int cons_phone = console_phone_get(false); 234 235 cbuffer_flush(); 105 236 async_msg_0(cons_phone, CONSOLE_FLUSH); 106 237 } … … 123 254 { 124 255 int cons_phone = console_phone_get(true); 256 257 cbuffer_flush(); 125 258 async_msg_1(cons_phone, CONSOLE_SET_STYLE, style); 126 259 } … … 129 262 { 130 263 int cons_phone = console_phone_get(true); 264 265 cbuffer_flush(); 131 266 async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags); 132 267 } … … 135 270 { 136 271 int cons_phone = console_phone_get(true); 272 273 cbuffer_flush(); 137 274 async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color); 138 275 } … … 141 278 { 142 279 int cons_phone = console_phone_get(true); 280 281 cbuffer_flush(); 143 282 async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0); 144 283 }
Note:
See TracChangeset
for help on using the changeset viewer.