persistentstorage/dbms/sdbms/SD_UTL.CPP
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "SD_STD.H"
       
    17 
       
    18 GLDEF_C void Panic(TDbsPanic aPanic)
       
    19 //
       
    20 // Panic the client
       
    21 //
       
    22 	{
       
    23 	_LIT(KCategory,"DBMS-server");
       
    24 	Dbms::Panic(KCategory,aPanic);
       
    25 	}
       
    26 
       
    27 // Class Dbms
       
    28 
       
    29 EXPORT_C void Dbms::Panic(const TDesC& aCategory,TInt aCode)
       
    30 //
       
    31 // Panic the client
       
    32 // Outside of the server this calls User::Panic, within it calls the server and LEAVES!
       
    33 //
       
    34 	{
       
    35 	__TRACE(aCategory);
       
    36 	__TRACE(aCode);
       
    37 	CDbsServer* server=CDbsServer::Instance();
       
    38 	if (server)
       
    39 		{
       
    40 		server->Panic(aCategory,aCode);
       
    41 		__LEAVE(KDbsLeavePanic);
       
    42 		}
       
    43 	else
       
    44 		User::Panic(aCategory,aCode);
       
    45 	}
       
    46 
       
    47 // streaming functions
       
    48 
       
    49 GLDEF_C void ExternalizeL(const TDbCol& aCol,RWriteStream& aStream)
       
    50 	{
       
    51 	aStream<<aCol.iName<<TUint8(aCol.iType)<<TInt32(aCol.iMaxLength)<<TUint8(aCol.iAttributes);
       
    52 	}
       
    53 
       
    54 GLDEF_C void ExternalizeL(const CDbColSet& aColSet,RWriteStream& aStream)
       
    55 	{
       
    56 	TInt cc=aColSet.Count();
       
    57 	aStream.WriteInt32L(cc);
       
    58 	for (TInt ii=0;++ii<=cc;)
       
    59 		aStream<<aColSet[ii];
       
    60 	}
       
    61 
       
    62 GLDEF_C void InternalizeL(CDbColSet& aColSet,RReadStream& aStream)
       
    63 	{
       
    64 	__ASSERT(aColSet.Count()==0);
       
    65 	TDbCol col;
       
    66 	TPtr name(col.iName.Des());
       
    67 	TInt cc=aStream.ReadInt32L();
       
    68 	while (--cc>=0)
       
    69 		{
       
    70 		aStream>>name;
       
    71 		col.iType=TDbColType(aStream.ReadUint8L());
       
    72 		col.iMaxLength=aStream.ReadInt32L();
       
    73 		col.iAttributes=aStream.ReadUint8L();
       
    74 		aColSet.AddL(col);
       
    75 		}
       
    76 	}
       
    77 
       
    78 GLDEF_C void ExternalizeL(const CDbKey& aKey,RWriteStream& aStream)
       
    79 	{
       
    80 	TInt cc=aKey.Count();
       
    81 	aStream.WriteInt32L(cc);
       
    82 	for (TInt ii=0;ii<cc;++ii)
       
    83 		{
       
    84 		const TDbKeyCol& col=aKey[ii];
       
    85 		aStream<<col.iName<<TUint8(col.iOrder)<<TInt32(col.iLength);
       
    86 		}
       
    87 	aStream<<TUint8(aKey.Comparison())<<TUint8(aKey.IsUnique());
       
    88 	}
       
    89 
       
    90 GLDEF_C void InternalizeL(CDbKey& aKey,RReadStream& aStream)
       
    91 	{
       
    92 	__ASSERT(aKey.Count()==0);
       
    93 	TDbKeyCol col;
       
    94 	TPtr name(col.iName.Des());
       
    95 	TInt cc=aStream.ReadInt32L();
       
    96 	while (--cc>=0)
       
    97 		{
       
    98 		aStream>>name;
       
    99 		TUint8 uInt = aStream.ReadUint8L();
       
   100 		col.iOrder=TDbKeyCol::TOrder(uInt);
       
   101 		col.iLength=aStream.ReadInt32L();
       
   102 		aKey.AddL(col);
       
   103 		}
       
   104 	aKey.SetComparison(TDbTextComparison(aStream.ReadUint8L()));
       
   105 	if (aStream.ReadUint8L())
       
   106 		aKey.MakeUnique();
       
   107 	}
       
   108 
       
   109 GLDEF_C void ExternalizeL(const CDbNames& aNames,RWriteStream& aStream)
       
   110 	{
       
   111 	TInt cc=aNames.Count();
       
   112 	aStream.WriteInt32L(cc);
       
   113 	for (TInt ii=0;ii<cc;++ii)
       
   114 		aStream<<aNames[ii];
       
   115 	}
       
   116 
       
   117 GLDEF_C void InternalizeL(CDbNames& aNames,RReadStream& aStream)
       
   118 	{
       
   119 	__ASSERT(aNames.Count()==0);
       
   120 	TDbName name;
       
   121 	TInt cc=aStream.ReadInt32L();
       
   122 	while (--cc>=0)
       
   123 		{
       
   124 		aStream>>name;
       
   125 		aNames.AddL(name);
       
   126 		}
       
   127 	}
       
   128 
       
   129 /**
       
   130 A helper function, used in
       
   131 "RWriteStream& operator<<(RWriteStream& aStream,const CDbStrings& aStrings)".
       
   132 @internalComponent
       
   133 */
       
   134 GLDEF_C void ExternalizeL(const CDbStrings& aStrings,RWriteStream& aStream)
       
   135 	{
       
   136 	TInt cc=aStrings.Count();
       
   137 	aStream.WriteInt32L(cc);
       
   138 	for (TInt ii=0;ii<cc;++ii)
       
   139 		aStream<<aStrings[ii];
       
   140 	}
       
   141 
       
   142 /** 
       
   143 Represents a generic read/write DBMS string. It maps to a modifiable buffer descriptor 
       
   144 with maximum size KDbMaxStrLen.
       
   145 
       
   146 @see TBuf 
       
   147 @internalComponent
       
   148 */
       
   149 typedef TBuf<KDbMaxStrLen> TDbString;
       
   150 
       
   151 /**
       
   152 A helper function, used in
       
   153 "RReadStream& operator>>(RReadStream& aStream,CDbStrings& aStrings)".
       
   154 @internalComponent
       
   155 */
       
   156 GLDEF_C void InternalizeL(CDbStrings& aStrings,RReadStream& aStream)
       
   157 	{
       
   158 	__ASSERT(aStrings.Count()==0);
       
   159 	TDbString str;
       
   160 	TInt cc=aStream.ReadInt32L();
       
   161 	while (--cc>=0)
       
   162 		{
       
   163 		aStream>>str;
       
   164 		aStrings.AddL(str);
       
   165 		}
       
   166 	}