|
1 /* |
|
2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Stream for storing firmware update package |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <centralrepository.h> |
|
22 #include "fotadiskstoragePrivateCRKeys.h" |
|
23 #include "fotaengstream.h" |
|
24 #include "fotaengine.h" |
|
25 #include "fotaenginedebug.h" |
|
26 |
|
27 // ======================= MEMBER FUNCTIONS ================================== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // RFotaWriteStream::RFotaWriteStream() |
|
31 // --------------------------------------------------------------------------- |
|
32 RFotaWriteStream::RFotaWriteStream() : RWriteStream (), iWriteLimit(0) |
|
33 { |
|
34 iFotaEngineSession = 0; |
|
35 iBuf.iMyWriteStream = this; |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // RFotaWriteStream::OpenL() |
|
40 // Opens stream |
|
41 // --------------------------------------------------------------------------- |
|
42 TInt RFotaWriteStream::OpenL(const TInt /*aPkgId*/) |
|
43 { |
|
44 FLOG(_L( "[RFotaEngineSession] RFotaWriteStream::OpenL() >>" ) ); |
|
45 |
|
46 // Get write limit |
|
47 TInt writelimit( KDefaultWriteLimit ); |
|
48 CRepository* centrep( NULL); |
|
49 TRAPD( err, centrep = CRepository::NewL( KCRUidFotaDiskStorage ) ); |
|
50 if(err) FLOG(_L(" writelimit not defined in centrep") ); |
|
51 if ( centrep ) |
|
52 { |
|
53 err = centrep->Get( KFotaDiskSpaceReservationKey, writelimit ); |
|
54 } |
|
55 iWriteLimit = writelimit; |
|
56 delete centrep; |
|
57 |
|
58 iBuf.ResetL(); |
|
59 Attach ( &iBuf ); // set sink |
|
60 |
|
61 FLOG(_L( "[RFotaEngineSession] RFotaWriteStream::OpenL() <<" ) ); |
|
62 return 0; |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // TDP2StreamBuf::Reset() |
|
68 // Redefine write area. |
|
69 // --------------------------------------------------------------------------- |
|
70 void TDP2StreamBuf::ResetL() |
|
71 { |
|
72 FLOG(_L("TDP2StreamBuf::ResetL() >>" )); |
|
73 // Define write area (chunk) |
|
74 TArea a (EWrite) ; |
|
75 TInt limitedwritearea(-1); |
|
76 TInt chunksize = iMyWriteStream->iFotaEngineSession->iChunk.Size(); |
|
77 // TInt writelimit = iMyWriteStream->iWriteLimit; |
|
78 /* 08-nov-06 flexible mem handling overrides this |
|
79 // If writelimit is being exceeded, raise error |
|
80 if ( iBytesWritten > writelimit ) |
|
81 { |
|
82 User::Leave ( KErrOverflow ); |
|
83 } |
|
84 */ |
|
85 /* 08-nov-06 flexible mem handling overrides this |
|
86 // Ensure that we cant go beyond write limit |
|
87 if ( (iSentChunks+1) * chunksize > writelimit ) |
|
88 { |
|
89 limitedwritearea = writelimit - iBytesWritten; |
|
90 |
|
91 // 0-size writearea would crash writestream base classes |
|
92 if ( limitedwritearea == 0 ) |
|
93 { |
|
94 limitedwritearea += 1; |
|
95 } |
|
96 } |
|
97 */ |
|
98 |
|
99 // Define write area |
|
100 TUint8* p1 = iMyWriteStream->iFotaEngineSession->iChunk.Base(); |
|
101 TUint8* p2; |
|
102 if ( limitedwritearea == -1 ) |
|
103 { |
|
104 p2 = p1 + chunksize; |
|
105 } |
|
106 else |
|
107 { |
|
108 p2 = p1 + limitedwritearea; |
|
109 } |
|
110 SetBuf (a,p1 , p2 ); |
|
111 FLOG(_L("TDP2StreamBuf::ResetL() <<" )); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // TDP2StreamBuf::DoRelease() |
|
116 // Stream is released. This is called when data has been comitted to stream. |
|
117 // --------------------------------------------------------------------------- |
|
118 void TDP2StreamBuf::DoRelease() |
|
119 { |
|
120 FLOG(_L("TDP2StreamBuf::DoRelease() >>" )); |
|
121 TRAPD(err, OverflowL() ); |
|
122 if ( err ) FLOG(_L(" DoRelease overflow err %d"),err); |
|
123 this->iMyWriteStream->iFotaEngineSession->ReleaseChunkHandle(); |
|
124 FLOG(_L("TDP2StreamBuf::DoRelease() <<" )); |
|
125 } |
|
126 |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // TDP2StreamBuf::TDP2StreamBuf() |
|
130 // --------------------------------------------------------------------------- |
|
131 TDP2StreamBuf::TDP2StreamBuf() : iBytesWritten(0), iSentChunks(0) |
|
132 ,iMyWriteStream(0) |
|
133 { |
|
134 } |
|
135 |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // TDP2StreamBuf::UnderflowL(TInt aMaxLength) |
|
139 // --------------------------------------------------------------------------- |
|
140 TInt TDP2StreamBuf::UnderflowL(TInt aMaxLength) |
|
141 { |
|
142 FLOG(_L("TDP2StreamBuf::UnderflowL %d"), aMaxLength ); |
|
143 return KErrNone; |
|
144 } |
|
145 |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // TDP2StreamBuf::OverflowL() |
|
149 // Send buffer data to server. Reset buffer. |
|
150 // --------------------------------------------------------------------------- |
|
151 void TDP2StreamBuf::OverflowL() |
|
152 { |
|
153 FLOG(_L("TDP2StreamBuf::OverflowL >>") ); |
|
154 // Send pointers to data to server. Then reset. |
|
155 TUint8* p1 = iMyWriteStream->iFotaEngineSession->iChunk.Base(); |
|
156 TUint8* p2 = Ptr(EWrite); // start point of |
|
157 // write area |
|
158 FLOG(_L("TDP2StreamBuf::OverflowL ptrs 0x%x 0x%x"),p1,p2 ); |
|
159 TPtr8 data(p1, p2-p1, p2-p1 ); |
|
160 iBytesWritten += p2-p1; |
|
161 if ( p2-p1 >0 ) |
|
162 { |
|
163 iMyWriteStream->iFotaEngineSession->SendChunkL(p1,p2); |
|
164 iSentChunks++; |
|
165 } |
|
166 ResetL(); |
|
167 FLOG(_L("TDP2StreamBuf::OverflowL <<") ); |
|
168 } |
|
169 |
|
170 // End of file |