114
|
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 |
TUint aCmdOptions )
|
|
85 |
{
|
|
86 |
CP_DEBUG( _L8("RCPServerClient::AddL()") );
|
|
87 |
HBufC8 *inbuf = aMap.PackForServerLC( );
|
|
88 |
TInt32 id( 0);
|
|
89 |
TPckg<TInt32> sizeDes(id);
|
|
90 |
TIpcArgs args;
|
|
91 |
args.Set( KDescriptorPosition, &*inbuf );
|
|
92 |
args.Set( KReturnPosition, &sizeDes );
|
|
93 |
if( aCmdOptions & KDisablePersist )
|
|
94 |
{
|
|
95 |
User::LeaveIfError( SendReceive( ECpServerAddDataNonPersistent, args ) );
|
|
96 |
}
|
|
97 |
else
|
|
98 |
{
|
|
99 |
User::LeaveIfError( SendReceive( ECpServerAddData, args ) );
|
|
100 |
}
|
|
101 |
TLiwGenericParam param( KItemId, id);
|
|
102 |
aOutParamList.AppendL( param );
|
|
103 |
CleanupStack::PopAndDestroy( inbuf );
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
// -----------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
void RCPServerClient::GetListL( const CCPLiwMap& aMap,
|
|
113 |
CLiwGenericParamList& aOutParamList )
|
|
114 |
{
|
|
115 |
CP_DEBUG( _L8("RCPServerClient::GetListL()") );
|
|
116 |
TIpcArgs args;
|
|
117 |
HBufC8 *inbuf = aMap.PackForServerLC( );
|
|
118 |
TInt error(KErrNone);
|
|
119 |
TInt sizeList( 0);
|
|
120 |
TPckg<TInt> sizeDes(sizeList);
|
|
121 |
args.Set( KDescriptorPosition, &*inbuf );
|
|
122 |
args.Set( KReturnPosition, &sizeDes );
|
|
123 |
error = SendReceive( ECpServerGetListSize, args );
|
|
124 |
if ( error == KErrNone )
|
|
125 |
{
|
|
126 |
TIpcArgs args;
|
|
127 |
RBuf8 outbuf;
|
|
128 |
outbuf.CleanupClosePushL( );
|
|
129 |
outbuf.CreateL( sizeList );
|
|
130 |
args.Set( KDescriptorPosition, &outbuf );
|
|
131 |
error = SendReceive( ECpServerGetListData, args );
|
|
132 |
if ( error == KErrNone )
|
|
133 |
{
|
|
134 |
RDesReadStream stream(outbuf);
|
|
135 |
CleanupClosePushL( stream );
|
|
136 |
aOutParamList.InternalizeL( stream ) ;
|
|
137 |
CleanupStack::PopAndDestroy( &stream );
|
|
138 |
}
|
|
139 |
CleanupStack::PopAndDestroy( &outbuf );
|
|
140 |
}
|
|
141 |
User::LeaveIfError( error );
|
|
142 |
CleanupStack::PopAndDestroy( inbuf );
|
|
143 |
}
|
|
144 |
|
|
145 |
// -----------------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
//
|
|
149 |
void RCPServerClient::ExecuteActionL( const CCPLiwMap& aMap, TUint aOptions )
|
|
150 |
{
|
|
151 |
CP_DEBUG( _L8("RCPServerClient::ExecuteActionL()") );
|
|
152 |
HBufC8 *inbuf = aMap.PackForServerLC( );
|
|
153 |
TIpcArgs args;
|
|
154 |
args.Set( KDescriptorPosition, &*inbuf );
|
|
155 |
args.Set( KOptionsPosition, static_cast<TInt>( aOptions ) );
|
|
156 |
User::LeaveIfError( SendReceive( ECpServerExecuteAction, args ) );
|
|
157 |
CleanupStack::PopAndDestroy( inbuf );
|
|
158 |
}
|
|
159 |
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
// -----------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
void RCPServerClient::ExecuteMultipleActionsL(
|
|
165 |
const CLiwGenericParamList& aList, TUint aOptions)
|
|
166 |
{
|
|
167 |
CP_DEBUG( _L8("RCPServerClient::ExecuteMultipleActionsL()") );
|
|
168 |
TIpcArgs args;
|
|
169 |
TInt size = aList.Size();
|
|
170 |
HBufC8* datadesc = HBufC8::NewLC( size );
|
|
171 |
TPtr8 ptr = datadesc->Des();
|
|
172 |
RDesWriteStream datastrm( ptr );
|
|
173 |
CleanupClosePushL(datastrm);
|
|
174 |
aList.ExternalizeL(datastrm);
|
|
175 |
datastrm.CommitL();
|
|
176 |
args.Set( KDescriptorPosition, &*datadesc );
|
|
177 |
args.Set( KOptionsPosition, static_cast<TInt>( aOptions ) );
|
|
178 |
User::LeaveIfError(SendReceive(ECpServerExecuteMultipleActions, args));
|
|
179 |
CleanupStack::PopAndDestroy(&datastrm);
|
|
180 |
CleanupStack::PopAndDestroy(datadesc);
|
|
181 |
}
|
|
182 |
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
// -----------------------------------------------------------------------------
|
|
186 |
//
|
|
187 |
void RCPServerClient::DeleteL( const CCPLiwMap& aMap )
|
|
188 |
{
|
|
189 |
CP_DEBUG( _L8("RCPServerClient::DeleteL()") );
|
|
190 |
HBufC8 *inbuf = aMap.PackForServerLC( );
|
|
191 |
TIpcArgs args;
|
|
192 |
args.Set( KDescriptorPosition, &*inbuf );
|
|
193 |
User::LeaveIfError( SendReceive( ECpServerRemoveData, args ) );
|
|
194 |
CleanupStack::PopAndDestroy( inbuf );
|
|
195 |
}
|
|
196 |
|
|
197 |
// -----------------------------------------------------------------------------
|
|
198 |
//
|
|
199 |
// -----------------------------------------------------------------------------
|
|
200 |
//
|
|
201 |
void RCPServerClient::RegisterObserverL( TRequestStatus& aStatus,
|
|
202 |
TIpcArgs& aArgs )
|
|
203 |
{
|
|
204 |
CP_DEBUG( _L8("RCPServerClient::RegisterObserver()") );
|
|
205 |
SendReceive( ECpServerRegisterObserver, aArgs, aStatus );
|
|
206 |
}
|
|
207 |
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
// -----------------------------------------------------------------------------
|
|
211 |
//
|
|
212 |
void RCPServerClient::AddObserver( TIpcArgs& aArgs )
|
|
213 |
{
|
|
214 |
CP_DEBUG( _L8("RCPServerClient::AddObserver()") );
|
|
215 |
SendReceive( ECpServerAddObserver, aArgs );
|
|
216 |
}
|
|
217 |
|
|
218 |
// -----------------------------------------------------------------------------
|
|
219 |
//
|
|
220 |
// -----------------------------------------------------------------------------
|
|
221 |
//
|
|
222 |
void RCPServerClient::RemoveObserver( TIpcArgs& aArgs )
|
|
223 |
{
|
|
224 |
CP_DEBUG( _L8("RCPServerClient::AddObserver()") );
|
|
225 |
SendReceive( ECpServerRemoveObserver, aArgs );
|
|
226 |
}
|
|
227 |
// -----------------------------------------------------------------------------
|
|
228 |
//
|
|
229 |
// -----------------------------------------------------------------------------
|
|
230 |
//
|
|
231 |
TInt RCPServerClient::GetChangeInfoData( TDes8& aBuf )
|
|
232 |
{
|
|
233 |
CP_DEBUG( _L8("RCPServerClient::GetChangeInfoData()") );
|
|
234 |
TIpcArgs args;
|
|
235 |
args.Set( KDescriptorPosition, &aBuf );
|
|
236 |
TInt error = SendReceive( ECpServerGetChangeInfoData, args );
|
|
237 |
return error;
|
|
238 |
}
|
|
239 |
|
|
240 |
// -----------------------------------------------------------------------------
|
|
241 |
//
|
|
242 |
// -----------------------------------------------------------------------------
|
|
243 |
//
|
|
244 |
void RCPServerClient::UnregisterObserver()
|
|
245 |
{
|
|
246 |
CP_DEBUG( _L8("RCPServerClient::UnregisterObserver()") );
|
|
247 |
SendReceive( ECpServerUnRegisterObserver );
|
|
248 |
}
|
|
249 |
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
// RCPServerClient::Version
|
|
252 |
// Version information.
|
|
253 |
// -----------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
TVersion RCPServerClient::Version() const
|
|
256 |
{
|
|
257 |
CP_DEBUG( _L8("RCPServerClient::Version()") );
|
|
258 |
return (TVersion( KCPServerMajorVersionNumber,
|
|
259 |
KCPServerMinorVersionNumber, KCPServerBuildVersionNumber ) );
|
|
260 |
}
|
|
261 |
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
// StartServer
|
|
264 |
// Static method to start the server.
|
|
265 |
// -----------------------------------------------------------------------------
|
|
266 |
//
|
|
267 |
static TInt StartServer()
|
|
268 |
{
|
|
269 |
TInt result;
|
|
270 |
|
|
271 |
TFindServer findServer( KCPServerName );
|
|
272 |
TFullName name;
|
|
273 |
|
|
274 |
result = findServer.Next( name );
|
|
275 |
if ( result != KErrNone )
|
|
276 |
{
|
|
277 |
// Server not running
|
|
278 |
result = CreateServerProcess( );
|
|
279 |
}
|
|
280 |
return result;
|
|
281 |
}
|
|
282 |
|
|
283 |
// -----------------------------------------------------------------------------
|
|
284 |
// CreateServerProcess
|
|
285 |
// Static method to create the server process.
|
|
286 |
// -----------------------------------------------------------------------------
|
|
287 |
//
|
|
288 |
static TInt CreateServerProcess()
|
|
289 |
{
|
|
290 |
CP_DEBUG( _L8("RCPServerClient::CreateServerProcess()") );
|
|
291 |
const TUidType serverUid( KNullUid, KNullUid, KServerUid3);
|
|
292 |
RProcess server;
|
|
293 |
TInt result;
|
|
294 |
result = server.Create( KCPServerFilename, KNullDesC, serverUid );
|
|
295 |
if ( result == KErrNone )
|
|
296 |
{
|
|
297 |
TRequestStatus stat = KRequestPending;
|
|
298 |
server.Rendezvous( stat );
|
|
299 |
if ( stat != KRequestPending )
|
|
300 |
{
|
|
301 |
server.Kill( 0 ); // abort startup
|
|
302 |
}
|
|
303 |
else
|
|
304 |
{
|
|
305 |
server.Resume( ); // logon OK - start the server
|
|
306 |
}
|
|
307 |
|
|
308 |
User::WaitForRequest( stat ); // wait for start or death
|
|
309 |
// we can't use the 'exit reason' if the server panicked as this
|
|
310 |
// is the panic 'reason' and may be '0' which cannot be distinguished
|
|
311 |
// from KErrNone
|
|
312 |
result = (server.ExitType( ) == EExitPanic ) ? KErrGeneral
|
|
313 |
: stat.Int( );
|
|
314 |
}
|
|
315 |
server.Close( );
|
|
316 |
return result;
|
|
317 |
}
|