convert line ends
[canaan.git] / prj / tech / libsrc / compapis / arqapi.h
blob742ac9951d129a699eb1d8687850e6608a465502
1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/compapis/RCS/arqapi.h $
3 // $Author: TOML $
4 // $Date: 1997/09/18 13:04:50 $
5 // $Revision: 1.12 $
6 //
8 #ifndef __ARQAPI_H
9 #define __ARQAPI_H
11 #include <comtools.h>
12 #include <prikind.h>
13 #include <arqguid.h>
15 #include <pshpack4.h>
17 ///////////////////////////////////////////////////////////////////////////////
19 struct IStream; typedef struct IStream IStream;
21 F_DECLARE_INTERFACE(IAsyncReadQueue);
22 F_DECLARE_INTERFACE(IAsyncReadControl);
23 F_DECLARE_INTERFACE(IAsyncReadFulfiller);
24 F_DECLARE_INTERFACE(IAsyncStreamer);
26 typedef struct sARQResult sARQResult;
27 typedef struct sARQRequest sARQRequest;
28 typedef struct sARQStreamerDesc sARQStreamerDesc;
29 typedef struct sARQStreamRequest sARQStreamRequest;
31 ///////////////////////////////////////////////////////////////////////////////
33 // Asynchronous Read Queue API
37 // Create an asynchronous read queue and add it to the global app-object
39 #define AsyncReadQueueCreate() \
40 { \
41 IUnknown * pAppUnknown = AppGetObj(IUnknown); \
42 _AsyncReadQueueCreate(IID_TO_REFIID(IID_IAsyncReadQueue), NULL, pAppUnknown); \
43 COMRelease(pAppUnknown); \
48 // Creates an asynchronous read queue, aggregating it with specfied pOuter,
49 // use IAggregate protocol if ppAsyncReadQueue is NULL, else self-init
51 EXTERN tResult LGAPI _AsyncReadQueueCreate(REFIID, IAsyncReadQueue ** ppAsyncReadQueue, IUnknown * pOuter);
54 ///////////////////////////////////////////////////////////////////////////////
56 // Read request structures
59 ///////////////////////////////////////
61 // STRUCT: sARQRequest
64 struct sARQRequest
66 // Pointer to object used to execute read
67 IAsyncReadFulfiller * pFulfiller;
69 // Queue to use, zero-based
70 unsigned queue;
72 // Priority of read
73 int priority;
75 // Optional, client defined data values
76 DWORD dwData[6];
78 // Optional tracing name for debug routines
79 const char * pszTrace;
84 ///////////////////////////////////////
86 // STRUCT: sARQStreamRequest
89 struct sARQStreamRequest
91 // Source of read
92 IStream * pSource;
94 // Starting offset, may be kARQCurPos
95 long offset;
97 // Length of read, may be kARQToEOF
98 long length;
100 // Queue to use, zero-based
101 unsigned queue;
103 // Priority of read
104 int priority;
106 // Flags composed of bits from eARQStreamRequestFlags
107 int flags;
109 // Destination, may be NULL if dynamic allocation is desired
110 void * pBufOut;
112 // Destination size
113 long bufSize;
115 // Optional tracing name for debug routines
116 const char * pszTrace;
120 // Helper macro
121 #define ARQInitStreamReq(arqreq, src, off, len, que, pri, f, p, sz, nm); \
123 arqreq.pSource = src; \
124 arqreq.offset = off; \
125 arqreq.length = len; \
126 arqreq.queue = que; \
127 arqreq.priority = pri; \
128 arqreq.flags = f; \
129 arqreq.pBufOut = p; \
130 arqreq.bufSize = sz; \
131 arqreq.pszTrace = nm; \
135 ///////////////////////////////////////
137 #define kARQCurPos (-1L)
138 #define kARQToEOF (-1L)
141 ///////////////////////////////////////
143 enum eARQStreamRequestFlags
145 // Specified buffer may safely be realloced
146 kARQDynamicBuf = 0x01
150 ///////////////////////////////////////////////////////////////////////////////
152 // STRUCT: sARQResult
155 struct sARQResult
157 // Status of the result
158 HRESULT result;
160 // Result, whether dynamically allocated or buffer supplied
161 void * buffer;
163 // Size of the result
164 long length;
166 // Flags, composed of bits from eARQResultFlags
167 unsigned flags;
169 // Number of read, if streaming 0 if starting, 'frame number' on
170 // subsequent reads
171 int streamIndex;
176 ///////////////////////////////////////
178 enum eARQResultFlags
180 // The buffer was malloc’ed by read queue system
181 kARQMalloc = 0x01,
183 // The request is associated with streaming data
184 kARQStreamed = 0x02,
186 // The request was killed
187 kARQKilled = 0x04
192 ///////////////////////////////////////////////////////////////////////////////
194 // STRUCT: sARQStreamerDesc
197 struct sARQStreamerDesc
199 // Source of read
200 IStream * pSource;
202 // Starting offset, may be kARQCurPos
203 long offsetStart;
205 // Length of header
206 long lenHeader;
208 // Queue to use, zero-based
209 unsigned queue;
211 // Priority of read
212 int priority;
214 // Flags composed of bits from eAsyncStreamerFlags
215 int flags;
217 // Destination of header read, if lenHeader specified.
218 // May be NULL if dynamic allocation is desired
219 void * pBufOut;
221 // Destination size
222 long bufSize;
224 // Optional tracing name for debug routines
225 const char * pszTrace;
230 // Helper macro
231 #define ARQInitStrDesc(strdsc, src, off, len, que, pri, f, p, sz, nm); \
233 strdsc.pSource = src; \
234 strdsc.offsetStart = off; \
235 strdsc.lenHeader = len; \
236 strdsc.queue = que; \
237 strdsc.priority = pri; \
238 strdsc.flags = f; \
239 strdsc.pBufOut = p; \
240 strdsc.bufSize = sz; \
241 strdsc.pszTrace = nm; \
245 ///////////////////////////////////////
247 enum eAsyncStreamerFlags
249 // The stream should preempt all others in the same queue, for its lifetime
250 kAsStrExclusive = 0x01
255 ///////////////////////////////////////////////////////////////////////////////
257 // INTERFACE: IAsyncReadQueue
260 #undef INTERFACE
261 #define INTERFACE IAsyncReadQueue
263 DECLARE_INTERFACE_(IAsyncReadQueue, IUnknown)
266 // IUnknown Methods
268 DECLARE_UNKNOWN_PURE();
271 // Add a simple request to queue
273 STDMETHOD (QueueRequest)(THIS_ const sARQRequest * pRequest,
274 IAsyncReadControl ** ppControl) PURE;
277 // Add a simple stream-oriented request to queue
279 STDMETHOD (QueueStreamRequest)(THIS_ const sARQStreamRequest * pRequest,
280 IAsyncReadControl ** ppControl) PURE;
283 // Get a reader for streaming
285 STDMETHOD (GetAsyncStreamer)(THIS_ const sARQStreamerDesc * pDesc,
286 IAsyncStreamer ** ppAsyncStreamer) PURE;
289 // Suspend all reads
291 STDMETHOD (Suspend)(THIS) PURE;
294 // Resume reading
296 STDMETHOD (Resume)(THIS) PURE;
299 // Query if a streamer is blocking
301 STDMETHOD_(BOOL, IsStreamerBlocking)(THIS) PURE;
304 // Synchronously satisfy all pending requests -- analogous to flush
306 STDMETHOD (FulfillAll)(THIS) PURE;
309 // Synchronously satisfy all pending requests with priority equal to or
310 // higher than the specified priority
312 STDMETHOD (FulfillToPriority)(THIS_ int priority) PURE;
315 // Kill all pending requests
317 STDMETHOD (KillAll)(THIS) PURE;
322 // @TBD (toml 11-12-96): need to finish coding up all these C access macros!
323 #define IAsyncReadQueue_QueryInterface(p, a, b) COMQueryInterface(p, a, b)
324 #define IAsyncReadQueue_AddRef(p) COMAddRef(p)
325 #define IAsyncReadQueue_Release(p) COMRelease(p)
326 #define IAsyncReadQueue_QueueRequest(p, a, b) COMCall2(p, QueueRequest, a, b)
327 #define IAsyncReadQueue_FulfillAll(p) COMCall0(p, FulfillAll)
329 ///////////////////////////////////////////////////////////////////////////////
331 // INTERFACE: IAsyncReadFulfiller
334 #undef INTERFACE
335 #define INTERFACE IAsyncReadFulfiller
337 DECLARE_INTERFACE_(IAsyncReadFulfiller, IUnknown)
340 // IUnknown Methods
342 DECLARE_UNKNOWN_PURE();
345 // Satisfy the request
347 STDMETHOD (DoFulfill)(THIS_ const sARQRequest *, sARQResult *) PURE;
350 // Kill the request, discard if paritally or wholly fulfilled
352 STDMETHOD (DoKill)(THIS_ const sARQRequest *, BOOL fDiscard) PURE;
357 ///////////////////////////////////////////////////////////////////////////////
359 // INTERFACE: IAsyncReadControl
362 #undef INTERFACE
363 #define INTERFACE IAsyncReadControl
365 DECLARE_INTERFACE_(IAsyncReadControl, IUnknown)
368 // IUnknown Methods
370 DECLARE_UNKNOWN_PURE();
373 // Query if request has been fulfilled
375 STDMETHOD_(BOOL, IsFulfilled)(THIS) PURE;
378 // Synchronously satisfy the request
380 STDMETHOD (Fulfill)(THIS) PURE;
383 // Kill the request, discard if paritally or wholly fulfilled
385 STDMETHOD (Kill)(THIS_ BOOL fDiscard) PURE;
388 // Get the result
390 STDMETHOD (GetResult)(THIS_ sARQResult *) PURE;
395 ///////////////////////////////////////////////////////////////////////////////
397 // INTERFACE: IAsyncStreamer
400 #undef INTERFACE
401 #define INTERFACE IAsyncStreamer
403 DECLARE_INTERFACE_(IAsyncStreamer, IUnknown)
406 // IUnknown Methods
408 DECLARE_UNKNOWN_PURE();
413 STDMETHOD (Read)(THIS_ void * pBufOut, long length) PURE;
418 STDMETHOD (GetNextResult)(THIS_ sARQResult *) PURE;
421 // Synchronously satisfy all pending requests from this stream -- analogous
422 // to flush
424 STDMETHOD (FulfillAll)(THIS) PURE;
427 // Kill all pending requests from this stream
429 STDMETHOD (KillAll)(THIS_ BOOL fDiscard) PURE;
434 ///////////////////////////////////////////////////////////////////////////////
436 #include <poppack.h>
438 #endif /* !__ARQAPI_H */