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 |
|
19 #include <s32mem.h> |
|
20 #include <liwcommon.h> |
|
21 |
|
22 #include "cpserverdef.h" |
|
23 #include "cpliwmap.h" |
|
24 #include "cpclientsession.h" |
|
25 #include "cpglobals.h" |
|
26 #include "cpdebug.h" |
|
27 #include "cpclientactivenotifier.h" |
|
28 |
|
29 // Number of message slots to reserve for this client server session. |
|
30 const TUint KDefaultMessageSlots( 1 ); |
|
31 |
|
32 // Function prototypes |
|
33 static TInt StartServer(); |
|
34 static TInt CreateServerProcess(); |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // RCPServerClient::RCPServerClient |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 RCPServerClient::RCPServerClient() : |
|
45 RSessionBase() |
|
46 { |
|
47 // No implementation required |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // RCPServerClient::Connect |
|
52 // Connect to Content publisher server session. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 TInt RCPServerClient::Connect() |
|
56 { |
|
57 TInt error =:: StartServer(); |
|
58 |
|
59 if ( error == KErrNone ) |
|
60 { |
|
61 error = CreateSession( KCPServerName, |
|
62 Version(), |
|
63 KDefaultMessageSlots ); |
|
64 } |
|
65 return error; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 // |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void RCPServerClient::Close() |
|
74 { |
|
75 RSessionBase::Close( ); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void RCPServerClient::AddL( const CCPLiwMap& aMap, |
|
83 CLiwGenericParamList& aOutParamList ) |
|
84 { |
|
85 CP_DEBUG( _L8("RCPServerClient::AddL()") ); |
|
86 HBufC8 *inbuf = aMap.PackForServerLC( ); |
|
87 TInt32 id( 0); |
|
88 TPckg<TInt32> sizeDes(id); |
|
89 TIpcArgs args; |
|
90 args.Set( KDescriptorPosition, &*inbuf ); |
|
91 args.Set( KReturnPosition, &sizeDes ); |
|
92 User::LeaveIfError( SendReceive( ECpServerAddData, args ) ); |
|
93 TLiwGenericParam param( KItemId, id); |
|
94 aOutParamList.AppendL( param ); |
|
95 CleanupStack::PopAndDestroy( inbuf ); |
|
96 } |
|
97 |
|
98 |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void RCPServerClient::GetListL( const CCPLiwMap& aMap, |
|
105 CLiwGenericParamList& aOutParamList ) |
|
106 { |
|
107 CP_DEBUG( _L8("RCPServerClient::GetListL()") ); |
|
108 TIpcArgs args; |
|
109 HBufC8 *inbuf = aMap.PackForServerLC( ); |
|
110 TInt error(KErrNone); |
|
111 TInt sizeList( 0); |
|
112 TPckg<TInt> sizeDes(sizeList); |
|
113 args.Set( KDescriptorPosition, &*inbuf ); |
|
114 args.Set( KReturnPosition, &sizeDes ); |
|
115 error = SendReceive( ECpServerGetListSize, args ); |
|
116 if ( error == KErrNone ) |
|
117 { |
|
118 TIpcArgs args; |
|
119 RBuf8 outbuf; |
|
120 outbuf.CleanupClosePushL( ); |
|
121 outbuf.CreateL( sizeList ); |
|
122 args.Set( KDescriptorPosition, &outbuf ); |
|
123 error = SendReceive( ECpServerGetListData, args ); |
|
124 if ( error == KErrNone ) |
|
125 { |
|
126 RDesReadStream stream(outbuf); |
|
127 CleanupClosePushL( stream ); |
|
128 aOutParamList.InternalizeL( stream ) ; |
|
129 CleanupStack::PopAndDestroy( &stream ); |
|
130 } |
|
131 CleanupStack::PopAndDestroy( &outbuf ); |
|
132 } |
|
133 User::LeaveIfError( error ); |
|
134 CleanupStack::PopAndDestroy( inbuf ); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void RCPServerClient::ExecuteActionL( const CCPLiwMap& aMap ) |
|
142 { |
|
143 CP_DEBUG( _L8("RCPServerClient::ExecuteActionL()") ); |
|
144 HBufC8 *inbuf = aMap.PackForServerLC( ); |
|
145 TIpcArgs args; |
|
146 args.Set( KDescriptorPosition, &*inbuf ); |
|
147 User::LeaveIfError( SendReceive( ECpServerExecuteAction, args ) ); |
|
148 CleanupStack::PopAndDestroy( inbuf ); |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void RCPServerClient::DeleteL( const CCPLiwMap& aMap ) |
|
156 { |
|
157 CP_DEBUG( _L8("RCPServerClient::DeleteL()") ); |
|
158 HBufC8 *inbuf = aMap.PackForServerLC( ); |
|
159 TIpcArgs args; |
|
160 args.Set( KDescriptorPosition, &*inbuf ); |
|
161 User::LeaveIfError( SendReceive( ECpServerRemoveData, args ) ); |
|
162 CleanupStack::PopAndDestroy( inbuf ); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void RCPServerClient::RegisterObserverL( TRequestStatus& aStatus, |
|
170 TIpcArgs& aArgs ) |
|
171 { |
|
172 CP_DEBUG( _L8("RCPServerClient::RegisterObserver()") ); |
|
173 SendReceive( ECpServerRegisterObserver, aArgs, aStatus ); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void RCPServerClient::AddObserver( TIpcArgs& aArgs ) |
|
181 { |
|
182 CP_DEBUG( _L8("RCPServerClient::AddObserver()") ); |
|
183 SendReceive( ECpServerAddObserver, aArgs ); |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void RCPServerClient::RemoveObserver( TIpcArgs& aArgs ) |
|
191 { |
|
192 CP_DEBUG( _L8("RCPServerClient::AddObserver()") ); |
|
193 SendReceive( ECpServerRemoveObserver, aArgs ); |
|
194 } |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 TInt RCPServerClient::GetChangeInfoData( TDes8& aBuf ) |
|
200 { |
|
201 CP_DEBUG( _L8("RCPServerClient::GetChangeInfoData()") ); |
|
202 TIpcArgs args; |
|
203 args.Set( KDescriptorPosition, &aBuf ); |
|
204 TInt error = SendReceive( ECpServerGetChangeInfoData, args ); |
|
205 return error; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void RCPServerClient::UnregisterObserver() |
|
213 { |
|
214 CP_DEBUG( _L8("RCPServerClient::UnregisterObserver()") ); |
|
215 SendReceive( ECpServerUnRegisterObserver ); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // RCPServerClient::Version |
|
220 // Version information. |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 TVersion RCPServerClient::Version() const |
|
224 { |
|
225 CP_DEBUG( _L8("RCPServerClient::Version()") ); |
|
226 return (TVersion( KCPServerMajorVersionNumber, |
|
227 KCPServerMinorVersionNumber, KCPServerBuildVersionNumber ) ); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // StartServer |
|
232 // Static method to start the server. |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 static TInt StartServer() |
|
236 { |
|
237 TInt result; |
|
238 |
|
239 TFindServer findServer( KCPServerName ); |
|
240 TFullName name; |
|
241 |
|
242 result = findServer.Next( name ); |
|
243 if ( result != KErrNone ) |
|
244 { |
|
245 // Server not running |
|
246 result = CreateServerProcess( ); |
|
247 } |
|
248 return result; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CreateServerProcess |
|
253 // Static method to create the server process. |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 static TInt CreateServerProcess() |
|
257 { |
|
258 CP_DEBUG( _L8("RCPServerClient::CreateServerProcess()") ); |
|
259 const TUidType serverUid( KNullUid, KNullUid, KServerUid3); |
|
260 RProcess server; |
|
261 TInt result; |
|
262 result = server.Create( KCPServerFilename, KNullDesC, serverUid ); |
|
263 if ( result == KErrNone ) |
|
264 { |
|
265 TRequestStatus stat = KRequestPending; |
|
266 server.Rendezvous( stat ); |
|
267 if ( stat != KRequestPending ) |
|
268 { |
|
269 server.Kill( 0 ); // abort startup |
|
270 } |
|
271 else |
|
272 { |
|
273 server.Resume( ); // logon OK - start the server |
|
274 } |
|
275 |
|
276 User::WaitForRequest( stat ); // wait for start or death |
|
277 // we can't use the 'exit reason' if the server panicked as this |
|
278 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
279 // from KErrNone |
|
280 result = (server.ExitType( ) == EExitPanic ) ? KErrGeneral |
|
281 : stat.Int( ); |
|
282 } |
|
283 server.Close( ); |
|
284 return result; |
|
285 } |
|