os/persistentdata/persistentstorage/dbms/sdbms/SD_OBJ.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// DBMS server and support classes
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "SD_STD.H"
sl@0
    19
sl@0
    20
// Class RDbsObject
sl@0
    21
void RDbsObject::OpenL(const RDbsObject& aDbs,TDbsFunction aFunction,const TIpcArgs* aArgs)
sl@0
    22
	{
sl@0
    23
	__ASSERT(!iHandle);
sl@0
    24
	iHandle=aDbs.SendReceiveL(TDbsFunction(aFunction|KDbsObjectReturn),aArgs);
sl@0
    25
	RDbs::operator=(STATIC_CAST(const RDbs&,aDbs));
sl@0
    26
	}
sl@0
    27
sl@0
    28
void RDbsObject::Close()
sl@0
    29
	{
sl@0
    30
	if (iHandle)
sl@0
    31
		{
sl@0
    32
		SendReceive(EDbsClose);
sl@0
    33
		iHandle=0;
sl@0
    34
		SetHandle(KNullHandle);		// set session handle
sl@0
    35
		}
sl@0
    36
	}
sl@0
    37
sl@0
    38
TInt RDbsObject::SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs) const
sl@0
    39
	{
sl@0
    40
	__ASSERT(iHandle);
sl@0
    41
	if(aArgs)
sl@0
    42
		return RDbs::SendReceive(DbsMessage(aFunction,iHandle),*aArgs);
sl@0
    43
	else
sl@0
    44
		return RDbs::SendReceive(DbsMessage(aFunction,iHandle),TIpcArgs());
sl@0
    45
	}
sl@0
    46
sl@0
    47
TInt RDbsObject::SendReceive(TDbsFunction aFunction) const
sl@0
    48
	{
sl@0
    49
	return SendReceive(aFunction,0);
sl@0
    50
	}
sl@0
    51
sl@0
    52
TInt RDbsObject::SendReceiveL(TDbsFunction aFunction,const TIpcArgs* aArgs) const
sl@0
    53
	{
sl@0
    54
	return __LEAVE_IF_ERROR(SendReceive(aFunction,aArgs));
sl@0
    55
	}
sl@0
    56
sl@0
    57
TInt RDbsObject::SendReceiveL(TDbsFunction aFunction) const
sl@0
    58
	{
sl@0
    59
	return SendReceiveL(aFunction,0);
sl@0
    60
	}
sl@0
    61
sl@0
    62
void RDbsObject::SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs,TRequestStatus& aStatus) const
sl@0
    63
	{
sl@0
    64
	__ASSERT(iHandle);
sl@0
    65
	if(aArgs)
sl@0
    66
		RDbs::SendReceive(DbsMessage(aFunction,iHandle),*aArgs,aStatus);
sl@0
    67
	else
sl@0
    68
		RDbs::SendReceive(DbsMessage(aFunction,iHandle),TIpcArgs(),aStatus);
sl@0
    69
	}
sl@0
    70
sl@0
    71
// Class TDbsParam
sl@0
    72
sl@0
    73
const TInt KBufGranularity=0x200;
sl@0
    74
sl@0
    75
TPtrC8 TDbsParam::PrepareLC(const CDbColSet& aColSet)
sl@0
    76
	{
sl@0
    77
	CBufFlat* buf=CBufFlat::NewL(KBufGranularity);
sl@0
    78
	CleanupStack::PushL(buf);
sl@0
    79
	RBufWriteStream strm(*buf);
sl@0
    80
	strm<<aColSet;
sl@0
    81
	return buf->Ptr(0);
sl@0
    82
	}
sl@0
    83
sl@0
    84
TPtrC8 TDbsParam::PrepareLC(const CDbKey& aKey)
sl@0
    85
	{
sl@0
    86
	CBufFlat* buf=CBufFlat::NewL(KBufGranularity);
sl@0
    87
	CleanupStack::PushL(buf);
sl@0
    88
	RBufWriteStream strm(*buf);
sl@0
    89
	strm<<aKey;
sl@0
    90
	return buf->Ptr(0);
sl@0
    91
	}
sl@0
    92
sl@0
    93
TPtrC8 TDbsParam::PrepareLC(const TDbLookupKey& aKey)
sl@0
    94
	{
sl@0
    95
	TInt tsize=0;
sl@0
    96
	const TDbLookupKey::SColumn* iter=aKey.First();
sl@0
    97
	const TDbLookupKey::SColumn* end=iter+aKey.Count();
sl@0
    98
	do
sl@0
    99
		{
sl@0
   100
		switch (iter->iType)
sl@0
   101
			{
sl@0
   102
		default:
sl@0
   103
			break;
sl@0
   104
		case EDbColText8:
sl@0
   105
			tsize+=iter->iDes8.iLength;
sl@0
   106
			break;
sl@0
   107
		case EDbColText16:
sl@0
   108
			tsize+=iter->iDes16.iLength<<1;
sl@0
   109
			break;
sl@0
   110
			};
sl@0
   111
		} while (++iter<end);
sl@0
   112
	//
sl@0
   113
	TInt size=(TUint8*)end-(TUint8*)&aKey;
sl@0
   114
	TDbLookupKey* key=(TDbLookupKey*)User::AllocLC(size+tsize);
sl@0
   115
	TUint8* text=Mem::Copy(key,&aKey,size);
sl@0
   116
	if (tsize)
sl@0
   117
		{
sl@0
   118
		TDbLookupKey::SColumn* iter=CONST_CAST(TDbLookupKey::SColumn*,key->First());
sl@0
   119
		TDbLookupKey::SColumn* end=(TDbLookupKey::SColumn*)text;
sl@0
   120
		do
sl@0
   121
			{
sl@0
   122
			switch (iter->iType)
sl@0
   123
				{
sl@0
   124
			default:
sl@0
   125
				break;
sl@0
   126
			case EDbColText8:
sl@0
   127
				{
sl@0
   128
				const TUint8* p=iter->iDes8.iPtr;
sl@0
   129
				iter->iDes8.iPtr=REINTERPRET_CAST(const TUint8*,(text-(TUint8*)key));
sl@0
   130
				text=Mem::Copy(text,p,iter->iDes8.iLength);
sl@0
   131
				}
sl@0
   132
				break;
sl@0
   133
			case EDbColText16:
sl@0
   134
				{
sl@0
   135
				const TUint16* p=iter->iDes16.iPtr;
sl@0
   136
				iter->iDes16.iPtr=REINTERPRET_CAST(const TUint16*,(text-(TUint8*)key));
sl@0
   137
				text=Mem::Copy(text,p,iter->iDes16.iLength<<1);
sl@0
   138
				}
sl@0
   139
				break;
sl@0
   140
				};
sl@0
   141
			} while (++iter<end);
sl@0
   142
		}
sl@0
   143
	return TPtrC8((TUint8*)key,size+tsize);
sl@0
   144
	}