convert line ends
[canaan.git] / prj / tech / libsrc / res / resarq.h
blob6f328e6f618821718f08c6648e39d24703efbde6
1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/res/RCS/resarq.h $
3 // $Author: TOML $
4 // $Date: 1997/08/12 12:19:14 $
5 // $Revision: 1.9 $
6 //
8 #ifndef __RESARQ_H
9 #define __RESARQ_H
11 EXTERN void LGAPI ResARQClearPreload(Id id);
13 #if defined(__ARQAPI_H) && defined(__cplusplus)
15 #include <pool.h>
16 #include <hashset.h>
18 #include <pshpack4.h>
20 ///////////////////////////////////////////////////////////////////////////////
22 // CLASS: cResARQ
25 class cResARQFulfiller : public IAsyncReadFulfiller
27 public:
28 cResARQFulfiller();
29 ~cResARQFulfiller();
31 ///////////////////////////////////
33 void Init();
34 void Term();
36 ///////////////////////////////////
38 BOOL Lock(Id id, int priority);
39 BOOL Extract(Id id, int priority, void *buf, long bufSize);
40 BOOL Preload(Id id);
41 BOOL IsFulfilled(Id id);
42 HRESULT Kill(Id id);
43 HRESULT GetResult(Id id, void **);
45 void ClearPreload(Id id);
46 BOOL IsAsynchronous();
48 ///////////////////////////////////
50 STDMETHOD (DoFulfill)(const sARQRequest *, sARQResult *);
51 STDMETHOD (DoKill)(const sARQRequest *, BOOL fDiscard);
53 DECLARE_UNAGGREGATABLE();
55 ///////////////////////////////////
57 private:
59 struct sResRequest;
60 class cResControlTable : public cHashSet<sResRequest *, Id *, cHashFunctions>
62 private:
63 virtual tHashSetKey GetKey(tHashSetNode node) const;
66 ///////////////////////////////////
68 // Asynchronous resource requests are tracked using a hash table of
69 // sResRequest structures
72 struct sResRequest
74 enum eRequestKind
76 kLock,
77 kExtract,
78 kPreload
81 ///////////////////////////////
83 sResRequest(cResControlTable & owningControlTable,
84 Id id, int priority, eRequestKind kind,
85 void * pBuf = NULL, long bufSize = 0)
86 : pControl(NULL),
87 id(id),
88 priority(priority),
89 pBuf(pBuf),
90 bufSize(bufSize),
91 nRequests(0),
92 kind(kind),
93 m_OwningControlTable(owningControlTable)
95 m_OwningControlTable.Insert(this);
98 ~sResRequest()
100 Verify(m_OwningControlTable.Remove(this));
101 if (pControl)
102 pControl->Release();
103 memset(this, 0xfe, sizeof(sResRequest));
106 ///////////////////////////////
108 IAsyncReadControl * pControl;
109 Id id;
110 int priority;
111 eRequestKind kind;
112 void * pBuf;
113 long bufSize;
114 unsigned nRequests;
116 cResControlTable & m_OwningControlTable;
118 ///////////////////////////////
120 DECLARE_POOL();
124 ///////////////////////////////////
126 BOOL QueueRequest(Id id, int priority, sResRequest::eRequestKind, void *buf = NULL, long bufSize = 0);
127 HRESULT SatisfyRequest(sResRequest *, void **);
129 ///////////////////////////////////
131 IAsyncReadQueue * m_pAsyncReadQueue;
132 cResControlTable m_Controls;
134 BOOL m_fSatisfyingPreload;
138 ///////////////////////////////////////
140 inline BOOL cResARQFulfiller::Lock(Id id, int priority)
142 return QueueRequest(id, priority, sResRequest::kLock);
145 ///////////////////////////////////////
147 inline BOOL cResARQFulfiller::Extract(Id id, int priority, void *buf, long bufSize)
149 return QueueRequest(id, priority, sResRequest::kExtract, buf, bufSize);
152 ///////////////////////////////////////
154 inline BOOL cResARQFulfiller::Preload(Id id)
156 return QueueRequest(id, kPriorityLowest, sResRequest::kPreload);
159 ///////////////////////////////////////
161 inline BOOL cResARQFulfiller::IsAsynchronous()
163 return !!m_pAsyncReadQueue;
166 ///////////////////////////////////////////////////////////////////////////////
168 #include <poppack.h>
170 #endif
173 #endif /* !__RESARQ_H */