1 USING: accessors alien.c-types classes.struct combinators
\r
2 continuations io kernel libc literals locals sequences
\r
3 specialized-arrays windows.com memoize
\r
4 windows.com.wrapper windows.kernel32 windows.ole32
\r
8 SPECIALIZED-ARRAY: uchar
\r
12 : with-hresult ( quot: ( -- result ) -- result )
\r
13 [ drop E_FAIL ] recover ; inline
\r
15 :: IStream-read ( stream pv cb out-read -- hresult )
\r
17 cb stream stream-read :> buf
\r
20 out-read [ bytes out-read 0 ULONG set-alien-value ] when
\r
22 cb bytes = [ S_OK ] [ S_FALSE ] if
\r
23 ] with-hresult ; inline
\r
25 :: IStream-write ( stream pv cb out-written -- hresult )
\r
27 pv cb <direct-uchar-array> stream stream-write
\r
28 out-written [ cb out-written 0 ULONG set-alien-value ] when
\r
30 ] with-hresult ; inline
\r
32 : origin>seek-type ( origin -- seek-type )
\r
34 { $ STREAM_SEEK_SET [ seek-absolute ] }
\r
35 { $ STREAM_SEEK_CUR [ seek-relative ] }
\r
36 { $ STREAM_SEEK_END [ seek-end ] }
\r
39 :: IStream-seek ( stream move origin new-position -- hresult )
\r
41 move origin origin>seek-type stream stream-seek
\r
43 stream stream-tell new-position 0 ULARGE_INTEGER set-alien-value
\r
46 ] with-hresult ; inline
\r
48 :: IStream-set-size ( stream new-size -- hresult )
\r
49 STG_E_INVALIDFUNCTION ;
\r
51 :: IStream-copy-to ( stream other-stream cb out-read out-written -- hresult )
\r
53 cb stream stream-read :> buf
\r
55 out-read [ bytes out-read 0 ULONG set-alien-value ] when
\r
57 other-stream buf bytes out-written IStream::Write
\r
58 ] with-hresult ; inline
\r
60 :: IStream-commit ( stream flags -- hresult )
\r
61 stream stream-flush S_OK ;
\r
63 :: IStream-revert ( stream -- hresult )
\r
64 STG_E_INVALIDFUNCTION ;
\r
66 :: IStream-lock-region ( stream offset cb lock-type -- hresult )
\r
67 STG_E_INVALIDFUNCTION ;
\r
69 :: IStream-unlock-region ( stream offset cb lock-type -- hresult )
\r
70 STG_E_INVALIDFUNCTION ;
\r
72 FROM: io.ports => tell-handle ;
\r
73 :: stream-size ( stream -- size )
\r
74 stream stream-tell :> old-pos
\r
75 0 seek-end stream stream-seek
\r
76 stream handle>> tell-handle :> size
\r
77 old-pos seek-absolute stream stream-seek
\r
80 :: IStream-stat ( stream out-stat stat-flag -- hresult )
\r
85 stream stream-size >>cbSize
\r
86 FILETIME <struct> >>mtime
\r
87 FILETIME <struct> >>ctime
\r
88 FILETIME <struct> >>atime
\r
89 STGM_READWRITE >>grfMode
\r
90 0 >>grfLocksSupported
\r
98 :: IStream-clone ( out-clone-stream -- hresult )
\r
99 f out-clone-stream 0 void* set-alien-value
\r
100 STG_E_INVALIDFUNCTION ;
\r
102 USE: tools.annotations
\r
103 : watch-istream-callbacks ( -- )
\r
104 \ IStream-read watch
\r
105 \ IStream-write watch
\r
106 \ IStream-seek watch
\r
107 \ IStream-set-size watch
\r
108 \ IStream-copy-to watch
\r
109 \ IStream-commit watch
\r
110 \ IStream-revert watch
\r
111 \ IStream-lock-region watch
\r
112 \ IStream-unlock-region watch
\r
113 \ IStream-stat watch
\r
114 \ IStream-clone watch ;
\r
116 CONSTANT: stream-wrapper
\r
123 [ IStream-set-size ]
\r
124 [ IStream-copy-to ]
\r
127 [ IStream-lock-region ]
\r
128 [ IStream-unlock-region ]
\r
137 : stream>IStream ( stream -- IStream )
\r
138 stream-wrapper com-wrap ;
\r