0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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 the License "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 |
|
|
18 |
#include "T_EntryArrayData.h"
|
|
19 |
#include "T_EntryData.h"
|
|
20 |
#include "FileserverUtil.h"
|
|
21 |
|
|
22 |
// Commands
|
|
23 |
_LIT( KCmdCount, "count" );
|
|
24 |
_LIT( KCmdDelete, "~" );
|
|
25 |
_LIT( KCmdNew, "new" );
|
|
26 |
_LIT( KCmdIndexOperator, "[]" );
|
|
27 |
|
|
28 |
// Parameters
|
|
29 |
_LIT( KParamDestination, "destination" );
|
|
30 |
_LIT( KParamExpected, "expected" );
|
|
31 |
_LIT( KParamIndex, "index" );
|
|
32 |
|
|
33 |
|
|
34 |
CT_EntryArrayData* CT_EntryArrayData::NewL()
|
|
35 |
/**
|
|
36 |
* Two phase constructor
|
|
37 |
*/
|
|
38 |
{
|
|
39 |
CT_EntryArrayData* ret = new (ELeave) CT_EntryArrayData();
|
|
40 |
CleanupStack::PushL( ret );
|
|
41 |
ret->ConstructL();
|
|
42 |
CleanupStack::Pop( ret );
|
|
43 |
return ret;
|
|
44 |
}
|
|
45 |
|
|
46 |
CT_EntryArrayData::CT_EntryArrayData()
|
|
47 |
: iEntryArray(NULL)
|
|
48 |
/**
|
|
49 |
* Protected constructor. First phase construction
|
|
50 |
*/
|
|
51 |
{
|
|
52 |
}
|
|
53 |
|
|
54 |
void CT_EntryArrayData::ConstructL()
|
|
55 |
/**
|
|
56 |
* Protected constructor. Second phase construction
|
|
57 |
*/
|
|
58 |
{
|
|
59 |
}
|
|
60 |
|
|
61 |
CT_EntryArrayData::~CT_EntryArrayData()
|
|
62 |
/**
|
|
63 |
* Destructor.
|
|
64 |
*/
|
|
65 |
|
|
66 |
{
|
|
67 |
DoCmdDelete();
|
|
68 |
}
|
|
69 |
|
|
70 |
TAny* CT_EntryArrayData::GetObject()
|
|
71 |
/**
|
|
72 |
* Return a pointer to the object that the data wraps
|
|
73 |
*
|
|
74 |
* @return pointer to the object that the data wraps
|
|
75 |
*/
|
|
76 |
|
|
77 |
{
|
|
78 |
return iEntryArray;
|
|
79 |
}
|
|
80 |
|
|
81 |
TBool CT_EntryArrayData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/ )
|
|
82 |
/**
|
|
83 |
* Process a command read from the ini file
|
|
84 |
*
|
|
85 |
* @param aCommand the command to process
|
|
86 |
* @param aSection the entry in the ini file requiring the command to be processed
|
|
87 |
*
|
|
88 |
* @return ETrue if the command is processed
|
|
89 |
*/
|
|
90 |
{
|
|
91 |
TBool retVal = ETrue;
|
|
92 |
|
|
93 |
if ( aCommand == KCmdIndexOperator )
|
|
94 |
{
|
|
95 |
DoCmdIndexOperatorL( aSection );
|
|
96 |
}
|
|
97 |
else if ( aCommand == KCmdCount )
|
|
98 |
{
|
|
99 |
DoCmdCount( aSection );
|
|
100 |
}
|
|
101 |
else if ( aCommand == KCmdDelete )
|
|
102 |
{
|
|
103 |
DoCmdDelete();
|
|
104 |
}
|
|
105 |
else if ( aCommand == KCmdNew )
|
|
106 |
{
|
|
107 |
DoCmdNew();
|
|
108 |
}
|
|
109 |
else
|
|
110 |
{
|
|
111 |
retVal = EFalse;
|
|
112 |
}
|
|
113 |
|
|
114 |
return retVal;
|
|
115 |
}
|
|
116 |
|
|
117 |
void CT_EntryArrayData::DoCmdIndexOperatorL( const TDesC& aSection )
|
|
118 |
/**
|
|
119 |
* Assigns an element of TEntryArray to another TEntry object using "=" operator
|
|
120 |
*/
|
|
121 |
{
|
|
122 |
TInt index;
|
|
123 |
TPtrC entryObjectName;
|
|
124 |
|
|
125 |
if( GET_MANDATORY_INT_PARAMETER( KParamIndex, aSection, index ) &&
|
|
126 |
GET_MANDATORY_STRING_PARAMETER( KParamDestination, aSection, entryObjectName ))
|
|
127 |
{
|
|
128 |
TEntry* entry = new(ELeave) TEntry();
|
|
129 |
CleanupStack::PushL(entry);
|
|
130 |
|
|
131 |
*entry = iEntryArray->operator[](index);
|
|
132 |
CT_EntryData* entryWrapperObject = static_cast<CT_EntryData*>(GetDataWrapperL(entryObjectName));
|
|
133 |
|
|
134 |
if(!entryWrapperObject)
|
|
135 |
{
|
|
136 |
ERR_PRINTF2(_L("%S is not initialised"), &entryObjectName);
|
|
137 |
SetBlockResult(EFail);
|
|
138 |
CleanupStack::PopAndDestroy(entry);
|
|
139 |
}
|
|
140 |
else
|
|
141 |
{
|
|
142 |
entryWrapperObject->SetObjectL(entry);
|
|
143 |
CleanupStack::Pop(entry);
|
|
144 |
}
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
void CT_EntryArrayData::DoCmdCount( const TDesC& aSection )
|
|
149 |
/**
|
|
150 |
* Checks if TEntryArray has expected number of elements
|
|
151 |
*/
|
|
152 |
{
|
|
153 |
TInt expected;
|
|
154 |
if( GET_MANDATORY_INT_PARAMETER( KParamExpected, aSection, expected ) )
|
|
155 |
{
|
|
156 |
INFO_PRINTF2( _L( "Count(). Expected value = %d" ), expected );
|
|
157 |
|
|
158 |
TInt result = iEntryArray->Count();
|
|
159 |
if ( result != expected )
|
|
160 |
{
|
|
161 |
ERR_PRINTF3(_L("Count %d != expected %d"), result, expected );
|
|
162 |
SetBlockResult( EFail );
|
|
163 |
}
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
void CT_EntryArrayData::DoCmdDelete()
|
|
168 |
/**
|
|
169 |
* Deletes TEntryArray class instance
|
|
170 |
*/
|
|
171 |
{
|
|
172 |
DoCleanup();
|
|
173 |
}
|
|
174 |
|
|
175 |
void CT_EntryArrayData::DoCmdNew()
|
|
176 |
/**
|
|
177 |
* Creates new TEntryArray class instance
|
|
178 |
*/
|
|
179 |
{
|
|
180 |
DoCmdDelete();
|
|
181 |
|
|
182 |
INFO_PRINTF1( _L( "Create new TEntryArray() class instance." ) );
|
|
183 |
TRAPD( err, iEntryArray = new (ELeave) TEntryArray() );
|
|
184 |
if ( err != KErrNone )
|
|
185 |
{
|
|
186 |
ERR_PRINTF2( _L( "new TEntryArray() error %d" ), err );
|
|
187 |
SetBlockResult( EFail );
|
|
188 |
}
|
|
189 |
}
|
|
190 |
|
|
191 |
|
|
192 |
void CT_EntryArrayData::SetObjectL( TAny* aAny )
|
|
193 |
/**
|
|
194 |
* Set the wrapped data object with new value
|
|
195 |
*/
|
|
196 |
{
|
|
197 |
DoCleanup();
|
|
198 |
iEntryArray = static_cast<TEntryArray*> ( aAny );
|
|
199 |
}
|
|
200 |
|
|
201 |
void CT_EntryArrayData::DoCleanup()
|
|
202 |
/** Deltes TEntry class instance */
|
|
203 |
{
|
|
204 |
INFO_PRINTF1( _L( "Delete TEntryArray class instance" ) );
|
|
205 |
delete iEntryArray;
|
|
206 |
iEntryArray = NULL;
|
|
207 |
}
|
|
208 |
|
|
209 |
|