60
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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: Example Device Info Extension Data Container Plugin source file.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// EXTERNAL INCLUDES
|
|
19 |
#include <e32base.h>
|
|
20 |
|
|
21 |
// CLASS HEADER
|
|
22 |
#include "exampledevinfextdatacontainerplugin.h"
|
|
23 |
|
|
24 |
// -----------------------------------------------------------------------------
|
|
25 |
// CExampleDevInfExtDataContainerPlugin::CExampleDevInfExtDataContainerPlugin()
|
|
26 |
// -----------------------------------------------------------------------------
|
|
27 |
CExampleDevInfExtDataContainerPlugin::CExampleDevInfExtDataContainerPlugin()
|
|
28 |
{
|
|
29 |
}
|
|
30 |
|
|
31 |
// -----------------------------------------------------------------------------
|
|
32 |
// void CExampleDevInfExtDataContainerPlugin::ConstructL()
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
void CExampleDevInfExtDataContainerPlugin::ConstructL()
|
|
35 |
{
|
|
36 |
}
|
|
37 |
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
// CExampleDevInfExtDataContainerPlugin* CExampleDevInfExtDataContainerPlugin::NewL()
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
CExampleDevInfExtDataContainerPlugin* CExampleDevInfExtDataContainerPlugin::NewL()
|
|
42 |
{
|
|
43 |
CExampleDevInfExtDataContainerPlugin* self =
|
|
44 |
new (ELeave) CExampleDevInfExtDataContainerPlugin();
|
|
45 |
CleanupStack::PushL( self );
|
|
46 |
self->ConstructL();
|
|
47 |
CleanupStack::Pop( self );
|
|
48 |
return self;
|
|
49 |
}
|
|
50 |
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
// CExampleDevInfExtDataContainerPlugin::~CExampleDevInfExtDataContainerPlugin()
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
CExampleDevInfExtDataContainerPlugin::~CExampleDevInfExtDataContainerPlugin()
|
|
55 |
{
|
|
56 |
for( TInt i = 0; i < iExtensionArray.Count(); i++ )
|
|
57 |
{
|
|
58 |
iExtensionArray[ i ].iXValArray.Close();
|
|
59 |
}
|
|
60 |
iExtensionArray.Close();
|
|
61 |
}
|
|
62 |
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
// TInt CExampleDevInfExtDataContainerPlugin::GetExtensionCountL()
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
TInt CExampleDevInfExtDataContainerPlugin::GetExtensionCountL()
|
|
67 |
{
|
|
68 |
return iExtensionArray.Count();
|
|
69 |
}
|
|
70 |
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
// const TDesC8& CExampleDevInfExtDataContainerPlugin::GetExtNameL()
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
const TDesC8& CExampleDevInfExtDataContainerPlugin::GetExtNameL( TInt aExtIndex )
|
|
75 |
{
|
|
76 |
if( aExtIndex < 0 || aExtIndex >= iExtensionArray.Count() )
|
|
77 |
{
|
|
78 |
// Illegal index
|
|
79 |
User::Leave( KErrArgument );
|
|
80 |
}
|
|
81 |
|
|
82 |
return iExtensionArray[ aExtIndex ].iXNam;
|
|
83 |
}
|
|
84 |
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
// TInt CExampleDevInfExtDataContainerPlugin::GetExtValueCountL()
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
TInt CExampleDevInfExtDataContainerPlugin::GetExtValueCountL( TInt aExtIndex )
|
|
89 |
{
|
|
90 |
if( aExtIndex < 0 || aExtIndex >= iExtensionArray.Count() )
|
|
91 |
{
|
|
92 |
// Illegal index
|
|
93 |
User::Leave( KErrArgument );
|
|
94 |
}
|
|
95 |
|
|
96 |
return iExtensionArray[ aExtIndex ].iXValArray.Count();
|
|
97 |
}
|
|
98 |
|
|
99 |
// -----------------------------------------------------------------------------
|
|
100 |
// const TDesC8& CExampleDevInfExtDataContainerPlugin::GetExtValueL()
|
|
101 |
// -----------------------------------------------------------------------------
|
|
102 |
const TDesC8& CExampleDevInfExtDataContainerPlugin::GetExtValueL( TInt aExtIndex,
|
|
103 |
TInt aValueIndex )
|
|
104 |
{
|
|
105 |
|
|
106 |
// Check for illegal indices
|
|
107 |
if( aExtIndex < 0 || aExtIndex >= iExtensionArray.Count() )
|
|
108 |
{
|
|
109 |
User::Leave( KErrArgument );
|
|
110 |
}
|
|
111 |
if( aValueIndex < 0 ||
|
|
112 |
aValueIndex >= iExtensionArray[ aExtIndex ].iXValArray.Count() )
|
|
113 |
{
|
|
114 |
User::Leave( KErrArgument );
|
|
115 |
}
|
|
116 |
|
|
117 |
return iExtensionArray[ aExtIndex ].iXValArray[ aValueIndex ];
|
|
118 |
}
|
|
119 |
|
|
120 |
// -----------------------------------------------------------------------------
|
|
121 |
// void CExampleDevInfExtDataContainerPlugin::ClearExtensions()
|
|
122 |
// -----------------------------------------------------------------------------
|
|
123 |
void CExampleDevInfExtDataContainerPlugin::ClearExtensions()
|
|
124 |
{
|
|
125 |
for( TInt i = 0; i < iExtensionArray.Count(); i++ )
|
|
126 |
{
|
|
127 |
iExtensionArray[ i ].iXValArray.Reset();
|
|
128 |
}
|
|
129 |
iExtensionArray.Reset();
|
|
130 |
}
|
|
131 |
|
|
132 |
// -----------------------------------------------------------------------------
|
|
133 |
// void CExampleDevInfExtDataContainerPlugin::InsertExtension()
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
void CExampleDevInfExtDataContainerPlugin::InsertExtension(
|
|
136 |
const TDesC8& aXNam, const TDesC8& aXVal )
|
|
137 |
{
|
|
138 |
TInt index = FindExtensionIndex( aXNam );
|
|
139 |
if( index != KErrNotFound )
|
|
140 |
{
|
|
141 |
AddXValToItem( index, aXVal );
|
|
142 |
}
|
|
143 |
else
|
|
144 |
{
|
|
145 |
AddNewXValItem( aXNam, aXVal );
|
|
146 |
}
|
|
147 |
}
|
|
148 |
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
// void CExampleDevInfExtDataContainerPlugin::RemoveExtension()
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
void CExampleDevInfExtDataContainerPlugin::RemoveExtension( const TDesC8& aXNam )
|
|
153 |
{
|
|
154 |
TInt index = FindExtensionIndex( aXNam );
|
|
155 |
if( index != KErrNotFound )
|
|
156 |
{
|
|
157 |
iExtensionArray.Remove( index );
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
// -----------------------------------------------------------------------------
|
|
162 |
// void CExampleDevInfExtDataContainerPlugin::FindExtensionIndex()
|
|
163 |
// -----------------------------------------------------------------------------
|
|
164 |
TInt CExampleDevInfExtDataContainerPlugin::FindExtensionIndex(
|
|
165 |
const TDesC8& aXNam )
|
|
166 |
{
|
|
167 |
TInt index = KErrNotFound;
|
|
168 |
|
|
169 |
for( TInt i = 0; i < iExtensionArray.Count(); i++ )
|
|
170 |
{
|
|
171 |
TExampleDevInfExtExtensionItem item = iExtensionArray[ i ];
|
|
172 |
if( aXNam.Compare( item.iXNam ) == 0 )
|
|
173 |
{
|
|
174 |
index = i;
|
|
175 |
break;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
return index;
|
|
179 |
}
|
|
180 |
|
|
181 |
// -----------------------------------------------------------------------------
|
|
182 |
// void CExampleDevInfExtDataContainerPlugin::AddXValToItem()
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
void CExampleDevInfExtDataContainerPlugin::AddXValToItem(
|
|
185 |
const TInt aIndex, const TDesC8& aXVal )
|
|
186 |
{
|
|
187 |
ASSERT( aIndex >= 0 );
|
|
188 |
ASSERT( aIndex < iExtensionArray.Count() );
|
|
189 |
|
|
190 |
if( aXVal.Length() == 0 )
|
|
191 |
{
|
|
192 |
// No XVal set, do not insert anything to XVal array
|
|
193 |
return;
|
|
194 |
}
|
|
195 |
else if( aXVal.Length() <= KExtensionElementMaxLength )
|
|
196 |
{
|
|
197 |
iExtensionArray[ aIndex ].iXValArray.Append( aXVal );
|
|
198 |
}
|
|
199 |
else
|
|
200 |
{
|
|
201 |
iExtensionArray[ aIndex ].iXValArray.Append(
|
|
202 |
aXVal.Left( KExtensionElementMaxLength ) );
|
|
203 |
}
|
|
204 |
}
|
|
205 |
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
// void CExampleDevInfExtDataContainerPlugin::AddNewXValItem()
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
void CExampleDevInfExtDataContainerPlugin::AddNewXValItem(
|
|
210 |
const TDesC8& aXNam, const TDesC8& aXVal )
|
|
211 |
{
|
|
212 |
TExampleDevInfExtExtensionItem item;
|
|
213 |
|
|
214 |
// Insert XNam
|
|
215 |
if( aXNam.Length() <= KExtensionElementMaxLength )
|
|
216 |
{
|
|
217 |
item.iXNam = aXNam;
|
|
218 |
}
|
|
219 |
else
|
|
220 |
{
|
|
221 |
item.iXNam = aXNam.Left( KExtensionElementMaxLength );
|
|
222 |
}
|
|
223 |
|
|
224 |
// Insert XVal
|
|
225 |
if( aXVal.Length() > 0 )
|
|
226 |
{
|
|
227 |
if( aXVal.Length() <= KExtensionElementMaxLength )
|
|
228 |
{
|
|
229 |
item.iXValArray.Append( aXVal );
|
|
230 |
}
|
|
231 |
else
|
|
232 |
{
|
|
233 |
item.iXValArray.Append( aXVal.Left( KExtensionElementMaxLength ) );
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
// Add to extension array as a new entry
|
|
238 |
iExtensionArray.Append( item );
|
|
239 |
}
|
|
240 |
|
|
241 |
// End of file
|