|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // apamdr.cpp |
|
15 // |
|
16 |
|
17 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
18 #if !defined(__APA_INTERNAL_H__) |
|
19 #include "apainternal.h" |
|
20 #endif |
|
21 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include "APASTD.H" // Panics etc. |
|
23 |
|
24 #include <apamdr.h> |
|
25 |
|
26 #include <apgdoor.h> |
|
27 #include <s32mem.h> // class TBufBuf |
|
28 |
|
29 const TInt KHugeGranularity = 4096; // 4k granularity for the door's host buffer |
|
30 |
|
31 // |
|
32 // HBufBuf |
|
33 // |
|
34 |
|
35 class HBufBuf : public TBufBuf |
|
36 { |
|
37 public: |
|
38 static HBufBuf* NewL(CBufBase& aBuf,TInt aPos,TInt aMode=ERead|EWrite); |
|
39 private: |
|
40 void DoRelease(); |
|
41 }; |
|
42 |
|
43 HBufBuf* HBufBuf::NewL(CBufBase& aBuf,TInt aPos,TInt aMode) |
|
44 // |
|
45 // Create a pre-set buffer stream buffer. |
|
46 // |
|
47 { |
|
48 HBufBuf* buf=new(ELeave) HBufBuf; |
|
49 buf->Set(aBuf,aPos,aMode); |
|
50 return buf; |
|
51 } |
|
52 |
|
53 void HBufBuf::DoRelease() |
|
54 // |
|
55 // Finished with this stream buffer. |
|
56 // |
|
57 { |
|
58 delete this; |
|
59 } |
|
60 |
|
61 // |
|
62 // TApaModelDoorFactory |
|
63 // |
|
64 |
|
65 EXPORT_C TApaModelDoorFactory::TApaModelDoorFactory(const MApaModelHeaderFactory* aFactory) |
|
66 :iHeaderFactory(aFactory) |
|
67 /** Constructs a door factory object. |
|
68 |
|
69 @param aFactory A pointer to a factory object for constructing the application |
|
70 model wrapper object, also known as the application model header, a CApaModelHeader |
|
71 type. The application model wrapper is provided by the application model (not |
|
72 the application UI), and supplies the knowledge for internalizing the application |
|
73 model data from an embedded store. |
|
74 @see CApaModelHeader |
|
75 @see MApaModelHeaderFactory */ |
|
76 {} |
|
77 |
|
78 |
|
79 EXPORT_C void TApaModelDoorFactory::NewPictureL(TPictureHeader& aPictureHeader,const CStreamStore& aPictureStore)const |
|
80 /** Constructs and restores an application's door (picture) from a stream in the |
|
81 specified store. |
|
82 |
|
83 The restored door is a CApaModelDoor type object. |
|
84 |
|
85 @param aPictureHeader The header identifying the door to be restored. The |
|
86 UID identifying the door must be KUidPictureTypeDoor, otherwise the function |
|
87 leaves with KErrNotSupported. On entry, the door picture must be represented |
|
88 by a stream ID, otherwise the function leaves with KErrBadHandle; on return, |
|
89 the door picture is represented by a pointer to an internalized CApaModelDoor |
|
90 object. |
|
91 @param aPictureStore The store from which the door will be restored. |
|
92 @see TPictureHeader::iPicture */ |
|
93 { |
|
94 if (aPictureHeader.iPictureType!=KUidPictureTypeDoor) |
|
95 User::Leave(KErrNotSupported); // wrong type |
|
96 if (!aPictureHeader.iPicture.IsId()) |
|
97 User::Leave(KErrBadHandle); // not an id - can't restore |
|
98 // |
|
99 // create and restore the door |
|
100 TStreamId id = aPictureHeader.iPicture.AsId(); |
|
101 aPictureHeader.iPicture = CApaModelDoor::NewL(aPictureStore,id,iHeaderFactory); |
|
102 } |
|
103 |
|
104 |
|
105 // |
|
106 // CApaModelDoor |
|
107 // |
|
108 |
|
109 |
|
110 EXPORT_C CApaModelDoor* CApaModelDoor::NewL(CApaModelHeader* aHeader) |
|
111 /** Creates a model door object. |
|
112 |
|
113 @param aHeader A pointer to an existing concrete application model wrapper |
|
114 object. |
|
115 @return A pointer to the new model door object. */ |
|
116 { |
|
117 CApaModelDoor* self = new(ELeave) CApaModelDoor(aHeader); |
|
118 return self; |
|
119 } |
|
120 |
|
121 |
|
122 EXPORT_C CApaModelDoor* CApaModelDoor::NewLC(CApaModelHeader* aHeader) |
|
123 /** Creates a model door object, and puts a pointer to it onto the cleanup stack. |
|
124 |
|
125 @param aHeader A pointer to an existing concrete application model wrapper |
|
126 object. |
|
127 @return A pointer to the new model door object. */ |
|
128 { |
|
129 CApaModelDoor* self = CApaModelDoor::NewL(aHeader); |
|
130 CleanupStack::PushL(self); |
|
131 return self; |
|
132 } |
|
133 |
|
134 |
|
135 EXPORT_C CApaModelDoor* CApaModelDoor::NewL(const CStreamStore& aStore,TStreamId aHeadStreamId,const MApaModelHeaderFactory* aFactory) |
|
136 /** Creates a model door object and restores it from an embedded store within the |
|
137 specified store. |
|
138 |
|
139 @param aStore The store from which the model door is to be restored. |
|
140 @param aHeadStreamId The head stream ID. This is the ID of the stream containing |
|
141 the stream dictionary which is restored as part of the process of creating |
|
142 this model door object. The stream dictionary contains the ID of the stream |
|
143 hosting the embedded store. |
|
144 @param aFactory A pointer to a factory object for constructing the application |
|
145 model wrapper object, also known as the application model header, a CApaModelHeader |
|
146 type. |
|
147 @return A pointer to the new model door object. |
|
148 @see MApaModelHeaderFactory */ |
|
149 { |
|
150 CApaModelDoor* self = new(ELeave) CApaModelDoor(); |
|
151 CleanupStack::PushL(self); |
|
152 self->RestoreL(aStore,aHeadStreamId,aFactory); |
|
153 CleanupStack::Pop(); |
|
154 return self; |
|
155 } |
|
156 |
|
157 |
|
158 CApaModelDoor::CApaModelDoor() |
|
159 {} |
|
160 |
|
161 |
|
162 CApaModelDoor::CApaModelDoor(CApaModelHeader* aHeader) |
|
163 :iModelHeader(aHeader) |
|
164 {} |
|
165 |
|
166 |
|
167 EXPORT_C CApaModelDoor::~CApaModelDoor() |
|
168 /** Destructor. |
|
169 |
|
170 Frees all resources owned by the object, prior to its destruction. */ |
|
171 { |
|
172 delete iModelHeader; |
|
173 delete iStore; |
|
174 delete iStoreHost; |
|
175 } |
|
176 |
|
177 |
|
178 EXPORT_C TStreamId CApaModelDoor::StoreL(CStreamStore& aTargetStore)const |
|
179 /** Stores the model data in the specified store as an embedded store. |
|
180 |
|
181 The function stores the model data, if the model exists in memory, otherwise, |
|
182 it simply copies the stream containing the embedded document into the specified |
|
183 store. |
|
184 |
|
185 @param aStore The store in which the model data is to be stored. |
|
186 @return The stream ID of the head stream for the embedded model data. This |
|
187 stream contains the stream dictionary through which the embedded data and |
|
188 its door can be restored. */ |
|
189 { |
|
190 // create stream dictionary |
|
191 CStreamDictionary* streamDic = CStreamDictionary::NewLC(); |
|
192 // |
|
193 // stream out door's state |
|
194 ExternalizeBaseStreamL(aTargetStore,*streamDic); |
|
195 // |
|
196 // store the model |
|
197 TStreamId id; |
|
198 RStoreWriteStream stream; |
|
199 if (iModelHeader) |
|
200 { |
|
201 // create an embedded store in a new write stream |
|
202 id = stream.CreateL(aTargetStore); |
|
203 CEmbeddedStore* target=CEmbeddedStore::NewLC(stream); // takes ownership of stream |
|
204 streamDic->AssignL(KUidApaDoorDocStream,id); |
|
205 // store the model |
|
206 CStreamDictionary* rootDict=CStreamDictionary::NewLC(); |
|
207 iModelHeader->StoreL(*target,*rootDict); |
|
208 CApaProcess::WriteRootStreamL(*target,*rootDict,iModelHeader->AppId()); |
|
209 CleanupStack::PopAndDestroy(); // rootDict |
|
210 // close the new embedded store |
|
211 target->CommitL(); |
|
212 CleanupStack::PopAndDestroy(); // target |
|
213 } |
|
214 else if (iStore) |
|
215 { |
|
216 RStoreWriteStream trg; |
|
217 id = trg.CreateLC(aTargetStore); |
|
218 CopyStoreL(*iStore,trg); |
|
219 CleanupStack::PopAndDestroy(); // trg |
|
220 streamDic->AssignL(KUidApaDoorDocStream,id); |
|
221 } |
|
222 else |
|
223 Panic(EPanicNoModelHeaderWhenStoring); // impossible situation |
|
224 // |
|
225 // store the stream dictionary and return its stream id |
|
226 id = stream.CreateLC(aTargetStore); |
|
227 stream<< *streamDic; |
|
228 stream.CommitL(); |
|
229 CleanupStack::PopAndDestroy(2); // stream,streamDic |
|
230 return id; |
|
231 } |
|
232 |
|
233 |
|
234 void CApaModelDoor::CopyStoreL(const CEmbeddedStore& aSourceStore,RWriteStream& aTargetStream) |
|
235 // static method |
|
236 // copies an embedded store containing a doc to aTargetStream |
|
237 // |
|
238 { |
|
239 // read the contents of aSourceStore's rootstream (so I can write it out in a mo') |
|
240 CStreamDictionary* root=ReadStreamDictionaryLC(aSourceStore,aSourceStore.Root()); |
|
241 // |
|
242 // copy the source store directly |
|
243 MStreamBuf* host=aSourceStore.Host(); |
|
244 TStreamPos pos=aSourceStore.Position(aSourceStore.Root()); |
|
245 host->SeekL(host->ERead,EStreamBeginning); |
|
246 RReadStream stream(host); |
|
247 aTargetStream.WriteL(stream,pos.Offset()); |
|
248 // |
|
249 // write the root stream |
|
250 aTargetStream<< *root; |
|
251 aTargetStream.CommitL(); |
|
252 CleanupStack::PopAndDestroy(); // root |
|
253 } |
|
254 |
|
255 |
|
256 EXPORT_C void CApaModelDoor::RestoreL(const CStreamStore& aSourceStore,TStreamId aHeadStreamId,const MApaModelHeaderFactory* aFactory) |
|
257 /** Restores the embedded model data from the specified store. |
|
258 |
|
259 @param aStore The store from which the embedded model data is to be restored. |
|
260 @param aHeadStreamId The stream ID of the head stream for the embedded model |
|
261 data. This stream contains the stream dictionary through which the embedded |
|
262 model data and its door can be restored. |
|
263 @param aFactory A pointer to a factory object for constructing the application |
|
264 model wrapper object, also known as the application model header, a CApaModelHeader |
|
265 type. The application model wrapper is provided by the application model (not |
|
266 the application UI), and supplies the knowledge for internalizing the application |
|
267 model data from an embedded store. The pointer must not be null, otherwise |
|
268 the function raises an APPARC 22 panic. */ |
|
269 { |
|
270 __ASSERT_ALWAYS(aFactory,Panic(EPanicNoFactory)); |
|
271 // |
|
272 delete iStore; |
|
273 delete iStoreHost; |
|
274 iStore=NULL; |
|
275 iStoreHost = NULL; |
|
276 // |
|
277 // internalize the streamDic from the headstream |
|
278 CStreamDictionary* streamDic=ReadStreamDictionaryLC(aSourceStore,aHeadStreamId); |
|
279 // |
|
280 // internalize the door's state |
|
281 TSize size=InternalizeBaseStreamL(aSourceStore,*streamDic); |
|
282 SetSizeInTwips(size); |
|
283 // |
|
284 // internalize the embedded store |
|
285 RStoreReadStream src; |
|
286 src.OpenL(aSourceStore,streamDic->At(KUidApaDoorDocStream)); |
|
287 CleanupStack::PopAndDestroy(); // streamDic |
|
288 streamDic = NULL; |
|
289 iStore = CEmbeddedStore::FromL(src); |
|
290 // |
|
291 // check for a security stream, then internalize the model |
|
292 TRAP_IGNORE(InternalizeModelL(*aFactory)); //lint !e613 Possible use of null pointer - Asserted above |
|
293 // ignore any leave, we still have the data in the store to fall back on |
|
294 } |
|
295 |
|
296 |
|
297 void CApaModelDoor::InternalizeModelL(const MApaModelHeaderFactory& aFactory) |
|
298 // internalizes the model if the data is not encrypted |
|
299 // if the factory does not recognize the doc type, NewHeaderL() will leave (probably KErrNotSupported) |
|
300 { |
|
301 CStreamDictionary* streamDic = ReadStreamDictionaryLC(*iStore,iStore->Root()); |
|
302 if (streamDic->At(KUidSecurityStream)==KNullStreamId) |
|
303 {// not encrypted, so internalize the model |
|
304 TApaAppIdentifier appId = CApaProcess::ReadAppIdentifierL(*iStore,*streamDic); |
|
305 iModelHeader = aFactory.NewHeaderL(*iStore,*streamDic,appId); |
|
306 } |
|
307 CleanupStack::PopAndDestroy(); // streamDic |
|
308 } |
|
309 |
|
310 |
|
311 CStreamDictionary* CApaModelDoor::ReadStreamDictionaryLC(const CStreamStore& aSourceStore,TStreamId aStreamId) |
|
312 // static method |
|
313 // |
|
314 { |
|
315 // read the stream dic from the doc's root stream |
|
316 CStreamDictionary* streamDic=CStreamDictionary::NewLC(); |
|
317 RStoreReadStream stream; |
|
318 stream.OpenLC(aSourceStore,aStreamId); |
|
319 stream>> *streamDic; |
|
320 CleanupStack::PopAndDestroy(); // root |
|
321 return streamDic; |
|
322 } |
|
323 |
|
324 |
|
325 TSize CApaModelDoor::GlassDoorSize()const |
|
326 { |
|
327 TSize size; |
|
328 GetSizeInTwips(size); |
|
329 return size; |
|
330 } |
|
331 |
|
332 |
|
333 EXPORT_C void CApaModelDoor::DetachFromStoreL(TDetach aDegree) |
|
334 /** Restores the model to the specified degree. |
|
335 |
|
336 @param aDegree The degree to which restoration is needed. */ |
|
337 { |
|
338 if (iModelHeader) |
|
339 { |
|
340 iModelHeader->DetachFromStoreL(aDegree); |
|
341 if (!iStoreHost) |
|
342 { |
|
343 delete iStore; |
|
344 iStore = NULL; |
|
345 } |
|
346 } |
|
347 else if (!iStoreHost) |
|
348 { |
|
349 if (aDegree==EDetachDraw) |
|
350 { |
|
351 delete iStore; |
|
352 iStore = NULL; |
|
353 // now all I can do is draw as I am, any attempt to change me will result in a panic |
|
354 } |
|
355 else |
|
356 { |
|
357 __ASSERT_ALWAYS(iStore,Panic(EPanicNoStoreOnDetach)); |
|
358 // instantiate the mem buffer, and a stream to write to it |
|
359 CBufSeg* bufSeg = CBufSeg::NewL(KHugeGranularity); |
|
360 CleanupStack::PushL(bufSeg); |
|
361 HBufBuf* buf=HBufBuf::NewL(*bufSeg,0); |
|
362 RWriteStream writeStream(buf); |
|
363 writeStream.PushL(); |
|
364 // write the store to the mem buffer |
|
365 CopyStoreL(*iStore,writeStream); |
|
366 CleanupStack::Pop(2); // bufSeg,writeStream |
|
367 // |
|
368 // set iStoreHost as host for the embedded store |
|
369 MStreamBuf* host=iStore->Host(); |
|
370 __ASSERT_ALWAYS(host!=NULL,Panic(EDPanicNoHostForStore)); |
|
371 iStore->Detach(); |
|
372 host->Release(); //lint !e613 Possible use of null pointer - Asserted above |
|
373 iStore->Reattach(buf); |
|
374 iStoreHost = bufSeg; |
|
375 } |
|
376 } |
|
377 } |
|
378 |
|
379 |
|
380 |
|
381 EXPORT_C void CApaModelDoor::Draw(CGraphicsContext& /*aGc*/,const TPoint& /*aTopLeft*/,const TRect& /*aClipRect*/, |
|
382 MGraphicsDeviceMap* /*aMap*/)const |
|
383 /** |
|
384 Not supported; if called, raises an APPARC 17 panic. |
|
385 @removed |
|
386 */ |
|
387 { |
|
388 Panic(EPanicNotSupported); |
|
389 } |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 EXPORT_C void CApaModelDoor::ExternalizeL(RWriteStream& /*aStream*/)const |
|
395 /** |
|
396 Not supported; if called, raises an APPARC 17 panic. |
|
397 @removed |
|
398 */ |
|
399 { |
|
400 Panic(EPanicNotSupported); |
|
401 } |
|
402 |
|
403 |
|
404 EXPORT_C void CApaModelDoor::GetOriginalSizeInTwips(TSize& aSize)const |
|
405 /** Gets the door's original size, in twips. |
|
406 |
|
407 @param aSize This size, in twips. */ |
|
408 { |
|
409 aSize = TSize(500,500); // ? |
|
410 } |
|
411 |
|
412 |
|
413 EXPORT_C void CApaModelDoor::SetScaleFactor(TInt aScaleFactorWidth,TInt aScaleFactorHeight) |
|
414 /** Sets the door's scale factors. |
|
415 |
|
416 @param aScaleFactorWidth The width scale factor, in percent. |
|
417 @param aScaleFactorHeight The height scale factor, in percent. */ |
|
418 { |
|
419 iScaleFactor.iWidth = aScaleFactorWidth; |
|
420 iScaleFactor.iHeight = aScaleFactorHeight; |
|
421 } |
|
422 |
|
423 |
|
424 EXPORT_C TInt CApaModelDoor::ScaleFactorWidth()const |
|
425 /** Gets the door's width scale factor. |
|
426 |
|
427 @return The width scale factor, in percent. */ |
|
428 { |
|
429 return iScaleFactor.iWidth; |
|
430 } |
|
431 |
|
432 |
|
433 EXPORT_C TInt CApaModelDoor::ScaleFactorHeight()const |
|
434 /** Gets the door's height scale factor. |
|
435 |
|
436 @return The height scale factor, in percent. */ |
|
437 { |
|
438 return iScaleFactor.iHeight; |
|
439 } |
|
440 |
|
441 // CApaModelHeader |
|
442 |
|
443 /** Constructor for CApaModelHeader */ |
|
444 EXPORT_C CApaModelHeader::CApaModelHeader() |
|
445 { |
|
446 } |
|
447 |
|
448 /** Reserved for future use */ |
|
449 EXPORT_C void CApaModelHeader::Reserved_1() |
|
450 {} |
|
451 |
|
452 /** Reserved for future use */ |
|
453 EXPORT_C void CApaModelHeader::Reserved_2() |
|
454 {} |
|
455 |
|
456 // MApaModelHeaderFactory |
|
457 |
|
458 /** Constructor for MApaModelHeaderFactory */ |
|
459 EXPORT_C MApaModelHeaderFactory::MApaModelHeaderFactory() |
|
460 {} |
|
461 |
|
462 /** Reserved for future use */ |
|
463 EXPORT_C void MApaModelHeaderFactory::MApaModelHeaderFactory_Reserved1() |
|
464 {} |
|
465 |
|
466 /** Reserved for future use */ |
|
467 EXPORT_C void MApaModelHeaderFactory::MApaModelHeaderFactory_Reserved2() |
|
468 {} |