1 //---------------------------------------------------------------
2 //
3 //  For conditions of distribution and use, see copyright notice
4 //  in Flashpix.h
5 //
6 //  Copyright (c) 1999 Digital Imaging Group, Inc.
7 //
8 //  Contents: Defines CHandle
9 //
10 //  Classes:  CHandle
11 //    CStgHandle
12 //    CStmHandle
13 //
14 //---------------------------------------------------------------
15 
16 #ifndef __HANDLE_HXX__
17 #define __HANDLE_HXX__
18 
19 #include "msf.hxx"
20 #include "msffunc.hxx"
21 
22 //+--------------------------------------------------------------
23 //
24 //  Class:  CHandle (h)
25 //
26 //  Purpose:  An opaque handle to a directory entry-based object
27 //
28 //  Interface:  See below
29 //
30 //---------------------------------------------------------------
31 
32 class CStgHandle;
33 class CStmHandle;
34 
35 class CHandle
36 {
37 public:
38     inline CHandle(void);
39 
40     inline void Init(CMStream *pms,
41          SID sid);
42 
43     inline BOOL IsRoot(void) const;
44     inline BOOL IsValid(void) const;
45 
46     inline SCODE GetTime(WHICHTIME wt, TIME_T *ptm);
47     inline SCODE SetTime(WHICHTIME wt, TIME_T tm);
48 
49     inline SCODE DestroyEntry(CDfName const *pdfn);
50 
51 
52     inline CMStream *GetMS(void) const;
53     inline SID GetSid(void) const;
54 
55 private:
56     friend class CStgHandle;
57     friend class CStmHandle;
58 
59     CMStream *_pms;
60     SID _sid;
61 };
62 
63 //+--------------------------------------------------------------
64 //
65 //  Member: CHandle::CHandle, public
66 //
67 //  Synopsis: NULL constructor
68 //
69 //---------------------------------------------------------------
70 
CHandle(void)71 inline CHandle::CHandle(void)
72 {
73     _pms = NULL;
74     _sid = NOSTREAM;
75 }
76 
77 //+--------------------------------------------------------------
78 //
79 //  Member: CHandle::Init, public
80 //
81 //  Synopsis: Sets internal data members
82 //
83 //  Arguments:  [pms] - Multistream
84 //    [sid] - SID
85 //
86 //  Returns:  Appropriate status code
87 //
88 //---------------------------------------------------------------
89 
Init(CMStream * pms,SID sid)90 inline void CHandle::Init(CMStream *pms,
91         SID sid)
92 {
93     _pms = pms;
94     _sid = sid;
95 }
96 
97 //+--------------------------------------------------------------
98 //
99 //  Member: CHandle::IsRoot, public
100 //
101 //  Synopsis: Whether this is a root handle or not
102 //
103 //---------------------------------------------------------------
104 
IsRoot(void) const105 inline BOOL CHandle::IsRoot(void) const
106 {
107     return _sid == SIDROOT;
108 }
109 
110 //+--------------------------------------------------------------
111 //
112 //  Member: CHandle::IsValid, public
113 //
114 //  Synopsis: Whether this handle has been initialized
115 //
116 //---------------------------------------------------------------
117 
IsValid(void) const118 inline BOOL CHandle::IsValid(void) const
119 {
120     return _pms != NULL;
121 }
122 
123 //+--------------------------------------------------------------
124 //
125 //  Member: CHandle::GetTime, public
126 //
127 //  Synopsis: Returns the time
128 //
129 //---------------------------------------------------------------
130 
GetTime(WHICHTIME wt,TIME_T * ptm)131 inline SCODE CHandle::GetTime(WHICHTIME wt, TIME_T *ptm)
132 {
133     return _pms->GetTime(_sid, wt, ptm);
134 }
135 
136 //+--------------------------------------------------------------
137 //
138 //  Member: CHandle::SetTime, public
139 //
140 //  Synopsis: Sets the time
141 //
142 //---------------------------------------------------------------
143 
SetTime(WHICHTIME wt,TIME_T tm)144 inline SCODE CHandle::SetTime(WHICHTIME wt, TIME_T tm)
145 {
146     return _pms->SetTime(_sid, wt, tm);
147 }
148 
149 
150 //+--------------------------------------------------------------
151 //
152 //  Member: CHandle::DestroyEntry, public
153 //
154 //  Synopsis: Destroys this entry
155 //
156 //  Returns:  Appropriate status code
157 //
158 //---------------------------------------------------------------
159 
DestroyEntry(CDfName const * pdfn)160 inline SCODE CHandle::DestroyEntry(CDfName const *pdfn)
161 {
162     return _pms->DestroyEntry(_sid, pdfn);
163 }
164 
165 
166 //+--------------------------------------------------------------
167 //
168 //  Member: CHandle::GetMS, public
169 //
170 //  Synopsis: Returns the multistream
171 //
172 //---------------------------------------------------------------
173 
GetMS(void) const174 inline CMStream *CHandle::GetMS(void) const
175 {
176     return _pms;
177 }
178 
179 //+--------------------------------------------------------------
180 //
181 //  Member: CHandle::GetSid, public
182 //
183 //  Synopsis: Returns the sid
184 //
185 //---------------------------------------------------------------
186 
GetSid(void) const187 inline SID CHandle::GetSid(void) const
188 {
189     return _sid;
190 }
191 
192 //+--------------------------------------------------------------
193 //
194 //  Class:  CStgHandle, (stgh)
195 //
196 //  Purpose:  An opaque handle for Multistream directories
197 //
198 //  Interface:  See below
199 //
200 //---------------------------------------------------------------
201 
202 class CMSFIterator;
203 
204 class CStgHandle : public CHandle
205 {
206 public:
207     inline SCODE CreateEntry(CDfName const *pdfnName,
208            MSENTRYFLAGS const mefFlags,
209            CHandle *ph);
210     inline SCODE GetEntry(CDfName const *pdfnName,
211         MSENTRYFLAGS const mefFlags,
212         CHandle *ph);
213     inline SCODE RenameEntry(CDfName const *pdfnName,
214            CDfName const *pdfnNewName);
215     inline SCODE IsEntry(CDfName const *pdfnName,
216        SEntryBuffer *peb);
217     inline SCODE GetIterator(CMSFIterator **ppi);
218     inline SCODE GetClass(CLSID *pclsid);
219     inline SCODE SetClass(REFCLSID clsid);
220     inline SCODE GetStateBits(DWORD *pgrfStateBits);
221     inline SCODE SetStateBits(DWORD grfStateBits, DWORD grfMask);
222 };
223 
224 //+--------------------------------------------------------------
225 //
226 //  Member: CStgHandle::CreateEntry, public
227 //
228 //  Synopsis: Creates an entry
229 //
230 //---------------------------------------------------------------
231 
232 
CreateEntry(CDfName const * pdfnName,MSENTRYFLAGS const mefFlags,CHandle * ph)233 inline SCODE CStgHandle::CreateEntry(CDfName const *pdfnName,
234              MSENTRYFLAGS const mefFlags,
235              CHandle *ph)
236 {
237     ph->_pms = _pms;
238     return _pms->CreateEntry(_sid, pdfnName, mefFlags, &ph->_sid);
239 }
240 
241 //+--------------------------------------------------------------
242 //
243 //  Member: CStgHandle::GetEntry, public
244 //
245 //  Synopsis: Gets an entry
246 //
247 //---------------------------------------------------------------
248 
249 
GetEntry(CDfName const * pdfnName,MSENTRYFLAGS const mefFlags,CHandle * ph)250 inline SCODE CStgHandle::GetEntry(CDfName const *pdfnName,
251           MSENTRYFLAGS const mefFlags,
252           CHandle *ph)
253 {
254     SCODE sc;
255     SEntryBuffer eb = {0, 0, 0};
256 
257     ph->_pms = _pms;
258 
259     sc = _pms->IsEntry(_sid, pdfnName, &eb);
260     if (SUCCEEDED(sc))
261     {
262         msfAssert(eb.sid != NOSTREAM);
263         //  entry exists but it may be the wrong type
264 
265         if ((mefFlags != MEF_ANY) &&
266 	    (mefFlags != eb.dwType))
267         {
268       sc = STG_E_FILENOTFOUND;
269         }
270         else
271             ph->_sid = eb.sid;
272     }
273     return(sc);
274 }
275 
276 //+--------------------------------------------------------------
277 //
278 //  Member: CStgHandle::RenameEntry, public
279 //
280 //  Synopsis: Renames an entry
281 //
282 //---------------------------------------------------------------
283 
284 
RenameEntry(CDfName const * pdfnName,CDfName const * pdfnNewName)285 inline SCODE CStgHandle::RenameEntry(CDfName const *pdfnName,
286              CDfName const *pdfnNewName)
287 {
288     return _pms->RenameEntry(_sid, pdfnName, pdfnNewName);
289 }
290 
291 //+--------------------------------------------------------------
292 //
293 //  Member: CStgHandle::IsEntry, public
294 //
295 //  Synopsis: Gets entry info and checks for existence
296 //
297 //---------------------------------------------------------------
298 
IsEntry(CDfName const * pdfnName,SEntryBuffer * peb)299 inline SCODE CStgHandle::IsEntry(CDfName const *pdfnName,
300          SEntryBuffer *peb)
301 {
302     return _pms->IsEntry(_sid, pdfnName, peb);
303 }
304 
305 //+--------------------------------------------------------------
306 //
307 //  Member: CStgHandle::GetIterator, public
308 //
309 //  Synopsis: Gets an iterator
310 //
311 //---------------------------------------------------------------
312 
GetIterator(CMSFIterator ** ppi)313 inline SCODE CStgHandle::GetIterator(CMSFIterator **ppi)
314 {
315     return _pms->GetIterator(_sid, ppi);
316 }
317 
318 //+---------------------------------------------------------------------------
319 //
320 //  Member: CStgHandle::GetClass, public
321 //
322 //  Synopsis: Gets the class ID
323 //
324 //----------------------------------------------------------------------------
325 
GetClass(CLSID * pclsid)326 inline SCODE CStgHandle::GetClass(CLSID *pclsid)
327 {
328     return _pms->GetClass(_sid, pclsid);
329 
330 }
331 
332 //+---------------------------------------------------------------------------
333 //
334 //  Member: CStgHandle::SetClass, public
335 //
336 //  Synopsis: Sets the class ID
337 //
338 //----------------------------------------------------------------------------
339 
SetClass(REFCLSID clsid)340 inline SCODE CStgHandle::SetClass(REFCLSID clsid)
341 {
342     return _pms->SetClass(_sid, clsid);
343 }
344 
345 //+---------------------------------------------------------------------------
346 //
347 //  Member: CStgHandle::GetStateBits, public
348 //
349 //  Synopsis: Gets state bits
350 //
351 //----------------------------------------------------------------------------
352 
GetStateBits(DWORD * pgrfStateBits)353 inline SCODE CStgHandle::GetStateBits(DWORD *pgrfStateBits)
354 {
355     return _pms->GetStateBits(_sid, pgrfStateBits);
356 }
357 
358 //+---------------------------------------------------------------------------
359 //
360 //  Member: CStgHandle::SetStateBits, public
361 //
362 //  Synopsis: Sets state bits
363 //
364 //----------------------------------------------------------------------------
365 
SetStateBits(DWORD grfStateBits,DWORD grfMask)366 inline SCODE CStgHandle::SetStateBits(DWORD grfStateBits, DWORD grfMask)
367 {
368     return _pms->SetStateBits(_sid, grfStateBits, grfMask);
369 }
370 
371 //+--------------------------------------------------------------
372 //
373 //  Class:  CStmHandle, (stmh)
374 //
375 //  Purpose:  An opaque handle for Multistream streams
376 //
377 //  Interface:  See below
378 //
379 //---------------------------------------------------------------
380 
381 class CDirectStream;
382 
383 class CStmHandle : public CHandle
384 {
385 public:
386     inline SCODE GetSize(ULONG *pcbSize);
387 };
388 
389 //+--------------------------------------------------------------
390 //
391 //  Member: CStmHandle::GetSize, public
392 //
393 //  Synopsis: Gets the stream size
394 //
395 //---------------------------------------------------------------
396 
GetSize(ULONG * pcbSize)397 inline SCODE CStmHandle::GetSize(ULONG *pcbSize)
398 {
399     return _pms->GetEntrySize(_sid, pcbSize);
400 }
401 
402 #endif // #ifndef __HANDLE_HXX__
403 
404