|
1 /* |
|
2 * Copyright (c) 2007 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 * |
|
16 */ |
|
17 |
|
18 #include "cautils.h" |
|
19 #include "caclientsession.h" |
|
20 #include "caclientsubsession.h" |
|
21 #include "caclientproxy.h" |
|
22 #include "cainnerentry.h" |
|
23 #include "cainnerquery.h" |
|
24 #include "caidsarray.h" |
|
25 #include "caentriesarray.h" |
|
26 #include "caclientnotifierproxy.h" |
|
27 |
|
28 const TInt KInnerEntryExpandSize = 1024; |
|
29 |
|
30 // Function prototypes |
|
31 static TInt StartServer(); |
|
32 static TInt CreateServerProcess(); |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 // ----------------------------------------------------------------------------- |
|
39 RCaClientSession::RCaClientSession() : |
|
40 RSessionBase() |
|
41 { |
|
42 // No implementation required |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 // ----------------------------------------------------------------------------- |
|
48 TInt RCaClientSession::Connect() |
|
49 { |
|
50 TInt error = |
|
51 CreateSession( KCaSrvName, Version() ); |
|
52 if( error == KErrNone ) |
|
53 { |
|
54 ShareAuto(); |
|
55 } |
|
56 return error; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 // ----------------------------------------------------------------------------- |
|
62 TInt RCaClientSession::StartServer() |
|
63 { |
|
64 return ::StartServer(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 // ----------------------------------------------------------------------------- |
|
70 void RCaClientSession::Close() |
|
71 { |
|
72 RSessionBase::Close(); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 TVersion RCaClientSession::Version() const |
|
79 { |
|
80 return ( TVersion( KCaMajorVersion, KCaMinorVersion, KCaBuild ) ); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 // ----------------------------------------------------------------------------- |
|
86 void RCaClientSession::GetListL( const CCaInnerQuery& aQuery, |
|
87 RCaEntriesArray& aResult ) |
|
88 { |
|
89 TInt resultSize(0); |
|
90 TInt error = GetSizeL( aQuery, EContentArsenalGetList_GetSize, |
|
91 resultSize ); |
|
92 |
|
93 if( error == KErrNone ) |
|
94 { |
|
95 error = GetResultL( resultSize, EContentArsenalGetList_GetData, |
|
96 aResult ); |
|
97 } |
|
98 |
|
99 User::LeaveIfError( error ); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 // ----------------------------------------------------------------------------- |
|
105 void RCaClientSession::GetEntryIdsL( const CCaInnerQuery& aQuery, |
|
106 RCaIdsArray& aResult ) |
|
107 { |
|
108 TInt resultSize( 0 ); |
|
109 TInt error = GetSizeL( aQuery, EContentArsenalGetIds_GetSize, |
|
110 resultSize ); |
|
111 |
|
112 if( error == KErrNone ) |
|
113 { |
|
114 error = GetResultL( resultSize, EContentArsenalGetIds_GetData, |
|
115 aResult ); |
|
116 } |
|
117 |
|
118 User::LeaveIfError( error ); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 // ----------------------------------------------------------------------------- |
|
124 TInt RCaClientSession::GetSizeL( const CCaInnerQuery& aQuery, |
|
125 const TCaServerRequests aServerRequest, TInt& aResultSize ) |
|
126 { |
|
127 TIpcArgs args; |
|
128 HBufC8* serializedQuery = MenuUtils::MarshalDataL( aQuery, 128 ); |
|
129 CleanupStack::PushL( serializedQuery ); |
|
130 args.Set( KInputPosition1, serializedQuery ); |
|
131 TPckg<TInt> sizeDes( aResultSize ); |
|
132 args.Set( KOutputPosition, &sizeDes ); |
|
133 TInt error = SendReceive( aServerRequest, args ); |
|
134 CleanupStack::PopAndDestroy( serializedQuery ); |
|
135 return error; |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 // ----------------------------------------------------------------------------- |
|
141 void RCaClientSession::AddL( CCaInnerEntry& aEntry ) |
|
142 { |
|
143 TIpcArgs args; |
|
144 HBufC8* serializedEntry = MenuUtils::MarshalDataL( aEntry, KInnerEntryExpandSize ); |
|
145 CleanupStack::PushL( serializedEntry ); |
|
146 args.Set( KInputPosition1, serializedEntry ); |
|
147 TInt id( 0 ); |
|
148 TPckg<TInt> resultId( id ); |
|
149 args.Set( KOutputPosition, &resultId ); |
|
150 |
|
151 TInt error = SendReceive( EContentArsenalAdd, args ); |
|
152 User::LeaveIfError( error ); |
|
153 aEntry.SetId( id ); |
|
154 |
|
155 CleanupStack::PopAndDestroy( serializedEntry ); |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 // ----------------------------------------------------------------------------- |
|
161 void RCaClientSession::RemoveL( const RCaIdsArray& aEntries ) |
|
162 { |
|
163 TIpcArgs args; |
|
164 HBufC8* inbuf = aEntries.MarshalDataLC(); |
|
165 args.Set( KInputPosition1, inbuf ); |
|
166 User::LeaveIfError( SendReceive( EContentArsenalRemove, args ) ); |
|
167 CleanupStack::PopAndDestroy( inbuf ); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 // ----------------------------------------------------------------------------- |
|
173 void RCaClientSession::OrganizeL( const RCaIdsArray& aEntries, |
|
174 TCaOperationParams aParams ) |
|
175 { |
|
176 TIpcArgs args; |
|
177 HBufC8* inbuf = aEntries.MarshalDataLC(); |
|
178 args.Set( KInputPosition1, inbuf ); |
|
179 TPckg<TCaOperationParams> data( aParams ); |
|
180 args.Set( KInputPosition2, &data ); |
|
181 User::LeaveIfError( SendReceive( EContentArsenalOrganize, args ) ); |
|
182 CleanupStack::PopAndDestroy( inbuf ); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 // ----------------------------------------------------------------------------- |
|
188 void RCaClientSession::TouchL( const CCaInnerEntry& aEntry ) |
|
189 { |
|
190 TIpcArgs args; |
|
191 HBufC8* serializedEntry = MenuUtils::MarshalDataL( aEntry, KInnerEntryExpandSize ); |
|
192 CleanupStack::PushL( serializedEntry ); |
|
193 args.Set( KInputPosition1, serializedEntry ); |
|
194 |
|
195 User::LeaveIfError( SendReceive( EContentArsenalTouch, args ) ); |
|
196 |
|
197 CleanupStack::PopAndDestroy( serializedEntry ); |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 // ----------------------------------------------------------------------------- |
|
203 void RCaClientSession::CustomSortL( const RCaIdsArray& aEntries, |
|
204 const TInt aGroupId ) |
|
205 { |
|
206 TIpcArgs args; |
|
207 HBufC8* inbuf = aEntries.MarshalDataLC(); |
|
208 args.Set( KInputPosition1, inbuf ); |
|
209 TPckg<TInt> groupId( aGroupId ); |
|
210 args.Set( KInputPosition2, &groupId ); |
|
211 User::LeaveIfError( SendReceive( EContentArsenalCustomSort, args ) ); |
|
212 CleanupStack::PopAndDestroy( inbuf ); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 // ----------------------------------------------------------------------------- |
|
218 template<typename SerializableObject> |
|
219 TInt RCaClientSession::GetResultL( TInt aSize, TCaServerRequests aRequest, |
|
220 SerializableObject& aObject ) |
|
221 { |
|
222 TIpcArgs args; |
|
223 RBuf8 outbuf; |
|
224 outbuf.CleanupClosePushL(); |
|
225 outbuf.CreateL( aSize ); |
|
226 args.Set( KOutputPosition, &outbuf ); |
|
227 TInt error = SendReceive( aRequest, args ); |
|
228 if( error == KErrNone ) |
|
229 { |
|
230 RDesReadStream stream( outbuf ); |
|
231 CleanupClosePushL( stream ); |
|
232 aObject.InternalizeL( stream ); |
|
233 CleanupStack::PopAndDestroy( &stream ); |
|
234 } |
|
235 CleanupStack::PopAndDestroy( &outbuf ); |
|
236 return error; |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // StartServer |
|
241 // Static function to start the server. |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 static TInt StartServer() |
|
245 { |
|
246 TInt result; |
|
247 |
|
248 TFindServer findServer( KCaSrvName ); |
|
249 TFullName name; |
|
250 |
|
251 result = findServer.Next( name ); |
|
252 if( result != KErrNone ) |
|
253 { |
|
254 // Server not running |
|
255 result = CreateServerProcess(); |
|
256 } |
|
257 return result; |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CreateServerProcess |
|
262 // Static function to create the server process. |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 static TInt CreateServerProcess() |
|
266 { |
|
267 TInt err( KErrNone ); |
|
268 RProcess server; |
|
269 err = server.Create( KCaSrvExe, KNullDesC, EOwnerThread ); |
|
270 if( !err ) |
|
271 { |
|
272 TRequestStatus status; |
|
273 server.Rendezvous( status ); |
|
274 if( status != KRequestPending ) |
|
275 { |
|
276 server.Kill( 0 ); // Abort startup. |
|
277 } |
|
278 else |
|
279 { |
|
280 server.Resume(); // Logon OK - start the server. |
|
281 } |
|
282 User::WaitForRequest( status ); // Wait for start or death. |
|
283 // We can't use the 'exit reason' if the server panicked as this |
|
284 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
285 // from KErrNone. |
|
286 err = ( server.ExitType() == EExitPanic ) ? KErrGeneral |
|
287 : status.Int(); |
|
288 server.Close(); |
|
289 } |
|
290 return err; |
|
291 } |
|
292 |