|
1 /* |
|
2 * Copyright (c) 2005-2008 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: CCapList implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "caplist.h" |
|
22 #include "caputils.h" |
|
23 #include "capparser.h" |
|
24 #include "capability.h" |
|
25 #include "debug.h" |
|
26 |
|
27 // ============================= MEMBER FUNCTIONS =============================== |
|
28 |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CCapList::NewL() |
|
32 // Two-phase constructor. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CCapList* CCapList::NewL() |
|
36 { |
|
37 TRACE_FUNC_ENTRY; |
|
38 CCapList* self = new(ELeave) CCapList(); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop( self ); |
|
42 TRACE_FUNC_EXIT; |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CCapList::~CCapList() |
|
48 // Gets phone serial number from etel. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CCapList::~CCapList() |
|
52 { |
|
53 TRACE_FUNC_ENTRY; |
|
54 delete iList; |
|
55 TRACE_FUNC_EXIT; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CCapList::CCapList() |
|
60 // Constructor |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CCapList::CCapList() |
|
64 { |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CCapList::ConstructL() |
|
69 // Initializes the member data |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CCapList::ConstructL() |
|
73 { |
|
74 TRACE_FUNC_ENTRY; |
|
75 iList = CStringList::NewL(); |
|
76 TRACE_FUNC_EXIT; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CCapList::List() |
|
81 // Returns the list |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CStringList* CCapList::List() |
|
85 { |
|
86 __ASSERT_DEBUG(iList, CapUtil::Panic(KErrGeneral)); |
|
87 return iList; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CCapList::FindFromMark(TInt aId, TInt aType) |
|
92 // Find from mark |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 TInt CCapList::FindFromMark(TInt aId, TInt aType) |
|
96 { |
|
97 TRACE_FUNC_ENTRY; |
|
98 TInt mark = List()->Mark(); |
|
99 TInt count= List()->Count(); |
|
100 |
|
101 if ( mark >= count ) |
|
102 { |
|
103 return KErrNotFound; |
|
104 } |
|
105 |
|
106 TInt index=Find(aId, aType, mark); |
|
107 if ( index == KErrNotFound ) |
|
108 { |
|
109 LOGGER_WRITE_1( "CCapList::FindFromMark(TInt aId, TInt aType) returned : %d", KErrNotFound ); |
|
110 return KErrNotFound; |
|
111 } |
|
112 |
|
113 |
|
114 __ASSERT_DEBUG(index>=mark, CapUtil::Panic(KErrGeneral)); |
|
115 |
|
116 List()->SetMark(index+1); |
|
117 LOGGER_WRITE_1( "CCapList::FindFromMark(TInt aId, TInt aType) returned : %d", index ); |
|
118 return index; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CCapList::FindServiceHeader() |
|
123 // Finds service xml-file identification header. This header must be the first |
|
124 // line in every service file. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 TBool CCapList::FindServiceHeader() |
|
128 { |
|
129 TRACE_FUNC_ENTRY; |
|
130 if (List()->Count()<1) |
|
131 { |
|
132 LOGGER_WRITE( "CCapList::FindServiceHeader() : returned EFalse" ); |
|
133 return EFalse; |
|
134 } |
|
135 |
|
136 TBuf<KBufSize> buf; |
|
137 TPtrC ptr=List()->ReadPtr(0); |
|
138 CapUtil::StrCopy(buf, ptr); |
|
139 buf.Trim(); |
|
140 if (buf.Compare(KServiceHeader)==0) |
|
141 { |
|
142 LOGGER_WRITE( "CCapList::FindServiceHeader() : returned ETrue" ); |
|
143 return ETrue; |
|
144 } |
|
145 else |
|
146 { |
|
147 LOGGER_WRITE( "CCapList::FindServiceHeader() : returned EFalse" ); |
|
148 return EFalse; |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CCapList::FindServiceL(CStringList* aList) |
|
154 // Find service |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CCapList::FindServiceL(CStringList* aList) |
|
158 { |
|
159 TRACE_FUNC_ENTRY; |
|
160 aList->Reset(); |
|
161 List()->SetMark(0); |
|
162 |
|
163 if (!FindServiceHeader()) |
|
164 { |
|
165 LOGGER_WRITE( "CCapList::FindServiceL(CStringList* aList) : returned EFalse" ); |
|
166 return EFalse; |
|
167 } |
|
168 |
|
169 |
|
170 for (;;) |
|
171 { |
|
172 TInt start=FindFromMark(EService, TXmlParser::EElementBegin); |
|
173 TInt stop=FindFromMark(EService, TXmlParser::EElementEnd); |
|
174 |
|
175 if (start==KErrNotFound || stop==KErrNotFound || start>=stop) |
|
176 { |
|
177 break; |
|
178 } |
|
179 |
|
180 aList->CopyL(List(), start, stop); |
|
181 } |
|
182 |
|
183 if (aList->Count()>0) |
|
184 { |
|
185 LOGGER_WRITE( "CCapList::FindServiceL(CStringList* aList) : returned ETrue" ); |
|
186 return ETrue; |
|
187 } |
|
188 |
|
189 LOGGER_WRITE( "CCapList::FindServiceL(CStringList* aList) : returned EFalse" ); |
|
190 return EFalse; |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CCapList::Find(TInt aId, TInt aType, TInt aIndex) |
|
195 // Find element |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CCapList::Find(TInt aId, TInt aType, TInt aIndex) |
|
199 { |
|
200 TInt count=List()->Count(); |
|
201 if (aIndex<0 || aIndex>=count) |
|
202 { |
|
203 CapUtil::Panic(KErrArgument); |
|
204 } |
|
205 |
|
206 for (TInt i=aIndex; i<count; i++) |
|
207 { |
|
208 TPtrC ptr=List()->ReadPtr(i); |
|
209 |
|
210 TInt id=0; |
|
211 TInt type=0; |
|
212 |
|
213 CapParser::ParseElement(ptr, id, type); |
|
214 if (type==TXmlParser::EElementUnknown) |
|
215 { |
|
216 continue; // invalid capability element |
|
217 } |
|
218 |
|
219 if (id==aId && aType==type) |
|
220 { |
|
221 return i; |
|
222 } |
|
223 } |
|
224 return KErrNotFound; |
|
225 } |
|
226 |
|
227 |
|
228 // End of files |