|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * xSP View client-side API. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "xSPViewServices.h" |
|
22 #include "xSPViewServices_priv.h" |
|
23 |
|
24 // System includes |
|
25 #include <w32std.h> |
|
26 #include <apgtask.h> |
|
27 #include <apacmdln.h> |
|
28 #include <apgcli.h> |
|
29 #include <e32svr.h> |
|
30 |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 EXPORT_C TInt RxSPViewServices::Open() |
|
35 { |
|
36 if( Handle() != KNullHandle ) return KErrAlreadyExists; |
|
37 |
|
38 TInt err = CreateSession(KxSPServer, Version()); |
|
39 if(err == KErrNotFound) |
|
40 { |
|
41 TRAP(err, StartPhonebookL()); |
|
42 if(err == KErrNone) |
|
43 { |
|
44 err = CreateSession(KxSPServer, Version()); |
|
45 } |
|
46 } |
|
47 |
|
48 return err; |
|
49 } |
|
50 |
|
51 EXPORT_C void RxSPViewServices::Close() |
|
52 { |
|
53 RSessionBase::Close(); |
|
54 } |
|
55 |
|
56 TVersion RxSPViewServices::Version() const |
|
57 { |
|
58 return TVersion(KxSPViewServerMajor, KxSPViewServerMinor, KxSPViewServerBuild); |
|
59 } |
|
60 |
|
61 // Show the tab view from plugin aEComID with ID aOriginalViewID. |
|
62 EXPORT_C TInt RxSPViewServices::Activate(TUint32 aEComID, TInt aOriginalViewID) |
|
63 { |
|
64 TInt err = Open(); |
|
65 |
|
66 if( err == KErrAlreadyExists || err == KErrNone ) |
|
67 { |
|
68 TBool close( EFalse ); |
|
69 if( err == KErrNone ) |
|
70 { |
|
71 close = ETrue; |
|
72 } |
|
73 |
|
74 err = SendReceive( EActivateView1, TIpcArgs( aEComID, aOriginalViewID ) ); |
|
75 |
|
76 if( close ) |
|
77 { |
|
78 Close(); |
|
79 } |
|
80 } |
|
81 |
|
82 return err; |
|
83 } |
|
84 |
|
85 // Opens the detail view for a contact item |
|
86 EXPORT_C void RxSPViewServices::ActivateL( TUint32 aEComID, |
|
87 TInt aOriginalViewID, |
|
88 MVPbkContactLink* aContactLink, |
|
89 TInt aFocusedField ) |
|
90 { |
|
91 CPbk2ViewState* pbkViewParam = CPbk2ViewState::NewLC(); |
|
92 pbkViewParam->SetFocusedContact(aContactLink); |
|
93 |
|
94 pbkViewParam->SetFocusedFieldIndex(aFocusedField); |
|
95 HBufC8* paramBuf = pbkViewParam->PackLC(); |
|
96 |
|
97 TPtr8 ptr = paramBuf->Des(); |
|
98 |
|
99 User::LeaveIfError(Activate(aEComID, aOriginalViewID, ptr)); |
|
100 |
|
101 CleanupStack::PopAndDestroy(2); // paramBuf, pbkViewParam |
|
102 } |
|
103 |
|
104 // Opens the detail view for a contact item. The contact item is specified in the HBuf object, |
|
105 // which is contructed from either CPbk2ViewState on S60 3.2 or CPbkViewState. |
|
106 EXPORT_C TInt RxSPViewServices::Activate(TUint32 aEComID, TInt aOriginalViewID, TPtr8& aParamBuf) |
|
107 { |
|
108 TInt err = Open(); |
|
109 |
|
110 if( err == KErrAlreadyExists || err == KErrNone ) |
|
111 { |
|
112 TBool close( EFalse ); |
|
113 if( err == KErrNone ) |
|
114 { |
|
115 close = ETrue; |
|
116 } |
|
117 |
|
118 err = SendReceive( EActivateView2, TIpcArgs( aEComID, aOriginalViewID, &aParamBuf ) ); |
|
119 |
|
120 if( close ) |
|
121 { |
|
122 Close(); |
|
123 } |
|
124 } |
|
125 |
|
126 return err; |
|
127 } |
|
128 |
|
129 EXPORT_C void RxSPViewServices::Activate( TUint32 aEComID, |
|
130 TInt aOriginalViewID, |
|
131 TPtr8& aParamBuf, |
|
132 TRequestStatus& aStatus ) |
|
133 { |
|
134 SendReceive(EActivateView2Async, TIpcArgs(aEComID, aOriginalViewID, &aParamBuf), aStatus); |
|
135 } |
|
136 |
|
137 EXPORT_C TInt RxSPViewServices::CancelActivate() const |
|
138 { |
|
139 TInt err = SendReceive( ECancelActivateView2Async ); |
|
140 return err; |
|
141 } |
|
142 |
|
143 EXPORT_C RxSPViewServices::RxSPViewServices() : |
|
144 RSessionBase(), |
|
145 iViewCount( NULL, 0, 0 ), |
|
146 iPackedViewDataBufferLength( NULL, 0, 0 ) |
|
147 { |
|
148 } |
|
149 |
|
150 EXPORT_C TInt RxSPViewServices::Open( TInt aAsyncMessageSlots, |
|
151 TIpcSessionType aType, |
|
152 TRequestStatus& aStatus ) |
|
153 { |
|
154 if( Handle() != KNullHandle ) return KErrAlreadyExists; |
|
155 |
|
156 TInt err = CreateSession(KxSPServer, |
|
157 Version(), |
|
158 aAsyncMessageSlots, |
|
159 aType, |
|
160 NULL, |
|
161 &aStatus); |
|
162 if(err == KErrNotFound) |
|
163 { |
|
164 TRAP(err, StartPhonebookL()); |
|
165 if(err == KErrNone) |
|
166 { |
|
167 err = CreateSession(KxSPServer, |
|
168 Version(), |
|
169 aAsyncMessageSlots, |
|
170 aType, |
|
171 NULL, |
|
172 &aStatus); |
|
173 } |
|
174 } |
|
175 |
|
176 return err; |
|
177 } |
|
178 |
|
179 EXPORT_C TInt RxSPViewServices::GetViewCount( TInt& aCount ) const |
|
180 { |
|
181 TPckg<TInt> countBuf( aCount ); |
|
182 TInt err = SendReceive( EGetViewCount, TIpcArgs( &countBuf ) ); |
|
183 return err; |
|
184 } |
|
185 |
|
186 EXPORT_C TInt RxSPViewServices::GetViewCount( TInt& aCount, TRequestStatus& aStatus ) |
|
187 { |
|
188 iViewCount.Set(reinterpret_cast<TUint8*>(&aCount), sizeof(aCount), sizeof(aCount)); |
|
189 SendReceive( EGetViewCountAsync, TIpcArgs( &iViewCount ), aStatus ); |
|
190 return KErrNone; |
|
191 } |
|
192 |
|
193 EXPORT_C TInt RxSPViewServices::CancelGetViewCount() const |
|
194 { |
|
195 TInt err = SendReceive( ECancelGetViewCountAsync ); |
|
196 return err; |
|
197 } |
|
198 |
|
199 EXPORT_C TInt RxSPViewServices::GetPackedViewDataBufferLength( TInt aIndex, |
|
200 TInt& aLength ) const |
|
201 { |
|
202 TPckg<TInt> lengthBuf( aLength ); |
|
203 TInt err = SendReceive( EGetViewDataPackLength, TIpcArgs( aIndex, &lengthBuf ) ); |
|
204 return err; |
|
205 } |
|
206 |
|
207 EXPORT_C TInt RxSPViewServices::GetPackedViewDataBufferLength( TInt aIndex, |
|
208 TInt& aLength, |
|
209 TRequestStatus& aStatus ) |
|
210 { |
|
211 iPackedViewDataBufferLength.Set(reinterpret_cast<TUint8*>(&aLength), |
|
212 sizeof(aLength), |
|
213 sizeof(aLength)); |
|
214 SendReceive( EGetViewDataPackLengthAsync, |
|
215 TIpcArgs( aIndex, &iPackedViewDataBufferLength ), |
|
216 aStatus ); |
|
217 return KErrNone; |
|
218 } |
|
219 |
|
220 EXPORT_C TInt RxSPViewServices::CancelGetPackedViewDataBufferLength() const |
|
221 { |
|
222 TInt err = SendReceive( ECancelGetViewDataPackLengthAsync ); |
|
223 return err; |
|
224 } |
|
225 |
|
226 EXPORT_C TInt RxSPViewServices::GetPackedViewData( TInt aIndex, |
|
227 TDes8& aPackedViewData ) const |
|
228 { |
|
229 TInt err = SendReceive( EGetViewData, TIpcArgs( aIndex, &aPackedViewData ) ); |
|
230 return err; |
|
231 } |
|
232 |
|
233 EXPORT_C TInt RxSPViewServices::GetPackedViewData( TInt aIndex, |
|
234 TDes8& aPackedViewData, |
|
235 TRequestStatus& aStatus ) |
|
236 { |
|
237 SendReceive( EGetViewDataAsync, TIpcArgs( aIndex, &aPackedViewData ), aStatus ); |
|
238 return KErrNone; |
|
239 } |
|
240 |
|
241 EXPORT_C TInt RxSPViewServices::CancelGetPackedViewData() const |
|
242 { |
|
243 TInt err = SendReceive( ECancelGetViewDataAsync ); |
|
244 return err; |
|
245 } |
|
246 |
|
247 |
|
248 // Starts Phonebook in the background if it is not already running. |
|
249 void RxSPViewServices::StartPhonebookL() |
|
250 { |
|
251 RMutex mutex; |
|
252 TInt err = mutex.CreateGlobal(KxSPServer); |
|
253 if(err == KErrAlreadyExists) |
|
254 { |
|
255 err = mutex.OpenGlobal(KxSPServer); |
|
256 } |
|
257 User::LeaveIfError(err); |
|
258 CleanupClosePushL(mutex); |
|
259 |
|
260 mutex.Wait(); |
|
261 |
|
262 RWsSession ws; |
|
263 User::LeaveIfError(ws.Connect()); |
|
264 CleanupClosePushL(ws); |
|
265 TApaTaskList list(ws); |
|
266 TUid uid = { KUid }; |
|
267 TApaTask task(list.FindApp(uid)); |
|
268 if(!task.Exists()) |
|
269 { |
|
270 // Phonebook is not running => we are going to launch it. |
|
271 RSemaphore semaphore; |
|
272 User::LeaveIfError(semaphore.CreateGlobal(KxSPServer, 0)); |
|
273 CleanupClosePushL(semaphore); |
|
274 |
|
275 // Launch Phonebook |
|
276 CApaCommandLine* cmd = CApaCommandLine::NewLC(); |
|
277 cmd->SetExecutableNameL(KPhonebookExe); |
|
278 cmd->SetCommandL(EApaCommandBackground); |
|
279 RApaLsSession ls; |
|
280 User::LeaveIfError(ls.Connect()); |
|
281 CleanupClosePushL(ls); |
|
282 User::LeaveIfError(ls.StartApp(*cmd)); |
|
283 |
|
284 // Wait here until server has started or timeout occurs. |
|
285 semaphore.Wait(KTimeoutActivate); |
|
286 CleanupStack::PopAndDestroy(3); // ls, cmd, semaphore |
|
287 } |
|
288 CleanupStack::PopAndDestroy(); // ws |
|
289 |
|
290 mutex.Signal(); |
|
291 CleanupStack::PopAndDestroy(); // mutex |
|
292 } |
|
293 |
|
294 // End of file. |