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