|
1 |
|
2 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 // All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Nokia Corporation - initial contribution. |
|
11 // |
|
12 // Contributors: |
|
13 // |
|
14 // Description: |
|
15 // |
|
16 |
|
17 #ifndef SDPUTIL_H |
|
18 #define SDPUTIL_H |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32base.h> |
|
22 |
|
23 enum TSdpLeaveError |
|
24 { |
|
25 ESdpUnexpectedAttributeValueType = -1, |
|
26 }; |
|
27 |
|
28 _LIT(KSdpDatabasePanicString, "SDP-Database"); |
|
29 _LIT(KSdpParsePanicString, "SDP-Parse"); |
|
30 |
|
31 /** |
|
32 Panic values: |
|
33 ESdpDbBadAttrValueGetter Panics if the virtual base class method is called. Must be overriden in derived classes. |
|
34 ESdpDbBadSearchPattern Panics if a bad search pattern is provided. |
|
35 ESdpDbRecordBadHandle Panics if a bad handle to a record is provided. |
|
36 ESdpCSdpStackFixIsEmpty Panics if CSdpStackFix is empty |
|
37 ESdpNoAttrValue Panics if an attribute value is missing. |
|
38 ESdpAttrValueBadSize Panics if an attribute value is a bad size. |
|
39 ESDPServerNoDatabase Panics if there is no server database |
|
40 ESdpDbAttributeEncodingFailed Panics if the attribute cannot be encoded because it is of unknown type. |
|
41 ESdpDbStoredAttrValNotEncoded Panics if the attribute was not correctly encoded. |
|
42 ESdpDbOrderedQueueItemIsHead Panics if the queue iterator has failed. |
|
43 ESdpDbOrderedQueuePositionClash Panics if there is a position clash in the queue. |
|
44 */ |
|
45 enum TSdpDbPanic |
|
46 { |
|
47 ESdpDbBadAttrValueGetter = 0, |
|
48 ESdpDbBadSearchPattern = 1, |
|
49 ESdpDbRecordBadHandle = 2, |
|
50 ESdpCSdpStackFixIsEmpty = 3, |
|
51 ESdpNoAttrValue = 4, |
|
52 ESdpAttrValueBadSize = 5, |
|
53 ESDPServerNoDatabase = 6, |
|
54 ESdpDbAttributeEncodingFailed = 7, |
|
55 ESdpDbStoredAttrValNotEncoded = 8, |
|
56 ESdpDbOrderedQueueItemIsHead = 9, |
|
57 ESdpDbOrderedQueuePositionClash = 10, |
|
58 }; |
|
59 |
|
60 void DbPanic(TSdpDbPanic aCode); |
|
61 |
|
62 //TSdpAgPanic - see ..\agent\agutil.h |
|
63 |
|
64 |
|
65 /** |
|
66 Panic values: |
|
67 EGetUintBadDescriptorLength Panics if the descriptor has a bad length |
|
68 EFrameOverrun Panics if the frame has overrun |
|
69 EListOverrun Panics if the list has overrun |
|
70 EGetUint64BadDescriptorLength Panics if the descriptor does not contain a parsable Uint64 |
|
71 EGetUint128BadDescriptorLength Panics if the descriptor does not contain a parsable Uint128 |
|
72 */ |
|
73 enum TSdpParsePanic |
|
74 { |
|
75 EGetUintBadDescriptorLength = 0, |
|
76 EFrameOverrun = 1, |
|
77 EListOverrun = 2, |
|
78 EGetUint64BadDescriptorLength = 3, |
|
79 EGetUint128BadDescriptorLength = 4, |
|
80 }; |
|
81 |
|
82 void ParsePanic(TSdpParsePanic); |
|
83 |
|
84 template<class T> |
|
85 class TOrderedQue : public TDblQue<T> |
|
86 { |
|
87 public: |
|
88 inline TOrderedQue(TInt aOffset); |
|
89 void AddInOrder(T& aRef); |
|
90 void ResetAndDestroy(); |
|
91 }; |
|
92 |
|
93 const TInt KStackGranularity=4; |
|
94 |
|
95 template<class T> |
|
96 class CSdpStackFix : public CArrayFixSeg<T> |
|
97 { |
|
98 public: |
|
99 inline CSdpStackFix(); |
|
100 inline ~CSdpStackFix(); |
|
101 |
|
102 inline TBool IsEmpty() const; |
|
103 inline void PushL(T aItem); |
|
104 inline T Pop(); |
|
105 inline const T& Head() const; |
|
106 inline T& Head(); |
|
107 inline const T& Last() const; |
|
108 }; |
|
109 |
|
110 |
|
111 // |
|
112 // Inlines |
|
113 // |
|
114 |
|
115 template<class T> |
|
116 inline TOrderedQue<T>::TOrderedQue(TInt aOffset) |
|
117 : TDblQue<T>(aOffset) |
|
118 { |
|
119 } |
|
120 |
|
121 template <class T> |
|
122 void TOrderedQue<T>::AddInOrder(T& aRef) |
|
123 { |
|
124 if (TDblQue<T>::IsEmpty() || aRef > (*TDblQue<T>::Last())) |
|
125 { |
|
126 TDblQue<T>::AddLast(aRef); |
|
127 return; |
|
128 } |
|
129 |
|
130 TDblQueIter<T> iter (*this); |
|
131 while (aRef > *iter) |
|
132 iter++; |
|
133 |
|
134 __ASSERT_DEBUG(!TDblQue<T>::IsHead(iter), DbPanic(ESdpDbOrderedQueueItemIsHead)); |
|
135 __ASSERT_DEBUG(*iter > aRef, DbPanic(ESdpDbOrderedQueuePositionClash)); // If this fails, there is a position clash! |
|
136 PtrAdd((TDblQueLink*)&aRef, TDblQue<T>::iOffset)->AddBefore(PtrAdd((TDblQueLink*)&(*iter), TDblQue<T>::iOffset)); |
|
137 } |
|
138 |
|
139 template <class T> |
|
140 void TOrderedQue<T>::ResetAndDestroy() |
|
141 { |
|
142 while (!TDblQue<T>::IsEmpty()) |
|
143 { |
|
144 delete TDblQue<T>::First(); |
|
145 } |
|
146 } |
|
147 |
|
148 template <class T> |
|
149 inline CSdpStackFix<T>::CSdpStackFix() |
|
150 : CArrayFixSeg<T>(KStackGranularity) |
|
151 { |
|
152 CArrayFixSeg<T>::Reset(); |
|
153 } |
|
154 |
|
155 template <class T> |
|
156 inline CSdpStackFix<T>::~CSdpStackFix() |
|
157 { |
|
158 CArrayFixSeg<T>::Reset(); |
|
159 } |
|
160 |
|
161 template <class T> |
|
162 inline TBool CSdpStackFix<T>::IsEmpty() const |
|
163 { |
|
164 return CArrayFixSeg<T>::Count()==0; |
|
165 } |
|
166 |
|
167 template <class T> |
|
168 inline void CSdpStackFix<T>::PushL(T aItem) |
|
169 { |
|
170 CArrayFixSeg<T>::AppendL(aItem); |
|
171 } |
|
172 |
|
173 template <class T> |
|
174 inline T CSdpStackFix<T>::Pop() |
|
175 { |
|
176 __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); |
|
177 T item=Head(); |
|
178 CArrayFixSeg<T>::Delete(CArrayFixSeg<T>::Count()-1); |
|
179 return item; |
|
180 } |
|
181 |
|
182 template <class T> |
|
183 inline const T &CSdpStackFix<T>::Head() const |
|
184 { |
|
185 __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); |
|
186 return CArrayFixSeg<T>::At(CArrayFixSeg<T>::Count()-1); |
|
187 } |
|
188 |
|
189 template <class T> |
|
190 inline T &CSdpStackFix<T>::Head() |
|
191 { |
|
192 __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); |
|
193 return CArrayFixSeg<T>::At(CArrayFixSeg<T>::Count()-1); |
|
194 } |
|
195 |
|
196 template <class T> |
|
197 inline const T &CSdpStackFix<T>::Last() const |
|
198 { |
|
199 __ASSERT_DEBUG(!IsEmpty(), DbPanic(ESdpCSdpStackFixIsEmpty)); |
|
200 return CArrayFixSeg<T>::At(0); |
|
201 } |
|
202 |
|
203 |
|
204 #endif |