Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1451 → Rev 1450

/uspace/trunk/libc/generic/io/stream.c
7,7 → 7,6
#include <ipc/ns.h>
#include <ipc/fb.h>
#include <ipc/services.h>
#include <console.h>
 
#define FDS 32
 
17,8 → 16,13
void * param;
} stream_t;
 
int console_phone = -1;
 
typedef struct vfb_descriptor_t {
int phone;
int vfb;
} vfb_descriptor_t;
 
 
stream_t streams[FDS] = {{0, 0, 0}};
 
/*
28,27 → 32,17
return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}*/
 
static ssize_t write_stderr(void *param, const void *buf, size_t count)
static void vfb_send_char(vfb_descriptor_t *d, char c)
{
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
static char read_stdin(void)
{
ipcarg_t r0,r1;
ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1);
return r0;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1);
}
static ssize_t write_stdout(void *param, const void *buf, size_t count)
static ssize_t write_vfb(void *param, const void *buf, size_t count)
{
int i;
ipcarg_t r0,r1;
 
for (i = 0; i < count; i++)
ipc_call_sync_2(console_phone, CONSOLE_PUTCHAR, 0, ((const char *)buf)[i], &r0, &r1);
vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]);
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
55,42 → 49,39
}
 
 
static ssize_t write_stderr(void *param, const void *buf, size_t count)
{
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
static stream_t open_stdin(void)
 
stream_t open_vfb(void)
{
stream_t stream;
vfb_descriptor_t *vfb;
int phoneid;
int res;
ipcarg_t vfb_no;
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
}
while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
}
stream.r = read_stdin;
stream.param = 0;
return stream;
}
 
static stream_t open_stdout(void)
{
stream_t stream;
int res;
ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no);
vfb = malloc(sizeof(vfb_descriptor_t));
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
}
}
vfb->phone = phoneid;
vfb->vfb = vfb_no;
stream.w = write_stdout;
stream.param = 0;
stream.w = write_vfb;
stream.param = vfb;
return stream;
}
 
 
fd_t open(const char *fname, int flags)
{
int c = 0;
101,7 → 92,7
return EMFILE;
if (!strcmp(fname, "stdin")) {
streams[c] = open_stdin();
streams[c].r = (preadfn_t)1;
return c;
}
108,7 → 99,7
if (!strcmp(fname, "stdout")) {
//streams[c].w = write_stdout;
//return c;
streams[c] = open_stdout();
streams[c] = open_vfb();
return c;
}