Changeset 907bb49 in mainline


Ignore:
Timestamp:
2009-03-18T22:22:31Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
266daf5a
Parents:
eada065e
Message:

Consolidate console interface.

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/init/init.c

    reada065e r907bb49  
    4545#include <malloc.h>
    4646#include <macros.h>
     47#include <console.h>
    4748#include "init.h"
    4849#include "version.h"
  • uspace/app/klog/klog.c

    reada065e r907bb49  
    4242#include <sysinfo.h>
    4343#include <io/stream.h>
     44#include <console.h>
    4445#include <errno.h>
    4546
  • uspace/app/tetris/input.c

    reada065e r907bb49  
    5959#include <async.h>
    6060#include <ipc/console.h>
     61#include <console.h>
    6162#include <kbd/kbd.h>
    6263
     
    115116again:
    116117                if (!getchar_inprog) {
    117                         cons_phone = get_console_phone();
     118                        cons_phone = console_phone_get();
    118119                        getchar_inprog = async_send_2(cons_phone,
    119120                            CONSOLE_GETKEY, 0, 0, &charcall);
  • uspace/lib/libc/generic/console.c

    reada065e r907bb49  
    11/*
     2 * Copyright (c) 2006 Josef Cejka
     3 * Copyright (c) 2006 Jakub Vana
    24 * Copyright (c) 2008 Jiri Svoboda
    35 * All rights reserved.
     
    3638#include <io/stream.h>
    3739#include <ipc/console.h>
     40#include <ipc/services.h>
    3841#include <console.h>
     42
     43static int console_phone = -1;
     44
     45void console_open(void)
     46{
     47        if (console_phone < 0) {
     48                int phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0, 0);
     49                if (phone >= 0)
     50                        console_phone = phone;
     51        }
     52}
     53
     54void console_close(void)
     55{
     56        if (console_phone >= 0) {
     57                if (ipc_hangup(console_phone) == 0) {
     58                        console_phone = -1;
     59                }
     60        }
     61}
     62
     63int console_phone_get(void)
     64{
     65        if (console_phone < 0)
     66                console_open();
     67       
     68        return console_phone;
     69}
     70
     71void console_wait(void)
     72{
     73        while (console_phone < 0)
     74                console_open();
     75}
    3976
    4077void console_clear(void)
    4178{
    42         int cons_phone = get_console_phone();
     79        int cons_phone = console_phone_get();
    4380        async_msg_0(cons_phone, CONSOLE_CLEAR);
    4481}
     
    4683void console_goto(int row, int col)
    4784{
    48         int cons_phone = get_console_phone();
     85        int cons_phone = console_phone_get();
    4986        async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
     87}
     88
     89void console_putchar(int c)
     90{
     91        int cons_phone = console_phone_get();
     92        async_msg_1(cons_phone, CONSOLE_PUTCHAR, c);
    5093}
    5194
    5295void console_flush(void)
    5396{
    54         int cons_phone = get_console_phone();
     97        int cons_phone = console_phone_get();
    5598        async_msg_0(cons_phone, CONSOLE_FLUSH);
    5699}
     
    58101int console_get_size(int *rows, int *cols)
    59102{
    60         int cons_phone = get_console_phone();
     103        int cons_phone = console_phone_get();
    61104        ipcarg_t r, c;
    62105        int rc;
     
    72115void console_set_style(int style)
    73116{
    74         int cons_phone = get_console_phone();
     117        int cons_phone = console_phone_get();
    75118        async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
    76119}
     
    78121void console_set_color(int fg_color, int bg_color, int flags)
    79122{
    80         int cons_phone = get_console_phone();
     123        int cons_phone = console_phone_get();
    81124        async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
    82125}
     
    84127void console_set_rgb_color(int fg_color, int bg_color)
    85128{
    86         int cons_phone = get_console_phone();
     129        int cons_phone = console_phone_get();
    87130        async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
    88131}
     
    90133void console_cursor_visibility(int show)
    91134{
    92         int cons_phone = get_console_phone();
     135        int cons_phone = console_phone_get();
    93136        async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
    94137}
  • uspace/lib/libc/generic/io/stream.c

    reada065e r907bb49  
    4444#include <ipc/services.h>
    4545#include <ipc/console.h>
     46#include <console.h>
    4647#include <kbd/kbd.h>
    4748#include <unistd.h>
    4849#include <async.h>
    4950#include <sys/types.h>
    50 
    51 static int console_phone = -1;
    5251
    5352ssize_t write_stderr(const void *buf, size_t count)
     
    5857ssize_t read_stdin(void *buf, size_t count)
    5958{
    60         open_console();
    61         if (console_phone >= 0) {
     59        int cons_phone = console_phone_get();
     60
     61        if (cons_phone >= 0) {
    6262                kbd_event_t ev;
    6363                int rc;
     
    8080ssize_t write_stdout(const void *buf, size_t count)
    8181{
    82         open_console();
    83         if (console_phone >= 0) {
     82        int cons_phone = console_phone_get();
     83
     84        if (cons_phone >= 0) {
    8485                int i;
    85        
     86
    8687                for (i = 0; i < count; i++)
    87                         async_msg_1(console_phone, CONSOLE_PUTCHAR,
    88                             ((const char *) buf)[i]);
    89                
     88                        console_putchar(((const char *) buf)[i]);
     89
    9090                return count;
    9191        } else
    9292                return __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, count);
    93 }
    94 
    95 void open_console(void)
    96 {
    97         if (console_phone < 0) {
    98                 int phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0, 0);
    99                 if (phone >= 0)
    100                         console_phone = phone;
    101         }
    102 }
    103 
    104 void close_console(void)
    105 {
    106         if (console_phone >= 0) {
    107                 if (ipc_hangup(console_phone) == 0) {
    108                         console_phone = -1;
    109                 }
    110         }
    11193}
    11294
     
    11698}
    11799
    118 int get_console_phone(void)
    119 {
    120         if (console_phone < 0)
    121                 console_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_CONSOLE, 0, 0);
    122        
    123         return console_phone;
    124 }
    125 
    126 void console_wait(void)
    127 {
    128         while (console_phone < 0)
    129                 get_console_phone();
    130 }
    131 
    132100/** @}
    133101 */
  • uspace/lib/libc/generic/kbd.c

    reada065e r907bb49  
    3838#include <ipc/ipc.h>
    3939#include <ipc/console.h>
     40#include <console.h>
    4041#include <async.h>
    4142
    4243int kbd_get_event(kbd_event_t *ev)
    4344{
    44         int console_phone = get_console_phone();
     45        int cons_phone = console_phone_get();
    4546        ipcarg_t r0, r1, r2, r3;
    4647        int rc;
    4748
    48         rc = async_req_0_4(console_phone, CONSOLE_GETKEY, &r0, &r1, &r2, &r3);
     49        if (cons_phone < 0)
     50                return -1;
     51
     52        rc = async_req_0_4(cons_phone, CONSOLE_GETKEY, &r0, &r1, &r2, &r3);
    4953        if (rc < 0)
    5054                return -1;
  • uspace/lib/libc/include/console.h

    reada065e r907bb49  
    3939#include <console/color.h>
    4040
     41extern void console_open(void);
     42extern void console_close(void);
     43
     44extern int console_phone_get(void);
     45extern void console_wait(void);
     46
    4147extern void console_clear(void);
    4248extern void console_goto(int, int);
     49extern void console_putchar(int);
    4350extern void console_flush(void);
     51
    4452extern int console_get_size(int *, int *);
    4553extern void console_set_style(int);
  • uspace/lib/libc/include/io/stream.h

    reada065e r907bb49  
    4040#define EMFILE -17
    4141
    42 extern void open_console(void);
    43 extern void close_console(void);
    4442extern void klog_update(void);
    4543
     
    4846extern ssize_t write_stderr(const void *, size_t);
    4947
    50 extern int get_console_phone(void);
    51 extern void console_wait(void);
    52 
    5348#endif
    5449
  • uspace/srv/loader/main.c

    reada065e r907bb49  
    5454#include <ipc/loader.h>
    5555#include <loader/pcb.h>
     56#include <console.h>
    5657#include <errno.h>
    5758#include <async.h>
     
    283284                DPRINTF("Run ELF interpreter.\n");
    284285                DPRINTF("Entry point: 0x%lx\n", interp_info.entry);
    285                 close_console();
     286                console_close();
    286287               
    287288                ipc_answer_0(rid, EOK);
     
    289290        } else {
    290291                /* Statically linked program */
    291                 close_console();
     292                console_close();
    292293                ipc_answer_0(rid, EOK);
    293294                elf_run(&prog_info, &pcb);
Note: See TracChangeset for help on using the changeset viewer.