1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/centralrepository/cenrepcli/clirep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,768 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "clirep.h"
1.20 +#include <e32math.h>
1.21 +#include "srvparams.h"
1.22 +#include "srvreqs.h"
1.23 +
1.24 +using namespace NCentralRepositoryConstants;
1.25 +
1.26 +RRepositorySession* CClientRepository::Session()
1.27 + {
1.28 + return static_cast<RRepositorySession*>(Dll::Tls());
1.29 + }
1.30 +
1.31 +CClientRepository* CClientRepository::NewLC(TUid aRepositoryUid)
1.32 + {
1.33 + CClientRepository* rep = new(ELeave) CClientRepository();
1.34 + CleanupStack::PushL(rep);
1.35 + rep->ConstructL(aRepositoryUid);
1.36 + return rep;
1.37 + }
1.38 +
1.39 +void CClientRepository::ConstructL(TUid aRepositoryUid)
1.40 + {
1.41 + RRepositorySession* session = Session();
1.42 +
1.43 + if(session == NULL)
1.44 + {
1.45 + session = new (ELeave) RRepositorySession();
1.46 + CleanupStack::PushL(session);
1.47 + User::LeaveIfError(Dll::SetTls(session));
1.48 + CleanupStack::Pop(session);
1.49 + User::LeaveIfError(session->Connect());
1.50 + }
1.51 + else
1.52 + {
1.53 + session->IncrementSubSessionCounter();
1.54 + }
1.55 +
1.56 + iSubSession = new (ELeave) RRepositorySubSession();
1.57 + User::LeaveIfError(iSubSession->Open(session, EInitialise, TIpcArgs(aRepositoryUid.iUid)));
1.58 + }
1.59 +
1.60 +CClientRepository::CClientRepository()
1.61 + {
1.62 + }
1.63 +
1.64 +CClientRepository::~CClientRepository()
1.65 + {
1.66 + if(iSubSession)
1.67 + {
1.68 + iSubSession->Close();
1.69 + delete iSubSession;
1.70 + }
1.71 + RRepositorySession* session = Session();
1.72 + if(session && session->DecrementSubSessionCounter() == 0)
1.73 + {
1.74 + //The last subSesssion is closed. Time to close the session.
1.75 + session->Close();
1.76 + delete session;
1.77 + Dll::FreeTls();
1.78 + //SetSession(NULL);
1.79 + }
1.80 + }
1.81 +
1.82 +TInt CClientRepository::Create(TUint32 aId, TInt aVal)
1.83 + {
1.84 + return iSubSession->SendReceive(ECreateInt, TIpcArgs(aId, aVal));
1.85 + }
1.86 +
1.87 +TInt CClientRepository::Create(TUint32 aId, const TReal& aVal)
1.88 + {
1.89 + TPckg<TReal> p(aVal);
1.90 + return iSubSession->SendReceive(ECreateReal, TIpcArgs(aId, &p));
1.91 + }
1.92 +
1.93 +TInt CClientRepository::Create(TUint32 aId, const TDesC8& aVal)
1.94 + {
1.95 + return iSubSession->SendReceive(ECreateString, TIpcArgs(aId, &aVal));
1.96 + }
1.97 +
1.98 +TInt CClientRepository::Create(TUint32 aId, const TDesC16& aVal)
1.99 + {
1.100 + TPtrC8 ptr8((const TUint8*)aVal.Ptr(), aVal.Size());
1.101 + return iSubSession->SendReceive(ECreateString, TIpcArgs(aId, &ptr8));
1.102 + }
1.103 +
1.104 +TInt CClientRepository::Delete(TUint32 aId)
1.105 + {
1.106 + return iSubSession->SendReceive(EDelete, TIpcArgs(aId));
1.107 + }
1.108 +
1.109 +TInt CClientRepository::Delete(TUint32 aPartialKey, TUint32 aMask, TUint32 &aErrorKey)
1.110 + {
1.111 + aErrorKey = KUnspecifiedKey; // set in case not filled by server
1.112 + TPckg<TUint32> p(aErrorKey);
1.113 + return iSubSession->SendReceive(EDeleteRange, TIpcArgs(aPartialKey, aMask, &p));
1.114 + }
1.115 +
1.116 +TInt CClientRepository::Get(TUint32 aId, TInt& aVal)
1.117 + {
1.118 + TPckg<TInt> p(aVal);
1.119 + return iSubSession->SendReceive(EGetInt, TIpcArgs(aId, &p));
1.120 + }
1.121 +
1.122 +TInt CClientRepository::Set(TUint32 aId, TInt aVal)
1.123 + {
1.124 + return iSubSession->SendReceive(ESetInt, TIpcArgs(aId, aVal));
1.125 + }
1.126 +
1.127 +TInt CClientRepository::Get(TUint32 aId, TReal& aVal)
1.128 + {
1.129 + TPckg<TReal> p(aVal);
1.130 + return iSubSession->SendReceive(EGetReal, TIpcArgs(aId, &p));
1.131 + }
1.132 +
1.133 +TInt CClientRepository::Set(TUint32 aId, const TReal& aVal)
1.134 + {
1.135 + TPckg<TReal> p(aVal);
1.136 + return iSubSession->SendReceive(ESetReal, TIpcArgs(aId, &p));
1.137 + }
1.138 +
1.139 +TInt CClientRepository::Get(TUint32 aId, TDes8& aVal)
1.140 + {
1.141 + TPckg<TInt> p(aVal.MaxLength());
1.142 + return iSubSession->SendReceive(EGetString, TIpcArgs(aId, &aVal, &p));
1.143 + }
1.144 +
1.145 +TInt CClientRepository::Get(TUint32 aId, TDes8& aVal, TInt& aActualLen)
1.146 + {
1.147 + aActualLen = aVal.MaxLength();
1.148 + TPckg<TInt> p(aActualLen);
1.149 + return iSubSession->SendReceive(EGetString, TIpcArgs(aId, &aVal, &p));
1.150 + }
1.151 +
1.152 +TInt CClientRepository::Set(TUint32 aId, const TDesC8& aVal)
1.153 + {
1.154 + return iSubSession->SendReceive(ESetString, TIpcArgs(aId, &aVal));
1.155 + }
1.156 +
1.157 +TInt CClientRepository::Get(TUint32 aId, TDes& aVal)
1.158 + {
1.159 + TPtr8 ptr8((TUint8*)aVal.Ptr(), 0, aVal.MaxSize());
1.160 +
1.161 + TPckg<TInt> p(ptr8.MaxLength());
1.162 +
1.163 + TInt r = iSubSession->SendReceive(EGetString, TIpcArgs(aId, &ptr8, &p));
1.164 +
1.165 + if(r==KErrNone || r==KErrOverflow)
1.166 + {
1.167 + TInt len = ptr8.Length();
1.168 + // note the following handles the case where client is getting an odd-length 8-bit
1.169 + // descriptor into 16-bit aVal. Round up length and ensure the extra byte is zero.
1.170 + if(len&1)
1.171 + {
1.172 + ptr8.SetLength(len+1); // set the length before trying to write the value
1.173 + ptr8[len] = 0;
1.174 + }
1.175 + aVal.SetLength((len + 1)/2);
1.176 + }
1.177 +
1.178 + return r;
1.179 + }
1.180 +
1.181 +TInt CClientRepository::Get(TUint32 aId, TDes& aVal, TInt& aActualLen)
1.182 + {
1.183 + TPtr8 ptr8((TUint8*)aVal.Ptr(), 0, aVal.MaxSize());
1.184 +
1.185 + aActualLen = ptr8.MaxLength();
1.186 + TPckg<TInt> p(aActualLen);
1.187 +
1.188 + TInt r = iSubSession->SendReceive(EGetString, TIpcArgs(aId, &ptr8, &p));
1.189 +
1.190 + if(r==KErrNone || r==KErrOverflow)
1.191 + {
1.192 + TInt len = ptr8.Length();
1.193 + // note the following handles the case where client is getting an odd-length 8-bit
1.194 + // descriptor into 16-bit aVal. Round up length and ensure the extra byte is zero.
1.195 + if(len&1)
1.196 + {
1.197 + ptr8.SetLength(len+1); // set the length before trying to write the value
1.198 + ptr8[len] = 0;
1.199 + }
1.200 + aVal.SetLength((len + 1)/2);
1.201 + aActualLen = ((aActualLen + 1)/2);
1.202 + }
1.203 +
1.204 + return r;
1.205 + }
1.206 +
1.207 +TInt CClientRepository::Set(TUint32 aId, const TDesC& aVal)
1.208 + {
1.209 + TPtrC8 ptr8((const TUint8*)aVal.Ptr(), aVal.Size());
1.210 + return iSubSession->SendReceive(ESetString, TIpcArgs(aId, &ptr8));
1.211 + }
1.212 +
1.213 +TInt CClientRepository::GetMeta(TUint32 aId, TUint32& aMeta)
1.214 + {
1.215 + TPckg<TUint32> p(aMeta);
1.216 + return iSubSession->SendReceive(EGetMeta, TIpcArgs(aId, &p));
1.217 + }
1.218 +
1.219 +TInt CClientRepository::Move(TUint32 aSourcePartialId, TUint32 aTargetPartialId,
1.220 + TUint32 aIdMask, TUint32 &aErrorId)
1.221 + {
1.222 + aErrorId = KUnspecifiedKey; // set in case not filled by server
1.223 + TPckg<TUint32> p(aErrorId);
1.224 + TKeyFilter srcKeyIdentifier = {aSourcePartialId, aIdMask};
1.225 + TKeyFilter tgtKeyIdentifier = {aTargetPartialId, aIdMask};
1.226 + TPckg<TKeyFilter> pSrc(srcKeyIdentifier);
1.227 + TPckg<TKeyFilter> pTrg(tgtKeyIdentifier);
1.228 +
1.229 + TInt r = iSubSession->SendReceive(EMove, TIpcArgs(&pSrc, &pTrg, &p));
1.230 +
1.231 + return r;
1.232 + }
1.233 +
1.234 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.235 +//operations valid in transactions.
1.236 +TInt CClientRepository::FindL(TUint32 aPartialId, TUint32 aIdMask,
1.237 + RArray<TUint32>& aFoundIds)
1.238 + {
1.239 + CleanupFailTransactionPushL();
1.240 + aFoundIds.Reset();
1.241 +
1.242 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.243 + TUint32* start = uids.Begin();
1.244 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.245 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.246 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.247 +
1.248 + TInt r = iSubSession->SendReceive(EFind, TIpcArgs(&pIdentifier, 0, &ptr));
1.249 +
1.250 + if(r == KErrNone)
1.251 + {
1.252 + r = GetFindResult(uids, aFoundIds);
1.253 + if (r==KErrNoMemory)
1.254 + User::LeaveNoMemory();
1.255 + }
1.256 +
1.257 + CleanupStack::Pop();
1.258 +
1.259 + return r;
1.260 + }
1.261 +
1.262 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.263 +//operations valid in transactions.
1.264 +TInt CClientRepository::FindEqL(TUint32 aPartialId, TUint32 aIdMask, TInt aVal,
1.265 + RArray<TUint32>& aFoundIds)
1.266 + {
1.267 + CleanupFailTransactionPushL();
1.268 + aFoundIds.Reset();
1.269 +
1.270 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.271 + TUint32* start = uids.Begin();
1.272 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.273 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.274 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.275 +
1.276 + TInt r = iSubSession->SendReceive(EFindEqInt, TIpcArgs(&pIdentifier, aVal, &ptr));
1.277 +
1.278 + if(r == KErrNone)
1.279 + {
1.280 + r = GetFindResult(uids, aFoundIds);
1.281 + if (r==KErrNoMemory)
1.282 + User::LeaveNoMemory();
1.283 + }
1.284 +
1.285 + CleanupStack::Pop();
1.286 +
1.287 + return r;
1.288 + }
1.289 +
1.290 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.291 +//operations valid in transactions.
1.292 +TInt CClientRepository::FindEqL(TUint32 aPartialId, TUint32 aIdMask,
1.293 + const TReal& aVal, RArray<TUint32>& aFoundIds)
1.294 + {
1.295 + CleanupFailTransactionPushL();
1.296 + aFoundIds.Reset();
1.297 +
1.298 + TPckg<TReal> pVal(aVal);
1.299 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.300 + TUint32* start = uids.Begin();
1.301 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.302 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.303 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.304 +
1.305 + TInt r = iSubSession->SendReceive(EFindEqReal, TIpcArgs(&pIdentifier, &pVal, &ptr));
1.306 +
1.307 + if(r == KErrNone)
1.308 + {
1.309 + r = GetFindResult(uids, aFoundIds);
1.310 + if (r==KErrNoMemory)
1.311 + User::LeaveNoMemory();
1.312 + }
1.313 +
1.314 + CleanupStack::Pop();
1.315 +
1.316 + return r;
1.317 + }
1.318 +
1.319 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.320 +//operations valid in transactions.
1.321 +TInt CClientRepository::FindEqL(TUint32 aPartialId, TUint32 aIdMask,
1.322 + const TDesC8& aVal, RArray<TUint32>& aFoundIds)
1.323 + {
1.324 + CleanupFailTransactionPushL();
1.325 + aFoundIds.Reset();
1.326 +
1.327 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.328 + TUint32* start = uids.Begin();
1.329 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.330 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.331 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.332 +
1.333 + TInt r = iSubSession->SendReceive(EFindEqString, TIpcArgs(&pIdentifier, &aVal, &ptr));
1.334 +
1.335 + if(r == KErrNone)
1.336 + {
1.337 + r = GetFindResult(uids, aFoundIds);
1.338 + if (r==KErrNoMemory)
1.339 + User::LeaveNoMemory();
1.340 + }
1.341 +
1.342 + CleanupStack::Pop();
1.343 +
1.344 + return r;
1.345 + }
1.346 +
1.347 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.348 +//operations valid in transactions.
1.349 +TInt CClientRepository::FindEqL(TUint32 aPartialId, TUint32 aIdMask,
1.350 + const TDesC& aVal, RArray<TUint32>& aFoundIds)
1.351 + {
1.352 + CleanupFailTransactionPushL();
1.353 + aFoundIds.Reset();
1.354 +
1.355 + TPtrC8 pVal((const TUint8*)aVal.Ptr(), aVal.Length()*2);
1.356 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.357 + TUint32* start = uids.Begin();
1.358 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.359 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.360 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.361 +
1.362 + TInt r = iSubSession->SendReceive(EFindEqString, TIpcArgs(&pIdentifier, &pVal, &ptr));
1.363 +
1.364 + if(r == KErrNone)
1.365 + {
1.366 + r = GetFindResult(uids, aFoundIds);
1.367 + if (r==KErrNoMemory)
1.368 + User::LeaveNoMemory();
1.369 + }
1.370 +
1.371 + CleanupStack::Pop();
1.372 +
1.373 + return r;
1.374 + }
1.375 +
1.376 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.377 +//operations valid in transactions.
1.378 +TInt CClientRepository::FindNeqL(TUint32 aPartialId, TUint32 aIdMask,
1.379 + TInt aVal, RArray<TUint32>& aFoundIds)
1.380 + {
1.381 + CleanupFailTransactionPushL();
1.382 + aFoundIds.Reset();
1.383 +
1.384 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.385 + TUint32* start = uids.Begin();
1.386 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.387 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.388 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.389 +
1.390 + TInt r = iSubSession->SendReceive(EFindNeqInt, TIpcArgs(&pIdentifier, aVal, &ptr));
1.391 +
1.392 + if(r == KErrNone)
1.393 + {
1.394 + r = GetFindResult(uids, aFoundIds);
1.395 + if (r==KErrNoMemory)
1.396 + User::LeaveNoMemory();
1.397 + }
1.398 +
1.399 + CleanupStack::Pop();
1.400 +
1.401 + return r;
1.402 + }
1.403 +
1.404 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.405 +//operations valid in transactions.
1.406 +TInt CClientRepository::FindNeqL(TUint32 aPartialId, TUint32 aIdMask,
1.407 + const TReal& aVal, RArray<TUint32>& aFoundIds)
1.408 + {
1.409 + CleanupFailTransactionPushL();
1.410 + aFoundIds.Reset();
1.411 +
1.412 + TPckg<TReal> pVal(aVal);
1.413 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.414 + TUint32* start = uids.Begin();
1.415 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.416 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.417 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.418 +
1.419 + TInt r = iSubSession->SendReceive(EFindNeqReal, TIpcArgs(&pIdentifier, &pVal, &ptr));
1.420 +
1.421 + if(r == KErrNone)
1.422 + {
1.423 + r = GetFindResult(uids, aFoundIds);
1.424 + if (r==KErrNoMemory)
1.425 + User::LeaveNoMemory();
1.426 + }
1.427 +
1.428 + CleanupStack::Pop();
1.429 +
1.430 + return r;
1.431 + }
1.432 +
1.433 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.434 +//operations valid in transactions.
1.435 +TInt CClientRepository::FindNeqL(TUint32 aPartialId, TUint32 aIdMask,
1.436 + const TDesC8& aVal, RArray<TUint32>& aFoundIds)
1.437 + {
1.438 + CleanupFailTransactionPushL();
1.439 + aFoundIds.Reset();
1.440 +
1.441 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.442 + TUint32* start = uids.Begin();
1.443 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.444 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.445 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.446 +
1.447 + TInt r = iSubSession->SendReceive(EFindNeqString, TIpcArgs(&pIdentifier, &aVal, &ptr));
1.448 +
1.449 + if(r == KErrNone)
1.450 + {
1.451 + r = GetFindResult(uids, aFoundIds);
1.452 + if (r==KErrNoMemory)
1.453 + User::LeaveNoMemory();
1.454 + }
1.455 +
1.456 + CleanupStack::Pop();
1.457 +
1.458 + return r;
1.459 + }
1.460 +
1.461 +//Calls FailTransaction if it Leaves. This is the pattern for all client-side failure of
1.462 +//operations valid in transactions.
1.463 +TInt CClientRepository::FindNeqL(TUint32 aPartialId, TUint32 aIdMask,
1.464 + const TDesC& aVal, RArray<TUint32>& aFoundIds)
1.465 + {
1.466 + CleanupFailTransactionPushL();
1.467 + aFoundIds.Reset();
1.468 +
1.469 + TPtrC8 pVal((const TUint8*)aVal.Ptr(), aVal.Length()*2);
1.470 + TFixedArray<TUint32, KCentRepFindWithLenghtBufSize> uids;
1.471 + TUint32* start = uids.Begin();
1.472 + TPtr8 ptr(reinterpret_cast<TUint8*>(start), uids.Count() * uids.Length());
1.473 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.474 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.475 +
1.476 + TInt r = iSubSession->SendReceive(EFindNeqString, TIpcArgs(&pIdentifier, &pVal, &ptr));
1.477 +
1.478 + if(r == KErrNone)
1.479 + {
1.480 + r = GetFindResult(uids, aFoundIds);
1.481 + if (r==KErrNoMemory)
1.482 + User::LeaveNoMemory();
1.483 + }
1.484 +
1.485 + CleanupStack::Pop();
1.486 +
1.487 + return r;
1.488 + }
1.489 +
1.490 +/** Private helper function for all the Find~L functions.
1.491 +No need to call FailTransaction since all the methods that call this method calls
1.492 +FailTransaction prior to this method.
1.493 +@internalComponent
1.494 +*/
1.495 +TInt CClientRepository::GetFindResult(const TFixedArray<TUint32, KCentRepFindWithLenghtBufSize>& aUids, RArray<TUint32>& aFoundIds)
1.496 + {
1.497 + iClientErr = KErrNone;
1.498 + const TUint32 numFound = aUids[0];
1.499 + const TUint32 numInitial = numFound > KCentRepFindBufSize ? KCentRepFindBufSize : numFound;
1.500 + const TUint32 numFinal = numFound > KCentRepFindBufSize ? numFound - KCentRepFindBufSize : 0;
1.501 +
1.502 + for(TUint32 i = 1; i <= numInitial; i++)
1.503 + {
1.504 + //initialise client error first
1.505 + iClientErr=aFoundIds.Append(aUids[i]);
1.506 + if (iClientErr!=KErrNone)
1.507 + return iClientErr;
1.508 + }
1.509 +
1.510 + if(numFinal)
1.511 + {
1.512 + TAny* tempBuf = User::Alloc(numFinal * sizeof(TUint32));
1.513 + if (tempBuf==NULL)
1.514 + {
1.515 + return KErrNoMemory;
1.516 + }
1.517 + TPtr8 p(static_cast<TUint8*>(tempBuf), numFinal * sizeof(TUint32));
1.518 + TInt r = iSubSession->SendReceive(EGetFindResult, TIpcArgs(&p));
1.519 + if (r == KErrNone)
1.520 + {
1.521 + for(TUint32 i = 0; i < numFinal; i++)
1.522 + {
1.523 + iClientErr=aFoundIds.Append(static_cast<const TUint32*>(tempBuf)[i]);
1.524 + if (iClientErr!=KErrNone)
1.525 + {
1.526 + User::Free(tempBuf);
1.527 + return iClientErr;
1.528 + }
1.529 + }
1.530 + }
1.531 + User::Free(tempBuf);
1.532 + }
1.533 + return iClientErr;
1.534 + }
1.535 +
1.536 +TInt CClientRepository::NotifyRequest(TUint32 aId, TRequestStatus& aStatus)
1.537 + {
1.538 + TInt r = iSubSession->SendReceive(ENotifyRequestCheck, TIpcArgs(aId));
1.539 + if(r==KErrNone)
1.540 + iSubSession->SendReceive(ENotifyRequest, TIpcArgs(aId), aStatus);
1.541 + return r;
1.542 + }
1.543 +
1.544 +TInt CClientRepository::NotifyCancel(TUint32 aId)
1.545 + {
1.546 + return iSubSession->SendReceive(ENotifyCancel, TIpcArgs(aId));
1.547 + }
1.548 +
1.549 +TInt CClientRepository::NotifyCancelAll()
1.550 + {
1.551 + return iSubSession->SendReceive(ENotifyCancelAll);
1.552 + }
1.553 +
1.554 +TInt CClientRepository::NotifyRequest(TUint32 aPartialId, TUint32 aIdMask,
1.555 + TRequestStatus& aStatus)
1.556 + {
1.557 + iSubSession->SendReceive(EGroupNotifyRequest,
1.558 + TIpcArgs(aPartialId, aIdMask), aStatus);
1.559 + return KErrNone;
1.560 + }
1.561 +
1.562 +TInt CClientRepository::NotifyCancel(TUint32 aPartialId, TUint32 aIdMask)
1.563 + {
1.564 + TKeyFilter keyIdentifier = {aPartialId, aIdMask};
1.565 + TPckg<TKeyFilter> pIdentifier(keyIdentifier);
1.566 +
1.567 + return iSubSession->SendReceive(EGroupNotifyCancel, TIpcArgs(&pIdentifier));
1.568 + }
1.569 +
1.570 +TInt CClientRepository::Reset()
1.571 + {
1.572 + return iSubSession->SendReceive(EResetAll);
1.573 + }
1.574 +
1.575 +TInt CClientRepository::Reset(TUint32 aId)
1.576 + {
1.577 + return iSubSession->SendReceive(EReset, TIpcArgs(aId));
1.578 + }
1.579 +
1.580 +TInt CClientRepository::StartTransaction(TTransactionMode aMode)
1.581 + {
1.582 + return iSubSession->SendReceive(ETransactionStart, TIpcArgs(aMode));
1.583 + }
1.584 +
1.585 +void CClientRepository::StartTransaction(TTransactionMode aMode, TRequestStatus& aStatus)
1.586 + {
1.587 + iSubSession->SendReceive(ETransactionStart, TIpcArgs(aMode), aStatus);
1.588 + }
1.589 +
1.590 +TInt CClientRepository::CommitTransaction(TUint32& aKeyInfo)
1.591 + {
1.592 + // set to KUnspecifiedKey in case failure happens before setting in server
1.593 + aKeyInfo = KUnspecifiedKey;
1.594 + TPckg<TUint32> p(aKeyInfo);
1.595 + return iSubSession->SendReceive(ETransactionCommit, TIpcArgs(&p));
1.596 + }
1.597 +
1.598 +void CClientRepository::CommitTransaction(TDes8& aKeyInfo, TRequestStatus& aStatus)
1.599 + {
1.600 + // set to KUnspecifiedKey in case failure happens before setting in server
1.601 + aKeyInfo.Copy(TPckg<TUint32>(KUnspecifiedKey));
1.602 + iSubSession->SendReceive(ETransactionCommit, TIpcArgs(&aKeyInfo), aStatus);
1.603 + }
1.604 +
1.605 +void CClientRepository::CancelTransaction()
1.606 + {
1.607 + iSubSession->SendReceive(ETransactionCancel);
1.608 + }
1.609 +
1.610 +static void CancelTransactionCleanupOperation(TAny* aRepository)
1.611 + {
1.612 + static_cast<CClientRepository*>(aRepository)->CancelTransaction();
1.613 + }
1.614 +
1.615 +// So CancelTransaction is called in case of Leave. Must pop with CleanupStack::Pop() or similar
1.616 +void CClientRepository::CleanupCancelTransactionPushL()
1.617 + {
1.618 + CleanupStack::PushL(TCleanupItem(CancelTransactionCleanupOperation, this));
1.619 + }
1.620 +
1.621 +void CClientRepository::FailTransaction()
1.622 + {
1.623 + if (iClientErr==KErrNone)
1.624 + iSubSession->SendReceive(ETransactionFail,TIpcArgs(KErrAbort));
1.625 + else
1.626 + iSubSession->SendReceive(ETransactionFail,TIpcArgs(iClientErr));
1.627 + //reset the internal client code
1.628 + iClientErr=KErrNone;
1.629 + }
1.630 +
1.631 +// So FailTransaction is called in case of Leave. Must pop with CleanupStack::Pop() or similar
1.632 +static void FailTransactionCleanupOperation(TAny* aRepository)
1.633 + {
1.634 + static_cast<CClientRepository*>(aRepository)->FailTransaction();
1.635 + }
1.636 +
1.637 +void CClientRepository::CleanupFailTransactionPushL()
1.638 + {
1.639 + CleanupStack::PushL(TCleanupItem(FailTransactionCleanupOperation, this));
1.640 + }
1.641 +
1.642 +TInt CClientRepository::TransactionState()
1.643 + {
1.644 + TInt iValue;
1.645 +
1.646 + TPckg<TInt> p(iValue);
1.647 +
1.648 + iSubSession->SendReceive(ETransactionState, TIpcArgs(&p));
1.649 +
1.650 + return iValue;
1.651 + }
1.652 +
1.653 +TInt RRepositorySubSession::Open(RRepositorySession* aSession,TInt aFunction,const TIpcArgs& aArgs)
1.654 + {
1.655 + iSession = aSession;
1.656 + return(CreateSubSession(*aSession, aFunction, aArgs));
1.657 + }
1.658 +
1.659 +void RRepositorySubSession::Close()
1.660 + {
1.661 + RSubSessionBase::CloseSubSession(EClose);
1.662 + }
1.663 +
1.664 +TInt RRepositorySubSession::SendReceive(TInt aFunction) const
1.665 + {
1.666 + return RSubSessionBase::SendReceive(aFunction);
1.667 + }
1.668 +
1.669 +TInt RRepositorySubSession::SendReceive(TInt aFunction, const TIpcArgs& aArgs) const
1.670 + {
1.671 + return RSubSessionBase::SendReceive(aFunction, aArgs);
1.672 + }
1.673 +
1.674 +void RRepositorySubSession::SendReceive(TInt aFunction, const TIpcArgs& aArgs, TRequestStatus& aStatus) const
1.675 + {
1.676 + RSubSessionBase::SendReceive(aFunction, aArgs, aStatus);
1.677 + }
1.678 +
1.679 +inline TInt RRepositorySession::IncrementSubSessionCounter()
1.680 + {
1.681 + return ++iSubSessionCounter;
1.682 + }
1.683 +
1.684 +RRepositorySession ::RRepositorySession()
1.685 + :iSubSessionCounter(1)
1.686 + {
1.687 + }
1.688 +
1.689 +inline TInt RRepositorySession::DecrementSubSessionCounter()
1.690 + {
1.691 + ASSERT(iSubSessionCounter > 0);
1.692 + return --iSubSessionCounter;
1.693 + }
1.694 +
1.695 +#if defined(__CENTREP_SERVER_PERFTEST__) || defined(__CENTREP_SERVER_MEMTEST__) || defined(__CENTREP_SERVER_CACHETEST__)
1.696 +TInt RRepositorySession::SendReceive(TInt aFunction) const
1.697 + {
1.698 + return RSessionBase::SendReceive(aFunction);
1.699 + }
1.700 +
1.701 +TInt RRepositorySession::SendReceive(TInt aFunction,
1.702 + const TIpcArgs& aArgs) const
1.703 + {
1.704 + return RSessionBase::SendReceive(aFunction, aArgs);
1.705 + }
1.706 +
1.707 +void RRepositorySession::SendReceive(TInt aFunction, const TIpcArgs& aArgs,
1.708 + TRequestStatus& aStatus) const
1.709 + {
1.710 + RSessionBase::SendReceive(aFunction, aArgs, aStatus);
1.711 + }
1.712 +#endif
1.713 +
1.714 +LOCAL_C TInt StartServer();
1.715 +
1.716 +TInt RRepositorySession::Connect()
1.717 + {
1.718 + const TVersion KVersion(KServerMajorVersion, KServerMinorVersion,
1.719 + KServerBuildVersion);
1.720 + TInt retry = 2;
1.721 + TInt err = KErrGeneral;
1.722 + // Use unlimited message slots as we can call subscribe multiple times per
1.723 + // session.
1.724 + TInt numMessageSlots = -1;
1.725 + for(;;)
1.726 + {
1.727 + // Try to create a new session with the server.
1.728 + err = CreateSession(KServerName, KVersion, numMessageSlots);
1.729 + if((err != KErrNotFound) && (err != KErrServerTerminated))
1.730 + break; //completed
1.731 + // Server not running, try to start it.
1.732 + if(--retry==0)
1.733 + break; // Failed.
1.734 + err = StartServer();
1.735 + if((err != KErrNone) && (err != KErrAlreadyExists))
1.736 + break; // Launched server
1.737 + }
1.738 + return err;
1.739 + }
1.740 +
1.741 +//
1.742 +// Start the server process or thread
1.743 +//
1.744 +LOCAL_C TInt StartServer()
1.745 + {
1.746 + const TUidType serverUid(KNullUid,KNullUid,KServerUid3);
1.747 + //
1.748 + // EPOC and EKA2 is easy, we just create a new server process. Simultaneous
1.749 + // launching of two such processes should be detected when the second one
1.750 + // attempts to create the server object, failing with KErrAlreadyExists.
1.751 + //
1.752 + RProcess server;
1.753 + TInt r=server.Create(KServerImg,KNullDesC,serverUid);
1.754 +
1.755 + if (r!=KErrNone)
1.756 + return r;
1.757 + TRequestStatus stat;
1.758 + server.Rendezvous(stat);
1.759 + if (stat!=KRequestPending)
1.760 + server.Kill(0); // abort startup
1.761 + else
1.762 + server.Resume(); // logon OK - start the server
1.763 + User::WaitForRequest(stat); // wait for start or death
1.764 + // we can't use the 'exit reason' if the server panicked as this
1.765 + // is the panic 'reason' and may be '0' which cannot be distinguished
1.766 + // from KErrNone
1.767 + r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
1.768 + server.Close();
1.769 + return r;
1.770 + }
1.771 +