|
1 /* |
|
2 * Copyright (c) 2008 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: Client API, private implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tsfswclientimpl.h" |
|
20 #include "tsfswclientobserver.h" |
|
21 #include "tsfswcommon.h" |
|
22 #include <s32mem.h> |
|
23 |
|
24 #include "clientlogging.h" |
|
25 |
|
26 // -------------------------------------------------------------------------- |
|
27 // StartServer |
|
28 // -------------------------------------------------------------------------- |
|
29 // |
|
30 static TInt StartServer() |
|
31 { |
|
32 RProcess server; |
|
33 const TUidType uid( KNullUid, KNullUid, KTsFswServerUid ); |
|
34 TInt err = server.Create( KTsFswServerImg, KNullDesC, uid ); |
|
35 if ( err != KErrNone ) |
|
36 { |
|
37 return err; |
|
38 } |
|
39 TRequestStatus stat; |
|
40 server.Rendezvous( stat ); |
|
41 if ( stat != KRequestPending ) |
|
42 { |
|
43 server.Kill( 0 ); |
|
44 } |
|
45 else |
|
46 { |
|
47 server.Resume(); |
|
48 } |
|
49 User::WaitForRequest( stat ); |
|
50 err = server.ExitType() == EExitPanic ? KErrGeneral : stat.Int(); |
|
51 server.Close(); |
|
52 return err; |
|
53 } |
|
54 |
|
55 // -------------------------------------------------------------------------- |
|
56 // CTsFswClientImpl::RTsFswClient::Connect |
|
57 // -------------------------------------------------------------------------- |
|
58 // |
|
59 TInt CTsFswClientImpl::RTsFswClient::Connect() |
|
60 { |
|
61 const TInt KAsyncMessageSlots = 4; |
|
62 const TInt KMaxRetry = 4; |
|
63 |
|
64 TInt retry = KMaxRetry; |
|
65 for ( ; ; ) |
|
66 { |
|
67 TInt err = CreateSession( KTsFswServerName, TVersion( 0, 0, 0 ), KAsyncMessageSlots ); |
|
68 if ( err != KErrNotFound && err != KErrServerTerminated ) |
|
69 { |
|
70 return err; |
|
71 } |
|
72 if ( !--retry ) |
|
73 { |
|
74 return err; |
|
75 } |
|
76 err = StartServer(); |
|
77 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
78 { |
|
79 return err; |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 // -------------------------------------------------------------------------- |
|
85 // CTsFswClientImpl::RTsFswClient::Subscribe |
|
86 // -------------------------------------------------------------------------- |
|
87 // |
|
88 void CTsFswClientImpl::RTsFswClient::Subscribe( TRequestStatus& aStatus ) |
|
89 { |
|
90 SendReceive( ETsFswSubscribe, aStatus ); |
|
91 } |
|
92 |
|
93 // -------------------------------------------------------------------------- |
|
94 // CTsFswClientImpl::RTsFswClient::CancelSubscribe |
|
95 // -------------------------------------------------------------------------- |
|
96 // |
|
97 void CTsFswClientImpl::RTsFswClient::CancelSubscribe() |
|
98 { |
|
99 SendReceive( ETsFswCancel ); |
|
100 } |
|
101 |
|
102 // -------------------------------------------------------------------------- |
|
103 // CTsFswClientImpl::RTsFswClient::GetContentL |
|
104 // -------------------------------------------------------------------------- |
|
105 // |
|
106 void CTsFswClientImpl::RTsFswClient::GetContentL( RTsFswArray& aDst ) |
|
107 { |
|
108 TSLOG_CONTEXT( GetContentL, TSLOG_LOCAL ); |
|
109 TSLOG_IN(); |
|
110 |
|
111 for ( ; ; ) |
|
112 { |
|
113 TPckgBuf<TInt> bufSize; |
|
114 User::LeaveIfError( SendReceive( ETsFswGetBufferSize, |
|
115 TIpcArgs( &bufSize ) ) ); |
|
116 HBufC8* buf = HBufC8::NewLC( bufSize() ); |
|
117 TPtr8 p( buf->Des() ); |
|
118 TInt err = SendReceive( ETsFswGetBuffer, |
|
119 TIpcArgs( &p, bufSize() ) ); |
|
120 if ( err == KErrNone ) |
|
121 { |
|
122 RDesReadStream strm( p ); |
|
123 CleanupClosePushL( strm ); |
|
124 CTsFswEntry::InternalizeArrayL( strm, aDst ); |
|
125 CleanupStack::PopAndDestroy( &strm ); |
|
126 } |
|
127 else if ( err != KErrArgument ) |
|
128 { |
|
129 User::Leave( err ); |
|
130 } |
|
131 CleanupStack::PopAndDestroy( buf ); |
|
132 if ( err == KErrNone ) |
|
133 { |
|
134 break; |
|
135 } |
|
136 // If result was KErrArgument then the size received from GetBufferSize is |
|
137 // not valid anymore so restart the whole procedure. |
|
138 } |
|
139 |
|
140 TSLOG_OUT(); |
|
141 } |
|
142 |
|
143 // -------------------------------------------------------------------------- |
|
144 // CTsFswClientImpl::RTsFswClient::CloseApp |
|
145 // -------------------------------------------------------------------------- |
|
146 // |
|
147 void CTsFswClientImpl::RTsFswClient::CloseApp( TInt aWgId ) |
|
148 { |
|
149 SendReceive( ETsFswCloseApp, TIpcArgs( aWgId ) ); |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------- |
|
153 // CTsFswClientImpl::RTsFswClient::SwitchToApp |
|
154 // -------------------------------------------------------------------------- |
|
155 // |
|
156 void CTsFswClientImpl::RTsFswClient::SwitchToApp( TInt aWgId ) |
|
157 { |
|
158 SendReceive( ETsFswSwitchToApp, TIpcArgs( aWgId ) ); |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CTsFswClientImpl::RTsFswClient::ForegroundAppUid |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 TUid CTsFswClientImpl::RTsFswClient::ForegroundAppUid( TInt aType ) |
|
166 { |
|
167 TUid result = KNullUid; |
|
168 TPckgBuf<TInt> uidBuf; |
|
169 if ( SendReceive( ETsFswForegroundAppUid, |
|
170 TIpcArgs( &uidBuf, &aType ) ) == KErrNone ) |
|
171 { |
|
172 result = TUid::Uid( uidBuf() ); |
|
173 } |
|
174 return result; |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CTsFswClientImpl::NewL |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 CTsFswClientImpl* CTsFswClientImpl::NewL() |
|
182 { |
|
183 CTsFswClientImpl* self = NewLC(); |
|
184 CleanupStack::Pop( self ); |
|
185 return self; |
|
186 } |
|
187 |
|
188 // -------------------------------------------------------------------------- |
|
189 // CTsFswClientImpl::NewLC() |
|
190 // -------------------------------------------------------------------------- |
|
191 // |
|
192 CTsFswClientImpl* CTsFswClientImpl::NewLC() |
|
193 { |
|
194 CTsFswClientImpl* self = new ( ELeave ) CTsFswClientImpl; |
|
195 CleanupStack::PushL( self ); |
|
196 self->ConstructL(); |
|
197 return self; |
|
198 } |
|
199 |
|
200 // -------------------------------------------------------------------------- |
|
201 // CTsFswClientImpl::CTsFswClientImpl() |
|
202 // -------------------------------------------------------------------------- |
|
203 // |
|
204 CTsFswClientImpl::CTsFswClientImpl() |
|
205 : CActive( CActive::EPriorityStandard ) |
|
206 { |
|
207 CActiveScheduler::Add( this ); |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // CTsFswClientImpl::~CTsFswClientImpl() |
|
212 // -------------------------------------------------------------------------- |
|
213 // |
|
214 CTsFswClientImpl::~CTsFswClientImpl() |
|
215 { |
|
216 Cancel(); |
|
217 iClient.Close(); |
|
218 } |
|
219 |
|
220 // -------------------------------------------------------------------------- |
|
221 // CTsFswClientImpl::ConstructL() |
|
222 // -------------------------------------------------------------------------- |
|
223 // |
|
224 void CTsFswClientImpl::ConstructL() |
|
225 { |
|
226 User::LeaveIfError( iClient.Connect() ); |
|
227 } |
|
228 |
|
229 // -------------------------------------------------------------------------- |
|
230 // CTsFswClientImpl::GetContentL |
|
231 // -------------------------------------------------------------------------- |
|
232 // |
|
233 void CTsFswClientImpl::GetContentL( RTsFswArray& aDst ) |
|
234 { |
|
235 iClient.GetContentL( aDst ); |
|
236 } |
|
237 |
|
238 // -------------------------------------------------------------------------- |
|
239 // CTsFswClientImpl::Subscribe |
|
240 // -------------------------------------------------------------------------- |
|
241 // |
|
242 void CTsFswClientImpl::Subscribe( MTsFswObserver& aObserver ) |
|
243 { |
|
244 Cancel(); |
|
245 iObserver = &aObserver; |
|
246 iClient.Subscribe( iStatus ); |
|
247 SetActive(); |
|
248 } |
|
249 |
|
250 // -------------------------------------------------------------------------- |
|
251 // CTsFswClientImpl::CancelSubscribe |
|
252 // -------------------------------------------------------------------------- |
|
253 // |
|
254 void CTsFswClientImpl::CancelSubscribe() |
|
255 { |
|
256 Cancel(); |
|
257 } |
|
258 |
|
259 // -------------------------------------------------------------------------- |
|
260 // CTsFswClientImpl::CloseApp |
|
261 // -------------------------------------------------------------------------- |
|
262 // |
|
263 void CTsFswClientImpl::CloseApp( TInt aWgId ) |
|
264 { |
|
265 iClient.CloseApp( aWgId ); |
|
266 } |
|
267 |
|
268 // -------------------------------------------------------------------------- |
|
269 // CTsFswClientImpl::SwitchToApp |
|
270 // -------------------------------------------------------------------------- |
|
271 // |
|
272 void CTsFswClientImpl::SwitchToApp( TInt aWgId ) |
|
273 { |
|
274 iClient.SwitchToApp( aWgId ); |
|
275 } |
|
276 |
|
277 // -------------------------------------------------------------------------- |
|
278 // CTsFswClientImpl::ForegroundAppUid |
|
279 // -------------------------------------------------------------------------- |
|
280 // |
|
281 TUid CTsFswClientImpl::ForegroundAppUid( TInt aType ) |
|
282 { |
|
283 return iClient.ForegroundAppUid( aType ); |
|
284 } |
|
285 |
|
286 // -------------------------------------------------------------------------- |
|
287 // CTsFswClientImpl::RunL |
|
288 // -------------------------------------------------------------------------- |
|
289 // |
|
290 void CTsFswClientImpl::RunL() |
|
291 { |
|
292 TSLOG_CONTEXT( RunL, TSLOG_LOCAL ); |
|
293 TSLOG1_IN( "%d", iStatus.Int() ); |
|
294 |
|
295 if ( iStatus == KErrNone && iObserver ) |
|
296 { |
|
297 iClient.Subscribe( iStatus ); |
|
298 SetActive(); |
|
299 iObserver->HandleFswContentChanged(); |
|
300 } |
|
301 |
|
302 TSLOG_OUT(); |
|
303 } |
|
304 |
|
305 // -------------------------------------------------------------------------- |
|
306 // CTsFswClientImpl::DoCancel |
|
307 // -------------------------------------------------------------------------- |
|
308 // |
|
309 void CTsFswClientImpl::DoCancel() |
|
310 { |
|
311 iClient.CancelSubscribe(); |
|
312 } |
|
313 |
|
314 |
|
315 // end of file |