Subversion Repositories HelenOS-historic

Rev

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

Rev Author Line No. Line
1363 vana 1
#include <io/io.h>
2
#include <io/stream.h>
3
#include <string.h>
4
#include <malloc.h>
5
#include <libc.h>
6
#include <ipc/ipc.h>
7
#include <ipc/ns.h>
8
#include <ipc/fb.h>
9
#include <ipc/services.h>
10
 
11
#define FDS 32
12
 
1366 decky 13
typedef struct stream_t {
1363 vana 14
    pwritefn_t w;
15
    preadfn_t r;
16
    void * param;
1366 decky 17
} stream_t;
1363 vana 18
 
19
 
1366 decky 20
typedef struct vfb_descriptor_t {
1363 vana 21
    int phone;
22
    int vfb;
1366 decky 23
} vfb_descriptor_t;
1363 vana 24
 
25
 
1366 decky 26
stream_t streams[FDS] = {{0, 0, 0}};
1363 vana 27
 
28
/*
29
ssize_t write_stdout(void *param, const void * buf, size_t count);
30
ssize_t write_stdout(void *param, const void * buf, size_t count)
31
{
32
    return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
33
}*/
34
 
1366 decky 35
static void vfb_send_char(vfb_descriptor_t *d, char c)
1363 vana 36
{
37
    ipcarg_t r0,r1;
1366 decky 38
    ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1);
1363 vana 39
}
40
 
1366 decky 41
static ssize_t write_vfb(void *param, const void *buf, size_t count)
1363 vana 42
{
43
    int i;
1366 decky 44
    for (i = 0; i < count; i++)
45
        vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]);
1363 vana 46
 
47
    return count;
48
    //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
49
}
50
 
51
 
1366 decky 52
static ssize_t write_stderr(void *param, const void *buf, size_t count)
1363 vana 53
{
54
    return count;
55
    //return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
56
}
57
 
58
 
59
stream_t open_vfb(void)
60
{
61
    stream_t stream;
62
    vfb_descriptor_t *vfb;
63
    int phoneid;
64
    int res;
65
    ipcarg_t vfb_no;
66
 
1366 decky 67
    while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
1363 vana 68
        volatile int a;
1366 decky 69
 
70
        for (a = 0; a < 1048576; a++);
1363 vana 71
    }
72
 
1366 decky 73
    ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no);
74
    vfb = malloc(sizeof(vfb_descriptor_t));
1363 vana 75
 
1366 decky 76
    vfb->phone = phoneid;
77
    vfb->vfb = vfb_no;
1363 vana 78
 
1366 decky 79
    stream.w = write_vfb;
80
    stream.param = vfb;
1363 vana 81
    return stream;
82
}
83
 
84
 
1366 decky 85
fd_t open(const char *fname, int flags)
1363 vana 86
{
1366 decky 87
    int c = 0;
88
 
89
    while (((streams[c].w) || (streams[c].r)) && (c < FDS))
90
        c++;
91
    if (c == FDS)
92
        return EMFILE;
93
 
94
    if (!strcmp(fname, "stdin")) {
95
        streams[c].r = (preadfn_t)1;
1363 vana 96
        return c;
97
    }
98
 
1366 decky 99
    if (!strcmp(fname, "stdout")) {
100
        //streams[c].w = write_stdout;
1363 vana 101
        //return c;
1366 decky 102
        streams[c] = open_vfb();
1363 vana 103
        return c;
104
    }
105
 
1366 decky 106
    if (!strcmp(fname, "stderr")) {
107
        streams[c].w = write_stderr;
1363 vana 108
        return c;
109
    }
110
}
111
 
112
 
1366 decky 113
ssize_t write(int fd, const void *buf, size_t count)
1363 vana 114
{
1366 decky 115
    if (fd < FDS)
116
        return streams[fd].w(streams[fd].param, buf, count);
117
 
1363 vana 118
    return 0;
119
}