|
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 "HWRMService.h" |
|
21 #include "HWRMPluginHandler.h" |
|
22 #include "HWRMtrace.h" |
|
23 |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 // None |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 // None |
|
30 |
|
31 // CONSTANTS |
|
32 // None |
|
33 |
|
34 // MACROS |
|
35 // None |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 // None |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 // None |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 // None |
|
45 |
|
46 // FORWARD DECLARATIONS |
|
47 // None |
|
48 |
|
49 // ============================= LOCAL FUNCTIONS =============================== |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CHWRMService::BaseConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // This method must be called within NewL of the subclass. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void CHWRMService::BaseConstructL(CHWRMPluginHandler* aPluginHandler, |
|
60 CHWRMReservationHandler* aReservationHandler) |
|
61 { |
|
62 COMPONENT_TRACE3(_L( "HWRM Server - CHWRMService::BaseConstructL(0x%x, 0x%x)" ), aPluginHandler, aReservationHandler ) ; |
|
63 |
|
64 if ( !aPluginHandler ) |
|
65 { |
|
66 User::Leave(KErrBadHandle); |
|
67 } |
|
68 |
|
69 iPluginHandler = aPluginHandler; |
|
70 |
|
71 iTransactionList = CHWRMPluginTransactionList::NewL(); |
|
72 |
|
73 iReservationHandler = aReservationHandler; |
|
74 |
|
75 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMService::BaseConstructL - return" ) ); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CHWRMService::BaseDestruct |
|
80 // Cleans up base class. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CHWRMService::BaseDestruct() |
|
84 { |
|
85 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMService::BaseDestruct()" ) ); |
|
86 |
|
87 // No need to destroy iPluginHandler or iReservationHandler, not owned |
|
88 |
|
89 // Complete any pending requests |
|
90 while ( iTransactionList->GetFirstItem() ) |
|
91 { |
|
92 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMService::BaseDestruct - Deleting request %d" ), iTransactionList->GetFirstItem()->iTransId ); |
|
93 THWRMPluginRequestData* data = static_cast<THWRMPluginRequestData*>(iTransactionList->RemoveFirstItem()); |
|
94 |
|
95 if (data->iRequestMessage.Handle()) |
|
96 { |
|
97 // Check that this request is not first one of a split request |
|
98 if ( !data->iSplitCommand || !CheckForMessage(data->iRequestMessage.Handle()) ) |
|
99 { |
|
100 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMService::BaseDestruct() - Canceling pending message" ) ); |
|
101 data->iRequestMessage.Complete(KErrCancel); |
|
102 } |
|
103 else |
|
104 { |
|
105 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMService::BaseDestruct() - Split request, not canceling message yet" ) ); |
|
106 } |
|
107 } |
|
108 |
|
109 TRAPD(err, iPluginHandler->CancelCommandL(data->iTransId)); |
|
110 |
|
111 if ( err != KErrNone ) |
|
112 { |
|
113 COMPONENT_TRACE3(_L( "HWRM Server - CHWRMService::BaseDestruct - Cancelling Command (transid: %d) failed: %d" ), data->iTransId, err ); |
|
114 } |
|
115 |
|
116 delete data; |
|
117 } |
|
118 |
|
119 // Destroy transaction list |
|
120 delete iTransactionList; |
|
121 |
|
122 // NULL things for completeness (and PC-lint) |
|
123 iTransactionList = NULL; |
|
124 iPluginHandler = NULL; |
|
125 iReservationHandler = NULL; |
|
126 |
|
127 COMPONENT_TRACE1(_L( "HWRM Server - CHWRMService::BaseDestruct - return" ) ); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CHWRMService::CompleteRequest |
|
132 // Completes request. Subclass calls this from ProcessResponseL |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 TInt CHWRMService::CompleteRequest(TUint8 aTransId, TInt aCompletionCode) |
|
136 { |
|
137 return CompleteRequest(aTransId, aCompletionCode, iTransactionList, ETrue); |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CHWRMService::CompleteRequest |
|
142 // Completes request. Subclass calls this from ProcessResponseL |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CHWRMService::CompleteRequest(TUint8 aTransId, TInt aCompletionCode, |
|
146 CHWRMPluginTransactionList* aTransactionList, TBool aCompleteMsg) |
|
147 { |
|
148 // Handle message completion |
|
149 TInt contextErr(KErrNone); |
|
150 |
|
151 THWRMPluginRequestData* data = static_cast<THWRMPluginRequestData*>( |
|
152 aTransactionList->FindTransaction( aTransId, ETrue ) ); |
|
153 |
|
154 if ( data ) |
|
155 { |
|
156 // Message can be completed, if there is one pending |
|
157 if ( data->iRequestMessage.Handle() ) |
|
158 { |
|
159 // Check that this request is not first one of a split request |
|
160 if ( aCompleteMsg && |
|
161 ( !data->iSplitCommand || !CheckForMessage( data->iRequestMessage.Handle() ) ) ) |
|
162 { |
|
163 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMService::CompleteRequest - Completing pending message" ) ) ); |
|
164 data->iRequestMessage.Complete(aCompletionCode); |
|
165 } |
|
166 else |
|
167 { |
|
168 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMService::CompleteRequest - Split request, not completing message yet" ) ) ); |
|
169 } |
|
170 } |
|
171 else |
|
172 { |
|
173 // No else, message has already been completed. |
|
174 // This happens when command was requested by timer. |
|
175 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMService::CompleteRequest - No message to complete" ) ) ); |
|
176 } |
|
177 |
|
178 // Cleanup data |
|
179 if(data->iSplitCommandData) |
|
180 { |
|
181 COMPONENT_TRACE3( ( _L( "HWRM Server - CHWRMService::CompleteRequest Deleting iSplitCommandData(0x%x) for Id(0x%x)" ) ), data->iSplitCommandData, data->iSplitCommandId ); |
|
182 delete data->iSplitCommandData; |
|
183 } |
|
184 delete data; |
|
185 data = NULL; |
|
186 } |
|
187 else |
|
188 { |
|
189 // Unexpected completion, something is amiss. |
|
190 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMService::CompleteRequest - No related transaction data found!" ) ) ); |
|
191 contextErr = KErrBadHandle; |
|
192 } |
|
193 |
|
194 return contextErr; |
|
195 } |
|
196 |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CHWRMService::CheckForMessage |
|
200 // Checks transaction list if specified message is in any transaction. |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TBool CHWRMService::CheckForMessage(TInt aHandle) |
|
204 { |
|
205 COMPONENT_TRACE2(_L( "HWRM Server - CHWRMService::CheckForMessage - Checking for message: 0x%x" ), aHandle ); |
|
206 |
|
207 THWRMPluginRequestData* data = static_cast<THWRMPluginRequestData*>(iTransactionList->GetFirstItem()); |
|
208 TBool retval(EFalse); |
|
209 |
|
210 while ( !retval && data ) |
|
211 { |
|
212 if ( data->iRequestMessage.Handle() == aHandle ) |
|
213 { |
|
214 retval = ETrue; |
|
215 } |
|
216 data = static_cast<THWRMPluginRequestData*>(data->iNextData); |
|
217 } |
|
218 |
|
219 return retval; |
|
220 } |
|
221 |
|
222 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
223 |
|
224 // End of File |