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: Service implementation class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "RNewFileServiceClient.h" |
|
22 #include "NewFileServiceDefs.h" |
|
23 #include "cnewfileserviceserverobserver.h" |
|
24 #include <NewFileServiceClient.h> |
|
25 |
|
26 #include <s32mem.h> |
|
27 |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS ============================= |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // RNewFileServiceClient::RNewFileServiceClient |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 RNewFileServiceClient::RNewFileServiceClient() |
|
38 { |
|
39 } |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // RNewFileServiceClient::~RNewFileServiceClient |
|
44 // Destructor |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 RNewFileServiceClient::~RNewFileServiceClient() |
|
48 { |
|
49 delete iObserver; |
|
50 |
|
51 if ( iWait.IsStarted() ) |
|
52 { |
|
53 iWait.AsyncStop(); |
|
54 } |
|
55 |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // RNewFileServiceClient::ServiceUid |
|
61 // |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 TUid RNewFileServiceClient::ServiceUid() const |
|
65 { |
|
66 return TUid::Uid( NEWSERVICEUID ); |
|
67 |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // RNewFileServiceClient::NewFileL |
|
73 // |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 TBool RNewFileServiceClient::NewFileL( RFile& aFile, TDesC8* aGenericParams, |
|
77 TNewServiceFileType aType ) |
|
78 { |
|
79 TIpcArgs args; |
|
80 |
|
81 TNewServiceParamPack pack; |
|
82 pack.iType = aType; |
|
83 pack.iMultipleFiles = EFalse; |
|
84 |
|
85 TPckgBuf< TNewServiceParamPack > paramPack; |
|
86 paramPack = pack; |
|
87 args.Set( 0, ¶mPack ); |
|
88 |
|
89 |
|
90 if ( aGenericParams ) |
|
91 { |
|
92 args.Set( ENewServiceIndexFileName, aGenericParams ); |
|
93 } |
|
94 |
|
95 TInt err = aFile.TransferToServer( args, ENewServiceIndexFsHandle, |
|
96 ENewServiceIndexFileHandle ); |
|
97 #ifdef _DEBUG |
|
98 RDebug::Print( _L("transfer to server error: %d"), err ); |
|
99 #endif |
|
100 |
|
101 iObserver = CNewFileServiceServerObserver::NewL(); |
|
102 |
|
103 // Send through IPC, pass iObservers TRequestStatus to server |
|
104 SendReceive( ENewFileToHandle, args, iObserver->IssueWait( this ) ); |
|
105 |
|
106 // Wait until server notifies iObserver |
|
107 if ( !iWait.IsStarted() ) |
|
108 { |
|
109 iWait.Start(); // CSI: 10 # |
|
110 } |
|
111 |
|
112 return paramPack().iReturnValue; |
|
113 } |
|
114 |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // RNewFileServiceClient::NewFileL |
|
118 // |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 TBool RNewFileServiceClient::NewFileL( CDesCArray& aFilenames, |
|
122 TDesC8* aGenericParams, |
|
123 TNewServiceFileType aType, |
|
124 TBool aMultipleFiles ) |
|
125 { |
|
126 #ifdef _DEBUG |
|
127 RDebug::Print( _L("RNewFileServiceClient::NewFileL") ); |
|
128 #endif |
|
129 |
|
130 TIpcArgs args; |
|
131 |
|
132 TNewServiceParamPack pack; |
|
133 pack.iType = aType; |
|
134 pack.iMultipleFiles = aMultipleFiles; |
|
135 |
|
136 TPckgBuf< TNewServiceParamPack > paramPack = pack; |
|
137 args.Set( ENewServiceIndexParams, ¶mPack ); |
|
138 |
|
139 if ( aGenericParams ) |
|
140 { |
|
141 args.Set( ENewServiceIndexFileName, aGenericParams ); |
|
142 } |
|
143 else |
|
144 { |
|
145 args.Set( ENewServiceIndexFileName, &KNullDesC() ); |
|
146 } |
|
147 |
|
148 iObserver = CNewFileServiceServerObserver::NewL(); |
|
149 |
|
150 // Send through IPC, pass iObservers TRequestStatus to server |
|
151 SendReceive( ECreateNewFile, args, iObserver->IssueWait( this ) ); |
|
152 |
|
153 // Wait until server notifies iObserver |
|
154 if ( !iWait.IsStarted() ) |
|
155 { |
|
156 iWait.Start(); // CSI: 10 # |
|
157 } |
|
158 |
|
159 pack = paramPack(); |
|
160 |
|
161 if ( !pack.iReturnValue ) |
|
162 { |
|
163 #ifdef _DEBUG |
|
164 RDebug::Print( _L("RNewFileServiceClient::NewFileL - return value received: False") ); |
|
165 #endif |
|
166 // don't bother with filename array if the user canceled |
|
167 return EFalse; |
|
168 } |
|
169 |
|
170 #ifdef _DEBUG |
|
171 RDebug::Print( _L("RNewFileServiceClient::NewFileL - return value received: True") ); |
|
172 #endif |
|
173 |
|
174 TPckgBuf< TInt > lengthBuf; |
|
175 args.Set( ENewServiceIndexParams, &lengthBuf ); |
|
176 User::LeaveIfError( SendReceive( EGetFilenameArrayLength, args ) ); |
|
177 |
|
178 TInt length( lengthBuf() ); |
|
179 |
|
180 HBufC8* buffer = HBufC8::NewLC( length ); |
|
181 TPtr8 ptr = buffer->Des(); |
|
182 args.Set( ENewServiceIndexParams, &ptr ); |
|
183 User::LeaveIfError( SendReceive( EGetFilenameArray, args ) ); |
|
184 |
|
185 // Unpack filename array |
|
186 RDesReadStream stream; |
|
187 stream.Open( ptr ); |
|
188 |
|
189 TInt count( stream.ReadInt32L() ); |
|
190 |
|
191 for ( TInt i( 0 ); i < count; i++ ) |
|
192 { |
|
193 TInt length( stream.ReadInt16L() ); |
|
194 TFileName filename; |
|
195 stream.ReadL( filename, length ); |
|
196 #ifdef _DEBUG |
|
197 RDebug::Print( filename ); |
|
198 #endif |
|
199 aFilenames.AppendL( filename ); |
|
200 } |
|
201 |
|
202 CleanupStack::PopAndDestroy(); // buffer |
|
203 |
|
204 |
|
205 return ETrue; |
|
206 } |
|
207 |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // RNewFileServiceClient::ServerRequestReady |
|
211 // |
|
212 // ---------------------------------------------------------------------------- |
|
213 // |
|
214 void RNewFileServiceClient::ServerRequestReady( TInt aError ) |
|
215 { |
|
216 |
|
217 if (aError == KErrAbort) |
|
218 { |
|
219 iError = KErrAbort; |
|
220 } |
|
221 // Server processed command and active object was notified and |
|
222 // client can continue now |
|
223 if ( iWait.IsStarted() ) |
|
224 { |
|
225 iWait.AsyncStop(); |
|
226 } |
|
227 } |
|
228 |
|
229 |
|
230 void RNewFileServiceClient::SetFileServiceClient(CNewFileServiceClient* aClient) |
|
231 { |
|
232 iNewFileServiceClient = aClient; |
|
233 } |
|
234 |
|
235 |
|
236 // End of File |
|