|
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 // DBMS server and support classes |
|
15 // |
|
16 // |
|
17 |
|
18 #include "SD_STD.H" |
|
19 |
|
20 // Class RDbsObject |
|
21 void RDbsObject::OpenL(const RDbsObject& aDbs,TDbsFunction aFunction,const TIpcArgs* aArgs) |
|
22 { |
|
23 __ASSERT(!iHandle); |
|
24 iHandle=aDbs.SendReceiveL(TDbsFunction(aFunction|KDbsObjectReturn),aArgs); |
|
25 RDbs::operator=(STATIC_CAST(const RDbs&,aDbs)); |
|
26 } |
|
27 |
|
28 void RDbsObject::Close() |
|
29 { |
|
30 if (iHandle) |
|
31 { |
|
32 SendReceive(EDbsClose); |
|
33 iHandle=0; |
|
34 SetHandle(KNullHandle); // set session handle |
|
35 } |
|
36 } |
|
37 |
|
38 TInt RDbsObject::SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs) const |
|
39 { |
|
40 __ASSERT(iHandle); |
|
41 if(aArgs) |
|
42 return RDbs::SendReceive(DbsMessage(aFunction,iHandle),*aArgs); |
|
43 else |
|
44 return RDbs::SendReceive(DbsMessage(aFunction,iHandle),TIpcArgs()); |
|
45 } |
|
46 |
|
47 TInt RDbsObject::SendReceive(TDbsFunction aFunction) const |
|
48 { |
|
49 return SendReceive(aFunction,0); |
|
50 } |
|
51 |
|
52 TInt RDbsObject::SendReceiveL(TDbsFunction aFunction,const TIpcArgs* aArgs) const |
|
53 { |
|
54 return __LEAVE_IF_ERROR(SendReceive(aFunction,aArgs)); |
|
55 } |
|
56 |
|
57 TInt RDbsObject::SendReceiveL(TDbsFunction aFunction) const |
|
58 { |
|
59 return SendReceiveL(aFunction,0); |
|
60 } |
|
61 |
|
62 void RDbsObject::SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs,TRequestStatus& aStatus) const |
|
63 { |
|
64 __ASSERT(iHandle); |
|
65 if(aArgs) |
|
66 RDbs::SendReceive(DbsMessage(aFunction,iHandle),*aArgs,aStatus); |
|
67 else |
|
68 RDbs::SendReceive(DbsMessage(aFunction,iHandle),TIpcArgs(),aStatus); |
|
69 } |
|
70 |
|
71 // Class TDbsParam |
|
72 |
|
73 const TInt KBufGranularity=0x200; |
|
74 |
|
75 TPtrC8 TDbsParam::PrepareLC(const CDbColSet& aColSet) |
|
76 { |
|
77 CBufFlat* buf=CBufFlat::NewL(KBufGranularity); |
|
78 CleanupStack::PushL(buf); |
|
79 RBufWriteStream strm(*buf); |
|
80 strm<<aColSet; |
|
81 return buf->Ptr(0); |
|
82 } |
|
83 |
|
84 TPtrC8 TDbsParam::PrepareLC(const CDbKey& aKey) |
|
85 { |
|
86 CBufFlat* buf=CBufFlat::NewL(KBufGranularity); |
|
87 CleanupStack::PushL(buf); |
|
88 RBufWriteStream strm(*buf); |
|
89 strm<<aKey; |
|
90 return buf->Ptr(0); |
|
91 } |
|
92 |
|
93 TPtrC8 TDbsParam::PrepareLC(const TDbLookupKey& aKey) |
|
94 { |
|
95 TInt tsize=0; |
|
96 const TDbLookupKey::SColumn* iter=aKey.First(); |
|
97 const TDbLookupKey::SColumn* end=iter+aKey.Count(); |
|
98 do |
|
99 { |
|
100 switch (iter->iType) |
|
101 { |
|
102 default: |
|
103 break; |
|
104 case EDbColText8: |
|
105 tsize+=iter->iDes8.iLength; |
|
106 break; |
|
107 case EDbColText16: |
|
108 tsize+=iter->iDes16.iLength<<1; |
|
109 break; |
|
110 }; |
|
111 } while (++iter<end); |
|
112 // |
|
113 TInt size=(TUint8*)end-(TUint8*)&aKey; |
|
114 TDbLookupKey* key=(TDbLookupKey*)User::AllocLC(size+tsize); |
|
115 TUint8* text=Mem::Copy(key,&aKey,size); |
|
116 if (tsize) |
|
117 { |
|
118 TDbLookupKey::SColumn* iter=CONST_CAST(TDbLookupKey::SColumn*,key->First()); |
|
119 TDbLookupKey::SColumn* end=(TDbLookupKey::SColumn*)text; |
|
120 do |
|
121 { |
|
122 switch (iter->iType) |
|
123 { |
|
124 default: |
|
125 break; |
|
126 case EDbColText8: |
|
127 { |
|
128 const TUint8* p=iter->iDes8.iPtr; |
|
129 iter->iDes8.iPtr=REINTERPRET_CAST(const TUint8*,(text-(TUint8*)key)); |
|
130 text=Mem::Copy(text,p,iter->iDes8.iLength); |
|
131 } |
|
132 break; |
|
133 case EDbColText16: |
|
134 { |
|
135 const TUint16* p=iter->iDes16.iPtr; |
|
136 iter->iDes16.iPtr=REINTERPRET_CAST(const TUint16*,(text-(TUint8*)key)); |
|
137 text=Mem::Copy(text,p,iter->iDes16.iLength<<1); |
|
138 } |
|
139 break; |
|
140 }; |
|
141 } while (++iter<end); |
|
142 } |
|
143 return TPtrC8((TUint8*)key,size+tsize); |
|
144 } |