sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // DBMS server and support classes sl@0: // sl@0: // sl@0: sl@0: #include "SD_STD.H" sl@0: sl@0: // Class RDbsObject sl@0: void RDbsObject::OpenL(const RDbsObject& aDbs,TDbsFunction aFunction,const TIpcArgs* aArgs) sl@0: { sl@0: __ASSERT(!iHandle); sl@0: iHandle=aDbs.SendReceiveL(TDbsFunction(aFunction|KDbsObjectReturn),aArgs); sl@0: RDbs::operator=(STATIC_CAST(const RDbs&,aDbs)); sl@0: } sl@0: sl@0: void RDbsObject::Close() sl@0: { sl@0: if (iHandle) sl@0: { sl@0: SendReceive(EDbsClose); sl@0: iHandle=0; sl@0: SetHandle(KNullHandle); // set session handle sl@0: } sl@0: } sl@0: sl@0: TInt RDbsObject::SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs) const sl@0: { sl@0: __ASSERT(iHandle); sl@0: if(aArgs) sl@0: return RDbs::SendReceive(DbsMessage(aFunction,iHandle),*aArgs); sl@0: else sl@0: return RDbs::SendReceive(DbsMessage(aFunction,iHandle),TIpcArgs()); sl@0: } sl@0: sl@0: TInt RDbsObject::SendReceive(TDbsFunction aFunction) const sl@0: { sl@0: return SendReceive(aFunction,0); sl@0: } sl@0: sl@0: TInt RDbsObject::SendReceiveL(TDbsFunction aFunction,const TIpcArgs* aArgs) const sl@0: { sl@0: return __LEAVE_IF_ERROR(SendReceive(aFunction,aArgs)); sl@0: } sl@0: sl@0: TInt RDbsObject::SendReceiveL(TDbsFunction aFunction) const sl@0: { sl@0: return SendReceiveL(aFunction,0); sl@0: } sl@0: sl@0: void RDbsObject::SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs,TRequestStatus& aStatus) const sl@0: { sl@0: __ASSERT(iHandle); sl@0: if(aArgs) sl@0: RDbs::SendReceive(DbsMessage(aFunction,iHandle),*aArgs,aStatus); sl@0: else sl@0: RDbs::SendReceive(DbsMessage(aFunction,iHandle),TIpcArgs(),aStatus); sl@0: } sl@0: sl@0: // Class TDbsParam sl@0: sl@0: const TInt KBufGranularity=0x200; sl@0: sl@0: TPtrC8 TDbsParam::PrepareLC(const CDbColSet& aColSet) sl@0: { sl@0: CBufFlat* buf=CBufFlat::NewL(KBufGranularity); sl@0: CleanupStack::PushL(buf); sl@0: RBufWriteStream strm(*buf); sl@0: strm<<aColSet; sl@0: return buf->Ptr(0); sl@0: } sl@0: sl@0: TPtrC8 TDbsParam::PrepareLC(const CDbKey& aKey) sl@0: { sl@0: CBufFlat* buf=CBufFlat::NewL(KBufGranularity); sl@0: CleanupStack::PushL(buf); sl@0: RBufWriteStream strm(*buf); sl@0: strm<<aKey; sl@0: return buf->Ptr(0); sl@0: } sl@0: sl@0: TPtrC8 TDbsParam::PrepareLC(const TDbLookupKey& aKey) sl@0: { sl@0: TInt tsize=0; sl@0: const TDbLookupKey::SColumn* iter=aKey.First(); sl@0: const TDbLookupKey::SColumn* end=iter+aKey.Count(); sl@0: do sl@0: { sl@0: switch (iter->iType) sl@0: { sl@0: default: sl@0: break; sl@0: case EDbColText8: sl@0: tsize+=iter->iDes8.iLength; sl@0: break; sl@0: case EDbColText16: sl@0: tsize+=iter->iDes16.iLength<<1; sl@0: break; sl@0: }; sl@0: } while (++iter<end); sl@0: // sl@0: TInt size=(TUint8*)end-(TUint8*)&aKey; sl@0: TDbLookupKey* key=(TDbLookupKey*)User::AllocLC(size+tsize); sl@0: TUint8* text=Mem::Copy(key,&aKey,size); sl@0: if (tsize) sl@0: { sl@0: TDbLookupKey::SColumn* iter=CONST_CAST(TDbLookupKey::SColumn*,key->First()); sl@0: TDbLookupKey::SColumn* end=(TDbLookupKey::SColumn*)text; sl@0: do sl@0: { sl@0: switch (iter->iType) sl@0: { sl@0: default: sl@0: break; sl@0: case EDbColText8: sl@0: { sl@0: const TUint8* p=iter->iDes8.iPtr; sl@0: iter->iDes8.iPtr=REINTERPRET_CAST(const TUint8*,(text-(TUint8*)key)); sl@0: text=Mem::Copy(text,p,iter->iDes8.iLength); sl@0: } sl@0: break; sl@0: case EDbColText16: sl@0: { sl@0: const TUint16* p=iter->iDes16.iPtr; sl@0: iter->iDes16.iPtr=REINTERPRET_CAST(const TUint16*,(text-(TUint8*)key)); sl@0: text=Mem::Copy(text,p,iter->iDes16.iLength<<1); sl@0: } sl@0: break; sl@0: }; sl@0: } while (++iter<end); sl@0: } sl@0: return TPtrC8((TUint8*)key,size+tsize); sl@0: }