1 /* |
|
2 * =========================================================================== |
|
3 * Name : hgfswclientimpl.cpp |
|
4 * Part of : Huriganes / Fast Swap Server |
|
5 * Description : Client API, private implementation |
|
6 * Version : %version: sa1spcx1#10 % |
|
7 * |
|
8 * Copyright © 2008 Nokia Corporation. |
|
9 * This material, including documentation and any related |
|
10 * computer programs, is protected by copyright controlled by |
|
11 * Nokia Corporation. All rights are reserved. Copying, |
|
12 * including reproducing, storing, adapting or translating, any |
|
13 * or all of this material requires the prior written consent of |
|
14 * Nokia Corporation. This material also contains confidential |
|
15 * information which may not be disclosed to others without the |
|
16 * prior written consent of Nokia Corporation. |
|
17 * =========================================================================== |
|
18 */ |
|
19 |
|
20 #include "hgfswclientimpl.h" |
|
21 #include "hgfswclientobserver.h" |
|
22 #include "hgfswcommon.h" |
|
23 #include <s32mem.h> |
|
24 |
|
25 #include "clientlogging.h" |
|
26 |
|
27 static TInt StartServer() |
|
28 { |
|
29 RProcess server; |
|
30 const TUidType uid( KNullUid, KNullUid, KHgFswServerUid ); |
|
31 TInt err = server.Create( KHgFswServerImg, KNullDesC, uid ); |
|
32 if ( err != KErrNone ) |
|
33 { |
|
34 return err; |
|
35 } |
|
36 TRequestStatus stat; |
|
37 server.Rendezvous( stat ); |
|
38 if ( stat != KRequestPending ) |
|
39 { |
|
40 server.Kill( 0 ); |
|
41 } |
|
42 else |
|
43 { |
|
44 server.Resume(); |
|
45 } |
|
46 User::WaitForRequest( stat ); |
|
47 err = server.ExitType() == EExitPanic ? KErrGeneral : stat.Int(); |
|
48 server.Close(); |
|
49 return err; |
|
50 } |
|
51 |
|
52 TInt CHgFswClientImpl::RHgFswClient::Connect() |
|
53 { |
|
54 const TInt KAsyncMessageSlots = 4; |
|
55 const TInt KMaxRetry = 4; |
|
56 |
|
57 TInt retry = KMaxRetry; |
|
58 for ( ; ; ) |
|
59 { |
|
60 TInt err = CreateSession( KHgFswServerName, TVersion( 0, 0, 0 ), KAsyncMessageSlots ); |
|
61 if ( err != KErrNotFound && err != KErrServerTerminated ) |
|
62 { |
|
63 return err; |
|
64 } |
|
65 if ( !--retry ) |
|
66 { |
|
67 return err; |
|
68 } |
|
69 err = StartServer(); |
|
70 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
71 { |
|
72 return err; |
|
73 } |
|
74 } |
|
75 } |
|
76 |
|
77 void CHgFswClientImpl::RHgFswClient::Subscribe( TRequestStatus& aStatus ) |
|
78 { |
|
79 SendReceive( EHgFswSubscribe, aStatus ); |
|
80 } |
|
81 |
|
82 void CHgFswClientImpl::RHgFswClient::CancelSubscribe() |
|
83 { |
|
84 SendReceive( EHgFswCancel ); |
|
85 } |
|
86 |
|
87 void CHgFswClientImpl::RHgFswClient::GetContentL( RHgFswArray& aDst ) |
|
88 { |
|
89 HGLOG_CONTEXT( GetContentL, HGLOG_LOCAL ); |
|
90 HGLOG_IN(); |
|
91 |
|
92 for ( ; ; ) |
|
93 { |
|
94 TPckgBuf<TInt> bufSize; |
|
95 User::LeaveIfError( SendReceive( EHgFswGetBufferSize, |
|
96 TIpcArgs( &bufSize ) ) ); |
|
97 HBufC8* buf = HBufC8::NewLC( bufSize() ); |
|
98 TPtr8 p( buf->Des() ); |
|
99 TInt err = SendReceive( EHgFswGetBuffer, |
|
100 TIpcArgs( &p, bufSize() ) ); |
|
101 if ( err == KErrNone ) |
|
102 { |
|
103 RDesReadStream strm( p ); |
|
104 CleanupClosePushL( strm ); |
|
105 CHgFswEntry::InternalizeArrayL( strm, aDst ); |
|
106 CleanupStack::PopAndDestroy( &strm ); |
|
107 } |
|
108 else if ( err != KErrArgument ) |
|
109 { |
|
110 User::Leave( err ); |
|
111 } |
|
112 CleanupStack::PopAndDestroy( buf ); |
|
113 if ( err == KErrNone ) |
|
114 { |
|
115 break; |
|
116 } |
|
117 // If result was KErrArgument then the size received from GetBufferSize is |
|
118 // not valid anymore so restart the whole procedure. |
|
119 } |
|
120 |
|
121 HGLOG_OUT(); |
|
122 } |
|
123 |
|
124 void CHgFswClientImpl::RHgFswClient::CloseApp( TInt aWgId ) |
|
125 { |
|
126 SendReceive( EHgFswCloseApp, TIpcArgs( aWgId ) ); |
|
127 } |
|
128 |
|
129 void CHgFswClientImpl::RHgFswClient::SwitchToApp( TInt aWgId ) |
|
130 { |
|
131 SendReceive( EHgFswSwitchToApp, TIpcArgs( aWgId ) ); |
|
132 } |
|
133 |
|
134 TUid CHgFswClientImpl::RHgFswClient::ForegroundAppUid( TInt aType ) |
|
135 { |
|
136 TUid result = KNullUid; |
|
137 TPckgBuf<TInt> uidBuf; |
|
138 if ( SendReceive( EHgFswForegroundAppUid, |
|
139 TIpcArgs( &uidBuf, &aType ) ) == KErrNone ) |
|
140 { |
|
141 result = TUid::Uid( uidBuf() ); |
|
142 } |
|
143 return result; |
|
144 } |
|
145 |
|
146 CHgFswClientImpl* CHgFswClientImpl::NewL() |
|
147 { |
|
148 CHgFswClientImpl* self = NewLC(); |
|
149 CleanupStack::Pop( self ); |
|
150 return self; |
|
151 } |
|
152 |
|
153 CHgFswClientImpl* CHgFswClientImpl::NewLC() |
|
154 { |
|
155 CHgFswClientImpl* self = new ( ELeave ) CHgFswClientImpl; |
|
156 CleanupStack::PushL( self ); |
|
157 self->ConstructL(); |
|
158 return self; |
|
159 } |
|
160 |
|
161 CHgFswClientImpl::CHgFswClientImpl() |
|
162 : CActive( CActive::EPriorityStandard ) |
|
163 { |
|
164 CActiveScheduler::Add( this ); |
|
165 } |
|
166 |
|
167 CHgFswClientImpl::~CHgFswClientImpl() |
|
168 { |
|
169 Cancel(); |
|
170 iClient.Close(); |
|
171 } |
|
172 |
|
173 void CHgFswClientImpl::ConstructL() |
|
174 { |
|
175 User::LeaveIfError( iClient.Connect() ); |
|
176 } |
|
177 |
|
178 void CHgFswClientImpl::GetContentL( RHgFswArray& aDst ) |
|
179 { |
|
180 iClient.GetContentL( aDst ); |
|
181 } |
|
182 |
|
183 void CHgFswClientImpl::Subscribe( MHgFswObserver& aObserver ) |
|
184 { |
|
185 Cancel(); |
|
186 iObserver = &aObserver; |
|
187 iClient.Subscribe( iStatus ); |
|
188 SetActive(); |
|
189 } |
|
190 |
|
191 void CHgFswClientImpl::CancelSubscribe() |
|
192 { |
|
193 Cancel(); |
|
194 } |
|
195 |
|
196 void CHgFswClientImpl::CloseApp( TInt aWgId ) |
|
197 { |
|
198 iClient.CloseApp( aWgId ); |
|
199 } |
|
200 |
|
201 void CHgFswClientImpl::SwitchToApp( TInt aWgId ) |
|
202 { |
|
203 iClient.SwitchToApp( aWgId ); |
|
204 } |
|
205 |
|
206 TUid CHgFswClientImpl::ForegroundAppUid( TInt aType ) |
|
207 { |
|
208 return iClient.ForegroundAppUid( aType ); |
|
209 } |
|
210 |
|
211 void CHgFswClientImpl::RunL() |
|
212 { |
|
213 HGLOG_CONTEXT( RunL, HGLOG_LOCAL ); |
|
214 HGLOG1_IN( "%d", iStatus.Int() ); |
|
215 |
|
216 if ( iStatus == KErrNone && iObserver ) |
|
217 { |
|
218 iClient.Subscribe( iStatus ); |
|
219 SetActive(); |
|
220 iObserver->HandleFswContentChanged(); |
|
221 } |
|
222 |
|
223 HGLOG_OUT(); |
|
224 } |
|
225 |
|
226 void CHgFswClientImpl::DoCancel() |
|
227 { |
|
228 iClient.CancelSubscribe(); |
|
229 } |
|
230 |
|
231 |
|
232 // end of file |
|