Subversion Repositories HelenOS-historic

Rev

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