|
1 /* |
|
2 * Copyright (c) 2002-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: Base class for app servers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <badesca.h> |
|
22 #include <s32mem.h> |
|
23 #include <AiwGenericParam.h> |
|
24 |
|
25 #include "CNewFileServiceBase.h" |
|
26 #include "NewFileServiceDefs.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KFilenameArrayGranularity( 2 ); |
|
30 |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS ============================= |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CNewFileServiceBase::CNewFileServiceBase |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CNewFileServiceBase::CNewFileServiceBase():iError(0) |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CNewFileServiceBase::~CNewFileServiceBase |
|
47 // |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 // Destructor |
|
51 EXPORT_C CNewFileServiceBase::~CNewFileServiceBase() |
|
52 { |
|
53 delete iFilenameArray; |
|
54 delete iGenericParams; |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CNewFileServiceBase::DeserializeGenericParamsL |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CNewFileServiceBase::DeserializeGenericParamsL( const RMessage2& aMessage ) |
|
64 { |
|
65 if ( !iGenericParams ) |
|
66 { |
|
67 iGenericParams = CAiwGenericParamList::NewL(); |
|
68 } |
|
69 else |
|
70 { |
|
71 iGenericParams->Reset(); |
|
72 } |
|
73 |
|
74 TInt dataLength( aMessage.GetDesLengthL( ENewServiceIndexFileName ) ); |
|
75 if ( dataLength == 0 ) |
|
76 { |
|
77 return; |
|
78 } |
|
79 |
|
80 HBufC8* buffer = HBufC8::NewLC( dataLength ); |
|
81 TPtr8 ptr( buffer->Des() ); |
|
82 aMessage.ReadL( ENewServiceIndexFileName, ptr ); |
|
83 |
|
84 RDesReadStream stream( ptr ); |
|
85 iGenericParams->InternalizeL( stream ); |
|
86 CleanupStack::PopAndDestroy(); // buffer |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CNewFileServiceBase::ServiceL |
|
92 // |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C void CNewFileServiceBase::ServiceL( const RMessage2& aMessage ) |
|
96 { |
|
97 #ifdef _DEBUG |
|
98 RDebug::Print( _L("CNewFileServiceBase::ServiceL %d"), |
|
99 aMessage.Function() ); |
|
100 #endif |
|
101 switch ( aMessage.Function() ) |
|
102 { |
|
103 case ECreateNewFile: |
|
104 { |
|
105 TPckgBuf< TNewServiceParamPack > paramPack; |
|
106 aMessage.ReadL( ENewServiceIndexParams, paramPack ); |
|
107 |
|
108 if ( !iFilenameArray ) |
|
109 { |
|
110 iFilenameArray = new ( ELeave ) |
|
111 CDesCArrayFlat( KFilenameArrayGranularity ); |
|
112 } |
|
113 iFilenameArray->Reset(); |
|
114 |
|
115 DeserializeGenericParamsL( aMessage ); |
|
116 |
|
117 // Copy the message handle so we can reply to the message when |
|
118 // the service observer gets called |
|
119 iPendingMessage = aMessage; |
|
120 |
|
121 HandleNewFileL( this, *iFilenameArray, paramPack().iType, |
|
122 paramPack().iMultipleFiles ); |
|
123 |
|
124 break; |
|
125 } |
|
126 |
|
127 case ENewFileToHandle: |
|
128 { |
|
129 TPckgBuf< TNewServiceParamPack > paramPack; |
|
130 aMessage.ReadL( ENewServiceIndexParams, paramPack ); |
|
131 |
|
132 DeserializeGenericParamsL( aMessage ); |
|
133 |
|
134 // Adopt file handle from client |
|
135 RFile file; |
|
136 TInt err = file.AdoptFromClient( aMessage, |
|
137 ENewServiceIndexFsHandle, |
|
138 ENewServiceIndexFileHandle ); |
|
139 #ifdef _DEBUG |
|
140 RDebug::Print( _L("adopt error: %d" ), err ); |
|
141 #endif |
|
142 // Copy the message handle so we can reply to the message when |
|
143 // the service observer gets called |
|
144 iPendingMessage = aMessage; |
|
145 |
|
146 HandleNewFileL( this, file, paramPack().iType ); |
|
147 |
|
148 break; |
|
149 } |
|
150 |
|
151 case EGetFilenameArrayLength: |
|
152 { |
|
153 // Calculate the size of the buffer needed to transfer the |
|
154 //filenames to the client side |
|
155 TPckgBuf< TInt > lengthBuf; |
|
156 TInt count( iFilenameArray->MdcaCount() ); |
|
157 #ifdef _DEBUG |
|
158 RDebug::Print( _L("Filename array count: %d"), count ); |
|
159 #endif |
|
160 TInt length = sizeof( TInt ) + count * sizeof( TUint16 ); |
|
161 for ( TInt i( 0 ); i < count; i++ ) |
|
162 { |
|
163 length += iFilenameArray->MdcaPoint( i ).Size(); |
|
164 } |
|
165 |
|
166 lengthBuf = length; |
|
167 aMessage.WriteL( ENewServiceIndexParams, lengthBuf ); |
|
168 aMessage.Complete( KErrNone ); |
|
169 break; |
|
170 } |
|
171 |
|
172 case EGetFilenameArray: |
|
173 { |
|
174 // Allocate a buffer with the same size as in the client side |
|
175 TInt length( aMessage.GetDesMaxLengthL( ENewServiceIndexParams ) ); |
|
176 HBufC8* buffer = HBufC8::NewLC( length ); |
|
177 |
|
178 TPtr8 ptr = buffer->Des(); |
|
179 RDesWriteStream stream( ptr ); |
|
180 |
|
181 // Stream the filename array to the buffer |
|
182 TInt count( iFilenameArray->MdcaCount() ); |
|
183 stream.WriteInt32L( count ); |
|
184 for ( TInt i( 0 ); i < count; i++ ) |
|
185 { |
|
186 TPtrC filename = iFilenameArray->MdcaPoint( i ); |
|
187 stream.WriteUint16L( filename.Length() ); |
|
188 stream.WriteL( filename ); |
|
189 } |
|
190 |
|
191 stream.CommitL(); |
|
192 |
|
193 // Return the buffer to the client side |
|
194 aMessage.WriteL( ENewServiceIndexParams, ptr ); |
|
195 aMessage.Complete( KErrNone ); |
|
196 CleanupStack::PopAndDestroy(); // buffer |
|
197 |
|
198 // notify the application that the transfer is complete and |
|
199 // it's ok to quit / whatever |
|
200 ServiceCompleteL(); |
|
201 |
|
202 break; |
|
203 } |
|
204 default: |
|
205 { |
|
206 // Complete old message if still open |
|
207 if ( !iPendingMessage.IsNull() ) |
|
208 { |
|
209 iPendingMessage.Complete( KErrCancel ); |
|
210 } |
|
211 |
|
212 CApaAppServiceBase::ServiceL(aMessage); |
|
213 break; |
|
214 } |
|
215 } |
|
216 } |
|
217 |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CNewFileServiceBase::HandleCompletedNewServiceL |
|
221 // |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C void CNewFileServiceBase::HandleCompletedNewServiceL( |
|
225 TBool aReturnValue ) |
|
226 { |
|
227 // Message was already completed in ServiceL |
|
228 if ( iPendingMessage.IsNull() ) |
|
229 { |
|
230 return; |
|
231 } |
|
232 |
|
233 TNewServiceParamPack pack; |
|
234 TPckgBuf< TNewServiceParamPack > paramPack; |
|
235 pack.iReturnValue = aReturnValue; |
|
236 paramPack = pack; |
|
237 |
|
238 iPendingMessage.WriteL( ENewServiceIndexParams, paramPack ); |
|
239 if(iError != KErrAbort) |
|
240 { |
|
241 iPendingMessage.Complete( KErrNone ); |
|
242 } |
|
243 else |
|
244 { |
|
245 iPendingMessage.Complete( KErrAbort ); |
|
246 iError = 0; |
|
247 } |
|
248 } |
|
249 |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CNewFileServiceBase::GenericParams |
|
253 // |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 EXPORT_C CAiwGenericParamList* CNewFileServiceBase::GenericParams() |
|
257 { |
|
258 return iGenericParams; |
|
259 } |
|
260 |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CNewFileServiceBase::GenericParams |
|
264 // |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 EXPORT_C TInt CNewFileServiceBase::GetErrorCode() |
|
268 { |
|
269 return iError; |
|
270 } |
|
271 |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CNewFileServiceBase::GenericParams |
|
275 // |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 EXPORT_C void CNewFileServiceBase::SetErrorCode(TInt aError) |
|
279 { |
|
280 iError = aError; |
|
281 } |
|
282 |
|
283 |
|
284 // End of File |