|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "HWRMtrace.h" |
|
21 #include "HWRMPluginTransactionList.h" |
|
22 |
|
23 // EXTERNAL DATA STRUCTURES |
|
24 // None |
|
25 |
|
26 // EXTERNAL FUNCTION PROTOTYPES |
|
27 // None |
|
28 |
|
29 // CONSTANTS |
|
30 // None |
|
31 |
|
32 // MACROS |
|
33 // None |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 // None |
|
37 |
|
38 // MODULE DATA STRUCTURES |
|
39 // None |
|
40 |
|
41 // LOCAL FUNCTION PROTOTYPES |
|
42 // None |
|
43 |
|
44 // FORWARD DECLARATIONS |
|
45 // None |
|
46 |
|
47 // ============================= LOCAL FUNCTIONS =============================== |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CHWRMPluginTransactionList::CHWRMPluginTransactionList |
|
53 // C++ constructor |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CHWRMPluginTransactionList::CHWRMPluginTransactionList() |
|
57 : iTransactionData(NULL), |
|
58 iTransactionDataLast(NULL) |
|
59 { |
|
60 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::CHWRMPluginTransactionList()" )); |
|
61 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::CHWRMPluginTransactionList - return " )); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CHWRMPluginTransactionList::NewL |
|
66 // Two-phased constructor. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CHWRMPluginTransactionList* CHWRMPluginTransactionList::NewL() |
|
70 { |
|
71 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::NewL()" )); |
|
72 |
|
73 CHWRMPluginTransactionList* self = new( ELeave ) CHWRMPluginTransactionList(); |
|
74 |
|
75 // No ConstructL as nothing to do there. |
|
76 |
|
77 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPluginTransactionList::NewL - return 0x%x" ), self ); |
|
78 |
|
79 return self; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------- |
|
83 // Destructor |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 CHWRMPluginTransactionList::~CHWRMPluginTransactionList() |
|
87 { |
|
88 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::~CHWRMPluginTransactionList()" ) ); |
|
89 |
|
90 // delete any existing transaction data |
|
91 while ( iTransactionData ) |
|
92 { |
|
93 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPluginTransactionList::~CHWRMPluginTransactionList - Deleting transaction %d" ), iTransactionData->iTransId ); |
|
94 THWRMPluginTransactionListItem* data = iTransactionData; |
|
95 iTransactionData = iTransactionData->iNextData; |
|
96 delete data; |
|
97 } |
|
98 |
|
99 // No need to delete iTransactionDataLast, obviously. Just NULL it to |
|
100 iTransactionDataLast = NULL; |
|
101 |
|
102 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::~CHWRMPluginTransactionList - return " )); |
|
103 } |
|
104 |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CHWRMPluginTransactionList::FindTransaction |
|
108 // Find transaction from list. |
|
109 // Uses linear search, but there should rarely be more than one concurrent |
|
110 // transaction so it won't be a problem. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 THWRMPluginTransactionListItem* CHWRMPluginTransactionList::FindTransaction( TUint8 aTransId, TBool aRemove ) |
|
114 { |
|
115 COMPONENT_TRACE3(_L( "HWRM Server - CHWRMPluginTransactionList::FindTransaction(0x%x, 0x%x)" ), aTransId, aRemove ); |
|
116 |
|
117 #ifdef COMPONENT_TRACE_FLAG |
|
118 // check the transaction list contents |
|
119 THWRMPluginTransactionListItem* checkData = iTransactionData; |
|
120 TInt count(0); |
|
121 if ( checkData ) |
|
122 { |
|
123 while ( checkData ) |
|
124 { |
|
125 COMPONENT_TRACE3(_L( "HWRM Server - CHWRMPluginTransactionList::FindTransaction - Data %d in list: 0x%x" ), count, checkData->iTransId ); |
|
126 count++; |
|
127 checkData = checkData->iNextData; |
|
128 } |
|
129 } |
|
130 else |
|
131 { |
|
132 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::FindTransaction - List is empty" ) ); |
|
133 } |
|
134 #endif |
|
135 |
|
136 THWRMPluginTransactionListItem* data = iTransactionData; |
|
137 // comment to ignore Coverity false positive. See more detailed comment below. |
|
138 // coverity[assign_zero] |
|
139 THWRMPluginTransactionListItem* dataPrevious = NULL; |
|
140 |
|
141 TBool found(EFalse); |
|
142 |
|
143 while ( data && !found ) |
|
144 { |
|
145 if ( data->iTransId == aTransId ) |
|
146 { |
|
147 found = ETrue; |
|
148 |
|
149 // update pointers, if remove |
|
150 if ( aRemove ) |
|
151 { |
|
152 if ( iTransactionData == data ) |
|
153 { |
|
154 iTransactionData = data->iNextData; |
|
155 } |
|
156 else |
|
157 { |
|
158 // dataPrevious is always not NULL here. |
|
159 // If the while loop IS on its first iteration iTransactionData == data |
|
160 // is true since data = iTransactionData is how data is initiated. If this is |
|
161 // NOT the first iteration dataPrevious = data in the else claues below will |
|
162 // have made sure dataPrevious != NULL. Comments to instruct Coverity to ignore |
|
163 // this false positive are justified. |
|
164 // |
|
165 //coverity[var_deref_op] |
|
166 dataPrevious->iNextData = data->iNextData; |
|
167 } |
|
168 |
|
169 if ( iTransactionDataLast == data ) |
|
170 { |
|
171 iTransactionDataLast = dataPrevious; |
|
172 } |
|
173 |
|
174 iCount--; |
|
175 } |
|
176 } |
|
177 else |
|
178 { |
|
179 dataPrevious = data; |
|
180 data = data->iNextData; |
|
181 } |
|
182 } |
|
183 #ifdef COMPONENT_TRACE_FLAG |
|
184 if ( data ) |
|
185 { |
|
186 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPluginTransactionList::FindTransaction - return transaction 0x%x" ), data->iTransId ); |
|
187 } |
|
188 else |
|
189 { |
|
190 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::FindTransaction - return NULL" ) ); |
|
191 } |
|
192 #endif |
|
193 |
|
194 return data; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CHWRMPluginTransactionList::AddTransaction |
|
199 // Adds transaction to list |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CHWRMPluginTransactionList::AddTransaction( THWRMPluginTransactionListItem* aTransactionData ) |
|
203 { |
|
204 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPluginTransactionList::AddTransaction(0x%x)" ), aTransactionData ); |
|
205 |
|
206 // if previous data exists, put it last in the list. |
|
207 if ( iTransactionData ) |
|
208 { |
|
209 iTransactionDataLast->iNextData = aTransactionData; |
|
210 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::AddTransaction - Added transaction to list" ) ); |
|
211 } |
|
212 else |
|
213 { |
|
214 iTransactionData = aTransactionData; |
|
215 } |
|
216 |
|
217 iTransactionDataLast = aTransactionData; |
|
218 iTransactionDataLast->iNextData = NULL; |
|
219 |
|
220 iCount++; |
|
221 |
|
222 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::AddTransaction - return" ) ); |
|
223 |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CHWRMPluginTransactionList::RemoveFirstItem |
|
228 // Removes first item from transaction list and adjust pointers accordingly |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 THWRMPluginTransactionListItem* CHWRMPluginTransactionList::RemoveFirstItem() |
|
232 { |
|
233 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMPluginTransactionList::RemoveFirstItem()" ) ); |
|
234 |
|
235 THWRMPluginTransactionListItem* retval = iTransactionData; |
|
236 |
|
237 iTransactionData = iTransactionData->iNextData; |
|
238 |
|
239 iCount--; |
|
240 |
|
241 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMPluginTransactionList::RemoveFirstItem - return 0x%x" ), retval ); |
|
242 |
|
243 return retval; |
|
244 } |
|
245 |
|
246 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
247 |
|
248 // End of File |