|
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 p2 = p1 + chunksize; |
|
103 |
|
104 /* // dead code |
|
105 if ( limitedwritearea == -1 ) |
|
106 { |
|
107 p2 = p1 + chunksize; |
|
108 } |
|
109 else |
|
110 { |
|
111 p2 = p1 + limitedwritearea; |
|
112 } |
|
113 */ |
|
114 SetBuf (a,p1 , p2 ); |
|
115 FLOG(_L("TDP2StreamBuf::ResetL() <<" )); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // TDP2StreamBuf::DoRelease() |
|
120 // Stream is released. This is called when data has been comitted to stream. |
|
121 // --------------------------------------------------------------------------- |
|
122 void TDP2StreamBuf::DoRelease() |
|
123 { |
|
124 FLOG(_L("TDP2StreamBuf::DoRelease() >>" )); |
|
125 TRAPD(err, OverflowL() ); |
|
126 if ( err ) FLOG(_L(" DoRelease overflow err %d"),err); |
|
127 this->iMyWriteStream->iFotaEngineSession->ReleaseChunkHandle(); |
|
128 FLOG(_L("TDP2StreamBuf::DoRelease() <<" )); |
|
129 } |
|
130 |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // TDP2StreamBuf::TDP2StreamBuf() |
|
134 // --------------------------------------------------------------------------- |
|
135 TDP2StreamBuf::TDP2StreamBuf() : iBytesWritten(0), iSentChunks(0) |
|
136 ,iMyWriteStream(0) |
|
137 { |
|
138 } |
|
139 |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // TDP2StreamBuf::UnderflowL(TInt aMaxLength) |
|
143 // --------------------------------------------------------------------------- |
|
144 TInt TDP2StreamBuf::UnderflowL(TInt aMaxLength) |
|
145 { |
|
146 FLOG(_L("TDP2StreamBuf::UnderflowL %d"), aMaxLength ); |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // TDP2StreamBuf::OverflowL() |
|
153 // Send buffer data to server. Reset buffer. |
|
154 // --------------------------------------------------------------------------- |
|
155 void TDP2StreamBuf::OverflowL() |
|
156 { |
|
157 FLOG(_L("TDP2StreamBuf::OverflowL >>") ); |
|
158 // Send pointers to data to server. Then reset. |
|
159 TUint8* p1 = iMyWriteStream->iFotaEngineSession->iChunk.Base(); |
|
160 TUint8* p2 = Ptr(EWrite); // start point of |
|
161 // write area |
|
162 FLOG(_L("TDP2StreamBuf::OverflowL ptrs 0x%x 0x%x"),p1,p2 ); |
|
163 TPtr8 data(p1, p2-p1, p2-p1 ); |
|
164 iBytesWritten += p2-p1; |
|
165 if ( p2-p1 >0 ) |
|
166 { |
|
167 iMyWriteStream->iFotaEngineSession->SendChunkL(p1,p2); |
|
168 iSentChunks++; |
|
169 } |
|
170 ResetL(); |
|
171 FLOG(_L("TDP2StreamBuf::OverflowL <<") ); |
|
172 } |
|
173 |
|
174 // End of file |